@math.gl/sql 0.0.0-stage → 5.0.0-beta.12

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 (353) hide show
  1. package/LICENSE +249 -0
  2. package/README.md +26 -2
  3. package/THIRD-PARTY-NOTICES.md +5 -0
  4. package/dist/arrow/aggregates.d.ts +46 -0
  5. package/dist/arrow/aggregates.d.ts.map +1 -0
  6. package/dist/arrow/aggregates.js +289 -0
  7. package/dist/arrow/aggregates.js.map +1 -0
  8. package/dist/arrow/buffers.d.ts +30 -0
  9. package/dist/arrow/buffers.d.ts.map +1 -0
  10. package/dist/arrow/buffers.js +177 -0
  11. package/dist/arrow/buffers.js.map +1 -0
  12. package/dist/arrow/cast.d.ts +19 -0
  13. package/dist/arrow/cast.d.ts.map +1 -0
  14. package/dist/arrow/cast.js +138 -0
  15. package/dist/arrow/cast.js.map +1 -0
  16. package/dist/arrow/compiler.d.ts +10 -0
  17. package/dist/arrow/compiler.d.ts.map +1 -0
  18. package/dist/arrow/compiler.js +1538 -0
  19. package/dist/arrow/compiler.js.map +1 -0
  20. package/dist/arrow/float16.d.ts +7 -0
  21. package/dist/arrow/float16.d.ts.map +1 -0
  22. package/dist/arrow/float16.js +26 -0
  23. package/dist/arrow/float16.js.map +1 -0
  24. package/dist/arrow/index.cjs +3321 -0
  25. package/dist/arrow/index.cjs.map +6 -0
  26. package/dist/arrow/index.d.ts +5 -0
  27. package/dist/arrow/index.d.ts.map +1 -0
  28. package/dist/arrow/index.js +7 -0
  29. package/dist/arrow/index.js.map +1 -0
  30. package/dist/arrow/like.d.ts +3 -0
  31. package/dist/arrow/like.d.ts.map +1 -0
  32. package/dist/arrow/like.js +75 -0
  33. package/dist/arrow/like.js.map +1 -0
  34. package/dist/arrow/list-values.d.ts +14 -0
  35. package/dist/arrow/list-values.d.ts.map +1 -0
  36. package/dist/arrow/list-values.js +201 -0
  37. package/dist/arrow/list-values.js.map +1 -0
  38. package/dist/arrow/predicate.d.ts +7 -0
  39. package/dist/arrow/predicate.d.ts.map +1 -0
  40. package/dist/arrow/predicate.js +10 -0
  41. package/dist/arrow/predicate.js.map +1 -0
  42. package/dist/arrow/query-arrow-aggregate-snapshots.d.ts +24 -0
  43. package/dist/arrow/query-arrow-aggregate-snapshots.d.ts.map +1 -0
  44. package/dist/arrow/query-arrow-aggregate-snapshots.js +64 -0
  45. package/dist/arrow/query-arrow-aggregate-snapshots.js.map +1 -0
  46. package/dist/arrow/query-arrow-sql.d.ts +8 -0
  47. package/dist/arrow/query-arrow-sql.d.ts.map +1 -0
  48. package/dist/arrow/query-arrow-sql.js +223 -0
  49. package/dist/arrow/query-arrow-sql.js.map +1 -0
  50. package/dist/arrow/query-arrow-table.d.ts +36 -0
  51. package/dist/arrow/query-arrow-table.d.ts.map +1 -0
  52. package/dist/arrow/query-arrow-table.js +208 -0
  53. package/dist/arrow/query-arrow-table.js.map +1 -0
  54. package/dist/arrow/query-worker-entry.d.ts +2 -0
  55. package/dist/arrow/query-worker-entry.d.ts.map +1 -0
  56. package/dist/arrow/query-worker-entry.js +7 -0
  57. package/dist/arrow/query-worker-entry.js.map +1 -0
  58. package/dist/arrow/query-worker.d.ts +65 -0
  59. package/dist/arrow/query-worker.d.ts.map +1 -0
  60. package/dist/arrow/query-worker.js +135 -0
  61. package/dist/arrow/query-worker.js.map +1 -0
  62. package/dist/arrow/registry.d.ts +4 -0
  63. package/dist/arrow/registry.d.ts.map +1 -0
  64. package/dist/arrow/registry.js +66 -0
  65. package/dist/arrow/registry.js.map +1 -0
  66. package/dist/arrow/relational-query.d.ts +36 -0
  67. package/dist/arrow/relational-query.d.ts.map +1 -0
  68. package/dist/arrow/relational-query.js +174 -0
  69. package/dist/arrow/relational-query.js.map +1 -0
  70. package/dist/arrow/replace-arrow-columns.d.ts +8 -0
  71. package/dist/arrow/replace-arrow-columns.d.ts.map +1 -0
  72. package/dist/arrow/replace-arrow-columns.js +63 -0
  73. package/dist/arrow/replace-arrow-columns.js.map +1 -0
  74. package/dist/arrow/signature.d.ts +6 -0
  75. package/dist/arrow/signature.d.ts.map +1 -0
  76. package/dist/arrow/signature.js +51 -0
  77. package/dist/arrow/signature.js.map +1 -0
  78. package/dist/arrow/temporal-cast.d.ts +9 -0
  79. package/dist/arrow/temporal-cast.d.ts.map +1 -0
  80. package/dist/arrow/temporal-cast.js +60 -0
  81. package/dist/arrow/temporal-cast.js.map +1 -0
  82. package/dist/arrow/types.d.ts +62 -0
  83. package/dist/arrow/types.d.ts.map +1 -0
  84. package/dist/arrow/types.js +5 -0
  85. package/dist/arrow/types.js.map +1 -0
  86. package/dist/arrow/unnest-arrow-column.d.ts +22 -0
  87. package/dist/arrow/unnest-arrow-column.d.ts.map +1 -0
  88. package/dist/arrow/unnest-arrow-column.js +112 -0
  89. package/dist/arrow/unnest-arrow-column.js.map +1 -0
  90. package/dist/arrow/worker-entry.d.ts +2 -0
  91. package/dist/arrow/worker-entry.d.ts.map +1 -0
  92. package/dist/arrow/worker-entry.js +9 -0
  93. package/dist/arrow/worker-entry.js.map +1 -0
  94. package/dist/arrow/worker.cjs +4074 -0
  95. package/dist/arrow/worker.cjs.map +6 -0
  96. package/dist/arrow/worker.d.ts +58 -0
  97. package/dist/arrow/worker.d.ts.map +1 -0
  98. package/dist/arrow/worker.js +84 -0
  99. package/dist/arrow/worker.js.map +1 -0
  100. package/dist/color-functions/index.cjs +382 -0
  101. package/dist/color-functions/index.cjs.map +6 -0
  102. package/dist/color-functions/index.d.ts +26 -0
  103. package/dist/color-functions/index.d.ts.map +1 -0
  104. package/dist/color-functions/index.js +306 -0
  105. package/dist/color-functions/index.js.map +1 -0
  106. package/dist/diagnostic-log.d.ts +8 -0
  107. package/dist/diagnostic-log.d.ts.map +1 -0
  108. package/dist/diagnostic-log.js +15 -0
  109. package/dist/diagnostic-log.js.map +1 -0
  110. package/dist/expressions/ast.d.ts +12 -0
  111. package/dist/expressions/ast.d.ts.map +1 -0
  112. package/dist/expressions/ast.js +114 -0
  113. package/dist/expressions/ast.js.map +1 -0
  114. package/dist/expressions/columnar-predicate.d.ts +56 -0
  115. package/dist/expressions/columnar-predicate.d.ts.map +1 -0
  116. package/dist/expressions/columnar-predicate.js +176 -0
  117. package/dist/expressions/columnar-predicate.js.map +1 -0
  118. package/dist/expressions/evaluation-error.d.ts +14 -0
  119. package/dist/expressions/evaluation-error.d.ts.map +1 -0
  120. package/dist/expressions/evaluation-error.js +26 -0
  121. package/dist/expressions/evaluation-error.js.map +1 -0
  122. package/dist/expressions/expression-eval.d.ts +105 -0
  123. package/dist/expressions/expression-eval.d.ts.map +1 -0
  124. package/dist/expressions/expression-eval.js +330 -0
  125. package/dist/expressions/expression-eval.js.map +1 -0
  126. package/dist/expressions/function-libraries.d.ts +63 -0
  127. package/dist/expressions/function-libraries.d.ts.map +1 -0
  128. package/dist/expressions/function-libraries.js +69 -0
  129. package/dist/expressions/function-libraries.js.map +1 -0
  130. package/dist/expressions/function-registry.d.ts +93 -0
  131. package/dist/expressions/function-registry.d.ts.map +1 -0
  132. package/dist/expressions/function-registry.js +139 -0
  133. package/dist/expressions/function-registry.js.map +1 -0
  134. package/dist/expressions/get.d.ts +9 -0
  135. package/dist/expressions/get.d.ts.map +1 -0
  136. package/dist/expressions/get.js +32 -0
  137. package/dist/expressions/get.js.map +1 -0
  138. package/dist/expressions/index.cjs +1888 -0
  139. package/dist/expressions/index.cjs.map +6 -0
  140. package/dist/expressions/index.d.ts +13 -0
  141. package/dist/expressions/index.d.ts.map +1 -0
  142. package/dist/expressions/index.js +14 -0
  143. package/dist/expressions/index.js.map +1 -0
  144. package/dist/expressions/numeric-functions.d.ts +277 -0
  145. package/dist/expressions/numeric-functions.d.ts.map +1 -0
  146. package/dist/expressions/numeric-functions.js +52 -0
  147. package/dist/expressions/numeric-functions.js.map +1 -0
  148. package/dist/expressions/parse-expression-string.d.ts +21 -0
  149. package/dist/expressions/parse-expression-string.d.ts.map +1 -0
  150. package/dist/expressions/parse-expression-string.js +61 -0
  151. package/dist/expressions/parse-expression-string.js.map +1 -0
  152. package/dist/expressions/predicate-expression.d.ts +7 -0
  153. package/dist/expressions/predicate-expression.d.ts.map +1 -0
  154. package/dist/expressions/predicate-expression.js +112 -0
  155. package/dist/expressions/predicate-expression.js.map +1 -0
  156. package/dist/expressions/scalar-type.d.ts +6 -0
  157. package/dist/expressions/scalar-type.d.ts.map +1 -0
  158. package/dist/expressions/scalar-type.js +23 -0
  159. package/dist/expressions/scalar-type.js.map +1 -0
  160. package/dist/expressions/vendor/jsep/runtime.d.ts +3 -0
  161. package/dist/expressions/vendor/jsep/runtime.d.ts.map +1 -0
  162. package/dist/expressions/vendor/jsep/runtime.js +972 -0
  163. package/dist/expressions/vendor/jsep/runtime.js.map +1 -0
  164. package/dist/expressions/vendor/jsep/types.d.ts +148 -0
  165. package/dist/expressions/vendor/jsep/types.d.ts.map +1 -0
  166. package/dist/expressions/vendor/jsep/types.js +6 -0
  167. package/dist/expressions/vendor/jsep/types.js.map +1 -0
  168. package/dist/index.cjs +5294 -0
  169. package/dist/index.cjs.map +6 -0
  170. package/dist/index.d.ts +11 -0
  171. package/dist/index.d.ts.map +1 -0
  172. package/dist/index.js +11 -0
  173. package/dist/index.js.map +1 -0
  174. package/dist/math-functions/index.cjs +444 -0
  175. package/dist/math-functions/index.cjs.map +6 -0
  176. package/dist/math-functions/index.d.ts +44 -0
  177. package/dist/math-functions/index.d.ts.map +1 -0
  178. package/dist/math-functions/index.js +182 -0
  179. package/dist/math-functions/index.js.map +1 -0
  180. package/dist/parser/bind-sql-predicate.d.ts +4 -0
  181. package/dist/parser/bind-sql-predicate.d.ts.map +1 -0
  182. package/dist/parser/bind-sql-predicate.js +11 -0
  183. package/dist/parser/bind-sql-predicate.js.map +1 -0
  184. package/dist/parser/index.cjs +1807 -0
  185. package/dist/parser/index.cjs.map +6 -0
  186. package/dist/parser/index.d.ts +12 -0
  187. package/dist/parser/index.d.ts.map +1 -0
  188. package/dist/parser/index.js +11 -0
  189. package/dist/parser/index.js.map +1 -0
  190. package/dist/parser/parameter-snapshots.d.ts +21 -0
  191. package/dist/parser/parameter-snapshots.d.ts.map +1 -0
  192. package/dist/parser/parameter-snapshots.js +85 -0
  193. package/dist/parser/parameter-snapshots.js.map +1 -0
  194. package/dist/parser/parse-sql-expression.d.ts +50 -0
  195. package/dist/parser/parse-sql-expression.d.ts.map +1 -0
  196. package/dist/parser/parse-sql-expression.js +501 -0
  197. package/dist/parser/parse-sql-expression.js.map +1 -0
  198. package/dist/parser/parse-sql-predicate.d.ts +13 -0
  199. package/dist/parser/parse-sql-predicate.d.ts.map +1 -0
  200. package/dist/parser/parse-sql-predicate.js +365 -0
  201. package/dist/parser/parse-sql-predicate.js.map +1 -0
  202. package/dist/parser/parse-sql-query.d.ts +9 -0
  203. package/dist/parser/parse-sql-query.d.ts.map +1 -0
  204. package/dist/parser/parse-sql-query.js +81 -0
  205. package/dist/parser/parse-sql-query.js.map +1 -0
  206. package/dist/parser/parse-sql-select.d.ts +57 -0
  207. package/dist/parser/parse-sql-select.d.ts.map +1 -0
  208. package/dist/parser/parse-sql-select.js +247 -0
  209. package/dist/parser/parse-sql-select.js.map +1 -0
  210. package/dist/parser/parse-sql-statement.d.ts +54 -0
  211. package/dist/parser/parse-sql-statement.d.ts.map +1 -0
  212. package/dist/parser/parse-sql-statement.js +207 -0
  213. package/dist/parser/parse-sql-statement.js.map +1 -0
  214. package/dist/parser/query-types.d.ts +56 -0
  215. package/dist/parser/query-types.d.ts.map +1 -0
  216. package/dist/parser/query-types.js +5 -0
  217. package/dist/parser/query-types.js.map +1 -0
  218. package/dist/parser/sql-parameters.d.ts +29 -0
  219. package/dist/parser/sql-parameters.d.ts.map +1 -0
  220. package/dist/parser/sql-parameters.js +110 -0
  221. package/dist/parser/sql-parameters.js.map +1 -0
  222. package/dist/parser/sql-parse-error.d.ts +13 -0
  223. package/dist/parser/sql-parse-error.d.ts.map +1 -0
  224. package/dist/parser/sql-parse-error.js +20 -0
  225. package/dist/parser/sql-parse-error.js.map +1 -0
  226. package/dist/parser/sql-predicate-schema.d.ts +164 -0
  227. package/dist/parser/sql-predicate-schema.d.ts.map +1 -0
  228. package/dist/parser/sql-predicate-schema.js +249 -0
  229. package/dist/parser/sql-predicate-schema.js.map +1 -0
  230. package/dist/parser/sql-predicate-types.d.ts +48 -0
  231. package/dist/parser/sql-predicate-types.d.ts.map +1 -0
  232. package/dist/parser/sql-predicate-types.js +9 -0
  233. package/dist/parser/sql-predicate-types.js.map +1 -0
  234. package/dist/parser/sql-predicate.d.ts +6 -0
  235. package/dist/parser/sql-predicate.d.ts.map +1 -0
  236. package/dist/parser/sql-predicate.js +8 -0
  237. package/dist/parser/sql-predicate.js.map +1 -0
  238. package/dist/scales/arrow-domains.d.ts +22 -0
  239. package/dist/scales/arrow-domains.d.ts.map +1 -0
  240. package/dist/scales/arrow-domains.js +166 -0
  241. package/dist/scales/arrow-domains.js.map +1 -0
  242. package/dist/scales/arrow-scales.d.ts +44 -0
  243. package/dist/scales/arrow-scales.d.ts.map +1 -0
  244. package/dist/scales/arrow-scales.js +255 -0
  245. package/dist/scales/arrow-scales.js.map +1 -0
  246. package/dist/scales/compile-scale.d.ts +2 -0
  247. package/dist/scales/compile-scale.d.ts.map +1 -0
  248. package/dist/scales/compile-scale.js +5 -0
  249. package/dist/scales/compile-scale.js.map +1 -0
  250. package/dist/scales/conformance.cjs +180 -0
  251. package/dist/scales/conformance.cjs.map +6 -0
  252. package/dist/scales/conformance.d.ts +26 -0
  253. package/dist/scales/conformance.d.ts.map +1 -0
  254. package/dist/scales/conformance.js +164 -0
  255. package/dist/scales/conformance.js.map +1 -0
  256. package/dist/scales/hdr-colors.d.ts +2 -0
  257. package/dist/scales/hdr-colors.d.ts.map +1 -0
  258. package/dist/scales/hdr-colors.js +5 -0
  259. package/dist/scales/hdr-colors.js.map +1 -0
  260. package/dist/scales/index.cjs +4334 -0
  261. package/dist/scales/index.cjs.map +6 -0
  262. package/dist/scales/index.d.ts +10 -0
  263. package/dist/scales/index.d.ts.map +1 -0
  264. package/dist/scales/index.js +11 -0
  265. package/dist/scales/index.js.map +1 -0
  266. package/dist/scales/palettes.d.ts +2 -0
  267. package/dist/scales/palettes.d.ts.map +1 -0
  268. package/dist/scales/palettes.js +5 -0
  269. package/dist/scales/palettes.js.map +1 -0
  270. package/dist/scales/parse-sql-scale.d.ts +27 -0
  271. package/dist/scales/parse-sql-scale.d.ts.map +1 -0
  272. package/dist/scales/parse-sql-scale.js +257 -0
  273. package/dist/scales/parse-sql-scale.js.map +1 -0
  274. package/dist/scales/quantile-sketch.d.ts +2 -0
  275. package/dist/scales/quantile-sketch.d.ts.map +1 -0
  276. package/dist/scales/quantile-sketch.js +5 -0
  277. package/dist/scales/quantile-sketch.js.map +1 -0
  278. package/dist/scales/scale-types.d.ts +2 -0
  279. package/dist/scales/scale-types.d.ts.map +1 -0
  280. package/dist/scales/scale-types.js +5 -0
  281. package/dist/scales/scale-types.js.map +1 -0
  282. package/dist/scales/streaming-domains.d.ts +18 -0
  283. package/dist/scales/streaming-domains.d.ts.map +1 -0
  284. package/dist/scales/streaming-domains.js +115 -0
  285. package/dist/scales/streaming-domains.js.map +1 -0
  286. package/package.json +92 -4
  287. package/src/arrow/aggregates.ts +386 -0
  288. package/src/arrow/buffers.ts +177 -0
  289. package/src/arrow/cast.ts +160 -0
  290. package/src/arrow/compiler.ts +1778 -0
  291. package/src/arrow/float16.ts +25 -0
  292. package/src/arrow/index.ts +22 -0
  293. package/src/arrow/like.ts +72 -0
  294. package/src/arrow/list-values.ts +221 -0
  295. package/src/arrow/predicate.ts +19 -0
  296. package/src/arrow/query-arrow-aggregate-snapshots.ts +107 -0
  297. package/src/arrow/query-arrow-sql.ts +255 -0
  298. package/src/arrow/query-arrow-table.ts +298 -0
  299. package/src/arrow/query-worker-entry.ts +8 -0
  300. package/src/arrow/query-worker.ts +194 -0
  301. package/src/arrow/registry.ts +87 -0
  302. package/src/arrow/relational-query.ts +247 -0
  303. package/src/arrow/replace-arrow-columns.ts +71 -0
  304. package/src/arrow/signature.ts +50 -0
  305. package/src/arrow/temporal-cast.ts +66 -0
  306. package/src/arrow/types.ts +76 -0
  307. package/src/arrow/unnest-arrow-column.ts +145 -0
  308. package/src/arrow/worker-entry.ts +10 -0
  309. package/src/arrow/worker.ts +143 -0
  310. package/src/color-functions/index.ts +405 -0
  311. package/src/diagnostic-log.ts +20 -0
  312. package/src/expressions/ast.ts +143 -0
  313. package/src/expressions/columnar-predicate.ts +293 -0
  314. package/src/expressions/evaluation-error.ts +29 -0
  315. package/src/expressions/expression-eval.ts +489 -0
  316. package/src/expressions/function-libraries.ts +126 -0
  317. package/src/expressions/function-registry.ts +171 -0
  318. package/src/expressions/get.ts +37 -0
  319. package/src/expressions/index.ts +40 -0
  320. package/src/expressions/numeric-functions.ts +99 -0
  321. package/src/expressions/parse-expression-string.ts +80 -0
  322. package/src/expressions/predicate-expression.ts +128 -0
  323. package/src/expressions/scalar-type.ts +39 -0
  324. package/src/expressions/vendor/jsep/LICENSE.txt +23 -0
  325. package/src/expressions/vendor/jsep/runtime.ts +949 -0
  326. package/src/expressions/vendor/jsep/types.ts +191 -0
  327. package/src/index.ts +54 -0
  328. package/src/math-functions/index.ts +235 -0
  329. package/src/parser/bind-sql-predicate.ts +21 -0
  330. package/src/parser/index.ts +43 -0
  331. package/src/parser/parameter-snapshots.ts +103 -0
  332. package/src/parser/parse-sql-expression.ts +500 -0
  333. package/src/parser/parse-sql-predicate.ts +454 -0
  334. package/src/parser/parse-sql-query.ts +90 -0
  335. package/src/parser/parse-sql-select.ts +272 -0
  336. package/src/parser/parse-sql-statement.ts +260 -0
  337. package/src/parser/query-types.ts +71 -0
  338. package/src/parser/sql-parameters.ts +174 -0
  339. package/src/parser/sql-parse-error.ts +33 -0
  340. package/src/parser/sql-predicate-schema.ts +279 -0
  341. package/src/parser/sql-predicate-types.ts +91 -0
  342. package/src/parser/sql-predicate.ts +28 -0
  343. package/src/scales/arrow-domains.ts +190 -0
  344. package/src/scales/arrow-scales.ts +363 -0
  345. package/src/scales/compile-scale.ts +5 -0
  346. package/src/scales/conformance.ts +186 -0
  347. package/src/scales/hdr-colors.ts +5 -0
  348. package/src/scales/index.ts +37 -0
  349. package/src/scales/palettes.ts +5 -0
  350. package/src/scales/parse-sql-scale.ts +300 -0
  351. package/src/scales/quantile-sketch.ts +5 -0
  352. package/src/scales/scale-types.ts +5 -0
  353. package/src/scales/streaming-domains.ts +139 -0
@@ -0,0 +1,186 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import type {ResolvedScaleDescriptor, ScaleColor, ScaleValue} from './scale-types';
6
+
7
+ /** One backend-independent sampling expectation, before storage-format quantization. */
8
+ export type ScaleConformanceSample = Readonly<{
9
+ /** Input value; null represents an invalid source row. */
10
+ input: ScaleValue | null;
11
+ /** Expected numeric value, color channels, or invalid output. */
12
+ expected: number | ScaleColor | null;
13
+ }>;
14
+
15
+ /** Serializable fixture for CPU, worker, and GPU scale implementations. */
16
+ export type ScaleConformanceCase = Readonly<{
17
+ /** Stable descriptive case identifier. */
18
+ id: string;
19
+ /** Resolved domain, range, class breaks, and color interpretation. */
20
+ descriptor: ResolvedScaleDescriptor;
21
+ /** Maximum absolute error per numeric component, including alpha. */
22
+ absoluteTolerance: number;
23
+ /** Independently specified expected values, not generated by the sampler under test. */
24
+ samples: readonly ScaleConformanceSample[];
25
+ }>;
26
+
27
+ /**
28
+ * Small portable conformance corpus. Import this optional entry only in tests;
29
+ * the runtime scales entry does not import these fixtures. Storage packing and
30
+ * approximate domain resolution need separate backend-specific tests.
31
+ */
32
+ export const SCALE_CONFORMANCE_CASES: readonly ScaleConformanceCase[] = [
33
+ {
34
+ id: 'linear-extrapolation',
35
+ descriptor: {type: 'linear', domain: [0, 10], range: {type: 'numeric', values: [0, 100]}},
36
+ absoluteTolerance: 0.00001,
37
+ samples: [
38
+ {input: null, expected: null},
39
+ {input: -1, expected: -10},
40
+ {input: 0, expected: 0},
41
+ {input: 5, expected: 50},
42
+ {input: 11, expected: 110}
43
+ ]
44
+ },
45
+ {
46
+ id: 'log-domain',
47
+ descriptor: {type: 'log', domain: [1, 100], range: {type: 'numeric', values: [0, 1]}},
48
+ absoluteTolerance: 0.00001,
49
+ samples: [
50
+ {input: 0, expected: null},
51
+ {input: 1, expected: 0},
52
+ {input: 10, expected: 0.5},
53
+ {input: 100, expected: 1}
54
+ ]
55
+ },
56
+ {
57
+ id: 'linear-srgb-interpolation',
58
+ descriptor: {
59
+ type: 'sequential',
60
+ domain: [0, 1],
61
+ interpolation: 'linear-srgb',
62
+ range: {
63
+ type: 'colors',
64
+ values: [
65
+ [0, 0, 0, 0],
66
+ [1, 1, 1, 1]
67
+ ]
68
+ }
69
+ },
70
+ absoluteTolerance: 0.00001,
71
+ samples: [
72
+ {input: -1, expected: [0, 0, 0, 0]},
73
+ {input: 0.5, expected: [0.7353569830524495, 0.7353569830524495, 0.7353569830524495, 0.5]},
74
+ {input: 2, expected: [1, 1, 1, 1]}
75
+ ]
76
+ },
77
+ {
78
+ id: 'null-under-over-colors',
79
+ descriptor: {
80
+ type: 'sequential',
81
+ domain: [0, 1],
82
+ range: {
83
+ type: 'colors',
84
+ values: [
85
+ [0, 0, 0, 1],
86
+ [1, 1, 1, 1]
87
+ ]
88
+ },
89
+ nullColor: [0, 0, 0, 0],
90
+ underColor: [1, 0, 0, 1],
91
+ overColor: [0, 0, 1, 1]
92
+ },
93
+ absoluteTolerance: 0.00001,
94
+ samples: [
95
+ {input: null, expected: [0, 0, 0, 0]},
96
+ {input: -1, expected: [1, 0, 0, 1]},
97
+ {input: 0, expected: [0, 0, 0, 1]},
98
+ {input: 1, expected: [1, 1, 1, 1]},
99
+ {input: 2, expected: [0, 0, 1, 1]}
100
+ ]
101
+ },
102
+ {
103
+ id: 'quantile-boundary-after-duplicate-removal',
104
+ descriptor: {
105
+ type: 'quantile',
106
+ domain: [0, 10],
107
+ thresholds: [5],
108
+ range: {
109
+ type: 'colors',
110
+ values: [
111
+ [0, 0, 0, 1],
112
+ [1, 1, 1, 1]
113
+ ]
114
+ }
115
+ },
116
+ absoluteTolerance: 0,
117
+ samples: [
118
+ {input: 4.999, expected: [0, 0, 0, 1]},
119
+ {input: 5, expected: [1, 1, 1, 1]},
120
+ {input: 10, expected: [1, 1, 1, 1]}
121
+ ]
122
+ },
123
+ {
124
+ id: 'linear-encoding-conversion',
125
+ descriptor: {
126
+ type: 'sequential',
127
+ domain: [0, 1],
128
+ interpolation: 'linear-srgb',
129
+ range: {
130
+ type: 'colors',
131
+ values: [
132
+ [0, 0, 0, 1],
133
+ [1, 1, 1, 1]
134
+ ]
135
+ },
136
+ encoding: {primaries: 'srgb', transfer: 'linear', format: 'rgba32float'}
137
+ },
138
+ absoluteTolerance: 0.00001,
139
+ samples: [{input: 0.5, expected: [0.5, 0.5, 0.5, 1]}]
140
+ },
141
+ {
142
+ id: 'ordinal-unknown-category',
143
+ descriptor: {
144
+ type: 'ordinal',
145
+ domain: ['first', 'second'],
146
+ range: {
147
+ type: 'colors',
148
+ values: [
149
+ [1, 0, 0, 1],
150
+ [0, 0, 1, 1]
151
+ ]
152
+ }
153
+ },
154
+ absoluteTolerance: 0,
155
+ samples: [
156
+ {input: 'first', expected: [1, 0, 0, 1]},
157
+ {input: 'second', expected: [0, 0, 1, 1]},
158
+ {input: 'unknown', expected: null}
159
+ ]
160
+ },
161
+ {
162
+ id: 'hdr-linear-extended-channels',
163
+ descriptor: {
164
+ type: 'sequential',
165
+ domain: [0, 1],
166
+ range: {
167
+ type: 'colors',
168
+ values: [
169
+ [0, 0, 0, 0],
170
+ [4, 2, -0.5, 1]
171
+ ]
172
+ },
173
+ encoding: {
174
+ primaries: 'rec2020',
175
+ transfer: 'linear',
176
+ format: 'rgba32float',
177
+ referenceWhiteNits: 203
178
+ }
179
+ },
180
+ absoluteTolerance: 0.00001,
181
+ samples: [
182
+ {input: 0.5, expected: [2, 1, -0.25, 0.5]},
183
+ {input: 1, expected: [4, 2, -0.5, 1]}
184
+ ]
185
+ }
186
+ ];
@@ -0,0 +1,5 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ export * from '@math.gl/core/color';
@@ -0,0 +1,37 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ export {
6
+ validateScaleSpec,
7
+ createResolvedScale
8
+ } from './scale-types';
9
+ export type {
10
+ ScaleColor,
11
+ ScaleValue,
12
+ ScaleDomain,
13
+ ScaleRange,
14
+ ScaleColorEncoding,
15
+ ScaleSpec,
16
+ ResolvedScaleDescriptor,
17
+ ResolvedScale
18
+ } from './scale-types';
19
+
20
+ export {parseSQLScaleExpression, parseSQLScaleAST} from './parse-sql-scale';
21
+ export type {ParsedSQLScale} from './parse-sql-scale';
22
+
23
+ export {compileResolvedScale} from './compile-scale';
24
+ export {resolvePalette, listScalePalettes} from './palettes';
25
+
26
+ export {ScaleQuantileSketch} from './quantile-sketch';
27
+
28
+ export {
29
+ convertScaleColor,
30
+ decodeSRGB,
31
+ encodeSRGB,
32
+ packFloat16,
33
+ unpackFloat16,
34
+ packRGBA16F
35
+ } from './hdr-colors';
36
+
37
+ export * from './arrow-scales';
@@ -0,0 +1,5 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ export * from '@math.gl/core/color';
@@ -0,0 +1,300 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import type {SQLParameterOptions} from '../parser/sql-parameters';
6
+ import type {Expression} from '../expressions';
7
+ import {parseSQLExpression} from '../parser/parse-sql-expression';
8
+ import {
9
+ validateScaleSpec,
10
+ type ScaleColor,
11
+ type ScaleDomain,
12
+ type ScaleRange,
13
+ type ScaleSpec
14
+ } from './scale-types';
15
+
16
+ /** SQL call shape with arguments produced by the SQL expression parser. */
17
+ type Call = {
18
+ type: 'CallExpression';
19
+ callee: {type: 'Identifier'; name: string};
20
+ arguments: Expression[];
21
+ };
22
+
23
+ /** A row expression and its validated, unresolved visualization scale. */
24
+ export type ParsedSQLScale = Readonly<{
25
+ /** Row-preserving value expression, evaluated by an Arrow/GPU backend. */
26
+ value: Expression;
27
+ /** Serializable specification, with unresolved domain dependencies. */
28
+ scale: ScaleSpec;
29
+ }>;
30
+
31
+ function call(node: Expression, expected?: string): Call {
32
+ const candidate = node as unknown as Call;
33
+ if (candidate.type !== 'CallExpression' || candidate.callee?.type !== 'Identifier') {
34
+ throw new Error(expected ? `${expected} expects a function call` : 'Expected a scale function');
35
+ }
36
+ if (expected && candidate.callee.name.toUpperCase() !== expected) {
37
+ throw new Error(`Expected ${expected}`);
38
+ }
39
+ return candidate;
40
+ }
41
+
42
+ function name(node: Expression): string {
43
+ const candidate = node as {type: string; name?: string};
44
+ if (candidate.type !== 'Identifier' || !candidate.name) {
45
+ throw new Error('Data-derived scale domain requires one column identifier');
46
+ }
47
+ return candidate.name;
48
+ }
49
+
50
+ /** Uses an existing column directly or records a computed numeric domain. */
51
+ function quantileDomain(value: Expression): ScaleDomain {
52
+ return value.type === 'Identifier'
53
+ ? {type: 'extent', column: name(value)}
54
+ : {type: 'expression-extent', expression: value};
55
+ }
56
+
57
+ function literal(node: Expression): string | number {
58
+ const value = node as {type: string; value?: unknown};
59
+ if (
60
+ value.type !== 'Literal' ||
61
+ (typeof value.value !== 'string' && typeof value.value !== 'number') ||
62
+ (typeof value.value === 'number' && !Number.isFinite(value.value))
63
+ ) {
64
+ throw new Error('Scale argument requires a literal number or quoted string');
65
+ }
66
+ return value.value;
67
+ }
68
+
69
+ function number(node: Expression): number {
70
+ // SQL negative numbers are sometimes represented as unary nodes.
71
+ const unary = node as {type: string; operator?: string; argument?: Expression};
72
+ if (
73
+ unary.type === 'UnaryExpression' &&
74
+ (unary.operator === '-' || unary.operator === '+') &&
75
+ unary.argument
76
+ ) {
77
+ const n = number(unary.argument);
78
+ return unary.operator === '-' ? -n : n;
79
+ }
80
+ const value = literal(node);
81
+ if (typeof value !== 'number') throw new Error('Expected numeric scale argument');
82
+ return value;
83
+ }
84
+
85
+ function color(hex: string): ScaleColor {
86
+ if (!/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(hex)) {
87
+ throw new Error('Explicit SQL color stops require #RRGGBB or #RRGGBBAA');
88
+ }
89
+ const bytes = hex.slice(1).match(/../g)!;
90
+ return [0, 1, 2, 3].map(
91
+ index => parseInt(bytes[index] ?? 'ff', 16) / 255
92
+ ) as unknown as ScaleColor;
93
+ }
94
+
95
+ function parseDomain(node: Expression): ScaleDomain {
96
+ const fn = call(node);
97
+ const functionName = fn.callee.name.toUpperCase();
98
+ const args = arrayArguments(fn.arguments);
99
+ switch (functionName) {
100
+ case 'DOMAIN':
101
+ if (args.length === 1 && args[0]!.type === 'Identifier')
102
+ return {type: 'extent', column: name(args[0]!)};
103
+ if (args.length >= 2) return {type: 'fixed', values: args.map(number)};
104
+ break;
105
+ case 'DOMAIN_ZERO':
106
+ if (args.length === 1) return {type: 'extent', column: name(args[0]!), includeZero: true};
107
+ break;
108
+ case 'DOMAIN_SYMMETRIC':
109
+ if (args.length === 2)
110
+ return {type: 'symmetric', column: name(args[0]!), pivot: number(args[1]!)};
111
+ break;
112
+ case 'DOMAIN_QUANTILE':
113
+ if (args.length === 3) {
114
+ return {
115
+ type: 'percentile',
116
+ column: name(args[0]!),
117
+ lower: number(args[1]!),
118
+ upper: number(args[2]!)
119
+ };
120
+ }
121
+ break;
122
+ }
123
+ throw new Error(`Invalid ${functionName} domain arguments`);
124
+ }
125
+
126
+ /** Parses an ordered list of unique fixed category keys. */
127
+ function parseCategories(node: Expression): ScaleDomain {
128
+ const values = arrayArguments(call(node, 'CATEGORIES').arguments).map(argument =>
129
+ argument.type === 'Literal' ? literal(argument) : number(argument)
130
+ );
131
+ if (!values.length || new Set(values).size !== values.length) {
132
+ throw new Error('CATEGORIES requires at least one category and no duplicates');
133
+ }
134
+ return {type: 'fixed', values};
135
+ }
136
+
137
+ /** Accepts a single bound list wherever a scale expects an explicit list of stops. */
138
+ function arrayArguments(args: Expression[]): Expression[] {
139
+ return args.length === 1 && args[0]!.type === 'ArrayExpression'
140
+ ? (args[0]!.elements as Expression[])
141
+ : args;
142
+ }
143
+
144
+ /** Converts explicit hex colors or normalized numeric RGB/RGBA tuples. */
145
+ function colorStop(node: Expression): ScaleColor {
146
+ if (node.type !== 'ArrayExpression') {
147
+ const value = literal(node);
148
+ if (typeof value !== 'string')
149
+ throw new Error('Palette colors require hex strings or RGB/RGBA tuples');
150
+ return color(value);
151
+ }
152
+ if (node.elements.length !== 3 && node.elements.length !== 4) {
153
+ throw new Error('Palette colors require RGB or RGBA tuples');
154
+ }
155
+ const components = (node.elements as Expression[]).map(number);
156
+ return [components[0]!, components[1]!, components[2]!, components[3] ?? 1];
157
+ }
158
+
159
+ function parseRange(node: Expression): ScaleRange {
160
+ const fn = call(node);
161
+ const args = arrayArguments(fn.arguments);
162
+ if (
163
+ fn.callee.name.toUpperCase() === 'PALETTE' &&
164
+ fn.arguments.length === 1 &&
165
+ fn.arguments[0]?.type === 'ArrayExpression'
166
+ ) {
167
+ return {type: 'colors', values: args.map(colorStop)};
168
+ }
169
+ switch (fn.callee.name.toUpperCase()) {
170
+ case 'RANGE':
171
+ if (args.length >= 2) return {type: 'numeric', values: args.map(number)};
172
+ break;
173
+ case 'PALETTE': {
174
+ if (args.length === 1) {
175
+ const stop = literal(args[0]!);
176
+ if (typeof stop === 'string' && stop.startsWith('#')) {
177
+ return {type: 'colors', values: [color(stop)]};
178
+ }
179
+ }
180
+ if (
181
+ args.length === 1 ||
182
+ (args.length === 2 &&
183
+ typeof literal(args[0]!) === 'string' &&
184
+ typeof literal(args[1]!) === 'number')
185
+ ) {
186
+ const paletteName = literal(args[0]!);
187
+ if (typeof paletteName !== 'string') throw new Error('Palette name must be a string');
188
+ const count = args.length === 2 ? number(args[1]!) : undefined;
189
+ return {type: 'palette', name: paletteName, ...(count === undefined ? {} : {count})};
190
+ }
191
+ if (args.length >= 2 && args.every(arg => typeof literal(arg) === 'string')) {
192
+ return {type: 'colors', values: args.map(arg => color(literal(arg) as string))};
193
+ }
194
+ break;
195
+ }
196
+ }
197
+ throw new Error('Expected RANGE(numbers...) or PALETTE(name[, count] | color stops...)');
198
+ }
199
+
200
+ /**
201
+ * Parse one scale expression into a row-value AST and a JSON-safe scale spec.
202
+ * This does not evaluate domain statistics, produce colors, or modify row count.
203
+ */
204
+ export function parseSQLScaleExpression(
205
+ sql: string,
206
+ options: SQLParameterOptions = {}
207
+ ): ParsedSQLScale {
208
+ return parseSQLScaleAST(parseSQLExpression(sql, options));
209
+ }
210
+
211
+ /**
212
+ * Extracts a scale from a parsed SQL expression without reparsing or evaluating it.
213
+ *
214
+ * Pass a scale call from `parseSQLExpression` or a SELECT projection. The returned
215
+ * value retains the input row-expression identity; this function does not mutate
216
+ * the AST, resolve domain statistics, or compile backend-specific code.
217
+ * @param expression - A scale call in the public portable expression AST.
218
+ * @returns The row-value expression and validated scale specification.
219
+ * @throws If the root is not a supported scale call or its scale arguments are invalid.
220
+ */
221
+ export function parseSQLScaleAST(expression: Expression): ParsedSQLScale {
222
+ const root = call(expression);
223
+ const fn = root.callee.name.toUpperCase();
224
+ const args = root.arguments;
225
+ const names: Record<string, ScaleSpec['type']> = {
226
+ SCALE_LINEAR: 'linear',
227
+ SCALE_SQRT: 'sqrt',
228
+ SCALE_LOG: 'log',
229
+ SCALE_COLOR: 'sequential',
230
+ SCALE_DIVERGING: 'diverging',
231
+ SCALE_ORDINAL: 'ordinal',
232
+ SCALE_QUANTILE: 'quantile',
233
+ SCALE_QUANTIZE: 'quantize',
234
+ SCALE_THRESHOLD: 'threshold'
235
+ };
236
+ const type = names[fn];
237
+ if (!type) throw new Error(`Unsupported SQL scale function: ${fn}`);
238
+ const inferredOrdinal = fn === 'SCALE_ORDINAL' && args.length === 2;
239
+ if (!inferredOrdinal && args.length !== 3) {
240
+ throw new Error(`${fn} expects ${fn === 'SCALE_ORDINAL' ? 'two or three' : 'three'} arguments`);
241
+ }
242
+ const value = args[0]!;
243
+ const domain = inferredOrdinal
244
+ ? {type: 'categories' as const, column: name(value)}
245
+ : fn === 'SCALE_ORDINAL'
246
+ ? parseCategories(args[1]!)
247
+ : fn === 'SCALE_QUANTILE'
248
+ ? quantileDomain(value)
249
+ : fn === 'SCALE_QUANTIZE'
250
+ ? {type: 'extent' as const, column: name(value)}
251
+ : fn === 'SCALE_THRESHOLD'
252
+ ? {type: 'fixed' as const, values: call(args[1]!, 'ARRAY').arguments.map(number)}
253
+ : parseDomain(args[1]!);
254
+ let range = parseRange(args[inferredOrdinal ? 1 : 2]!);
255
+ if (fn === 'SCALE_QUANTILE' || fn === 'SCALE_QUANTIZE') {
256
+ const count = number(args[1]!);
257
+ if (!Number.isSafeInteger(count) || count < 2) {
258
+ throw new Error(`${fn} class count must be an integer >= 2`);
259
+ }
260
+ if (range.type === 'palette') {
261
+ range = {...range, count};
262
+ } else if (fn !== 'SCALE_QUANTILE' || range.type !== 'colors') {
263
+ throw new Error(`${fn} requires a named palette`);
264
+ } else if (range.values.length !== count) {
265
+ throw new Error('SCALE_QUANTILE requires one color per class');
266
+ }
267
+ }
268
+ const colors = [
269
+ 'sequential',
270
+ 'diverging',
271
+ 'ordinal',
272
+ 'quantile',
273
+ 'quantize',
274
+ 'threshold'
275
+ ].includes(type);
276
+ if (colors && range.type === 'numeric') throw new Error(`${fn} requires a color range`);
277
+ if (!colors && range.type !== 'numeric') throw new Error(`${fn} requires a numeric RANGE`);
278
+ if (type === 'threshold' && domain.type === 'fixed') {
279
+ const breaks = domain.values as readonly number[];
280
+ if (!breaks.length || breaks.some((value, index) => index > 0 && value <= breaks[index - 1]!)) {
281
+ throw new Error('SCALE_THRESHOLD breaks must be nonempty and strictly increasing');
282
+ }
283
+ const count = breaks.length + 1;
284
+ if (range.type === 'palette' && range.count === undefined) range = {...range, count};
285
+ if (
286
+ (range.type === 'colors' && range.values.length !== count) ||
287
+ (range.type === 'palette' && range.count !== count)
288
+ ) {
289
+ throw new Error('SCALE_THRESHOLD requires one more color than breaks');
290
+ }
291
+ } else if (
292
+ domain.type === 'fixed' &&
293
+ range.type === 'colors' &&
294
+ domain.values.length !== range.values.length
295
+ ) {
296
+ throw new Error('Explicit domain and color stops must have equal lengths');
297
+ }
298
+ const scale = validateScaleSpec({type, domain, range});
299
+ return {value, scale};
300
+ }
@@ -0,0 +1,5 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ export * from '@math.gl/core/color';
@@ -0,0 +1,5 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ export * from '@math.gl/core/color';
@@ -0,0 +1,139 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import type {RecordBatch} from 'apache-arrow';
6
+ import type {ScaleDomain, ScaleValue} from './scale-types';
7
+ import {arrowScaleValue} from './arrow-domains';
8
+
9
+ import {ScaleQuantileSketch} from './quantile-sketch';
10
+
11
+ type ColumnState = {
12
+ min: number;
13
+ max: number;
14
+ seen: number;
15
+ categories?: Set<ScaleValue>;
16
+ sketch?: ScaleQuantileSketch;
17
+ };
18
+
19
+ export type StreamingDomainOptions = {
20
+ /** Maximum retained weighted samples per referenced percentile column. */
21
+ quantileCapacity?: number;
22
+ /** Also keep quantile sketches for these columns, e.g. SCALE_QUANTILE inputs. */
23
+ quantileColumns?: readonly string[];
24
+ };
25
+
26
+ /**
27
+ * Incremental domain accumulator. Each Arrow batch is visited once per
28
+ * referenced column, even when multiple visual scales depend on that column.
29
+ */
30
+ export function createStreamingDomainAccumulator(
31
+ domains: readonly ScaleDomain[],
32
+ options: StreamingDomainOptions = {}
33
+ ): {
34
+ update(batch: RecordBatch): void;
35
+ result(): readonly (readonly ScaleValue[])[];
36
+ quantileBreaks(column: string, classes: number): readonly number[];
37
+ } {
38
+ const columns = new Map<string, ColumnState>();
39
+ const quantileColumns = new Set(options.quantileColumns ?? []);
40
+ const streamingDomains = domains.map(domain => {
41
+ if (domain.type === 'expression-extent') {
42
+ throw new Error('Streaming scale domains require computed values in a projected column');
43
+ }
44
+ return domain;
45
+ });
46
+ for (const domain of streamingDomains) {
47
+ if (domain.type === 'fixed') continue;
48
+ const previous = columns.get(domain.column);
49
+ if (previous) {
50
+ if (
51
+ (domain.type === 'percentile' || quantileColumns.has(domain.column)) &&
52
+ !previous.sketch
53
+ ) {
54
+ previous.sketch = new ScaleQuantileSketch(options.quantileCapacity);
55
+ }
56
+ if (domain.type === 'categories') previous.categories ??= new Set();
57
+ continue;
58
+ }
59
+ columns.set(domain.column, {
60
+ min: Infinity,
61
+ max: -Infinity,
62
+ seen: 0,
63
+ ...(domain.type === 'categories' ? {categories: new Set<ScaleValue>()} : {}),
64
+ ...(domain.type === 'percentile' || quantileColumns.has(domain.column)
65
+ ? {sketch: new ScaleQuantileSketch(options.quantileCapacity)}
66
+ : {})
67
+ });
68
+ }
69
+
70
+ for (const name of quantileColumns) {
71
+ if (!columns.has(name))
72
+ columns.set(name, {
73
+ min: Infinity,
74
+ max: -Infinity,
75
+ seen: 0,
76
+ sketch: new ScaleQuantileSketch(options.quantileCapacity)
77
+ });
78
+ }
79
+
80
+ return {
81
+ update(batch) {
82
+ for (const [name, state] of columns) {
83
+ const vector = batch.getChild(name);
84
+ if (!vector) throw new Error(`Missing scale column: ${name}`);
85
+ for (let row = 0; row < vector.length; row++) {
86
+ const value = arrowScaleValue(vector.get(row));
87
+ if (value === null || value === undefined) continue;
88
+ if (typeof value === 'string') {
89
+ state.categories?.add(value);
90
+ } else if (typeof value === 'number' && Number.isFinite(value)) {
91
+ state.categories?.add(value);
92
+ state.seen++;
93
+ state.min = Math.min(state.min, value);
94
+ state.max = Math.max(state.max, value);
95
+ state.sketch?.add(value);
96
+ } else {
97
+ throw new Error(`Scale column ${name} has unsupported value at row ${row}`);
98
+ }
99
+ }
100
+ }
101
+ },
102
+ result() {
103
+ return streamingDomains.map(domain => {
104
+ if (domain.type === 'fixed') return [...domain.values];
105
+ const state = columns.get(domain.column)!;
106
+ if (domain.type === 'categories') {
107
+ const labels = [...state.categories!];
108
+ return domain.order === 'first-seen'
109
+ ? labels
110
+ : labels.sort((a, b) =>
111
+ typeof a === 'number' && typeof b === 'number' ? a - b : a < b ? -1 : a > b ? 1 : 0
112
+ );
113
+ }
114
+ if (!state.seen) return [];
115
+ if (domain.type === 'percentile') {
116
+ return [state.sketch!.quantile(domain.lower)!, state.sketch!.quantile(domain.upper)!];
117
+ }
118
+ if (domain.type === 'symmetric') {
119
+ const radius = Math.max(
120
+ Math.abs(state.min - domain.pivot),
121
+ Math.abs(state.max - domain.pivot)
122
+ );
123
+ return [domain.pivot - radius, domain.pivot + radius];
124
+ }
125
+ if (domain.includeZero) return [Math.min(state.min, 0), Math.max(state.max, 0)];
126
+ return [state.min, state.max];
127
+ });
128
+ },
129
+ quantileBreaks(column, classes) {
130
+ if (!Number.isSafeInteger(classes) || classes < 2) {
131
+ throw new Error('Scale class count must be at least two');
132
+ }
133
+ const sketch = columns.get(column)?.sketch;
134
+ if (!sketch) throw new Error(`Column ${column} has no quantile sketch`);
135
+ if (!sketch.length) return [];
136
+ return Array.from({length: classes - 1}, (_, i) => sketch.quantile((i + 1) / classes)!);
137
+ }
138
+ };
139
+ }