@carto/api-client 0.5.15-alpha.raster-0 → 0.5.15-alpha.raster-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "homepage": "https://github.com/CartoDB/carto-api-client#readme",
9
9
  "author": "Don McCurdy <donmccurdy@carto.com>",
10
10
  "packageManager": "yarn@4.3.1",
11
- "version": "0.5.15-alpha.raster-0",
11
+ "version": "0.5.15-alpha.raster-1",
12
12
  "license": "MIT",
13
13
  "publishConfig": {
14
14
  "access": "public"
@@ -92,7 +92,7 @@ export const STYLE_LAYER_GROUPS: StyleLayerGroup[] = [
92
92
  ];
93
93
 
94
94
  export function applyLayerGroupFilters(
95
- style: any,
95
+ style: any, // this Maplibre/Mapbox style, we don't want to add a dependency on Maplibre
96
96
  visibleLayerGroups: Record<StyleLayerGroupSlug, boolean>
97
97
  ) {
98
98
  if (!Array.isArray(style?.layers)) {
@@ -1,4 +1,7 @@
1
- export {default as BASEMAP} from './basemap-styles.js';
1
+ export {
2
+ default as BASEMAP,
3
+ applyLayerGroupFilters as _applyLayerGroupFilters,
4
+ } from './basemap-styles.js';
2
5
  export {getRasterTileLayerStyleProps as _getRasterTileLayerStyleProps} from './raster-layer.js';
3
6
  export {fetchMap} from './fetch-map.js';
4
7
  export type {FetchMapOptions, FetchMapResult} from './fetch-map.js';
@@ -39,7 +39,7 @@ import type {
39
39
  import type {ProviderType, SchemaField} from '../types.js';
40
40
  import {DEFAULT_AGGREGATION_EXP_ALIAS} from '../constants-internal.js';
41
41
  import {AggregationTypes} from '../constants.js';
42
- import type {TilejsonResult} from '../sources/types.js';
42
+ import type {Attribute, TilejsonResult} from '../sources/types.js';
43
43
 
44
44
  export type D3Scale = {
45
45
  domain: (d?: any) => any[];
@@ -211,10 +211,10 @@ export function getLayerProps(
211
211
  }
212
212
 
213
213
  function domainFromAttribute(
214
- attribute: any,
214
+ attribute: Attribute,
215
215
  scaleType: ScaleType,
216
216
  scaleLength: number
217
- ) {
217
+ ): number[] | string[] {
218
218
  if (scaleType === 'ordinal' || scaleType === 'point') {
219
219
  if (!attribute.categories) {
220
220
  return [0, 1];
@@ -225,7 +225,7 @@ function domainFromAttribute(
225
225
  }
226
226
 
227
227
  if (scaleType === 'quantile' && attribute.quantiles) {
228
- return attribute.quantiles.global
228
+ return 'global' in attribute.quantiles
229
229
  ? attribute.quantiles.global[scaleLength]
230
230
  : attribute.quantiles[scaleLength];
231
231
  }
@@ -234,7 +234,7 @@ function domainFromAttribute(
234
234
  if (scaleType === 'log' && min === 0) {
235
235
  min = 1e-5;
236
236
  }
237
- return [min, attribute.max];
237
+ return [min ?? 0, attribute.max ?? 1];
238
238
  }
239
239
 
240
240
  function domainFromValues(values: any, scaleType: ScaleType) {
@@ -263,7 +263,9 @@ function calculateDomain(
263
263
  // Tileset data type
264
264
  const {attributes} = data.tilestats.layers[0];
265
265
  const attribute = attributes.find((a: any) => a.attribute === name);
266
- return domainFromAttribute(attribute, scaleType, scaleLength as number);
266
+ if (attribute) {
267
+ return domainFromAttribute(attribute, scaleType, scaleLength as number);
268
+ }
267
269
  }
268
270
 
269
271
  return [0, 1];
@@ -318,7 +320,7 @@ export function getColorAccessor(
318
320
  scaleType: ScaleType,
319
321
  {aggregation, range}: {aggregation: string; range: any},
320
322
  opacity: number | undefined,
321
- data: any
323
+ data: TilejsonResult
322
324
  ): {accessor: any; scale: any} {
323
325
  const scale = calculateLayerScale(
324
326
  colorColumn || name,
@@ -456,7 +458,7 @@ export function getSizeAccessor(
456
458
  scaleType: ScaleType | undefined,
457
459
  aggregation: string | null | undefined,
458
460
  range: Iterable<Range> | null | undefined,
459
- data: any
461
+ data: TilejsonResult
460
462
  ): {accessor: any; scale: any} {
461
463
  const scale = scaleType ? SCALE_FUNCS[scaleType]() : identity;
462
464
  if (scaleType) {
@@ -36,6 +36,7 @@ import {
36
36
  getRasterTileLayerStylePropsRgb,
37
37
  getRasterTileLayerStylePropsScaledBand,
38
38
  } from './raster-layer.js';
39
+ import type {TilejsonResult} from '../sources/types.js';
39
40
 
40
41
  export type Scale = {
41
42
  field: VisualChannelField;
@@ -257,7 +258,7 @@ function createChannelProps(
257
258
  layerType: LayerType,
258
259
  config: MapLayerConfig,
259
260
  visualChannels: VisualChannels,
260
- data: any,
261
+ data: TilejsonResult,
261
262
  dataset: Dataset
262
263
  ): {
263
264
  channelProps: Record<string, any>;
@@ -270,15 +271,24 @@ function createChannelProps(
270
271
  radiusScale,
271
272
  strokeColorField,
272
273
  strokeColorScale,
274
+ sizeField: strokeWidthField,
275
+ sizeScale: strokeWidthScale,
273
276
  weightField,
274
277
  } = visualChannels;
275
278
  if (layerType === 'raster') {
279
+ const rasterMetadata = data.raster_metadata;
280
+ if (!rasterMetadata) {
281
+ return {
282
+ channelProps: {},
283
+ scales: {},
284
+ };
285
+ }
276
286
  const rasterStyleType = config.visConfig.rasterStyleType;
277
287
  if (rasterStyleType === 'Rgb') {
278
288
  return {
279
289
  channelProps: getRasterTileLayerStylePropsRgb({
280
290
  layerConfig: config,
281
- rasterMetadata: data.raster_metadata,
291
+ rasterMetadata,
282
292
  visualChannels,
283
293
  }),
284
294
  scales: {},
@@ -288,7 +298,7 @@ function createChannelProps(
288
298
  channelProps: getRasterTileLayerStylePropsScaledBand({
289
299
  layerConfig: config,
290
300
  visualChannels,
291
- rasterMetadata: data.raster_metadata,
301
+ rasterMetadata,
292
302
  }),
293
303
  scales: {
294
304
  ...(colorField && {
@@ -427,6 +437,22 @@ function createChannelProps(
427
437
  ...domainAndRangeFromScale(scale),
428
438
  };
429
439
  }
440
+ if (strokeWidthField) {
441
+ const {accessor, scale} = getSizeAccessor(
442
+ strokeWidthField,
443
+ strokeWidthScale,
444
+ visConfig.sizeAggregation,
445
+ visConfig.sizeRange,
446
+ data
447
+ );
448
+ result.getLineWidth = accessor;
449
+ scales.lineWidth = updateTriggers.getLineWidth = {
450
+ field: strokeWidthField,
451
+ type: strokeWidthScale || 'identity',
452
+ ...domainAndRangeFromScale(scale),
453
+ };
454
+ }
455
+
430
456
  if (heightField && visConfig.enable3d) {
431
457
  const {accessor, scale} = getSizeAccessor(
432
458
  heightField,
package/src/index.ts CHANGED
@@ -2,11 +2,6 @@ export * from './client.js';
2
2
  export * from './constants.js';
3
3
  export * from './deck/index.js';
4
4
  export * from './fetch-map/index.js';
5
- export type {
6
- LayerDescriptor,
7
- LayerType,
8
- _getRasterTileLayerStyleProps,
9
- } from './fetch-map/index.js';
10
5
  export {
11
6
  createVecExprEvaluator as _createVecExprEvaluator,
12
7
  evaluateVecExpr as _evaluateVecExpr,
@@ -292,14 +292,64 @@ export interface Tilestats {
292
292
 
293
293
  export interface Layer {
294
294
  layer: string;
295
+ /** Number of features in the layer. */
295
296
  count: number;
297
+
298
+ /** Number of attributes in the layer. */
296
299
  attributeCount: number;
297
300
  attributes: Attribute[];
301
+
302
+ /** Type of geometry as in geojson geometry type (Point, LineString, Polygon, etc.) */
303
+ geometry?: string;
304
+ }
305
+
306
+ export interface AttributeCategoryItem {
307
+ category: string;
308
+ frequency: number;
309
+ }
310
+
311
+ /**
312
+ * Quantiles by number of buckets.
313
+ *
314
+ * Example:
315
+ * ```ts
316
+ * {
317
+ * // for 3 buckets, first 1/3 of items lies in range [min, 20], second 1/3 is in [20, 40], and last 1/3 is in [40, max]
318
+ * 3: [20, 40],
319
+ * 4: [20, 30, 50], for 4 buckets ...
320
+ * }
321
+ * ```
322
+ */
323
+ export interface QuantileStats {
324
+ [bucketCount: number]: number[];
298
325
  }
299
326
 
300
327
  export interface Attribute {
301
- attribute: string;
328
+ /**
329
+ * String, Number, Timestamp, Boolean
330
+ */
302
331
  type: string;
332
+
333
+ /**
334
+ * Attribute name.
335
+ */
336
+ attribute: string;
337
+
338
+ // Stats for numeric attributes
339
+ min?: number;
340
+ max?: number;
341
+ sum?: number;
342
+
343
+ /** Quantiles by number of buckets */
344
+ quantiles?:
345
+ | {
346
+ // Quantile stats for numeric attributes in static spatial index tilesets are enclosed in extra global object
347
+ global: QuantileStats;
348
+ }
349
+ | QuantileStats;
350
+
351
+ // Stats for string/boolean attributes
352
+ categories?: AttributeCategoryItem[];
303
353
  }
304
354
 
305
355
  export interface VectorLayer {
@@ -325,17 +375,8 @@ export type RasterMetadataBandStats = {
325
375
 
326
376
  /**
327
377
  * Quantiles by number of buckets.
328
- *
329
- * Example:
330
- * ```ts
331
- * {
332
- * // for 3 buckets, first 1/3 of items lies in range [min, 20], second 1/3 is in [20, 40], and last 1/3 is in [40, max]
333
- * 3: [20, 40],
334
- * 4: [20, 30, 50], for 4 buckets ...
335
- * }
336
- * ```
337
378
  */
338
- quantiles?: Record<number, number[]>;
379
+ quantiles?: QuantileStats;
339
380
 
340
381
  /**
341
382
  * Top values by number of values.