@carto/api-client 0.5.17 → 0.5.18-alpha.colormapfix-2

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.17",
11
+ "version": "0.5.18-alpha.colormapfix-2",
12
12
  "license": "MIT",
13
13
  "publishConfig": {
14
14
  "access": "public"
@@ -132,5 +132,6 @@
132
132
  "resolutions": {
133
133
  "@carto/api-client": "portal:./",
134
134
  "rollup": "^4.20.0"
135
- }
135
+ },
136
+ "stableVersion": "0.5.17"
136
137
  }
@@ -374,44 +374,39 @@ export function calculateLayerScale(
374
374
  range: ColorRange,
375
375
  data: TilejsonResult
376
376
  ): {scale: D3Scale; domain: string[] | number[]} {
377
- let domain: string[] | number[] = [];
378
- let scaleDomain: number[] | undefined;
379
- let scaleColor: string[] = [];
377
+ let scaleDomain: number[] | string[] | undefined;
378
+ let scaleColors: string[] = [];
380
379
  const {colors} = range;
381
380
 
382
- if (scaleType === 'custom') {
383
- domain = calculateDomain(data, name, scaleType, colors.length);
384
- const [min, max] = domain as number[];
385
- if (range.uiCustomScaleType === 'logarithmic') {
386
- scaleDomain = getLog10ScaleSteps({
387
- min,
388
- max,
389
- steps: colors.length,
390
- });
391
-
392
- scaleColor = colors;
393
- } else if (range.colorMap) {
381
+ const domain = calculateDomain(data, name, scaleType, colors.length);
382
+ if (scaleType !== 'identity') {
383
+ if (range.colorMap) {
394
384
  const {colorMap} = range;
395
385
  scaleDomain = [];
396
386
  colorMap.forEach(([value, color]) => {
397
- (scaleDomain as number[]).push(Number(value));
398
- scaleColor.push(color);
387
+ (scaleDomain as any[]).push(value);
388
+ scaleColors.push(color);
399
389
  });
400
- }
401
- } else if (scaleType !== 'identity') {
402
- domain = calculateDomain(data, name, scaleType, colors.length);
403
- scaleColor = colors;
404
-
405
- if (scaleType === 'ordinal') {
406
- domain = domain.slice(0, scaleColor.length);
390
+ } else {
391
+ if (scaleType === 'custom' && range.uiCustomScaleType === 'logarithmic') {
392
+ const [min, max] = domain as number[];
393
+ scaleDomain = getLog10ScaleSteps({
394
+ min,
395
+ max,
396
+ steps: colors.length,
397
+ });
398
+
399
+ scaleColors = colors;
400
+ } else {
401
+ scaleColors = colors;
402
+ }
407
403
  }
408
404
  }
409
-
410
405
  return {
411
406
  scale: createColorScale(
412
407
  scaleType,
413
408
  scaleDomain || domain,
414
- scaleColor.map(hexToRGB),
409
+ scaleColors.map(hexToRGB),
415
410
  UNKNOWN_COLOR_RGB
416
411
  ),
417
412
  domain,