@genome-spy/core 0.67.0 → 0.69.0

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 (290) hide show
  1. package/dist/bundle/index.es.js +15884 -13130
  2. package/dist/bundle/index.js +130 -149
  3. package/dist/schema.json +6498 -6191
  4. package/dist/src/data/collector.d.ts +20 -0
  5. package/dist/src/data/collector.d.ts.map +1 -1
  6. package/dist/src/data/collector.js +148 -0
  7. package/dist/src/data/dataFlow.d.ts +6 -0
  8. package/dist/src/data/dataFlow.d.ts.map +1 -1
  9. package/dist/src/data/dataFlow.js +20 -0
  10. package/dist/src/data/flowInit.d.ts.map +1 -1
  11. package/dist/src/data/flowInit.js +2 -3
  12. package/dist/src/data/flowNode.d.ts +33 -10
  13. package/dist/src/data/flowNode.d.ts.map +1 -1
  14. package/dist/src/data/flowNode.js +84 -13
  15. package/dist/src/data/flowTestUtils.d.ts +2 -2
  16. package/dist/src/data/flowTestUtils.d.ts.map +1 -1
  17. package/dist/src/data/flowTestUtils.js +5 -4
  18. package/dist/src/data/keyIndex.d.ts +18 -0
  19. package/dist/src/data/keyIndex.d.ts.map +1 -0
  20. package/dist/src/data/keyIndex.js +241 -0
  21. package/dist/src/data/keyIndex.test.d.ts +2 -0
  22. package/dist/src/data/keyIndex.test.d.ts.map +1 -0
  23. package/dist/src/data/sources/dataSource.d.ts.map +1 -1
  24. package/dist/src/data/sources/dataSource.js +7 -3
  25. package/dist/src/data/sources/dataSourceFactory.d.ts +14 -12
  26. package/dist/src/data/sources/dataSourceFactory.d.ts.map +1 -1
  27. package/dist/src/data/sources/dataSourceFactory.js +52 -16
  28. package/dist/src/data/sources/lazy/bigBedSource.d.ts.map +1 -1
  29. package/dist/src/data/sources/lazy/bigBedSource.js +11 -10
  30. package/dist/src/data/sources/lazy/bigWigSource.d.ts.map +1 -1
  31. package/dist/src/data/sources/lazy/bigWigSource.js +11 -10
  32. package/dist/src/data/sources/lazy/mockLazySource.d.ts +29 -0
  33. package/dist/src/data/sources/lazy/mockLazySource.d.ts.map +1 -0
  34. package/dist/src/data/sources/lazy/mockLazySource.js +44 -0
  35. package/dist/src/data/sources/lazy/singleAxisLazySource.d.ts +22 -1
  36. package/dist/src/data/sources/lazy/singleAxisLazySource.d.ts.map +1 -1
  37. package/dist/src/data/sources/lazy/singleAxisLazySource.js +34 -2
  38. package/dist/src/data/sources/lazy/singleAxisWindowedSource.d.ts.map +1 -1
  39. package/dist/src/data/sources/lazy/singleAxisWindowedSource.js +16 -1
  40. package/dist/src/data/sources/lazy/tabixSource.d.ts +0 -1
  41. package/dist/src/data/sources/lazy/tabixSource.d.ts.map +1 -1
  42. package/dist/src/data/sources/lazy/tabixSource.js +56 -16
  43. package/dist/src/data/sources/sequenceSource.d.ts.map +1 -1
  44. package/dist/src/data/sources/sequenceSource.js +5 -3
  45. package/dist/src/data/sources/urlSource.d.ts.map +1 -1
  46. package/dist/src/data/sources/urlSource.js +7 -3
  47. package/dist/src/data/transforms/filter.d.ts +4 -4
  48. package/dist/src/data/transforms/filter.d.ts.map +1 -1
  49. package/dist/src/data/transforms/filter.js +13 -7
  50. package/dist/src/data/transforms/filterScoredLabels.d.ts.map +1 -1
  51. package/dist/src/data/transforms/filterScoredLabels.js +11 -6
  52. package/dist/src/data/transforms/filterScoredLabels.test.d.ts +2 -0
  53. package/dist/src/data/transforms/filterScoredLabels.test.d.ts.map +1 -0
  54. package/dist/src/data/transforms/formula.d.ts +4 -4
  55. package/dist/src/data/transforms/formula.d.ts.map +1 -1
  56. package/dist/src/data/transforms/formula.js +12 -6
  57. package/dist/src/data/transforms/measureText.d.ts +2 -2
  58. package/dist/src/data/transforms/measureText.d.ts.map +1 -1
  59. package/dist/src/data/transforms/measureText.js +16 -12
  60. package/dist/src/data/transforms/stack.d.ts.map +1 -1
  61. package/dist/src/data/transforms/stack.js +1 -0
  62. package/dist/src/data/transforms/transform.d.ts +2 -2
  63. package/dist/src/data/transforms/transform.d.ts.map +1 -1
  64. package/dist/src/data/transforms/transform.js +3 -3
  65. package/dist/src/encoder/accessor.d.ts +51 -4
  66. package/dist/src/encoder/accessor.d.ts.map +1 -1
  67. package/dist/src/encoder/accessor.js +174 -10
  68. package/dist/src/encoder/encoder.d.ts +11 -2
  69. package/dist/src/encoder/encoder.d.ts.map +1 -1
  70. package/dist/src/encoder/encoder.js +29 -9
  71. package/dist/src/encoder/metadataChannels.d.ts +15 -0
  72. package/dist/src/encoder/metadataChannels.d.ts.map +1 -0
  73. package/dist/src/encoder/metadataChannels.js +65 -0
  74. package/dist/src/encoder/metadataChannels.test.d.ts +2 -0
  75. package/dist/src/encoder/metadataChannels.test.d.ts.map +1 -0
  76. package/dist/src/genome/genome.d.ts +8 -0
  77. package/dist/src/genome/genome.d.ts.map +1 -1
  78. package/dist/src/genome/genome.js +16 -1
  79. package/dist/src/genome/scaleLocus.d.ts.map +1 -1
  80. package/dist/src/genome/scaleLocus.js +14 -1
  81. package/dist/src/genomeSpy/containerUi.d.ts +0 -1
  82. package/dist/src/genomeSpy/containerUi.d.ts.map +1 -1
  83. package/dist/src/genomeSpy/containerUi.js +0 -14
  84. package/dist/src/genomeSpy/inputBindingManager.js +1 -1
  85. package/dist/src/genomeSpy/interactionController.d.ts.map +1 -1
  86. package/dist/src/genomeSpy/interactionController.js +7 -1
  87. package/dist/src/genomeSpy/loadingIndicatorManager.d.ts +3 -7
  88. package/dist/src/genomeSpy/loadingIndicatorManager.d.ts.map +1 -1
  89. package/dist/src/genomeSpy/loadingIndicatorManager.js +68 -20
  90. package/dist/src/genomeSpy/loadingStatusRegistry.d.ts +52 -0
  91. package/dist/src/genomeSpy/loadingStatusRegistry.d.ts.map +1 -0
  92. package/dist/src/genomeSpy/loadingStatusRegistry.js +86 -0
  93. package/dist/src/genomeSpy/viewContextFactory.d.ts.map +1 -1
  94. package/dist/src/genomeSpy/viewContextFactory.js +0 -1
  95. package/dist/src/genomeSpy/viewDataInit.d.ts.map +1 -1
  96. package/dist/src/genomeSpy/viewDataInit.js +56 -11
  97. package/dist/src/genomeSpy.d.ts +0 -2
  98. package/dist/src/genomeSpy.d.ts.map +1 -1
  99. package/dist/src/genomeSpy.js +47 -27
  100. package/dist/src/gl/glslScaleGenerator.js +1 -1
  101. package/dist/src/marks/mark.d.ts.map +1 -1
  102. package/dist/src/marks/mark.js +40 -41
  103. package/dist/src/marks/markUtils.js +1 -1
  104. package/dist/src/marks/point.d.ts.map +1 -1
  105. package/dist/src/marks/point.js +4 -6
  106. package/dist/src/paramRuntime/expressionCompiler.d.ts +7 -0
  107. package/dist/src/paramRuntime/expressionCompiler.d.ts.map +1 -0
  108. package/dist/src/paramRuntime/expressionCompiler.js +10 -0
  109. package/dist/src/paramRuntime/expressionRef.d.ts +20 -0
  110. package/dist/src/paramRuntime/expressionRef.d.ts.map +1 -0
  111. package/dist/src/paramRuntime/expressionRef.js +95 -0
  112. package/dist/src/paramRuntime/expressionRef.test.d.ts +2 -0
  113. package/dist/src/paramRuntime/expressionRef.test.d.ts.map +1 -0
  114. package/dist/src/paramRuntime/graphRuntime.d.ts +176 -0
  115. package/dist/src/paramRuntime/graphRuntime.d.ts.map +1 -0
  116. package/dist/src/paramRuntime/graphRuntime.js +628 -0
  117. package/dist/src/paramRuntime/graphRuntime.test.d.ts +2 -0
  118. package/dist/src/paramRuntime/graphRuntime.test.d.ts.map +1 -0
  119. package/dist/src/paramRuntime/index.d.ts +9 -0
  120. package/dist/src/paramRuntime/index.d.ts.map +1 -0
  121. package/dist/src/paramRuntime/index.js +8 -0
  122. package/dist/src/paramRuntime/lifecycleRegistry.d.ts +27 -0
  123. package/dist/src/paramRuntime/lifecycleRegistry.d.ts.map +1 -0
  124. package/dist/src/paramRuntime/lifecycleRegistry.js +54 -0
  125. package/dist/src/paramRuntime/paramRuntime.d.ts +165 -0
  126. package/dist/src/paramRuntime/paramRuntime.d.ts.map +1 -0
  127. package/dist/src/paramRuntime/paramRuntime.js +222 -0
  128. package/dist/src/paramRuntime/paramRuntime.test.d.ts +2 -0
  129. package/dist/src/paramRuntime/paramRuntime.test.d.ts.map +1 -0
  130. package/dist/src/paramRuntime/paramStore.d.ts +68 -0
  131. package/dist/src/paramRuntime/paramStore.d.ts.map +1 -0
  132. package/dist/src/paramRuntime/paramStore.js +148 -0
  133. package/dist/src/paramRuntime/paramStore.test.d.ts +2 -0
  134. package/dist/src/paramRuntime/paramStore.test.d.ts.map +1 -0
  135. package/dist/src/paramRuntime/paramUtils.d.ts +86 -0
  136. package/dist/src/paramRuntime/paramUtils.d.ts.map +1 -0
  137. package/dist/src/paramRuntime/paramUtils.js +272 -0
  138. package/dist/src/paramRuntime/selectionStore.d.ts +6 -0
  139. package/dist/src/paramRuntime/selectionStore.d.ts.map +1 -0
  140. package/dist/src/paramRuntime/selectionStore.js +13 -0
  141. package/dist/src/paramRuntime/types.d.ts +16 -0
  142. package/dist/src/paramRuntime/types.d.ts.map +1 -0
  143. package/dist/src/paramRuntime/types.js +25 -0
  144. package/dist/src/paramRuntime/viewParamRuntime.d.ts +164 -0
  145. package/dist/src/paramRuntime/viewParamRuntime.d.ts.map +1 -0
  146. package/dist/src/paramRuntime/viewParamRuntime.js +443 -0
  147. package/dist/src/scale/scale.d.ts +6 -1
  148. package/dist/src/scale/scale.d.ts.map +1 -1
  149. package/dist/src/scale/scale.js +83 -23
  150. package/dist/src/scales/axisResolution.d.ts.map +1 -1
  151. package/dist/src/scales/axisResolution.js +10 -0
  152. package/dist/src/scales/{scaleDomainAggregator.d.ts → domainPlanner.d.ts} +6 -3
  153. package/dist/src/scales/domainPlanner.d.ts.map +1 -0
  154. package/dist/src/scales/{scaleDomainAggregator.js → domainPlanner.js} +128 -10
  155. package/dist/src/scales/domainPlanner.test.d.ts +2 -0
  156. package/dist/src/scales/domainPlanner.test.d.ts.map +1 -0
  157. package/dist/src/scales/scaleInstanceManager.d.ts +6 -3
  158. package/dist/src/scales/scaleInstanceManager.d.ts.map +1 -1
  159. package/dist/src/scales/scaleInstanceManager.js +17 -11
  160. package/dist/src/scales/scaleInteractionController.d.ts +6 -0
  161. package/dist/src/scales/scaleInteractionController.d.ts.map +1 -1
  162. package/dist/src/scales/scaleInteractionController.js +41 -3
  163. package/dist/src/scales/scaleResolution.d.ts +20 -17
  164. package/dist/src/scales/scaleResolution.d.ts.map +1 -1
  165. package/dist/src/scales/scaleResolution.js +188 -71
  166. package/dist/src/scales/scaleResolution.test.d.ts.map +1 -1
  167. package/dist/src/selection/selection.d.ts +21 -0
  168. package/dist/src/selection/selection.d.ts.map +1 -1
  169. package/dist/src/selection/selection.js +83 -1
  170. package/dist/src/spec/channel.d.ts +52 -15
  171. package/dist/src/spec/coreSchemaRoot.d.ts +53 -0
  172. package/dist/src/spec/data.d.ts +4 -0
  173. package/dist/src/spec/parameter.d.ts +16 -11
  174. package/dist/src/spec/root.d.ts +1 -1
  175. package/dist/src/spec/testing.d.ts +12 -0
  176. package/dist/src/spec/testing.d.ts.map +1 -0
  177. package/dist/src/spec/testing.js +20 -0
  178. package/dist/src/spec/view.d.ts +157 -41
  179. package/dist/src/styles/genome-spy.css +3 -31
  180. package/dist/src/styles/genome-spy.css.d.ts +1 -1
  181. package/dist/src/styles/genome-spy.css.d.ts.map +1 -1
  182. package/dist/src/styles/genome-spy.css.js +0 -29
  183. package/dist/src/tooltip/dataTooltipHandler.d.ts +1 -1
  184. package/dist/src/tooltip/dataTooltipHandler.js +23 -32
  185. package/dist/src/tooltip/dataTooltipHandler.test.d.ts +2 -0
  186. package/dist/src/tooltip/dataTooltipHandler.test.d.ts.map +1 -0
  187. package/dist/src/tooltip/flattenDatumRows.d.ts +13 -0
  188. package/dist/src/tooltip/flattenDatumRows.d.ts.map +1 -0
  189. package/dist/src/tooltip/flattenDatumRows.js +47 -0
  190. package/dist/src/tooltip/flattenDatumRows.test.d.ts +2 -0
  191. package/dist/src/tooltip/flattenDatumRows.test.d.ts.map +1 -0
  192. package/dist/src/tooltip/refseqGeneTooltipHandler.d.ts +1 -1
  193. package/dist/src/tooltip/refseqGeneTooltipHandler.js +7 -1
  194. package/dist/src/tooltip/tooltipContext.d.ts +13 -0
  195. package/dist/src/tooltip/tooltipContext.d.ts.map +1 -0
  196. package/dist/src/tooltip/tooltipContext.js +543 -0
  197. package/dist/src/tooltip/tooltipContext.test.d.ts +2 -0
  198. package/dist/src/tooltip/tooltipContext.test.d.ts.map +1 -0
  199. package/dist/src/tooltip/tooltipHandler.d.ts +40 -1
  200. package/dist/src/tooltip/tooltipHandler.d.ts.map +1 -1
  201. package/dist/src/tooltip/tooltipHandler.ts +62 -1
  202. package/dist/src/types/encoder.d.ts +38 -3
  203. package/dist/src/types/rendering.d.ts +4 -3
  204. package/dist/src/types/viewContext.d.ts +0 -14
  205. package/dist/src/utils/inputBinding.d.ts +10 -2
  206. package/dist/src/utils/inputBinding.d.ts.map +1 -1
  207. package/dist/src/utils/inputBinding.js +12 -3
  208. package/dist/src/utils/throttle.d.ts +4 -1
  209. package/dist/src/utils/throttle.d.ts.map +1 -1
  210. package/dist/src/utils/throttle.js +54 -23
  211. package/dist/src/utils/throttle.test.d.ts +2 -0
  212. package/dist/src/utils/throttle.test.d.ts.map +1 -0
  213. package/dist/src/utils/transition.d.ts +21 -0
  214. package/dist/src/utils/transition.d.ts.map +1 -1
  215. package/dist/src/utils/transition.js +28 -0
  216. package/dist/src/utils/ui/tooltip.d.ts.map +1 -1
  217. package/dist/src/utils/ui/tooltip.js +7 -1
  218. package/dist/src/utils/ui/tooltip.test.d.ts +2 -0
  219. package/dist/src/utils/ui/tooltip.test.d.ts.map +1 -0
  220. package/dist/src/view/axisGridView.d.ts.map +1 -1
  221. package/dist/src/view/axisGridView.js +22 -5
  222. package/dist/src/view/axisView.d.ts.map +1 -1
  223. package/dist/src/view/axisView.js +20 -5
  224. package/dist/src/view/concatView.js +3 -3
  225. package/dist/src/view/containerMutationHelper.js +1 -1
  226. package/dist/src/view/containerView.d.ts +9 -5
  227. package/dist/src/view/containerView.d.ts.map +1 -1
  228. package/dist/src/view/containerView.js +34 -9
  229. package/dist/src/view/dataReadiness.d.ts +46 -0
  230. package/dist/src/view/dataReadiness.d.ts.map +1 -0
  231. package/dist/src/view/dataReadiness.js +267 -0
  232. package/dist/src/view/dataReadiness.test.d.ts +2 -0
  233. package/dist/src/view/dataReadiness.test.d.ts.map +1 -0
  234. package/dist/src/view/facetView.d.ts.map +1 -1
  235. package/dist/src/view/facetView.js +7 -5
  236. package/dist/src/view/flowBuilder.d.ts.map +1 -1
  237. package/dist/src/view/flowBuilder.js +17 -4
  238. package/dist/src/view/gridView/gridChild.d.ts.map +1 -1
  239. package/dist/src/view/gridView/gridChild.js +16 -3
  240. package/dist/src/view/gridView/gridView.d.ts.map +1 -1
  241. package/dist/src/view/gridView/gridView.js +119 -2
  242. package/dist/src/view/gridView/scrollbar.d.ts.map +1 -1
  243. package/dist/src/view/gridView/scrollbar.js +3 -0
  244. package/dist/src/view/gridView/selectionRect.d.ts +6 -10
  245. package/dist/src/view/gridView/selectionRect.d.ts.map +1 -1
  246. package/dist/src/view/gridView/selectionRect.js +22 -24
  247. package/dist/src/view/gridView/separatorView.d.ts +51 -0
  248. package/dist/src/view/gridView/separatorView.d.ts.map +1 -0
  249. package/dist/src/view/gridView/separatorView.js +275 -0
  250. package/dist/src/view/layerView.d.ts.map +1 -1
  251. package/dist/src/view/layerView.js +7 -5
  252. package/dist/src/view/layout/flexLayout.d.ts +0 -30
  253. package/dist/src/view/layout/flexLayout.d.ts.map +1 -1
  254. package/dist/src/view/layout/flexLayout.js +0 -86
  255. package/dist/src/view/multiscale.d.ts +35 -0
  256. package/dist/src/view/multiscale.d.ts.map +1 -0
  257. package/dist/src/view/multiscale.js +233 -0
  258. package/dist/src/view/multiscale.test.d.ts +2 -0
  259. package/dist/src/view/multiscale.test.d.ts.map +1 -0
  260. package/dist/src/view/testUtils.d.ts.map +1 -1
  261. package/dist/src/view/testUtils.js +6 -1
  262. package/dist/src/view/unitView.d.ts +8 -13
  263. package/dist/src/view/unitView.d.ts.map +1 -1
  264. package/dist/src/view/unitView.js +120 -45
  265. package/dist/src/view/view.d.ts +27 -18
  266. package/dist/src/view/view.d.ts.map +1 -1
  267. package/dist/src/view/view.js +298 -37
  268. package/dist/src/view/viewFactory.d.ts +0 -12
  269. package/dist/src/view/viewFactory.d.ts.map +1 -1
  270. package/dist/src/view/viewFactory.js +55 -25
  271. package/dist/src/view/viewParamRuntime.test.d.ts +2 -0
  272. package/dist/src/view/viewParamRuntime.test.d.ts.map +1 -0
  273. package/dist/src/view/viewSelectors.d.ts +148 -0
  274. package/dist/src/view/viewSelectors.d.ts.map +1 -0
  275. package/dist/src/view/viewSelectors.js +776 -0
  276. package/dist/src/view/viewSelectors.test.d.ts +2 -0
  277. package/dist/src/view/viewSelectors.test.d.ts.map +1 -0
  278. package/dist/src/view/viewUtils.d.ts +0 -8
  279. package/dist/src/view/viewUtils.d.ts.map +1 -1
  280. package/dist/src/view/viewUtils.js +1 -21
  281. package/package.json +4 -4
  282. package/dist/src/scales/scaleDomainAggregator.d.ts.map +0 -1
  283. package/dist/src/scales/scaleDomainAggregator.test.d.ts +0 -2
  284. package/dist/src/scales/scaleDomainAggregator.test.d.ts.map +0 -1
  285. package/dist/src/spec/sampleView.d.ts +0 -197
  286. package/dist/src/view/paramMediator.d.ts +0 -149
  287. package/dist/src/view/paramMediator.d.ts.map +0 -1
  288. package/dist/src/view/paramMediator.js +0 -478
  289. package/dist/src/view/paramMediator.test.d.ts +0 -2
  290. package/dist/src/view/paramMediator.test.d.ts.map +0 -1
@@ -1,478 +0,0 @@
1
- import { isString } from "vega-util";
2
- import createFunction from "../utils/expression.js";
3
- import {
4
- asSelectionConfig,
5
- createIntervalSelection,
6
- createMultiPointSelection,
7
- createSinglePointSelection,
8
- isIntervalSelectionConfig,
9
- isPointSelectionConfig,
10
- } from "../selection/selection.js";
11
-
12
- /**
13
- * A class that manages parameters and expressions.
14
- * Supports nesting and scoped parameters.
15
- *
16
- * TODO: The proposed JavaScript signals may provide a better way to implement this.
17
- * https://github.com/proposal-signals/proposal-signals
18
- *
19
- * @typedef {import("../utils/expression.js").ExpressionFunction & { addListener: (listener: () => void) => void, removeListener: (listener: () => void) => void, invalidate: () => void, identifier: () => string}} ExprRefFunction
20
- */
21
- export default class ParamMediator {
22
- /**
23
- * @typedef {import("../spec/parameter.js").Parameter} Parameter
24
- * @typedef {(value: any) => void} ParameterSetter
25
- */
26
-
27
- /** @type {Map<string, any>} */
28
- #paramValues;
29
-
30
- /**
31
- * @type {Map<string, Set<() => void>>}
32
- * @protected
33
- */
34
- paramListeners;
35
-
36
- /** @type {Map<string, (value: any) => void>} */
37
- #allocatedSetters = new Map();
38
-
39
- /** @type {Map<string, ExprRefFunction>} */
40
- #expressions = new Map();
41
-
42
- /** @type {Map<string, Parameter>} */
43
- #paramConfigs = new Map();
44
-
45
- /** @type {() => ParamMediator} */
46
- #parentFinder;
47
-
48
- /**
49
- * @param {() => ParamMediator} [parentFinder]
50
- * An optional function that returns the parent mediator.
51
- * N.B. The function must always return the same mediator for the same parent,
52
- * i.e., the changing the structure of the hierarchy is NOT supported.
53
- */
54
- constructor(parentFinder) {
55
- this.#parentFinder = parentFinder ?? (() => undefined);
56
-
57
- this.#paramValues = new Map();
58
- this.paramListeners = new Map();
59
- }
60
-
61
- /**
62
- * @param {Parameter} param
63
- * @returns {ParameterSetter}
64
- */
65
- registerParam(param) {
66
- const name = param.name;
67
-
68
- if ("value" in param && "expr" in param) {
69
- throw new Error(
70
- `The parameter "${name}" must not have both value and expr properties!`
71
- );
72
- }
73
-
74
- /** @type {ParameterSetter} */
75
- let setter;
76
-
77
- if (param.push == "outer") {
78
- const outerMediator = this.findMediatorForParam(name);
79
- if (!outerMediator) {
80
- throw new Error(
81
- `Parameter "${name}" not found in outer scope!`
82
- );
83
- }
84
-
85
- const outerProps = outerMediator.paramConfigs.get(name);
86
- if ("expr" in outerProps || "select" in outerProps) {
87
- throw new Error(
88
- `The outer parameter "${name}" must not have expr or select properties!`
89
- );
90
- }
91
- setter = outerMediator.getSetter(name);
92
- // The following will become a bit fragile if the view hierarchy is going to
93
- // support mutation (i.e. adding/removing children) in future.
94
- this.#allocatedSetters.set(name, setter);
95
- } else if ("value" in param) {
96
- setter = this.allocateSetter(name, param.value);
97
- } else if ("expr" in param) {
98
- const expr = this.createExpression(param.expr);
99
- // TODO: getSetter(param) should return a setter that throws if
100
- // modifying the value is attempted.
101
- const realSetter = this.allocateSetter(name, expr(null));
102
- expr.addListener(() => realSetter(expr(null)));
103
- // NOP
104
- setter = (_) => undefined;
105
- } else {
106
- setter = this.allocateSetter(name, null);
107
- }
108
-
109
- if ("select" in param) {
110
- const select = asSelectionConfig(param.select);
111
- if (isPointSelectionConfig(select)) {
112
- // Set initial value so that production rules in shaders can be generated, etc.
113
- setter(
114
- select.toggle
115
- ? createMultiPointSelection()
116
- : createSinglePointSelection(null)
117
- );
118
- } else if (isIntervalSelectionConfig(select)) {
119
- if (!select.encodings) {
120
- throw new Error(
121
- `Interval selection "${name}" must have encodings defined!`
122
- );
123
- }
124
- setter(createIntervalSelection(select.encodings));
125
- }
126
- }
127
-
128
- this.#paramConfigs.set(name, param);
129
-
130
- return setter;
131
- }
132
-
133
- /**
134
- *
135
- * @param {string} paramName
136
- * @param {T} initialValue
137
- * @param {boolean} [passive] If true, the setter will not notify listeners when the value changes.
138
- * @returns {(value: T) => void}
139
- * @template T
140
- */
141
- allocateSetter(paramName, initialValue, passive = false) {
142
- validateParameterName(paramName);
143
-
144
- if (this.#allocatedSetters.has(paramName)) {
145
- throw new Error(
146
- "Setter already allocated for parameter: " + paramName
147
- );
148
- }
149
-
150
- /** @type {(value: any) => void} */
151
- const setter = (value) => {
152
- const previous = this.#paramValues.get(paramName);
153
- if (value !== previous) {
154
- this.#paramValues.set(paramName, value);
155
-
156
- const listeners = this.paramListeners.get(paramName);
157
- if (listeners && !passive) {
158
- for (const listener of listeners) {
159
- listener();
160
- }
161
- }
162
- }
163
- };
164
-
165
- setter(initialValue);
166
-
167
- this.#allocatedSetters.set(paramName, setter);
168
-
169
- return setter;
170
- }
171
-
172
- /**
173
- * Gets an existing setter for a parameter. Throws if the setter is not found.
174
- * @param {string} paramName
175
- */
176
- getSetter(paramName) {
177
- const setter = this.#allocatedSetters.get(paramName);
178
- if (!setter) {
179
- throw new Error("Setter not found for parameter: " + paramName);
180
- }
181
- return setter;
182
- }
183
-
184
- /**
185
- * Get the value of a parameter from this mediator.
186
- * @param {string} paramName
187
- */
188
- getValue(paramName) {
189
- return this.#paramValues.get(paramName);
190
- }
191
-
192
- /**
193
- * Get the value of a parameter from this mediator or the ancestors.
194
- * @param {string} paramName
195
- */
196
- findValue(paramName) {
197
- const mediator = this.findMediatorForParam(paramName);
198
- return mediator?.getValue(paramName);
199
- }
200
-
201
- /**
202
- * Returns configs for all parameters that have been registered using `registerParam`.
203
- */
204
- get paramConfigs() {
205
- return /** @type {ReadonlyMap<string, Parameter>} */ (
206
- this.#paramConfigs
207
- );
208
- }
209
-
210
- /**
211
- *
212
- * @param {string} paramName
213
- * @returns {ParamMediator}
214
- */
215
- findMediatorForParam(paramName) {
216
- if (this.#paramValues.has(paramName)) {
217
- return this;
218
- } else {
219
- return this.#parentFinder()?.findMediatorForParam(paramName);
220
- }
221
- }
222
-
223
- // TODO: deallocateSetter
224
-
225
- /**
226
- * Parse expr and return a function that returns the value of the parameter.
227
- *
228
- * @param {string} expr
229
- */
230
- createExpression(expr) {
231
- if (this.#expressions.has(expr)) {
232
- return this.#expressions.get(expr);
233
- }
234
-
235
- const globalObject = {};
236
-
237
- /** @type {ExprRefFunction} */
238
- const fn = /** @type {any} */ (createFunction(expr, globalObject));
239
-
240
- /** @type {Map<string, ParamMediator>} */
241
- const mediatorsForParams = new Map();
242
-
243
- for (const param of fn.globals) {
244
- const mediator = this.findMediatorForParam(param);
245
- if (!mediator) {
246
- throw new Error(
247
- `Unknown variable "${param}" in expression: ${expr}`
248
- );
249
- }
250
-
251
- mediatorsForParams.set(param, mediator);
252
-
253
- Object.defineProperty(globalObject, param, {
254
- enumerable: true,
255
- get() {
256
- return mediator.getValue(param);
257
- },
258
- });
259
- }
260
- // TODO: There should be a way to "materialize" the global object when
261
- // it is used in expressions in transformation batches, i.e., when the same
262
- // expression is applied to multiple data objects. In that case, the global
263
- // object remains constant and the Map lookups cause unnecessary overhead.
264
-
265
- // Keep track of them so that they can be detached later
266
- const myListeners = new Set();
267
-
268
- /**
269
- *
270
- * @param {() => void} listener
271
- */
272
- fn.addListener = (listener) => {
273
- for (const [param, mediator] of mediatorsForParams) {
274
- const listeners =
275
- mediator.paramListeners.get(param) ?? new Set();
276
- mediator.paramListeners.set(param, listeners);
277
-
278
- listeners.add(listener);
279
- myListeners.add(listener);
280
- }
281
- };
282
-
283
- /**
284
- * @param {() => void} listener
285
- */
286
- fn.removeListener = (listener) => {
287
- for (const [param, mediator] of mediatorsForParams) {
288
- mediator.paramListeners.get(param)?.delete(listener);
289
- }
290
- myListeners.delete(listener);
291
- };
292
-
293
- /**
294
- * Detach listeners. This must be called if the expression is no longer used.
295
- * TODO: What if the expression is used in multiple places?
296
- */
297
- fn.invalidate = () => {
298
- for (const [param, mediator] of mediatorsForParams) {
299
- for (const listener of myListeners) {
300
- mediator.paramListeners.get(param)?.delete(listener);
301
- }
302
- }
303
- myListeners.clear();
304
- };
305
-
306
- // TODO: This should contain unique identifier for each parameter.
307
- // As the same parameter name may be used in different branches of the
308
- // hierarchy, they should be distinguished by a unique identifier, e.g.,
309
- // a serial number of something similar.
310
- fn.identifier = () => fn.code;
311
-
312
- this.#expressions.set(expr, fn);
313
-
314
- return fn;
315
- }
316
-
317
- /**
318
- * A convenience method for evaluating an expression.
319
- *
320
- * @param {string} expr
321
- */
322
- evaluateAndGet(expr) {
323
- const fn = this.createExpression(expr);
324
- return fn();
325
- }
326
-
327
- /**
328
- * Returns true if this ParamMediator has any parameters that are point selections.
329
- * Point selections necessitate the use of uniqueIds in the data.
330
- *
331
- * @returns {boolean}
332
- */
333
- hasPointSelections() {
334
- for (const param of this.#paramConfigs.values()) {
335
- if (isSelectionParameter(param)) {
336
- const select = param.select;
337
- if (isString(select)) {
338
- if (select == "point") {
339
- return true;
340
- }
341
- } else if (select.type == "point") {
342
- return true;
343
- }
344
- }
345
- }
346
-
347
- return false;
348
- }
349
- }
350
-
351
- /**
352
- * @param {any} x
353
- * @returns {x is import("../spec/parameter.js").ExprRef}
354
- */
355
- export function isExprRef(x) {
356
- return typeof x == "object" && x != null && "expr" in x && isString(x.expr);
357
- }
358
-
359
- /**
360
- * Removes ExprRef from the type and checks that the value is not an ExprRef.
361
- * This is designed to be used with `activateExprRefProps`.
362
- *
363
- * @param {T | import("../spec/parameter.js").ExprRef} x
364
- * @template T
365
- * @returns {T}
366
- */
367
- export function withoutExprRef(x) {
368
- if (isExprRef(x)) {
369
- throw new Error(
370
- `ExprRef ${JSON.stringify(
371
- x
372
- )} not allowed here. Expected a scalar value.`
373
- );
374
- }
375
- return /** @type {T} */ (x);
376
- }
377
-
378
- /**
379
- * @param {Parameter} param
380
- * @returns {param is import("../spec/parameter.js").VariableParameter}
381
- */
382
- export function isVariableParameter(param) {
383
- return ("expr" in param || "bind" in param) && !("select" in param);
384
- }
385
-
386
- /**
387
- * @param {Parameter} param
388
- * @returns {param is import("../spec/parameter.js").SelectionParameter}
389
- */
390
- export function isSelectionParameter(param) {
391
- return !("expr" in param || "bind" in param) && "select" in param;
392
- }
393
-
394
- /**
395
- * Takes a record of properties that may have ExprRefs as values. Converts the
396
- * ExprRefs to getters and setups a listener that is called when any of the
397
- * expressions (upstream parameters) change.
398
- *
399
- * @param {ParamMediator} paramMediator
400
- * @param {T} props The properties object
401
- * @param {(props: (keyof T)[]) => void} [listener] Listener to be called when any of the expressions change
402
- * @returns T
403
- * @template {Record<string, any | import("../spec/parameter.js").ExprRef>} T
404
- */
405
- export function activateExprRefProps(paramMediator, props, listener) {
406
- /** @type {Record<string, any | import("../spec/parameter.js").ExprRef>} */
407
- const activatedProps = { ...props };
408
-
409
- /** @type {(keyof T)[]} */
410
- const alteredProps = [];
411
-
412
- const batchPropertyChange = (/** @type {keyof T} */ prop) => {
413
- alteredProps.push(prop);
414
- if (alteredProps.length === 1) {
415
- queueMicrotask(() => {
416
- listener(alteredProps.slice());
417
- alteredProps.length = 0;
418
- });
419
- }
420
- };
421
-
422
- for (const [key, value] of Object.entries(props)) {
423
- if (isExprRef(value)) {
424
- const fn = paramMediator.createExpression(value.expr);
425
- if (listener) {
426
- fn.addListener(() => batchPropertyChange(key));
427
- }
428
-
429
- Object.defineProperty(activatedProps, key, {
430
- enumerable: true,
431
- get() {
432
- return fn();
433
- },
434
- });
435
- } else {
436
- activatedProps[key] = value;
437
- }
438
- }
439
-
440
- return /** @type {T} */ (activatedProps);
441
- }
442
-
443
- /**
444
- * Validates a parameter name. If the name is invalid, throws an error.
445
- * Otherwise, returns the name.
446
- *
447
- * @param {string} name
448
- * @returns {string} the name
449
- */
450
- export function validateParameterName(name) {
451
- if (!/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(name)) {
452
- throw new Error(
453
- `Invalid parameter name: ${name}. Must be a valid JavaScript identifier.`
454
- );
455
- }
456
-
457
- return name;
458
- }
459
-
460
- /**
461
- * Creates a function that always returns the same value.
462
- * Provides functionality for creating a constant expression reference.
463
- * They just do nothing.
464
- *
465
- * @param {any} value
466
- * @returns {ExprRefFunction}
467
- */
468
- export function makeConstantExprRef(value) {
469
- return Object.assign(() => value, {
470
- addListener: () => /** @type {void} */ (undefined),
471
- removeListener: () => /** @type {void} */ (undefined),
472
- invalidate: () => /** @type {void} */ (undefined),
473
- identifier: () => "constant",
474
- fields: [],
475
- globals: [],
476
- code: JSON.stringify(value),
477
- });
478
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=paramMediator.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"paramMediator.test.d.ts","sourceRoot":"","sources":["../../../src/view/paramMediator.test.js"],"names":[],"mappings":""}