@deck.gl/aggregation-layers 8.8.0-alpha.6 → 8.8.0-beta.1

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 (229) hide show
  1. package/dist/dist.dev.js +757 -645
  2. package/dist/es5/aggregation-layer.js +19 -7
  3. package/dist/es5/aggregation-layer.js.map +1 -1
  4. package/dist/es5/contour-layer/contour-layer.js +5 -5
  5. package/dist/es5/contour-layer/contour-layer.js.map +1 -1
  6. package/dist/es5/contour-layer/contour-utils.js +1 -1
  7. package/dist/es5/contour-layer/contour-utils.js.map +1 -1
  8. package/dist/es5/contour-layer/marching-squares-codes.js.map +1 -1
  9. package/dist/es5/contour-layer/marching-squares.js.map +1 -1
  10. package/dist/es5/cpu-grid-layer/cpu-grid-layer.js +5 -3
  11. package/dist/es5/cpu-grid-layer/cpu-grid-layer.js.map +1 -1
  12. package/dist/es5/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.js +1 -1
  13. package/dist/es5/gpu-grid-layer/gpu-grid-cell-layer.js +8 -8
  14. package/dist/es5/gpu-grid-layer/gpu-grid-cell-layer.js.map +1 -1
  15. package/dist/es5/gpu-grid-layer/gpu-grid-layer.js +12 -12
  16. package/dist/es5/gpu-grid-layer/gpu-grid-layer.js.map +1 -1
  17. package/dist/es5/grid-aggregation-layer.js +25 -12
  18. package/dist/es5/grid-aggregation-layer.js.map +1 -1
  19. package/dist/es5/grid-layer/grid-layer.js +18 -9
  20. package/dist/es5/grid-layer/grid-layer.js.map +1 -1
  21. package/dist/es5/heatmap-layer/heatmap-layer-utils.js.map +1 -1
  22. package/dist/es5/heatmap-layer/heatmap-layer.js +17 -6
  23. package/dist/es5/heatmap-layer/heatmap-layer.js.map +1 -1
  24. package/dist/es5/heatmap-layer/max-vs.glsl.js +1 -1
  25. package/dist/es5/heatmap-layer/triangle-layer-fragment.glsl.js +1 -1
  26. package/dist/es5/heatmap-layer/triangle-layer-vertex.glsl.js +1 -1
  27. package/dist/es5/heatmap-layer/triangle-layer.js +7 -7
  28. package/dist/es5/heatmap-layer/triangle-layer.js.map +1 -1
  29. package/dist/es5/heatmap-layer/weights-fs.glsl.js +1 -1
  30. package/dist/es5/heatmap-layer/weights-vs.glsl.js +1 -1
  31. package/dist/es5/hexagon-layer/hexagon-layer.js +16 -5
  32. package/dist/es5/hexagon-layer/hexagon-layer.js.map +1 -1
  33. package/dist/es5/index.js.map +1 -1
  34. package/dist/es5/screen-grid-layer/screen-grid-cell-layer.js +26 -19
  35. package/dist/es5/screen-grid-layer/screen-grid-cell-layer.js.map +1 -1
  36. package/dist/es5/screen-grid-layer/screen-grid-layer-vertex.glsl.js +1 -1
  37. package/dist/es5/screen-grid-layer/screen-grid-layer.js +18 -8
  38. package/dist/es5/screen-grid-layer/screen-grid-layer.js.map +1 -1
  39. package/dist/es5/types.js +2 -0
  40. package/dist/es5/types.js.map +1 -0
  41. package/dist/es5/utils/bin-sorter.js +9 -0
  42. package/dist/es5/utils/bin-sorter.js.map +1 -1
  43. package/dist/esm/aggregation-layer.js +12 -5
  44. package/dist/esm/aggregation-layer.js.map +1 -1
  45. package/dist/esm/contour-layer/contour-layer.js +6 -3
  46. package/dist/esm/contour-layer/contour-layer.js.map +1 -1
  47. package/dist/esm/contour-layer/contour-utils.js +1 -1
  48. package/dist/esm/contour-layer/contour-utils.js.map +1 -1
  49. package/dist/esm/contour-layer/marching-squares-codes.js.map +1 -1
  50. package/dist/esm/contour-layer/marching-squares.js.map +1 -1
  51. package/dist/esm/cpu-grid-layer/cpu-grid-layer.js +6 -3
  52. package/dist/esm/cpu-grid-layer/cpu-grid-layer.js.map +1 -1
  53. package/dist/esm/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.js.map +1 -1
  54. package/dist/esm/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.js +1 -1
  55. package/dist/esm/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.js.map +1 -1
  56. package/dist/esm/gpu-grid-layer/gpu-grid-cell-layer.js +8 -6
  57. package/dist/esm/gpu-grid-layer/gpu-grid-cell-layer.js.map +1 -1
  58. package/dist/esm/gpu-grid-layer/gpu-grid-layer.js +11 -9
  59. package/dist/esm/gpu-grid-layer/gpu-grid-layer.js.map +1 -1
  60. package/dist/esm/grid-aggregation-layer.js +13 -5
  61. package/dist/esm/grid-aggregation-layer.js.map +1 -1
  62. package/dist/esm/grid-layer/grid-layer.js +15 -8
  63. package/dist/esm/grid-layer/grid-layer.js.map +1 -1
  64. package/dist/esm/heatmap-layer/heatmap-layer-utils.js.map +1 -1
  65. package/dist/esm/heatmap-layer/heatmap-layer.js +22 -13
  66. package/dist/esm/heatmap-layer/heatmap-layer.js.map +1 -1
  67. package/dist/esm/heatmap-layer/max-fs.glsl.js.map +1 -1
  68. package/dist/esm/heatmap-layer/max-vs.glsl.js +1 -1
  69. package/dist/esm/heatmap-layer/max-vs.glsl.js.map +1 -1
  70. package/dist/esm/heatmap-layer/triangle-layer-fragment.glsl.js +1 -1
  71. package/dist/esm/heatmap-layer/triangle-layer-fragment.glsl.js.map +1 -1
  72. package/dist/esm/heatmap-layer/triangle-layer-vertex.glsl.js +1 -1
  73. package/dist/esm/heatmap-layer/triangle-layer-vertex.glsl.js.map +1 -1
  74. package/dist/esm/heatmap-layer/triangle-layer.js +6 -5
  75. package/dist/esm/heatmap-layer/triangle-layer.js.map +1 -1
  76. package/dist/esm/heatmap-layer/weights-fs.glsl.js +1 -1
  77. package/dist/esm/heatmap-layer/weights-fs.glsl.js.map +1 -1
  78. package/dist/esm/heatmap-layer/weights-vs.glsl.js +1 -1
  79. package/dist/esm/heatmap-layer/weights-vs.glsl.js.map +1 -1
  80. package/dist/esm/hexagon-layer/hexagon-layer.js +11 -2
  81. package/dist/esm/hexagon-layer/hexagon-layer.js.map +1 -1
  82. package/dist/esm/index.js.map +1 -1
  83. package/dist/esm/screen-grid-layer/screen-grid-cell-layer.js +16 -10
  84. package/dist/esm/screen-grid-layer/screen-grid-cell-layer.js.map +1 -1
  85. package/dist/esm/screen-grid-layer/screen-grid-layer-fragment.glsl.js.map +1 -1
  86. package/dist/esm/screen-grid-layer/screen-grid-layer-vertex.glsl.js +1 -1
  87. package/dist/esm/screen-grid-layer/screen-grid-layer-vertex.glsl.js.map +1 -1
  88. package/dist/esm/screen-grid-layer/screen-grid-layer.js +15 -7
  89. package/dist/esm/screen-grid-layer/screen-grid-layer.js.map +1 -1
  90. package/dist/esm/types.js +2 -0
  91. package/dist/esm/types.js.map +1 -0
  92. package/dist/esm/utils/bin-sorter.js +16 -0
  93. package/dist/esm/utils/bin-sorter.js.map +1 -1
  94. package/dist.min.js +1 -1
  95. package/package.json +6 -4
  96. package/src/{aggregation-layer.js → aggregation-layer.ts} +32 -15
  97. package/src/contour-layer/{contour-layer.js → contour-layer.ts} +95 -15
  98. package/src/contour-layer/{contour-utils.js → contour-utils.ts} +11 -5
  99. package/src/contour-layer/{marching-squares-codes.js → marching-squares-codes.ts} +0 -0
  100. package/src/contour-layer/{marching-squares.js → marching-squares.ts} +6 -6
  101. package/src/cpu-grid-layer/cpu-grid-layer.ts +310 -0
  102. package/src/gpu-grid-layer/{gpu-grid-cell-layer-fragment.glsl.js → gpu-grid-cell-layer-fragment.glsl.ts} +0 -0
  103. package/src/gpu-grid-layer/{gpu-grid-cell-layer-vertex.glsl.js → gpu-grid-cell-layer-vertex.glsl.ts} +0 -0
  104. package/src/gpu-grid-layer/{gpu-grid-cell-layer.js → gpu-grid-cell-layer.ts} +22 -14
  105. package/src/gpu-grid-layer/{gpu-grid-layer.js → gpu-grid-layer.ts} +122 -17
  106. package/src/{grid-aggregation-layer.js → grid-aggregation-layer.ts} +25 -13
  107. package/src/grid-layer/{grid-layer.js → grid-layer.ts} +38 -13
  108. package/src/heatmap-layer/{heatmap-layer-utils.js → heatmap-layer-utils.ts} +5 -5
  109. package/src/heatmap-layer/{heatmap-layer.js → heatmap-layer.ts} +138 -29
  110. package/src/heatmap-layer/{max-fs.glsl.js → max-fs.glsl.ts} +0 -0
  111. package/src/heatmap-layer/{max-vs.glsl.js → max-vs.glsl.ts} +0 -0
  112. package/src/heatmap-layer/{triangle-layer-fragment.glsl.js → triangle-layer-fragment.glsl.ts} +0 -0
  113. package/src/heatmap-layer/{triangle-layer-vertex.glsl.js → triangle-layer-vertex.glsl.ts} +0 -0
  114. package/src/heatmap-layer/{triangle-layer.js → triangle-layer.ts} +20 -10
  115. package/src/heatmap-layer/{weights-fs.glsl.js → weights-fs.glsl.ts} +0 -0
  116. package/src/heatmap-layer/{weights-vs.glsl.js → weights-vs.glsl.ts} +0 -0
  117. package/src/hexagon-layer/{hexagon-layer.js → hexagon-layer.ts} +174 -9
  118. package/src/index.ts +9 -0
  119. package/src/screen-grid-layer/{screen-grid-cell-layer.js → screen-grid-cell-layer.ts} +31 -14
  120. package/src/screen-grid-layer/{screen-grid-layer-fragment.glsl.js → screen-grid-layer-fragment.glsl.ts} +0 -0
  121. package/src/screen-grid-layer/{screen-grid-layer-vertex.glsl.js → screen-grid-layer-vertex.glsl.ts} +0 -0
  122. package/src/screen-grid-layer/{screen-grid-layer.js → screen-grid-layer.ts} +117 -15
  123. package/src/types.ts +10 -0
  124. package/src/utils/{bin-sorter.js → bin-sorter.ts} +26 -11
  125. package/typed/aggregation-layer.d.ts +16 -11
  126. package/typed/aggregation-layer.d.ts.map +1 -1
  127. package/typed/aggregation-layer.js +151 -0
  128. package/typed/contour-layer/contour-layer.d.ts +92 -36
  129. package/typed/contour-layer/contour-layer.d.ts.map +1 -1
  130. package/typed/contour-layer/contour-layer.js +234 -0
  131. package/typed/contour-layer/contour-utils.d.ts +8 -9
  132. package/typed/contour-layer/contour-utils.d.ts.map +1 -1
  133. package/typed/contour-layer/contour-utils.js +64 -0
  134. package/typed/contour-layer/marching-squares-codes.d.ts +2 -2
  135. package/typed/contour-layer/marching-squares-codes.d.ts.map +1 -1
  136. package/typed/contour-layer/marching-squares-codes.js +337 -0
  137. package/typed/contour-layer/marching-squares.d.ts +6 -6
  138. package/typed/contour-layer/marching-squares.d.ts.map +1 -1
  139. package/typed/contour-layer/marching-squares.js +147 -0
  140. package/typed/cpu-grid-layer/cpu-grid-layer.d.ts +221 -126
  141. package/typed/cpu-grid-layer/cpu-grid-layer.d.ts.map +1 -1
  142. package/typed/cpu-grid-layer/cpu-grid-layer.js +129 -0
  143. package/typed/cpu-grid-layer/grid-aggregator.js +141 -0
  144. package/typed/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.d.ts +1 -1
  145. package/typed/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.d.ts.map +1 -1
  146. package/typed/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.js +34 -0
  147. package/typed/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.d.ts +1 -1
  148. package/typed/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.d.ts.map +1 -1
  149. package/typed/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.js +141 -0
  150. package/typed/gpu-grid-layer/gpu-grid-cell-layer.d.ts +67 -81
  151. package/typed/gpu-grid-layer/gpu-grid-cell-layer.d.ts.map +1 -1
  152. package/typed/gpu-grid-layer/gpu-grid-cell-layer.js +143 -0
  153. package/typed/gpu-grid-layer/gpu-grid-layer.d.ts +131 -62
  154. package/typed/gpu-grid-layer/gpu-grid-layer.d.ts.map +1 -1
  155. package/typed/gpu-grid-layer/gpu-grid-layer.js +289 -0
  156. package/typed/grid-aggregation-layer.d.ts +19 -6
  157. package/typed/grid-aggregation-layer.d.ts.map +1 -1
  158. package/typed/grid-aggregation-layer.js +172 -0
  159. package/typed/grid-layer/grid-layer.d.ts +109 -90
  160. package/typed/grid-layer/grid-layer.d.ts.map +1 -1
  161. package/typed/grid-layer/grid-layer.js +60 -0
  162. package/typed/heatmap-layer/heatmap-layer-utils.d.ts +6 -6
  163. package/typed/heatmap-layer/heatmap-layer-utils.d.ts.map +1 -1
  164. package/typed/heatmap-layer/heatmap-layer-utils.js +78 -0
  165. package/typed/heatmap-layer/heatmap-layer.d.ts +147 -82
  166. package/typed/heatmap-layer/heatmap-layer.d.ts.map +1 -1
  167. package/typed/heatmap-layer/heatmap-layer.js +478 -0
  168. package/typed/heatmap-layer/max-fs.glsl.d.ts +1 -1
  169. package/typed/heatmap-layer/max-fs.glsl.d.ts.map +1 -1
  170. package/typed/heatmap-layer/max-fs.glsl.js +7 -0
  171. package/typed/heatmap-layer/max-vs.glsl.d.ts +1 -1
  172. package/typed/heatmap-layer/max-vs.glsl.d.ts.map +1 -1
  173. package/typed/heatmap-layer/max-vs.glsl.js +12 -0
  174. package/typed/heatmap-layer/triangle-layer-fragment.glsl.d.ts +1 -1
  175. package/typed/heatmap-layer/triangle-layer-fragment.glsl.d.ts.map +1 -1
  176. package/typed/heatmap-layer/triangle-layer-fragment.glsl.js +58 -0
  177. package/typed/heatmap-layer/triangle-layer-vertex.glsl.d.ts +1 -1
  178. package/typed/heatmap-layer/triangle-layer-vertex.glsl.d.ts.map +1 -1
  179. package/typed/heatmap-layer/triangle-layer-vertex.glsl.js +51 -0
  180. package/typed/heatmap-layer/triangle-layer.d.ts +25 -8
  181. package/typed/heatmap-layer/triangle-layer.d.ts.map +1 -1
  182. package/typed/heatmap-layer/triangle-layer.js +67 -0
  183. package/typed/heatmap-layer/weights-fs.glsl.d.ts +1 -1
  184. package/typed/heatmap-layer/weights-fs.glsl.d.ts.map +1 -1
  185. package/typed/heatmap-layer/weights-fs.glsl.js +19 -0
  186. package/typed/heatmap-layer/weights-vs.glsl.d.ts +1 -1
  187. package/typed/heatmap-layer/weights-vs.glsl.d.ts.map +1 -1
  188. package/typed/heatmap-layer/weights-vs.glsl.js +23 -0
  189. package/typed/hexagon-layer/hexagon-aggregator.js +112 -0
  190. package/typed/hexagon-layer/hexagon-layer.d.ts +232 -125
  191. package/typed/hexagon-layer/hexagon-layer.d.ts.map +1 -1
  192. package/typed/hexagon-layer/hexagon-layer.js +171 -0
  193. package/typed/index.d.ts +7 -0
  194. package/typed/index.d.ts.map +1 -1
  195. package/typed/index.js +33 -0
  196. package/typed/screen-grid-layer/screen-grid-cell-layer.d.ts +46 -25
  197. package/typed/screen-grid-layer/screen-grid-cell-layer.d.ts.map +1 -1
  198. package/typed/screen-grid-layer/screen-grid-cell-layer.js +159 -0
  199. package/typed/screen-grid-layer/screen-grid-layer-fragment.glsl.d.ts +1 -1
  200. package/typed/screen-grid-layer/screen-grid-layer-fragment.glsl.d.ts.map +1 -1
  201. package/typed/screen-grid-layer/screen-grid-layer-fragment.glsl.js +37 -0
  202. package/typed/screen-grid-layer/screen-grid-layer-vertex.glsl.d.ts +1 -1
  203. package/typed/screen-grid-layer/screen-grid-layer-vertex.glsl.d.ts.map +1 -1
  204. package/typed/screen-grid-layer/screen-grid-layer-vertex.glsl.js +83 -0
  205. package/typed/screen-grid-layer/screen-grid-layer.d.ts +113 -30
  206. package/typed/screen-grid-layer/screen-grid-layer.d.ts.map +1 -1
  207. package/typed/screen-grid-layer/screen-grid-layer.js +216 -0
  208. package/typed/types.d.ts +11 -0
  209. package/typed/types.d.ts.map +1 -0
  210. package/typed/types.js +1 -0
  211. package/typed/utils/aggregation-operation-utils.js +94 -0
  212. package/typed/utils/bin-sorter.d.ts +27 -21
  213. package/typed/utils/bin-sorter.d.ts.map +1 -1
  214. package/typed/utils/bin-sorter.js +167 -0
  215. package/typed/utils/color-utils.js +53 -0
  216. package/typed/utils/cpu-aggregator.js +417 -0
  217. package/typed/utils/gpu-grid-aggregation/aggregate-all-fs.glsl.js +39 -0
  218. package/typed/utils/gpu-grid-aggregation/aggregate-all-vs.glsl.js +53 -0
  219. package/typed/utils/gpu-grid-aggregation/aggregate-to-grid-fs.glsl.js +31 -0
  220. package/typed/utils/gpu-grid-aggregation/aggregate-to-grid-vs.glsl.js +77 -0
  221. package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator-constants.js +41 -0
  222. package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator-utils.js +1 -0
  223. package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator.js +562 -0
  224. package/typed/utils/gpu-grid-aggregation/transform-mean-vs.glsl.js +36 -0
  225. package/typed/utils/grid-aggregation-utils.js +114 -0
  226. package/typed/utils/prop-utils.js +28 -0
  227. package/typed/utils/resource-utils.js +40 -0
  228. package/typed/utils/scale-utils.js +184 -0
  229. package/src/cpu-grid-layer/cpu-grid-layer.js +0 -153
@@ -0,0 +1,167 @@
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
+ }
@@ -0,0 +1,53 @@
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
+ }
@@ -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
+ `;