@deck.gl/aggregation-layers 9.0.35 → 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
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "deck.gl layers that aggregate the input data into alternative representations",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
- "version": "9.0.35",
6
+ "version": "9.1.0-beta.1",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -38,16 +38,17 @@
38
38
  "prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env=dev"
39
39
  },
40
40
  "dependencies": {
41
- "@luma.gl/constants": "~9.0.27",
42
- "@luma.gl/shadertools": "~9.0.27",
43
- "@math.gl/web-mercator": "^4.0.0",
41
+ "@luma.gl/constants": "^9.1.0-beta.11",
42
+ "@luma.gl/shadertools": "^9.1.0-beta.11",
43
+ "@math.gl/core": "^4.1.0",
44
+ "@math.gl/web-mercator": "^4.1.0",
44
45
  "d3-hexbin": "^0.2.1"
45
46
  },
46
47
  "peerDependencies": {
47
- "@deck.gl/core": "^9.0.0",
48
- "@deck.gl/layers": "^9.0.0",
49
- "@luma.gl/core": "~9.0.0",
50
- "@luma.gl/engine": "~9.0.0"
48
+ "@deck.gl/core": "9.0.0-alpha.0",
49
+ "@deck.gl/layers": "9.0.0-alpha.0",
50
+ "@luma.gl/core": "^9.1.0-beta.11",
51
+ "@luma.gl/engine": "^9.1.0-beta.11"
51
52
  },
52
- "gitHead": "8e8fc65d8fa9b9bf7e6d82a7e89d37c6d0126aae"
53
+ "gitHead": "a86fb154cf323eacc3f56ef087f636fb9f6c30b6"
53
54
  }
@@ -0,0 +1,107 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import {
6
+ CompositeLayer,
7
+ LayerDataSource,
8
+ LayerContext,
9
+ UpdateParameters,
10
+ CompositeLayerProps,
11
+ Attribute,
12
+ AttributeManager
13
+ } from '@deck.gl/core';
14
+ import {Aggregator} from './aggregator/aggregator';
15
+
16
+ export type AggregationLayerProps<DataT> = CompositeLayerProps & {
17
+ data: LayerDataSource<DataT>;
18
+ };
19
+
20
+ export default abstract class AggregationLayer<
21
+ DataT,
22
+ ExtraPropsT extends {} = {}
23
+ > extends CompositeLayer<Required<AggregationLayer<DataT>> & ExtraPropsT> {
24
+ static layerName = 'AggregationLayer';
25
+
26
+ state!: {
27
+ aggregatorType: string;
28
+ aggregator: Aggregator;
29
+ };
30
+
31
+ /** Allow this layer to participates in the draw cycle */
32
+ get isDrawable() {
33
+ return true;
34
+ }
35
+
36
+ abstract getAggregatorType(): string;
37
+ /** Called to create an Aggregator instance */
38
+ abstract createAggregator(type: string): Aggregator;
39
+ /** Called when some attributes change, a chance to mark Aggregator as dirty */
40
+ abstract onAttributeChange(id: string): void;
41
+
42
+ initializeState(): void {
43
+ this.getAttributeManager()!.remove(['instancePickingColors']);
44
+ }
45
+
46
+ // Extend Layer.updateState to update the Aggregator instance
47
+ // returns true if aggregator is changed
48
+ updateState(params: UpdateParameters<this>): boolean {
49
+ super.updateState(params);
50
+
51
+ const aggregatorType = this.getAggregatorType();
52
+ if (params.changeFlags.extensionsChanged || this.state.aggregatorType !== aggregatorType) {
53
+ this.state.aggregator?.destroy();
54
+ const aggregator = this.createAggregator(aggregatorType);
55
+ aggregator.setProps({
56
+ attributes: this.getAttributeManager()?.attributes
57
+ });
58
+ this.setState({aggregator, aggregatorType});
59
+ return true;
60
+ }
61
+ return false;
62
+ }
63
+
64
+ // Override Layer.finalizeState to dispose the Aggregator instance
65
+ finalizeState(context: LayerContext) {
66
+ super.finalizeState(context);
67
+ this.state.aggregator.destroy();
68
+ }
69
+
70
+ // Override Layer.updateAttributes to update the aggregator
71
+ protected updateAttributes(changedAttributes: {[id: string]: Attribute}) {
72
+ const {aggregator} = this.state;
73
+ aggregator.setProps({
74
+ attributes: changedAttributes
75
+ });
76
+
77
+ for (const id in changedAttributes) {
78
+ this.onAttributeChange(id);
79
+ }
80
+
81
+ // In aggregator.update() the aggregator allocates the buffers to store its output
82
+ // These buffers will be exposed by aggregator.getResults() and passed to the sublayers
83
+ // Therefore update() must be called before renderLayers()
84
+ // CPUAggregator's output is populated right here in update()
85
+ // GPUAggregator's output is pre-allocated and populated in preDraw(), see comments below
86
+ aggregator.update();
87
+ }
88
+
89
+ draw({shaderModuleProps}) {
90
+ // GPU aggregation needs `shaderModuleProps` for projection/filter uniforms which are only accessible at draw time
91
+ // GPUAggregator's Buffers are pre-allocated during `update()` and passed down to the sublayer attributes in renderLayers()
92
+ // Although the Buffers have been bound to the sublayer's Model, their content are not populated yet
93
+ // GPUAggregator.preDraw() is called in the draw cycle here right before Buffers are used by sublayer.draw()
94
+ const {aggregator} = this.state;
95
+ // @ts-expect-error only used by GPU aggregators
96
+ aggregator.setProps({shaderModuleProps});
97
+ aggregator.preDraw();
98
+ }
99
+
100
+ // override CompositeLayer._getAttributeManager to create AttributeManager instance
101
+ _getAttributeManager() {
102
+ return new AttributeManager(this.context.device, {
103
+ id: this.props.id,
104
+ stats: this.context.stats
105
+ });
106
+ }
107
+ }
@@ -0,0 +1,88 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {Attribute, BinaryAttribute} from '@deck.gl/core';
6
+
7
+ /** Method used to reduce a list of values to one number */
8
+ export type AggregationOperation = 'SUM' | 'MEAN' | 'MIN' | 'MAX' | 'COUNT';
9
+
10
+ /** Baseline inputs to an Aggregator */
11
+ export type AggregationProps = {
12
+ /** Number of data points */
13
+ pointCount: number;
14
+ /** The input data */
15
+ attributes: {[id: string]: Attribute};
16
+ /** How to aggregate the values inside a bin, defined for each channel */
17
+ operations: AggregationOperation[];
18
+ /** Additional options to control bin sorting, e.g. bin size */
19
+ binOptions: Record<string, number | number[]>;
20
+ /** Callback after a channel is updated */
21
+ onUpdate?: (event: {channel: number}) => void;
22
+ };
23
+
24
+ /** Descriptor of an aggregated bin */
25
+ export type AggregatedBin = {
26
+ /** The unique identifier of the bin */
27
+ id: number[];
28
+ /** Aggregated values by channel */
29
+ value: number[];
30
+ /** Count of data points in this bin */
31
+ count: number;
32
+ /** Indices of data points in this bin. Only available if using CPU aggregation. */
33
+ pointIndices?: number[];
34
+ };
35
+
36
+ /**
37
+ * The Aggregator interface describes a class that performs aggregation.
38
+ *
39
+ * _Aggregation_ is a 2-step process:
40
+ * 1. Sort: Group a collection of _data points_ by some property into _bins_.
41
+ * 2. Aggregate: for each _bin_, calculate a numeric output (_result_) from some metrics (_values_) from all its members.
42
+ * Multiple results can be obtained independently (_channels_).
43
+ *
44
+ * An implementation of the _Aggregator_ interface takes the following inputs:
45
+ * - The number of data points
46
+ * - The group that each data point belongs to, by mapping each data point to a _binId_ (integer or array of integers)
47
+ * - The values to aggregate, by mapping each data point in each channel to one _value_ (number)
48
+ * - The method (_operation_) to reduce a list of values to one number, such as SUM
49
+ *
50
+ * And yields the following outputs:
51
+ * - A list of _binId_ that data points get sorted into
52
+ * - The aggregated values (_result_) as a list of numbers, comprised of one number per bin per channel
53
+ * - The [min, max] among all aggregated values (_domain_) for each channel
54
+ *
55
+ */
56
+ export interface Aggregator {
57
+ /** Update aggregation props */
58
+ setProps(props: Partial<AggregationProps>): void;
59
+
60
+ /** Flags a channel to need update
61
+ * @param {number} channel - mark the given channel as dirty. If not provided, all channels will be updated.
62
+ */
63
+ setNeedsUpdate(channel?: number): void;
64
+
65
+ /** Called after props are set and before results are accessed */
66
+ update(): void;
67
+
68
+ /** Called before layer is drawn to screen. */
69
+ preDraw(): void;
70
+
71
+ /** Dispose all allocated resources */
72
+ destroy(): void;
73
+
74
+ /** Get the number of bins */
75
+ get binCount(): number;
76
+
77
+ /** Returns an accessor to the bins. */
78
+ getBins(): BinaryAttribute | null;
79
+
80
+ /** Returns an accessor to the output for a given channel. */
81
+ getResult(channel: number): BinaryAttribute | null;
82
+
83
+ /** Returns the [min, max] of aggregated values for a given channel. */
84
+ getResultDomain(channel: number): [min: number, max: number];
85
+
86
+ /** Returns the information for a given bin. */
87
+ getBin(index: number): AggregatedBin | null;
88
+ }
@@ -0,0 +1,101 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {Bin} from './cpu-aggregator';
6
+ import type {AggregationOperation} from '../aggregator';
7
+
8
+ /** A reducer function that takes a list of data points and outputs one measurement */
9
+ export type AggregationFunc = (
10
+ /** Indices of the points */
11
+ pointIndices: number[],
12
+ /** Accessor to the value for each point */
13
+ getValue: (index: number) => number
14
+ ) => number;
15
+
16
+ const count: AggregationFunc = pointIndices => {
17
+ return pointIndices.length;
18
+ };
19
+
20
+ const sum: AggregationFunc = (pointIndices, getValue) => {
21
+ let result = 0;
22
+ for (const i of pointIndices) {
23
+ result += getValue(i);
24
+ }
25
+ return result;
26
+ };
27
+
28
+ const mean: AggregationFunc = (pointIndices, getValue) => {
29
+ if (pointIndices.length === 0) {
30
+ return NaN;
31
+ }
32
+ return sum(pointIndices, getValue) / pointIndices.length;
33
+ };
34
+
35
+ const min: AggregationFunc = (pointIndices, getValue) => {
36
+ let result = Infinity;
37
+ for (const i of pointIndices) {
38
+ const value = getValue(i);
39
+ if (value < result) {
40
+ result = value;
41
+ }
42
+ }
43
+ return result;
44
+ };
45
+
46
+ const max: AggregationFunc = (pointIndices, getValue) => {
47
+ let result = -Infinity;
48
+ for (const i of pointIndices) {
49
+ const value = getValue(i);
50
+ if (value > result) {
51
+ result = value;
52
+ }
53
+ }
54
+ return result;
55
+ };
56
+
57
+ export const BUILT_IN_OPERATIONS: Record<AggregationOperation, AggregationFunc> = {
58
+ COUNT: count,
59
+ SUM: sum,
60
+ MEAN: mean,
61
+ MIN: min,
62
+ MAX: max
63
+ } as const;
64
+
65
+ /**
66
+ * Performs the aggregation step. See interface Aggregator comments.
67
+ * @returns Floa32Array of aggregated values, one for each bin, and the [min,max] of the values
68
+ */
69
+ export function aggregate({
70
+ bins,
71
+ getValue,
72
+ operation,
73
+ target
74
+ }: {
75
+ /** Data points sorted by bins */
76
+ bins: Bin[];
77
+ /** Given the index of a data point, returns its value */
78
+ getValue: (index: number) => number;
79
+ /** Method used to reduce a list of values to one number */
80
+ operation: AggregationFunc;
81
+ /** Array to write the output into */
82
+ target?: Float32Array | null;
83
+ }): {
84
+ value: Float32Array;
85
+ domain: [min: number, max: number];
86
+ } {
87
+ if (!target || target.length < bins.length) {
88
+ target = new Float32Array(bins.length);
89
+ }
90
+ let min = Infinity;
91
+ let max = -Infinity;
92
+
93
+ for (let j = 0; j < bins.length; j++) {
94
+ const {points} = bins[j];
95
+ target[j] = operation(points, getValue);
96
+ if (target[j] < min) min = target[j];
97
+ if (target[j] > max) max = target[j];
98
+ }
99
+
100
+ return {value: target, domain: [min, max]};
101
+ }
@@ -0,0 +1,203 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {Aggregator, AggregationProps, AggregatedBin} from '../aggregator';
6
+ import {_deepEqual as deepEqual, BinaryAttribute} from '@deck.gl/core';
7
+ import {sortBins, packBinIds} from './sort-bins';
8
+ import {aggregate, AggregationFunc, BUILT_IN_OPERATIONS} from './aggregate';
9
+ import {VertexAccessor, evaluateVertexAccessor} from './vertex-accessor';
10
+
11
+ /** Options used to construct a new CPUAggregator */
12
+ export type CPUAggregatorProps = {
13
+ /** Size of bin IDs */
14
+ dimensions: number;
15
+ /** Accessor to map each data point to a bin ID.
16
+ * Bin ID should be an array with [dimensions] elements; or null if the data point should be skipped
17
+ */
18
+ getBin: VertexAccessor<number[] | null, any>;
19
+ /** Accessor to map each data point to a weight value, defined per channel */
20
+ getValue: VertexAccessor<number>[];
21
+ } & Partial<CPUAggregationProps>;
22
+
23
+ /** Props used to run CPU aggregation, can be changed at any time */
24
+ type CPUAggregationProps = AggregationProps & {
25
+ /** Custom callback to aggregate points, overrides the built-in operations */
26
+ customOperations: (AggregationFunc | null | undefined)[];
27
+ };
28
+
29
+ export type Bin = {
30
+ id: number[];
31
+ index: number;
32
+ /** list of data point indices */
33
+ points: number[];
34
+ };
35
+
36
+ /** An Aggregator implementation that calculates aggregation on the CPU */
37
+ export class CPUAggregator implements Aggregator {
38
+ readonly dimensions: number;
39
+ readonly channelCount: number;
40
+
41
+ props: CPUAggregatorProps & CPUAggregationProps;
42
+
43
+ /** Dirty flag
44
+ * If true, redo sorting
45
+ * If array, redo aggregation on the specified channel
46
+ */
47
+ protected needsUpdate: boolean[] | boolean;
48
+
49
+ protected bins: Bin[] = [];
50
+ protected binIds: (BinaryAttribute & {value: Float32Array}) | null = null;
51
+ protected results: (BinaryAttribute & {
52
+ value: Float32Array;
53
+ domain: [min: number, max: number];
54
+ })[] = [];
55
+
56
+ constructor(props: CPUAggregatorProps) {
57
+ this.dimensions = props.dimensions;
58
+ this.channelCount = props.getValue.length;
59
+ this.props = {
60
+ ...props,
61
+ binOptions: {},
62
+ pointCount: 0,
63
+ operations: [],
64
+ customOperations: [],
65
+ attributes: {}
66
+ };
67
+ this.needsUpdate = true;
68
+ this.setProps(props);
69
+ }
70
+
71
+ destroy() {}
72
+
73
+ get binCount() {
74
+ return this.bins.length;
75
+ }
76
+
77
+ /** Update aggregation props */
78
+ setProps(props: Partial<CPUAggregationProps>) {
79
+ const oldProps = this.props;
80
+
81
+ if (props.binOptions) {
82
+ if (!deepEqual(props.binOptions, oldProps.binOptions, 2)) {
83
+ this.setNeedsUpdate();
84
+ }
85
+ }
86
+ if (props.operations) {
87
+ for (let channel = 0; channel < this.channelCount; channel++) {
88
+ if (props.operations[channel] !== oldProps.operations[channel]) {
89
+ this.setNeedsUpdate(channel);
90
+ }
91
+ }
92
+ }
93
+ if (props.customOperations) {
94
+ for (let channel = 0; channel < this.channelCount; channel++) {
95
+ if (
96
+ Boolean(props.customOperations[channel]) !== Boolean(oldProps.customOperations[channel])
97
+ ) {
98
+ this.setNeedsUpdate(channel);
99
+ }
100
+ }
101
+ }
102
+ if (props.pointCount !== undefined && props.pointCount !== oldProps.pointCount) {
103
+ this.setNeedsUpdate();
104
+ }
105
+ if (props.attributes) {
106
+ props.attributes = {...oldProps.attributes, ...props.attributes};
107
+ }
108
+ Object.assign(this.props, props);
109
+ }
110
+
111
+ /** Flags a channel to need update
112
+ * This is called internally by setProps() if certain props change
113
+ * Users of this class still need to manually set the dirty flag sometimes, because even if no props changed
114
+ * the underlying buffers could have been updated and require rerunning the aggregation
115
+ * @param {number} channel - mark the given channel as dirty. If not provided, all channels will be updated.
116
+ */
117
+ setNeedsUpdate(channel?: number): void {
118
+ if (channel === undefined) {
119
+ this.needsUpdate = true;
120
+ } else if (this.needsUpdate !== true) {
121
+ this.needsUpdate = this.needsUpdate || [];
122
+ this.needsUpdate[channel] = true;
123
+ }
124
+ }
125
+
126
+ /** Run aggregation */
127
+ update() {
128
+ if (this.needsUpdate === true) {
129
+ this.bins = sortBins({
130
+ pointCount: this.props.pointCount,
131
+ getBinId: evaluateVertexAccessor(
132
+ this.props.getBin,
133
+ this.props.attributes,
134
+ this.props.binOptions
135
+ )
136
+ });
137
+ const value = packBinIds({
138
+ bins: this.bins,
139
+ dimensions: this.dimensions,
140
+ // Reuse allocated typed array
141
+ target: this.binIds?.value
142
+ });
143
+ this.binIds = {value, type: 'float32', size: this.dimensions};
144
+ }
145
+ for (let channel = 0; channel < this.channelCount; channel++) {
146
+ if (this.needsUpdate === true || this.needsUpdate[channel]) {
147
+ const operation =
148
+ this.props.customOperations[channel] ||
149
+ BUILT_IN_OPERATIONS[this.props.operations[channel]];
150
+ const {value, domain} = aggregate({
151
+ bins: this.bins,
152
+ getValue: evaluateVertexAccessor(
153
+ this.props.getValue[channel],
154
+ this.props.attributes,
155
+ undefined
156
+ ),
157
+ operation,
158
+ // Reuse allocated typed array
159
+ target: this.results[channel]?.value
160
+ });
161
+ this.results[channel] = {value, domain, type: 'float32', size: 1};
162
+ this.props.onUpdate?.({channel});
163
+ }
164
+ }
165
+ this.needsUpdate = false;
166
+ }
167
+
168
+ preDraw() {}
169
+
170
+ /** Returns an accessor to the bins. */
171
+ getBins(): BinaryAttribute | null {
172
+ return this.binIds;
173
+ }
174
+
175
+ /** Returns an accessor to the output for a given channel. */
176
+ getResult(channel: number): BinaryAttribute | null {
177
+ return this.results[channel];
178
+ }
179
+
180
+ /** Returns the [min, max] of aggregated values for a given channel. */
181
+ getResultDomain(channel: number): [min: number, max: number] {
182
+ return this.results[channel]?.domain ?? [Infinity, -Infinity];
183
+ }
184
+
185
+ /** Returns the information for a given bin. */
186
+ getBin(index: number): AggregatedBin | null {
187
+ const bin = this.bins[index];
188
+ if (!bin) {
189
+ return null;
190
+ }
191
+ const value = new Array(this.channelCount);
192
+ for (let i = 0; i < value.length; i++) {
193
+ const result = this.results[i];
194
+ value[i] = result?.value[index];
195
+ }
196
+ return {
197
+ id: bin.id,
198
+ value,
199
+ count: bin.points.length,
200
+ pointIndices: bin.points
201
+ };
202
+ }
203
+ }
@@ -0,0 +1,63 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {Bin} from './cpu-aggregator';
6
+
7
+ /** Group data points into bins */
8
+ export function sortBins({
9
+ pointCount,
10
+ getBinId
11
+ }: {
12
+ pointCount: number;
13
+ getBinId: (index: number) => number[] | null;
14
+ }): Bin[] {
15
+ const binsById: Map<string, Bin> = new Map();
16
+
17
+ for (let i = 0; i < pointCount; i++) {
18
+ const id = getBinId(i);
19
+ if (id === null) {
20
+ continue;
21
+ }
22
+ let bin = binsById.get(String(id));
23
+ if (bin) {
24
+ bin.points.push(i);
25
+ } else {
26
+ bin = {
27
+ id,
28
+ index: binsById.size,
29
+ points: [i]
30
+ };
31
+ binsById.set(String(id), bin);
32
+ }
33
+ }
34
+ return Array.from(binsById.values());
35
+ }
36
+
37
+ /** Pack bin ids into a typed array */
38
+ export function packBinIds({
39
+ bins,
40
+ dimensions,
41
+ target
42
+ }: {
43
+ bins: Bin[];
44
+ /** Size of bin IDs */
45
+ dimensions: number;
46
+ /** Array to write output into */
47
+ target?: Float32Array | null;
48
+ }): Float32Array {
49
+ const targetLength = bins.length * dimensions;
50
+ if (!target || target.length < targetLength) {
51
+ target = new Float32Array(targetLength);
52
+ }
53
+
54
+ for (let i = 0; i < bins.length; i++) {
55
+ const {id} = bins[i];
56
+ if (Array.isArray(id)) {
57
+ target.set(id, i * dimensions);
58
+ } else {
59
+ target[i] = id;
60
+ }
61
+ }
62
+ return target;
63
+ }
@@ -0,0 +1,86 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {Attribute} from '@deck.gl/core';
6
+ import type {TypedArray} from '@luma.gl/core';
7
+
8
+ /** This is designed to mirror a vertex shader function
9
+ * For each vertex, calculates a value from attribtes, vertex index and options (uniforms)
10
+ */
11
+ export type VertexAccessor<ValueT, OptionsT = undefined> = {
12
+ /** Attribute ids that provide input to getValue, used to index into the attributes map.
13
+ * For example `['position', 'size']`
14
+ */
15
+ sources?: string[];
16
+ /** Called for each data point to retrieve a value during update. */
17
+ getValue: (
18
+ /** Attributes at the vertex index */
19
+ data: any,
20
+ /** Vertex index */
21
+ index: number,
22
+ /** Shared options across all vertices */
23
+ options: OptionsT
24
+ ) => ValueT;
25
+ };
26
+
27
+ /** Evaluate a VertexAccessor with a set of attributes */
28
+ export function evaluateVertexAccessor<ValueT, OptionsT>(
29
+ accessor: VertexAccessor<ValueT, OptionsT>,
30
+ attributes: Record<string, Attribute>,
31
+ options: OptionsT
32
+ ): (vertexIndex: number) => ValueT {
33
+ const vertexReaders: {[id: string]: (i: number) => number | number[]} = {};
34
+ for (const id of accessor.sources || []) {
35
+ const attribute = attributes[id];
36
+ if (attribute) {
37
+ vertexReaders[id] = getVertexReader(attribute);
38
+ } else {
39
+ throw new Error(`Cannot find attribute ${id}`);
40
+ }
41
+ }
42
+ const data: {[id: string]: number | number[]} = {};
43
+
44
+ return (vertexIndex: number) => {
45
+ for (const id in vertexReaders) {
46
+ data[id] = vertexReaders[id](vertexIndex);
47
+ }
48
+ return accessor.getValue(data, vertexIndex, options);
49
+ };
50
+ }
51
+
52
+ /** Read value out of a deck.gl Attribute by vertex */
53
+ function getVertexReader(attribute: Attribute): (vertexIndex: number) => number | number[] {
54
+ const value = attribute.value as TypedArray;
55
+ const {offset = 0, stride, size} = attribute.getAccessor();
56
+ const bytesPerElement = value.BYTES_PER_ELEMENT;
57
+ const elementOffset = offset / bytesPerElement;
58
+ const elementStride = stride ? stride / bytesPerElement : size;
59
+
60
+ if (size === 1) {
61
+ // Size 1, returns (i: number) => number
62
+ if (attribute.isConstant) {
63
+ return () => value[0];
64
+ }
65
+ return (vertexIndex: number) => {
66
+ const i = elementOffset + elementStride * vertexIndex;
67
+ return value[i];
68
+ };
69
+ }
70
+
71
+ // Size >1, returns (i: number) => number[]
72
+ let result: number[];
73
+ if (attribute.isConstant) {
74
+ result = Array.from(value);
75
+ return () => result;
76
+ }
77
+
78
+ result = new Array(size);
79
+ return (vertexIndex: number) => {
80
+ const i = elementOffset + elementStride * vertexIndex;
81
+ for (let j = 0; j < size; j++) {
82
+ result[j] = value[i + j];
83
+ }
84
+ return result;
85
+ };
86
+ }