@deck.gl/aggregation-layers 9.0.34 → 9.1.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 (318) hide show
  1. package/dist/common/aggregation-layer.d.ts +30 -0
  2. package/dist/common/aggregation-layer.d.ts.map +1 -0
  3. package/dist/common/aggregation-layer.js +69 -0
  4. package/dist/common/aggregator/aggregator.d.ts +76 -0
  5. package/dist/common/aggregator/aggregator.d.ts.map +1 -0
  6. package/dist/common/aggregator/aggregator.js +4 -0
  7. package/dist/common/aggregator/cpu-aggregator/aggregate.d.ts +27 -0
  8. package/dist/common/aggregator/cpu-aggregator/aggregate.d.ts.map +1 -0
  9. package/dist/common/aggregator/cpu-aggregator/aggregate.js +66 -0
  10. package/dist/common/aggregator/cpu-aggregator/cpu-aggregator.d.ts +70 -0
  11. package/dist/common/aggregator/cpu-aggregator/cpu-aggregator.d.ts.map +1 -0
  12. package/dist/common/aggregator/cpu-aggregator/cpu-aggregator.js +139 -0
  13. package/dist/common/aggregator/cpu-aggregator/sort-bins.d.ts +15 -0
  14. package/dist/common/aggregator/cpu-aggregator/sort-bins.d.ts.map +1 -0
  15. package/dist/common/aggregator/cpu-aggregator/sort-bins.js +43 -0
  16. package/dist/common/aggregator/cpu-aggregator/vertex-accessor.d.ts +21 -0
  17. package/dist/common/aggregator/cpu-aggregator/vertex-accessor.d.ts.map +1 -0
  18. package/dist/common/aggregator/cpu-aggregator/vertex-accessor.js +55 -0
  19. package/dist/common/aggregator/gpu-aggregator/aggregation-transform-uniforms.d.ts +18 -0
  20. package/dist/common/aggregator/gpu-aggregator/aggregation-transform-uniforms.d.ts.map +1 -0
  21. package/dist/common/aggregator/gpu-aggregator/aggregation-transform-uniforms.js +20 -0
  22. package/dist/common/aggregator/gpu-aggregator/bin-sorter-uniforms.d.ts +14 -0
  23. package/dist/common/aggregator/gpu-aggregator/bin-sorter-uniforms.d.ts.map +1 -0
  24. package/dist/common/aggregator/gpu-aggregator/bin-sorter-uniforms.js +17 -0
  25. package/dist/common/aggregator/gpu-aggregator/utils.d.ts +6 -0
  26. package/dist/common/aggregator/gpu-aggregator/utils.d.ts.map +1 -0
  27. package/dist/common/aggregator/gpu-aggregator/utils.js +24 -0
  28. package/dist/common/aggregator/gpu-aggregator/webgl-aggregation-transform.d.ts +24 -0
  29. package/dist/common/aggregator/gpu-aggregator/webgl-aggregation-transform.d.ts.map +1 -0
  30. package/dist/common/aggregator/gpu-aggregator/webgl-aggregation-transform.js +215 -0
  31. package/dist/common/aggregator/gpu-aggregator/webgl-aggregator.d.ts +81 -0
  32. package/dist/common/aggregator/gpu-aggregator/webgl-aggregator.d.ts.map +1 -0
  33. package/dist/common/aggregator/gpu-aggregator/webgl-aggregator.js +201 -0
  34. package/dist/common/aggregator/gpu-aggregator/webgl-bin-sorter.d.ts +38 -0
  35. package/dist/common/aggregator/gpu-aggregator/webgl-bin-sorter.d.ts.map +1 -0
  36. package/dist/common/aggregator/gpu-aggregator/webgl-bin-sorter.js +223 -0
  37. package/dist/common/aggregator/index.d.ts +6 -0
  38. package/dist/common/aggregator/index.d.ts.map +1 -0
  39. package/dist/common/aggregator/index.js +5 -0
  40. package/dist/common/types.d.ts +11 -0
  41. package/dist/common/types.d.ts.map +1 -0
  42. package/dist/common/types.js +4 -0
  43. package/dist/common/utils/bounds-utils.d.ts +10 -0
  44. package/dist/common/utils/bounds-utils.d.ts.map +1 -0
  45. package/dist/common/utils/bounds-utils.js +20 -0
  46. package/dist/common/utils/color-utils.d.ts +10 -0
  47. package/dist/common/utils/color-utils.d.ts.map +1 -0
  48. package/dist/common/utils/color-utils.js +65 -0
  49. package/dist/common/utils/prop-utils.d.ts.map +1 -0
  50. package/dist/common/utils/prop-utils.js +12 -0
  51. package/dist/common/utils/scale-utils.d.ts +46 -0
  52. package/dist/common/utils/scale-utils.d.ts.map +1 -0
  53. package/dist/common/utils/scale-utils.js +180 -0
  54. package/dist/contour-layer/bin-options-uniforms.d.ts +13 -0
  55. package/dist/contour-layer/bin-options-uniforms.d.ts.map +1 -0
  56. package/dist/contour-layer/bin-options-uniforms.js +17 -0
  57. package/dist/contour-layer/contour-layer.d.ts +42 -50
  58. package/dist/contour-layer/contour-layer.d.ts.map +1 -1
  59. package/dist/contour-layer/contour-layer.js +232 -192
  60. package/dist/contour-layer/contour-utils.d.ts +36 -15
  61. package/dist/contour-layer/contour-utils.d.ts.map +1 -1
  62. package/dist/contour-layer/contour-utils.js +24 -29
  63. package/dist/contour-layer/marching-squares-codes.d.ts.map +1 -1
  64. package/dist/contour-layer/marching-squares-codes.js +3 -0
  65. package/dist/contour-layer/marching-squares.d.ts +22 -6
  66. package/dist/contour-layer/marching-squares.d.ts.map +1 -1
  67. package/dist/contour-layer/marching-squares.js +71 -68
  68. package/dist/contour-layer/value-reader.d.ts +10 -0
  69. package/dist/contour-layer/value-reader.d.ts.map +1 -0
  70. package/dist/contour-layer/value-reader.js +46 -0
  71. package/dist/dist.dev.js +4842 -4081
  72. package/dist/grid-layer/bin-options-uniforms.d.ts +13 -0
  73. package/dist/grid-layer/bin-options-uniforms.d.ts.map +1 -0
  74. package/dist/grid-layer/bin-options-uniforms.js +17 -0
  75. package/dist/grid-layer/grid-cell-layer-vertex.glsl.d.ts +3 -0
  76. package/dist/grid-layer/grid-cell-layer-vertex.glsl.d.ts.map +1 -0
  77. package/dist/grid-layer/grid-cell-layer-vertex.glsl.js +51 -0
  78. package/dist/grid-layer/grid-cell-layer.d.ts +32 -0
  79. package/dist/grid-layer/grid-cell-layer.d.ts.map +1 -0
  80. package/dist/grid-layer/grid-cell-layer.js +93 -0
  81. package/dist/grid-layer/grid-layer-uniforms.d.ts +21 -0
  82. package/dist/grid-layer/grid-layer-uniforms.d.ts.map +1 -0
  83. package/dist/grid-layer/grid-layer-uniforms.js +23 -0
  84. package/dist/grid-layer/grid-layer.d.ts +175 -13
  85. package/dist/grid-layer/grid-layer.d.ts.map +1 -1
  86. package/dist/grid-layer/grid-layer.js +342 -46
  87. package/dist/{aggregation-layer.d.ts → heatmap-layer/aggregation-layer.d.ts} +1 -0
  88. package/dist/heatmap-layer/aggregation-layer.d.ts.map +1 -0
  89. package/dist/{aggregation-layer.js → heatmap-layer/aggregation-layer.js} +6 -21
  90. package/dist/heatmap-layer/heatmap-layer-uniforms.d.ts +30 -0
  91. package/dist/heatmap-layer/heatmap-layer-uniforms.d.ts.map +1 -0
  92. package/dist/heatmap-layer/heatmap-layer-uniforms.js +32 -0
  93. package/dist/heatmap-layer/heatmap-layer-utils.d.ts +1 -1
  94. package/dist/heatmap-layer/heatmap-layer-utils.d.ts.map +1 -1
  95. package/dist/heatmap-layer/heatmap-layer-utils.js +3 -0
  96. package/dist/heatmap-layer/heatmap-layer.d.ts +6 -4
  97. package/dist/heatmap-layer/heatmap-layer.d.ts.map +1 -1
  98. package/dist/heatmap-layer/heatmap-layer.js +43 -33
  99. package/dist/heatmap-layer/max-fs.glsl.d.ts.map +1 -1
  100. package/dist/heatmap-layer/max-fs.glsl.js +3 -0
  101. package/dist/heatmap-layer/max-vs.glsl.d.ts +1 -1
  102. package/dist/heatmap-layer/max-vs.glsl.d.ts.map +1 -1
  103. package/dist/heatmap-layer/max-vs.glsl.js +6 -4
  104. package/dist/heatmap-layer/triangle-layer-fragment.glsl.d.ts +1 -1
  105. package/dist/heatmap-layer/triangle-layer-fragment.glsl.d.ts.map +1 -1
  106. package/dist/heatmap-layer/triangle-layer-fragment.glsl.js +5 -23
  107. package/dist/heatmap-layer/triangle-layer-uniforms.d.ts +22 -0
  108. package/dist/heatmap-layer/triangle-layer-uniforms.d.ts.map +1 -0
  109. package/dist/heatmap-layer/triangle-layer-uniforms.js +22 -0
  110. package/dist/heatmap-layer/triangle-layer-vertex.glsl.d.ts +1 -1
  111. package/dist/heatmap-layer/triangle-layer-vertex.glsl.d.ts.map +1 -1
  112. package/dist/heatmap-layer/triangle-layer-vertex.glsl.js +10 -30
  113. package/dist/heatmap-layer/triangle-layer.d.ts +4 -10
  114. package/dist/heatmap-layer/triangle-layer.d.ts.map +1 -1
  115. package/dist/heatmap-layer/triangle-layer.js +17 -30
  116. package/dist/heatmap-layer/weights-fs.glsl.d.ts.map +1 -1
  117. package/dist/heatmap-layer/weights-fs.glsl.js +3 -0
  118. package/dist/heatmap-layer/weights-vs.glsl.d.ts +1 -1
  119. package/dist/heatmap-layer/weights-vs.glsl.d.ts.map +1 -1
  120. package/dist/heatmap-layer/weights-vs.glsl.js +6 -7
  121. package/dist/hexagon-layer/bin-options-uniforms.d.ts +14 -0
  122. package/dist/hexagon-layer/bin-options-uniforms.d.ts.map +1 -0
  123. package/dist/hexagon-layer/bin-options-uniforms.js +17 -0
  124. package/dist/hexagon-layer/hexagon-cell-layer-vertex.glsl.d.ts +3 -0
  125. package/dist/hexagon-layer/hexagon-cell-layer-vertex.glsl.d.ts.map +1 -0
  126. package/dist/hexagon-layer/hexagon-cell-layer-vertex.glsl.js +55 -0
  127. package/dist/hexagon-layer/hexagon-cell-layer.d.ts +29 -0
  128. package/dist/hexagon-layer/hexagon-cell-layer.d.ts.map +1 -0
  129. package/dist/hexagon-layer/hexagon-cell-layer.js +94 -0
  130. package/dist/hexagon-layer/hexagon-layer-uniforms.d.ts +19 -0
  131. package/dist/hexagon-layer/hexagon-layer-uniforms.d.ts.map +1 -0
  132. package/dist/hexagon-layer/hexagon-layer-uniforms.js +21 -0
  133. package/dist/hexagon-layer/hexagon-layer.d.ts +84 -54
  134. package/dist/hexagon-layer/hexagon-layer.d.ts.map +1 -1
  135. package/dist/hexagon-layer/hexagon-layer.js +307 -123
  136. package/dist/hexagon-layer/hexbin.d.ts +17 -0
  137. package/dist/hexagon-layer/hexbin.d.ts.map +1 -0
  138. package/dist/hexagon-layer/hexbin.js +69 -0
  139. package/dist/index.cjs +3025 -2946
  140. package/dist/index.cjs.map +4 -4
  141. package/dist/index.d.ts +7 -13
  142. package/dist/index.d.ts.map +1 -1
  143. package/dist/index.js +5 -27
  144. package/dist/screen-grid-layer/bin-options-uniforms.d.ts +11 -0
  145. package/dist/screen-grid-layer/bin-options-uniforms.d.ts.map +1 -0
  146. package/dist/screen-grid-layer/bin-options-uniforms.js +15 -0
  147. package/dist/screen-grid-layer/screen-grid-cell-layer.d.ts +11 -16
  148. package/dist/screen-grid-layer/screen-grid-cell-layer.d.ts.map +1 -1
  149. package/dist/screen-grid-layer/screen-grid-cell-layer.js +52 -134
  150. package/dist/screen-grid-layer/screen-grid-layer-fragment.glsl.d.ts +1 -1
  151. package/dist/screen-grid-layer/screen-grid-layer-fragment.glsl.d.ts.map +1 -1
  152. package/dist/screen-grid-layer/screen-grid-layer-fragment.glsl.js +4 -24
  153. package/dist/screen-grid-layer/screen-grid-layer-uniforms.d.ts +17 -0
  154. package/dist/screen-grid-layer/screen-grid-layer-uniforms.d.ts.map +1 -0
  155. package/dist/screen-grid-layer/screen-grid-layer-uniforms.js +19 -0
  156. package/dist/screen-grid-layer/screen-grid-layer-vertex.glsl.d.ts +1 -1
  157. package/dist/screen-grid-layer/screen-grid-layer-vertex.glsl.d.ts.map +1 -1
  158. package/dist/screen-grid-layer/screen-grid-layer-vertex.glsl.js +21 -62
  159. package/dist/screen-grid-layer/screen-grid-layer.d.ts +33 -40
  160. package/dist/screen-grid-layer/screen-grid-layer.d.ts.map +1 -1
  161. package/dist/screen-grid-layer/screen-grid-layer.js +157 -174
  162. package/dist.min.js +401 -382
  163. package/package.json +10 -9
  164. package/src/common/aggregation-layer.ts +107 -0
  165. package/src/common/aggregator/aggregator.ts +88 -0
  166. package/src/common/aggregator/cpu-aggregator/aggregate.ts +101 -0
  167. package/src/common/aggregator/cpu-aggregator/cpu-aggregator.ts +203 -0
  168. package/src/common/aggregator/cpu-aggregator/sort-bins.ts +63 -0
  169. package/src/common/aggregator/cpu-aggregator/vertex-accessor.ts +86 -0
  170. package/src/common/aggregator/gpu-aggregator/aggregation-transform-uniforms.ts +33 -0
  171. package/src/common/aggregator/gpu-aggregator/bin-sorter-uniforms.ts +27 -0
  172. package/src/common/aggregator/gpu-aggregator/utils.ts +27 -0
  173. package/src/common/aggregator/gpu-aggregator/webgl-aggregation-transform.ts +247 -0
  174. package/src/common/aggregator/gpu-aggregator/webgl-aggregator.ts +274 -0
  175. package/src/common/aggregator/gpu-aggregator/webgl-bin-sorter.ts +258 -0
  176. package/src/common/aggregator/index.ts +10 -0
  177. package/src/{types.ts → common/types.ts} +10 -4
  178. package/src/common/utils/bounds-utils.ts +34 -0
  179. package/src/common/utils/color-utils.ts +86 -0
  180. package/src/common/utils/prop-utils.ts +13 -0
  181. package/src/common/utils/scale-utils.ts +236 -0
  182. package/src/contour-layer/bin-options-uniforms.ts +26 -0
  183. package/src/contour-layer/contour-layer.ts +300 -265
  184. package/src/contour-layer/contour-utils.ts +68 -39
  185. package/src/contour-layer/marching-squares-codes.ts +4 -0
  186. package/src/contour-layer/marching-squares.ts +93 -82
  187. package/src/contour-layer/value-reader.ts +65 -0
  188. package/src/grid-layer/bin-options-uniforms.ts +26 -0
  189. package/src/grid-layer/grid-cell-layer-vertex.glsl.ts +68 -0
  190. package/src/grid-layer/grid-cell-layer.ts +141 -0
  191. package/src/grid-layer/grid-layer-uniforms.ts +37 -0
  192. package/src/grid-layer/grid-layer.ts +614 -73
  193. package/src/{aggregation-layer.ts → heatmap-layer/aggregation-layer.ts} +6 -21
  194. package/src/heatmap-layer/heatmap-layer-uniforms.ts +50 -0
  195. package/src/heatmap-layer/heatmap-layer-utils.ts +9 -1
  196. package/src/heatmap-layer/heatmap-layer.ts +59 -36
  197. package/src/heatmap-layer/max-fs.glsl.ts +4 -0
  198. package/src/heatmap-layer/max-vs.glsl.ts +7 -4
  199. package/src/heatmap-layer/triangle-layer-fragment.glsl.ts +5 -23
  200. package/src/heatmap-layer/triangle-layer-uniforms.ts +37 -0
  201. package/src/heatmap-layer/triangle-layer-vertex.glsl.ts +10 -30
  202. package/src/heatmap-layer/triangle-layer.ts +26 -31
  203. package/src/heatmap-layer/weights-fs.glsl.ts +4 -0
  204. package/src/heatmap-layer/weights-vs.glsl.ts +7 -7
  205. package/src/hexagon-layer/bin-options-uniforms.ts +27 -0
  206. package/src/hexagon-layer/hexagon-cell-layer-vertex.glsl.ts +73 -0
  207. package/src/hexagon-layer/hexagon-cell-layer.ts +141 -0
  208. package/src/hexagon-layer/hexagon-layer-uniforms.ts +34 -0
  209. package/src/hexagon-layer/hexagon-layer.ts +454 -186
  210. package/src/hexagon-layer/hexbin.ts +79 -0
  211. package/src/index.ts +21 -34
  212. package/src/screen-grid-layer/bin-options-uniforms.ts +23 -0
  213. package/src/screen-grid-layer/screen-grid-cell-layer.ts +71 -156
  214. package/src/screen-grid-layer/screen-grid-layer-fragment.glsl.ts +4 -24
  215. package/src/screen-grid-layer/screen-grid-layer-uniforms.ts +31 -0
  216. package/src/screen-grid-layer/screen-grid-layer-vertex.glsl.ts +21 -64
  217. package/src/screen-grid-layer/screen-grid-layer.ts +194 -222
  218. package/dist/aggregation-layer.d.ts.map +0 -1
  219. package/dist/cpu-grid-layer/cpu-grid-layer.d.ts +0 -158
  220. package/dist/cpu-grid-layer/cpu-grid-layer.d.ts.map +0 -1
  221. package/dist/cpu-grid-layer/cpu-grid-layer.js +0 -130
  222. package/dist/cpu-grid-layer/grid-aggregator.d.ts +0 -35
  223. package/dist/cpu-grid-layer/grid-aggregator.d.ts.map +0 -1
  224. package/dist/cpu-grid-layer/grid-aggregator.js +0 -141
  225. package/dist/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.d.ts +0 -3
  226. package/dist/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.d.ts.map +0 -1
  227. package/dist/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.js +0 -30
  228. package/dist/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.d.ts +0 -3
  229. package/dist/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.d.ts.map +0 -1
  230. package/dist/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.js +0 -112
  231. package/dist/gpu-grid-layer/gpu-grid-cell-layer.d.ts +0 -48
  232. package/dist/gpu-grid-layer/gpu-grid-cell-layer.d.ts.map +0 -1
  233. package/dist/gpu-grid-layer/gpu-grid-cell-layer.js +0 -146
  234. package/dist/gpu-grid-layer/gpu-grid-layer.d.ts +0 -99
  235. package/dist/gpu-grid-layer/gpu-grid-layer.d.ts.map +0 -1
  236. package/dist/gpu-grid-layer/gpu-grid-layer.js +0 -289
  237. package/dist/grid-aggregation-layer.d.ts +0 -67
  238. package/dist/grid-aggregation-layer.d.ts.map +0 -1
  239. package/dist/grid-aggregation-layer.js +0 -173
  240. package/dist/hexagon-layer/hexagon-aggregator.d.ts +0 -27
  241. package/dist/hexagon-layer/hexagon-aggregator.d.ts.map +0 -1
  242. package/dist/hexagon-layer/hexagon-aggregator.js +0 -112
  243. package/dist/types.d.ts +0 -12
  244. package/dist/types.d.ts.map +0 -1
  245. package/dist/types.js +0 -1
  246. package/dist/utils/aggregation-operation-utils.d.ts +0 -19
  247. package/dist/utils/aggregation-operation-utils.d.ts.map +0 -1
  248. package/dist/utils/aggregation-operation-utils.js +0 -94
  249. package/dist/utils/bin-sorter.d.ts +0 -52
  250. package/dist/utils/bin-sorter.d.ts.map +0 -1
  251. package/dist/utils/bin-sorter.js +0 -167
  252. package/dist/utils/color-utils.d.ts +0 -3
  253. package/dist/utils/color-utils.d.ts.map +0 -1
  254. package/dist/utils/color-utils.js +0 -53
  255. package/dist/utils/cpu-aggregator.d.ts +0 -169
  256. package/dist/utils/cpu-aggregator.d.ts.map +0 -1
  257. package/dist/utils/cpu-aggregator.js +0 -421
  258. package/dist/utils/gpu-grid-aggregation/aggregate-all-fs.glsl.d.ts +0 -3
  259. package/dist/utils/gpu-grid-aggregation/aggregate-all-fs.glsl.d.ts.map +0 -1
  260. package/dist/utils/gpu-grid-aggregation/aggregate-all-fs.glsl.js +0 -36
  261. package/dist/utils/gpu-grid-aggregation/aggregate-all-vs.glsl.d.ts +0 -3
  262. package/dist/utils/gpu-grid-aggregation/aggregate-all-vs.glsl.d.ts.map +0 -1
  263. package/dist/utils/gpu-grid-aggregation/aggregate-all-vs.glsl.js +0 -42
  264. package/dist/utils/gpu-grid-aggregation/aggregate-to-grid-fs.glsl.d.ts +0 -3
  265. package/dist/utils/gpu-grid-aggregation/aggregate-to-grid-fs.glsl.d.ts.map +0 -1
  266. package/dist/utils/gpu-grid-aggregation/aggregate-to-grid-fs.glsl.js +0 -30
  267. package/dist/utils/gpu-grid-aggregation/aggregate-to-grid-vs.glsl.d.ts +0 -3
  268. package/dist/utils/gpu-grid-aggregation/aggregate-to-grid-vs.glsl.d.ts.map +0 -1
  269. package/dist/utils/gpu-grid-aggregation/aggregate-to-grid-vs.glsl.js +0 -61
  270. package/dist/utils/gpu-grid-aggregation/gpu-grid-aggregator-constants.d.ts +0 -38
  271. package/dist/utils/gpu-grid-aggregation/gpu-grid-aggregator-constants.d.ts.map +0 -1
  272. package/dist/utils/gpu-grid-aggregation/gpu-grid-aggregator-constants.js +0 -41
  273. package/dist/utils/gpu-grid-aggregation/gpu-grid-aggregator-utils.d.ts +0 -1
  274. package/dist/utils/gpu-grid-aggregation/gpu-grid-aggregator-utils.d.ts.map +0 -1
  275. package/dist/utils/gpu-grid-aggregation/gpu-grid-aggregator-utils.js +0 -1
  276. package/dist/utils/gpu-grid-aggregation/gpu-grid-aggregator.d.ts +0 -76
  277. package/dist/utils/gpu-grid-aggregation/gpu-grid-aggregator.d.ts.map +0 -1
  278. package/dist/utils/gpu-grid-aggregation/gpu-grid-aggregator.js +0 -555
  279. package/dist/utils/gpu-grid-aggregation/transform-mean-vs.glsl.d.ts +0 -3
  280. package/dist/utils/gpu-grid-aggregation/transform-mean-vs.glsl.d.ts.map +0 -1
  281. package/dist/utils/gpu-grid-aggregation/transform-mean-vs.glsl.js +0 -32
  282. package/dist/utils/grid-aggregation-utils.d.ts +0 -30
  283. package/dist/utils/grid-aggregation-utils.d.ts.map +0 -1
  284. package/dist/utils/grid-aggregation-utils.js +0 -114
  285. package/dist/utils/prop-utils.d.ts.map +0 -1
  286. package/dist/utils/prop-utils.js +0 -28
  287. package/dist/utils/resource-utils.d.ts +0 -14
  288. package/dist/utils/resource-utils.d.ts.map +0 -1
  289. package/dist/utils/resource-utils.js +0 -38
  290. package/dist/utils/scale-utils.d.ts +0 -15
  291. package/dist/utils/scale-utils.d.ts.map +0 -1
  292. package/dist/utils/scale-utils.js +0 -184
  293. package/src/cpu-grid-layer/cpu-grid-layer.ts +0 -329
  294. package/src/cpu-grid-layer/grid-aggregator.ts +0 -184
  295. package/src/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.ts +0 -35
  296. package/src/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.ts +0 -143
  297. package/src/gpu-grid-layer/gpu-grid-cell-layer.ts +0 -201
  298. package/src/gpu-grid-layer/gpu-grid-layer.ts +0 -455
  299. package/src/grid-aggregation-layer.ts +0 -243
  300. package/src/hexagon-layer/hexagon-aggregator.ts +0 -127
  301. package/src/utils/aggregation-operation-utils.ts +0 -118
  302. package/src/utils/bin-sorter.ts +0 -218
  303. package/src/utils/color-utils.ts +0 -57
  304. package/src/utils/cpu-aggregator.ts +0 -503
  305. package/src/utils/gpu-grid-aggregation/aggregate-all-fs.glsl.ts +0 -40
  306. package/src/utils/gpu-grid-aggregation/aggregate-all-vs.glsl.ts +0 -54
  307. package/src/utils/gpu-grid-aggregation/aggregate-to-grid-fs.glsl.ts +0 -35
  308. package/src/utils/gpu-grid-aggregation/aggregate-to-grid-vs.glsl.ts +0 -79
  309. package/src/utils/gpu-grid-aggregation/gpu-grid-aggregator-constants.ts +0 -46
  310. package/src/utils/gpu-grid-aggregation/gpu-grid-aggregator-utils.ts +0 -0
  311. package/src/utils/gpu-grid-aggregation/gpu-grid-aggregator.md +0 -155
  312. package/src/utils/gpu-grid-aggregation/gpu-grid-aggregator.ts +0 -690
  313. package/src/utils/gpu-grid-aggregation/transform-mean-vs.glsl.ts +0 -38
  314. package/src/utils/grid-aggregation-utils.ts +0 -147
  315. package/src/utils/prop-utils.ts +0 -29
  316. package/src/utils/resource-utils.ts +0 -53
  317. package/src/utils/scale-utils.js +0 -219
  318. /package/dist/{utils → common/utils}/prop-utils.d.ts +0 -0
@@ -1,243 +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
-
21
- import {GL} from '@luma.gl/constants';
22
- import {LayerContext, log, UpdateParameters, Accessor} from '@deck.gl/core';
23
- import AggregationLayer, {AggregationLayerProps} from './aggregation-layer';
24
- import GPUGridAggregator from './utils/gpu-grid-aggregation/gpu-grid-aggregator';
25
- import BinSorter from './utils/bin-sorter';
26
- import {pointToDensityGridDataCPU} from './cpu-grid-layer/grid-aggregator';
27
- import type {Buffer} from '@luma.gl/core';
28
-
29
- export type GridAggregationLayerProps<DataT> = AggregationLayerProps<DataT>;
30
-
31
- export default abstract class GridAggregationLayer<
32
- DataT,
33
- ExtraPropsT extends {} = {}
34
- > extends AggregationLayer<DataT, ExtraPropsT> {
35
- static layerName = 'GridAggregationLayer';
36
-
37
- state!: AggregationLayer<DataT>['state'] & {
38
- aggregationDataDirty?: boolean;
39
- aggregationWeightsDirty?: boolean;
40
- aggregationDirty?: boolean;
41
- gpuAggregation?: any;
42
- getValue?: () => any;
43
- sortedBins?: BinSorter;
44
- weights: {
45
- [key: string]: {
46
- aggregationBuffer?: Buffer;
47
- maxMinBuffer?: Buffer;
48
- aggregationData: Float32Array | null;
49
- maxMinData: Float32Array;
50
- maxData: Float32Array;
51
- minData: Float32Array;
52
- getWeight: Accessor<DataT, number>;
53
- operation: number;
54
- };
55
- };
56
- cpuGridAggregator?: Function;
57
- gpuGridAggregator?: GPUGridAggregator;
58
- layerData: any;
59
- numRow: number;
60
- numCol: number;
61
- gridOffset: {xOffset: number; yOffset: number};
62
- posOffset: number[];
63
- gridOrigin: number[];
64
- translation: number[];
65
- scaling: number[];
66
- boundingBox: {xMin: number; yMin: number; xMax: number; yMax: number};
67
- projectPoints?: (p: [number, number]) => [number, number];
68
- };
69
-
70
- initializeAggregationLayer({dimensions}) {
71
- super.initializeAggregationLayer(dimensions);
72
- this.setState({
73
- // CPU aggregation results
74
- layerData: {},
75
- gpuGridAggregator: new GPUGridAggregator(this.context.device, {
76
- id: `${this.id}-gpu-aggregator`
77
- }),
78
- cpuGridAggregator: pointToDensityGridDataCPU
79
- });
80
- }
81
-
82
- updateState(opts: UpdateParameters<this>) {
83
- // get current attributes
84
- super.updateState(opts);
85
-
86
- this.updateAggregationState(opts);
87
-
88
- const {aggregationDataDirty, aggregationWeightsDirty, gpuAggregation} = this.state;
89
- if (this.getNumInstances() <= 0) {
90
- return;
91
- }
92
- let aggregationDirty = false;
93
- // CPU aggregation is two steps
94
- // 1. Create bins (based on cellSize and position) 2. Aggregate weights for each bin
95
- // For GPU aggregation both above steps are combined into one step
96
-
97
- // step-1
98
- if (aggregationDataDirty || (gpuAggregation && aggregationWeightsDirty)) {
99
- this._updateAggregation(opts);
100
- aggregationDirty = true;
101
- }
102
- // step-2 (Applicalbe for CPU aggregation only)
103
- if (!gpuAggregation && (aggregationDataDirty || aggregationWeightsDirty)) {
104
- this._updateWeightBins();
105
- this._uploadAggregationResults();
106
- aggregationDirty = true;
107
- }
108
-
109
- this.setState({aggregationDirty});
110
- }
111
-
112
- finalizeState(context: LayerContext) {
113
- const {count} = this.state.weights;
114
- if (count && count.aggregationBuffer) {
115
- count.aggregationBuffer.delete();
116
- }
117
- this.state.gpuGridAggregator?.delete();
118
- super.finalizeState(context);
119
- }
120
-
121
- updateShaders(shaders: any): void {
122
- if (this.state.gpuAggregation) {
123
- this.state.gpuGridAggregator!.updateShaders(shaders);
124
- }
125
- }
126
-
127
- // Methods that can be overriden by subclasses for customizations
128
-
129
- updateAggregationState(opts: UpdateParameters<this>) {
130
- // Sublayers should implement this method.
131
- log.assert(false);
132
- }
133
-
134
- allocateResources(numRow, numCol) {
135
- if (this.state.numRow !== numRow || this.state.numCol !== numCol) {
136
- const dataBytes = numCol * numRow * 4 * 4;
137
- const {weights} = this.state;
138
- for (const name in weights) {
139
- const weight = weights[name];
140
- if (weight.aggregationBuffer) {
141
- weight.aggregationBuffer.delete();
142
- }
143
- weight.aggregationBuffer = this.context.device.createBuffer({
144
- byteLength: dataBytes,
145
- // @ts-expect-error legacy
146
- accessor: {
147
- size: 4,
148
- type: GL.FLOAT,
149
- divisor: 1
150
- }
151
- });
152
- }
153
- }
154
- }
155
-
156
- updateResults({aggregationData, maxMinData, maxData, minData}) {
157
- const {count} = this.state.weights;
158
- if (count) {
159
- count.aggregationData = aggregationData;
160
- count.maxMinData = maxMinData;
161
- count.maxData = maxData;
162
- count.minData = minData;
163
- }
164
- }
165
-
166
- // Private
167
-
168
- _updateAggregation(opts) {
169
- const {
170
- cpuGridAggregator,
171
- gpuGridAggregator,
172
- gridOffset,
173
- posOffset,
174
- translation = [0, 0],
175
- scaling = [0, 0, 0],
176
- boundingBox,
177
- projectPoints,
178
- gpuAggregation,
179
- numCol,
180
- numRow
181
- } = this.state;
182
- const {props} = opts;
183
- const {viewport} = this.context;
184
- const attributes = this.getAttributes();
185
- const vertexCount = this.getNumInstances();
186
-
187
- if (!gpuAggregation) {
188
- const result = cpuGridAggregator!(props, {
189
- gridOffset,
190
- projectPoints,
191
- attributes,
192
- viewport,
193
- posOffset,
194
- boundingBox
195
- });
196
- this.setState({
197
- layerData: result
198
- });
199
- } else {
200
- const {weights} = this.state;
201
- gpuGridAggregator!.run({
202
- weights,
203
- cellSize: [gridOffset.xOffset, gridOffset.yOffset],
204
- numCol,
205
- numRow,
206
- translation,
207
- scaling,
208
- vertexCount,
209
- projectPoints,
210
- attributes,
211
- moduleSettings: this.getModuleSettings()
212
- });
213
- }
214
- }
215
-
216
- _updateWeightBins() {
217
- const {getValue} = this.state;
218
-
219
- const sortedBins = new BinSorter(this.state.layerData.data || [], {getValue});
220
- this.setState({sortedBins});
221
- }
222
-
223
- _uploadAggregationResults(): void {
224
- const {numCol, numRow} = this.state;
225
- const {data} = this.state.layerData;
226
- const {aggregatedBins, minValue, maxValue, totalCount} = this.state.sortedBins!;
227
-
228
- const ELEMENTCOUNT = 4;
229
- const aggregationSize = numCol * numRow * ELEMENTCOUNT;
230
- const aggregationData = new Float32Array(aggregationSize).fill(0);
231
- for (const bin of aggregatedBins) {
232
- const {lonIdx, latIdx} = data[bin.i];
233
- const {value, counts} = bin;
234
- const cellIndex = (lonIdx + latIdx * numCol) * ELEMENTCOUNT;
235
- aggregationData[cellIndex] = value;
236
- aggregationData[cellIndex + ELEMENTCOUNT - 1] = counts;
237
- }
238
- const maxMinData = new Float32Array([maxValue, 0, 0, minValue]);
239
- const maxData = new Float32Array([maxValue, 0, 0, totalCount]);
240
- const minData = new Float32Array([minValue, 0, 0, totalCount]);
241
- this.updateResults({aggregationData, maxMinData, maxData, minData});
242
- }
243
- }
@@ -1,127 +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
-
21
- import {hexbin} from 'd3-hexbin';
22
- import {createIterable, log} from '@deck.gl/core';
23
-
24
- /**
25
- * Use d3-hexbin to performs hexagonal binning from geo points to hexagons
26
- * @param {Iterable} data - array of points
27
- * @param {Number} radius - hexagon radius in meter
28
- * @param {function} getPosition - get points lon lat
29
- * @param {Object} viewport - current viewport object
30
-
31
- * @return {Object} - hexagons and countRange
32
- */
33
- export function pointToHexbin(props, aggregationParams) {
34
- const {data, radius} = props;
35
- const {viewport, attributes} = aggregationParams;
36
- // get hexagon radius in mercator world unit
37
- const centerLngLat = data.length ? getPointsCenter(data, aggregationParams) : null;
38
- const radiusCommon = getRadiusInCommon(radius, viewport, centerLngLat);
39
-
40
- // add world space coordinates to points
41
- const screenPoints: {
42
- screenCoord: number[];
43
- source: any;
44
- index: number;
45
- }[] = [];
46
- const {iterable, objectInfo} = createIterable(data);
47
- const positions = attributes.positions.value;
48
- const {size} = attributes.positions.getAccessor();
49
- for (const object of iterable) {
50
- objectInfo.index++;
51
- const posIndex = objectInfo.index * size;
52
- const position = [positions[posIndex], positions[posIndex + 1]];
53
- const arrayIsFinite = Number.isFinite(position[0]) && Number.isFinite(position[1]);
54
- if (arrayIsFinite) {
55
- screenPoints.push({
56
- screenCoord: viewport.projectFlat(position),
57
- source: object,
58
- index: objectInfo.index
59
- });
60
- } else {
61
- log.warn('HexagonLayer: invalid position')();
62
- }
63
- }
64
-
65
- const newHexbin = hexbin()
66
- .radius(radiusCommon)
67
- .x(d => d.screenCoord[0])
68
- .y(d => d.screenCoord[1]);
69
-
70
- const hexagonBins = newHexbin(screenPoints);
71
-
72
- return {
73
- hexagons: hexagonBins.map((hex, index) => ({
74
- position: viewport.unprojectFlat([hex.x, hex.y]),
75
- points: hex,
76
- index
77
- })),
78
- radiusCommon
79
- };
80
- }
81
-
82
- /**
83
- * Get the bounding box of all data points
84
- */
85
- export function getPointsCenter(data, aggregationParams) {
86
- const {attributes} = aggregationParams;
87
- const positions = attributes.positions.value;
88
- const {size} = attributes.positions.getAccessor();
89
-
90
- let minX = Infinity;
91
- let minY = Infinity;
92
- let maxX = -Infinity;
93
- let maxY = -Infinity;
94
- let i;
95
-
96
- for (i = 0; i < size * data.length; i += size) {
97
- const x = positions[i];
98
- const y = positions[i + 1];
99
- const arrayIsFinite = Number.isFinite(x) && Number.isFinite(y);
100
-
101
- if (arrayIsFinite) {
102
- minX = Math.min(x, minX);
103
- maxX = Math.max(x, maxX);
104
- minY = Math.min(y, minY);
105
- maxY = Math.max(y, maxY);
106
- }
107
- }
108
-
109
- // return center
110
- return [minX, minY, maxX, maxY].every(Number.isFinite)
111
- ? [(minX + maxX) / 2, (minY + maxY) / 2]
112
- : null;
113
- }
114
-
115
- /**
116
- * Get radius in mercator world space coordinates from meter
117
- * @param {Number} radius - in meter
118
- * @param {Object} viewport - current viewport object
119
- * @param {Array<Number>} center - data center
120
-
121
- * @return {Number} radius in mercator world spcae coordinates
122
- */
123
- export function getRadiusInCommon(radius, viewport, center) {
124
- const {unitsPerMeter} = viewport.getDistanceScales(center);
125
- // x, y distance should be the same
126
- return radius * unitsPerMeter[0];
127
- }
@@ -1,118 +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
-
21
- export const AGGREGATION_OPERATION = {
22
- SUM: 1,
23
- MEAN: 2,
24
- MIN: 3,
25
- MAX: 4
26
- };
27
-
28
- function sumReducer(accu, cur) {
29
- return accu + cur;
30
- }
31
-
32
- function maxReducer(accu, cur) {
33
- return cur > accu ? cur : accu;
34
- }
35
-
36
- function minReducer(accu, cur) {
37
- return cur < accu ? cur : accu;
38
- }
39
-
40
- export function getMean(pts, accessor) {
41
- if (Number.isFinite(accessor)) {
42
- return pts.length ? accessor : null;
43
- }
44
- const filtered = pts.map(accessor).filter(Number.isFinite);
45
-
46
- return filtered.length ? filtered.reduce(sumReducer, 0) / filtered.length : null;
47
- }
48
-
49
- export function getSum(pts, accessor) {
50
- if (Number.isFinite(accessor)) {
51
- return pts.length ? pts.length * accessor : null;
52
- }
53
- const filtered = pts.map(accessor).filter(Number.isFinite);
54
-
55
- return filtered.length ? filtered.reduce(sumReducer, 0) : null;
56
- }
57
-
58
- export function getMax(pts, accessor) {
59
- if (Number.isFinite(accessor)) {
60
- return pts.length ? accessor : null;
61
- }
62
- const filtered = pts.map(accessor).filter(Number.isFinite);
63
-
64
- return filtered.length ? filtered.reduce(maxReducer, -Infinity) : null;
65
- }
66
-
67
- export function getMin(pts, accessor) {
68
- if (Number.isFinite(accessor)) {
69
- return pts.length ? accessor : null;
70
- }
71
- const filtered = pts.map(accessor).filter(Number.isFinite);
72
-
73
- return filtered.length ? filtered.reduce(minReducer, Infinity) : null;
74
- }
75
-
76
- // Function to convert from aggregation/accessor props (like colorAggregation and getColorWeight) to getValue prop (like getColorValue)
77
- export function getValueFunc(aggregation, accessor, context) {
78
- const op = AGGREGATION_OPERATION[aggregation] || AGGREGATION_OPERATION.SUM;
79
- accessor = wrapAccessor(accessor, context);
80
- switch (op) {
81
- case AGGREGATION_OPERATION.MIN:
82
- return pts => getMin(pts, accessor);
83
- case AGGREGATION_OPERATION.SUM:
84
- return pts => getSum(pts, accessor);
85
- case AGGREGATION_OPERATION.MEAN:
86
- return pts => getMean(pts, accessor);
87
- case AGGREGATION_OPERATION.MAX:
88
- return pts => getMax(pts, accessor);
89
- default:
90
- return null;
91
- }
92
- }
93
-
94
- type AccessorContext = {
95
- data?;
96
- index?: number;
97
- indices?: number[];
98
- };
99
-
100
- function wrapAccessor(accessor, context: AccessorContext = {}) {
101
- if (Number.isFinite(accessor)) {
102
- return accessor;
103
- }
104
- return pt => {
105
- context.index = pt.index;
106
- return accessor(pt.source, context);
107
- };
108
- }
109
-
110
- export function wrapGetValueFunc(getValue, context: AccessorContext = {}) {
111
- return pts => {
112
- context.indices = pts.map(pt => pt.index);
113
- return getValue(
114
- pts.map(pt => pt.source),
115
- context
116
- );
117
- };
118
- }
@@ -1,218 +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
-
21
- // getValue takes an array of points returns a value to sort the bins on.
22
- // by default it returns the number of points
23
- // this is where to pass in a function to color the bins by
24
- // avg/mean/max of specific value of the point
25
- const defaultGetValue = points => points.length;
26
-
27
- import {clamp, getQuantileDomain, getOrdinalDomain} from './scale-utils';
28
-
29
- const MAX_32_BIT_FLOAT = 3.402823466e38;
30
-
31
- // access array of points in each bin
32
- const defaultGetPoints = bin => bin.points;
33
- // access index of each bin
34
- const defaultGetIndex = bin => bin.index;
35
-
36
- // d3-scending
37
- const ascending = (a, b) => (a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN);
38
-
39
- const defaultProps = {
40
- getValue: defaultGetValue,
41
- getPoints: defaultGetPoints,
42
- getIndex: defaultGetIndex,
43
- filterData: null
44
- };
45
-
46
- export type AggregatedBin = {
47
- i: number;
48
- value: any;
49
- counts: number;
50
- };
51
-
52
- export default class BinSorter {
53
- maxCount!: number;
54
- maxValue!: number;
55
- minValue!: number;
56
- totalCount!: number;
57
-
58
- aggregatedBins: AggregatedBin[];
59
- sortedBins!: AggregatedBin[];
60
- binMap: Record<number, AggregatedBin>;
61
-
62
- constructor(bins: unknown[] = [], props: Partial<typeof defaultProps> = defaultProps) {
63
- this.aggregatedBins = this.getAggregatedBins(bins, props);
64
- this._updateMinMaxValues();
65
- this.binMap = this.getBinMap();
66
- }
67
-
68
- /**
69
- * Get an array of object with aggregated values and index of bins
70
- * Array object will be sorted by value optionally.
71
- * @param {Array} bins
72
- * @param {Function} getValue
73
- * @return {Array} array of values and index lookup
74
- */
75
- getAggregatedBins(bins, props): AggregatedBin[] {
76
- const {
77
- getValue = defaultGetValue,
78
- getPoints = defaultGetPoints,
79
- getIndex = defaultGetIndex,
80
- filterData
81
- } = props;
82
-
83
- const hasFilter = typeof filterData === 'function';
84
- const binCount = bins.length;
85
- const aggregatedBins: AggregatedBin[] = [];
86
- let index = 0;
87
-
88
- for (let binIndex = 0; binIndex < binCount; binIndex++) {
89
- const bin = bins[binIndex];
90
- const points = getPoints(bin);
91
- const i = getIndex(bin);
92
-
93
- const filteredPoints = hasFilter ? points.filter(filterData) : points;
94
-
95
- bin.filteredPoints = hasFilter ? filteredPoints : null;
96
-
97
- const value = filteredPoints.length ? getValue(filteredPoints) : null;
98
-
99
- if (value !== null && value !== undefined) {
100
- // filter bins if value is null or undefined
101
- aggregatedBins[index] = {
102
- i: Number.isFinite(i) ? i : binIndex,
103
- value,
104
- counts: filteredPoints.length
105
- };
106
- index++;
107
- }
108
- }
109
- return aggregatedBins;
110
- }
111
-
112
- _percentileToIndex(percentileRange): [number, number] {
113
- const len = this.sortedBins.length;
114
- if (len < 2) {
115
- return [0, 0];
116
- }
117
-
118
- const [lower, upper] = percentileRange.map(n => clamp(n, 0, 100));
119
-
120
- const lowerIdx = Math.ceil((lower / 100) * (len - 1));
121
- const upperIdx = Math.floor((upper / 100) * (len - 1));
122
-
123
- return [lowerIdx, upperIdx];
124
- }
125
-
126
- /**
127
- * Get a mapping from cell/hexagon index to sorted bin
128
- * This is used to retrieve bin value for color calculation
129
- * @return {Object} bin index to aggregatedBins
130
- */
131
- getBinMap(): Record<number, AggregatedBin> {
132
- const binMap = {};
133
- for (const bin of this.aggregatedBins) {
134
- binMap[bin.i] = bin;
135
- }
136
- return binMap;
137
- }
138
-
139
- // Private
140
-
141
- /**
142
- * Get ths max count of all bins
143
- */
144
- _updateMinMaxValues(): void {
145
- let maxCount = 0;
146
- let maxValue = 0;
147
- let minValue = MAX_32_BIT_FLOAT;
148
- let totalCount = 0;
149
- for (const x of this.aggregatedBins) {
150
- maxCount = maxCount > x.counts ? maxCount : x.counts;
151
- maxValue = maxValue > x.value ? maxValue : x.value;
152
- minValue = minValue < x.value ? minValue : x.value;
153
- totalCount += x.counts;
154
- }
155
- this.maxCount = maxCount;
156
- this.maxValue = maxValue;
157
- this.minValue = minValue;
158
- this.totalCount = totalCount;
159
- }
160
-
161
- /**
162
- * Get range of values of all bins
163
- * @param {Number[]} range
164
- * @param {Number} range[0] - lower bound
165
- * @param {Number} range[1] - upper bound
166
- * @return {Array} array of new value range
167
- */
168
- getValueRange(percentileRange: [number, number]): [number, number] {
169
- if (!this.sortedBins) {
170
- this.sortedBins = this.aggregatedBins.sort((a, b) => ascending(a.value, b.value));
171
- }
172
- if (!this.sortedBins.length) {
173
- // @ts-expect-error
174
- return [];
175
- }
176
- let lowerIdx = 0;
177
- let upperIdx = this.sortedBins.length - 1;
178
-
179
- if (Array.isArray(percentileRange)) {
180
- const idxRange = this._percentileToIndex(percentileRange);
181
- lowerIdx = idxRange[0];
182
- upperIdx = idxRange[1];
183
- }
184
-
185
- return [this.sortedBins[lowerIdx].value, this.sortedBins[upperIdx].value];
186
- }
187
-
188
- getValueDomainByScale(scale: string, [lower = 0, upper = 100] = []) {
189
- if (!this.sortedBins) {
190
- this.sortedBins = this.aggregatedBins.sort((a, b) => ascending(a.value, b.value));
191
- }
192
- if (!this.sortedBins.length) {
193
- return [];
194
- }
195
- const indexEdge = this._percentileToIndex([lower, upper]);
196
-
197
- return this._getScaleDomain(scale, indexEdge);
198
- }
199
-
200
- _getScaleDomain(scaleType: string, [lowerIdx, upperIdx]: [number, number]): [number, number] {
201
- const bins = this.sortedBins;
202
-
203
- switch (scaleType) {
204
- case 'quantize':
205
- case 'linear':
206
- return [bins[lowerIdx].value, bins[upperIdx].value];
207
-
208
- case 'quantile':
209
- return getQuantileDomain(bins.slice(lowerIdx, upperIdx + 1), d => d.value);
210
-
211
- case 'ordinal':
212
- return getOrdinalDomain(bins, d => d.value) as [number, number];
213
-
214
- default:
215
- return [bins[lowerIdx].value, bins[upperIdx].value];
216
- }
217
- }
218
- }