@deck.gl/aggregation-layers 8.9.0-alpha.5 → 8.9.0-beta.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.
Files changed (118) hide show
  1. package/dist/dist.dev.js +5994 -20632
  2. package/dist/es5/aggregation-layer.js.map +1 -1
  3. package/dist/es5/contour-layer/contour-layer.js +9 -3
  4. package/dist/es5/contour-layer/contour-layer.js.map +1 -1
  5. package/dist/es5/cpu-grid-layer/cpu-grid-layer.js.map +1 -1
  6. package/dist/es5/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.js +1 -1
  7. package/dist/es5/gpu-grid-layer/gpu-grid-layer.js.map +1 -1
  8. package/dist/es5/grid-aggregation-layer.js.map +1 -1
  9. package/dist/es5/grid-layer/grid-layer.js.map +1 -1
  10. package/dist/es5/heatmap-layer/heatmap-layer.js.map +1 -1
  11. package/dist/es5/heatmap-layer/max-vs.glsl.js +1 -1
  12. package/dist/es5/heatmap-layer/triangle-layer-fragment.glsl.js +1 -1
  13. package/dist/es5/heatmap-layer/triangle-layer-vertex.glsl.js +1 -1
  14. package/dist/es5/heatmap-layer/weights-fs.glsl.js +1 -1
  15. package/dist/es5/heatmap-layer/weights-vs.glsl.js +1 -1
  16. package/dist/es5/hexagon-layer/hexagon-layer.js.map +1 -1
  17. package/dist/es5/screen-grid-layer/screen-grid-cell-layer.js.map +1 -1
  18. package/dist/es5/screen-grid-layer/screen-grid-layer-vertex.glsl.js +1 -1
  19. package/dist/es5/screen-grid-layer/screen-grid-layer.js.map +1 -1
  20. package/dist/esm/aggregation-layer.js.map +1 -1
  21. package/dist/esm/contour-layer/contour-layer.js +9 -3
  22. package/dist/esm/contour-layer/contour-layer.js.map +1 -1
  23. package/dist/esm/cpu-grid-layer/cpu-grid-layer.js.map +1 -1
  24. package/dist/esm/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.js +1 -1
  25. package/dist/esm/gpu-grid-layer/gpu-grid-layer.js.map +1 -1
  26. package/dist/esm/grid-aggregation-layer.js.map +1 -1
  27. package/dist/esm/grid-layer/grid-layer.js.map +1 -1
  28. package/dist/esm/heatmap-layer/heatmap-layer.js.map +1 -1
  29. package/dist/esm/heatmap-layer/max-vs.glsl.js +1 -1
  30. package/dist/esm/heatmap-layer/triangle-layer-fragment.glsl.js +1 -1
  31. package/dist/esm/heatmap-layer/triangle-layer-vertex.glsl.js +1 -1
  32. package/dist/esm/heatmap-layer/weights-fs.glsl.js +1 -1
  33. package/dist/esm/heatmap-layer/weights-vs.glsl.js +1 -1
  34. package/dist/esm/hexagon-layer/hexagon-layer.js.map +1 -1
  35. package/dist/esm/screen-grid-layer/screen-grid-cell-layer.js.map +1 -1
  36. package/dist/esm/screen-grid-layer/screen-grid-layer-vertex.glsl.js +1 -1
  37. package/dist/esm/screen-grid-layer/screen-grid-layer.js.map +1 -1
  38. package/dist.min.js +568 -1
  39. package/package.json +4 -4
  40. package/src/aggregation-layer.ts +1 -1
  41. package/src/contour-layer/contour-layer.ts +11 -4
  42. package/src/cpu-grid-layer/cpu-grid-layer.ts +4 -3
  43. package/src/gpu-grid-layer/gpu-grid-layer.ts +4 -3
  44. package/src/grid-aggregation-layer.ts +1 -1
  45. package/src/grid-layer/grid-layer.ts +1 -1
  46. package/src/heatmap-layer/heatmap-layer.ts +4 -3
  47. package/src/hexagon-layer/hexagon-layer.ts +1 -1
  48. package/src/screen-grid-layer/screen-grid-cell-layer.ts +1 -1
  49. package/src/screen-grid-layer/screen-grid-layer.ts +4 -3
  50. package/typed/aggregation-layer.d.ts +1 -1
  51. package/typed/aggregation-layer.d.ts.map +1 -1
  52. package/typed/aggregation-layer.js +151 -0
  53. package/typed/contour-layer/contour-layer.d.ts +1 -1
  54. package/typed/contour-layer/contour-layer.d.ts.map +1 -1
  55. package/typed/contour-layer/contour-layer.js +234 -0
  56. package/typed/contour-layer/contour-utils.js +64 -0
  57. package/typed/contour-layer/marching-squares-codes.js +337 -0
  58. package/typed/contour-layer/marching-squares.js +147 -0
  59. package/typed/cpu-grid-layer/cpu-grid-layer.d.ts +1 -1
  60. package/typed/cpu-grid-layer/cpu-grid-layer.d.ts.map +1 -1
  61. package/typed/cpu-grid-layer/cpu-grid-layer.js +129 -0
  62. package/typed/cpu-grid-layer/grid-aggregator.js +141 -0
  63. package/typed/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.js +34 -0
  64. package/typed/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.js +141 -0
  65. package/typed/gpu-grid-layer/gpu-grid-cell-layer.d.ts +2 -2
  66. package/typed/gpu-grid-layer/gpu-grid-cell-layer.js +143 -0
  67. package/typed/gpu-grid-layer/gpu-grid-layer.d.ts +1 -1
  68. package/typed/gpu-grid-layer/gpu-grid-layer.d.ts.map +1 -1
  69. package/typed/gpu-grid-layer/gpu-grid-layer.js +289 -0
  70. package/typed/grid-aggregation-layer.d.ts +1 -1
  71. package/typed/grid-aggregation-layer.d.ts.map +1 -1
  72. package/typed/grid-aggregation-layer.js +172 -0
  73. package/typed/grid-layer/grid-layer.d.ts +1 -1
  74. package/typed/grid-layer/grid-layer.d.ts.map +1 -1
  75. package/typed/grid-layer/grid-layer.js +60 -0
  76. package/typed/heatmap-layer/heatmap-layer-utils.js +78 -0
  77. package/typed/heatmap-layer/heatmap-layer.d.ts +1 -1
  78. package/typed/heatmap-layer/heatmap-layer.d.ts.map +1 -1
  79. package/typed/heatmap-layer/heatmap-layer.js +478 -0
  80. package/typed/heatmap-layer/max-fs.glsl.js +7 -0
  81. package/typed/heatmap-layer/max-vs.glsl.js +12 -0
  82. package/typed/heatmap-layer/triangle-layer-fragment.glsl.js +58 -0
  83. package/typed/heatmap-layer/triangle-layer-vertex.glsl.js +51 -0
  84. package/typed/heatmap-layer/triangle-layer.js +67 -0
  85. package/typed/heatmap-layer/weights-fs.glsl.js +19 -0
  86. package/typed/heatmap-layer/weights-vs.glsl.js +23 -0
  87. package/typed/hexagon-layer/hexagon-aggregator.js +112 -0
  88. package/typed/hexagon-layer/hexagon-layer.d.ts +1 -1
  89. package/typed/hexagon-layer/hexagon-layer.d.ts.map +1 -1
  90. package/typed/hexagon-layer/hexagon-layer.js +171 -0
  91. package/typed/index.js +33 -0
  92. package/typed/screen-grid-layer/screen-grid-cell-layer.d.ts +2 -2
  93. package/typed/screen-grid-layer/screen-grid-cell-layer.d.ts.map +1 -1
  94. package/typed/screen-grid-layer/screen-grid-cell-layer.js +159 -0
  95. package/typed/screen-grid-layer/screen-grid-layer-fragment.glsl.js +37 -0
  96. package/typed/screen-grid-layer/screen-grid-layer-vertex.glsl.js +83 -0
  97. package/typed/screen-grid-layer/screen-grid-layer.d.ts +1 -1
  98. package/typed/screen-grid-layer/screen-grid-layer.d.ts.map +1 -1
  99. package/typed/screen-grid-layer/screen-grid-layer.js +216 -0
  100. package/typed/types.js +1 -0
  101. package/typed/utils/aggregation-operation-utils.js +94 -0
  102. package/typed/utils/bin-sorter.js +167 -0
  103. package/typed/utils/color-utils.js +53 -0
  104. package/typed/utils/cpu-aggregator.js +417 -0
  105. package/typed/utils/gpu-grid-aggregation/aggregate-all-fs.glsl.js +39 -0
  106. package/typed/utils/gpu-grid-aggregation/aggregate-all-vs.glsl.js +53 -0
  107. package/typed/utils/gpu-grid-aggregation/aggregate-to-grid-fs.glsl.js +31 -0
  108. package/typed/utils/gpu-grid-aggregation/aggregate-to-grid-vs.glsl.js +77 -0
  109. package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator-constants.js +41 -0
  110. package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator-utils.js +1 -0
  111. package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator.js +562 -0
  112. package/typed/utils/gpu-grid-aggregation/transform-mean-vs.glsl.js +36 -0
  113. package/typed/utils/grid-aggregation-utils.d.ts +2 -2
  114. package/typed/utils/grid-aggregation-utils.d.ts.map +1 -1
  115. package/typed/utils/grid-aggregation-utils.js +114 -0
  116. package/typed/utils/prop-utils.js +28 -0
  117. package/typed/utils/resource-utils.js +40 -0
  118. package/typed/utils/scale-utils.js +184 -0
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@deck.gl/aggregation-layers",
3
3
  "description": "deck.gl layers that aggregate the input data into alternative representations",
4
4
  "license": "MIT",
5
- "version": "8.9.0-alpha.5",
5
+ "version": "8.9.0-beta.2",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
@@ -26,8 +26,8 @@
26
26
  ],
27
27
  "sideEffects": false,
28
28
  "scripts": {
29
- "build-bundle": "webpack --config ../../scripts/bundle.config.js",
30
- "prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env.dev"
29
+ "build-bundle": "ocular-bundle ./bundle.ts",
30
+ "prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env=dev"
31
31
  },
32
32
  "dependencies": {
33
33
  "@luma.gl/constants": "^8.5.16",
@@ -40,5 +40,5 @@
40
40
  "@deck.gl/layers": "^8.0.0",
41
41
  "@luma.gl/core": "^8.0.0"
42
42
  },
43
- "gitHead": "36330f8ca588055b11ed8032dc68ced641cb258b"
43
+ "gitHead": "5dae086e4f3eb46c30d8e761f9d600be4f68e949"
44
44
  }
@@ -31,7 +31,7 @@ import {filterProps} from './utils/prop-utils';
31
31
  export type AggregationLayerProps<DataT = any> = CompositeLayerProps<DataT>;
32
32
 
33
33
  export default abstract class AggregationLayer<
34
- ExtraPropsT = {}
34
+ ExtraPropsT extends {} = {}
35
35
  > extends CompositeLayer<ExtraPropsT> {
36
36
  static layerName = 'AggregationLayer';
37
37
 
@@ -50,7 +50,13 @@ const defaultProps: DefaultProps<ContourLayerProps> = {
50
50
  aggregation: 'SUM',
51
51
 
52
52
  // contour lines
53
- contours: [{threshold: DEFAULT_THRESHOLD}],
53
+ contours: {
54
+ type: 'object',
55
+ value: [{threshold: DEFAULT_THRESHOLD}],
56
+ optional: true,
57
+ compare: true,
58
+ depth: 2
59
+ },
54
60
 
55
61
  zOffset: 0.005
56
62
  };
@@ -139,9 +145,10 @@ export type _ContourLayerProps<DataT> = {
139
145
  };
140
146
 
141
147
  /** Aggregate data into iso-lines or iso-bands for a given threshold and cell size. */
142
- export default class ContourLayer<DataT = any, ExtraPropsT = {}> extends GridAggregationLayer<
143
- ExtraPropsT & Required<_ContourLayerProps<DataT>>
144
- > {
148
+ export default class ContourLayer<
149
+ DataT = any,
150
+ ExtraPropsT extends {} = {}
151
+ > extends GridAggregationLayer<ExtraPropsT & Required<_ContourLayerProps<DataT>>> {
145
152
  static layerName = 'ContourLayer';
146
153
  static defaultProps = defaultProps;
147
154
 
@@ -237,9 +237,10 @@ export type _CPUGridLayerProps<DataT> = {
237
237
  };
238
238
 
239
239
  /** Aggregate data into a grid-based heatmap. Aggregation is performed on CPU. */
240
- export default class CPUGridLayer<DataT = any, ExtraPropsT = {}> extends AggregationLayer<
241
- ExtraPropsT & Required<_CPUGridLayerProps<DataT>>
242
- > {
240
+ export default class CPUGridLayer<
241
+ DataT = any,
242
+ ExtraPropsT extends {} = {}
243
+ > extends AggregationLayer<ExtraPropsT & Required<_CPUGridLayerProps<DataT>>> {
243
244
  static layerName = 'CPUGridLayer';
244
245
  static defaultProps = defaultProps;
245
246
 
@@ -169,9 +169,10 @@ export type _GPUGridLayerProps<DataT> = {
169
169
  };
170
170
 
171
171
  /** Aggregate data into a grid-based heatmap. Aggregation is performed on GPU (WebGL2 only). */
172
- export default class GPUGridLayer<DataT = any, ExtraPropsT = {}> extends GridAggregationLayer<
173
- ExtraPropsT & Required<_GPUGridLayerProps<DataT>>
174
- > {
172
+ export default class GPUGridLayer<
173
+ DataT = any,
174
+ ExtraPropsT extends {} = {}
175
+ > extends GridAggregationLayer<ExtraPropsT & Required<_GPUGridLayerProps<DataT>>> {
175
176
  static layerName = 'GPUGridLayer';
176
177
  static defaultProps = defaultProps;
177
178
 
@@ -29,7 +29,7 @@ import {pointToDensityGridDataCPU} from './cpu-grid-layer/grid-aggregator';
29
29
  export type GridAggregationLayerProps<DataT = any> = AggregationLayerProps<DataT>;
30
30
 
31
31
  export default abstract class GridAggregationLayer<
32
- ExtraPropsT = {}
32
+ ExtraPropsT extends {} = {}
33
33
  > extends AggregationLayer<ExtraPropsT> {
34
34
  static layerName = 'GridAggregationLayer';
35
35
 
@@ -35,7 +35,7 @@ type _GridLayerProps<DataT> = _CPUGridLayerProps<DataT> &
35
35
  };
36
36
 
37
37
  /** Aggregate data into a grid-based heatmap. The color and height of a cell are determined based on the objects it contains. */
38
- export default class GridLayer<DataT = any, ExtraPropsT = {}> extends CompositeLayer<
38
+ export default class GridLayer<DataT = any, ExtraPropsT extends {} = {}> extends CompositeLayer<
39
39
  ExtraPropsT & Required<_GridLayerProps<DataT>>
40
40
  > {
41
41
  static layerName = 'GridLayer';
@@ -187,9 +187,10 @@ type _HeatmapLayerProps<DataT> = {
187
187
  };
188
188
 
189
189
  /** Visualizes the spatial distribution of data. */
190
- export default class HeatmapLayer<DataT = any, ExtraPropsT = {}> extends AggregationLayer<
191
- ExtraPropsT & Required<_HeatmapLayerProps<DataT>>
192
- > {
190
+ export default class HeatmapLayer<
191
+ DataT = any,
192
+ ExtraPropsT extends {} = {}
193
+ > extends AggregationLayer<ExtraPropsT & Required<_HeatmapLayerProps<DataT>>> {
193
194
  static layerName = 'HeatmapLayer';
194
195
  static defaultProps = defaultProps;
195
196
 
@@ -247,7 +247,7 @@ type _HexagonLayerProps<DataT = any> = {
247
247
  };
248
248
 
249
249
  /** Aggregates data into a hexagon-based heatmap. The color and height of a hexagon are determined based on the objects it contains. */
250
- export default class HexagonLayer<ExtraPropsT = {}> extends AggregationLayer<
250
+ export default class HexagonLayer<ExtraPropsT extends {} = {}> extends AggregationLayer<
251
251
  ExtraPropsT & Required<_HexagonLayerProps>
252
252
  > {
253
253
  static layerName = 'HexagonLayer';
@@ -47,7 +47,7 @@ export type _ScreenGridCellLayerProps<DataT> = _ScreenGridLayerProps<DataT> & {
47
47
  maxTexture: Texture2D;
48
48
  };
49
49
 
50
- export default class ScreenGridCellLayer<DataT = any, ExtraPropsT = {}> extends Layer<
50
+ export default class ScreenGridCellLayer<DataT = any, ExtraPropsT extends {} = {}> extends Layer<
51
51
  ExtraPropsT & Required<_ScreenGridCellLayerProps<DataT>>
52
52
  > {
53
53
  static layerName = 'ScreenGridCellLayer';
@@ -139,9 +139,10 @@ export type _ScreenGridLayerProps<DataT> = {
139
139
  };
140
140
 
141
141
  /** Aggregates data into histogram bins and renders them as a grid. */
142
- export default class ScreenGridLayer<DataT = any, ExtraProps = {}> extends GridAggregationLayer<
143
- ExtraProps & Required<_ScreenGridLayerProps<DataT>>
144
- > {
142
+ export default class ScreenGridLayer<
143
+ DataT = any,
144
+ ExtraProps extends {} = {}
145
+ > extends GridAggregationLayer<ExtraProps & Required<_ScreenGridLayerProps<DataT>>> {
145
146
  static layerName = 'ScreenGridLayer';
146
147
  static defaultProps = defaultProps;
147
148
 
@@ -1,6 +1,6 @@
1
1
  import { CompositeLayer, AttributeManager, UpdateParameters, CompositeLayerProps } from '@deck.gl/core/typed';
2
2
  export declare type AggregationLayerProps<DataT = any> = CompositeLayerProps<DataT>;
3
- export default abstract class AggregationLayer<ExtraPropsT = {}> extends CompositeLayer<ExtraPropsT> {
3
+ export default abstract class AggregationLayer<ExtraPropsT extends {} = {}> extends CompositeLayer<ExtraPropsT> {
4
4
  static layerName: string;
5
5
  state: CompositeLayer['state'] & {
6
6
  ignoreProps?: Record<string, any>;
@@ -1 +1 @@
1
- {"version":3,"file":"aggregation-layer.d.ts","sourceRoot":"","sources":["../src/aggregation-layer.ts"],"names":[],"mappings":"AAoBA,OAAO,EACL,cAAc,EACd,gBAAgB,EAEhB,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,eAAe,CAAC;AAIvB,oBAAY,qBAAqB,CAAC,KAAK,GAAG,GAAG,IAAI,mBAAmB,CAAC,KAAK,CAAC,CAAC;AAE5E,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,gBAAgB,CAC5C,WAAW,GAAG,EAAE,CAChB,SAAQ,cAAc,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C;KAClB,CAAC;IAEF,0BAA0B,CAAC,UAAU,EAAE,GAAG;IAU1C,WAAW,CAAC,IAAI,EAAE,gBAAgB,CAAC,IAAI,CAAC;IAexC,gBAAgB,CAAC,iBAAiB,KAAA;IAMlC,aAAa;;;IAIb,iBAAiB;IAcjB,aAAa,CAAC,OAAO,KAAA;IAIrB;;;;;;;QAOI;IACJ,kBAAkB,CAChB,UAAU,KAAA,EACV,MAAM,GAAE;QAAC,UAAU,CAAC,EAAE,OAAO,CAAC;QAAC,SAAS,CAAC,EAAE,GAAG,CAAA;KAAM,GACnD,MAAM,GAAG,OAAO;IAyCnB;;;;;QAKI;IACJ,kBAAkB,CAAC,IAAI,CAAC,EAAE,MAAM;IAYhC,oBAAoB;CAMrB"}
@@ -0,0 +1,151 @@
1
+ // Copyright (c) 2015 - 2017 Uber Technologies, Inc.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in
11
+ // all copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ // THE SOFTWARE.
20
+ import { CompositeLayer, AttributeManager, _compareProps as compareProps } from '@deck.gl/core';
21
+ import { cssToDeviceRatio } from '@luma.gl/core';
22
+ import { filterProps } from './utils/prop-utils';
23
+ export default class AggregationLayer extends CompositeLayer {
24
+ initializeAggregationLayer(dimensions) {
25
+ super.initializeState(this.context);
26
+ this.setState({
27
+ // Layer props , when changed doesn't require updating aggregation
28
+ ignoreProps: filterProps(this.constructor._propTypes, dimensions.data.props),
29
+ dimensions
30
+ });
31
+ }
32
+ updateState(opts) {
33
+ super.updateState(opts);
34
+ const { changeFlags } = opts;
35
+ if (changeFlags.extensionsChanged) {
36
+ const shaders = this.getShaders({});
37
+ if (shaders && shaders.defines) {
38
+ shaders.defines.NON_INSTANCED_MODEL = 1;
39
+ }
40
+ this.updateShaders(shaders);
41
+ }
42
+ // Explictly call to update attributes as 'CompositeLayer' doesn't call this
43
+ this._updateAttributes();
44
+ }
45
+ updateAttributes(changedAttributes) {
46
+ // Super classes, can refer to state.changedAttributes to determine what
47
+ // attributes changed
48
+ this.setState({ changedAttributes });
49
+ }
50
+ getAttributes() {
51
+ return this.getAttributeManager().getShaderAttributes();
52
+ }
53
+ getModuleSettings() {
54
+ // For regular layer draw this happens during draw cycle (_drawLayersInViewport) not during update cycle
55
+ // For aggregation layers this is called during updateState to update aggregation data
56
+ // NOTE: it is similar to LayerPass._getModuleParameters() but doesn't inlcude `effects` it is not needed for aggregation
57
+ const { viewport, mousePosition, gl } = this.context;
58
+ const moduleSettings = Object.assign(Object.create(this.props), {
59
+ viewport,
60
+ mousePosition,
61
+ pickingActive: 0,
62
+ devicePixelRatio: cssToDeviceRatio(gl)
63
+ });
64
+ return moduleSettings;
65
+ }
66
+ updateShaders(shaders) {
67
+ // Default implemention is empty, subclasses can update their Model objects if needed
68
+ }
69
+ /**
70
+ * Checks if aggregation is dirty
71
+ * @param {Object} updateOpts - object {props, oldProps, changeFlags}
72
+ * @param {Object} params - object {dimension, compareAll}
73
+ * @param {Object} params.dimension - {props, accessors} array of props and/or accessors
74
+ * @param {Boolean} params.compareAll - when `true` it will include non layer props for comparision
75
+ * @returns {Boolean} - returns true if dimensions' prop or accessor is changed
76
+ **/
77
+ isAggregationDirty(updateOpts, params = {}) {
78
+ const { props, oldProps, changeFlags } = updateOpts;
79
+ const { compareAll = false, dimension } = params;
80
+ const { ignoreProps } = this.state;
81
+ const { props: dataProps, accessors = [] } = dimension;
82
+ const { updateTriggersChanged } = changeFlags;
83
+ if (changeFlags.dataChanged) {
84
+ return true;
85
+ }
86
+ if (updateTriggersChanged) {
87
+ if (updateTriggersChanged.all) {
88
+ return true;
89
+ }
90
+ for (const accessor of accessors) {
91
+ if (updateTriggersChanged[accessor]) {
92
+ return true;
93
+ }
94
+ }
95
+ }
96
+ if (compareAll) {
97
+ if (changeFlags.extensionsChanged) {
98
+ return true;
99
+ }
100
+ // Compare non layer props too (like extension props)
101
+ // ignoreprops refers to all Layer props other than aggregation props that need to be comapred
102
+ return compareProps({
103
+ oldProps,
104
+ newProps: props,
105
+ ignoreProps,
106
+ propTypes: this.constructor._propTypes
107
+ });
108
+ }
109
+ // Compare props of the dimension
110
+ for (const name of dataProps) {
111
+ if (props[name] !== oldProps[name]) {
112
+ return true;
113
+ }
114
+ }
115
+ return false;
116
+ }
117
+ /**
118
+ * Checks if an attribute is changed
119
+ * @param {String} name - name of the attribute
120
+ * @returns {Boolean} - `true` if attribute `name` is changed, `false` otherwise,
121
+ * If `name` is not passed or `undefiend`, `true` if any attribute is changed, `false` otherwise
122
+ **/
123
+ isAttributeChanged(name) {
124
+ const { changedAttributes } = this.state;
125
+ if (!name) {
126
+ // if name not specified return true if any attribute is changed
127
+ return !isObjectEmpty(changedAttributes);
128
+ }
129
+ return changedAttributes && changedAttributes[name] !== undefined;
130
+ }
131
+ // Private
132
+ // override Composite layer private method to create AttributeManager instance
133
+ _getAttributeManager() {
134
+ return new AttributeManager(this.context.gl, {
135
+ id: this.props.id,
136
+ stats: this.context.stats
137
+ });
138
+ }
139
+ }
140
+ AggregationLayer.layerName = 'AggregationLayer';
141
+ // Helper methods
142
+ // Returns true if given object is empty, false otherwise.
143
+ function isObjectEmpty(obj) {
144
+ let isEmpty = true;
145
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
146
+ for (const key in obj) {
147
+ isEmpty = false;
148
+ break;
149
+ }
150
+ return isEmpty;
151
+ }
@@ -60,7 +60,7 @@ export declare type _ContourLayerProps<DataT> = {
60
60
  getWeight?: Accessor<DataT, number>;
61
61
  };
62
62
  /** Aggregate data into iso-lines or iso-bands for a given threshold and cell size. */
63
- export default class ContourLayer<DataT = any, ExtraPropsT = {}> extends GridAggregationLayer<ExtraPropsT & Required<_ContourLayerProps<DataT>>> {
63
+ export default class ContourLayer<DataT = any, ExtraPropsT extends {} = {}> extends GridAggregationLayer<ExtraPropsT & Required<_ContourLayerProps<DataT>>> {
64
64
  static layerName: string;
65
65
  static defaultProps: DefaultProps<ContourLayerProps<any>>;
66
66
  initializeState(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"contour-layer.d.ts","sourceRoot":"","sources":["../../src/contour-layer/contour-layer.ts"],"names":[],"mappings":"AAuBA,OAAO,EACL,QAAQ,EACR,gBAAgB,EAChB,KAAK,EACL,KAAK,EAEL,QAAQ,EACR,gBAAgB,EAChB,YAAY,EACb,MAAM,eAAe,CAAC;AAKvB,OAAO,oBAAoB,EAAE,EAAC,yBAAyB,EAAC,MAAM,2BAA2B,CAAC;AAgC1F,gDAAgD;AAChD,oBAAY,iBAAiB,CAAC,KAAK,GAAG,GAAG,IAAI,kBAAkB,CAAC,KAAK,CAAC,GACpE,yBAAyB,CAAC,KAAK,CAAC,CAAC;AAEnC,wCAAwC;AACxC,oBAAY,kBAAkB,CAAC,KAAK,IAAI;IACtC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;OAGG;IACH,WAAW,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,K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EnC,eAAe,IAAI,IAAI;IA2BvB,WAAW,CAAC,IAAI,EAAE,gBAAgB,CAAC,IAAI,CAAC,GAAG,IAAI;IAgB/C,YAAY,IAAI,KAAK,EAAE;IA4CvB,sBAAsB,CAAC,IAAI,KAAA;IAyE3B,OAAO,CAAC,gBAAgB;IAUxB,OAAO,CAAC,aAAa;IASrB,OAAO,CAAC,iBAAiB;IAsBzB,OAAO,CAAC,oBAAoB;CAc7B"}
@@ -0,0 +1,234 @@
1
+ // Copyright (c) 2015 - 2018 Uber Technologies, Inc.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in
11
+ // all copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ // THE SOFTWARE.
20
+ import GL from '@luma.gl/constants';
21
+ import { LineLayer, SolidPolygonLayer } from '@deck.gl/layers';
22
+ import { generateContours } from './contour-utils';
23
+ import { log } from '@deck.gl/core';
24
+ import GPUGridAggregator from '../utils/gpu-grid-aggregation/gpu-grid-aggregator';
25
+ import { AGGREGATION_OPERATION, getValueFunc } from '../utils/aggregation-operation-utils';
26
+ import { getBoundingBox, getGridParams } from '../utils/grid-aggregation-utils';
27
+ import GridAggregationLayer from '../grid-aggregation-layer';
28
+ const DEFAULT_COLOR = [255, 255, 255, 255];
29
+ const DEFAULT_STROKE_WIDTH = 1;
30
+ const DEFAULT_THRESHOLD = 1;
31
+ const defaultProps = {
32
+ // grid aggregation
33
+ cellSize: { type: 'number', min: 1, max: 1000, value: 1000 },
34
+ getPosition: { type: 'accessor', value: x => x.position },
35
+ getWeight: { type: 'accessor', value: 1 },
36
+ gpuAggregation: true,
37
+ aggregation: 'SUM',
38
+ // contour lines
39
+ contours: [{ threshold: DEFAULT_THRESHOLD }],
40
+ zOffset: 0.005
41
+ };
42
+ const POSITION_ATTRIBUTE_NAME = 'positions';
43
+ const DIMENSIONS = {
44
+ data: {
45
+ props: ['cellSize']
46
+ },
47
+ weights: {
48
+ props: ['aggregation'],
49
+ accessors: ['getWeight']
50
+ }
51
+ };
52
+ export default class ContourLayer extends GridAggregationLayer {
53
+ initializeState() {
54
+ super.initializeAggregationLayer({
55
+ dimensions: DIMENSIONS
56
+ });
57
+ this.setState({
58
+ contourData: {},
59
+ projectPoints: false,
60
+ weights: {
61
+ count: {
62
+ size: 1,
63
+ operation: AGGREGATION_OPERATION.SUM
64
+ }
65
+ }
66
+ });
67
+ const attributeManager = this.getAttributeManager();
68
+ attributeManager.add({
69
+ [POSITION_ATTRIBUTE_NAME]: {
70
+ size: 3,
71
+ accessor: 'getPosition',
72
+ type: GL.DOUBLE,
73
+ fp64: this.use64bitPositions()
74
+ },
75
+ // this attribute is used in gpu aggregation path only
76
+ count: { size: 3, accessor: 'getWeight' }
77
+ });
78
+ }
79
+ updateState(opts) {
80
+ super.updateState(opts);
81
+ let contoursChanged = false;
82
+ const { oldProps, props } = opts;
83
+ const { aggregationDirty } = this.state;
84
+ if (oldProps.contours !== props.contours || oldProps.zOffset !== props.zOffset) {
85
+ contoursChanged = true;
86
+ this._updateThresholdData(opts.props);
87
+ }
88
+ if (this.getNumInstances() > 0 && (aggregationDirty || contoursChanged)) {
89
+ this._generateContours();
90
+ }
91
+ }
92
+ renderLayers() {
93
+ const { contourSegments, contourPolygons } = this.state.contourData;
94
+ const LinesSubLayerClass = this.getSubLayerClass('lines', LineLayer);
95
+ const BandsSubLayerClass = this.getSubLayerClass('bands', SolidPolygonLayer);
96
+ // Contour lines layer
97
+ const lineLayer = contourSegments &&
98
+ contourSegments.length > 0 &&
99
+ new LinesSubLayerClass(this.getSubLayerProps({
100
+ id: 'lines'
101
+ }), {
102
+ data: this.state.contourData.contourSegments,
103
+ getSourcePosition: d => d.start,
104
+ getTargetPosition: d => d.end,
105
+ getColor: d => d.contour.color || DEFAULT_COLOR,
106
+ getWidth: d => d.contour.strokeWidth || DEFAULT_STROKE_WIDTH
107
+ });
108
+ // Contour bands layer
109
+ const bandsLayer = contourPolygons &&
110
+ contourPolygons.length > 0 &&
111
+ new BandsSubLayerClass(this.getSubLayerProps({
112
+ id: 'bands'
113
+ }), {
114
+ data: this.state.contourData.contourPolygons,
115
+ getPolygon: d => d.vertices,
116
+ getFillColor: d => d.contour.color || DEFAULT_COLOR
117
+ });
118
+ return [lineLayer, bandsLayer];
119
+ }
120
+ // Aggregation Overrides
121
+ /* eslint-disable max-statements, complexity */
122
+ updateAggregationState(opts) {
123
+ const { props, oldProps } = opts;
124
+ const { cellSize, coordinateSystem } = props;
125
+ const { viewport } = this.context;
126
+ const cellSizeChanged = oldProps.cellSize !== cellSize;
127
+ let gpuAggregation = props.gpuAggregation;
128
+ if (this.state.gpuAggregation !== props.gpuAggregation) {
129
+ if (gpuAggregation && !GPUGridAggregator.isSupported(this.context.gl)) {
130
+ log.warn('GPU Grid Aggregation not supported, falling back to CPU')();
131
+ gpuAggregation = false;
132
+ }
133
+ }
134
+ const gpuAggregationChanged = gpuAggregation !== this.state.gpuAggregation;
135
+ this.setState({
136
+ gpuAggregation
137
+ });
138
+ const { dimensions } = this.state;
139
+ const positionsChanged = this.isAttributeChanged(POSITION_ATTRIBUTE_NAME);
140
+ const { data, weights } = dimensions;
141
+ let { boundingBox } = this.state;
142
+ if (positionsChanged) {
143
+ boundingBox = getBoundingBox(this.getAttributes(), this.getNumInstances());
144
+ this.setState({ boundingBox });
145
+ }
146
+ if (positionsChanged || cellSizeChanged) {
147
+ const { gridOffset, translation, width, height, numCol, numRow } = getGridParams(boundingBox, cellSize, viewport, coordinateSystem);
148
+ this.allocateResources(numRow, numCol);
149
+ this.setState({
150
+ gridOffset,
151
+ boundingBox,
152
+ translation,
153
+ posOffset: translation.slice(),
154
+ gridOrigin: [-1 * translation[0], -1 * translation[1]],
155
+ width,
156
+ height,
157
+ numCol,
158
+ numRow
159
+ });
160
+ }
161
+ const aggregationDataDirty = positionsChanged ||
162
+ gpuAggregationChanged ||
163
+ this.isAggregationDirty(opts, {
164
+ dimension: data,
165
+ compareAll: gpuAggregation // check for all (including extentions props) when using gpu aggregation
166
+ });
167
+ const aggregationWeightsDirty = this.isAggregationDirty(opts, {
168
+ dimension: weights
169
+ });
170
+ if (aggregationWeightsDirty) {
171
+ this._updateAccessors(opts);
172
+ }
173
+ if (aggregationDataDirty || aggregationWeightsDirty) {
174
+ this._resetResults();
175
+ }
176
+ this.setState({
177
+ aggregationDataDirty,
178
+ aggregationWeightsDirty
179
+ });
180
+ }
181
+ /* eslint-enable max-statements, complexity */
182
+ // Private (Aggregation)
183
+ _updateAccessors(opts) {
184
+ const { getWeight, aggregation, data } = opts.props;
185
+ const { count } = this.state.weights;
186
+ if (count) {
187
+ count.getWeight = getWeight;
188
+ count.operation = AGGREGATION_OPERATION[aggregation];
189
+ }
190
+ this.setState({ getValue: getValueFunc(aggregation, getWeight, { data }) });
191
+ }
192
+ _resetResults() {
193
+ const { count } = this.state.weights;
194
+ if (count) {
195
+ count.aggregationData = null;
196
+ }
197
+ }
198
+ // Private (Contours)
199
+ _generateContours() {
200
+ const { numCol, numRow, gridOrigin, gridOffset, thresholdData } = this.state;
201
+ const { count } = this.state.weights;
202
+ let { aggregationData } = count;
203
+ if (!aggregationData) {
204
+ aggregationData = count.aggregationBuffer.getData();
205
+ count.aggregationData = aggregationData;
206
+ }
207
+ const { cellWeights } = GPUGridAggregator.getCellData({ countsData: aggregationData });
208
+ const contourData = generateContours({
209
+ thresholdData,
210
+ cellWeights,
211
+ gridSize: [numCol, numRow],
212
+ gridOrigin,
213
+ cellSize: [gridOffset.xOffset, gridOffset.yOffset]
214
+ });
215
+ // contourData contains both iso-lines and iso-bands if requested.
216
+ this.setState({ contourData });
217
+ }
218
+ _updateThresholdData(props) {
219
+ const { contours, zOffset } = props;
220
+ const count = contours.length;
221
+ const thresholdData = new Array(count);
222
+ for (let i = 0; i < count; i++) {
223
+ const contour = contours[i];
224
+ thresholdData[i] = {
225
+ contour,
226
+ zIndex: contour.zIndex || i,
227
+ zOffset
228
+ };
229
+ }
230
+ this.setState({ thresholdData });
231
+ }
232
+ }
233
+ ContourLayer.layerName = 'ContourLayer';
234
+ ContourLayer.defaultProps = defaultProps;
@@ -0,0 +1,64 @@
1
+ import { getCode, getVertices, CONTOUR_TYPE } from './marching-squares';
2
+ // Given all the cell weights, generates contours for each threshold.
3
+ /* eslint-disable max-depth */
4
+ export function generateContours({ thresholdData, cellWeights, gridSize, gridOrigin, cellSize }) {
5
+ const contourSegments = [];
6
+ const contourPolygons = [];
7
+ const width = gridSize[0];
8
+ const height = gridSize[1];
9
+ let segmentIndex = 0;
10
+ let polygonIndex = 0;
11
+ for (const data of thresholdData) {
12
+ const { contour } = data;
13
+ const { threshold } = contour;
14
+ for (let x = -1; x < width; x++) {
15
+ for (let y = -1; y < height; y++) {
16
+ // Get the MarchingSquares code based on neighbor cell weights.
17
+ const { code, meanCode } = getCode({
18
+ cellWeights,
19
+ threshold,
20
+ x,
21
+ y,
22
+ width,
23
+ height
24
+ });
25
+ const opts = {
26
+ type: CONTOUR_TYPE.ISO_BANDS,
27
+ gridOrigin,
28
+ cellSize,
29
+ x,
30
+ y,
31
+ width,
32
+ height,
33
+ code,
34
+ meanCode,
35
+ thresholdData: data
36
+ };
37
+ if (Array.isArray(threshold)) {
38
+ opts.type = CONTOUR_TYPE.ISO_BANDS;
39
+ const polygons = getVertices(opts);
40
+ for (const polygon of polygons) {
41
+ contourPolygons[polygonIndex++] = {
42
+ vertices: polygon,
43
+ contour
44
+ };
45
+ }
46
+ }
47
+ else {
48
+ // Get the intersection vertices based on MarchingSquares code.
49
+ opts.type = CONTOUR_TYPE.ISO_LINES;
50
+ const vertices = getVertices(opts);
51
+ for (let i = 0; i < vertices.length; i += 2) {
52
+ contourSegments[segmentIndex++] = {
53
+ start: vertices[i],
54
+ end: vertices[i + 1],
55
+ contour
56
+ };
57
+ }
58
+ }
59
+ }
60
+ }
61
+ }
62
+ return { contourSegments, contourPolygons };
63
+ }
64
+ /* eslint-enable max-depth */