@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.
@@ -9157,6 +9157,37 @@ function formatDate(value) {
9157
9157
  function formatTimestamp(value) {
9158
9158
  return String(Math.floor(new Date(value).getTime() / 1e3));
9159
9159
  }
9160
+ function roundedPow10(exp) {
9161
+ const raw = Math.pow(10, exp);
9162
+ if (exp < 0) {
9163
+ const shift = Math.pow(10, -exp);
9164
+ return Math.round(raw * shift) / shift;
9165
+ }
9166
+ return raw;
9167
+ }
9168
+ function getLog10ScaleSteps({
9169
+ min: min2,
9170
+ max: max2,
9171
+ steps
9172
+ }) {
9173
+ if (min2 === 0) {
9174
+ if (max2 === Infinity) {
9175
+ return [...Array(steps - 1)].map((_v, i) => roundedPow10(i + 1));
9176
+ }
9177
+ const maxLog = Math.log10(max2);
9178
+ const endExponent = Math.ceil(maxLog);
9179
+ const startExponent = endExponent - steps + 1;
9180
+ return [...Array(steps - 1)].map(
9181
+ (_v, i) => roundedPow10(startExponent + i)
9182
+ );
9183
+ } else {
9184
+ const minLog = Math.log10(min2);
9185
+ const startExponent = Math.ceil(minLog) === minLog ? minLog + 1 : Math.ceil(minLog);
9186
+ return [...Array(steps - 1)].map(
9187
+ (_v, i) => roundedPow10(startExponent + i)
9188
+ );
9189
+ }
9190
+ }
9160
9191
 
9161
9192
  // src/fetch-map/layer-map.ts
9162
9193
  var SCALE_FUNCS = {
@@ -9173,7 +9204,19 @@ var SCALE_FUNCS = {
9173
9204
  function identity2(v2) {
9174
9205
  return v2;
9175
9206
  }
9207
+ var hexToRGB = (c) => {
9208
+ const { r, g, b } = rgb(c);
9209
+ return [r, g, b];
9210
+ };
9211
+ var rgbToHex = (c) => {
9212
+ const [r, g, b] = c;
9213
+ const rStr = r.toString(16).padStart(2, "0");
9214
+ const gStr = g.toString(16).padStart(2, "0");
9215
+ const bStr = b.toString(16).padStart(2, "0");
9216
+ return `#${rStr}${gStr}${bStr}`.toUpperCase();
9217
+ };
9176
9218
  var UNKNOWN_COLOR = "#868d91";
9219
+ var UNKNOWN_COLOR_RGB = hexToRGB(UNKNOWN_COLOR);
9177
9220
  var OPACITY_MAP = {
9178
9221
  getFillColor: "opacity",
9179
9222
  getLineColor: "strokeOpacity",
@@ -9354,7 +9397,7 @@ function findAccessorKey(keys, properties) {
9354
9397
  return keys;
9355
9398
  }
9356
9399
  function getColorAccessor({ name, colorColumn }, scaleType, { aggregation, range }, opacity, data) {
9357
- const scale2 = calculateLayerScale(
9400
+ const { scale: scale2, domain } = calculateLayerScale(
9358
9401
  colorColumn || name,
9359
9402
  scaleType,
9360
9403
  range,
@@ -9367,30 +9410,54 @@ function getColorAccessor({ name, colorColumn }, scaleType, { aggregation, range
9367
9410
  accessorKeys = findAccessorKey(accessorKeys, properties);
9368
9411
  }
9369
9412
  const propertyValue = properties[accessorKeys[0]];
9370
- const { r, g, b } = rgb(scale2(propertyValue));
9413
+ const [r, g, b] = scale2(propertyValue);
9371
9414
  return [r, g, b, propertyValue === null ? 0 : alpha];
9372
9415
  };
9373
- return { accessor: normalizeAccessor(accessor, data), scale: scale2 };
9416
+ return {
9417
+ accessor: normalizeAccessor(accessor, data),
9418
+ scaleDomain: scale2.domain(),
9419
+ domain,
9420
+ range: scale2.range().map(rgbToHex)
9421
+ };
9374
9422
  }
9375
9423
  function calculateLayerScale(name, scaleType, range, data) {
9376
9424
  let domain = [];
9425
+ let scaleDomain;
9377
9426
  let scaleColor = [];
9378
- if (scaleType !== "identity") {
9379
- const { colorMap, colors } = range;
9380
- if (Array.isArray(colorMap)) {
9427
+ const { colors } = range;
9428
+ if (scaleType === "custom") {
9429
+ if (range.uiCustomScaleType === "logarithmic") {
9430
+ domain = calculateDomain(data, name, scaleType, colors.length);
9431
+ const [min2, max2] = domain;
9432
+ scaleDomain = getLog10ScaleSteps({
9433
+ min: min2,
9434
+ max: max2,
9435
+ steps: colors.length
9436
+ });
9437
+ scaleColor = colors;
9438
+ } else if (range.colorMap) {
9439
+ const { colorMap } = range;
9381
9440
  colorMap.forEach(([value, color2]) => {
9382
9441
  domain.push(value);
9383
9442
  scaleColor.push(color2);
9384
9443
  });
9385
- } else {
9386
- domain = calculateDomain(data, name, scaleType, colors.length);
9387
- scaleColor = colors;
9388
9444
  }
9445
+ } else if (scaleType !== "identity") {
9446
+ domain = calculateDomain(data, name, scaleType, colors.length);
9447
+ scaleColor = colors;
9389
9448
  if (scaleType === "ordinal") {
9390
9449
  domain = domain.slice(0, scaleColor.length);
9391
9450
  }
9392
9451
  }
9393
- return createColorScale(scaleType, domain, scaleColor, UNKNOWN_COLOR);
9452
+ return {
9453
+ scale: createColorScale(
9454
+ scaleType,
9455
+ scaleDomain || domain,
9456
+ scaleColor.map(hexToRGB),
9457
+ UNKNOWN_COLOR_RGB
9458
+ ),
9459
+ domain
9460
+ };
9394
9461
  }
9395
9462
  function createColorScale(scaleType, domain, range, unknown) {
9396
9463
  const scale2 = SCALE_FUNCS[scaleType]();
@@ -9446,9 +9513,13 @@ function negateAccessor(accessor) {
9446
9513
  }
9447
9514
  function getSizeAccessor({ name }, scaleType, aggregation, range, data) {
9448
9515
  const scale2 = scaleType ? SCALE_FUNCS[scaleType]() : identity2;
9449
- if (scaleType) {
9516
+ let domain = [];
9517
+ if (scaleType && range) {
9450
9518
  if (aggregation !== AggregationTypes.Count) {
9451
- scale2.domain(calculateDomain(data, name, scaleType));
9519
+ domain = calculateDomain(data, name, scaleType);
9520
+ scale2.domain(domain);
9521
+ } else {
9522
+ domain = scale2.domain();
9452
9523
  }
9453
9524
  scale2.range(range);
9454
9525
  }
@@ -9460,7 +9531,12 @@ function getSizeAccessor({ name }, scaleType, aggregation, range, data) {
9460
9531
  const propertyValue = properties[accessorKeys[0]];
9461
9532
  return scale2(propertyValue);
9462
9533
  };
9463
- return { accessor: normalizeAccessor(accessor, data), scale: scale2 };
9534
+ return {
9535
+ accessor: normalizeAccessor(accessor, data),
9536
+ domain,
9537
+ scaleDomain: domain,
9538
+ range
9539
+ };
9464
9540
  }
9465
9541
  var FORMATS = {
9466
9542
  date: formatDate,
@@ -9766,10 +9842,11 @@ function domainFromRasterMetadataBand(band, scaleType, colorRange) {
9766
9842
  }
9767
9843
  if (scaleType === "custom") {
9768
9844
  if (colorRange.uiCustomScaleType === "logarithmic") {
9769
- if (colorRange.colorMap) {
9770
- return colorRange.colorMap?.map(([value]) => value) || [];
9771
- }
9772
- return [band.stats.min, band.stats.max];
9845
+ return getLog10ScaleSteps({
9846
+ min: band.stats.min,
9847
+ max: band.stats.max,
9848
+ steps: colorRange.colors.length
9849
+ });
9773
9850
  } else {
9774
9851
  return colorRange.colorMap?.map(([value]) => value) || [];
9775
9852
  }
@@ -9804,7 +9881,7 @@ function getRasterTileLayerStylePropsScaledBand({
9804
9881
  const scaleFun = createColorScale(
9805
9882
  scaleType,
9806
9883
  domain,
9807
- colorRange.colors.map(hexToRGB),
9884
+ colorRange.colors.map(hexToRGB2),
9808
9885
  UNKNOWN_COLOR2
9809
9886
  );
9810
9887
  const bandColorScaleDataTransform = createBandColorScaleDataTransform({
@@ -9872,7 +9949,7 @@ function bufferSetRgba(target, index, r, g, b, a) {
9872
9949
  target[index + 2] = b;
9873
9950
  target[index + 3] = a;
9874
9951
  }
9875
- function hexToRGB(hexColor) {
9952
+ function hexToRGB2(hexColor) {
9876
9953
  const r = parseInt(hexColor.slice(1, 3), 16);
9877
9954
  const g = parseInt(hexColor.slice(3, 5), 16);
9878
9955
  const b = parseInt(hexColor.slice(5, 7), 16);
@@ -10013,24 +10090,7 @@ function createStyleProps(config2, mapping) {
10013
10090
  result.highlightColor = config2.visConfig.enable3d ? [255, 255, 255, 60] : [252, 242, 26, 255];
10014
10091
  return result;
10015
10092
  }
10016
- function domainAndRangeFromScale(scale2) {
10017
- return {
10018
- domain: scale2.domain(),
10019
- range: scale2.range()
10020
- };
10021
- }
10022
10093
  function createChannelProps(id, layerType, config2, visualChannels, data, dataset) {
10023
- const {
10024
- colorField,
10025
- colorScale,
10026
- radiusField,
10027
- radiusScale,
10028
- strokeColorField,
10029
- strokeColorScale,
10030
- sizeField: strokeWidthField,
10031
- sizeScale: strokeWidthScale,
10032
- weightField
10033
- } = visualChannels;
10034
10094
  if (layerType === "raster") {
10035
10095
  const rasterMetadata = data.raster_metadata;
10036
10096
  if (!rasterMetadata) {
@@ -10048,6 +10108,7 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
10048
10108
  visualChannels
10049
10109
  }),
10050
10110
  scales: {}
10111
+ // TODO
10051
10112
  };
10052
10113
  } else {
10053
10114
  return {
@@ -10057,40 +10118,35 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
10057
10118
  rasterMetadata
10058
10119
  }),
10059
10120
  scales: {
10060
- ...colorField && {
10061
- fillColor: {
10062
- field: colorField,
10063
- type: "ordinal",
10064
- domain: [],
10065
- range: []
10066
- }
10067
- }
10121
+ // TODO
10068
10122
  }
10069
10123
  };
10070
10124
  }
10071
10125
  }
10072
- const { heightField, heightScale } = visualChannels;
10073
10126
  const { textLabel, visConfig } = config2;
10074
10127
  const result = {};
10075
10128
  const updateTriggers = {};
10076
10129
  const scales = {};
10077
- if (colorField) {
10078
- const { colorAggregation: aggregation, colorRange: range } = visConfig;
10079
- const { accessor, scale: scale2 } = getColorAccessor(
10080
- colorField,
10081
- colorScale,
10082
- { aggregation, range },
10083
- visConfig.opacity,
10084
- data
10085
- );
10086
- result.getFillColor = accessor;
10087
- scales.fillColor = updateTriggers.getFillColor = {
10088
- field: colorField,
10089
- type: colorScale,
10090
- ...domainAndRangeFromScale(scale2)
10091
- };
10092
- } else if (visConfig.filled) {
10093
- scales.fillColor = {};
10130
+ {
10131
+ const { colorField, colorScale } = visualChannels;
10132
+ const { colorRange, colorAggregation } = visConfig;
10133
+ if (colorField && colorScale && colorRange) {
10134
+ const { accessor, ...scaleProps } = getColorAccessor(
10135
+ colorField,
10136
+ colorScale,
10137
+ { aggregation: colorAggregation, range: colorRange },
10138
+ visConfig.opacity,
10139
+ data
10140
+ );
10141
+ result.getFillColor = accessor;
10142
+ scales.fillColor = updateTriggers.getFillColor = {
10143
+ field: colorField,
10144
+ type: colorScale,
10145
+ ...scaleProps
10146
+ };
10147
+ } else {
10148
+ scales.fillColor = {};
10149
+ }
10094
10150
  }
10095
10151
  if (layerType === "clusterTile") {
10096
10152
  const aggregationExpAlias = getDefaultAggregationExpColumnAliasForLayerType(
@@ -10143,82 +10199,102 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
10143
10199
  radiusRange: visConfig.radiusRange
10144
10200
  };
10145
10201
  }
10146
- if (radiusField) {
10147
- const { accessor, scale: scale2 } = getSizeAccessor(
10148
- radiusField,
10149
- radiusScale,
10150
- visConfig.sizeAggregation,
10151
- visConfig.radiusRange || visConfig.sizeRange,
10152
- data
10153
- );
10154
- result.getPointRadius = accessor;
10155
- scales.pointRadius = updateTriggers.getPointRadius = {
10156
- field: radiusField,
10157
- type: radiusScale || "identity",
10158
- ...domainAndRangeFromScale(scale2)
10159
- };
10202
+ {
10203
+ const radiusRange = visConfig.radiusRange;
10204
+ const { radiusField, radiusScale } = visualChannels;
10205
+ if (radiusField && radiusRange && radiusScale) {
10206
+ const { accessor, ...scaleProps } = getSizeAccessor(
10207
+ radiusField,
10208
+ radiusScale,
10209
+ visConfig.sizeAggregation,
10210
+ radiusRange,
10211
+ data
10212
+ );
10213
+ result.getPointRadius = accessor;
10214
+ scales.pointRadius = updateTriggers.getPointRadius = {
10215
+ field: radiusField,
10216
+ type: radiusScale,
10217
+ ...scaleProps
10218
+ };
10219
+ }
10160
10220
  }
10161
- if (strokeColorField) {
10162
- const opacity = visConfig.strokeOpacity !== void 0 ? visConfig.strokeOpacity : 1;
10163
- const { strokeColorAggregation: aggregation, strokeColorRange: range } = visConfig;
10164
- const { accessor, scale: scale2 } = getColorAccessor(
10165
- strokeColorField,
10166
- strokeColorScale,
10167
- { aggregation, range },
10168
- opacity,
10169
- data
10170
- );
10171
- result.getLineColor = accessor;
10172
- scales.lineColor = updateTriggers.getLineColor = {
10173
- field: strokeColorField,
10174
- type: strokeColorScale,
10175
- ...domainAndRangeFromScale(scale2)
10176
- };
10221
+ {
10222
+ const strokeColorRange = visConfig.strokeColorRange;
10223
+ const { strokeColorScale, strokeColorField } = visualChannels;
10224
+ if (strokeColorField && strokeColorRange && strokeColorScale) {
10225
+ const { strokeColorAggregation: aggregation } = visConfig;
10226
+ const opacity = visConfig.strokeOpacity !== void 0 ? visConfig.strokeOpacity : 1;
10227
+ const { accessor, ...scaleProps } = getColorAccessor(
10228
+ strokeColorField,
10229
+ strokeColorScale,
10230
+ { aggregation, range: strokeColorRange },
10231
+ opacity,
10232
+ data
10233
+ );
10234
+ result.getLineColor = accessor;
10235
+ scales.lineColor = updateTriggers.getLineColor = {
10236
+ field: strokeColorField,
10237
+ type: strokeColorScale,
10238
+ ...scaleProps
10239
+ };
10240
+ }
10177
10241
  }
10178
- if (strokeWidthField) {
10179
- const { accessor, scale: scale2 } = getSizeAccessor(
10180
- strokeWidthField,
10181
- strokeWidthScale,
10182
- visConfig.sizeAggregation,
10183
- visConfig.sizeRange,
10184
- data
10185
- );
10186
- result.getLineWidth = accessor;
10187
- scales.lineWidth = updateTriggers.getLineWidth = {
10188
- field: strokeWidthField,
10189
- type: strokeWidthScale || "identity",
10190
- ...domainAndRangeFromScale(scale2)
10191
- };
10242
+ {
10243
+ const { sizeField: strokeWidthField, sizeScale: strokeWidthScale } = visualChannels;
10244
+ const { sizeRange, sizeAggregation } = visConfig;
10245
+ if (strokeWidthField && sizeRange) {
10246
+ const { accessor, ...scaleProps } = getSizeAccessor(
10247
+ strokeWidthField,
10248
+ strokeWidthScale,
10249
+ sizeAggregation,
10250
+ sizeRange,
10251
+ data
10252
+ );
10253
+ result.getLineWidth = accessor;
10254
+ scales.lineWidth = updateTriggers.getLineWidth = {
10255
+ field: strokeWidthField,
10256
+ type: strokeWidthScale || "identity",
10257
+ ...scaleProps
10258
+ };
10259
+ }
10192
10260
  }
10193
- if (heightField && visConfig.enable3d) {
10194
- const { accessor, scale: scale2 } = getSizeAccessor(
10195
- heightField,
10196
- heightScale,
10197
- visConfig.heightAggregation,
10198
- visConfig.heightRange || visConfig.sizeRange,
10199
- data
10200
- );
10201
- result.getElevation = accessor;
10202
- scales.elevation = updateTriggers.getElevation = {
10203
- field: heightField,
10204
- type: heightScale || "identity",
10205
- ...domainAndRangeFromScale(scale2)
10206
- };
10261
+ {
10262
+ const { enable3d, heightRange } = visConfig;
10263
+ const { heightField, heightScale } = visualChannels;
10264
+ if (heightField && heightRange && enable3d) {
10265
+ const { accessor, ...scaleProps } = getSizeAccessor(
10266
+ heightField,
10267
+ heightScale,
10268
+ visConfig.heightAggregation,
10269
+ heightRange,
10270
+ data
10271
+ );
10272
+ result.getElevation = accessor;
10273
+ scales.elevation = updateTriggers.getElevation = {
10274
+ field: heightField,
10275
+ type: heightScale || "identity",
10276
+ ...scaleProps
10277
+ };
10278
+ }
10207
10279
  }
10208
- if (weightField) {
10209
- const { accessor, scale: scale2 } = getSizeAccessor(
10210
- weightField,
10211
- void 0,
10212
- visConfig.weightAggregation,
10213
- void 0,
10214
- data
10215
- );
10216
- result.getWeight = accessor;
10217
- scales.weight = updateTriggers.getWeight = {
10218
- field: weightField,
10219
- type: "identity",
10220
- ...domainAndRangeFromScale(scale2)
10221
- };
10280
+ {
10281
+ const { weightField } = visualChannels;
10282
+ const { weightAggregation } = visConfig;
10283
+ if (weightField && weightAggregation) {
10284
+ const { accessor, ...scaleProps } = getSizeAccessor(
10285
+ weightField,
10286
+ void 0,
10287
+ weightAggregation,
10288
+ void 0,
10289
+ data
10290
+ );
10291
+ result.getWeight = accessor;
10292
+ scales.weight = updateTriggers.getWeight = {
10293
+ field: weightField,
10294
+ type: "identity",
10295
+ ...scaleProps
10296
+ };
10297
+ }
10222
10298
  }
10223
10299
  if (visConfig.customMarkers) {
10224
10300
  const maxIconSize = getMaxMarkerSize(visConfig, visualChannels);
@@ -10977,6 +11053,7 @@ export {
10977
11053
  domainFromValues as _domainFromValues,
10978
11054
  evaluateVecExpr as _evaluateVecExpr,
10979
11055
  _getHexagonResolution,
11056
+ getLog10ScaleSteps as _getLog10ScaleSteps,
10980
11057
  getRasterTileLayerStyleProps as _getRasterTileLayerStyleProps,
10981
11058
  validateVecExprSyntax as _validateVecExprSyntax,
10982
11059
  addFilter,