@deck.gl/aggregation-layers 8.8.12 → 8.8.13
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 +246 -246
- package/package.json +2 -2
- package/typed/aggregation-layer.js +151 -0
- package/typed/contour-layer/contour-layer.js +234 -0
- package/typed/contour-layer/contour-utils.js +64 -0
- package/typed/contour-layer/marching-squares-codes.js +337 -0
- package/typed/contour-layer/marching-squares.js +147 -0
- package/typed/cpu-grid-layer/cpu-grid-layer.js +129 -0
- package/typed/cpu-grid-layer/grid-aggregator.js +141 -0
- package/typed/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.js +34 -0
- package/typed/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.js +141 -0
- package/typed/gpu-grid-layer/gpu-grid-cell-layer.js +143 -0
- package/typed/gpu-grid-layer/gpu-grid-layer.js +289 -0
- package/typed/grid-aggregation-layer.js +172 -0
- package/typed/grid-layer/grid-layer.js +60 -0
- package/typed/heatmap-layer/heatmap-layer-utils.js +78 -0
- package/typed/heatmap-layer/heatmap-layer.js +478 -0
- package/typed/heatmap-layer/max-fs.glsl.js +7 -0
- package/typed/heatmap-layer/max-vs.glsl.js +12 -0
- package/typed/heatmap-layer/triangle-layer-fragment.glsl.js +58 -0
- package/typed/heatmap-layer/triangle-layer-vertex.glsl.js +51 -0
- package/typed/heatmap-layer/triangle-layer.js +67 -0
- package/typed/heatmap-layer/weights-fs.glsl.js +19 -0
- package/typed/heatmap-layer/weights-vs.glsl.js +23 -0
- package/typed/hexagon-layer/hexagon-aggregator.js +112 -0
- package/typed/hexagon-layer/hexagon-layer.js +171 -0
- package/typed/index.js +33 -0
- package/typed/screen-grid-layer/screen-grid-cell-layer.js +159 -0
- package/typed/screen-grid-layer/screen-grid-layer-fragment.glsl.js +37 -0
- package/typed/screen-grid-layer/screen-grid-layer-vertex.glsl.js +83 -0
- package/typed/screen-grid-layer/screen-grid-layer.js +216 -0
- package/typed/types.js +1 -0
- package/typed/utils/aggregation-operation-utils.js +94 -0
- package/typed/utils/bin-sorter.js +167 -0
- package/typed/utils/color-utils.js +53 -0
- package/typed/utils/cpu-aggregator.js +417 -0
- package/typed/utils/gpu-grid-aggregation/aggregate-all-fs.glsl.js +39 -0
- package/typed/utils/gpu-grid-aggregation/aggregate-all-vs.glsl.js +53 -0
- package/typed/utils/gpu-grid-aggregation/aggregate-to-grid-fs.glsl.js +31 -0
- package/typed/utils/gpu-grid-aggregation/aggregate-to-grid-vs.glsl.js +77 -0
- package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator-constants.js +41 -0
- package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator-utils.js +1 -0
- package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator.js +562 -0
- package/typed/utils/gpu-grid-aggregation/transform-mean-vs.glsl.js +36 -0
- package/typed/utils/grid-aggregation-utils.js +114 -0
- package/typed/utils/prop-utils.js +28 -0
- package/typed/utils/resource-utils.js +40 -0
- package/typed/utils/scale-utils.js +184 -0
|
@@ -0,0 +1,417 @@
|
|
|
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 BinSorter from './bin-sorter';
|
|
21
|
+
import { getScaleFunctionByScaleType } from './scale-utils';
|
|
22
|
+
import { getValueFunc, wrapGetValueFunc } from './aggregation-operation-utils';
|
|
23
|
+
function nop() { }
|
|
24
|
+
const dimensionSteps = ['getBins', 'getDomain', 'getScaleFunc'];
|
|
25
|
+
const defaultDimensions = [
|
|
26
|
+
{
|
|
27
|
+
key: 'fillColor',
|
|
28
|
+
accessor: 'getFillColor',
|
|
29
|
+
pickingInfo: 'colorValue',
|
|
30
|
+
getBins: {
|
|
31
|
+
triggers: {
|
|
32
|
+
value: {
|
|
33
|
+
prop: 'getColorValue',
|
|
34
|
+
updateTrigger: 'getColorValue'
|
|
35
|
+
},
|
|
36
|
+
weight: {
|
|
37
|
+
prop: 'getColorWeight',
|
|
38
|
+
updateTrigger: 'getColorWeight'
|
|
39
|
+
},
|
|
40
|
+
aggregation: {
|
|
41
|
+
prop: 'colorAggregation'
|
|
42
|
+
},
|
|
43
|
+
filterData: {
|
|
44
|
+
prop: '_filterData',
|
|
45
|
+
updateTrigger: '_filterData'
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
getDomain: {
|
|
50
|
+
triggers: {
|
|
51
|
+
lowerPercentile: {
|
|
52
|
+
prop: 'lowerPercentile'
|
|
53
|
+
},
|
|
54
|
+
upperPercentile: {
|
|
55
|
+
prop: 'upperPercentile'
|
|
56
|
+
},
|
|
57
|
+
scaleType: {
|
|
58
|
+
prop: 'colorScaleType'
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
getScaleFunc: {
|
|
63
|
+
triggers: {
|
|
64
|
+
domain: { prop: 'colorDomain' },
|
|
65
|
+
range: { prop: 'colorRange' }
|
|
66
|
+
},
|
|
67
|
+
onSet: {
|
|
68
|
+
props: 'onSetColorDomain'
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
nullValue: [0, 0, 0, 0]
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
key: 'elevation',
|
|
75
|
+
accessor: 'getElevation',
|
|
76
|
+
pickingInfo: 'elevationValue',
|
|
77
|
+
getBins: {
|
|
78
|
+
triggers: {
|
|
79
|
+
value: {
|
|
80
|
+
prop: 'getElevationValue',
|
|
81
|
+
updateTrigger: 'getElevationValue'
|
|
82
|
+
},
|
|
83
|
+
weight: {
|
|
84
|
+
prop: 'getElevationWeight',
|
|
85
|
+
updateTrigger: 'getElevationWeight'
|
|
86
|
+
},
|
|
87
|
+
aggregation: {
|
|
88
|
+
prop: 'elevationAggregation'
|
|
89
|
+
},
|
|
90
|
+
filterData: {
|
|
91
|
+
prop: '_filterData',
|
|
92
|
+
updateTrigger: '_filterData'
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
getDomain: {
|
|
97
|
+
triggers: {
|
|
98
|
+
lowerPercentile: {
|
|
99
|
+
prop: 'elevationLowerPercentile'
|
|
100
|
+
},
|
|
101
|
+
upperPercentile: {
|
|
102
|
+
prop: 'elevationUpperPercentile'
|
|
103
|
+
},
|
|
104
|
+
scaleType: {
|
|
105
|
+
prop: 'elevationScaleType'
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
getScaleFunc: {
|
|
110
|
+
triggers: {
|
|
111
|
+
domain: { prop: 'elevationDomain' },
|
|
112
|
+
range: { prop: 'elevationRange' }
|
|
113
|
+
},
|
|
114
|
+
onSet: {
|
|
115
|
+
props: 'onSetElevationDomain'
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
nullValue: -1
|
|
119
|
+
}
|
|
120
|
+
];
|
|
121
|
+
const defaultGetCellSize = props => props.cellSize;
|
|
122
|
+
export default class CPUAggregator {
|
|
123
|
+
constructor(opts) {
|
|
124
|
+
this.state = {
|
|
125
|
+
layerData: {},
|
|
126
|
+
dimensions: {
|
|
127
|
+
// color: {
|
|
128
|
+
// getValue: null,
|
|
129
|
+
// domain: null,
|
|
130
|
+
// sortedBins: null,
|
|
131
|
+
// scaleFunc: nop
|
|
132
|
+
// },
|
|
133
|
+
// elevation: {
|
|
134
|
+
// getValue: null,
|
|
135
|
+
// domain: null,
|
|
136
|
+
// sortedBins: null,
|
|
137
|
+
// scaleFunc: nop
|
|
138
|
+
// }
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
this.changeFlags = {};
|
|
142
|
+
this.dimensionUpdaters = {};
|
|
143
|
+
this._getCellSize = opts.getCellSize || defaultGetCellSize;
|
|
144
|
+
this._getAggregator = opts.getAggregator;
|
|
145
|
+
this._addDimension(opts.dimensions || defaultDimensions);
|
|
146
|
+
}
|
|
147
|
+
static defaultDimensions() {
|
|
148
|
+
return defaultDimensions;
|
|
149
|
+
}
|
|
150
|
+
updateState(opts, aggregationParams) {
|
|
151
|
+
const { oldProps, props, changeFlags } = opts;
|
|
152
|
+
this.updateGetValueFuncs(oldProps, props, changeFlags);
|
|
153
|
+
const reprojectNeeded = this.needsReProjectPoints(oldProps, props, changeFlags);
|
|
154
|
+
let aggregationDirty = false;
|
|
155
|
+
if (changeFlags.dataChanged || reprojectNeeded) {
|
|
156
|
+
// project data into bin and aggregate wegiths per bin
|
|
157
|
+
this.getAggregatedData(props, aggregationParams);
|
|
158
|
+
aggregationDirty = true;
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
const dimensionChanges = this.getDimensionChanges(oldProps, props, changeFlags) || [];
|
|
162
|
+
// this here is layer
|
|
163
|
+
dimensionChanges.forEach(f => typeof f === 'function' && f());
|
|
164
|
+
aggregationDirty = true;
|
|
165
|
+
}
|
|
166
|
+
this.setState({ aggregationDirty });
|
|
167
|
+
return this.state;
|
|
168
|
+
}
|
|
169
|
+
// Update private state
|
|
170
|
+
setState(updateObject) {
|
|
171
|
+
this.state = { ...this.state, ...updateObject };
|
|
172
|
+
}
|
|
173
|
+
// Update private state.dimensions
|
|
174
|
+
setDimensionState(key, updateObject) {
|
|
175
|
+
this.setState({
|
|
176
|
+
dimensions: {
|
|
177
|
+
...this.state.dimensions,
|
|
178
|
+
[key]: { ...this.state.dimensions[key], ...updateObject }
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
normalizeResult(result = {}) {
|
|
183
|
+
// support previous hexagonAggregator API
|
|
184
|
+
if (result.hexagons) {
|
|
185
|
+
return { data: result.hexagons, ...result };
|
|
186
|
+
}
|
|
187
|
+
else if (result.layerData) {
|
|
188
|
+
return { data: result.layerData, ...result };
|
|
189
|
+
}
|
|
190
|
+
return result;
|
|
191
|
+
}
|
|
192
|
+
getAggregatedData(props, aggregationParams) {
|
|
193
|
+
const aggregator = this._getAggregator(props);
|
|
194
|
+
const result = aggregator(props, aggregationParams);
|
|
195
|
+
this.setState({
|
|
196
|
+
layerData: this.normalizeResult(result)
|
|
197
|
+
});
|
|
198
|
+
this.changeFlags = {
|
|
199
|
+
layerData: true
|
|
200
|
+
};
|
|
201
|
+
this.getSortedBins(props);
|
|
202
|
+
}
|
|
203
|
+
updateGetValueFuncs(oldProps, props, changeFlags) {
|
|
204
|
+
for (const key in this.dimensionUpdaters) {
|
|
205
|
+
const { value, weight, aggregation } = this.dimensionUpdaters[key].getBins.triggers;
|
|
206
|
+
let getValue = props[value.prop];
|
|
207
|
+
const getValueChanged = this.needUpdateDimensionStep(this.dimensionUpdaters[key].getBins, oldProps, props, changeFlags);
|
|
208
|
+
if (getValueChanged) {
|
|
209
|
+
if (getValue) {
|
|
210
|
+
getValue = wrapGetValueFunc(getValue, { data: props.data });
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
// If `getValue` is not provided from props, build it with aggregation and weight.
|
|
214
|
+
getValue = getValueFunc(props[aggregation.prop], props[weight.prop], { data: props.data });
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (getValue) {
|
|
218
|
+
this.setDimensionState(key, { getValue });
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
needsReProjectPoints(oldProps, props, changeFlags) {
|
|
223
|
+
return (this._getCellSize(oldProps) !== this._getCellSize(props) ||
|
|
224
|
+
this._getAggregator(oldProps) !== this._getAggregator(props) ||
|
|
225
|
+
(changeFlags.updateTriggersChanged &&
|
|
226
|
+
(changeFlags.updateTriggersChanged.all || changeFlags.updateTriggersChanged.getPosition)));
|
|
227
|
+
}
|
|
228
|
+
// Adds dimensions
|
|
229
|
+
addDimension(dimensions) {
|
|
230
|
+
this._addDimension(dimensions);
|
|
231
|
+
}
|
|
232
|
+
_addDimension(dimensions = []) {
|
|
233
|
+
dimensions.forEach(dimension => {
|
|
234
|
+
const { key } = dimension;
|
|
235
|
+
this.dimensionUpdaters[key] = this.getDimensionUpdaters(dimension);
|
|
236
|
+
this.state.dimensions[key] = {
|
|
237
|
+
getValue: null,
|
|
238
|
+
domain: null,
|
|
239
|
+
sortedBins: null,
|
|
240
|
+
scaleFunc: nop
|
|
241
|
+
};
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
getDimensionUpdaters({ key, accessor, pickingInfo, getBins, getDomain, getScaleFunc, nullValue }) {
|
|
245
|
+
return {
|
|
246
|
+
key,
|
|
247
|
+
accessor,
|
|
248
|
+
pickingInfo,
|
|
249
|
+
getBins: { updater: this.getDimensionSortedBins, ...getBins },
|
|
250
|
+
getDomain: { updater: this.getDimensionValueDomain, ...getDomain },
|
|
251
|
+
getScaleFunc: { updater: this.getDimensionScale, ...getScaleFunc },
|
|
252
|
+
attributeAccessor: this.getSubLayerDimensionAttribute(key, nullValue)
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
needUpdateDimensionStep(dimensionStep, oldProps, props, changeFlags) {
|
|
256
|
+
// whether need to update current dimension step
|
|
257
|
+
// dimension step is the value, domain, scaleFunction of each dimension
|
|
258
|
+
// each step is an object with properties links to layer prop and whether the prop is
|
|
259
|
+
// controlled by updateTriggers
|
|
260
|
+
// getBins: {
|
|
261
|
+
// value: {
|
|
262
|
+
// prop: 'getElevationValue',
|
|
263
|
+
// updateTrigger: 'getElevationValue'
|
|
264
|
+
// },
|
|
265
|
+
// weight: {
|
|
266
|
+
// prop: 'getElevationWeight',
|
|
267
|
+
// updateTrigger: 'getElevationWeight'
|
|
268
|
+
// },
|
|
269
|
+
// aggregation: {
|
|
270
|
+
// prop: 'elevationAggregation'
|
|
271
|
+
// }
|
|
272
|
+
// }
|
|
273
|
+
return Object.values(dimensionStep.triggers).some(item => {
|
|
274
|
+
if (item.updateTrigger) {
|
|
275
|
+
// check based on updateTriggers change first
|
|
276
|
+
// if data has changed, always update value
|
|
277
|
+
return (changeFlags.dataChanged ||
|
|
278
|
+
(changeFlags.updateTriggersChanged &&
|
|
279
|
+
(changeFlags.updateTriggersChanged.all ||
|
|
280
|
+
changeFlags.updateTriggersChanged[item.updateTrigger])));
|
|
281
|
+
}
|
|
282
|
+
// fallback to direct comparison
|
|
283
|
+
return oldProps[item.prop] !== props[item.prop];
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
getDimensionChanges(oldProps, props, changeFlags) {
|
|
287
|
+
// const {dimensionUpdaters} = this.state;
|
|
288
|
+
const updaters = [];
|
|
289
|
+
// get dimension to be updated
|
|
290
|
+
for (const key in this.dimensionUpdaters) {
|
|
291
|
+
// return the first triggered updater for each dimension
|
|
292
|
+
const needUpdate = dimensionSteps.find(step => this.needUpdateDimensionStep(this.dimensionUpdaters[key][step], oldProps, props, changeFlags));
|
|
293
|
+
if (needUpdate) {
|
|
294
|
+
updaters.push(this.dimensionUpdaters[key][needUpdate].updater.bind(this, props, this.dimensionUpdaters[key]));
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return updaters.length ? updaters : null;
|
|
298
|
+
}
|
|
299
|
+
getUpdateTriggers(props) {
|
|
300
|
+
const _updateTriggers = props.updateTriggers || {};
|
|
301
|
+
const updateTriggers = {};
|
|
302
|
+
for (const key in this.dimensionUpdaters) {
|
|
303
|
+
const { accessor } = this.dimensionUpdaters[key];
|
|
304
|
+
// fold dimension triggers into each accessor
|
|
305
|
+
updateTriggers[accessor] = {};
|
|
306
|
+
dimensionSteps.forEach(step => {
|
|
307
|
+
Object.values(this.dimensionUpdaters[key][step].triggers).forEach(({ prop, updateTrigger }) => {
|
|
308
|
+
if (updateTrigger) {
|
|
309
|
+
// if prop is based on updateTrigger e.g. getColorValue, getColorWeight
|
|
310
|
+
// and updateTriggers is passed in from layer prop
|
|
311
|
+
// fold the updateTriggers into accessor
|
|
312
|
+
const fromProp = _updateTriggers[updateTrigger];
|
|
313
|
+
if (typeof fromProp === 'object' && !Array.isArray(fromProp)) {
|
|
314
|
+
// if updateTrigger is an object spread it
|
|
315
|
+
Object.assign(updateTriggers[accessor], fromProp);
|
|
316
|
+
}
|
|
317
|
+
else if (fromProp !== undefined) {
|
|
318
|
+
updateTriggers[accessor][prop] = fromProp;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
// if prop is not based on updateTrigger
|
|
323
|
+
updateTriggers[accessor][prop] = props[prop];
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
return updateTriggers;
|
|
329
|
+
}
|
|
330
|
+
getSortedBins(props) {
|
|
331
|
+
for (const key in this.dimensionUpdaters) {
|
|
332
|
+
this.getDimensionSortedBins(props, this.dimensionUpdaters[key]);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
getDimensionSortedBins(props, dimensionUpdater) {
|
|
336
|
+
const { key } = dimensionUpdater;
|
|
337
|
+
const { getValue } = this.state.dimensions[key];
|
|
338
|
+
const sortedBins = new BinSorter(this.state.layerData.data || [], {
|
|
339
|
+
getValue,
|
|
340
|
+
filterData: props._filterData
|
|
341
|
+
});
|
|
342
|
+
this.setDimensionState(key, { sortedBins });
|
|
343
|
+
this.getDimensionValueDomain(props, dimensionUpdater);
|
|
344
|
+
}
|
|
345
|
+
getDimensionValueDomain(props, dimensionUpdater) {
|
|
346
|
+
const { getDomain, key } = dimensionUpdater;
|
|
347
|
+
const { triggers: { lowerPercentile, upperPercentile, scaleType } } = getDomain;
|
|
348
|
+
const valueDomain = this.state.dimensions[key].sortedBins.getValueDomainByScale(props[scaleType.prop], [props[lowerPercentile.prop], props[upperPercentile.prop]]);
|
|
349
|
+
this.setDimensionState(key, { valueDomain });
|
|
350
|
+
this.getDimensionScale(props, dimensionUpdater);
|
|
351
|
+
}
|
|
352
|
+
getDimensionScale(props, dimensionUpdater) {
|
|
353
|
+
const { key, getScaleFunc, getDomain } = dimensionUpdater;
|
|
354
|
+
const { domain, range } = getScaleFunc.triggers;
|
|
355
|
+
const { scaleType } = getDomain.triggers;
|
|
356
|
+
const { onSet } = getScaleFunc;
|
|
357
|
+
const dimensionRange = props[range.prop];
|
|
358
|
+
const dimensionDomain = props[domain.prop] || this.state.dimensions[key].valueDomain;
|
|
359
|
+
const getScaleFunction = getScaleFunctionByScaleType(scaleType && props[scaleType.prop]);
|
|
360
|
+
const scaleFunc = getScaleFunction(dimensionDomain, dimensionRange);
|
|
361
|
+
if (typeof onSet === 'object' && typeof props[onSet.props] === 'function') {
|
|
362
|
+
props[onSet.props](scaleFunc.domain());
|
|
363
|
+
}
|
|
364
|
+
this.setDimensionState(key, { scaleFunc });
|
|
365
|
+
}
|
|
366
|
+
getSubLayerDimensionAttribute(key, nullValue) {
|
|
367
|
+
return cell => {
|
|
368
|
+
const { sortedBins, scaleFunc } = this.state.dimensions[key];
|
|
369
|
+
const bin = sortedBins.binMap[cell.index];
|
|
370
|
+
if (bin && bin.counts === 0) {
|
|
371
|
+
// no points left in bin after filtering
|
|
372
|
+
return nullValue;
|
|
373
|
+
}
|
|
374
|
+
const cv = bin && bin.value;
|
|
375
|
+
const domain = scaleFunc.domain();
|
|
376
|
+
const isValueInDomain = cv >= domain[0] && cv <= domain[domain.length - 1];
|
|
377
|
+
// if cell value is outside domain, set alpha to 0
|
|
378
|
+
return isValueInDomain ? scaleFunc(cv) : nullValue;
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
getSubLayerAccessors(props) {
|
|
382
|
+
const accessors = {};
|
|
383
|
+
for (const key in this.dimensionUpdaters) {
|
|
384
|
+
const { accessor } = this.dimensionUpdaters[key];
|
|
385
|
+
accessors[accessor] = this.getSubLayerDimensionAttribute(props, key);
|
|
386
|
+
}
|
|
387
|
+
return accessors;
|
|
388
|
+
}
|
|
389
|
+
getPickingInfo({ info }) {
|
|
390
|
+
const isPicked = info.picked && info.index > -1;
|
|
391
|
+
let object = null;
|
|
392
|
+
if (isPicked) {
|
|
393
|
+
// const {sortedColorBins, sortedElevationBins} = this.state;
|
|
394
|
+
const cell = this.state.layerData.data[info.index];
|
|
395
|
+
const binInfo = {};
|
|
396
|
+
for (const key in this.dimensionUpdaters) {
|
|
397
|
+
const { pickingInfo } = this.dimensionUpdaters[key];
|
|
398
|
+
const { sortedBins } = this.state.dimensions[key];
|
|
399
|
+
const value = sortedBins.binMap[cell.index] && sortedBins.binMap[cell.index].value;
|
|
400
|
+
binInfo[pickingInfo] = value;
|
|
401
|
+
}
|
|
402
|
+
object = Object.assign(binInfo, cell, {
|
|
403
|
+
points: cell.filteredPoints || cell.points
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
// override object with picked cell
|
|
407
|
+
info.picked = Boolean(object);
|
|
408
|
+
info.object = object;
|
|
409
|
+
return info;
|
|
410
|
+
}
|
|
411
|
+
getAccessor(dimensionKey) {
|
|
412
|
+
if (!this.dimensionUpdaters.hasOwnProperty(dimensionKey)) {
|
|
413
|
+
return nop;
|
|
414
|
+
}
|
|
415
|
+
return this.dimensionUpdaters[dimensionKey].attributeAccessor;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
export default `\
|
|
21
|
+
#version 300 es
|
|
22
|
+
#define SHADER_NAME gpu-aggregation-all-fs
|
|
23
|
+
|
|
24
|
+
precision highp float;
|
|
25
|
+
|
|
26
|
+
in vec2 vTextureCoord;
|
|
27
|
+
uniform sampler2D uSampler;
|
|
28
|
+
uniform bool combineMaxMin;
|
|
29
|
+
out vec4 fragColor;
|
|
30
|
+
void main(void) {
|
|
31
|
+
vec4 textureColor = texture(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));
|
|
32
|
+
if (textureColor.a == 0.) {
|
|
33
|
+
discard;
|
|
34
|
+
}
|
|
35
|
+
fragColor.rgb = textureColor.rgb;
|
|
36
|
+
// if combineMinMax is true, use Alpha channel for first weights min value.
|
|
37
|
+
fragColor.a = combineMaxMin ? textureColor.r : textureColor.a;
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
export default `\
|
|
21
|
+
#version 300 es
|
|
22
|
+
#define SHADER_NAME gpu-aggregation-all-vs-64
|
|
23
|
+
|
|
24
|
+
in vec2 position;
|
|
25
|
+
uniform ivec2 gridSize;
|
|
26
|
+
out vec2 vTextureCoord;
|
|
27
|
+
|
|
28
|
+
void main(void) {
|
|
29
|
+
// Map each position to single pixel
|
|
30
|
+
vec2 pos = vec2(-1.0, -1.0);
|
|
31
|
+
|
|
32
|
+
// Move to pixel center, pixel-size in screen sapce (2/gridSize) * 0.5 => 1/gridSize
|
|
33
|
+
vec2 offset = 1.0 / vec2(gridSize);
|
|
34
|
+
pos = pos + offset;
|
|
35
|
+
|
|
36
|
+
gl_Position = vec4(pos, 0.0, 1.0);
|
|
37
|
+
|
|
38
|
+
int yIndex = gl_InstanceID / gridSize[0];
|
|
39
|
+
int xIndex = gl_InstanceID - (yIndex * gridSize[0]);
|
|
40
|
+
|
|
41
|
+
vec2 yIndexFP64 = vec2(float(yIndex), 0.);
|
|
42
|
+
vec2 xIndexFP64 = vec2(float(xIndex), 0.);
|
|
43
|
+
vec2 gridSizeYFP64 = vec2(gridSize[1], 0.);
|
|
44
|
+
vec2 gridSizeXFP64 = vec2(gridSize[0], 0.);
|
|
45
|
+
|
|
46
|
+
vec2 texCoordXFP64 = div_fp64(yIndexFP64, gridSizeYFP64);
|
|
47
|
+
vec2 texCoordYFP64 = div_fp64(xIndexFP64, gridSizeXFP64);
|
|
48
|
+
|
|
49
|
+
vTextureCoord = vec2(texCoordYFP64.x, texCoordXFP64.x);
|
|
50
|
+
// Enforce default value for ANGLE issue (https://bugs.chromium.org/p/angleproject/issues/detail?id=3941)
|
|
51
|
+
gl_PointSize = 1.0;
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
export default `\
|
|
21
|
+
#define SHADER_NAME gpu-aggregation-to-grid-fs
|
|
22
|
+
|
|
23
|
+
precision highp float;
|
|
24
|
+
|
|
25
|
+
varying vec3 vWeights;
|
|
26
|
+
|
|
27
|
+
void main(void) {
|
|
28
|
+
gl_FragColor = vec4(vWeights, 1.0);
|
|
29
|
+
DECKGL_FILTER_COLOR(gl_FragColor, geometry);
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
export default `\
|
|
21
|
+
#define SHADER_NAME gpu-aggregation-to-grid-vs
|
|
22
|
+
|
|
23
|
+
attribute vec3 positions;
|
|
24
|
+
attribute vec3 positions64Low;
|
|
25
|
+
attribute vec3 weights;
|
|
26
|
+
uniform vec2 cellSize;
|
|
27
|
+
uniform vec2 gridSize;
|
|
28
|
+
uniform bool projectPoints;
|
|
29
|
+
uniform vec2 translation;
|
|
30
|
+
uniform vec3 scaling;
|
|
31
|
+
|
|
32
|
+
varying vec3 vWeights;
|
|
33
|
+
|
|
34
|
+
vec2 project_to_pixel(vec4 pos) {
|
|
35
|
+
vec4 result;
|
|
36
|
+
pos.xy = pos.xy/pos.w;
|
|
37
|
+
result = pos + vec4(translation, 0., 0.);
|
|
38
|
+
result.xy = scaling.z > 0. ? result.xy * scaling.xy : result.xy;
|
|
39
|
+
return result.xy;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
void main(void) {
|
|
43
|
+
|
|
44
|
+
vWeights = weights;
|
|
45
|
+
|
|
46
|
+
vec4 windowPos = vec4(positions, 1.);
|
|
47
|
+
if (projectPoints) {
|
|
48
|
+
windowPos = project_position_to_clipspace(positions, positions64Low, vec3(0));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
vec2 pos = project_to_pixel(windowPos);
|
|
52
|
+
|
|
53
|
+
vec2 pixelXY64[2];
|
|
54
|
+
pixelXY64[0] = vec2(pos.x, 0.);
|
|
55
|
+
pixelXY64[1] = vec2(pos.y, 0.);
|
|
56
|
+
|
|
57
|
+
// Transform (0,0):windowSize -> (0, 0): gridSize
|
|
58
|
+
vec2 gridXY64[2];
|
|
59
|
+
gridXY64[0] = div_fp64(pixelXY64[0], vec2(cellSize.x, 0));
|
|
60
|
+
gridXY64[1] = div_fp64(pixelXY64[1], vec2(cellSize.y, 0));
|
|
61
|
+
float x = floor(gridXY64[0].x);
|
|
62
|
+
float y = floor(gridXY64[1].x);
|
|
63
|
+
pos = vec2(x, y);
|
|
64
|
+
|
|
65
|
+
// Transform (0,0):gridSize -> (-1, -1):(1,1)
|
|
66
|
+
pos = (pos * (2., 2.) / (gridSize)) - (1., 1.);
|
|
67
|
+
|
|
68
|
+
// Move to pixel center, pixel-size in screen sapce (2/gridSize) * 0.5 => 1/gridSize
|
|
69
|
+
vec2 offset = 1.0 / gridSize;
|
|
70
|
+
pos = pos + offset;
|
|
71
|
+
|
|
72
|
+
gl_Position = vec4(pos, 0.0, 1.0);
|
|
73
|
+
|
|
74
|
+
// Enforce default value for ANGLE issue (https://bugs.chromium.org/p/angleproject/issues/detail?id=3941)
|
|
75
|
+
gl_PointSize = 1.0;
|
|
76
|
+
}
|
|
77
|
+
`;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import GL from '@luma.gl/constants';
|
|
2
|
+
import { AGGREGATION_OPERATION } from '../aggregation-operation-utils';
|
|
3
|
+
export const DEFAULT_RUN_PARAMS = {
|
|
4
|
+
projectPoints: false,
|
|
5
|
+
viewport: null,
|
|
6
|
+
createBufferObjects: true,
|
|
7
|
+
moduleSettings: {}
|
|
8
|
+
};
|
|
9
|
+
export const MAX_32_BIT_FLOAT = 3.402823466e38;
|
|
10
|
+
export const MIN_BLEND_EQUATION = [GL.MIN, GL.FUNC_ADD];
|
|
11
|
+
export const MAX_BLEND_EQUATION = [GL.MAX, GL.FUNC_ADD];
|
|
12
|
+
export const MAX_MIN_BLEND_EQUATION = [GL.MAX, GL.MIN];
|
|
13
|
+
export const EQUATION_MAP = {
|
|
14
|
+
[AGGREGATION_OPERATION.SUM]: GL.FUNC_ADD,
|
|
15
|
+
[AGGREGATION_OPERATION.MEAN]: GL.FUNC_ADD,
|
|
16
|
+
[AGGREGATION_OPERATION.MIN]: MIN_BLEND_EQUATION,
|
|
17
|
+
[AGGREGATION_OPERATION.MAX]: MAX_BLEND_EQUATION
|
|
18
|
+
};
|
|
19
|
+
export const ELEMENTCOUNT = 4;
|
|
20
|
+
export const DEFAULT_WEIGHT_PARAMS = {
|
|
21
|
+
size: 1,
|
|
22
|
+
operation: AGGREGATION_OPERATION.SUM,
|
|
23
|
+
needMin: false,
|
|
24
|
+
needMax: false,
|
|
25
|
+
combineMaxMin: false
|
|
26
|
+
};
|
|
27
|
+
export const PIXEL_SIZE = 4; // RGBA32F
|
|
28
|
+
export const WEIGHT_SIZE = 3;
|
|
29
|
+
export const MAX_MIN_TEXTURE_OPTS = {
|
|
30
|
+
format: GL.RGBA32F,
|
|
31
|
+
type: GL.FLOAT,
|
|
32
|
+
border: 0,
|
|
33
|
+
mipmaps: false,
|
|
34
|
+
parameters: {
|
|
35
|
+
[GL.TEXTURE_MAG_FILTER]: GL.NEAREST,
|
|
36
|
+
[GL.TEXTURE_MIN_FILTER]: GL.NEAREST
|
|
37
|
+
},
|
|
38
|
+
dataFormat: GL.RGBA,
|
|
39
|
+
width: 1,
|
|
40
|
+
height: 1
|
|
41
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|