@carto/kepler.gl 0.0.33-alpha1 → 0.0.34

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.
Files changed (30) hide show
  1. package/dist/components/index.js +25 -2
  2. package/dist/components/side-panel/layer-panel/color-dimension-scale-selector.js +45 -0
  3. package/dist/components/side-panel/layer-panel/layer-configurator.js +108 -33
  4. package/dist/components/side-panel/layer-panel/vis-config-by-field-selector.js +23 -5
  5. package/dist/constants/default-settings.js +12 -9
  6. package/dist/constants/index.js +7 -1
  7. package/dist/deckgl-layers/layer-utils/cpu-aggregator.js +12 -9
  8. package/dist/layers/aggregation-layer.js +23 -1
  9. package/dist/layers/base-layer.js +120 -6
  10. package/dist/layers/cluster-layer/cluster-layer.js +2 -1
  11. package/dist/layers/h3-hexagon-layer/h3-hexagon-layer.js +16 -14
  12. package/dist/utils/data-scale-utils.js +2 -2
  13. package/dist/utils/data-utils.js +19 -1
  14. package/package.json +1 -1
  15. package/src/components/index.js +5 -0
  16. package/src/components/side-panel/layer-panel/color-dimension-scale-selector.js +33 -0
  17. package/src/components/side-panel/layer-panel/layer-configurator.js +101 -23
  18. package/src/components/side-panel/layer-panel/vis-config-by-field-selector.js +31 -3
  19. package/src/constants/default-settings.js +21 -13
  20. package/src/constants/index.js +2 -1
  21. package/src/deckgl-layers/layer-utils/cpu-aggregator.js +25 -8
  22. package/src/layers/aggregation-layer.js +19 -1
  23. package/src/layers/base-layer.js +82 -8
  24. package/src/layers/cluster-layer/cluster-layer.js +1 -0
  25. package/src/layers/h3-hexagon-layer/h3-hexagon-layer.js +14 -17
  26. package/src/utils/data-scale-utils.js +2 -4
  27. package/src/utils/data-utils.d.ts +1 -0
  28. package/src/utils/data-utils.js +14 -0
  29. package/umd/keplergl.min.js +31 -31
  30. package/CHANGELOG.md +0 -711
@@ -23,11 +23,10 @@ import {findDefaultColorField} from 'utils/dataset-utils';
23
23
  import {GeoJsonLayer} from '@deck.gl/layers';
24
24
  import {H3HexagonLayer} from '@deck.gl/geo-layers';
25
25
  import EnhancedColumnLayer from 'deckgl-layers/column-layer/enhanced-column-layer';
26
- import {getCentroid, idToPolygonGeo, h3IsValid, getHexFields} from './h3-utils';
26
+ import {getCentroid, idToPolygonGeo, h3IsValid, getHexFields, getVertices} from './h3-utils';
27
27
  import H3HexagonLayerIcon from './h3-hexagon-layer-icon';
28
28
  import {CHANNEL_SCALES, HIGHLIGH_COLOR_3D} from 'constants/default-settings';
29
-
30
- import {createDataContainer} from 'utils/table-utils';
29
+ import {getLatLngBounds} from 'utils/data-utils';
31
30
 
32
31
  const DEFAULT_LINE_SCALE_VALUE = 8;
33
32
 
@@ -183,22 +182,20 @@ export default class HexagonIdLayer extends Layer {
183
182
  /* eslint-enable complexity */
184
183
 
185
184
  updateLayerMeta(dataContainer, getHexId) {
186
- const centroids = dataContainer.map((d, index) => {
187
- const id = getHexId({index});
188
- if (!h3IsValid(id)) {
189
- return null;
190
- }
191
- // save a reference of centroids to dataToFeature
192
- // so we don't have to re calculate it again
193
- return getCentroid({id});
194
- }, true);
185
+ const validHexagonIds = dataContainer.map((d, index) => getHexId({index})).filter(h3IsValid);
195
186
 
196
- const centroidsDataContainer = createDataContainer(centroids);
197
-
198
- const bounds = this.getPointsBounds(centroidsDataContainer, (d, dc) => {
199
- return [dc.valueAt(d.index, 0), dc.valueAt(d.index, 1)];
200
- });
187
+ // save a reference of centroids to dataToFeature
188
+ // so we don't have to re calculate it again
189
+ const centroids = validHexagonIds.map(id => getCentroid({id}));
201
190
  this.dataToFeature = {centroids};
191
+
192
+ const vertices = validHexagonIds.map(id => getVertices({id})).flat();
193
+ // using the same way to compute bounds as in base-layer.js, even if it's complicated and not very efficient
194
+ const latBounds = getLatLngBounds(vertices, 1, [-90, 90]);
195
+ const lngBounds = getLatLngBounds(vertices, 0, [-180, 180]);
196
+
197
+ const bounds =
198
+ !latBounds || !lngBounds ? null : [lngBounds[0], latBounds[0], lngBounds[1], latBounds[1]];
202
199
  this.updateMeta({bounds});
203
200
  }
204
201
 
@@ -20,6 +20,7 @@
20
20
 
21
21
  import {notNullorUndefined, unique} from './data-utils';
22
22
  import {extent} from 'd3-array';
23
+ import {uniqueSortedByFrequency} from './data-utils';
23
24
 
24
25
  /**
25
26
  * return quantile domain for an array of data
@@ -37,10 +38,7 @@ export function getQuantileDomain(data, valueAccessor, sortFunc) {
37
38
  */
38
39
  export function getOrdinalDomain(dataContainer, valueAccessor) {
39
40
  const values = dataContainer.mapIndex(valueAccessor);
40
-
41
- return unique(values)
42
- .filter(notNullorUndefined)
43
- .sort();
41
+ return uniqueSortedByFrequency(values);
44
42
  }
45
43
 
46
44
  /**
@@ -12,6 +12,7 @@ export function isNumber(d: any): boolean;
12
12
  export function isPlainObject(d: any): boolean;
13
13
  export function numberSort(a: any, b: any): any;
14
14
  export function unique(values: any[]): any[];
15
+ export function uniqueSortedByFrequency(values: any[]): any[];
15
16
  export function arrayMove(array: any[], from: number, to: number);
16
17
  export function getSortingFunction(fieldType: string): numberSort | undefined;
17
18
  export function preciseRound(num: number, decimals: number): string;
@@ -47,6 +47,20 @@ export function unique(values) {
47
47
  return results;
48
48
  }
49
49
 
50
+ export function uniqueSortedByFrequency(values) {
51
+ const frequency = values.reduce((res, value) => {
52
+ if (notNullorUndefined(value)) {
53
+ if (!res[value]) {
54
+ res[value] = 0;
55
+ }
56
+ res[value] += 1;
57
+ }
58
+ return res;
59
+ }, {});
60
+
61
+ return Object.keys(frequency).sort((a, b) => frequency[b] - frequency[a]);
62
+ }
63
+
50
64
  /* eslint-disable max-statements */
51
65
  /**
52
66
  * return center of map from given points