@carto/api-client 0.5.15-alpha.raster-2 → 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.
@@ -9541,7 +9541,19 @@ var SCALE_FUNCS = {
9541
9541
  function identity2(v2) {
9542
9542
  return v2;
9543
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
+ };
9544
9555
  var UNKNOWN_COLOR = "#868d91";
9556
+ var UNKNOWN_COLOR_RGB = hexToRGB(UNKNOWN_COLOR);
9545
9557
  var OPACITY_MAP = {
9546
9558
  getFillColor: "opacity",
9547
9559
  getLineColor: "strokeOpacity",
@@ -9648,13 +9660,6 @@ function getLayerProps(type, config2, dataset) {
9648
9660
  };
9649
9661
  }
9650
9662
  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
- }
9658
9663
  if (scaleType === "ordinal" || scaleType === "point") {
9659
9664
  if (!attribute.categories) {
9660
9665
  return [0, 1];
@@ -9729,7 +9734,7 @@ function findAccessorKey(keys, properties) {
9729
9734
  return keys;
9730
9735
  }
9731
9736
  function getColorAccessor({ name, colorColumn }, scaleType, { aggregation, range }, opacity, data) {
9732
- const scale2 = calculateLayerScale(
9737
+ const { scale: scale2, domain } = calculateLayerScale(
9733
9738
  colorColumn || name,
9734
9739
  scaleType,
9735
9740
  range,
@@ -9742,18 +9747,30 @@ function getColorAccessor({ name, colorColumn }, scaleType, { aggregation, range
9742
9747
  accessorKeys = findAccessorKey(accessorKeys, properties);
9743
9748
  }
9744
9749
  const propertyValue = properties[accessorKeys[0]];
9745
- const { r, g, b } = rgb(scale2(propertyValue));
9750
+ const [r, g, b] = scale2(propertyValue);
9746
9751
  return [r, g, b, propertyValue === null ? 0 : alpha];
9747
9752
  };
9748
- 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
+ };
9749
9759
  }
9750
9760
  function calculateLayerScale(name, scaleType, range, data) {
9751
9761
  let domain = [];
9762
+ let scaleDomain;
9752
9763
  let scaleColor = [];
9753
9764
  const { colors } = range;
9754
9765
  if (scaleType === "custom") {
9755
9766
  if (range.uiCustomScaleType === "logarithmic") {
9756
- domain = calculateDomain(data, name, "log10steps", colors.length);
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
+ });
9757
9774
  scaleColor = colors;
9758
9775
  } else if (range.colorMap) {
9759
9776
  const { colorMap } = range;
@@ -9769,7 +9786,15 @@ function calculateLayerScale(name, scaleType, range, data) {
9769
9786
  domain = domain.slice(0, scaleColor.length);
9770
9787
  }
9771
9788
  }
9772
- 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
+ };
9773
9798
  }
9774
9799
  function createColorScale(scaleType, domain, range, unknown) {
9775
9800
  const scale2 = SCALE_FUNCS[scaleType]();
@@ -9825,9 +9850,13 @@ function negateAccessor(accessor) {
9825
9850
  }
9826
9851
  function getSizeAccessor({ name }, scaleType, aggregation, range, data) {
9827
9852
  const scale2 = scaleType ? SCALE_FUNCS[scaleType]() : identity2;
9828
- if (scaleType) {
9853
+ let domain = [];
9854
+ if (scaleType && range) {
9829
9855
  if (aggregation !== AggregationTypes.Count) {
9830
- scale2.domain(calculateDomain(data, name, scaleType));
9856
+ domain = calculateDomain(data, name, scaleType);
9857
+ scale2.domain(domain);
9858
+ } else {
9859
+ domain = scale2.domain();
9831
9860
  }
9832
9861
  scale2.range(range);
9833
9862
  }
@@ -9839,7 +9868,12 @@ function getSizeAccessor({ name }, scaleType, aggregation, range, data) {
9839
9868
  const propertyValue = properties[accessorKeys[0]];
9840
9869
  return scale2(propertyValue);
9841
9870
  };
9842
- return { accessor: normalizeAccessor(accessor, data), scale: scale2 };
9871
+ return {
9872
+ accessor: normalizeAccessor(accessor, data),
9873
+ domain,
9874
+ scaleDomain: domain,
9875
+ range
9876
+ };
9843
9877
  }
9844
9878
  var FORMATS = {
9845
9879
  date: formatDate,
@@ -10184,7 +10218,7 @@ function getRasterTileLayerStylePropsScaledBand({
10184
10218
  const scaleFun = createColorScale(
10185
10219
  scaleType,
10186
10220
  domain,
10187
- colorRange.colors.map(hexToRGB),
10221
+ colorRange.colors.map(hexToRGB2),
10188
10222
  UNKNOWN_COLOR2
10189
10223
  );
10190
10224
  const bandColorScaleDataTransform = createBandColorScaleDataTransform({
@@ -10252,7 +10286,7 @@ function bufferSetRgba(target, index, r, g, b, a) {
10252
10286
  target[index + 2] = b;
10253
10287
  target[index + 3] = a;
10254
10288
  }
10255
- function hexToRGB(hexColor) {
10289
+ function hexToRGB2(hexColor) {
10256
10290
  const r = parseInt(hexColor.slice(1, 3), 16);
10257
10291
  const g = parseInt(hexColor.slice(3, 5), 16);
10258
10292
  const b = parseInt(hexColor.slice(5, 7), 16);
@@ -10397,24 +10431,7 @@ function createStyleProps(config2, mapping) {
10397
10431
  result.highlightColor = config2.visConfig.enable3d ? [255, 255, 255, 60] : [252, 242, 26, 255];
10398
10432
  return result;
10399
10433
  }
10400
- function domainAndRangeFromScale(scale2) {
10401
- return {
10402
- domain: scale2.domain(),
10403
- range: scale2.range()
10404
- };
10405
- }
10406
10434
  function createChannelProps(id, layerType, config2, visualChannels, data, dataset) {
10407
- const {
10408
- colorField,
10409
- colorScale,
10410
- radiusField,
10411
- radiusScale,
10412
- strokeColorField,
10413
- strokeColorScale,
10414
- sizeField: strokeWidthField,
10415
- sizeScale: strokeWidthScale,
10416
- weightField
10417
- } = visualChannels;
10418
10435
  if (layerType === "raster") {
10419
10436
  const rasterMetadata = data.raster_metadata;
10420
10437
  if (!rasterMetadata) {
@@ -10432,6 +10449,7 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
10432
10449
  visualChannels
10433
10450
  }),
10434
10451
  scales: {}
10452
+ // TODO
10435
10453
  };
10436
10454
  } else {
10437
10455
  return {
@@ -10441,40 +10459,35 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
10441
10459
  rasterMetadata
10442
10460
  }),
10443
10461
  scales: {
10444
- ...colorField && {
10445
- fillColor: {
10446
- field: colorField,
10447
- type: "ordinal",
10448
- domain: [],
10449
- range: []
10450
- }
10451
- }
10462
+ // TODO
10452
10463
  }
10453
10464
  };
10454
10465
  }
10455
10466
  }
10456
- const { heightField, heightScale } = visualChannels;
10457
10467
  const { textLabel, visConfig } = config2;
10458
10468
  const result = {};
10459
10469
  const updateTriggers = {};
10460
10470
  const scales = {};
10461
- if (colorField) {
10462
- const { colorAggregation: aggregation, colorRange: range } = visConfig;
10463
- const { accessor, scale: scale2 } = getColorAccessor(
10464
- colorField,
10465
- colorScale,
10466
- { aggregation, range },
10467
- visConfig.opacity,
10468
- data
10469
- );
10470
- result.getFillColor = accessor;
10471
- scales.fillColor = updateTriggers.getFillColor = {
10472
- field: colorField,
10473
- type: colorScale,
10474
- ...domainAndRangeFromScale(scale2)
10475
- };
10476
- } else if (visConfig.filled) {
10477
- 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
+ }
10478
10491
  }
10479
10492
  if (layerType === "clusterTile") {
10480
10493
  const aggregationExpAlias = getDefaultAggregationExpColumnAliasForLayerType(
@@ -10527,82 +10540,102 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
10527
10540
  radiusRange: visConfig.radiusRange
10528
10541
  };
10529
10542
  }
10530
- if (radiusField) {
10531
- const { accessor, scale: scale2 } = getSizeAccessor(
10532
- radiusField,
10533
- radiusScale,
10534
- visConfig.sizeAggregation,
10535
- visConfig.radiusRange || visConfig.sizeRange,
10536
- data
10537
- );
10538
- result.getPointRadius = accessor;
10539
- scales.pointRadius = updateTriggers.getPointRadius = {
10540
- field: radiusField,
10541
- type: radiusScale || "identity",
10542
- ...domainAndRangeFromScale(scale2)
10543
- };
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
+ }
10544
10561
  }
10545
- if (strokeColorField) {
10546
- const opacity = visConfig.strokeOpacity !== void 0 ? visConfig.strokeOpacity : 1;
10547
- const { strokeColorAggregation: aggregation, strokeColorRange: range } = visConfig;
10548
- const { accessor, scale: scale2 } = getColorAccessor(
10549
- strokeColorField,
10550
- strokeColorScale,
10551
- { aggregation, range },
10552
- opacity,
10553
- data
10554
- );
10555
- result.getLineColor = accessor;
10556
- scales.lineColor = updateTriggers.getLineColor = {
10557
- field: strokeColorField,
10558
- type: strokeColorScale,
10559
- ...domainAndRangeFromScale(scale2)
10560
- };
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
+ }
10561
10582
  }
10562
- if (strokeWidthField) {
10563
- const { accessor, scale: scale2 } = getSizeAccessor(
10564
- strokeWidthField,
10565
- strokeWidthScale,
10566
- visConfig.sizeAggregation,
10567
- visConfig.sizeRange,
10568
- data
10569
- );
10570
- result.getLineWidth = accessor;
10571
- scales.lineWidth = updateTriggers.getLineWidth = {
10572
- field: strokeWidthField,
10573
- type: strokeWidthScale || "identity",
10574
- ...domainAndRangeFromScale(scale2)
10575
- };
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
+ }
10576
10601
  }
10577
- if (heightField && visConfig.enable3d) {
10578
- const { accessor, scale: scale2 } = getSizeAccessor(
10579
- heightField,
10580
- heightScale,
10581
- visConfig.heightAggregation,
10582
- visConfig.heightRange || visConfig.sizeRange,
10583
- data
10584
- );
10585
- result.getElevation = accessor;
10586
- scales.elevation = updateTriggers.getElevation = {
10587
- field: heightField,
10588
- type: heightScale || "identity",
10589
- ...domainAndRangeFromScale(scale2)
10590
- };
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
+ }
10591
10620
  }
10592
- if (weightField) {
10593
- const { accessor, scale: scale2 } = getSizeAccessor(
10594
- weightField,
10595
- void 0,
10596
- visConfig.weightAggregation,
10597
- void 0,
10598
- data
10599
- );
10600
- result.getWeight = accessor;
10601
- scales.weight = updateTriggers.getWeight = {
10602
- field: weightField,
10603
- type: "identity",
10604
- ...domainAndRangeFromScale(scale2)
10605
- };
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
+ }
10606
10639
  }
10607
10640
  if (visConfig.customMarkers) {
10608
10641
  const maxIconSize = getMaxMarkerSize(visConfig, visualChannels);