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

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.
@@ -132,6 +132,7 @@ __export(src_exports, {
132
132
  _domainFromValues: () => domainFromValues,
133
133
  _evaluateVecExpr: () => evaluateVecExpr,
134
134
  _getHexagonResolution: () => _getHexagonResolution,
135
+ _getLog10ScaleSteps: () => getLog10ScaleSteps,
135
136
  _getRasterTileLayerStyleProps: () => getRasterTileLayerStyleProps,
136
137
  _validateVecExprSyntax: () => validateVecExprSyntax,
137
138
  addFilter: () => addFilter,
@@ -9493,6 +9494,37 @@ function formatDate(value) {
9493
9494
  function formatTimestamp(value) {
9494
9495
  return String(Math.floor(new Date(value).getTime() / 1e3));
9495
9496
  }
9497
+ function roundedPow10(exp) {
9498
+ const raw = Math.pow(10, exp);
9499
+ if (exp < 0) {
9500
+ const shift = Math.pow(10, -exp);
9501
+ return Math.round(raw * shift) / shift;
9502
+ }
9503
+ return raw;
9504
+ }
9505
+ function getLog10ScaleSteps({
9506
+ min: min2,
9507
+ max: max2,
9508
+ steps
9509
+ }) {
9510
+ if (min2 === 0) {
9511
+ if (max2 === Infinity) {
9512
+ return [...Array(steps - 1)].map((_v, i) => roundedPow10(i + 1));
9513
+ }
9514
+ const maxLog = Math.log10(max2);
9515
+ const endExponent = Math.ceil(maxLog);
9516
+ const startExponent = endExponent - steps + 1;
9517
+ return [...Array(steps - 1)].map(
9518
+ (_v, i) => roundedPow10(startExponent + i)
9519
+ );
9520
+ } else {
9521
+ const minLog = Math.log10(min2);
9522
+ const startExponent = Math.ceil(minLog) === minLog ? minLog + 1 : Math.ceil(minLog);
9523
+ return [...Array(steps - 1)].map(
9524
+ (_v, i) => roundedPow10(startExponent + i)
9525
+ );
9526
+ }
9527
+ }
9496
9528
 
9497
9529
  // src/fetch-map/layer-map.ts
9498
9530
  var SCALE_FUNCS = {
@@ -9509,7 +9541,19 @@ var SCALE_FUNCS = {
9509
9541
  function identity2(v2) {
9510
9542
  return v2;
9511
9543
  }
9544
+ var hexToRGB = (c) => {
9545
+ const { r, g, b } = rgb(c);
9546
+ return [r, g, b];
9547
+ };
9548
+ var rgbToHex = (c) => {
9549
+ const [r, g, b] = c;
9550
+ const rStr = r.toString(16).padStart(2, "0");
9551
+ const gStr = g.toString(16).padStart(2, "0");
9552
+ const bStr = b.toString(16).padStart(2, "0");
9553
+ return `#${rStr}${gStr}${bStr}`.toUpperCase();
9554
+ };
9512
9555
  var UNKNOWN_COLOR = "#868d91";
9556
+ var UNKNOWN_COLOR_RGB = hexToRGB(UNKNOWN_COLOR);
9513
9557
  var OPACITY_MAP = {
9514
9558
  getFillColor: "opacity",
9515
9559
  getLineColor: "strokeOpacity",
@@ -9690,7 +9734,7 @@ function findAccessorKey(keys, properties) {
9690
9734
  return keys;
9691
9735
  }
9692
9736
  function getColorAccessor({ name, colorColumn }, scaleType, { aggregation, range }, opacity, data) {
9693
- const scale2 = calculateLayerScale(
9737
+ const { scale: scale2, domain } = calculateLayerScale(
9694
9738
  colorColumn || name,
9695
9739
  scaleType,
9696
9740
  range,
@@ -9703,30 +9747,54 @@ function getColorAccessor({ name, colorColumn }, scaleType, { aggregation, range
9703
9747
  accessorKeys = findAccessorKey(accessorKeys, properties);
9704
9748
  }
9705
9749
  const propertyValue = properties[accessorKeys[0]];
9706
- const { r, g, b } = rgb(scale2(propertyValue));
9750
+ const [r, g, b] = scale2(propertyValue);
9707
9751
  return [r, g, b, propertyValue === null ? 0 : alpha];
9708
9752
  };
9709
- return { accessor: normalizeAccessor(accessor, data), scale: scale2 };
9753
+ return {
9754
+ accessor: normalizeAccessor(accessor, data),
9755
+ scaleDomain: scale2.domain(),
9756
+ domain,
9757
+ range: scale2.range().map(rgbToHex)
9758
+ };
9710
9759
  }
9711
9760
  function calculateLayerScale(name, scaleType, range, data) {
9712
9761
  let domain = [];
9762
+ let scaleDomain;
9713
9763
  let scaleColor = [];
9714
- if (scaleType !== "identity") {
9715
- const { colorMap, colors } = range;
9716
- if (Array.isArray(colorMap)) {
9764
+ const { colors } = range;
9765
+ if (scaleType === "custom") {
9766
+ if (range.uiCustomScaleType === "logarithmic") {
9767
+ domain = calculateDomain(data, name, scaleType, colors.length);
9768
+ const [min2, max2] = domain;
9769
+ scaleDomain = getLog10ScaleSteps({
9770
+ min: min2,
9771
+ max: max2,
9772
+ steps: colors.length
9773
+ });
9774
+ scaleColor = colors;
9775
+ } else if (range.colorMap) {
9776
+ const { colorMap } = range;
9717
9777
  colorMap.forEach(([value, color2]) => {
9718
9778
  domain.push(value);
9719
9779
  scaleColor.push(color2);
9720
9780
  });
9721
- } else {
9722
- domain = calculateDomain(data, name, scaleType, colors.length);
9723
- scaleColor = colors;
9724
9781
  }
9782
+ } else if (scaleType !== "identity") {
9783
+ domain = calculateDomain(data, name, scaleType, colors.length);
9784
+ scaleColor = colors;
9725
9785
  if (scaleType === "ordinal") {
9726
9786
  domain = domain.slice(0, scaleColor.length);
9727
9787
  }
9728
9788
  }
9729
- return createColorScale(scaleType, domain, scaleColor, UNKNOWN_COLOR);
9789
+ return {
9790
+ scale: createColorScale(
9791
+ scaleType,
9792
+ scaleDomain || domain,
9793
+ scaleColor.map(hexToRGB),
9794
+ UNKNOWN_COLOR_RGB
9795
+ ),
9796
+ domain
9797
+ };
9730
9798
  }
9731
9799
  function createColorScale(scaleType, domain, range, unknown) {
9732
9800
  const scale2 = SCALE_FUNCS[scaleType]();
@@ -9782,9 +9850,13 @@ function negateAccessor(accessor) {
9782
9850
  }
9783
9851
  function getSizeAccessor({ name }, scaleType, aggregation, range, data) {
9784
9852
  const scale2 = scaleType ? SCALE_FUNCS[scaleType]() : identity2;
9785
- if (scaleType) {
9853
+ let domain = [];
9854
+ if (scaleType && range) {
9786
9855
  if (aggregation !== AggregationTypes.Count) {
9787
- scale2.domain(calculateDomain(data, name, scaleType));
9856
+ domain = calculateDomain(data, name, scaleType);
9857
+ scale2.domain(domain);
9858
+ } else {
9859
+ domain = scale2.domain();
9788
9860
  }
9789
9861
  scale2.range(range);
9790
9862
  }
@@ -9796,7 +9868,12 @@ function getSizeAccessor({ name }, scaleType, aggregation, range, data) {
9796
9868
  const propertyValue = properties[accessorKeys[0]];
9797
9869
  return scale2(propertyValue);
9798
9870
  };
9799
- return { accessor: normalizeAccessor(accessor, data), scale: scale2 };
9871
+ return {
9872
+ accessor: normalizeAccessor(accessor, data),
9873
+ domain,
9874
+ scaleDomain: domain,
9875
+ range
9876
+ };
9800
9877
  }
9801
9878
  var FORMATS = {
9802
9879
  date: formatDate,
@@ -10102,10 +10179,11 @@ function domainFromRasterMetadataBand(band, scaleType, colorRange) {
10102
10179
  }
10103
10180
  if (scaleType === "custom") {
10104
10181
  if (colorRange.uiCustomScaleType === "logarithmic") {
10105
- if (colorRange.colorMap) {
10106
- return colorRange.colorMap?.map(([value]) => value) || [];
10107
- }
10108
- return [band.stats.min, band.stats.max];
10182
+ return getLog10ScaleSteps({
10183
+ min: band.stats.min,
10184
+ max: band.stats.max,
10185
+ steps: colorRange.colors.length
10186
+ });
10109
10187
  } else {
10110
10188
  return colorRange.colorMap?.map(([value]) => value) || [];
10111
10189
  }
@@ -10140,7 +10218,7 @@ function getRasterTileLayerStylePropsScaledBand({
10140
10218
  const scaleFun = createColorScale(
10141
10219
  scaleType,
10142
10220
  domain,
10143
- colorRange.colors.map(hexToRGB),
10221
+ colorRange.colors.map(hexToRGB2),
10144
10222
  UNKNOWN_COLOR2
10145
10223
  );
10146
10224
  const bandColorScaleDataTransform = createBandColorScaleDataTransform({
@@ -10208,7 +10286,7 @@ function bufferSetRgba(target, index, r, g, b, a) {
10208
10286
  target[index + 2] = b;
10209
10287
  target[index + 3] = a;
10210
10288
  }
10211
- function hexToRGB(hexColor) {
10289
+ function hexToRGB2(hexColor) {
10212
10290
  const r = parseInt(hexColor.slice(1, 3), 16);
10213
10291
  const g = parseInt(hexColor.slice(3, 5), 16);
10214
10292
  const b = parseInt(hexColor.slice(5, 7), 16);
@@ -10353,24 +10431,7 @@ function createStyleProps(config2, mapping) {
10353
10431
  result.highlightColor = config2.visConfig.enable3d ? [255, 255, 255, 60] : [252, 242, 26, 255];
10354
10432
  return result;
10355
10433
  }
10356
- function domainAndRangeFromScale(scale2) {
10357
- return {
10358
- domain: scale2.domain(),
10359
- range: scale2.range()
10360
- };
10361
- }
10362
10434
  function createChannelProps(id, layerType, config2, visualChannels, data, dataset) {
10363
- const {
10364
- colorField,
10365
- colorScale,
10366
- radiusField,
10367
- radiusScale,
10368
- strokeColorField,
10369
- strokeColorScale,
10370
- sizeField: strokeWidthField,
10371
- sizeScale: strokeWidthScale,
10372
- weightField
10373
- } = visualChannels;
10374
10435
  if (layerType === "raster") {
10375
10436
  const rasterMetadata = data.raster_metadata;
10376
10437
  if (!rasterMetadata) {
@@ -10388,6 +10449,7 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
10388
10449
  visualChannels
10389
10450
  }),
10390
10451
  scales: {}
10452
+ // TODO
10391
10453
  };
10392
10454
  } else {
10393
10455
  return {
@@ -10397,40 +10459,35 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
10397
10459
  rasterMetadata
10398
10460
  }),
10399
10461
  scales: {
10400
- ...colorField && {
10401
- fillColor: {
10402
- field: colorField,
10403
- type: "ordinal",
10404
- domain: [],
10405
- range: []
10406
- }
10407
- }
10462
+ // TODO
10408
10463
  }
10409
10464
  };
10410
10465
  }
10411
10466
  }
10412
- const { heightField, heightScale } = visualChannels;
10413
10467
  const { textLabel, visConfig } = config2;
10414
10468
  const result = {};
10415
10469
  const updateTriggers = {};
10416
10470
  const scales = {};
10417
- if (colorField) {
10418
- const { colorAggregation: aggregation, colorRange: range } = visConfig;
10419
- const { accessor, scale: scale2 } = getColorAccessor(
10420
- colorField,
10421
- colorScale,
10422
- { aggregation, range },
10423
- visConfig.opacity,
10424
- data
10425
- );
10426
- result.getFillColor = accessor;
10427
- scales.fillColor = updateTriggers.getFillColor = {
10428
- field: colorField,
10429
- type: colorScale,
10430
- ...domainAndRangeFromScale(scale2)
10431
- };
10432
- } else if (visConfig.filled) {
10433
- scales.fillColor = {};
10471
+ {
10472
+ const { colorField, colorScale } = visualChannels;
10473
+ const { colorRange, colorAggregation } = visConfig;
10474
+ if (colorField && colorScale && colorRange) {
10475
+ const { accessor, ...scaleProps } = getColorAccessor(
10476
+ colorField,
10477
+ colorScale,
10478
+ { aggregation: colorAggregation, range: colorRange },
10479
+ visConfig.opacity,
10480
+ data
10481
+ );
10482
+ result.getFillColor = accessor;
10483
+ scales.fillColor = updateTriggers.getFillColor = {
10484
+ field: colorField,
10485
+ type: colorScale,
10486
+ ...scaleProps
10487
+ };
10488
+ } else {
10489
+ scales.fillColor = {};
10490
+ }
10434
10491
  }
10435
10492
  if (layerType === "clusterTile") {
10436
10493
  const aggregationExpAlias = getDefaultAggregationExpColumnAliasForLayerType(
@@ -10483,82 +10540,102 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
10483
10540
  radiusRange: visConfig.radiusRange
10484
10541
  };
10485
10542
  }
10486
- if (radiusField) {
10487
- const { accessor, scale: scale2 } = getSizeAccessor(
10488
- radiusField,
10489
- radiusScale,
10490
- visConfig.sizeAggregation,
10491
- visConfig.radiusRange || visConfig.sizeRange,
10492
- data
10493
- );
10494
- result.getPointRadius = accessor;
10495
- scales.pointRadius = updateTriggers.getPointRadius = {
10496
- field: radiusField,
10497
- type: radiusScale || "identity",
10498
- ...domainAndRangeFromScale(scale2)
10499
- };
10543
+ {
10544
+ const radiusRange = visConfig.radiusRange;
10545
+ const { radiusField, radiusScale } = visualChannels;
10546
+ if (radiusField && radiusRange && radiusScale) {
10547
+ const { accessor, ...scaleProps } = getSizeAccessor(
10548
+ radiusField,
10549
+ radiusScale,
10550
+ visConfig.sizeAggregation,
10551
+ radiusRange,
10552
+ data
10553
+ );
10554
+ result.getPointRadius = accessor;
10555
+ scales.pointRadius = updateTriggers.getPointRadius = {
10556
+ field: radiusField,
10557
+ type: radiusScale,
10558
+ ...scaleProps
10559
+ };
10560
+ }
10500
10561
  }
10501
- if (strokeColorField) {
10502
- const opacity = visConfig.strokeOpacity !== void 0 ? visConfig.strokeOpacity : 1;
10503
- const { strokeColorAggregation: aggregation, strokeColorRange: range } = visConfig;
10504
- const { accessor, scale: scale2 } = getColorAccessor(
10505
- strokeColorField,
10506
- strokeColorScale,
10507
- { aggregation, range },
10508
- opacity,
10509
- data
10510
- );
10511
- result.getLineColor = accessor;
10512
- scales.lineColor = updateTriggers.getLineColor = {
10513
- field: strokeColorField,
10514
- type: strokeColorScale,
10515
- ...domainAndRangeFromScale(scale2)
10516
- };
10562
+ {
10563
+ const strokeColorRange = visConfig.strokeColorRange;
10564
+ const { strokeColorScale, strokeColorField } = visualChannels;
10565
+ if (strokeColorField && strokeColorRange && strokeColorScale) {
10566
+ const { strokeColorAggregation: aggregation } = visConfig;
10567
+ const opacity = visConfig.strokeOpacity !== void 0 ? visConfig.strokeOpacity : 1;
10568
+ const { accessor, ...scaleProps } = getColorAccessor(
10569
+ strokeColorField,
10570
+ strokeColorScale,
10571
+ { aggregation, range: strokeColorRange },
10572
+ opacity,
10573
+ data
10574
+ );
10575
+ result.getLineColor = accessor;
10576
+ scales.lineColor = updateTriggers.getLineColor = {
10577
+ field: strokeColorField,
10578
+ type: strokeColorScale,
10579
+ ...scaleProps
10580
+ };
10581
+ }
10517
10582
  }
10518
- if (strokeWidthField) {
10519
- const { accessor, scale: scale2 } = getSizeAccessor(
10520
- strokeWidthField,
10521
- strokeWidthScale,
10522
- visConfig.sizeAggregation,
10523
- visConfig.sizeRange,
10524
- data
10525
- );
10526
- result.getLineWidth = accessor;
10527
- scales.lineWidth = updateTriggers.getLineWidth = {
10528
- field: strokeWidthField,
10529
- type: strokeWidthScale || "identity",
10530
- ...domainAndRangeFromScale(scale2)
10531
- };
10583
+ {
10584
+ const { sizeField: strokeWidthField, sizeScale: strokeWidthScale } = visualChannels;
10585
+ const { sizeRange, sizeAggregation } = visConfig;
10586
+ if (strokeWidthField && sizeRange) {
10587
+ const { accessor, ...scaleProps } = getSizeAccessor(
10588
+ strokeWidthField,
10589
+ strokeWidthScale,
10590
+ sizeAggregation,
10591
+ sizeRange,
10592
+ data
10593
+ );
10594
+ result.getLineWidth = accessor;
10595
+ scales.lineWidth = updateTriggers.getLineWidth = {
10596
+ field: strokeWidthField,
10597
+ type: strokeWidthScale || "identity",
10598
+ ...scaleProps
10599
+ };
10600
+ }
10532
10601
  }
10533
- if (heightField && visConfig.enable3d) {
10534
- const { accessor, scale: scale2 } = getSizeAccessor(
10535
- heightField,
10536
- heightScale,
10537
- visConfig.heightAggregation,
10538
- visConfig.heightRange || visConfig.sizeRange,
10539
- data
10540
- );
10541
- result.getElevation = accessor;
10542
- scales.elevation = updateTriggers.getElevation = {
10543
- field: heightField,
10544
- type: heightScale || "identity",
10545
- ...domainAndRangeFromScale(scale2)
10546
- };
10602
+ {
10603
+ const { enable3d, heightRange } = visConfig;
10604
+ const { heightField, heightScale } = visualChannels;
10605
+ if (heightField && heightRange && enable3d) {
10606
+ const { accessor, ...scaleProps } = getSizeAccessor(
10607
+ heightField,
10608
+ heightScale,
10609
+ visConfig.heightAggregation,
10610
+ heightRange,
10611
+ data
10612
+ );
10613
+ result.getElevation = accessor;
10614
+ scales.elevation = updateTriggers.getElevation = {
10615
+ field: heightField,
10616
+ type: heightScale || "identity",
10617
+ ...scaleProps
10618
+ };
10619
+ }
10547
10620
  }
10548
- if (weightField) {
10549
- const { accessor, scale: scale2 } = getSizeAccessor(
10550
- weightField,
10551
- void 0,
10552
- visConfig.weightAggregation,
10553
- void 0,
10554
- data
10555
- );
10556
- result.getWeight = accessor;
10557
- scales.weight = updateTriggers.getWeight = {
10558
- field: weightField,
10559
- type: "identity",
10560
- ...domainAndRangeFromScale(scale2)
10561
- };
10621
+ {
10622
+ const { weightField } = visualChannels;
10623
+ const { weightAggregation } = visConfig;
10624
+ if (weightField && weightAggregation) {
10625
+ const { accessor, ...scaleProps } = getSizeAccessor(
10626
+ weightField,
10627
+ void 0,
10628
+ weightAggregation,
10629
+ void 0,
10630
+ data
10631
+ );
10632
+ result.getWeight = accessor;
10633
+ scales.weight = updateTriggers.getWeight = {
10634
+ field: weightField,
10635
+ type: "identity",
10636
+ ...scaleProps
10637
+ };
10638
+ }
10562
10639
  }
10563
10640
  if (visConfig.customMarkers) {
10564
10641
  const maxIconSize = getMaxMarkerSize(visConfig, visualChannels);
@@ -11326,6 +11403,7 @@ function hashBuckets(initialCount) {
11326
11403
  _domainFromValues,
11327
11404
  _evaluateVecExpr,
11328
11405
  _getHexagonResolution,
11406
+ _getLog10ScaleSteps,
11329
11407
  _getRasterTileLayerStyleProps,
11330
11408
  _validateVecExprSyntax,
11331
11409
  addFilter,