@deck.gl/aggregation-layers 8.8.0-alpha.6 → 8.8.0-beta.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.
- package/dist/dist.dev.js +515 -407
- package/dist/es5/aggregation-layer.js +19 -7
- package/dist/es5/aggregation-layer.js.map +1 -1
- package/dist/es5/contour-layer/contour-layer.js +5 -5
- package/dist/es5/contour-layer/contour-layer.js.map +1 -1
- package/dist/es5/contour-layer/contour-utils.js +1 -1
- package/dist/es5/contour-layer/contour-utils.js.map +1 -1
- package/dist/es5/contour-layer/marching-squares-codes.js.map +1 -1
- package/dist/es5/contour-layer/marching-squares.js.map +1 -1
- package/dist/es5/cpu-grid-layer/cpu-grid-layer.js +5 -3
- package/dist/es5/cpu-grid-layer/cpu-grid-layer.js.map +1 -1
- package/dist/es5/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.js +1 -1
- package/dist/es5/gpu-grid-layer/gpu-grid-cell-layer.js +8 -12
- package/dist/es5/gpu-grid-layer/gpu-grid-cell-layer.js.map +1 -1
- package/dist/es5/gpu-grid-layer/gpu-grid-layer.js +12 -12
- package/dist/es5/gpu-grid-layer/gpu-grid-layer.js.map +1 -1
- package/dist/es5/grid-aggregation-layer.js +25 -12
- package/dist/es5/grid-aggregation-layer.js.map +1 -1
- package/dist/es5/grid-layer/grid-layer.js +18 -9
- package/dist/es5/grid-layer/grid-layer.js.map +1 -1
- package/dist/es5/heatmap-layer/heatmap-layer-utils.js.map +1 -1
- package/dist/es5/heatmap-layer/heatmap-layer.js +17 -6
- package/dist/es5/heatmap-layer/heatmap-layer.js.map +1 -1
- package/dist/es5/heatmap-layer/max-vs.glsl.js +1 -1
- package/dist/es5/heatmap-layer/triangle-layer-fragment.glsl.js +1 -1
- package/dist/es5/heatmap-layer/triangle-layer-vertex.glsl.js +1 -1
- package/dist/es5/heatmap-layer/triangle-layer.js +7 -7
- package/dist/es5/heatmap-layer/triangle-layer.js.map +1 -1
- package/dist/es5/heatmap-layer/weights-fs.glsl.js +1 -1
- package/dist/es5/heatmap-layer/weights-vs.glsl.js +1 -1
- package/dist/es5/hexagon-layer/hexagon-layer.js +16 -5
- package/dist/es5/hexagon-layer/hexagon-layer.js.map +1 -1
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/screen-grid-layer/screen-grid-cell-layer.js +26 -19
- package/dist/es5/screen-grid-layer/screen-grid-cell-layer.js.map +1 -1
- package/dist/es5/screen-grid-layer/screen-grid-layer-vertex.glsl.js +1 -1
- package/dist/es5/screen-grid-layer/screen-grid-layer.js +18 -8
- package/dist/es5/screen-grid-layer/screen-grid-layer.js.map +1 -1
- package/dist/es5/types.js +2 -0
- package/dist/es5/types.js.map +1 -0
- package/dist/es5/utils/bin-sorter.js +9 -0
- package/dist/es5/utils/bin-sorter.js.map +1 -1
- package/dist/es5/utils/color-utils.js.map +1 -1
- package/dist/esm/aggregation-layer.js +12 -5
- package/dist/esm/aggregation-layer.js.map +1 -1
- package/dist/esm/contour-layer/contour-layer.js +6 -3
- package/dist/esm/contour-layer/contour-layer.js.map +1 -1
- package/dist/esm/contour-layer/contour-utils.js +1 -1
- package/dist/esm/contour-layer/contour-utils.js.map +1 -1
- package/dist/esm/contour-layer/marching-squares-codes.js.map +1 -1
- package/dist/esm/contour-layer/marching-squares.js.map +1 -1
- package/dist/esm/cpu-grid-layer/cpu-grid-layer.js +6 -3
- package/dist/esm/cpu-grid-layer/cpu-grid-layer.js.map +1 -1
- package/dist/esm/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.js.map +1 -1
- package/dist/esm/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.js +1 -1
- package/dist/esm/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.js.map +1 -1
- package/dist/esm/gpu-grid-layer/gpu-grid-cell-layer.js +8 -10
- package/dist/esm/gpu-grid-layer/gpu-grid-cell-layer.js.map +1 -1
- package/dist/esm/gpu-grid-layer/gpu-grid-layer.js +11 -9
- package/dist/esm/gpu-grid-layer/gpu-grid-layer.js.map +1 -1
- package/dist/esm/grid-aggregation-layer.js +13 -5
- package/dist/esm/grid-aggregation-layer.js.map +1 -1
- package/dist/esm/grid-layer/grid-layer.js +15 -8
- package/dist/esm/grid-layer/grid-layer.js.map +1 -1
- package/dist/esm/heatmap-layer/heatmap-layer-utils.js.map +1 -1
- package/dist/esm/heatmap-layer/heatmap-layer.js +22 -13
- package/dist/esm/heatmap-layer/heatmap-layer.js.map +1 -1
- package/dist/esm/heatmap-layer/max-fs.glsl.js.map +1 -1
- package/dist/esm/heatmap-layer/max-vs.glsl.js +1 -1
- package/dist/esm/heatmap-layer/max-vs.glsl.js.map +1 -1
- package/dist/esm/heatmap-layer/triangle-layer-fragment.glsl.js +1 -1
- package/dist/esm/heatmap-layer/triangle-layer-fragment.glsl.js.map +1 -1
- package/dist/esm/heatmap-layer/triangle-layer-vertex.glsl.js +1 -1
- package/dist/esm/heatmap-layer/triangle-layer-vertex.glsl.js.map +1 -1
- package/dist/esm/heatmap-layer/triangle-layer.js +6 -5
- package/dist/esm/heatmap-layer/triangle-layer.js.map +1 -1
- package/dist/esm/heatmap-layer/weights-fs.glsl.js +1 -1
- package/dist/esm/heatmap-layer/weights-fs.glsl.js.map +1 -1
- package/dist/esm/heatmap-layer/weights-vs.glsl.js +1 -1
- package/dist/esm/heatmap-layer/weights-vs.glsl.js.map +1 -1
- package/dist/esm/hexagon-layer/hexagon-layer.js +11 -2
- package/dist/esm/hexagon-layer/hexagon-layer.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/screen-grid-layer/screen-grid-cell-layer.js +16 -10
- package/dist/esm/screen-grid-layer/screen-grid-cell-layer.js.map +1 -1
- package/dist/esm/screen-grid-layer/screen-grid-layer-fragment.glsl.js.map +1 -1
- package/dist/esm/screen-grid-layer/screen-grid-layer-vertex.glsl.js +1 -1
- package/dist/esm/screen-grid-layer/screen-grid-layer-vertex.glsl.js.map +1 -1
- package/dist/esm/screen-grid-layer/screen-grid-layer.js +15 -7
- package/dist/esm/screen-grid-layer/screen-grid-layer.js.map +1 -1
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils/bin-sorter.js +16 -0
- package/dist/esm/utils/bin-sorter.js.map +1 -1
- package/dist/esm/utils/color-utils.js.map +1 -1
- package/dist.min.js +1 -1
- package/package.json +7 -5
- package/src/{aggregation-layer.js → aggregation-layer.ts} +32 -15
- package/src/contour-layer/{contour-layer.js → contour-layer.ts} +97 -16
- package/src/contour-layer/{contour-utils.js → contour-utils.ts} +11 -5
- package/src/contour-layer/{marching-squares-codes.js → marching-squares-codes.ts} +0 -0
- package/src/contour-layer/{marching-squares.js → marching-squares.ts} +6 -6
- package/src/cpu-grid-layer/cpu-grid-layer.ts +324 -0
- package/src/gpu-grid-layer/{gpu-grid-cell-layer-fragment.glsl.js → gpu-grid-cell-layer-fragment.glsl.ts} +0 -0
- package/src/gpu-grid-layer/{gpu-grid-cell-layer-vertex.glsl.js → gpu-grid-cell-layer-vertex.glsl.ts} +0 -0
- package/src/gpu-grid-layer/{gpu-grid-cell-layer.js → gpu-grid-cell-layer.ts} +36 -19
- package/src/gpu-grid-layer/{gpu-grid-layer.js → gpu-grid-layer.ts} +125 -18
- package/src/{grid-aggregation-layer.js → grid-aggregation-layer.ts} +25 -13
- package/src/grid-layer/{grid-layer.js → grid-layer.ts} +45 -14
- package/src/heatmap-layer/{heatmap-layer-utils.js → heatmap-layer-utils.ts} +5 -5
- package/src/heatmap-layer/{heatmap-layer.js → heatmap-layer.ts} +141 -30
- package/src/heatmap-layer/{max-fs.glsl.js → max-fs.glsl.ts} +0 -0
- package/src/heatmap-layer/{max-vs.glsl.js → max-vs.glsl.ts} +0 -0
- package/src/heatmap-layer/{triangle-layer-fragment.glsl.js → triangle-layer-fragment.glsl.ts} +0 -0
- package/src/heatmap-layer/{triangle-layer-vertex.glsl.js → triangle-layer-vertex.glsl.ts} +0 -0
- package/src/heatmap-layer/{triangle-layer.js → triangle-layer.ts} +20 -10
- package/src/heatmap-layer/{weights-fs.glsl.js → weights-fs.glsl.ts} +0 -0
- package/src/heatmap-layer/{weights-vs.glsl.js → weights-vs.glsl.ts} +0 -0
- package/src/hexagon-layer/{hexagon-layer.js → hexagon-layer.ts} +194 -9
- package/src/index.ts +9 -0
- package/src/screen-grid-layer/{screen-grid-cell-layer.js → screen-grid-cell-layer.ts} +33 -15
- package/src/screen-grid-layer/{screen-grid-layer-fragment.glsl.js → screen-grid-layer-fragment.glsl.ts} +0 -0
- package/src/screen-grid-layer/{screen-grid-layer-vertex.glsl.js → screen-grid-layer-vertex.glsl.ts} +0 -0
- package/src/screen-grid-layer/{screen-grid-layer.js → screen-grid-layer.ts} +119 -16
- package/src/types.ts +10 -0
- package/src/utils/{bin-sorter.js → bin-sorter.ts} +26 -11
- package/src/utils/{color-utils.js → color-utils.ts} +1 -1
- package/typed/aggregation-layer.d.ts +16 -11
- package/typed/aggregation-layer.d.ts.map +1 -1
- package/typed/contour-layer/contour-layer.d.ts +71 -36
- package/typed/contour-layer/contour-layer.d.ts.map +1 -1
- package/typed/contour-layer/contour-utils.d.ts +8 -9
- package/typed/contour-layer/contour-utils.d.ts.map +1 -1
- package/typed/contour-layer/marching-squares-codes.d.ts +2 -2
- package/typed/contour-layer/marching-squares-codes.d.ts.map +1 -1
- package/typed/contour-layer/marching-squares.d.ts +6 -6
- package/typed/contour-layer/marching-squares.d.ts.map +1 -1
- package/typed/cpu-grid-layer/cpu-grid-layer.d.ts +147 -126
- package/typed/cpu-grid-layer/cpu-grid-layer.d.ts.map +1 -1
- package/typed/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.d.ts +1 -1
- package/typed/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.d.ts.map +1 -1
- package/typed/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.d.ts +1 -1
- package/typed/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.d.ts.map +1 -1
- package/typed/gpu-grid-layer/gpu-grid-cell-layer.d.ts +30 -81
- package/typed/gpu-grid-layer/gpu-grid-cell-layer.d.ts.map +1 -1
- package/typed/gpu-grid-layer/gpu-grid-layer.d.ts +93 -62
- package/typed/gpu-grid-layer/gpu-grid-layer.d.ts.map +1 -1
- package/typed/grid-aggregation-layer.d.ts +19 -6
- package/typed/grid-aggregation-layer.d.ts.map +1 -1
- package/typed/grid-layer/grid-layer.d.ts +29 -91
- package/typed/grid-layer/grid-layer.d.ts.map +1 -1
- package/typed/heatmap-layer/heatmap-layer-utils.d.ts +6 -6
- package/typed/heatmap-layer/heatmap-layer-utils.d.ts.map +1 -1
- package/typed/heatmap-layer/heatmap-layer.d.ts +102 -82
- package/typed/heatmap-layer/heatmap-layer.d.ts.map +1 -1
- package/typed/heatmap-layer/max-fs.glsl.d.ts +1 -1
- package/typed/heatmap-layer/max-fs.glsl.d.ts.map +1 -1
- package/typed/heatmap-layer/max-vs.glsl.d.ts +1 -1
- package/typed/heatmap-layer/max-vs.glsl.d.ts.map +1 -1
- package/typed/heatmap-layer/triangle-layer-fragment.glsl.d.ts +1 -1
- package/typed/heatmap-layer/triangle-layer-fragment.glsl.d.ts.map +1 -1
- package/typed/heatmap-layer/triangle-layer-vertex.glsl.d.ts +1 -1
- package/typed/heatmap-layer/triangle-layer-vertex.glsl.d.ts.map +1 -1
- package/typed/heatmap-layer/triangle-layer.d.ts +25 -8
- package/typed/heatmap-layer/triangle-layer.d.ts.map +1 -1
- package/typed/heatmap-layer/weights-fs.glsl.d.ts +1 -1
- package/typed/heatmap-layer/weights-fs.glsl.d.ts.map +1 -1
- package/typed/heatmap-layer/weights-vs.glsl.d.ts +1 -1
- package/typed/heatmap-layer/weights-vs.glsl.d.ts.map +1 -1
- package/typed/hexagon-layer/hexagon-layer.d.ts +160 -125
- package/typed/hexagon-layer/hexagon-layer.d.ts.map +1 -1
- package/typed/index.d.ts +7 -0
- package/typed/index.d.ts.map +1 -1
- package/typed/screen-grid-layer/screen-grid-cell-layer.d.ts +34 -25
- package/typed/screen-grid-layer/screen-grid-cell-layer.d.ts.map +1 -1
- package/typed/screen-grid-layer/screen-grid-layer-fragment.glsl.d.ts +1 -1
- package/typed/screen-grid-layer/screen-grid-layer-fragment.glsl.d.ts.map +1 -1
- package/typed/screen-grid-layer/screen-grid-layer-vertex.glsl.d.ts +1 -1
- package/typed/screen-grid-layer/screen-grid-layer-vertex.glsl.d.ts.map +1 -1
- package/typed/screen-grid-layer/screen-grid-layer.d.ts +91 -30
- package/typed/screen-grid-layer/screen-grid-layer.d.ts.map +1 -1
- package/typed/types.d.ts +11 -0
- package/typed/types.d.ts.map +1 -0
- package/typed/utils/bin-sorter.d.ts +27 -21
- package/typed/utils/bin-sorter.d.ts.map +1 -1
- package/typed/utils/color-utils.d.ts +2 -2
- package/typed/utils/color-utils.d.ts.map +1 -1
- package/src/cpu-grid-layer/cpu-grid-layer.js +0 -153
|
@@ -18,20 +18,31 @@
|
|
|
18
18
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
19
|
// THE SOFTWARE.
|
|
20
20
|
|
|
21
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
Accessor,
|
|
23
|
+
AccessorFunction,
|
|
24
|
+
Color,
|
|
25
|
+
log,
|
|
26
|
+
Position,
|
|
27
|
+
Material,
|
|
28
|
+
UpdateParameters,
|
|
29
|
+
DefaultProps
|
|
30
|
+
} from '@deck.gl/core';
|
|
22
31
|
import {ColumnLayer} from '@deck.gl/layers';
|
|
23
32
|
|
|
24
33
|
import {defaultColorRange} from '../utils/color-utils';
|
|
25
34
|
|
|
26
35
|
import {pointToHexbin} from './hexagon-aggregator';
|
|
27
36
|
import CPUAggregator from '../utils/cpu-aggregator';
|
|
28
|
-
import AggregationLayer from '../aggregation-layer';
|
|
37
|
+
import AggregationLayer, {AggregationLayerProps} from '../aggregation-layer';
|
|
29
38
|
|
|
30
39
|
import GL from '@luma.gl/constants';
|
|
40
|
+
import {AggregateAccessor} from '../types';
|
|
31
41
|
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
32
43
|
function nop() {}
|
|
33
44
|
|
|
34
|
-
const defaultProps = {
|
|
45
|
+
const defaultProps: DefaultProps<HexagonLayerProps> = {
|
|
35
46
|
// color
|
|
36
47
|
colorDomain: null,
|
|
37
48
|
colorRange: defaultColorRange,
|
|
@@ -67,7 +78,184 @@ const defaultProps = {
|
|
|
67
78
|
_filterData: {type: 'function', value: null, optional: true}
|
|
68
79
|
};
|
|
69
80
|
|
|
70
|
-
|
|
81
|
+
/** All properties supported by by HexagonLayer. */
|
|
82
|
+
export type HexagonLayerProps<DataT = any> = _HexagonLayerProps<DataT> &
|
|
83
|
+
AggregationLayerProps<DataT>;
|
|
84
|
+
|
|
85
|
+
/** Properties added by HexagonLayer. */
|
|
86
|
+
type _HexagonLayerProps<DataT = any> = {
|
|
87
|
+
/**
|
|
88
|
+
* Radius of hexagon bin in meters. The hexagons are pointy-topped (rather than flat-topped).
|
|
89
|
+
* @default 1000
|
|
90
|
+
*/
|
|
91
|
+
radius?: number;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Function to aggregate data into hexagonal bins.
|
|
95
|
+
* @default d3-hexbin
|
|
96
|
+
*/
|
|
97
|
+
hexagonAggregator?: (props: any, params: any) => any;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Color scale input domain.
|
|
101
|
+
* @default [min(colorWeight), max(colorWeight)]
|
|
102
|
+
*/
|
|
103
|
+
colorDomain?: [number, number] | null;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Specified as an array of colors [color1, color2, ...].
|
|
107
|
+
* @default `6-class YlOrRd` - [colorbrewer](http://colorbrewer2.org/#type=sequential&scheme=YlOrRd&n=6)
|
|
108
|
+
*/
|
|
109
|
+
colorRange?: Color[];
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Hexagon radius multiplier, clamped between 0 - 1.
|
|
113
|
+
* @default 1
|
|
114
|
+
*/
|
|
115
|
+
coverage?: number;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Elevation scale input domain. The elevation scale is a linear scale that maps number of counts to elevation.
|
|
119
|
+
* @default [0, max(elevationWeight)]
|
|
120
|
+
*/
|
|
121
|
+
elevationDomain?: [number, number] | null;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Elevation scale output range.
|
|
125
|
+
* @default [0, 1000]
|
|
126
|
+
*/
|
|
127
|
+
elevationRange?: [number, number];
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Hexagon elevation multiplier.
|
|
131
|
+
* @default 1
|
|
132
|
+
*/
|
|
133
|
+
elevationScale?: number;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Whether to enable cell elevation. If set to false, all cell will be flat.
|
|
137
|
+
* @default false
|
|
138
|
+
*/
|
|
139
|
+
extruded?: boolean;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Filter bins and re-calculate color by `upperPercentile`.
|
|
143
|
+
* Hexagons with color value larger than the `upperPercentile` will be hidden.
|
|
144
|
+
* @default 100
|
|
145
|
+
*/
|
|
146
|
+
upperPercentile?: number;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Filter bins and re-calculate color by `lowerPercentile`.
|
|
150
|
+
* Hexagons with color value smaller than the `lowerPercentile` will be hidden.
|
|
151
|
+
* @default 0
|
|
152
|
+
*/
|
|
153
|
+
lowerPercentile?: number;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Filter bins and re-calculate elevation by `elevationUpperPercentile`.
|
|
157
|
+
* Hexagons with elevation value larger than the `elevationUpperPercentile` will be hidden.
|
|
158
|
+
* @default 100
|
|
159
|
+
*/
|
|
160
|
+
elevationUpperPercentile?: number;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Filter bins and re-calculate elevation by `elevationLowerPercentile`.
|
|
164
|
+
* Hexagons with elevation value larger than the `elevationLowerPercentile` will be hidden.
|
|
165
|
+
* @default 0
|
|
166
|
+
*/
|
|
167
|
+
elevationLowerPercentile?: number;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Scaling function used to determine the color of the grid cell, default value is 'quantize'.
|
|
171
|
+
* Supported Values are 'quantize', 'quantile' and 'ordinal'.
|
|
172
|
+
* @default 'quantize'
|
|
173
|
+
*/
|
|
174
|
+
colorScaleType?: 'quantize' | 'quantile' | 'ordinal';
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Scaling function used to determine the elevation of the grid cell, only supports 'linear'.
|
|
178
|
+
*/
|
|
179
|
+
elevationScaleType?: 'linear';
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Material settings for lighting effect. Applies if `extruded: true`.
|
|
183
|
+
*
|
|
184
|
+
* @default true
|
|
185
|
+
* @see https://deck.gl/docs/developer-guide/using-lighting
|
|
186
|
+
*/
|
|
187
|
+
material?: Material;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Defines the operation used to aggregate all data object weights to calculate a cell's color value.
|
|
191
|
+
* @default 'SUM'
|
|
192
|
+
*/
|
|
193
|
+
colorAggregation?: 'SUM' | 'MEAN' | 'MIN' | 'MAX';
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Defines the operation used to aggregate all data object weights to calculate a cell's elevation value.
|
|
197
|
+
* @default 'SUM'
|
|
198
|
+
*/
|
|
199
|
+
elevationAggregation?: 'SUM' | 'MEAN' | 'MIN' | 'MAX';
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Method called to retrieve the position of each object.
|
|
203
|
+
* @default object => object.position
|
|
204
|
+
*/
|
|
205
|
+
getPosition?: AccessorFunction<DataT, Position>;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* The weight of a data object used to calculate the color value for a bin.
|
|
209
|
+
* @default 1
|
|
210
|
+
*/
|
|
211
|
+
getColorWeight?: Accessor<DataT, number>;
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* After data objects are aggregated into bins, this accessor is called on each cell to get the value that its color is based on.
|
|
215
|
+
* @default null
|
|
216
|
+
*/
|
|
217
|
+
getColorValue?: AggregateAccessor<DataT> | null;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* The weight of a data object used to calculate the elevation value for a bin.
|
|
221
|
+
* @default 1
|
|
222
|
+
*/
|
|
223
|
+
getElevationWeight?: Accessor<DataT, number>;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* After data objects are aggregated into bins, this accessor is called on each cell to get the value that its elevation is based on.
|
|
227
|
+
* @default null
|
|
228
|
+
*/
|
|
229
|
+
getElevationValue?: AggregateAccessor<DataT> | null;
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* This callback will be called when cell color domain has been calculated.
|
|
233
|
+
* @default () => {}
|
|
234
|
+
*/
|
|
235
|
+
onSetColorDomain?: (minMax: [number, number]) => void;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* This callback will be called when cell elevation domain has been calculated.
|
|
239
|
+
* @default () => {}
|
|
240
|
+
*/
|
|
241
|
+
onSetElevationDomain?: (minMax: [number, number]) => void;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* (Experimental) Filter data objects
|
|
245
|
+
*/
|
|
246
|
+
_filterData: null | ((d: DataT) => boolean);
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
export default class HexagonLayer<ExtraPropsT = {}> extends AggregationLayer<
|
|
250
|
+
ExtraPropsT & Required<_HexagonLayerProps>
|
|
251
|
+
> {
|
|
252
|
+
static layerName = 'HexagonLayer';
|
|
253
|
+
static defaultProps = defaultProps;
|
|
254
|
+
|
|
255
|
+
state!: AggregationLayer['state'] & {
|
|
256
|
+
cpuAggregator: CPUAggregator;
|
|
257
|
+
aggregatorState: any;
|
|
258
|
+
};
|
|
71
259
|
initializeState() {
|
|
72
260
|
const cpuAggregator = new CPUAggregator({
|
|
73
261
|
getAggregator: props => props.hexagonAggregator,
|
|
@@ -79,7 +267,7 @@ export default class HexagonLayer extends AggregationLayer {
|
|
|
79
267
|
aggregatorState: cpuAggregator.state,
|
|
80
268
|
vertices: null
|
|
81
269
|
};
|
|
82
|
-
const attributeManager = this.getAttributeManager()
|
|
270
|
+
const attributeManager = this.getAttributeManager()!;
|
|
83
271
|
attributeManager.add({
|
|
84
272
|
positions: {size: 3, type: GL.DOUBLE, accessor: 'getPosition'}
|
|
85
273
|
});
|
|
@@ -87,7 +275,7 @@ export default class HexagonLayer extends AggregationLayer {
|
|
|
87
275
|
// they are calculated using 'getValue' accessor that takes an array of pints.
|
|
88
276
|
}
|
|
89
277
|
|
|
90
|
-
updateState(opts) {
|
|
278
|
+
updateState(opts: UpdateParameters<this>) {
|
|
91
279
|
super.updateState(opts);
|
|
92
280
|
|
|
93
281
|
if (opts.changeFlags.propsOrDataChanged) {
|
|
@@ -199,6 +387,3 @@ export default class HexagonLayer extends AggregationLayer {
|
|
|
199
387
|
);
|
|
200
388
|
}
|
|
201
389
|
}
|
|
202
|
-
|
|
203
|
-
HexagonLayer.layerName = 'HexagonLayer';
|
|
204
|
-
HexagonLayer.defaultProps = defaultProps;
|
package/src/index.ts
CHANGED
|
@@ -33,3 +33,12 @@ export {default as _GPUGridAggregator} from './utils/gpu-grid-aggregation/gpu-gr
|
|
|
33
33
|
export {default as _CPUAggregator} from './utils/cpu-aggregator';
|
|
34
34
|
export {default as _AggregationLayer} from './aggregation-layer';
|
|
35
35
|
export {default as _BinSorter} from './utils/bin-sorter';
|
|
36
|
+
|
|
37
|
+
// types
|
|
38
|
+
export type {ContourLayerProps} from './contour-layer/contour-layer';
|
|
39
|
+
export type {HeatmapLayerProps} from './heatmap-layer/heatmap-layer';
|
|
40
|
+
export type {HexagonLayerProps} from './hexagon-layer/hexagon-layer';
|
|
41
|
+
export type {CPUGridLayerProps} from './cpu-grid-layer/cpu-grid-layer';
|
|
42
|
+
export type {GridLayerProps} from './grid-layer/grid-layer';
|
|
43
|
+
export type {GPUGridLayerProps} from './gpu-grid-layer/gpu-grid-layer';
|
|
44
|
+
export type {ScreenGridLayerProps} from './screen-grid-layer/screen-grid-layer';
|
|
@@ -19,17 +19,18 @@
|
|
|
19
19
|
// THE SOFTWARE.
|
|
20
20
|
|
|
21
21
|
import GL from '@luma.gl/constants';
|
|
22
|
-
import {Model, Geometry, FEATURES, hasFeatures} from '@luma.gl/core';
|
|
23
|
-
import {Layer, log, picking} from '@deck.gl/core';
|
|
22
|
+
import {Model, Geometry, FEATURES, hasFeatures, Texture2D, DefaultProps} from '@luma.gl/core';
|
|
23
|
+
import {Layer, LayerProps, log, picking, UpdateParameters} from '@deck.gl/core';
|
|
24
24
|
import {defaultColorRange, colorRangeToFlatArray} from '../utils/color-utils';
|
|
25
25
|
import vs from './screen-grid-layer-vertex.glsl';
|
|
26
26
|
import fs from './screen-grid-layer-fragment.glsl';
|
|
27
|
+
import type {_ScreenGridLayerProps} from './screen-grid-layer';
|
|
27
28
|
|
|
28
29
|
const DEFAULT_MINCOLOR = [0, 0, 0, 0];
|
|
29
30
|
const DEFAULT_MAXCOLOR = [0, 255, 0, 255];
|
|
30
|
-
const COLOR_PROPS = [
|
|
31
|
+
const COLOR_PROPS = ['minColor', 'maxColor', 'colorRange', 'colorDomain'];
|
|
31
32
|
|
|
32
|
-
const defaultProps = {
|
|
33
|
+
const defaultProps: DefaultProps<ScreenGridCellLayerProps> = {
|
|
33
34
|
cellSizePixels: {value: 100, min: 1},
|
|
34
35
|
cellMarginPixels: {value: 2, min: 0, max: 5},
|
|
35
36
|
|
|
@@ -37,19 +38,37 @@ const defaultProps = {
|
|
|
37
38
|
colorRange: defaultColorRange
|
|
38
39
|
};
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
/** All properties supported by ScreenGridCellLayer. */
|
|
42
|
+
export type ScreenGridCellLayerProps<DataT = any> = _ScreenGridCellLayerProps<DataT> &
|
|
43
|
+
LayerProps<DataT>;
|
|
44
|
+
|
|
45
|
+
/** Proprties added by ScreenGridCellLayer. */
|
|
46
|
+
export type _ScreenGridCellLayerProps<DataT> = _ScreenGridLayerProps<DataT> & {
|
|
47
|
+
maxTexture: Texture2D;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default class ScreenGridCellLayer<DataT = any, ExtraPropsT = {}> extends Layer<
|
|
51
|
+
ExtraPropsT & Required<_ScreenGridCellLayerProps<DataT>>
|
|
52
|
+
> {
|
|
53
|
+
static layerName = 'ScreenGridCellLayer';
|
|
54
|
+
static defaultProps = defaultProps;
|
|
55
|
+
|
|
41
56
|
static isSupported(gl) {
|
|
42
57
|
return hasFeatures(gl, [FEATURES.TEXTURE_FLOAT]);
|
|
43
58
|
}
|
|
44
59
|
|
|
60
|
+
state!: Layer['state'] & {
|
|
61
|
+
model: Model;
|
|
62
|
+
};
|
|
45
63
|
getShaders() {
|
|
46
64
|
return {vs, fs, modules: [picking]};
|
|
47
65
|
}
|
|
48
66
|
|
|
49
67
|
initializeState() {
|
|
50
68
|
const {gl} = this.context;
|
|
51
|
-
const attributeManager = this.getAttributeManager()
|
|
69
|
+
const attributeManager = this.getAttributeManager()!;
|
|
52
70
|
attributeManager.addInstanced({
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
53
72
|
instancePositions: {size: 3, update: this.calculateInstancePositions},
|
|
54
73
|
instanceCounts: {size: 4, noAlloc: true}
|
|
55
74
|
});
|
|
@@ -63,10 +82,12 @@ export default class ScreenGridCellLayer extends Layer {
|
|
|
63
82
|
return changeFlags.somethingChanged;
|
|
64
83
|
}
|
|
65
84
|
|
|
66
|
-
updateState(
|
|
67
|
-
super.updateState(
|
|
85
|
+
updateState(params: UpdateParameters<this>) {
|
|
86
|
+
super.updateState(params);
|
|
87
|
+
|
|
88
|
+
const {oldProps, props, changeFlags} = params;
|
|
68
89
|
|
|
69
|
-
const attributeManager = this.getAttributeManager()
|
|
90
|
+
const attributeManager = this.getAttributeManager()!;
|
|
70
91
|
if (props.numInstances !== oldProps.numInstances) {
|
|
71
92
|
attributeManager.invalidateAll();
|
|
72
93
|
} else if (oldProps.cellSizePixels !== props.cellSizePixels) {
|
|
@@ -120,7 +141,7 @@ export default class ScreenGridCellLayer extends Layer {
|
|
|
120
141
|
|
|
121
142
|
// Private Methods
|
|
122
143
|
|
|
123
|
-
_getModel(gl) {
|
|
144
|
+
_getModel(gl: WebGLRenderingContext): Model {
|
|
124
145
|
return new Model(gl, {
|
|
125
146
|
...this.getShaders(),
|
|
126
147
|
id: this.props.id,
|
|
@@ -134,7 +155,7 @@ export default class ScreenGridCellLayer extends Layer {
|
|
|
134
155
|
});
|
|
135
156
|
}
|
|
136
157
|
|
|
137
|
-
_shouldUseMinMax() {
|
|
158
|
+
_shouldUseMinMax(): boolean {
|
|
138
159
|
const {minColor, maxColor, colorDomain, colorRange} = this.props;
|
|
139
160
|
if (minColor || maxColor) {
|
|
140
161
|
log.deprecated('ScreenGridLayer props: minColor and maxColor', 'colorRange, colorDomain')();
|
|
@@ -149,7 +170,7 @@ export default class ScreenGridCellLayer extends Layer {
|
|
|
149
170
|
return true;
|
|
150
171
|
}
|
|
151
172
|
|
|
152
|
-
_updateUniforms(oldProps, props, changeFlags) {
|
|
173
|
+
_updateUniforms(oldProps, props, changeFlags): void {
|
|
153
174
|
const {model} = this.state;
|
|
154
175
|
if (COLOR_PROPS.some(key => oldProps[key] !== props[key])) {
|
|
155
176
|
model.setUniforms({shouldUseMinMax: this._shouldUseMinMax()});
|
|
@@ -177,6 +198,3 @@ export default class ScreenGridCellLayer extends Layer {
|
|
|
177
198
|
}
|
|
178
199
|
}
|
|
179
200
|
}
|
|
180
|
-
|
|
181
|
-
ScreenGridCellLayer.layerName = 'ScreenGridCellLayer';
|
|
182
|
-
ScreenGridCellLayer.defaultProps = defaultProps;
|
|
File without changes
|
package/src/screen-grid-layer/{screen-grid-layer-vertex.glsl.js → screen-grid-layer-vertex.glsl.ts}
RENAMED
|
File without changes
|
|
@@ -18,15 +18,28 @@
|
|
|
18
18
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
19
|
// THE SOFTWARE.
|
|
20
20
|
|
|
21
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
Accessor,
|
|
23
|
+
Color,
|
|
24
|
+
GetPickingInfoParams,
|
|
25
|
+
Layer,
|
|
26
|
+
LayerContext,
|
|
27
|
+
LayersList,
|
|
28
|
+
log,
|
|
29
|
+
PickingInfo,
|
|
30
|
+
Position,
|
|
31
|
+
UpdateParameters,
|
|
32
|
+
DefaultProps
|
|
33
|
+
} from '@deck.gl/core';
|
|
22
34
|
import GL from '@luma.gl/constants';
|
|
35
|
+
import type {Texture2D} from '@luma.gl/core';
|
|
23
36
|
import GPUGridAggregator from '../utils/gpu-grid-aggregation/gpu-grid-aggregator';
|
|
24
37
|
import {AGGREGATION_OPERATION, getValueFunc} from '../utils/aggregation-operation-utils';
|
|
25
38
|
import ScreenGridCellLayer from './screen-grid-cell-layer';
|
|
26
|
-
import GridAggregationLayer from '../grid-aggregation-layer';
|
|
39
|
+
import GridAggregationLayer, {GridAggregationLayerProps} from '../grid-aggregation-layer';
|
|
27
40
|
import {getFloatTexture} from '../utils/resource-utils.js';
|
|
28
41
|
|
|
29
|
-
const defaultProps = {
|
|
42
|
+
const defaultProps: DefaultProps<ScreenGridLayerProps> = {
|
|
30
43
|
...ScreenGridCellLayer.defaultProps,
|
|
31
44
|
getPosition: {type: 'accessor', value: d => d.position},
|
|
32
45
|
getWeight: {type: 'accessor', value: 1},
|
|
@@ -46,7 +59,99 @@ const DIMENSIONS = {
|
|
|
46
59
|
}
|
|
47
60
|
};
|
|
48
61
|
|
|
49
|
-
|
|
62
|
+
/** All properties supported by ScreenGridLayer. */
|
|
63
|
+
export type ScreenGridLayerProps<DataT = any> = _ScreenGridLayerProps<DataT> &
|
|
64
|
+
GridAggregationLayerProps<DataT>;
|
|
65
|
+
|
|
66
|
+
/** Properties added by ScreenGridLayer. */
|
|
67
|
+
export type _ScreenGridLayerProps<DataT> = {
|
|
68
|
+
/**
|
|
69
|
+
* Unit width/height of the bins.
|
|
70
|
+
* @default 100
|
|
71
|
+
*/
|
|
72
|
+
cellSizePixels?: number;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Cell margin size in pixels.
|
|
76
|
+
* @default 2
|
|
77
|
+
*/
|
|
78
|
+
cellMarginPixels?: number;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Expressed as an rgba array, minimal color that could be rendered by a tile.
|
|
82
|
+
* @default [0, 0, 0, 255]
|
|
83
|
+
* @deprecated Deprecated in version 5.2.0, use `colorRange` and `colorDomain` instead.
|
|
84
|
+
*/
|
|
85
|
+
minColor?: Color | null;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Expressed as an rgba array, maximal color that could be rendered by a tile.
|
|
89
|
+
* @default [0, 255, 0, 255]
|
|
90
|
+
* @deprecated Deprecated in version 5.2.0, use `colorRange` and `colorDomain` instead.
|
|
91
|
+
*/
|
|
92
|
+
maxColor?: Color | null;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Color scale input domain. The color scale maps continues numeric domain into discrete color range.
|
|
96
|
+
* @default [1, max(weight)]
|
|
97
|
+
*/
|
|
98
|
+
colorDomain?: [number, number] | null;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Specified as an array of colors [color1, color2, ...].
|
|
102
|
+
*
|
|
103
|
+
* @default `6-class YlOrRd` - [colorbrewer](http://colorbrewer2.org/#type=sequential&scheme=YlOrRd&n=6)
|
|
104
|
+
*/
|
|
105
|
+
colorRange?: Color[];
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Method called to retrieve the position of each object.
|
|
109
|
+
*
|
|
110
|
+
* @default d => d.position
|
|
111
|
+
*/
|
|
112
|
+
getPosition?: Accessor<DataT, Position>;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* The weight of each object.
|
|
116
|
+
*
|
|
117
|
+
* @default 1
|
|
118
|
+
*/
|
|
119
|
+
getWeight?: Accessor<DataT, number>;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Perform aggregation is performed on GPU.
|
|
123
|
+
*
|
|
124
|
+
* NOTE: GPU Aggregation requires WebGL2 support by the browser.
|
|
125
|
+
* When `gpuAggregation` is set to true and browser doesn't support WebGL2, aggregation falls back to CPU.
|
|
126
|
+
*
|
|
127
|
+
* @default true
|
|
128
|
+
*/
|
|
129
|
+
gpuAggregation?: boolean;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Defines the type of aggregation operation
|
|
133
|
+
*
|
|
134
|
+
* V valid values are 'SUM', 'MEAN', 'MIN' and 'MAX'.
|
|
135
|
+
*
|
|
136
|
+
* @default 'SUM'
|
|
137
|
+
*/
|
|
138
|
+
aggregation?: 'SUM' | 'MEAN' | 'MIN' | 'MAX';
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export default class ScreenGridLayer<DataT = any, ExtraProps = {}> extends GridAggregationLayer<
|
|
142
|
+
ExtraProps & Required<_ScreenGridLayerProps<DataT>>
|
|
143
|
+
> {
|
|
144
|
+
static layerName = 'ScreenGridLayer';
|
|
145
|
+
static defaultProps = defaultProps;
|
|
146
|
+
|
|
147
|
+
state!: GridAggregationLayer['state'] & {
|
|
148
|
+
supported: boolean;
|
|
149
|
+
gpuGridAggregator?: any;
|
|
150
|
+
gpuAggregation?: any;
|
|
151
|
+
weights?: any;
|
|
152
|
+
maxTexture?: Texture2D;
|
|
153
|
+
};
|
|
154
|
+
|
|
50
155
|
initializeState() {
|
|
51
156
|
const {gl} = this.context;
|
|
52
157
|
if (!ScreenGridCellLayer.isSupported(gl)) {
|
|
@@ -55,9 +160,10 @@ export default class ScreenGridLayer extends GridAggregationLayer {
|
|
|
55
160
|
log.error(`ScreenGridLayer: ${this.id} is not supported on this browser`)();
|
|
56
161
|
return;
|
|
57
162
|
}
|
|
58
|
-
super.
|
|
163
|
+
super.initializeAggregationLayer({
|
|
59
164
|
dimensions: DIMENSIONS,
|
|
60
|
-
|
|
165
|
+
// @ts-expect-error
|
|
166
|
+
getCellSize: props => props.cellSizePixels // TODO
|
|
61
167
|
});
|
|
62
168
|
const weights = {
|
|
63
169
|
count: {
|
|
@@ -77,7 +183,7 @@ export default class ScreenGridLayer extends GridAggregationLayer {
|
|
|
77
183
|
posOffset: [0, 0],
|
|
78
184
|
translation: [1, -1]
|
|
79
185
|
});
|
|
80
|
-
const attributeManager = this.getAttributeManager()
|
|
186
|
+
const attributeManager = this.getAttributeManager()!;
|
|
81
187
|
attributeManager.add({
|
|
82
188
|
[POSITION_ATTRIBUTE_NAME]: {
|
|
83
189
|
size: 3,
|
|
@@ -90,15 +196,15 @@ export default class ScreenGridLayer extends GridAggregationLayer {
|
|
|
90
196
|
});
|
|
91
197
|
}
|
|
92
198
|
|
|
93
|
-
shouldUpdateState({changeFlags}) {
|
|
199
|
+
shouldUpdateState({changeFlags}: UpdateParameters<this>) {
|
|
94
200
|
return this.state.supported && changeFlags.somethingChanged;
|
|
95
201
|
}
|
|
96
202
|
|
|
97
|
-
updateState(opts) {
|
|
203
|
+
updateState(opts: UpdateParameters<this>) {
|
|
98
204
|
super.updateState(opts);
|
|
99
205
|
}
|
|
100
206
|
|
|
101
|
-
renderLayers() {
|
|
207
|
+
renderLayers(): LayersList | Layer {
|
|
102
208
|
if (!this.state.supported) {
|
|
103
209
|
return [];
|
|
104
210
|
}
|
|
@@ -121,8 +227,8 @@ export default class ScreenGridLayer extends GridAggregationLayer {
|
|
|
121
227
|
);
|
|
122
228
|
}
|
|
123
229
|
|
|
124
|
-
finalizeState() {
|
|
125
|
-
super.finalizeState();
|
|
230
|
+
finalizeState(context: LayerContext): void {
|
|
231
|
+
super.finalizeState(context);
|
|
126
232
|
|
|
127
233
|
const {aggregationBuffer, maxBuffer, maxTexture} = this.state;
|
|
128
234
|
|
|
@@ -131,7 +237,7 @@ export default class ScreenGridLayer extends GridAggregationLayer {
|
|
|
131
237
|
maxTexture?.delete();
|
|
132
238
|
}
|
|
133
239
|
|
|
134
|
-
getPickingInfo({info
|
|
240
|
+
getPickingInfo({info}: GetPickingInfoParams): PickingInfo {
|
|
135
241
|
const {index} = info;
|
|
136
242
|
if (index >= 0) {
|
|
137
243
|
const {gpuGridAggregator, gpuAggregation, weights} = this.state;
|
|
@@ -244,6 +350,3 @@ export default class ScreenGridLayer extends GridAggregationLayer {
|
|
|
244
350
|
}
|
|
245
351
|
}
|
|
246
352
|
}
|
|
247
|
-
|
|
248
|
-
ScreenGridLayer.layerName = 'ScreenGridLayer';
|
|
249
|
-
ScreenGridLayer.defaultProps = defaultProps;
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type AggregateAccessor<DataT = any> = {
|
|
2
|
+
/** a list of objects whose positions fall inside this cell. */
|
|
3
|
+
objects: DataT[];
|
|
4
|
+
objectInfo: {
|
|
5
|
+
/** the indices of `objects` in the original data. */
|
|
6
|
+
indices: number[];
|
|
7
|
+
/** the value of the `data` prop */
|
|
8
|
+
data: any;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -43,8 +43,23 @@ const defaultProps = {
|
|
|
43
43
|
filterData: null
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
+
export type AggregatedBin = {
|
|
47
|
+
i: number;
|
|
48
|
+
value: any;
|
|
49
|
+
counts: number;
|
|
50
|
+
};
|
|
51
|
+
|
|
46
52
|
export default class BinSorter {
|
|
47
|
-
|
|
53
|
+
maxCount!: number;
|
|
54
|
+
maxValue!: number;
|
|
55
|
+
minValue!: number;
|
|
56
|
+
totalCount!: number;
|
|
57
|
+
|
|
58
|
+
aggregatedBins: AggregatedBin[];
|
|
59
|
+
sortedBins!: AggregatedBin[];
|
|
60
|
+
binMap: Record<number, AggregatedBin>;
|
|
61
|
+
|
|
62
|
+
constructor(bins = [], props: Partial<typeof defaultProps> = defaultProps) {
|
|
48
63
|
this.aggregatedBins = this.getAggregatedBins(bins, props);
|
|
49
64
|
this._updateMinMaxValues();
|
|
50
65
|
this.binMap = this.getBinMap();
|
|
@@ -57,7 +72,7 @@ export default class BinSorter {
|
|
|
57
72
|
* @param {Function} getValue
|
|
58
73
|
* @return {Array} array of values and index lookup
|
|
59
74
|
*/
|
|
60
|
-
getAggregatedBins(bins, props) {
|
|
75
|
+
getAggregatedBins(bins, props): AggregatedBin[] {
|
|
61
76
|
const {
|
|
62
77
|
getValue = defaultGetValue,
|
|
63
78
|
getPoints = defaultGetPoints,
|
|
@@ -67,7 +82,7 @@ export default class BinSorter {
|
|
|
67
82
|
|
|
68
83
|
const hasFilter = typeof filterData === 'function';
|
|
69
84
|
const binCount = bins.length;
|
|
70
|
-
const aggregatedBins = [];
|
|
85
|
+
const aggregatedBins: AggregatedBin[] = [];
|
|
71
86
|
let index = 0;
|
|
72
87
|
|
|
73
88
|
for (let binIndex = 0; binIndex < binCount; binIndex++) {
|
|
@@ -94,7 +109,7 @@ export default class BinSorter {
|
|
|
94
109
|
return aggregatedBins;
|
|
95
110
|
}
|
|
96
111
|
|
|
97
|
-
_percentileToIndex(percentileRange) {
|
|
112
|
+
_percentileToIndex(percentileRange): [number, number] {
|
|
98
113
|
const len = this.sortedBins.length;
|
|
99
114
|
if (len < 2) {
|
|
100
115
|
return [0, 0];
|
|
@@ -113,7 +128,7 @@ export default class BinSorter {
|
|
|
113
128
|
* This is used to retrieve bin value for color calculation
|
|
114
129
|
* @return {Object} bin index to aggregatedBins
|
|
115
130
|
*/
|
|
116
|
-
getBinMap() {
|
|
131
|
+
getBinMap(): Record<number, AggregatedBin> {
|
|
117
132
|
const binMap = {};
|
|
118
133
|
for (const bin of this.aggregatedBins) {
|
|
119
134
|
binMap[bin.i] = bin;
|
|
@@ -125,9 +140,8 @@ export default class BinSorter {
|
|
|
125
140
|
|
|
126
141
|
/**
|
|
127
142
|
* Get ths max count of all bins
|
|
128
|
-
* @return {Number | Boolean} max count
|
|
129
143
|
*/
|
|
130
|
-
_updateMinMaxValues() {
|
|
144
|
+
_updateMinMaxValues(): void {
|
|
131
145
|
let maxCount = 0;
|
|
132
146
|
let maxValue = 0;
|
|
133
147
|
let minValue = MAX_32_BIT_FLOAT;
|
|
@@ -151,11 +165,12 @@ export default class BinSorter {
|
|
|
151
165
|
* @param {Number} range[1] - upper bound
|
|
152
166
|
* @return {Array} array of new value range
|
|
153
167
|
*/
|
|
154
|
-
getValueRange(percentileRange) {
|
|
168
|
+
getValueRange(percentileRange: [number, number]): [number, number] {
|
|
155
169
|
if (!this.sortedBins) {
|
|
156
170
|
this.sortedBins = this.aggregatedBins.sort((a, b) => ascending(a.value, b.value));
|
|
157
171
|
}
|
|
158
172
|
if (!this.sortedBins.length) {
|
|
173
|
+
// @ts-expect-error
|
|
159
174
|
return [];
|
|
160
175
|
}
|
|
161
176
|
let lowerIdx = 0;
|
|
@@ -170,7 +185,7 @@ export default class BinSorter {
|
|
|
170
185
|
return [this.sortedBins[lowerIdx].value, this.sortedBins[upperIdx].value];
|
|
171
186
|
}
|
|
172
187
|
|
|
173
|
-
getValueDomainByScale(scale, [lower = 0, upper = 100] = []) {
|
|
188
|
+
getValueDomainByScale(scale: string, [lower = 0, upper = 100] = []) {
|
|
174
189
|
if (!this.sortedBins) {
|
|
175
190
|
this.sortedBins = this.aggregatedBins.sort((a, b) => ascending(a.value, b.value));
|
|
176
191
|
}
|
|
@@ -182,7 +197,7 @@ export default class BinSorter {
|
|
|
182
197
|
return this._getScaleDomain(scale, indexEdge);
|
|
183
198
|
}
|
|
184
199
|
|
|
185
|
-
_getScaleDomain(scaleType, [lowerIdx, upperIdx]) {
|
|
200
|
+
_getScaleDomain(scaleType: string, [lowerIdx, upperIdx]: [number, number]): [number, number] {
|
|
186
201
|
const bins = this.sortedBins;
|
|
187
202
|
|
|
188
203
|
switch (scaleType) {
|
|
@@ -194,7 +209,7 @@ export default class BinSorter {
|
|
|
194
209
|
return getQuantileDomain(bins.slice(lowerIdx, upperIdx + 1), d => d.value);
|
|
195
210
|
|
|
196
211
|
case 'ordinal':
|
|
197
|
-
return getOrdinalDomain(bins, d => d.value);
|
|
212
|
+
return getOrdinalDomain(bins, d => d.value) as [number, number];
|
|
198
213
|
|
|
199
214
|
default:
|
|
200
215
|
return [bins[lowerIdx].value, bins[upperIdx].value];
|