@deck.gl/aggregation-layers 9.0.40 → 9.1.0-beta.3

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 (372) 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 +70 -0
  4. package/dist/common/aggregation-layer.js.map +1 -0
  5. package/dist/common/aggregator/aggregator.d.ts +76 -0
  6. package/dist/common/aggregator/aggregator.d.ts.map +1 -0
  7. package/dist/common/aggregator/aggregator.js +5 -0
  8. package/dist/common/aggregator/aggregator.js.map +1 -0
  9. package/dist/common/aggregator/cpu-aggregator/aggregate.d.ts +27 -0
  10. package/dist/common/aggregator/cpu-aggregator/aggregate.d.ts.map +1 -0
  11. package/dist/common/aggregator/cpu-aggregator/aggregate.js +67 -0
  12. package/dist/common/aggregator/cpu-aggregator/aggregate.js.map +1 -0
  13. package/dist/common/aggregator/cpu-aggregator/cpu-aggregator.d.ts +70 -0
  14. package/dist/common/aggregator/cpu-aggregator/cpu-aggregator.d.ts.map +1 -0
  15. package/dist/common/aggregator/cpu-aggregator/cpu-aggregator.js +140 -0
  16. package/dist/common/aggregator/cpu-aggregator/cpu-aggregator.js.map +1 -0
  17. package/dist/common/aggregator/cpu-aggregator/sort-bins.d.ts +15 -0
  18. package/dist/common/aggregator/cpu-aggregator/sort-bins.d.ts.map +1 -0
  19. package/dist/common/aggregator/cpu-aggregator/sort-bins.js +44 -0
  20. package/dist/common/aggregator/cpu-aggregator/sort-bins.js.map +1 -0
  21. package/dist/common/aggregator/cpu-aggregator/vertex-accessor.d.ts +21 -0
  22. package/dist/common/aggregator/cpu-aggregator/vertex-accessor.d.ts.map +1 -0
  23. package/dist/common/aggregator/cpu-aggregator/vertex-accessor.js +56 -0
  24. package/dist/common/aggregator/cpu-aggregator/vertex-accessor.js.map +1 -0
  25. package/dist/common/aggregator/gpu-aggregator/aggregation-transform-uniforms.d.ts +18 -0
  26. package/dist/common/aggregator/gpu-aggregator/aggregation-transform-uniforms.d.ts.map +1 -0
  27. package/dist/common/aggregator/gpu-aggregator/aggregation-transform-uniforms.js +21 -0
  28. package/dist/common/aggregator/gpu-aggregator/aggregation-transform-uniforms.js.map +1 -0
  29. package/dist/common/aggregator/gpu-aggregator/bin-sorter-uniforms.d.ts +14 -0
  30. package/dist/common/aggregator/gpu-aggregator/bin-sorter-uniforms.d.ts.map +1 -0
  31. package/dist/common/aggregator/gpu-aggregator/bin-sorter-uniforms.js +18 -0
  32. package/dist/common/aggregator/gpu-aggregator/bin-sorter-uniforms.js.map +1 -0
  33. package/dist/common/aggregator/gpu-aggregator/utils.d.ts +6 -0
  34. package/dist/common/aggregator/gpu-aggregator/utils.d.ts.map +1 -0
  35. package/dist/common/aggregator/gpu-aggregator/utils.js +25 -0
  36. package/dist/common/aggregator/gpu-aggregator/utils.js.map +1 -0
  37. package/dist/common/aggregator/gpu-aggregator/webgl-aggregation-transform.d.ts +24 -0
  38. package/dist/common/aggregator/gpu-aggregator/webgl-aggregation-transform.d.ts.map +1 -0
  39. package/dist/common/aggregator/gpu-aggregator/webgl-aggregation-transform.js +216 -0
  40. package/dist/common/aggregator/gpu-aggregator/webgl-aggregation-transform.js.map +1 -0
  41. package/dist/common/aggregator/gpu-aggregator/webgl-aggregator.d.ts +81 -0
  42. package/dist/common/aggregator/gpu-aggregator/webgl-aggregator.d.ts.map +1 -0
  43. package/dist/common/aggregator/gpu-aggregator/webgl-aggregator.js +202 -0
  44. package/dist/common/aggregator/gpu-aggregator/webgl-aggregator.js.map +1 -0
  45. package/dist/common/aggregator/gpu-aggregator/webgl-bin-sorter.d.ts +38 -0
  46. package/dist/common/aggregator/gpu-aggregator/webgl-bin-sorter.d.ts.map +1 -0
  47. package/dist/common/aggregator/gpu-aggregator/webgl-bin-sorter.js +224 -0
  48. package/dist/common/aggregator/gpu-aggregator/webgl-bin-sorter.js.map +1 -0
  49. package/dist/common/aggregator/index.d.ts +6 -0
  50. package/dist/common/aggregator/index.d.ts.map +1 -0
  51. package/dist/common/aggregator/index.js +6 -0
  52. package/dist/common/aggregator/index.js.map +1 -0
  53. package/dist/common/types.d.ts +11 -0
  54. package/dist/common/types.d.ts.map +1 -0
  55. package/dist/common/types.js +5 -0
  56. package/dist/common/types.js.map +1 -0
  57. package/dist/common/utils/bounds-utils.d.ts +10 -0
  58. package/dist/common/utils/bounds-utils.d.ts.map +1 -0
  59. package/dist/common/utils/bounds-utils.js +21 -0
  60. package/dist/common/utils/bounds-utils.js.map +1 -0
  61. package/dist/common/utils/color-utils.d.ts +10 -0
  62. package/dist/common/utils/color-utils.d.ts.map +1 -0
  63. package/dist/common/utils/color-utils.js +66 -0
  64. package/dist/common/utils/color-utils.js.map +1 -0
  65. package/dist/common/utils/prop-utils.d.ts.map +1 -0
  66. package/dist/common/utils/prop-utils.js +13 -0
  67. package/dist/common/utils/prop-utils.js.map +1 -0
  68. package/dist/common/utils/scale-utils.d.ts +46 -0
  69. package/dist/common/utils/scale-utils.d.ts.map +1 -0
  70. package/dist/common/utils/scale-utils.js +181 -0
  71. package/dist/common/utils/scale-utils.js.map +1 -0
  72. package/dist/contour-layer/bin-options-uniforms.d.ts +13 -0
  73. package/dist/contour-layer/bin-options-uniforms.d.ts.map +1 -0
  74. package/dist/contour-layer/bin-options-uniforms.js +18 -0
  75. package/dist/contour-layer/bin-options-uniforms.js.map +1 -0
  76. package/dist/contour-layer/contour-layer.d.ts +42 -50
  77. package/dist/contour-layer/contour-layer.d.ts.map +1 -1
  78. package/dist/contour-layer/contour-layer.js +233 -192
  79. package/dist/contour-layer/contour-layer.js.map +1 -0
  80. package/dist/contour-layer/contour-utils.d.ts +36 -15
  81. package/dist/contour-layer/contour-utils.d.ts.map +1 -1
  82. package/dist/contour-layer/contour-utils.js +25 -29
  83. package/dist/contour-layer/contour-utils.js.map +1 -0
  84. package/dist/contour-layer/marching-squares-codes.d.ts.map +1 -1
  85. package/dist/contour-layer/marching-squares-codes.js +4 -0
  86. package/dist/contour-layer/marching-squares-codes.js.map +1 -0
  87. package/dist/contour-layer/marching-squares.d.ts +22 -6
  88. package/dist/contour-layer/marching-squares.d.ts.map +1 -1
  89. package/dist/contour-layer/marching-squares.js +72 -68
  90. package/dist/contour-layer/marching-squares.js.map +1 -0
  91. package/dist/contour-layer/value-reader.d.ts +10 -0
  92. package/dist/contour-layer/value-reader.d.ts.map +1 -0
  93. package/dist/contour-layer/value-reader.js +47 -0
  94. package/dist/contour-layer/value-reader.js.map +1 -0
  95. package/dist/dist.dev.js +4844 -4083
  96. package/dist/grid-layer/bin-options-uniforms.d.ts +13 -0
  97. package/dist/grid-layer/bin-options-uniforms.d.ts.map +1 -0
  98. package/dist/grid-layer/bin-options-uniforms.js +18 -0
  99. package/dist/grid-layer/bin-options-uniforms.js.map +1 -0
  100. package/dist/grid-layer/grid-cell-layer-vertex.glsl.d.ts +3 -0
  101. package/dist/grid-layer/grid-cell-layer-vertex.glsl.d.ts.map +1 -0
  102. package/dist/grid-layer/grid-cell-layer-vertex.glsl.js +52 -0
  103. package/dist/grid-layer/grid-cell-layer-vertex.glsl.js.map +1 -0
  104. package/dist/grid-layer/grid-cell-layer.d.ts +32 -0
  105. package/dist/grid-layer/grid-cell-layer.d.ts.map +1 -0
  106. package/dist/grid-layer/grid-cell-layer.js +94 -0
  107. package/dist/grid-layer/grid-cell-layer.js.map +1 -0
  108. package/dist/grid-layer/grid-layer-uniforms.d.ts +21 -0
  109. package/dist/grid-layer/grid-layer-uniforms.d.ts.map +1 -0
  110. package/dist/grid-layer/grid-layer-uniforms.js +24 -0
  111. package/dist/grid-layer/grid-layer-uniforms.js.map +1 -0
  112. package/dist/grid-layer/grid-layer.d.ts +176 -14
  113. package/dist/grid-layer/grid-layer.d.ts.map +1 -1
  114. package/dist/grid-layer/grid-layer.js +343 -46
  115. package/dist/grid-layer/grid-layer.js.map +1 -0
  116. package/dist/{aggregation-layer.d.ts → heatmap-layer/aggregation-layer.d.ts} +1 -0
  117. package/dist/heatmap-layer/aggregation-layer.d.ts.map +1 -0
  118. package/dist/{aggregation-layer.js → heatmap-layer/aggregation-layer.js} +7 -21
  119. package/dist/heatmap-layer/aggregation-layer.js.map +1 -0
  120. package/dist/heatmap-layer/heatmap-layer-uniforms.d.ts +30 -0
  121. package/dist/heatmap-layer/heatmap-layer-uniforms.d.ts.map +1 -0
  122. package/dist/heatmap-layer/heatmap-layer-uniforms.js +33 -0
  123. package/dist/heatmap-layer/heatmap-layer-uniforms.js.map +1 -0
  124. package/dist/heatmap-layer/heatmap-layer-utils.d.ts +1 -1
  125. package/dist/heatmap-layer/heatmap-layer-utils.d.ts.map +1 -1
  126. package/dist/heatmap-layer/heatmap-layer-utils.js +4 -0
  127. package/dist/heatmap-layer/heatmap-layer-utils.js.map +1 -0
  128. package/dist/heatmap-layer/heatmap-layer.d.ts +6 -4
  129. package/dist/heatmap-layer/heatmap-layer.d.ts.map +1 -1
  130. package/dist/heatmap-layer/heatmap-layer.js +44 -33
  131. package/dist/heatmap-layer/heatmap-layer.js.map +1 -0
  132. package/dist/heatmap-layer/max-fs.glsl.d.ts.map +1 -1
  133. package/dist/heatmap-layer/max-fs.glsl.js +4 -0
  134. package/dist/heatmap-layer/max-fs.glsl.js.map +1 -0
  135. package/dist/heatmap-layer/max-vs.glsl.d.ts +1 -1
  136. package/dist/heatmap-layer/max-vs.glsl.d.ts.map +1 -1
  137. package/dist/heatmap-layer/max-vs.glsl.js +7 -4
  138. package/dist/heatmap-layer/max-vs.glsl.js.map +1 -0
  139. package/dist/heatmap-layer/triangle-layer-fragment.glsl.d.ts +1 -1
  140. package/dist/heatmap-layer/triangle-layer-fragment.glsl.d.ts.map +1 -1
  141. package/dist/heatmap-layer/triangle-layer-fragment.glsl.js +6 -23
  142. package/dist/heatmap-layer/triangle-layer-fragment.glsl.js.map +1 -0
  143. package/dist/heatmap-layer/triangle-layer-uniforms.d.ts +22 -0
  144. package/dist/heatmap-layer/triangle-layer-uniforms.d.ts.map +1 -0
  145. package/dist/heatmap-layer/triangle-layer-uniforms.js +23 -0
  146. package/dist/heatmap-layer/triangle-layer-uniforms.js.map +1 -0
  147. package/dist/heatmap-layer/triangle-layer-vertex.glsl.d.ts +1 -1
  148. package/dist/heatmap-layer/triangle-layer-vertex.glsl.d.ts.map +1 -1
  149. package/dist/heatmap-layer/triangle-layer-vertex.glsl.js +11 -30
  150. package/dist/heatmap-layer/triangle-layer-vertex.glsl.js.map +1 -0
  151. package/dist/heatmap-layer/triangle-layer.d.ts +4 -10
  152. package/dist/heatmap-layer/triangle-layer.d.ts.map +1 -1
  153. package/dist/heatmap-layer/triangle-layer.js +18 -30
  154. package/dist/heatmap-layer/triangle-layer.js.map +1 -0
  155. package/dist/heatmap-layer/weights-fs.glsl.d.ts.map +1 -1
  156. package/dist/heatmap-layer/weights-fs.glsl.js +4 -0
  157. package/dist/heatmap-layer/weights-fs.glsl.js.map +1 -0
  158. package/dist/heatmap-layer/weights-vs.glsl.d.ts +1 -1
  159. package/dist/heatmap-layer/weights-vs.glsl.d.ts.map +1 -1
  160. package/dist/heatmap-layer/weights-vs.glsl.js +7 -7
  161. package/dist/heatmap-layer/weights-vs.glsl.js.map +1 -0
  162. package/dist/hexagon-layer/bin-options-uniforms.d.ts +14 -0
  163. package/dist/hexagon-layer/bin-options-uniforms.d.ts.map +1 -0
  164. package/dist/hexagon-layer/bin-options-uniforms.js +18 -0
  165. package/dist/hexagon-layer/bin-options-uniforms.js.map +1 -0
  166. package/dist/hexagon-layer/hexagon-cell-layer-vertex.glsl.d.ts +3 -0
  167. package/dist/hexagon-layer/hexagon-cell-layer-vertex.glsl.d.ts.map +1 -0
  168. package/dist/hexagon-layer/hexagon-cell-layer-vertex.glsl.js +56 -0
  169. package/dist/hexagon-layer/hexagon-cell-layer-vertex.glsl.js.map +1 -0
  170. package/dist/hexagon-layer/hexagon-cell-layer.d.ts +29 -0
  171. package/dist/hexagon-layer/hexagon-cell-layer.d.ts.map +1 -0
  172. package/dist/hexagon-layer/hexagon-cell-layer.js +95 -0
  173. package/dist/hexagon-layer/hexagon-cell-layer.js.map +1 -0
  174. package/dist/hexagon-layer/hexagon-layer-uniforms.d.ts +19 -0
  175. package/dist/hexagon-layer/hexagon-layer-uniforms.d.ts.map +1 -0
  176. package/dist/hexagon-layer/hexagon-layer-uniforms.js +22 -0
  177. package/dist/hexagon-layer/hexagon-layer-uniforms.js.map +1 -0
  178. package/dist/hexagon-layer/hexagon-layer.d.ts +84 -54
  179. package/dist/hexagon-layer/hexagon-layer.d.ts.map +1 -1
  180. package/dist/hexagon-layer/hexagon-layer.js +308 -123
  181. package/dist/hexagon-layer/hexagon-layer.js.map +1 -0
  182. package/dist/hexagon-layer/hexbin.d.ts +17 -0
  183. package/dist/hexagon-layer/hexbin.d.ts.map +1 -0
  184. package/dist/hexagon-layer/hexbin.js +70 -0
  185. package/dist/hexagon-layer/hexbin.js.map +1 -0
  186. package/dist/index.cjs +3026 -2947
  187. package/dist/index.cjs.map +4 -4
  188. package/dist/index.d.ts +7 -13
  189. package/dist/index.d.ts.map +1 -1
  190. package/dist/index.js +6 -27
  191. package/dist/index.js.map +1 -0
  192. package/dist/screen-grid-layer/bin-options-uniforms.d.ts +11 -0
  193. package/dist/screen-grid-layer/bin-options-uniforms.d.ts.map +1 -0
  194. package/dist/screen-grid-layer/bin-options-uniforms.js +16 -0
  195. package/dist/screen-grid-layer/bin-options-uniforms.js.map +1 -0
  196. package/dist/screen-grid-layer/screen-grid-cell-layer.d.ts +11 -16
  197. package/dist/screen-grid-layer/screen-grid-cell-layer.d.ts.map +1 -1
  198. package/dist/screen-grid-layer/screen-grid-cell-layer.js +53 -134
  199. package/dist/screen-grid-layer/screen-grid-cell-layer.js.map +1 -0
  200. package/dist/screen-grid-layer/screen-grid-layer-fragment.glsl.d.ts +1 -1
  201. package/dist/screen-grid-layer/screen-grid-layer-fragment.glsl.d.ts.map +1 -1
  202. package/dist/screen-grid-layer/screen-grid-layer-fragment.glsl.js +5 -24
  203. package/dist/screen-grid-layer/screen-grid-layer-fragment.glsl.js.map +1 -0
  204. package/dist/screen-grid-layer/screen-grid-layer-uniforms.d.ts +17 -0
  205. package/dist/screen-grid-layer/screen-grid-layer-uniforms.d.ts.map +1 -0
  206. package/dist/screen-grid-layer/screen-grid-layer-uniforms.js +20 -0
  207. package/dist/screen-grid-layer/screen-grid-layer-uniforms.js.map +1 -0
  208. package/dist/screen-grid-layer/screen-grid-layer-vertex.glsl.d.ts +1 -1
  209. package/dist/screen-grid-layer/screen-grid-layer-vertex.glsl.d.ts.map +1 -1
  210. package/dist/screen-grid-layer/screen-grid-layer-vertex.glsl.js +22 -62
  211. package/dist/screen-grid-layer/screen-grid-layer-vertex.glsl.js.map +1 -0
  212. package/dist/screen-grid-layer/screen-grid-layer.d.ts +33 -40
  213. package/dist/screen-grid-layer/screen-grid-layer.d.ts.map +1 -1
  214. package/dist/screen-grid-layer/screen-grid-layer.js +158 -174
  215. package/dist/screen-grid-layer/screen-grid-layer.js.map +1 -0
  216. package/dist.min.js +401 -382
  217. package/package.json +10 -9
  218. package/src/common/aggregation-layer.ts +107 -0
  219. package/src/common/aggregator/aggregator.ts +88 -0
  220. package/src/common/aggregator/cpu-aggregator/aggregate.ts +101 -0
  221. package/src/common/aggregator/cpu-aggregator/cpu-aggregator.ts +203 -0
  222. package/src/common/aggregator/cpu-aggregator/sort-bins.ts +63 -0
  223. package/src/common/aggregator/cpu-aggregator/vertex-accessor.ts +86 -0
  224. package/src/common/aggregator/gpu-aggregator/aggregation-transform-uniforms.ts +33 -0
  225. package/src/common/aggregator/gpu-aggregator/bin-sorter-uniforms.ts +27 -0
  226. package/src/common/aggregator/gpu-aggregator/utils.ts +27 -0
  227. package/src/common/aggregator/gpu-aggregator/webgl-aggregation-transform.ts +247 -0
  228. package/src/common/aggregator/gpu-aggregator/webgl-aggregator.ts +274 -0
  229. package/src/common/aggregator/gpu-aggregator/webgl-bin-sorter.ts +258 -0
  230. package/src/common/aggregator/index.ts +10 -0
  231. package/src/{types.ts → common/types.ts} +10 -4
  232. package/src/common/utils/bounds-utils.ts +34 -0
  233. package/src/common/utils/color-utils.ts +86 -0
  234. package/src/common/utils/prop-utils.ts +13 -0
  235. package/src/common/utils/scale-utils.ts +236 -0
  236. package/src/contour-layer/bin-options-uniforms.ts +26 -0
  237. package/src/contour-layer/contour-layer.ts +300 -265
  238. package/src/contour-layer/contour-utils.ts +68 -39
  239. package/src/contour-layer/marching-squares-codes.ts +4 -0
  240. package/src/contour-layer/marching-squares.ts +93 -82
  241. package/src/contour-layer/value-reader.ts +65 -0
  242. package/src/grid-layer/bin-options-uniforms.ts +26 -0
  243. package/src/grid-layer/grid-cell-layer-vertex.glsl.ts +68 -0
  244. package/src/grid-layer/grid-cell-layer.ts +141 -0
  245. package/src/grid-layer/grid-layer-uniforms.ts +37 -0
  246. package/src/grid-layer/grid-layer.ts +614 -73
  247. package/src/{aggregation-layer.ts → heatmap-layer/aggregation-layer.ts} +6 -21
  248. package/src/heatmap-layer/heatmap-layer-uniforms.ts +50 -0
  249. package/src/heatmap-layer/heatmap-layer-utils.ts +9 -1
  250. package/src/heatmap-layer/heatmap-layer.ts +59 -36
  251. package/src/heatmap-layer/max-fs.glsl.ts +4 -0
  252. package/src/heatmap-layer/max-vs.glsl.ts +7 -4
  253. package/src/heatmap-layer/triangle-layer-fragment.glsl.ts +5 -23
  254. package/src/heatmap-layer/triangle-layer-uniforms.ts +37 -0
  255. package/src/heatmap-layer/triangle-layer-vertex.glsl.ts +10 -30
  256. package/src/heatmap-layer/triangle-layer.ts +26 -31
  257. package/src/heatmap-layer/weights-fs.glsl.ts +4 -0
  258. package/src/heatmap-layer/weights-vs.glsl.ts +7 -7
  259. package/src/hexagon-layer/bin-options-uniforms.ts +27 -0
  260. package/src/hexagon-layer/hexagon-cell-layer-vertex.glsl.ts +73 -0
  261. package/src/hexagon-layer/hexagon-cell-layer.ts +141 -0
  262. package/src/hexagon-layer/hexagon-layer-uniforms.ts +34 -0
  263. package/src/hexagon-layer/hexagon-layer.ts +454 -186
  264. package/src/hexagon-layer/hexbin.ts +79 -0
  265. package/src/index.ts +21 -34
  266. package/src/screen-grid-layer/bin-options-uniforms.ts +23 -0
  267. package/src/screen-grid-layer/screen-grid-cell-layer.ts +71 -156
  268. package/src/screen-grid-layer/screen-grid-layer-fragment.glsl.ts +4 -24
  269. package/src/screen-grid-layer/screen-grid-layer-uniforms.ts +31 -0
  270. package/src/screen-grid-layer/screen-grid-layer-vertex.glsl.ts +21 -64
  271. package/src/screen-grid-layer/screen-grid-layer.ts +194 -222
  272. package/dist/aggregation-layer.d.ts.map +0 -1
  273. package/dist/cpu-grid-layer/cpu-grid-layer.d.ts +0 -158
  274. package/dist/cpu-grid-layer/cpu-grid-layer.d.ts.map +0 -1
  275. package/dist/cpu-grid-layer/cpu-grid-layer.js +0 -130
  276. package/dist/cpu-grid-layer/grid-aggregator.d.ts +0 -35
  277. package/dist/cpu-grid-layer/grid-aggregator.d.ts.map +0 -1
  278. package/dist/cpu-grid-layer/grid-aggregator.js +0 -141
  279. package/dist/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.d.ts +0 -3
  280. package/dist/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.d.ts.map +0 -1
  281. package/dist/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.js +0 -30
  282. package/dist/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.d.ts +0 -3
  283. package/dist/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.d.ts.map +0 -1
  284. package/dist/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.js +0 -112
  285. package/dist/gpu-grid-layer/gpu-grid-cell-layer.d.ts +0 -48
  286. package/dist/gpu-grid-layer/gpu-grid-cell-layer.d.ts.map +0 -1
  287. package/dist/gpu-grid-layer/gpu-grid-cell-layer.js +0 -146
  288. package/dist/gpu-grid-layer/gpu-grid-layer.d.ts +0 -99
  289. package/dist/gpu-grid-layer/gpu-grid-layer.d.ts.map +0 -1
  290. package/dist/gpu-grid-layer/gpu-grid-layer.js +0 -289
  291. package/dist/grid-aggregation-layer.d.ts +0 -67
  292. package/dist/grid-aggregation-layer.d.ts.map +0 -1
  293. package/dist/grid-aggregation-layer.js +0 -173
  294. package/dist/hexagon-layer/hexagon-aggregator.d.ts +0 -27
  295. package/dist/hexagon-layer/hexagon-aggregator.d.ts.map +0 -1
  296. package/dist/hexagon-layer/hexagon-aggregator.js +0 -112
  297. package/dist/types.d.ts +0 -12
  298. package/dist/types.d.ts.map +0 -1
  299. package/dist/types.js +0 -1
  300. package/dist/utils/aggregation-operation-utils.d.ts +0 -19
  301. package/dist/utils/aggregation-operation-utils.d.ts.map +0 -1
  302. package/dist/utils/aggregation-operation-utils.js +0 -94
  303. package/dist/utils/bin-sorter.d.ts +0 -52
  304. package/dist/utils/bin-sorter.d.ts.map +0 -1
  305. package/dist/utils/bin-sorter.js +0 -167
  306. package/dist/utils/color-utils.d.ts +0 -3
  307. package/dist/utils/color-utils.d.ts.map +0 -1
  308. package/dist/utils/color-utils.js +0 -53
  309. package/dist/utils/cpu-aggregator.d.ts +0 -169
  310. package/dist/utils/cpu-aggregator.d.ts.map +0 -1
  311. package/dist/utils/cpu-aggregator.js +0 -421
  312. package/dist/utils/gpu-grid-aggregation/aggregate-all-fs.glsl.d.ts +0 -3
  313. package/dist/utils/gpu-grid-aggregation/aggregate-all-fs.glsl.d.ts.map +0 -1
  314. package/dist/utils/gpu-grid-aggregation/aggregate-all-fs.glsl.js +0 -36
  315. package/dist/utils/gpu-grid-aggregation/aggregate-all-vs.glsl.d.ts +0 -3
  316. package/dist/utils/gpu-grid-aggregation/aggregate-all-vs.glsl.d.ts.map +0 -1
  317. package/dist/utils/gpu-grid-aggregation/aggregate-all-vs.glsl.js +0 -42
  318. package/dist/utils/gpu-grid-aggregation/aggregate-to-grid-fs.glsl.d.ts +0 -3
  319. package/dist/utils/gpu-grid-aggregation/aggregate-to-grid-fs.glsl.d.ts.map +0 -1
  320. package/dist/utils/gpu-grid-aggregation/aggregate-to-grid-fs.glsl.js +0 -30
  321. package/dist/utils/gpu-grid-aggregation/aggregate-to-grid-vs.glsl.d.ts +0 -3
  322. package/dist/utils/gpu-grid-aggregation/aggregate-to-grid-vs.glsl.d.ts.map +0 -1
  323. package/dist/utils/gpu-grid-aggregation/aggregate-to-grid-vs.glsl.js +0 -61
  324. package/dist/utils/gpu-grid-aggregation/gpu-grid-aggregator-constants.d.ts +0 -38
  325. package/dist/utils/gpu-grid-aggregation/gpu-grid-aggregator-constants.d.ts.map +0 -1
  326. package/dist/utils/gpu-grid-aggregation/gpu-grid-aggregator-constants.js +0 -41
  327. package/dist/utils/gpu-grid-aggregation/gpu-grid-aggregator-utils.d.ts +0 -1
  328. package/dist/utils/gpu-grid-aggregation/gpu-grid-aggregator-utils.d.ts.map +0 -1
  329. package/dist/utils/gpu-grid-aggregation/gpu-grid-aggregator-utils.js +0 -1
  330. package/dist/utils/gpu-grid-aggregation/gpu-grid-aggregator.d.ts +0 -76
  331. package/dist/utils/gpu-grid-aggregation/gpu-grid-aggregator.d.ts.map +0 -1
  332. package/dist/utils/gpu-grid-aggregation/gpu-grid-aggregator.js +0 -555
  333. package/dist/utils/gpu-grid-aggregation/transform-mean-vs.glsl.d.ts +0 -3
  334. package/dist/utils/gpu-grid-aggregation/transform-mean-vs.glsl.d.ts.map +0 -1
  335. package/dist/utils/gpu-grid-aggregation/transform-mean-vs.glsl.js +0 -32
  336. package/dist/utils/grid-aggregation-utils.d.ts +0 -30
  337. package/dist/utils/grid-aggregation-utils.d.ts.map +0 -1
  338. package/dist/utils/grid-aggregation-utils.js +0 -114
  339. package/dist/utils/prop-utils.d.ts.map +0 -1
  340. package/dist/utils/prop-utils.js +0 -28
  341. package/dist/utils/resource-utils.d.ts +0 -14
  342. package/dist/utils/resource-utils.d.ts.map +0 -1
  343. package/dist/utils/resource-utils.js +0 -38
  344. package/dist/utils/scale-utils.d.ts +0 -15
  345. package/dist/utils/scale-utils.d.ts.map +0 -1
  346. package/dist/utils/scale-utils.js +0 -184
  347. package/src/cpu-grid-layer/cpu-grid-layer.ts +0 -329
  348. package/src/cpu-grid-layer/grid-aggregator.ts +0 -184
  349. package/src/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.ts +0 -35
  350. package/src/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.ts +0 -143
  351. package/src/gpu-grid-layer/gpu-grid-cell-layer.ts +0 -201
  352. package/src/gpu-grid-layer/gpu-grid-layer.ts +0 -455
  353. package/src/grid-aggregation-layer.ts +0 -243
  354. package/src/hexagon-layer/hexagon-aggregator.ts +0 -127
  355. package/src/utils/aggregation-operation-utils.ts +0 -118
  356. package/src/utils/bin-sorter.ts +0 -218
  357. package/src/utils/color-utils.ts +0 -57
  358. package/src/utils/cpu-aggregator.ts +0 -503
  359. package/src/utils/gpu-grid-aggregation/aggregate-all-fs.glsl.ts +0 -40
  360. package/src/utils/gpu-grid-aggregation/aggregate-all-vs.glsl.ts +0 -54
  361. package/src/utils/gpu-grid-aggregation/aggregate-to-grid-fs.glsl.ts +0 -35
  362. package/src/utils/gpu-grid-aggregation/aggregate-to-grid-vs.glsl.ts +0 -79
  363. package/src/utils/gpu-grid-aggregation/gpu-grid-aggregator-constants.ts +0 -46
  364. package/src/utils/gpu-grid-aggregation/gpu-grid-aggregator-utils.ts +0 -0
  365. package/src/utils/gpu-grid-aggregation/gpu-grid-aggregator.md +0 -155
  366. package/src/utils/gpu-grid-aggregation/gpu-grid-aggregator.ts +0 -690
  367. package/src/utils/gpu-grid-aggregation/transform-mean-vs.glsl.ts +0 -38
  368. package/src/utils/grid-aggregation-utils.ts +0 -147
  369. package/src/utils/prop-utils.ts +0 -29
  370. package/src/utils/resource-utils.ts +0 -53
  371. package/src/utils/scale-utils.js +0 -219
  372. /package/dist/{utils → common/utils}/prop-utils.d.ts +0 -0
@@ -0,0 +1,258 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import {Model, ModelProps} from '@luma.gl/engine';
6
+ import {createRenderTarget} from './utils';
7
+
8
+ import type {Device, Framebuffer, Texture} from '@luma.gl/core';
9
+ import type {WebGLAggregatorProps} from './webgl-aggregator';
10
+ import type {AggregationOperation} from '../aggregator';
11
+ import {BinSorterProps, binSorterUniforms} from './bin-sorter-uniforms';
12
+
13
+ const COLOR_CHANNELS = [0x1, 0x2, 0x4, 0x8]; // GPU color mask RED, GREEN, BLUE, ALPHA
14
+ const MAX_FLOAT32 = 3e38;
15
+ const EMPTY_MASKS = {SUM: 0, MEAN: 0, MIN: 0, MAX: 0, COUNT: 0};
16
+
17
+ export const TEXTURE_WIDTH = 1024;
18
+
19
+ /**
20
+ * This class manages the resources for performing the first step of aggregation
21
+ * Sort a list of data points into a number of bins
22
+ */
23
+ export class WebGLBinSorter {
24
+ device: Device;
25
+ model: Model;
26
+
27
+ /**
28
+ * A packed texture in which each pixel represents a bin.
29
+ * The index of the pixel in the memory layout is the bin index.
30
+ * Alpha value is the count of data points that fall into this bin
31
+ * R,G,B values are the aggregated values of each channel:
32
+ * - Sum of all data points if operation is 'SUM', or 'MEAN'
33
+ * - Min of all data points if operation is 'MIN'
34
+ * - Max of all data points if operation is 'MAX'
35
+ */
36
+ private binsFBO: Framebuffer | null = null;
37
+
38
+ constructor(device: Device, props: WebGLAggregatorProps) {
39
+ this.device = device;
40
+ this.model = createModel(device, props);
41
+ }
42
+
43
+ get texture(): Texture | null {
44
+ return this.binsFBO ? this.binsFBO.colorAttachments[0].texture : null;
45
+ }
46
+
47
+ destroy() {
48
+ this.model.destroy();
49
+ this.binsFBO?.colorAttachments[0].texture.destroy();
50
+ this.binsFBO?.destroy();
51
+ }
52
+
53
+ getBinValues(index: number): Float32Array | null {
54
+ if (!this.binsFBO) {
55
+ return null;
56
+ }
57
+ const x = index % TEXTURE_WIDTH;
58
+ const y = Math.floor(index / TEXTURE_WIDTH);
59
+ const buffer = this.device.readPixelsToArrayWebGL(this.binsFBO, {
60
+ sourceX: x,
61
+ sourceY: y,
62
+ sourceWidth: 1,
63
+ sourceHeight: 1
64
+ }).buffer;
65
+ return new Float32Array(buffer);
66
+ }
67
+
68
+ setDimensions(binCount: number, binIdRange: [number, number][]) {
69
+ const width = TEXTURE_WIDTH;
70
+ const height = Math.ceil(binCount / width);
71
+
72
+ // Only destroy existing texture if it is not large enough
73
+ if (!this.binsFBO) {
74
+ this.binsFBO = createRenderTarget(this.device, width, height);
75
+ } else if (this.binsFBO.height < height) {
76
+ this.binsFBO.resize({width, height});
77
+ }
78
+
79
+ const binSorterProps: BinSorterProps = {
80
+ binIdRange: [
81
+ binIdRange[0][0],
82
+ binIdRange[0][1],
83
+ binIdRange[1]?.[0] || 0,
84
+ binIdRange[1]?.[1] || 0
85
+ ],
86
+ targetSize: [this.binsFBO.width, this.binsFBO.height]
87
+ };
88
+ this.model.shaderInputs.setProps({binSorter: binSorterProps});
89
+ }
90
+
91
+ setModelProps(
92
+ props: Pick<ModelProps, 'vertexCount' | 'uniforms' | 'attributes' | 'constantAttributes'> & {
93
+ shaderModuleProps?: Record<string, any>;
94
+ }
95
+ ) {
96
+ const model = this.model;
97
+ if (props.attributes) {
98
+ model.setAttributes(props.attributes);
99
+ }
100
+ if (props.constantAttributes) {
101
+ model.setConstantAttributes(props.constantAttributes);
102
+ }
103
+ if (props.vertexCount !== undefined) {
104
+ model.setVertexCount(props.vertexCount);
105
+ }
106
+ if (props.shaderModuleProps) {
107
+ model.shaderInputs.setProps(props.shaderModuleProps);
108
+ }
109
+ }
110
+
111
+ /** Update aggregation */
112
+ update(
113
+ /** The aggregation operation for each channel. Use null to skip update. */
114
+ operations: (AggregationOperation | null)[]
115
+ ) {
116
+ if (!this.binsFBO) {
117
+ return;
118
+ }
119
+ const masks = getMaskByOperation(operations);
120
+ this._updateBins('SUM', masks.SUM + masks.MEAN);
121
+ this._updateBins('MIN', masks.MIN);
122
+ this._updateBins('MAX', masks.MAX);
123
+ }
124
+
125
+ /** Recalculate aggregation on the given channels using the given operation */
126
+ private _updateBins(
127
+ operation: AggregationOperation,
128
+ /** GPU bit mask of one or more channels that should be updated */
129
+ colorMask: number
130
+ ) {
131
+ if (colorMask === 0) {
132
+ return;
133
+ }
134
+ colorMask |= COLOR_CHANNELS[3]; // Also renders to the alpha channel (point count)
135
+
136
+ const model = this.model;
137
+ const target = this.binsFBO!;
138
+
139
+ const initialValue = operation === 'MAX' ? -MAX_FLOAT32 : operation === 'MIN' ? MAX_FLOAT32 : 0;
140
+ const renderPass = this.device.beginRenderPass({
141
+ id: `gpu-aggregation-${operation}`,
142
+ framebuffer: target,
143
+ parameters: {
144
+ viewport: [0, 0, target.width, target.height],
145
+ colorMask
146
+ },
147
+ clearColor: [initialValue, initialValue, initialValue, 0],
148
+ clearDepth: false,
149
+ clearStencil: false
150
+ });
151
+ model.setParameters({
152
+ blend: true,
153
+ blendColorSrcFactor: 'one',
154
+ blendColorDstFactor: 'one',
155
+ blendAlphaSrcFactor: 'one',
156
+ blendAlphaDstFactor: 'one',
157
+ blendColorOperation: operation === 'MAX' ? 'max' : operation === 'MIN' ? 'min' : 'add',
158
+ blendAlphaOperation: 'add'
159
+ });
160
+ model.draw(renderPass);
161
+ renderPass.end();
162
+ }
163
+ }
164
+
165
+ /** Convert a [channel -> operation] map to a [operation -> GPU color mask] map */
166
+ function getMaskByOperation(
167
+ operations: (AggregationOperation | null)[]
168
+ ): Record<AggregationOperation, number> {
169
+ const result: Record<AggregationOperation, number> = {...EMPTY_MASKS};
170
+ for (let channel = 0; channel < operations.length; channel++) {
171
+ const op = operations[channel];
172
+ if (op) {
173
+ result[op] += COLOR_CHANNELS[channel];
174
+ }
175
+ }
176
+ return result;
177
+ }
178
+
179
+ function createModel(device: Device, props: WebGLAggregatorProps): Model {
180
+ let userVs = props.vs;
181
+
182
+ if (props.dimensions === 2) {
183
+ // If user provides 2d bin IDs, convert them to 1d indices for data packing
184
+ userVs += /* glsl */ `
185
+ void getBin(out int binId) {
186
+ ivec2 binId2;
187
+ getBin(binId2);
188
+ if (binId2.x < binSorter.binIdRange.x || binId2.x >= binSorter.binIdRange.y) {
189
+ binId = -1;
190
+ } else {
191
+ binId = (binId2.y - binSorter.binIdRange.z) * (binSorter.binIdRange.y - binSorter.binIdRange.x) + binId2.x;
192
+ }
193
+ }
194
+ `;
195
+ }
196
+
197
+ const vs = `\
198
+ #version 300 es
199
+ #define SHADER_NAME gpu-aggregation-sort-bins-vertex
200
+
201
+ ${userVs}
202
+
203
+ out vec3 v_Value;
204
+
205
+ void main() {
206
+ int binIndex;
207
+ getBin(binIndex);
208
+ binIndex = binIndex - binSorter.binIdRange.x;
209
+ if (binIndex < 0) {
210
+ gl_Position = vec4(0.);
211
+ return;
212
+ }
213
+ int row = binIndex / binSorter.targetSize.x;
214
+ int col = binIndex - row * binSorter.targetSize.x;
215
+ vec2 position = (vec2(col, row) + 0.5) / vec2(binSorter.targetSize) * 2.0 - 1.0;
216
+ gl_Position = vec4(position, 0.0, 1.0);
217
+ gl_PointSize = 1.0;
218
+
219
+ #if NUM_CHANNELS == 3
220
+ getValue(v_Value);
221
+ #elif NUM_CHANNELS == 2
222
+ getValue(v_Value.xy);
223
+ #else
224
+ getValue(v_Value.x);
225
+ #endif
226
+ }
227
+ `;
228
+ const fs = /* glsl */ `\
229
+ #version 300 es
230
+ #define SHADER_NAME gpu-aggregation-sort-bins-fragment
231
+
232
+ precision highp float;
233
+
234
+ in vec3 v_Value;
235
+ out vec4 fragColor;
236
+
237
+ void main() {
238
+ fragColor.xyz = v_Value;
239
+
240
+ #ifdef MODULE_GEOMETRY
241
+ geometry.uv = vec2(0.);
242
+ DECKGL_FILTER_COLOR(fragColor, geometry);
243
+ #endif
244
+
245
+ fragColor.w = 1.0;
246
+ }
247
+ `;
248
+ const model = new Model(device, {
249
+ bufferLayout: props.bufferLayout,
250
+ modules: [...(props.modules || []), binSorterUniforms],
251
+ defines: {...props.defines, NON_INSTANCED_MODEL: 1, NUM_CHANNELS: props.channelCount},
252
+ isInstanced: false,
253
+ vs,
254
+ fs,
255
+ topology: 'point-list'
256
+ });
257
+ return model;
258
+ }
@@ -0,0 +1,10 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ export {CPUAggregator} from './cpu-aggregator/cpu-aggregator';
6
+ export {WebGLAggregator} from './gpu-aggregator/webgl-aggregator';
7
+
8
+ export type {Aggregator, AggregatedBin, AggregationOperation, AggregationProps} from './aggregator';
9
+ export type {CPUAggregatorProps} from './cpu-aggregator/cpu-aggregator';
10
+ export type {WebGLAggregatorProps} from './gpu-aggregator/webgl-aggregator';
@@ -1,11 +1,17 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
1
5
  /** Type assigned to e.g. getColorValue/getElevationValue props in aggregation layers (e.g. CPUGridLayer, HexagonLayer)*/
2
- export type AggregateAccessor<DataT = any> = (args: {
6
+ export type AggregateAccessor<DataT = any> = (
3
7
  /** a list of objects whose positions fall inside this cell. */
4
- objects: DataT[];
8
+ objects: DataT[],
5
9
  objectInfo: {
6
10
  /** the indices of `objects` in the original data. */
7
11
  indices: number[];
8
12
  /** the value of the `data` prop */
9
13
  data: any;
10
- };
11
- }) => number;
14
+ }
15
+ ) => number;
16
+
17
+ export type ScaleType = 'linear' | 'quantize' | 'quantile' | 'ordinal';
@@ -0,0 +1,34 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ /** Utility to estimate binIdRange as expected by AggregatorProps */
6
+ export function getBinIdRange({
7
+ dataBounds,
8
+ getBinId,
9
+ padding = 0
10
+ }: {
11
+ /** Bounds of the input data */
12
+ dataBounds: [min: number[], max: number[]];
13
+ /** Given a data point, returns the bin id that it belongs to */
14
+ getBinId: (p: number[]) => number[];
15
+ /** Add a border around the result to avoid clipping */
16
+ padding?: number;
17
+ }): [number, number][] {
18
+ const corners = [
19
+ dataBounds[0],
20
+ dataBounds[1],
21
+ [dataBounds[0][0], dataBounds[1][1]],
22
+ [dataBounds[1][0], dataBounds[0][1]]
23
+ ].map(p => getBinId(p));
24
+
25
+ const minX = Math.min(...corners.map(p => p[0])) - padding;
26
+ const minY = Math.min(...corners.map(p => p[1])) - padding;
27
+ const maxX = Math.max(...corners.map(p => p[0])) + padding + 1;
28
+ const maxY = Math.max(...corners.map(p => p[1])) + padding + 1;
29
+
30
+ return [
31
+ [minX, maxX],
32
+ [minY, maxY]
33
+ ];
34
+ }
@@ -0,0 +1,86 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {Color} from '@deck.gl/core';
6
+ import type {Device, Texture} from '@luma.gl/core';
7
+ import type {NumericArray, TypedArray, TypedArrayConstructor} from '@math.gl/types';
8
+ import type {ScaleType} from '../types';
9
+
10
+ export const defaultColorRange: Color[] = [
11
+ [255, 255, 178],
12
+ [254, 217, 118],
13
+ [254, 178, 76],
14
+ [253, 141, 60],
15
+ [240, 59, 32],
16
+ [189, 0, 38]
17
+ ];
18
+
19
+ // Converts a colorRange array to a flat array with 4 components per color
20
+ export function colorRangeToFlatArray(
21
+ colorRange: Color[] | NumericArray,
22
+ normalize = false,
23
+ ArrayType: TypedArrayConstructor = Float32Array
24
+ ): TypedArray {
25
+ let flatArray: TypedArray;
26
+
27
+ if (Number.isFinite(colorRange[0])) {
28
+ // its already a flat array.
29
+ flatArray = new ArrayType(colorRange as NumericArray);
30
+ } else {
31
+ // flatten it
32
+ flatArray = new ArrayType(colorRange.length * 4);
33
+ let index = 0;
34
+
35
+ for (let i = 0; i < colorRange.length; i++) {
36
+ const color = colorRange[i];
37
+ flatArray[index++] = color[0];
38
+ flatArray[index++] = color[1];
39
+ flatArray[index++] = color[2];
40
+ flatArray[index++] = Number.isFinite(color[3]) ? color[3] : 255;
41
+ }
42
+ }
43
+
44
+ if (normalize) {
45
+ for (let i = 0; i < flatArray.length; i++) {
46
+ flatArray[i] /= 255;
47
+ }
48
+ }
49
+ return flatArray;
50
+ }
51
+
52
+ export const COLOR_RANGE_FILTER: Record<ScaleType, 'linear' | 'nearest'> = {
53
+ linear: 'linear',
54
+ quantile: 'nearest',
55
+ quantize: 'nearest',
56
+ ordinal: 'nearest'
57
+ } as const;
58
+
59
+ export function updateColorRangeTexture(texture: Texture, type: ScaleType) {
60
+ texture.setSampler({
61
+ minFilter: COLOR_RANGE_FILTER[type],
62
+ magFilter: COLOR_RANGE_FILTER[type]
63
+ });
64
+ }
65
+
66
+ export function createColorRangeTexture(
67
+ device: Device,
68
+ colorRange: Color[] | NumericArray,
69
+ type: ScaleType = 'linear'
70
+ ): Texture {
71
+ const colors = colorRangeToFlatArray(colorRange, false, Uint8Array);
72
+
73
+ return device.createTexture({
74
+ format: 'rgba8unorm',
75
+ mipmaps: false,
76
+ sampler: {
77
+ minFilter: COLOR_RANGE_FILTER[type],
78
+ magFilter: COLOR_RANGE_FILTER[type],
79
+ addressModeU: 'clamp-to-edge',
80
+ addressModeV: 'clamp-to-edge'
81
+ },
82
+ data: colors,
83
+ width: colors.length / 4,
84
+ height: 1
85
+ });
86
+ }
@@ -0,0 +1,13 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ export function filterProps(props, filterKeys) {
6
+ const filteredProps = {};
7
+ for (const key in props) {
8
+ if (!filterKeys.includes(key)) {
9
+ filteredProps[key] = props[key];
10
+ }
11
+ }
12
+ return filteredProps;
13
+ }
@@ -0,0 +1,236 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {BinaryAttribute} from '@deck.gl/core';
6
+ import type {ScaleType} from '../types';
7
+
8
+ type ScaleProps = {
9
+ scaleType: ScaleType;
10
+ /** Trim the lower end of the domain by this percentile. Set to `0` to disable. */
11
+ lowerPercentile: number;
12
+ /** Trim the upper end of the domain by this percentile. Set to `100` to disable. */
13
+ upperPercentile: number;
14
+ };
15
+
16
+ /** Applies a scale to BinaryAttribute */
17
+ export class AttributeWithScale {
18
+ /** Input values accessor. Has either a `value` (CPU aggregation) or a `buffer` (GPU aggregation) */
19
+ private readonly input: BinaryAttribute;
20
+ private readonly inputLength: number;
21
+
22
+ private props: ScaleProps = {
23
+ scaleType: 'linear',
24
+ lowerPercentile: 0,
25
+ upperPercentile: 100
26
+ };
27
+
28
+ // cached calculations
29
+ private _percentile?: {attribute: BinaryAttribute; domain: number[]};
30
+ private _ordinal?: {attribute: BinaryAttribute; domain: number[]};
31
+
32
+ /** Output values accessor */
33
+ attribute: BinaryAttribute;
34
+ /** [min, max] of attribute values, or null if unknown */
35
+ domain: [number, number] | null = null;
36
+ /** Valid domain if lower/upper percentile are defined */
37
+ cutoff: [number, number] | null = null;
38
+
39
+ constructor(input: BinaryAttribute, inputLength: number) {
40
+ this.input = input;
41
+ this.inputLength = inputLength;
42
+ // No processing is needed with the default scale
43
+ this.attribute = input;
44
+ }
45
+
46
+ private getScalePercentile() {
47
+ if (!this._percentile) {
48
+ const value = getAttributeValue(this.input, this.inputLength);
49
+ this._percentile = applyScaleQuantile(value);
50
+ }
51
+ return this._percentile;
52
+ }
53
+
54
+ private getScaleOrdinal() {
55
+ if (!this._ordinal) {
56
+ const value = getAttributeValue(this.input, this.inputLength);
57
+ this._ordinal = applyScaleOrdinal(value);
58
+ }
59
+ return this._ordinal;
60
+ }
61
+
62
+ /** Returns the [lowerCutoff, upperCutoff] of scaled values, or null if not applicable */
63
+ private getCutoff({
64
+ scaleType,
65
+ lowerPercentile,
66
+ upperPercentile
67
+ }: ScaleProps): [number, number] | null {
68
+ if (scaleType === 'quantile') {
69
+ return [lowerPercentile, upperPercentile - 1];
70
+ }
71
+
72
+ if (lowerPercentile > 0 || upperPercentile < 100) {
73
+ const {domain: thresholds} = this.getScalePercentile();
74
+ let lowValue = thresholds[Math.floor(lowerPercentile) - 1] ?? -Infinity;
75
+ let highValue = thresholds[Math.floor(upperPercentile) - 1] ?? Infinity;
76
+
77
+ if (scaleType === 'ordinal') {
78
+ const {domain: sortedUniqueValues} = this.getScaleOrdinal();
79
+ lowValue = sortedUniqueValues.findIndex(x => x >= lowValue);
80
+ highValue = sortedUniqueValues.findIndex(x => x > highValue) - 1;
81
+ if (highValue === -2) {
82
+ highValue = sortedUniqueValues.length - 1;
83
+ }
84
+ }
85
+ return [lowValue, highValue];
86
+ }
87
+
88
+ return null;
89
+ }
90
+
91
+ update(props: ScaleProps) {
92
+ const oldProps = this.props;
93
+
94
+ if (props.scaleType !== oldProps.scaleType) {
95
+ switch (props.scaleType) {
96
+ case 'quantile': {
97
+ const {attribute} = this.getScalePercentile();
98
+ this.attribute = attribute;
99
+ this.domain = [0, 99];
100
+ break;
101
+ }
102
+ case 'ordinal': {
103
+ const {attribute, domain} = this.getScaleOrdinal();
104
+ this.attribute = attribute;
105
+ this.domain = [0, domain.length - 1];
106
+ break;
107
+ }
108
+
109
+ default:
110
+ this.attribute = this.input;
111
+ this.domain = null;
112
+ }
113
+ }
114
+ if (
115
+ props.scaleType !== oldProps.scaleType ||
116
+ props.lowerPercentile !== oldProps.lowerPercentile ||
117
+ props.upperPercentile !== oldProps.upperPercentile
118
+ ) {
119
+ this.cutoff = this.getCutoff(props);
120
+ }
121
+ this.props = props;
122
+ return this;
123
+ }
124
+ }
125
+
126
+ /**
127
+ * Transform an array of values to ordinal indices
128
+ */
129
+ export function applyScaleOrdinal(values: Float32Array): {
130
+ attribute: BinaryAttribute;
131
+ domain: number[];
132
+ } {
133
+ const uniqueValues = new Set<number>();
134
+ for (const x of values) {
135
+ if (Number.isFinite(x)) {
136
+ uniqueValues.add(x);
137
+ }
138
+ }
139
+ const sortedUniqueValues = Array.from(uniqueValues).sort();
140
+ const domainMap = new Map();
141
+ for (let i = 0; i < sortedUniqueValues.length; i++) {
142
+ domainMap.set(sortedUniqueValues[i], i);
143
+ }
144
+
145
+ return {
146
+ attribute: {
147
+ value: values.map(x => (Number.isFinite(x) ? domainMap.get(x) : NaN)),
148
+ type: 'float32',
149
+ size: 1
150
+ },
151
+ domain: sortedUniqueValues
152
+ };
153
+ }
154
+
155
+ /**
156
+ * Transform an array of values to percentiles
157
+ */
158
+ export function applyScaleQuantile(
159
+ values: Float32Array,
160
+ rangeLength = 100
161
+ ): {
162
+ attribute: BinaryAttribute;
163
+ domain: number[];
164
+ } {
165
+ const sortedValues = Array.from(values).filter(Number.isFinite).sort(ascending);
166
+ let i = 0;
167
+ const n = Math.max(1, rangeLength);
168
+ const thresholds: number[] = new Array(n - 1);
169
+ while (++i < n) {
170
+ thresholds[i - 1] = threshold(sortedValues, i / n);
171
+ }
172
+ return {
173
+ attribute: {
174
+ value: values.map(x => (Number.isFinite(x) ? bisectRight(thresholds, x) : NaN)),
175
+ type: 'float32',
176
+ size: 1
177
+ },
178
+ domain: thresholds
179
+ };
180
+ }
181
+
182
+ function getAttributeValue(attribute: BinaryAttribute, length: number): Float32Array {
183
+ const elementStride = (attribute.stride ?? 4) / 4;
184
+ const elementOffset = (attribute.offset ?? 0) / 4;
185
+ let value = attribute.value as Float32Array;
186
+ if (!value) {
187
+ const bytes = attribute.buffer?.readSyncWebGL(0, elementStride * 4 * length);
188
+ if (bytes) {
189
+ value = new Float32Array(bytes.buffer);
190
+ attribute.value = value;
191
+ }
192
+ }
193
+
194
+ if (elementStride === 1) {
195
+ return value.subarray(0, length);
196
+ }
197
+ const result = new Float32Array(length);
198
+ for (let i = 0; i < length; i++) {
199
+ result[i] = value[i * elementStride + elementOffset];
200
+ }
201
+ return result;
202
+ }
203
+
204
+ function ascending(a: number, b: number): number {
205
+ return a - b;
206
+ }
207
+
208
+ function threshold(domain: number[], fraction: number): number {
209
+ const domainLength = domain.length;
210
+ if (fraction <= 0 || domainLength < 2) {
211
+ return domain[0];
212
+ }
213
+ if (fraction >= 1) {
214
+ return domain[domainLength - 1];
215
+ }
216
+
217
+ const domainFraction = (domainLength - 1) * fraction;
218
+ const lowIndex = Math.floor(domainFraction);
219
+ const low = domain[lowIndex];
220
+ const high = domain[lowIndex + 1];
221
+ return low + (high - low) * (domainFraction - lowIndex);
222
+ }
223
+
224
+ function bisectRight(a: number[], x: number): number {
225
+ let lo = 0;
226
+ let hi = a.length;
227
+ while (lo < hi) {
228
+ const mid = (lo + hi) >>> 1;
229
+ if (a[mid] > x) {
230
+ hi = mid;
231
+ } else {
232
+ lo = mid + 1;
233
+ }
234
+ }
235
+ return lo;
236
+ }
@@ -0,0 +1,26 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {ShaderModule} from '@luma.gl/shadertools';
6
+
7
+ const uniformBlock = /* glsl */ `\
8
+ uniform binOptionsUniforms {
9
+ vec2 cellOriginCommon;
10
+ vec2 cellSizeCommon;
11
+ } binOptions;
12
+ `;
13
+
14
+ export type BinOptions = {
15
+ cellOriginCommon: [number, number];
16
+ cellSizeCommon: [number, number];
17
+ };
18
+
19
+ export const binOptionsUniforms = {
20
+ name: 'binOptions',
21
+ vs: uniformBlock,
22
+ uniformTypes: {
23
+ cellOriginCommon: 'vec2<f32>',
24
+ cellSizeCommon: 'vec2<f32>'
25
+ }
26
+ } as const satisfies ShaderModule<BinOptions>;