@deck.gl/aggregation-layers 8.9.21 → 8.9.23

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 (48) hide show
  1. package/LICENSE +1 -1
  2. package/package.json +2 -2
  3. package/typed/aggregation-layer.js +0 -151
  4. package/typed/contour-layer/contour-layer.js +0 -234
  5. package/typed/contour-layer/contour-utils.js +0 -64
  6. package/typed/contour-layer/marching-squares-codes.js +0 -337
  7. package/typed/contour-layer/marching-squares.js +0 -147
  8. package/typed/cpu-grid-layer/cpu-grid-layer.js +0 -129
  9. package/typed/cpu-grid-layer/grid-aggregator.js +0 -141
  10. package/typed/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.js +0 -34
  11. package/typed/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.js +0 -141
  12. package/typed/gpu-grid-layer/gpu-grid-cell-layer.js +0 -143
  13. package/typed/gpu-grid-layer/gpu-grid-layer.js +0 -289
  14. package/typed/grid-aggregation-layer.js +0 -172
  15. package/typed/grid-layer/grid-layer.js +0 -60
  16. package/typed/heatmap-layer/heatmap-layer-utils.js +0 -78
  17. package/typed/heatmap-layer/heatmap-layer.js +0 -478
  18. package/typed/heatmap-layer/max-fs.glsl.js +0 -7
  19. package/typed/heatmap-layer/max-vs.glsl.js +0 -12
  20. package/typed/heatmap-layer/triangle-layer-fragment.glsl.js +0 -58
  21. package/typed/heatmap-layer/triangle-layer-vertex.glsl.js +0 -51
  22. package/typed/heatmap-layer/triangle-layer.js +0 -67
  23. package/typed/heatmap-layer/weights-fs.glsl.js +0 -19
  24. package/typed/heatmap-layer/weights-vs.glsl.js +0 -23
  25. package/typed/hexagon-layer/hexagon-aggregator.js +0 -112
  26. package/typed/hexagon-layer/hexagon-layer.js +0 -171
  27. package/typed/index.js +0 -33
  28. package/typed/screen-grid-layer/screen-grid-cell-layer.js +0 -159
  29. package/typed/screen-grid-layer/screen-grid-layer-fragment.glsl.js +0 -37
  30. package/typed/screen-grid-layer/screen-grid-layer-vertex.glsl.js +0 -83
  31. package/typed/screen-grid-layer/screen-grid-layer.js +0 -216
  32. package/typed/types.js +0 -1
  33. package/typed/utils/aggregation-operation-utils.js +0 -94
  34. package/typed/utils/bin-sorter.js +0 -167
  35. package/typed/utils/color-utils.js +0 -53
  36. package/typed/utils/cpu-aggregator.js +0 -417
  37. package/typed/utils/gpu-grid-aggregation/aggregate-all-fs.glsl.js +0 -39
  38. package/typed/utils/gpu-grid-aggregation/aggregate-all-vs.glsl.js +0 -53
  39. package/typed/utils/gpu-grid-aggregation/aggregate-to-grid-fs.glsl.js +0 -31
  40. package/typed/utils/gpu-grid-aggregation/aggregate-to-grid-vs.glsl.js +0 -77
  41. package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator-constants.js +0 -41
  42. package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator-utils.js +0 -1
  43. package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator.js +0 -562
  44. package/typed/utils/gpu-grid-aggregation/transform-mean-vs.glsl.js +0 -36
  45. package/typed/utils/grid-aggregation-utils.js +0 -114
  46. package/typed/utils/prop-utils.js +0 -28
  47. package/typed/utils/resource-utils.js +0 -40
  48. package/typed/utils/scale-utils.js +0 -184
@@ -1,216 +0,0 @@
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 { log } from '@deck.gl/core';
21
- import GL from '@luma.gl/constants';
22
- import GPUGridAggregator from '../utils/gpu-grid-aggregation/gpu-grid-aggregator';
23
- import { AGGREGATION_OPERATION, getValueFunc } from '../utils/aggregation-operation-utils';
24
- import ScreenGridCellLayer from './screen-grid-cell-layer';
25
- import GridAggregationLayer from '../grid-aggregation-layer';
26
- import { getFloatTexture } from '../utils/resource-utils.js';
27
- const defaultProps = {
28
- ...ScreenGridCellLayer.defaultProps,
29
- getPosition: { type: 'accessor', value: d => d.position },
30
- getWeight: { type: 'accessor', value: 1 },
31
- gpuAggregation: true,
32
- aggregation: 'SUM'
33
- };
34
- const POSITION_ATTRIBUTE_NAME = 'positions';
35
- const DIMENSIONS = {
36
- data: {
37
- props: ['cellSizePixels']
38
- },
39
- weights: {
40
- props: ['aggregation'],
41
- accessors: ['getWeight']
42
- }
43
- };
44
- export default class ScreenGridLayer extends GridAggregationLayer {
45
- initializeState() {
46
- const { gl } = this.context;
47
- if (!ScreenGridCellLayer.isSupported(gl)) {
48
- // max aggregated value is sampled from a float texture
49
- this.setState({ supported: false });
50
- log.error(`ScreenGridLayer: ${this.id} is not supported on this browser`)();
51
- return;
52
- }
53
- super.initializeAggregationLayer({
54
- dimensions: DIMENSIONS,
55
- // @ts-expect-error
56
- getCellSize: props => props.cellSizePixels // TODO
57
- });
58
- const weights = {
59
- count: {
60
- size: 1,
61
- operation: AGGREGATION_OPERATION.SUM,
62
- needMax: true,
63
- maxTexture: getFloatTexture(gl, { id: `${this.id}-max-texture` })
64
- }
65
- };
66
- this.setState({
67
- supported: true,
68
- projectPoints: true,
69
- weights,
70
- subLayerData: { attributes: {} },
71
- maxTexture: weights.count.maxTexture,
72
- positionAttributeName: 'positions',
73
- posOffset: [0, 0],
74
- translation: [1, -1]
75
- });
76
- const attributeManager = this.getAttributeManager();
77
- attributeManager.add({
78
- [POSITION_ATTRIBUTE_NAME]: {
79
- size: 3,
80
- accessor: 'getPosition',
81
- type: GL.DOUBLE,
82
- fp64: this.use64bitPositions()
83
- },
84
- // this attribute is used in gpu aggregation path only
85
- count: { size: 3, accessor: 'getWeight' }
86
- });
87
- }
88
- shouldUpdateState({ changeFlags }) {
89
- return this.state.supported && changeFlags.somethingChanged;
90
- }
91
- updateState(opts) {
92
- super.updateState(opts);
93
- }
94
- renderLayers() {
95
- if (!this.state.supported) {
96
- return [];
97
- }
98
- const { maxTexture, numRow, numCol, weights } = this.state;
99
- const { updateTriggers } = this.props;
100
- const { aggregationBuffer } = weights.count;
101
- const CellLayerClass = this.getSubLayerClass('cells', ScreenGridCellLayer);
102
- return new CellLayerClass(this.props, this.getSubLayerProps({
103
- id: 'cell-layer',
104
- updateTriggers
105
- }), {
106
- data: { attributes: { instanceCounts: aggregationBuffer } },
107
- maxTexture,
108
- numInstances: numRow * numCol
109
- });
110
- }
111
- finalizeState(context) {
112
- super.finalizeState(context);
113
- const { aggregationBuffer, maxBuffer, maxTexture } = this.state;
114
- aggregationBuffer?.delete();
115
- maxBuffer?.delete();
116
- maxTexture?.delete();
117
- }
118
- getPickingInfo({ info }) {
119
- const { index } = info;
120
- if (index >= 0) {
121
- const { gpuGridAggregator, gpuAggregation, weights } = this.state;
122
- // Get count aggregation results
123
- const aggregationResults = gpuAggregation
124
- ? gpuGridAggregator.getData('count')
125
- : weights.count;
126
- // Each instance (one cell) is aggregated into single pixel,
127
- // Get current instance's aggregation details.
128
- info.object = GPUGridAggregator.getAggregationData({
129
- pixelIndex: index,
130
- ...aggregationResults
131
- });
132
- }
133
- return info;
134
- }
135
- // Aggregation Overrides
136
- updateResults({ aggregationData, maxData }) {
137
- const { count } = this.state.weights;
138
- count.aggregationData = aggregationData;
139
- count.aggregationBuffer.setData({ data: aggregationData });
140
- count.maxData = maxData;
141
- count.maxTexture.setImageData({ data: maxData });
142
- }
143
- /* eslint-disable complexity, max-statements */
144
- updateAggregationState(opts) {
145
- const cellSize = opts.props.cellSizePixels;
146
- const cellSizeChanged = opts.oldProps.cellSizePixels !== cellSize;
147
- const { viewportChanged } = opts.changeFlags;
148
- let gpuAggregation = opts.props.gpuAggregation;
149
- if (this.state.gpuAggregation !== opts.props.gpuAggregation) {
150
- if (gpuAggregation && !GPUGridAggregator.isSupported(this.context.gl)) {
151
- log.warn('GPU Grid Aggregation not supported, falling back to CPU')();
152
- gpuAggregation = false;
153
- }
154
- }
155
- const gpuAggregationChanged = gpuAggregation !== this.state.gpuAggregation;
156
- this.setState({
157
- gpuAggregation
158
- });
159
- const positionsChanged = this.isAttributeChanged(POSITION_ATTRIBUTE_NAME);
160
- const { dimensions } = this.state;
161
- const { data, weights } = dimensions;
162
- const aggregationDataDirty = positionsChanged ||
163
- gpuAggregationChanged ||
164
- viewportChanged ||
165
- this.isAggregationDirty(opts, {
166
- compareAll: gpuAggregation,
167
- dimension: data
168
- });
169
- const aggregationWeightsDirty = this.isAggregationDirty(opts, { dimension: weights });
170
- this.setState({
171
- aggregationDataDirty,
172
- aggregationWeightsDirty
173
- });
174
- const { viewport } = this.context;
175
- if (viewportChanged || cellSizeChanged) {
176
- const { width, height } = viewport;
177
- const numCol = Math.ceil(width / cellSize);
178
- const numRow = Math.ceil(height / cellSize);
179
- this.allocateResources(numRow, numCol);
180
- this.setState({
181
- // transformation from clipspace to screen(pixel) space
182
- scaling: [width / 2, -height / 2, 1],
183
- gridOffset: { xOffset: cellSize, yOffset: cellSize },
184
- width,
185
- height,
186
- numCol,
187
- numRow
188
- });
189
- }
190
- if (aggregationWeightsDirty) {
191
- this._updateAccessors(opts);
192
- }
193
- if (aggregationDataDirty || aggregationWeightsDirty) {
194
- this._resetResults();
195
- }
196
- }
197
- /* eslint-enable complexity, max-statements */
198
- // Private
199
- _updateAccessors(opts) {
200
- const { getWeight, aggregation, data } = opts.props;
201
- const { count } = this.state.weights;
202
- if (count) {
203
- count.getWeight = getWeight;
204
- count.operation = AGGREGATION_OPERATION[aggregation];
205
- }
206
- this.setState({ getValue: getValueFunc(aggregation, getWeight, { data }) });
207
- }
208
- _resetResults() {
209
- const { count } = this.state.weights;
210
- if (count) {
211
- count.aggregationData = null;
212
- }
213
- }
214
- }
215
- ScreenGridLayer.layerName = 'ScreenGridLayer';
216
- ScreenGridLayer.defaultProps = defaultProps;
package/typed/types.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,94 +0,0 @@
1
- // Copyright (c) 2015 - 2019 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 const AGGREGATION_OPERATION = {
21
- SUM: 1,
22
- MEAN: 2,
23
- MIN: 3,
24
- MAX: 4
25
- };
26
- function sumReducer(accu, cur) {
27
- return accu + cur;
28
- }
29
- function maxReducer(accu, cur) {
30
- return cur > accu ? cur : accu;
31
- }
32
- function minReducer(accu, cur) {
33
- return cur < accu ? cur : accu;
34
- }
35
- export function getMean(pts, accessor) {
36
- if (Number.isFinite(accessor)) {
37
- return pts.length ? accessor : null;
38
- }
39
- const filtered = pts.map(accessor).filter(Number.isFinite);
40
- return filtered.length ? filtered.reduce(sumReducer, 0) / filtered.length : null;
41
- }
42
- export function getSum(pts, accessor) {
43
- if (Number.isFinite(accessor)) {
44
- return pts.length ? pts.length * accessor : null;
45
- }
46
- const filtered = pts.map(accessor).filter(Number.isFinite);
47
- return filtered.length ? filtered.reduce(sumReducer, 0) : null;
48
- }
49
- export function getMax(pts, accessor) {
50
- if (Number.isFinite(accessor)) {
51
- return pts.length ? accessor : null;
52
- }
53
- const filtered = pts.map(accessor).filter(Number.isFinite);
54
- return filtered.length ? filtered.reduce(maxReducer, -Infinity) : null;
55
- }
56
- export function getMin(pts, accessor) {
57
- if (Number.isFinite(accessor)) {
58
- return pts.length ? accessor : null;
59
- }
60
- const filtered = pts.map(accessor).filter(Number.isFinite);
61
- return filtered.length ? filtered.reduce(minReducer, Infinity) : null;
62
- }
63
- // Function to convert from aggregation/accessor props (like colorAggregation and getColorWeight) to getValue prop (like getColorValue)
64
- export function getValueFunc(aggregation, accessor, context) {
65
- const op = AGGREGATION_OPERATION[aggregation] || AGGREGATION_OPERATION.SUM;
66
- accessor = wrapAccessor(accessor, context);
67
- switch (op) {
68
- case AGGREGATION_OPERATION.MIN:
69
- return pts => getMin(pts, accessor);
70
- case AGGREGATION_OPERATION.SUM:
71
- return pts => getSum(pts, accessor);
72
- case AGGREGATION_OPERATION.MEAN:
73
- return pts => getMean(pts, accessor);
74
- case AGGREGATION_OPERATION.MAX:
75
- return pts => getMax(pts, accessor);
76
- default:
77
- return null;
78
- }
79
- }
80
- function wrapAccessor(accessor, context = {}) {
81
- if (Number.isFinite(accessor)) {
82
- return accessor;
83
- }
84
- return pt => {
85
- context.index = pt.index;
86
- return accessor(pt.source, context);
87
- };
88
- }
89
- export function wrapGetValueFunc(getValue, context = {}) {
90
- return pts => {
91
- context.indices = pts.map(pt => pt.index);
92
- return getValue(pts.map(pt => pt.source), context);
93
- };
94
- }
@@ -1,167 +0,0 @@
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
- // getValue takes an array of points returns a value to sort the bins on.
21
- // by default it returns the number of points
22
- // this is where to pass in a function to color the bins by
23
- // avg/mean/max of specific value of the point
24
- const defaultGetValue = points => points.length;
25
- import { clamp, getQuantileDomain, getOrdinalDomain } from './scale-utils';
26
- const MAX_32_BIT_FLOAT = 3.402823466e38;
27
- // access array of points in each bin
28
- const defaultGetPoints = bin => bin.points;
29
- // access index of each bin
30
- const defaultGetIndex = bin => bin.index;
31
- // d3-scending
32
- const ascending = (a, b) => (a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN);
33
- const defaultProps = {
34
- getValue: defaultGetValue,
35
- getPoints: defaultGetPoints,
36
- getIndex: defaultGetIndex,
37
- filterData: null
38
- };
39
- export default class BinSorter {
40
- constructor(bins = [], props = defaultProps) {
41
- this.aggregatedBins = this.getAggregatedBins(bins, props);
42
- this._updateMinMaxValues();
43
- this.binMap = this.getBinMap();
44
- }
45
- /**
46
- * Get an array of object with aggregated values and index of bins
47
- * Array object will be sorted by value optionally.
48
- * @param {Array} bins
49
- * @param {Function} getValue
50
- * @return {Array} array of values and index lookup
51
- */
52
- getAggregatedBins(bins, props) {
53
- const { getValue = defaultGetValue, getPoints = defaultGetPoints, getIndex = defaultGetIndex, filterData } = props;
54
- const hasFilter = typeof filterData === 'function';
55
- const binCount = bins.length;
56
- const aggregatedBins = [];
57
- let index = 0;
58
- for (let binIndex = 0; binIndex < binCount; binIndex++) {
59
- const bin = bins[binIndex];
60
- const points = getPoints(bin);
61
- const i = getIndex(bin);
62
- const filteredPoints = hasFilter ? points.filter(filterData) : points;
63
- bin.filteredPoints = hasFilter ? filteredPoints : null;
64
- const value = filteredPoints.length ? getValue(filteredPoints) : null;
65
- if (value !== null && value !== undefined) {
66
- // filter bins if value is null or undefined
67
- aggregatedBins[index] = {
68
- i: Number.isFinite(i) ? i : binIndex,
69
- value,
70
- counts: filteredPoints.length
71
- };
72
- index++;
73
- }
74
- }
75
- return aggregatedBins;
76
- }
77
- _percentileToIndex(percentileRange) {
78
- const len = this.sortedBins.length;
79
- if (len < 2) {
80
- return [0, 0];
81
- }
82
- const [lower, upper] = percentileRange.map(n => clamp(n, 0, 100));
83
- const lowerIdx = Math.ceil((lower / 100) * (len - 1));
84
- const upperIdx = Math.floor((upper / 100) * (len - 1));
85
- return [lowerIdx, upperIdx];
86
- }
87
- /**
88
- * Get a mapping from cell/hexagon index to sorted bin
89
- * This is used to retrieve bin value for color calculation
90
- * @return {Object} bin index to aggregatedBins
91
- */
92
- getBinMap() {
93
- const binMap = {};
94
- for (const bin of this.aggregatedBins) {
95
- binMap[bin.i] = bin;
96
- }
97
- return binMap;
98
- }
99
- // Private
100
- /**
101
- * Get ths max count of all bins
102
- */
103
- _updateMinMaxValues() {
104
- let maxCount = 0;
105
- let maxValue = 0;
106
- let minValue = MAX_32_BIT_FLOAT;
107
- let totalCount = 0;
108
- for (const x of this.aggregatedBins) {
109
- maxCount = maxCount > x.counts ? maxCount : x.counts;
110
- maxValue = maxValue > x.value ? maxValue : x.value;
111
- minValue = minValue < x.value ? minValue : x.value;
112
- totalCount += x.counts;
113
- }
114
- this.maxCount = maxCount;
115
- this.maxValue = maxValue;
116
- this.minValue = minValue;
117
- this.totalCount = totalCount;
118
- }
119
- /**
120
- * Get range of values of all bins
121
- * @param {Number[]} range
122
- * @param {Number} range[0] - lower bound
123
- * @param {Number} range[1] - upper bound
124
- * @return {Array} array of new value range
125
- */
126
- getValueRange(percentileRange) {
127
- if (!this.sortedBins) {
128
- this.sortedBins = this.aggregatedBins.sort((a, b) => ascending(a.value, b.value));
129
- }
130
- if (!this.sortedBins.length) {
131
- // @ts-expect-error
132
- return [];
133
- }
134
- let lowerIdx = 0;
135
- let upperIdx = this.sortedBins.length - 1;
136
- if (Array.isArray(percentileRange)) {
137
- const idxRange = this._percentileToIndex(percentileRange);
138
- lowerIdx = idxRange[0];
139
- upperIdx = idxRange[1];
140
- }
141
- return [this.sortedBins[lowerIdx].value, this.sortedBins[upperIdx].value];
142
- }
143
- getValueDomainByScale(scale, [lower = 0, upper = 100] = []) {
144
- if (!this.sortedBins) {
145
- this.sortedBins = this.aggregatedBins.sort((a, b) => ascending(a.value, b.value));
146
- }
147
- if (!this.sortedBins.length) {
148
- return [];
149
- }
150
- const indexEdge = this._percentileToIndex([lower, upper]);
151
- return this._getScaleDomain(scale, indexEdge);
152
- }
153
- _getScaleDomain(scaleType, [lowerIdx, upperIdx]) {
154
- const bins = this.sortedBins;
155
- switch (scaleType) {
156
- case 'quantize':
157
- case 'linear':
158
- return [bins[lowerIdx].value, bins[upperIdx].value];
159
- case 'quantile':
160
- return getQuantileDomain(bins.slice(lowerIdx, upperIdx + 1), d => d.value);
161
- case 'ordinal':
162
- return getOrdinalDomain(bins, d => d.value);
163
- default:
164
- return [bins[lowerIdx].value, bins[upperIdx].value];
165
- }
166
- }
167
- }
@@ -1,53 +0,0 @@
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
- export const defaultColorRange = [
21
- [255, 255, 178],
22
- [254, 217, 118],
23
- [254, 178, 76],
24
- [253, 141, 60],
25
- [240, 59, 32],
26
- [189, 0, 38]
27
- ];
28
- // Converts a colorRange array to a flat array with 4 components per color
29
- export function colorRangeToFlatArray(colorRange, normalize = false, ArrayType = Float32Array) {
30
- let flatArray;
31
- if (Number.isFinite(colorRange[0])) {
32
- // its already a flat array.
33
- flatArray = new ArrayType(colorRange);
34
- }
35
- else {
36
- // flatten it
37
- flatArray = new ArrayType(colorRange.length * 4);
38
- let index = 0;
39
- for (let i = 0; i < colorRange.length; i++) {
40
- const color = colorRange[i];
41
- flatArray[index++] = color[0];
42
- flatArray[index++] = color[1];
43
- flatArray[index++] = color[2];
44
- flatArray[index++] = Number.isFinite(color[3]) ? color[3] : 255;
45
- }
46
- }
47
- if (normalize) {
48
- for (let i = 0; i < flatArray.length; i++) {
49
- flatArray[i] /= 255;
50
- }
51
- }
52
- return flatArray;
53
- }