@genome-spy/core 0.30.0 → 0.30.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 (234) hide show
  1. package/dist/index.es.js +16379 -0
  2. package/dist/index.js +43 -43
  3. package/package.json +10 -7
  4. package/src/data/collector.js +0 -183
  5. package/src/data/collector.test.js +0 -84
  6. package/src/data/dataFlow.js +0 -148
  7. package/src/data/dataFlow.test.js +0 -5
  8. package/src/data/facetNode.js +0 -17
  9. package/src/data/flow.test.js +0 -72
  10. package/src/data/flowBatch.d.ts +0 -40
  11. package/src/data/flowNode.js +0 -283
  12. package/src/data/flowNode.test.js +0 -50
  13. package/src/data/flowOptimizer.js +0 -123
  14. package/src/data/flowOptimizer.test.js +0 -193
  15. package/src/data/flowTestUtils.js +0 -63
  16. package/src/data/formats/fasta.js +0 -32
  17. package/src/data/formats/fasta.test.js +0 -27
  18. package/src/data/sources/dataSource.js +0 -22
  19. package/src/data/sources/dataSourceFactory.js +0 -24
  20. package/src/data/sources/dataUtils.js +0 -78
  21. package/src/data/sources/dynamicCallbackSource.js +0 -57
  22. package/src/data/sources/dynamicSource.js +0 -37
  23. package/src/data/sources/inlineSource.js +0 -67
  24. package/src/data/sources/inlineSource.test.js +0 -56
  25. package/src/data/sources/namedSource.js +0 -79
  26. package/src/data/sources/sequenceSource.js +0 -46
  27. package/src/data/sources/sequenceSource.test.js +0 -46
  28. package/src/data/sources/urlSource.js +0 -74
  29. package/src/data/transforms/aggregate.js +0 -70
  30. package/src/data/transforms/clone.js +0 -40
  31. package/src/data/transforms/clone.test.js +0 -11
  32. package/src/data/transforms/coverage.js +0 -187
  33. package/src/data/transforms/coverage.test.js +0 -123
  34. package/src/data/transforms/filter.js +0 -37
  35. package/src/data/transforms/filter.test.js +0 -18
  36. package/src/data/transforms/filterScoredLabels.js +0 -134
  37. package/src/data/transforms/flattenCompressedExons.js +0 -57
  38. package/src/data/transforms/flattenDelimited.js +0 -74
  39. package/src/data/transforms/flattenDelimited.test.js +0 -87
  40. package/src/data/transforms/flattenSequence.js +0 -39
  41. package/src/data/transforms/flattenSequence.test.js +0 -34
  42. package/src/data/transforms/formula.js +0 -39
  43. package/src/data/transforms/formula.test.js +0 -19
  44. package/src/data/transforms/identifier.js +0 -108
  45. package/src/data/transforms/identifier.test.js +0 -83
  46. package/src/data/transforms/linearizeGenomicCoordinate.js +0 -101
  47. package/src/data/transforms/measureText.js +0 -44
  48. package/src/data/transforms/pileup.js +0 -128
  49. package/src/data/transforms/pileup.test.js +0 -70
  50. package/src/data/transforms/project.js +0 -41
  51. package/src/data/transforms/project.test.js +0 -32
  52. package/src/data/transforms/regexExtract.js +0 -61
  53. package/src/data/transforms/regexExtract.test.js +0 -67
  54. package/src/data/transforms/regexFold.js +0 -141
  55. package/src/data/transforms/regexFold.test.js +0 -160
  56. package/src/data/transforms/sample.js +0 -101
  57. package/src/data/transforms/sample.test.js +0 -38
  58. package/src/data/transforms/stack.js +0 -137
  59. package/src/data/transforms/stack.test.js +0 -91
  60. package/src/data/transforms/transformFactory.js +0 -60
  61. package/src/embedApi.d.ts +0 -67
  62. package/src/encoder/accessor.js +0 -82
  63. package/src/encoder/accessor.test.js +0 -47
  64. package/src/encoder/encoder.js +0 -394
  65. package/src/encoder/encoder.test.js +0 -98
  66. package/src/fonts/Lato-Regular.json +0 -1267
  67. package/src/fonts/Lato-Regular.png +0 -0
  68. package/src/fonts/OFL.txt +0 -93
  69. package/src/fonts/README.md +0 -3
  70. package/src/fonts/bmFont.d.ts +0 -58
  71. package/src/fonts/bmFontManager.js +0 -357
  72. package/src/fonts/bmFontMetrics.js +0 -108
  73. package/src/genome/genome.js +0 -317
  74. package/src/genome/genome.test.js +0 -188
  75. package/src/genome/genomeStore.js +0 -54
  76. package/src/genome/locusFormat.js +0 -31
  77. package/src/genome/scaleIndex.d.ts +0 -38
  78. package/src/genome/scaleIndex.js +0 -166
  79. package/src/genome/scaleIndex.test.js +0 -78
  80. package/src/genome/scaleLocus.d.ts +0 -11
  81. package/src/genome/scaleLocus.js +0 -108
  82. package/src/genome/scaleLocus.test.js +0 -4
  83. package/src/genomeSpy.js +0 -785
  84. package/src/gl/arrayBuilder.js +0 -199
  85. package/src/gl/dataToVertices.js +0 -636
  86. package/src/gl/includes/common.glsl +0 -63
  87. package/src/gl/includes/picking.fragment.glsl +0 -1
  88. package/src/gl/includes/picking.vertex.glsl +0 -27
  89. package/src/gl/includes/sampleFacet.glsl +0 -107
  90. package/src/gl/includes/scales.glsl +0 -112
  91. package/src/gl/link.fragment.glsl +0 -18
  92. package/src/gl/link.vertex.glsl +0 -111
  93. package/src/gl/point.fragment.glsl +0 -123
  94. package/src/gl/point.vertex.glsl +0 -129
  95. package/src/gl/rect.fragment.glsl +0 -51
  96. package/src/gl/rect.vertex.glsl +0 -114
  97. package/src/gl/rule.fragment.glsl +0 -52
  98. package/src/gl/rule.vertex.glsl +0 -89
  99. package/src/gl/text.fragment.glsl +0 -31
  100. package/src/gl/text.vertex.glsl +0 -246
  101. package/src/gl/webGLHelper.js +0 -504
  102. package/src/img/bowtie.svg +0 -1
  103. package/src/img/genomespy-favicon.svg +0 -34
  104. package/src/index.html +0 -11
  105. package/src/index.js +0 -128
  106. package/src/marks/link.js +0 -175
  107. package/src/marks/mark.js +0 -975
  108. package/src/marks/markUtils.js +0 -125
  109. package/src/marks/pointMark.js +0 -251
  110. package/src/marks/rectMark.js +0 -241
  111. package/src/marks/rule.js +0 -250
  112. package/src/marks/text.js +0 -278
  113. package/src/node_modules/.vitest/results.json +0 -1
  114. package/src/scale/colorUtils.js +0 -184
  115. package/src/scale/glslScaleGenerator.js +0 -502
  116. package/src/scale/scale.js +0 -451
  117. package/src/scale/scale.test.js +0 -324
  118. package/src/scale/ticks.js +0 -203
  119. package/src/scale/ticks.test.js +0 -40
  120. package/src/singlePageApp.js +0 -13
  121. package/src/spec/axis.d.ts +0 -296
  122. package/src/spec/channel.d.ts +0 -430
  123. package/src/spec/data.d.ts +0 -196
  124. package/src/spec/font.d.ts +0 -15
  125. package/src/spec/genome.d.ts +0 -35
  126. package/src/spec/mark.d.ts +0 -429
  127. package/src/spec/root.d.ts +0 -17
  128. package/src/spec/sampleView.d.ts +0 -180
  129. package/src/spec/scale.d.ts +0 -273
  130. package/src/spec/title.d.ts +0 -102
  131. package/src/spec/tooltip.d.ts +0 -9
  132. package/src/spec/transform.d.ts +0 -479
  133. package/src/spec/view.d.ts +0 -201
  134. package/src/styles/genome-spy.scss +0 -153
  135. package/src/tooltip/dataTooltipHandler.js +0 -64
  136. package/src/tooltip/refseqGeneTooltipHandler.js +0 -78
  137. package/src/tooltip/tooltipHandler.ts +0 -12
  138. package/src/types/filetypes.d.ts +0 -14
  139. package/src/types/flatqueue.d.ts +0 -53
  140. package/src/types/glsl.d.ts +0 -4
  141. package/src/types/internmap.d.ts +0 -22
  142. package/src/types/object.d.ts +0 -21
  143. package/src/types/vega-loader.d.ts +0 -1
  144. package/src/types/vega-scale.d.ts +0 -60
  145. package/src/utils/addBaseUrl.js +0 -19
  146. package/src/utils/addBaseUrl.test.js +0 -22
  147. package/src/utils/animator.js +0 -83
  148. package/src/utils/arrayUtils.js +0 -61
  149. package/src/utils/binnedIndex.js +0 -167
  150. package/src/utils/binnedIndex.test.js +0 -155
  151. package/src/utils/clamp.js +0 -8
  152. package/src/utils/cloner.js +0 -34
  153. package/src/utils/cloner.test.js +0 -24
  154. package/src/utils/coalesce.js +0 -11
  155. package/src/utils/coalesce.test.js +0 -16
  156. package/src/utils/concatIterables.js +0 -26
  157. package/src/utils/concatIterables.test.js +0 -8
  158. package/src/utils/debounce.js +0 -37
  159. package/src/utils/domainArray.js +0 -216
  160. package/src/utils/domainArray.test.js +0 -130
  161. package/src/utils/eerp.js +0 -13
  162. package/src/utils/expression.js +0 -32
  163. package/src/utils/field.js +0 -28
  164. package/src/utils/formatObject.js +0 -31
  165. package/src/utils/indexer.js +0 -43
  166. package/src/utils/indexer.test.js +0 -47
  167. package/src/utils/inertia.js +0 -124
  168. package/src/utils/interactionEvent.js +0 -33
  169. package/src/utils/iterateNestedMaps.js +0 -21
  170. package/src/utils/iterateNestedMaps.test.js +0 -33
  171. package/src/utils/kWayMerge.js +0 -42
  172. package/src/utils/kWayMerge.test.js +0 -26
  173. package/src/utils/layout/flexLayout.js +0 -368
  174. package/src/utils/layout/flexLayout.test.js +0 -311
  175. package/src/utils/layout/grid.js +0 -95
  176. package/src/utils/layout/grid.test.js +0 -71
  177. package/src/utils/layout/padding.js +0 -120
  178. package/src/utils/layout/point.js +0 -23
  179. package/src/utils/layout/rectangle.js +0 -288
  180. package/src/utils/layout/rectangle.test.js +0 -172
  181. package/src/utils/mergeObjects.js +0 -99
  182. package/src/utils/mergeObjects.test.js +0 -42
  183. package/src/utils/numberExtractor.js +0 -24
  184. package/src/utils/numberExtractor.test.js +0 -6
  185. package/src/utils/point.js +0 -14
  186. package/src/utils/propertyCacher.js +0 -70
  187. package/src/utils/propertyCacher.test.js +0 -85
  188. package/src/utils/propertyCoalescer.js +0 -42
  189. package/src/utils/propertyCoalescer.test.js +0 -22
  190. package/src/utils/reservationMap.js +0 -103
  191. package/src/utils/reservationMap.test.js +0 -20
  192. package/src/utils/scaleNull.js +0 -19
  193. package/src/utils/setOperations.js +0 -75
  194. package/src/utils/smoothstep.js +0 -10
  195. package/src/utils/throttle.js +0 -34
  196. package/src/utils/topK.js +0 -76
  197. package/src/utils/topK.test.js +0 -64
  198. package/src/utils/transition.js +0 -74
  199. package/src/utils/ui/tooltip.js +0 -189
  200. package/src/utils/url.js +0 -22
  201. package/src/utils/variableTools.js +0 -24
  202. package/src/utils/variableTools.test.js +0 -13
  203. package/src/view/axisResolution.js +0 -140
  204. package/src/view/axisResolution.test.js +0 -201
  205. package/src/view/axisView.js +0 -747
  206. package/src/view/concatView.js +0 -45
  207. package/src/view/containerView.js +0 -159
  208. package/src/view/facetView.js +0 -491
  209. package/src/view/flowBuilder.js +0 -367
  210. package/src/view/flowBuilder.test.js +0 -125
  211. package/src/view/gridView.js +0 -786
  212. package/src/view/implicitRootView.js +0 -14
  213. package/src/view/importView.js +0 -19
  214. package/src/view/layerView.js +0 -74
  215. package/src/view/rendering.d.ts +0 -44
  216. package/src/view/renderingContext/compositeViewRenderingContext.js +0 -51
  217. package/src/view/renderingContext/deferredViewRenderingContext.js +0 -176
  218. package/src/view/renderingContext/layoutRecorderViewRenderingContext.js +0 -128
  219. package/src/view/renderingContext/simpleViewRenderingContext.js +0 -64
  220. package/src/view/renderingContext/svgViewRenderingContext.js +0 -125
  221. package/src/view/renderingContext/viewRenderingContext.js +0 -41
  222. package/src/view/scaleResolution.js +0 -797
  223. package/src/view/scaleResolution.test.js +0 -572
  224. package/src/view/scaleResolutionApi.d.ts +0 -40
  225. package/src/view/testUtils.js +0 -51
  226. package/src/view/title.js +0 -165
  227. package/src/view/unitView.js +0 -382
  228. package/src/view/view.js +0 -612
  229. package/src/view/view.test.js +0 -214
  230. package/src/view/viewContext.d.ts +0 -62
  231. package/src/view/viewFactory.js +0 -181
  232. package/src/view/viewFactory.test.js +0 -17
  233. package/src/view/viewUtils.js +0 -327
  234. package/src/view/zoom.js +0 -89
@@ -1,14 +0,0 @@
1
- import GridView from "./gridView";
2
-
3
- export default class ImplicitRootView extends GridView {
4
- /**
5
- * @param {import("./viewUtils").ViewContext} context
6
- * @param {import("./view").default} view
7
- */
8
- constructor(context, view) {
9
- super({ vconcat: [] }, context, undefined, "implicitRoot", 1);
10
-
11
- view.parent = this;
12
- this.appendChild(view);
13
- }
14
- }
@@ -1,19 +0,0 @@
1
- import View from "./view";
2
-
3
- /**
4
- * This is just a placeholder for custom tracks that are imported by name.
5
- */
6
- export default class ImportView extends View {
7
- /**
8
- *
9
- * @param {import("../spec/view").ImportSpec} spec
10
- * @param {import("./viewUtils").ViewContext} context
11
- * @param {import("./view").default} parent
12
- * @param {string} name
13
- */
14
- constructor(spec, context, parent, name) {
15
- super(spec, context, parent, name);
16
-
17
- this.spec = spec; // Set here again to keep types happy
18
- }
19
- }
@@ -1,74 +0,0 @@
1
- import { isLayerSpec, isUnitSpec } from "./viewFactory";
2
- import ContainerView from "./containerView";
3
-
4
- /**
5
- * @typedef {import("./view").default} View
6
- */
7
- export default class LayerView extends ContainerView {
8
- /**
9
- *
10
- * @param {import("./viewUtils").LayerSpec} spec
11
- * @param {import("./viewUtils").ViewContext} context
12
- * @param {ContainerView} parent
13
- * @param {string} name
14
- */
15
- constructor(spec, context, parent, name) {
16
- super(spec, context, parent, name);
17
-
18
- this.spec = spec;
19
-
20
- /** @type {(LayerView | import("./unitView").default)[]} */
21
- this.children = (spec.layer || []).map((childSpec, i) => {
22
- if (isLayerSpec(childSpec) || isUnitSpec(childSpec)) {
23
- return context.createView(childSpec, this, "layer" + i);
24
- } else {
25
- throw new Error(
26
- "LayerView accepts only unit or layer specs as children!"
27
- );
28
- }
29
- });
30
- }
31
-
32
- /**
33
- * @returns {IterableIterator<View>}
34
- */
35
- *[Symbol.iterator]() {
36
- for (const child of this.children) {
37
- yield child;
38
- }
39
- }
40
-
41
- /**
42
- * @param {import("./renderingContext/viewRenderingContext").default} context
43
- * @param {import("../utils/layout/rectangle").default} coords
44
- * @param {import("./view").RenderingOptions} [options]
45
- */
46
- render(context, coords, options = {}) {
47
- if (!this.isVisible()) {
48
- return;
49
- }
50
-
51
- context.pushView(this, coords);
52
-
53
- for (const child of this.children) {
54
- child.render(context, coords, options);
55
- }
56
-
57
- context.popView(this);
58
- }
59
-
60
- /**
61
- * @param {import("../utils/interactionEvent").default} event
62
- */
63
- propagateInteractionEvent(event) {
64
- this.handleInteractionEvent(undefined, event, true);
65
- if (this.children.length) {
66
- // Propagate to the top layer
67
- this.children.at(-1).propagateInteractionEvent(event);
68
- }
69
- if (event.stopped) {
70
- return;
71
- }
72
- this.handleInteractionEvent(undefined, event, false);
73
- }
74
- }
@@ -1,44 +0,0 @@
1
- import { LocSize } from "../utils/layout/flexLayout";
2
- import Rectangle from "../utils/layout/rectangle";
3
-
4
- /**
5
- * Describes the location of a sample facet. Left is the primary pos, right is for
6
- * transitioning between two sets of samples.
7
- */
8
- export interface SampleFacetRenderingOptions {
9
- /**
10
- * Location and height on unit scale, zero at top
11
- */
12
- locSize: LocSize;
13
-
14
- /**
15
- * Target (during transition)
16
- */
17
- targetLocSize?: LocSize;
18
- }
19
-
20
- export interface RenderingOptions {
21
- /**
22
- * Which facet to render (if faceting is being used)
23
- */
24
- facetId?: any;
25
-
26
- sampleFacetRenderingOptions?: SampleFacetRenderingOptions;
27
-
28
- /**
29
- * Clip rendering using the given rectangle.
30
- * Mainly intended for clipping scrollable views.
31
- */
32
- clipRect?: Rectangle;
33
- }
34
-
35
- /**
36
- * Options that affect the whole rendering pass.
37
- */
38
- export interface GlobalRenderingOptions {
39
- /**
40
- * Replace colors with unique ids for picking.
41
- * Views that haven't enabled picking can be skipped.
42
- */
43
- picking?: boolean;
44
- }
@@ -1,51 +0,0 @@
1
- import ViewRenderingContext from "./viewRenderingContext";
2
-
3
- /**
4
- * @typedef {import("../view").default} View
5
- */
6
- export default class CompositeViewRenderingContext extends ViewRenderingContext {
7
- /**
8
- *
9
- * @param {...ViewRenderingContext} contexts
10
- */
11
- constructor(...contexts) {
12
- super({});
13
-
14
- this.contexts = contexts;
15
- }
16
-
17
- /**
18
- * Must be called when a view's render() method is entered
19
- *
20
- * @param {View} view
21
- * @param {import("../../utils/layout/rectangle").default} coords View coordinates
22
- * inside the padding.
23
- */
24
- pushView(view, coords) {
25
- for (const context of this.contexts) {
26
- context.pushView(view, coords);
27
- }
28
- }
29
-
30
- /**
31
- * Must be called when a view's render() method is being exited
32
- *
33
- * @param {View} view
34
- */
35
- popView(view) {
36
- for (const context of this.contexts) {
37
- context.popView(view);
38
- }
39
- }
40
-
41
- /**
42
- *
43
- * @param {import("../../marks/mark").default} mark
44
- * @param {import("../view").RenderingOptions} options
45
- */
46
- renderMark(mark, options) {
47
- for (const context of this.contexts) {
48
- context.renderMark(mark, options);
49
- }
50
- }
51
- }
@@ -1,176 +0,0 @@
1
- import { group } from "d3-array";
2
-
3
- import ViewRenderingContext from "./viewRenderingContext";
4
-
5
- /**
6
- *
7
- * @typedef {object} DeferredRenderingRequest Allows for collecting marks for
8
- * optimized rendering order.
9
- * @prop {import("../../marks/mark").default} mark
10
- * @prop {function():void} callback
11
- * @prop {import("../../utils/layout/rectangle").default} coords
12
- * @prop {import("../../utils/layout/rectangle").default} [clipRect]
13
- */
14
- export default class DeferredViewRenderingContext extends ViewRenderingContext {
15
- /**
16
- * @param {import("../rendering").GlobalRenderingOptions} globalOptions
17
- * @param {import("../../gl/webGLHelper").default} webGLHelper
18
- */
19
- constructor(globalOptions, webGLHelper) {
20
- super(globalOptions);
21
-
22
- this.webGLHelper = webGLHelper;
23
-
24
- /**
25
- * @type {DeferredRenderingRequest[]}
26
- */
27
- this.buffer = [];
28
-
29
- /** @type {import("../../utils/layout/rectangle").default} */
30
- this.coords = undefined;
31
-
32
- /** @type {Set<import("../view").default>} */
33
- this.views = new Set();
34
- }
35
-
36
- /**
37
- * Must be called when a view's render() method is entered
38
- *
39
- * @param {import("../view").default} view
40
- * @param {import("../../utils/layout/rectangle").default} coords View coordinates
41
- * inside the padding.
42
- */
43
- pushView(view, coords) {
44
- this.views.add(view);
45
- this.coords = coords;
46
- }
47
-
48
- /**
49
- *
50
- * @param {import("../../marks/mark").default} mark
51
- * @param {import("../view").RenderingOptions} options
52
- */
53
- renderMark(mark, options) {
54
- if (this.globalOptions.picking && !mark.isPickingParticipant()) {
55
- return;
56
- }
57
-
58
- const callback = mark.render(options);
59
- if (callback) {
60
- this.buffer.push({
61
- mark,
62
- callback,
63
- coords: this.coords,
64
- clipRect: options.clipRect,
65
- });
66
- }
67
- }
68
-
69
- /**
70
- * Renders marks in an optimized order, minimizing the number of WebGL state
71
- * changes.
72
- */
73
- renderDeferred() {
74
- if (!this.batch) {
75
- this._buildBatch();
76
- }
77
-
78
- if (this.batch.length == 0) {
79
- return;
80
- }
81
-
82
- const gl = this.webGLHelper.gl;
83
- const picking = this.globalOptions.picking;
84
-
85
- gl.bindFramebuffer(
86
- gl.FRAMEBUFFER,
87
- picking ? this.webGLHelper._pickingBufferInfo.framebuffer : null
88
- );
89
-
90
- this.webGLHelper.clearAll();
91
-
92
- for (const view of this.views) {
93
- view.onBeforeRender();
94
- }
95
-
96
- // Execute the batch
97
- for (const op of this.batch) {
98
- op();
99
- }
100
-
101
- if (picking) {
102
- gl.bindFramebuffer(gl.FRAMEBUFFER, null);
103
- }
104
- }
105
-
106
- _buildBatch() {
107
- /**
108
- * Store the operations as a sequence of commands for cheap subsequent rendering.
109
- *
110
- * @type {(function():void)[]}
111
- */
112
- this.batch = [];
113
-
114
- /**
115
- * Is drawing enabled or not. As an optimization this is toggled off for invisible views.
116
- */
117
- let enabled = true;
118
-
119
- let viewportVisible = true;
120
-
121
- /**
122
- * @type {function(function():void):(function():void)}
123
- */
124
- const ifEnabled = (op) => () => {
125
- if (enabled) op();
126
- };
127
-
128
- /**
129
- * @type {function(function():void):(function():void)}
130
- */
131
- const ifEnabledAndVisible = (op) => () => {
132
- if (enabled && viewportVisible) op();
133
- };
134
-
135
- // Group by marks in order to minimize program changes
136
- const requestByMark = group(this.buffer, (request) => request.mark);
137
-
138
- for (const [mark, requests] of requestByMark.entries()) {
139
- if (!mark.isReady()) {
140
- continue;
141
- }
142
-
143
- // eslint-disable-next-line no-loop-func
144
- this.batch.push(() => {
145
- enabled = mark.unitView.getEffectiveOpacity() > 0;
146
- });
147
- // Change program, set common uniforms (mark properties, shared domains)
148
- this.batch.push(
149
- ...mark
150
- .prepareRender(this.globalOptions)
151
- .map((op) => ifEnabled(op))
152
- );
153
-
154
- /** @type {import("../../utils/layout/rectangle").default} */
155
- let previousCoords;
156
- for (const request of requests) {
157
- const coords = request.coords;
158
- // Render each facet
159
- if (!coords.equals(previousCoords)) {
160
- this.batch.push(
161
- // eslint-disable-next-line no-loop-func
162
- ifEnabled(() => {
163
- // Suppress rendering if viewport is outside the clipRect
164
- viewportVisible = mark.setViewport(
165
- coords,
166
- request.clipRect
167
- );
168
- })
169
- );
170
- }
171
- this.batch.push(ifEnabledAndVisible(request.callback));
172
- previousCoords = request.coords;
173
- }
174
- }
175
- }
176
- }
@@ -1,128 +0,0 @@
1
- import { peek } from "../../utils/arrayUtils";
2
- import ViewRenderingContext from "./viewRenderingContext";
3
-
4
- /**
5
- * A Rendering context that doesn't render anything. It creates a hierarchy
6
- * of view coordinates, including faceted views that are repeated multiple times.
7
- * The coordinates can be used for mouse events / interactions, for example.
8
- *
9
- * @typedef {import("../view").default} View
10
- * @typedef {import("../../utils/layout/rectangle").default} Rectangle
11
- *
12
- */
13
- export default class LayoutRecorderViewRenderingContext extends ViewRenderingContext {
14
- /**
15
- * @param {import("../rendering").GlobalRenderingOptions} globalOptions
16
- */
17
- constructor(globalOptions) {
18
- super(globalOptions);
19
-
20
- /** @type {ViewCoords} */
21
- this.root = undefined;
22
-
23
- /** @type {ViewCoords[]} */
24
- this.stack = [];
25
-
26
- /** @type {ViewCoords} */
27
- this.lastAddition = undefined;
28
- }
29
-
30
- /**
31
- * Must be called when a view's render() method is entered
32
- *
33
- * @param {View} view
34
- * @param {Rectangle} coords View coordinates
35
- * inside the padding.
36
- */
37
- pushView(view, coords) {
38
- // TODO: Facet id
39
-
40
- const viewCoords = new ViewCoords(view, coords);
41
-
42
- if (!this.root) {
43
- this.root = viewCoords;
44
- } else {
45
- peek(this.stack).addChild(viewCoords);
46
- }
47
- this.stack.push(viewCoords);
48
- }
49
-
50
- /**
51
- * Must be called when a view's render() method is being exited
52
- *
53
- * @param {View} view
54
- */
55
- popView(view) {
56
- this.stack.pop();
57
- }
58
-
59
- getLayout() {
60
- return this.root;
61
- }
62
- }
63
-
64
- /**
65
- * Represents coordinates of view instances. Faceted views objects may have
66
- * been rendered at multiple locations.
67
- */
68
- class ViewCoords {
69
- /**
70
- * @param {View} view
71
- * @param {Rectangle} coords
72
- */
73
- constructor(view, coords) {
74
- this.view = view;
75
- this.coords = coords;
76
- /** @type {ViewCoords[]} */
77
- this.children = [];
78
- }
79
-
80
- /**
81
- *
82
- * @param {ViewCoords} viewCoords
83
- */
84
- addChild(viewCoords) {
85
- const last = peek(this.children);
86
- if (
87
- last &&
88
- viewCoords.view === last.view &&
89
- viewCoords.coords.equals(last.coords)
90
- ) {
91
- // Skip extra copies of sample facets. They all have the same coords.
92
- return;
93
- }
94
-
95
- this.children.push(viewCoords);
96
- }
97
-
98
- /**
99
- * Broadcasts a message to views that include the given (x, y) point.
100
- * This is mainly intended for mouse events.
101
- *
102
- * @param {import("../../utils/interactionEvent").default} event
103
- */
104
- dispatchInteractionEvent(event) {
105
- if (this.coords.containsPoint(event.point.x, event.point.y)) {
106
- this.view.handleInteractionEvent(this.coords, event, true);
107
- if (event.stopped) {
108
- return;
109
- }
110
-
111
- if (this.children.length == 0) {
112
- event.target = this.view;
113
- } else {
114
- for (const child of this.children) {
115
- child.dispatchInteractionEvent(event);
116
- if (event.target) {
117
- break;
118
- }
119
- if (event.stopped) {
120
- return;
121
- }
122
- }
123
- }
124
-
125
- this.view.handleInteractionEvent(this.coords, event, false);
126
- }
127
- }
128
- }
@@ -1,64 +0,0 @@
1
- import ViewRenderingContext from "./viewRenderingContext";
2
-
3
- /**
4
- * This class is mainly for illustrative purpose, i.e., how the rendering
5
- * would be performed in the most straightforward, unoptimized way.
6
- *
7
- * @typedef {import("../view").default} View
8
- */
9
- export default class SimpleViewRenderingContext extends ViewRenderingContext {
10
- /**
11
- * @param {import("../rendering").GlobalRenderingOptions} globalOptions
12
- */
13
- constructor(globalOptions) {
14
- super(globalOptions);
15
- /** @type {import("../../utils/layout/rectangle").default} */
16
- this.coords = undefined;
17
-
18
- /** @type {Set<import("../view").default>} */
19
- this.views = new Set();
20
- }
21
-
22
- /**
23
- * Must be called when a view's render() method is entered
24
- *
25
- * @param {View} view
26
- * @param {import("../../utils/layout/rectangle").default} coords View coordinates
27
- * inside the padding.
28
- */
29
- pushView(view, coords) {
30
- if (!this.views.has(view)) {
31
- // Ensure that the method is called only once, even when rendering facets.
32
- view.onBeforeRender();
33
- this.views.add(view);
34
- }
35
-
36
- this.coords = coords;
37
- }
38
-
39
- /**
40
- * Must be called when a view's render() method is being exited
41
- *
42
- * @param {View} view
43
- */
44
- popView(view) {
45
- //
46
- }
47
-
48
- /**
49
- *
50
- * @param {import("../../marks/mark").default} mark
51
- * @param {import("../view").RenderingOptions} options
52
- */
53
- renderMark(mark, options) {
54
- if (this.globalOptions.picking && !mark.isPickingParticipant()) {
55
- return;
56
- }
57
-
58
- for (const op of mark.prepareRender(this.globalOptions)) {
59
- op();
60
- }
61
- mark.setViewport(this.coords, options.clipRect);
62
- mark.render(options)();
63
- }
64
- }
@@ -1,125 +0,0 @@
1
- import { peek } from "../../utils/arrayUtils";
2
- import ViewRenderingContext from "./viewRenderingContext";
3
-
4
- /**
5
- * A trivial proof-of-concept SVG rendering context. Doesn't render any
6
- * marks at this point, only placeholders.
7
- *
8
- * @typedef {import("../view").default} View
9
- */
10
- export default class SvgViewRenderingContext extends ViewRenderingContext {
11
- /**
12
- *
13
- * @param {import("../rendering").GlobalRenderingOptions} globalOptions
14
- */
15
- constructor(globalOptions) {
16
- super(globalOptions);
17
-
18
- /** @type {import("../../utils/layout/rectangle").default} */
19
- this.coords = undefined;
20
-
21
- this.svg = document.createElementNS(
22
- "http://www.w3.org/2000/svg",
23
- "svg"
24
- );
25
-
26
- /** @type {SVGElement[]} */
27
- this.nodeStack = [this.svg];
28
- }
29
-
30
- /**
31
- * Must be called when a view's render() method is entered
32
- *
33
- * @param {View} view
34
- * @param {import("../../utils/layout/rectangle").default} coords View coordinates
35
- * inside the padding.
36
- */
37
- pushView(view, coords) {
38
- view.onBeforeRender();
39
- this.coords = coords;
40
-
41
- if (this._currentNode === this.svg) {
42
- const viewBox = coords.expand(view.getPadding());
43
- this.svg.setAttributeNS(
44
- null,
45
- "viewBox",
46
- [viewBox.x, viewBox.y, viewBox.width, viewBox.height].join(" ")
47
- );
48
- }
49
-
50
- const group = createNode("g");
51
- const title = createNode("title");
52
- title.textContent = view.name;
53
- group.appendChild(title);
54
-
55
- this._currentNode.appendChild(group);
56
- this.nodeStack.push(group);
57
- }
58
-
59
- /**
60
- * Must be called when a view's render() method is being exited
61
- *
62
- * @param {View} view
63
- */
64
- popView(view) {
65
- this.nodeStack.pop();
66
- }
67
-
68
- /**
69
- *
70
- * @param {import("../../marks/mark").default} mark
71
- * @param {import("../view").RenderingOptions} options
72
- */
73
- renderMark(mark, options) {
74
- const current = this._currentNode;
75
-
76
- const rect = createNode("rect", {
77
- x: this.coords.x,
78
- y: this.coords.y,
79
- width: this.coords.width,
80
- height: this.coords.height,
81
- fill: "transparent",
82
- stroke: "black",
83
- "stroke-width": 1,
84
- });
85
-
86
- const name = createNode("text", {
87
- x: this.coords.x + this.coords.width / 2,
88
- y: this.coords.y + this.coords.height / 2,
89
- "dominant-baseline": "middle",
90
- "text-anchor": "middle",
91
- });
92
-
93
- name.textContent = mark.getType();
94
-
95
- current.appendChild(rect);
96
- current.appendChild(name);
97
- }
98
-
99
- getSvg() {
100
- return this.svg;
101
- }
102
-
103
- get _currentNode() {
104
- return peek(this.nodeStack);
105
- }
106
- }
107
-
108
- /**
109
- * Adapted from: https://stackoverflow.com/a/37411738/1547896
110
- *
111
- * @param {string} name
112
- * @param {Record<string, any>} [attributes]
113
- */
114
- function createNode(name, attributes) {
115
- const element = document.createElementNS(
116
- "http://www.w3.org/2000/svg",
117
- name
118
- );
119
- if (attributes) {
120
- for (const [k, v] of Object.entries(attributes)) {
121
- element.setAttributeNS(null, k, v);
122
- }
123
- }
124
- return element;
125
- }