@carto/api-client 0.5.15-alpha.raster-4 → 0.5.15

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-4",
11
+ "version": "0.5.15",
12
12
  "license": "MIT",
13
13
  "publishConfig": {
14
14
  "access": "public"
@@ -71,7 +71,6 @@
71
71
  "d3-format": "^3.1.0",
72
72
  "d3-scale": "^4.0.2",
73
73
  "h3-js": "^4.1.0",
74
- "jsep": "^1.4.0",
75
74
  "quadbin": "^0.4.1-alpha.0"
76
75
  },
77
76
  "devDependencies": {
@@ -112,7 +111,7 @@
112
111
  "@vitest/coverage-istanbul": "^3.0.9",
113
112
  "@webcomponents/webcomponentsjs": "^2.8.0",
114
113
  "concurrently": "^9.1.2",
115
- "echarts": "^5.6.0",
114
+ "echarts": "^6.0.0",
116
115
  "eslint": "^9.22.0",
117
116
  "lit": "^3.2.1",
118
117
  "lit-analyzer": "^2.0.3",
@@ -124,7 +123,7 @@
124
123
  "thenby": "^1.3.4",
125
124
  "tinybench": "^4.0.1",
126
125
  "tsup": "^8.3.6",
127
- "typescript": "~5.8.2",
126
+ "typescript": "~5.9.2",
128
127
  "typescript-eslint": "^8.26.1",
129
128
  "vite": "^7.0.0",
130
129
  "vitest": "3.2.4"
@@ -132,6 +131,5 @@
132
131
  "resolutions": {
133
132
  "@carto/api-client": "portal:./",
134
133
  "rollup": "^4.20.0"
135
- },
136
- "stableVersion": "0.5.14"
134
+ }
137
135
  }
@@ -92,7 +92,7 @@ export const STYLE_LAYER_GROUPS: StyleLayerGroup[] = [
92
92
  ];
93
93
 
94
94
  export function applyLayerGroupFilters(
95
- style: any, // this Maplibre/Mapbox style, we don't want to add a dependency on Maplibre
95
+ style: any,
96
96
  visibleLayerGroups: Record<StyleLayerGroupSlug, boolean>
97
97
  ) {
98
98
  if (!Array.isArray(style?.layers)) {
@@ -1,8 +1,4 @@
1
- export {
2
- default as BASEMAP,
3
- applyLayerGroupFilters as _applyLayerGroupFilters,
4
- } from './basemap-styles.js';
5
- export {getRasterTileLayerStyleProps as _getRasterTileLayerStyleProps} from './raster-layer.js';
1
+ export {default as BASEMAP} from './basemap-styles.js';
6
2
  export {fetchMap} from './fetch-map.js';
7
3
  export type {FetchMapOptions, FetchMapResult} from './fetch-map.js';
8
4
  export type {
@@ -15,4 +11,3 @@ export type {
15
11
  export * from './basemap.js';
16
12
  export * from './layer-map.js';
17
13
  export * from './parse-map.js';
18
- export {getLog10ScaleSteps as _getLog10ScaleSteps} from './utils.js';
@@ -25,11 +25,9 @@ import {
25
25
  createBinaryProxy,
26
26
  formatDate,
27
27
  formatTimestamp,
28
- getLog10ScaleSteps,
29
28
  scaleIdentity,
30
29
  } from './utils.js';
31
30
  import type {
32
- ColorRange,
33
31
  CustomMarkersRange,
34
32
  Dataset,
35
33
  MapLayerConfig,
@@ -40,7 +38,6 @@ import type {
40
38
  import type {ProviderType, SchemaField} from '../types.js';
41
39
  import {DEFAULT_AGGREGATION_EXP_ALIAS} from '../constants-internal.js';
42
40
  import {AggregationTypes} from '../constants.js';
43
- import type {Attribute, TilejsonResult} from '../sources/types.js';
44
41
 
45
42
  export type D3Scale = {
46
43
  domain: (d?: any) => any[];
@@ -75,21 +72,7 @@ function identity<T>(v: T): T {
75
72
  return v;
76
73
  }
77
74
 
78
- const hexToRGB = (c: any) => {
79
- const {r, g, b} = rgb(c);
80
- return [r, g, b];
81
- };
82
-
83
- const rgbToHex = (c: number[]) => {
84
- const [r, g, b] = c;
85
- const rStr = r.toString(16).padStart(2, '0');
86
- const gStr = g.toString(16).padStart(2, '0');
87
- const bStr = b.toString(16).padStart(2, '0');
88
- return `#${rStr}${gStr}${bStr}`.toUpperCase();
89
- };
90
-
91
75
  const UNKNOWN_COLOR = '#868d91';
92
- const UNKNOWN_COLOR_RGB = hexToRGB(UNKNOWN_COLOR);
93
76
 
94
77
  export const OPACITY_MAP: Record<string, string> = {
95
78
  getFillColor: 'opacity',
@@ -130,13 +113,6 @@ const sharedPropMap = {
130
113
  },
131
114
  };
132
115
 
133
- const rasterPropsMap = {
134
- isVisible: 'visible',
135
- visConfig: {
136
- opacity: 'opacity',
137
- },
138
- };
139
-
140
116
  const customMarkersPropsMap = {
141
117
  color: 'getIconColor',
142
118
  visConfig: {
@@ -198,13 +174,6 @@ export function getLayerProps(
198
174
  );
199
175
  }
200
176
 
201
- if (type === 'raster') {
202
- return {
203
- propMap: rasterPropsMap,
204
- defaultProps: {},
205
- };
206
- }
207
-
208
177
  let basePropMap: any = sharedPropMap;
209
178
  if (config.visConfig?.customMarkers) {
210
179
  basePropMap = mergePropMaps(basePropMap, customMarkersPropsMap);
@@ -226,21 +195,18 @@ export function getLayerProps(
226
195
  }
227
196
 
228
197
  function domainFromAttribute(
229
- attribute: Attribute,
198
+ attribute: any,
230
199
  scaleType: ScaleType,
231
200
  scaleLength: number
232
- ): number[] | string[] {
201
+ ) {
233
202
  if (scaleType === 'ordinal' || scaleType === 'point') {
234
- if (!attribute.categories) {
235
- return [0, 1];
236
- }
237
203
  return attribute.categories
238
204
  .map((c: any) => c.category)
239
205
  .filter((c: any) => c !== undefined && c !== null);
240
206
  }
241
207
 
242
208
  if (scaleType === 'quantile' && attribute.quantiles) {
243
- return 'global' in attribute.quantiles
209
+ return attribute.quantiles.global
244
210
  ? attribute.quantiles.global[scaleLength]
245
211
  : attribute.quantiles[scaleLength];
246
212
  }
@@ -249,7 +215,7 @@ function domainFromAttribute(
249
215
  if (scaleType === 'log' && min === 0) {
250
216
  min = 1e-5;
251
217
  }
252
- return [min ?? 0, attribute.max ?? 1];
218
+ return [min, attribute.max];
253
219
  }
254
220
 
255
221
  function domainFromValues(values: any, scaleType: ScaleType) {
@@ -269,8 +235,8 @@ function domainFromValues(values: any, scaleType: ScaleType) {
269
235
  }
270
236
 
271
237
  function calculateDomain(
272
- data: TilejsonResult,
273
- name: string,
238
+ data: any,
239
+ name: any,
274
240
  scaleType: ScaleType,
275
241
  scaleLength?: number
276
242
  ) {
@@ -278,16 +244,14 @@ function calculateDomain(
278
244
  // Tileset data type
279
245
  const {attributes} = data.tilestats.layers[0];
280
246
  const attribute = attributes.find((a: any) => a.attribute === name);
281
- if (attribute) {
282
- return domainFromAttribute(attribute, scaleType, scaleLength as number);
283
- }
247
+ return domainFromAttribute(attribute, scaleType, scaleLength as number);
284
248
  }
285
249
 
286
250
  return [0, 1];
287
251
  }
288
252
 
289
253
  function normalizeAccessor(accessor: any, data: any) {
290
- if (data.features || data.tilestats || data.raster_metadata) {
254
+ if (data.features || data.tilestats) {
291
255
  return (object: any, info: any) => {
292
256
  if (object) {
293
257
  return accessor(object.properties || object.__source.object.properties);
@@ -333,16 +297,11 @@ function findAccessorKey(keys: string[], properties: any): string[] {
333
297
  export function getColorAccessor(
334
298
  {name, colorColumn}: VisualChannelField,
335
299
  scaleType: ScaleType,
336
- {aggregation, range}: {aggregation?: string; range: ColorRange},
300
+ {aggregation, range}: {aggregation: string; range: any},
337
301
  opacity: number | undefined,
338
- data: TilejsonResult
339
- ): {
340
- accessor: any;
341
- domain: number[] | string[];
342
- scaleDomain: number[] | string[];
343
- range: string[];
344
- } {
345
- const {scale, domain} = calculateLayerScale(
302
+ data: any
303
+ ): {accessor: any; scale: any} {
304
+ const scale = calculateLayerScale(
346
305
  colorColumn || name,
347
306
  scaleType,
348
307
  range,
@@ -356,77 +315,43 @@ export function getColorAccessor(
356
315
  accessorKeys = findAccessorKey(accessorKeys, properties);
357
316
  }
358
317
  const propertyValue = properties[accessorKeys[0]];
359
- const [r, g, b] = scale(propertyValue);
318
+ const {r, g, b} = rgb(scale(propertyValue));
360
319
  return [r, g, b, propertyValue === null ? 0 : alpha];
361
320
  };
362
- return {
363
- accessor: normalizeAccessor(accessor, data),
364
- scaleDomain: scale.domain(),
365
- domain,
366
- range: scale.range().map(rgbToHex),
367
- };
321
+ return {accessor: normalizeAccessor(accessor, data), scale};
368
322
  }
369
323
 
370
- export function calculateLayerScale(
371
- name: string,
324
+ function calculateLayerScale(
325
+ name: any,
372
326
  scaleType: ScaleType,
373
- range: ColorRange,
374
- data: TilejsonResult
375
- ): {scale: D3Scale; domain: string[] | number[]} {
376
- let domain: string[] | number[] = [];
377
- let scaleDomain: number[] | undefined;
327
+ range: any,
328
+ data: any
329
+ ) {
330
+ const scale = SCALE_FUNCS[scaleType]();
331
+ let domain: (string | number)[] = [];
378
332
  let scaleColor: string[] = [];
379
- const {colors} = range;
380
-
381
- if (scaleType === 'custom') {
382
- domain = calculateDomain(data, name, scaleType, colors.length);
383
- const [min, max] = domain as number[];
384
- if (range.uiCustomScaleType === 'logarithmic') {
385
- scaleDomain = getLog10ScaleSteps({
386
- min,
387
- max,
388
- steps: colors.length,
389
- });
390
333
 
391
- scaleColor = colors;
392
- } else if (range.colorMap) {
393
- const {colorMap} = range;
394
- scaleDomain = [];
334
+ if (scaleType !== 'identity') {
335
+ const {colorMap, colors} = range;
336
+
337
+ if (Array.isArray(colorMap)) {
395
338
  colorMap.forEach(([value, color]) => {
396
- (scaleDomain as number[]).push(Number(value));
339
+ domain.push(value);
397
340
  scaleColor.push(color);
398
341
  });
342
+ } else {
343
+ domain = calculateDomain(data, name, scaleType, colors.length);
344
+ scaleColor = colors;
399
345
  }
400
- } else if (scaleType !== 'identity') {
401
- domain = calculateDomain(data, name, scaleType, colors.length);
402
- scaleColor = colors;
403
346
 
404
347
  if (scaleType === 'ordinal') {
405
348
  domain = domain.slice(0, scaleColor.length);
406
349
  }
407
350
  }
408
351
 
409
- return {
410
- scale: createColorScale(
411
- scaleType,
412
- scaleDomain || domain,
413
- scaleColor.map(hexToRGB),
414
- UNKNOWN_COLOR_RGB
415
- ),
416
- domain,
417
- };
418
- }
419
-
420
- export function createColorScale<T>(
421
- scaleType: ScaleType,
422
- domain: string[] | number[],
423
- range: T[],
424
- unknown: T
425
- ) {
426
- const scale = SCALE_FUNCS[scaleType]();
427
352
  scale.domain(domain);
428
- scale.range(range);
429
- scale.unknown!(unknown as any);
353
+ scale.range(scaleColor);
354
+ scale.unknown!(UNKNOWN_COLOR);
430
355
 
431
356
  return scale;
432
357
  }
@@ -502,22 +427,13 @@ export function getSizeAccessor(
502
427
  {name}: VisualChannelField,
503
428
  scaleType: ScaleType | undefined,
504
429
  aggregation: string | null | undefined,
505
- range: number[] | undefined,
506
- data: TilejsonResult
507
- ): {
508
- accessor: any;
509
- domain: number[];
510
- scaleDomain: number[];
511
- range: number[] | undefined;
512
- } {
430
+ range: Iterable<Range> | null | undefined,
431
+ data: any
432
+ ): {accessor: any; scale: any} {
513
433
  const scale = scaleType ? SCALE_FUNCS[scaleType]() : identity;
514
- let domain: number[] = [];
515
- if (scaleType && range) {
434
+ if (scaleType) {
516
435
  if (aggregation !== AggregationTypes.Count) {
517
- domain = calculateDomain(data, name, scaleType) as number[];
518
- (scale as D3Scale).domain(domain);
519
- } else {
520
- domain = (scale as D3Scale).domain();
436
+ (scale as D3Scale).domain(calculateDomain(data, name, scaleType));
521
437
  }
522
438
  (scale as D3Scale).range(range);
523
439
  }
@@ -530,12 +446,7 @@ export function getSizeAccessor(
530
446
  const propertyValue = properties[accessorKeys[0]];
531
447
  return scale(propertyValue);
532
448
  };
533
- return {
534
- accessor: normalizeAccessor(accessor, data),
535
- domain,
536
- scaleDomain: domain,
537
- range,
538
- };
449
+ return {accessor: normalizeAccessor(accessor, data), scale};
539
450
  }
540
451
 
541
452
  const FORMATS: Record<string, (value: any) => string> = {