@carto/api-client 0.5.15-alpha.raster-1 → 0.5.15-alpha.raster-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.
@@ -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 = {
@@ -9616,6 +9648,13 @@ function getLayerProps(type, config2, dataset) {
9616
9648
  };
9617
9649
  }
9618
9650
  function domainFromAttribute(attribute, scaleType, scaleLength) {
9651
+ if (scaleType === "log10steps" && attribute.min !== void 0 && attribute.max !== void 0) {
9652
+ return getLog10ScaleSteps({
9653
+ min: attribute.min,
9654
+ max: attribute.max,
9655
+ steps: scaleLength
9656
+ });
9657
+ }
9619
9658
  if (scaleType === "ordinal" || scaleType === "point") {
9620
9659
  if (!attribute.categories) {
9621
9660
  return [0, 1];
@@ -9711,17 +9750,21 @@ function getColorAccessor({ name, colorColumn }, scaleType, { aggregation, range
9711
9750
  function calculateLayerScale(name, scaleType, range, data) {
9712
9751
  let domain = [];
9713
9752
  let scaleColor = [];
9714
- if (scaleType !== "identity") {
9715
- const { colorMap, colors } = range;
9716
- if (Array.isArray(colorMap)) {
9753
+ const { colors } = range;
9754
+ if (scaleType === "custom") {
9755
+ if (range.uiCustomScaleType === "logarithmic") {
9756
+ domain = calculateDomain(data, name, "log10steps", colors.length);
9757
+ scaleColor = colors;
9758
+ } else if (range.colorMap) {
9759
+ const { colorMap } = range;
9717
9760
  colorMap.forEach(([value, color2]) => {
9718
9761
  domain.push(value);
9719
9762
  scaleColor.push(color2);
9720
9763
  });
9721
- } else {
9722
- domain = calculateDomain(data, name, scaleType, colors.length);
9723
- scaleColor = colors;
9724
9764
  }
9765
+ } else if (scaleType !== "identity") {
9766
+ domain = calculateDomain(data, name, scaleType, colors.length);
9767
+ scaleColor = colors;
9725
9768
  if (scaleType === "ordinal") {
9726
9769
  domain = domain.slice(0, scaleColor.length);
9727
9770
  }
@@ -10102,10 +10145,11 @@ function domainFromRasterMetadataBand(band, scaleType, colorRange) {
10102
10145
  }
10103
10146
  if (scaleType === "custom") {
10104
10147
  if (colorRange.uiCustomScaleType === "logarithmic") {
10105
- if (colorRange.colorMap) {
10106
- return colorRange.colorMap?.map(([value]) => value) || [];
10107
- }
10108
- return [band.stats.min, band.stats.max];
10148
+ return getLog10ScaleSteps({
10149
+ min: band.stats.min,
10150
+ max: band.stats.max,
10151
+ steps: colorRange.colors.length
10152
+ });
10109
10153
  } else {
10110
10154
  return colorRange.colorMap?.map(([value]) => value) || [];
10111
10155
  }
@@ -11326,6 +11370,7 @@ function hashBuckets(initialCount) {
11326
11370
  _domainFromValues,
11327
11371
  _evaluateVecExpr,
11328
11372
  _getHexagonResolution,
11373
+ _getLog10ScaleSteps,
11329
11374
  _getRasterTileLayerStyleProps,
11330
11375
  _validateVecExprSyntax,
11331
11376
  addFilter,