@genome-spy/core 0.14.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.
- package/dist/index.js +224 -0
- package/dist/style.css +1 -0
- package/package.json +54 -0
- package/src/data/collector.js +178 -0
- package/src/data/collector.test.js +82 -0
- package/src/data/dataFlow.js +109 -0
- package/src/data/dataFlow.test.js +3 -0
- package/src/data/facetNode.js +17 -0
- package/src/data/flow.test.js +71 -0
- package/src/data/flowBatch.d.ts +40 -0
- package/src/data/flowNode.js +283 -0
- package/src/data/flowNode.test.js +49 -0
- package/src/data/flowOptimizer.js +117 -0
- package/src/data/flowOptimizer.test.js +192 -0
- package/src/data/flowTestUtils.js +63 -0
- package/src/data/formats/fasta.js +32 -0
- package/src/data/formats/fasta.test.js +26 -0
- package/src/data/sources/dataSource.js +22 -0
- package/src/data/sources/dataSourceFactory.js +24 -0
- package/src/data/sources/dataUtils.js +31 -0
- package/src/data/sources/dynamicCallbackSource.js +56 -0
- package/src/data/sources/dynamicSource.js +36 -0
- package/src/data/sources/inlineSource.js +69 -0
- package/src/data/sources/inlineSource.test.js +55 -0
- package/src/data/sources/namedSource.js +74 -0
- package/src/data/sources/sequenceSource.js +46 -0
- package/src/data/sources/sequenceSource.test.js +45 -0
- package/src/data/sources/urlSource.js +74 -0
- package/src/data/transforms/aggregate.js +69 -0
- package/src/data/transforms/clone.js +40 -0
- package/src/data/transforms/clone.test.js +10 -0
- package/src/data/transforms/coverage.js +187 -0
- package/src/data/transforms/coverage.test.js +122 -0
- package/src/data/transforms/filter.js +37 -0
- package/src/data/transforms/filter.test.js +17 -0
- package/src/data/transforms/filterScoredLabels.js +134 -0
- package/src/data/transforms/flattenCompressedExons.js +57 -0
- package/src/data/transforms/flattenDelimited.js +68 -0
- package/src/data/transforms/flattenDelimited.test.js +86 -0
- package/src/data/transforms/flattenSequence.js +39 -0
- package/src/data/transforms/flattenSequence.test.js +33 -0
- package/src/data/transforms/formula.js +39 -0
- package/src/data/transforms/formula.test.js +18 -0
- package/src/data/transforms/identifier.js +108 -0
- package/src/data/transforms/identifier.test.js +82 -0
- package/src/data/transforms/linearizeGenomicCoordinate.js +101 -0
- package/src/data/transforms/measureText.js +44 -0
- package/src/data/transforms/pileup.js +128 -0
- package/src/data/transforms/pileup.test.js +69 -0
- package/src/data/transforms/project.js +41 -0
- package/src/data/transforms/project.test.js +31 -0
- package/src/data/transforms/regexExtract.js +61 -0
- package/src/data/transforms/regexExtract.test.js +66 -0
- package/src/data/transforms/regexFold.js +141 -0
- package/src/data/transforms/regexFold.test.js +159 -0
- package/src/data/transforms/sample.js +101 -0
- package/src/data/transforms/sample.test.js +37 -0
- package/src/data/transforms/stack.js +137 -0
- package/src/data/transforms/stack.test.js +90 -0
- package/src/data/transforms/transformFactory.js +60 -0
- package/src/encoder/accessor.js +82 -0
- package/src/encoder/accessor.test.js +46 -0
- package/src/encoder/encoder.js +369 -0
- package/src/encoder/encoder.test.js +97 -0
- package/src/fonts/Lato-Regular.json +1267 -0
- package/src/fonts/Lato-Regular.png +0 -0
- package/src/fonts/OFL.txt +93 -0
- package/src/fonts/README.md +3 -0
- package/src/fonts/bmFont.d.ts +58 -0
- package/src/fonts/bmFontManager.js +357 -0
- package/src/fonts/bmFontMetrics.js +108 -0
- package/src/genome/genome.js +305 -0
- package/src/genome/genome.test.js +152 -0
- package/src/genome/genomeStore.js +54 -0
- package/src/genome/locusFormat.js +31 -0
- package/src/genome/scaleIndex.js +199 -0
- package/src/genome/scaleIndex.test.js +61 -0
- package/src/genome/scaleLocus.js +112 -0
- package/src/genome/scaleLocus.test.js +3 -0
- package/src/genomeSpy.js +753 -0
- package/src/gl/arrayBuilder.js +199 -0
- package/src/gl/dataToVertices.js +621 -0
- package/src/gl/includes/common.glsl +63 -0
- package/src/gl/includes/fp64-arithmetic.glsl +187 -0
- package/src/gl/includes/fp64-utils.js +132 -0
- package/src/gl/includes/picking.fragment.glsl +3 -0
- package/src/gl/includes/picking.vertex.glsl +29 -0
- package/src/gl/includes/sampleFacet.glsl +107 -0
- package/src/gl/includes/scales.glsl +79 -0
- package/src/gl/includes/scales_fp64.glsl +30 -0
- package/src/gl/link.fragment.glsl +18 -0
- package/src/gl/link.vertex.glsl +111 -0
- package/src/gl/point.fragment.glsl +123 -0
- package/src/gl/point.vertex.glsl +128 -0
- package/src/gl/rect.fragment.glsl +51 -0
- package/src/gl/rect.vertex.glsl +114 -0
- package/src/gl/rule.fragment.glsl +52 -0
- package/src/gl/rule.vertex.glsl +89 -0
- package/src/gl/text.fragment.glsl +31 -0
- package/src/gl/text.vertex.glsl +246 -0
- package/src/gl/webGLHelper.js +490 -0
- package/src/img/bowtie.svg +1 -0
- package/src/img/genomespy-favicon.svg +34 -0
- package/src/index.html +11 -0
- package/src/index.js +151 -0
- package/src/marks/link.js +189 -0
- package/src/marks/mark.js +867 -0
- package/src/marks/markUtils.js +109 -0
- package/src/marks/pointMark.js +279 -0
- package/src/marks/rectMark.js +236 -0
- package/src/marks/rule.js +231 -0
- package/src/marks/text.js +274 -0
- package/src/options.d.ts +9 -0
- package/src/scale/colorUtils.js +184 -0
- package/src/scale/glslScaleGenerator.js +462 -0
- package/src/scale/scale.js +441 -0
- package/src/scale/scale.test.js +323 -0
- package/src/scale/ticks.js +198 -0
- package/src/scale/ticks.test.js +39 -0
- package/src/singlePageApp.js +13 -0
- package/src/spec/axis.d.ts +296 -0
- package/src/spec/channel.d.ts +127 -0
- package/src/spec/data.d.ts +185 -0
- package/src/spec/font.d.ts +15 -0
- package/src/spec/genome.d.ts +35 -0
- package/src/spec/mark.d.ts +432 -0
- package/src/spec/root.d.ts +22 -0
- package/src/spec/scale.d.ts +265 -0
- package/src/spec/tooltip.d.ts +9 -0
- package/src/spec/transform.d.ts +479 -0
- package/src/spec/view.d.ts +215 -0
- package/src/styles/genome-spy.scss +153 -0
- package/src/tooltip/dataTooltipHandler.js +59 -0
- package/src/tooltip/refseqGeneTooltipHandler.js +77 -0
- package/src/tooltip/tooltipHandler.ts +12 -0
- package/src/types/filetypes.d.ts +4 -0
- package/src/types/flatqueue.d.ts +53 -0
- package/src/types/glsl.d.ts +4 -0
- package/src/types/object.d.ts +21 -0
- package/src/types/vega-scale.d.ts +60 -0
- package/src/utils/animator.js +83 -0
- package/src/utils/arrayUtils.js +55 -0
- package/src/utils/binnedRangeIndex.js +83 -0
- package/src/utils/clamp.js +8 -0
- package/src/utils/cloner.js +32 -0
- package/src/utils/cloner.test.js +23 -0
- package/src/utils/coalesce.js +11 -0
- package/src/utils/coalesce.test.js +15 -0
- package/src/utils/concatIterables.js +26 -0
- package/src/utils/concatIterables.test.js +7 -0
- package/src/utils/debounce.js +37 -0
- package/src/utils/domainArray.js +224 -0
- package/src/utils/domainArray.test.js +129 -0
- package/src/utils/eerp.js +13 -0
- package/src/utils/expression.js +32 -0
- package/src/utils/field.js +28 -0
- package/src/utils/fisheye.js +60 -0
- package/src/utils/formatObject.js +31 -0
- package/src/utils/html.js +23 -0
- package/src/utils/html.test.js +13 -0
- package/src/utils/indexer.js +43 -0
- package/src/utils/indexer.test.js +46 -0
- package/src/utils/inertia.js +124 -0
- package/src/utils/interactionEvent.js +33 -0
- package/src/utils/iterateNestedMaps.js +21 -0
- package/src/utils/iterateNestedMaps.test.js +32 -0
- package/src/utils/kWayMerge.js +42 -0
- package/src/utils/kWayMerge.test.js +25 -0
- package/src/utils/layout/flexLayout.js +336 -0
- package/src/utils/layout/flexLayout.test.js +296 -0
- package/src/utils/layout/padding.js +107 -0
- package/src/utils/layout/point.js +23 -0
- package/src/utils/layout/rectangle.js +282 -0
- package/src/utils/layout/rectangle.test.js +171 -0
- package/src/utils/mergeObjects.js +99 -0
- package/src/utils/mergeObjects.test.js +41 -0
- package/src/utils/numberExtractor.js +24 -0
- package/src/utils/numberExtractor.test.js +5 -0
- package/src/utils/point.js +14 -0
- package/src/utils/propertyCacher.js +70 -0
- package/src/utils/propertyCacher.test.js +84 -0
- package/src/utils/propertyCoalescer.js +37 -0
- package/src/utils/propertyCoalescer.test.js +21 -0
- package/src/utils/reservationMap.js +103 -0
- package/src/utils/reservationMap.test.js +19 -0
- package/src/utils/scaleNull.js +19 -0
- package/src/utils/setOperations.js +75 -0
- package/src/utils/smoothstep.js +10 -0
- package/src/utils/throttle.js +34 -0
- package/src/utils/topK.js +76 -0
- package/src/utils/topK.test.js +63 -0
- package/src/utils/transition.js +74 -0
- package/src/utils/ui/tooltip.js +189 -0
- package/src/utils/url.js +22 -0
- package/src/utils/variableTools.js +24 -0
- package/src/utils/variableTools.test.js +12 -0
- package/src/view/axisResolution.js +135 -0
- package/src/view/axisResolution.test.js +200 -0
- package/src/view/axisView.js +746 -0
- package/src/view/channel.js +5 -0
- package/src/view/concatView.js +296 -0
- package/src/view/containerView.js +141 -0
- package/src/view/decoratorView.js +510 -0
- package/src/view/facetView.js +488 -0
- package/src/view/flowBuilder.js +362 -0
- package/src/view/flowBuilder.test.js +124 -0
- package/src/view/importView.js +19 -0
- package/src/view/layerView.js +60 -0
- package/src/view/rendering.d.ts +44 -0
- package/src/view/renderingContext/compositeViewRenderingContext.js +51 -0
- package/src/view/renderingContext/deferredViewRenderingContext.js +174 -0
- package/src/view/renderingContext/layoutRecorderViewRenderingContext.js +128 -0
- package/src/view/renderingContext/simpleViewRenderingContext.js +62 -0
- package/src/view/renderingContext/svgViewRenderingContext.js +121 -0
- package/src/view/renderingContext/viewRenderingContext.js +41 -0
- package/src/view/scaleResolution.js +756 -0
- package/src/view/scaleResolution.test.js +571 -0
- package/src/view/scaleResolutionApi.d.ts +40 -0
- package/src/view/testUtils.js +48 -0
- package/src/view/unitView.js +368 -0
- package/src/view/view.js +589 -0
- package/src/view/view.test.js +213 -0
- package/src/view/viewContext.d.ts +57 -0
- package/src/view/viewFactory.js +179 -0
- package/src/view/viewFactory.test.js +16 -0
- package/src/view/viewUtils.js +420 -0
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
import ContainerView from "./containerView";
|
|
2
|
+
import AxisView from "./axisView";
|
|
3
|
+
import { getFlattenedViews } from "./viewUtils";
|
|
4
|
+
import Padding from "../utils/layout/padding";
|
|
5
|
+
import UnitView from "./unitView";
|
|
6
|
+
import { ZERO_FLEXDIMENSIONS } from "../utils/layout/flexLayout";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {import("../spec/channel").PositionalChannel} PositionalChannel
|
|
10
|
+
* @typedef {import("../spec/view").GeometricDimension} GeometricDimension
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** @type {Record<PositionalChannel, AxisOrient[]>} */
|
|
14
|
+
const CHANNEL_ORIENTS = {
|
|
15
|
+
x: ["bottom", "top"],
|
|
16
|
+
y: ["left", "right"],
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* An internal view that wraps a unit or layer view and takes care of the axes.
|
|
21
|
+
*
|
|
22
|
+
* @typedef {import("../spec/view").LayerSpec} LayerSpec
|
|
23
|
+
* @typedef {import("./view").default} View
|
|
24
|
+
* @typedef {import("../spec/axis").Axis} Axis
|
|
25
|
+
* @typedef {import("../spec/axis").GenomeAxis} GenomeAxis
|
|
26
|
+
* @typedef {import("../spec/axis").AxisOrient} AxisOrient
|
|
27
|
+
*
|
|
28
|
+
* @typedef {Axis & { extent: number }} AugmentedAxis
|
|
29
|
+
*
|
|
30
|
+
* @typedef {object} ZoomEvent
|
|
31
|
+
* @prop {number} x
|
|
32
|
+
* @prop {number} y
|
|
33
|
+
* @prop {number} xDelta
|
|
34
|
+
* @prop {number} yDelta
|
|
35
|
+
* @prop {number} zDelta
|
|
36
|
+
*/
|
|
37
|
+
export default class DecoratorView extends ContainerView {
|
|
38
|
+
/**
|
|
39
|
+
* @param {import("./viewUtils").ViewContext} context
|
|
40
|
+
* @param {import("./containerView").default} parent
|
|
41
|
+
*/
|
|
42
|
+
constructor(context, parent) {
|
|
43
|
+
super({}, context, parent, "decorator");
|
|
44
|
+
|
|
45
|
+
/** @type { import("./layerView").default | import("./unitView").default } */
|
|
46
|
+
this.child = undefined;
|
|
47
|
+
|
|
48
|
+
/** @type {UnitView} */
|
|
49
|
+
this.backgroundView = undefined;
|
|
50
|
+
|
|
51
|
+
/** @type {Record<AxisOrient, AxisView>} */
|
|
52
|
+
this.axisViews = {
|
|
53
|
+
top: undefined,
|
|
54
|
+
right: undefined,
|
|
55
|
+
bottom: undefined,
|
|
56
|
+
left: undefined,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
["mousedown", "wheel"].forEach((type) =>
|
|
60
|
+
this.addInteractionEventListener(
|
|
61
|
+
type,
|
|
62
|
+
this.handleMouseEvent.bind(this)
|
|
63
|
+
)
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Creates the axis views
|
|
69
|
+
*
|
|
70
|
+
* TODO: Perhaps views need a common initialization method?
|
|
71
|
+
*/
|
|
72
|
+
initialize() {
|
|
73
|
+
Object.entries(CHANNEL_ORIENTS).forEach(([channel, orients]) =>
|
|
74
|
+
this._initializeAxes(channel, orients)
|
|
75
|
+
);
|
|
76
|
+
this._invalidateCacheByPrefix("size/", "ancestors");
|
|
77
|
+
|
|
78
|
+
// TODO: Merge viewConfig from all descendants (when there are layers)
|
|
79
|
+
// TODO: Implement styles
|
|
80
|
+
|
|
81
|
+
const viewConfig = this.child.spec?.view;
|
|
82
|
+
if (viewConfig?.fill || viewConfig?.stroke) {
|
|
83
|
+
this.backgroundView = new UnitView(
|
|
84
|
+
createBackground(viewConfig),
|
|
85
|
+
this.context,
|
|
86
|
+
this,
|
|
87
|
+
"background"
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @param {View} [whoIsAsking] Passed to the immediate parent. Allows for
|
|
94
|
+
* selectively breaking the inheritance.
|
|
95
|
+
*/
|
|
96
|
+
getEncoding(whoIsAsking) {
|
|
97
|
+
if (
|
|
98
|
+
Object.values(this.axisViews).find(
|
|
99
|
+
(view) => whoIsAsking === view
|
|
100
|
+
) ||
|
|
101
|
+
whoIsAsking == this.backgroundView
|
|
102
|
+
) {
|
|
103
|
+
// Prevent the axis views from inheriting any encodings
|
|
104
|
+
return {};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return super.getEncoding();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @param {View} [whoIsAsking] Passed to the immediate parent. Allows for
|
|
112
|
+
* selectively breaking the inheritance.
|
|
113
|
+
* @return {function(object):any}
|
|
114
|
+
*/
|
|
115
|
+
getFacetAccessor(whoIsAsking) {
|
|
116
|
+
if (whoIsAsking != this.child) {
|
|
117
|
+
// Axes have no facets
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (this.parent) {
|
|
122
|
+
return this.parent.getFacetAccessor(this);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @returns {IterableIterator<View>}
|
|
128
|
+
*/
|
|
129
|
+
*[Symbol.iterator]() {
|
|
130
|
+
yield this.child;
|
|
131
|
+
if (this.backgroundView) {
|
|
132
|
+
yield this.backgroundView;
|
|
133
|
+
}
|
|
134
|
+
for (const view of Object.values(this.axisViews)) {
|
|
135
|
+
if (view) {
|
|
136
|
+
yield view;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
_getAxisExtents() {
|
|
142
|
+
return this._cache("size/axisExtents", () => {
|
|
143
|
+
/** @type {Record<AxisOrient, number>} */
|
|
144
|
+
// @ts-ignore
|
|
145
|
+
const paddings = {};
|
|
146
|
+
for (const view of Object.values(this.axisViews)) {
|
|
147
|
+
if (view) {
|
|
148
|
+
paddings[view.getOrient()] = view.getPerpendicularSize();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return Padding.createFromRecord(paddings);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
_getAxisOffsets() {
|
|
156
|
+
return this._cache("size/axisOffsets", () => {
|
|
157
|
+
/** @type {Record<AxisOrient, number>} */
|
|
158
|
+
// @ts-ignore
|
|
159
|
+
const paddings = {};
|
|
160
|
+
for (const view of Object.values(this.axisViews)) {
|
|
161
|
+
if (view) {
|
|
162
|
+
paddings[view.getOrient()] = view.axisProps.offset;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return Padding.createFromRecord(paddings);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
getEffectivePadding() {
|
|
170
|
+
// TODO: Handle negative axis extents
|
|
171
|
+
return this._cache("size/effectivePadding", () =>
|
|
172
|
+
this.getPadding().add(this._getAxisExtents())
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
getSize() {
|
|
177
|
+
return this._cache("size/size", () =>
|
|
178
|
+
this.child.isVisible()
|
|
179
|
+
? this.getSizeFromSpec()
|
|
180
|
+
.addPadding(this.getPadding())
|
|
181
|
+
.addPadding(this.getAxisSizes())
|
|
182
|
+
: ZERO_FLEXDIMENSIONS
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Returns the amount of extra space the axes need on the plot edges.
|
|
188
|
+
* The calculation takes axis offsets into account.
|
|
189
|
+
*
|
|
190
|
+
* @returns {Padding}
|
|
191
|
+
*/
|
|
192
|
+
getAxisSizes() {
|
|
193
|
+
// TODO: Clamp negative sizes (if axes are positioned entirely onto the plots)
|
|
194
|
+
return this._cache("size/axisSizes", () =>
|
|
195
|
+
this._getAxisExtents().add(this._getAxisOffsets())
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* @param {import("./renderingContext/viewRenderingContext").default} context
|
|
201
|
+
* @param {import("../utils/layout/rectangle").default} coords
|
|
202
|
+
* @param {import("./view").RenderingOptions} [options]
|
|
203
|
+
*/
|
|
204
|
+
render(context, coords, options = {}) {
|
|
205
|
+
if (!this.isVisible() || !this.child.isVisible()) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
coords = coords.shrink(this.getPadding());
|
|
210
|
+
context.pushView(this, coords);
|
|
211
|
+
|
|
212
|
+
const extents = this._getAxisExtents();
|
|
213
|
+
const childCoords = coords.shrink(extents.add(this._getAxisOffsets()));
|
|
214
|
+
|
|
215
|
+
this._childCoords = childCoords;
|
|
216
|
+
|
|
217
|
+
if (this.backgroundView) {
|
|
218
|
+
this.backgroundView.render(context, childCoords, options);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
this.child.render(context, childCoords, options);
|
|
222
|
+
|
|
223
|
+
const entries = this._cache("axisViewEntries", () =>
|
|
224
|
+
Object.entries(this.axisViews).filter((e) => !!e[1])
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
for (const [orient, view] of entries) {
|
|
228
|
+
const props = view.axisProps;
|
|
229
|
+
|
|
230
|
+
/** @type {import("../utils/layout/rectangle").default} */
|
|
231
|
+
let axisCoords;
|
|
232
|
+
|
|
233
|
+
if (orient == "bottom") {
|
|
234
|
+
axisCoords = childCoords
|
|
235
|
+
.translate(0, childCoords.height + props.offset)
|
|
236
|
+
.modify({ height: extents.bottom });
|
|
237
|
+
} else if (orient == "top") {
|
|
238
|
+
axisCoords = childCoords
|
|
239
|
+
.translate(0, -extents.top - props.offset)
|
|
240
|
+
.modify({ height: extents.top });
|
|
241
|
+
} else if (orient == "left") {
|
|
242
|
+
axisCoords = childCoords
|
|
243
|
+
.translate(-extents.left - props.offset, 0)
|
|
244
|
+
.modify({ width: extents.left });
|
|
245
|
+
} else if (orient == "right") {
|
|
246
|
+
axisCoords = childCoords
|
|
247
|
+
.translate(childCoords.width + props.offset, 0)
|
|
248
|
+
.modify({ width: extents.right });
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Axes have no faceted data, thus, pass undefined facetId
|
|
252
|
+
view.render(context, axisCoords);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
context.popView(this);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Returns the views that should be scanned for resolutions: all view's ancestors and children.
|
|
260
|
+
* Axis views are not included.
|
|
261
|
+
*/
|
|
262
|
+
_getResolutionParticipants() {
|
|
263
|
+
return [...this.getAncestors(), ...getFlattenedViews(this.child)];
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* @param {string} channel
|
|
268
|
+
* @param {AxisOrient[]} orients
|
|
269
|
+
*/
|
|
270
|
+
_initializeAxes(channel, orients) {
|
|
271
|
+
const resolutions = this._getResolutionParticipants()
|
|
272
|
+
.map((view) => view.resolutions.axis[channel])
|
|
273
|
+
.filter((resolution) => resolution);
|
|
274
|
+
|
|
275
|
+
// First, fill the preferred slots
|
|
276
|
+
for (const r of resolutions) {
|
|
277
|
+
const axisProps = r.getAxisProps();
|
|
278
|
+
if (axisProps && axisProps.orient) {
|
|
279
|
+
if (!orients.includes(axisProps.orient)) {
|
|
280
|
+
throw new Error(
|
|
281
|
+
`Invalid axis orientation for '${channel}' channel: ${axisProps.orient}`
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
if (this.axisViews[axisProps.orient]) {
|
|
285
|
+
throw new Error(
|
|
286
|
+
`The slot for ${axisProps.orient} axis is already reserved!`
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
this.axisViews[axisProps.orient] = new AxisView(
|
|
290
|
+
{
|
|
291
|
+
...axisProps,
|
|
292
|
+
title: r.getTitle(),
|
|
293
|
+
},
|
|
294
|
+
r.scaleResolution.type,
|
|
295
|
+
this.context,
|
|
296
|
+
this
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// Next, fill the slots in the preferred order
|
|
302
|
+
// eslint-disable-next-line no-labels
|
|
303
|
+
resolutionLoop: for (const r of resolutions) {
|
|
304
|
+
const axisProps = r.getAxisProps();
|
|
305
|
+
if (axisProps && !axisProps.orient) {
|
|
306
|
+
for (const slot of orients) {
|
|
307
|
+
if (!this.axisViews[slot]) {
|
|
308
|
+
axisProps.orient = /** @type {AxisOrient} */ (slot);
|
|
309
|
+
this.axisViews[slot] = new AxisView(
|
|
310
|
+
{
|
|
311
|
+
...axisProps,
|
|
312
|
+
title: r.getTitle(),
|
|
313
|
+
},
|
|
314
|
+
r.scaleResolution.type,
|
|
315
|
+
this.context,
|
|
316
|
+
this
|
|
317
|
+
);
|
|
318
|
+
// eslint-disable-next-line no-labels
|
|
319
|
+
continue resolutionLoop;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
throw new Error(
|
|
323
|
+
"No room for axes. All slots are already reserved."
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* @param {import("../utils/layout/rectangle").default} coords
|
|
331
|
+
* Coordinates of the view
|
|
332
|
+
* @param {import("../utils/interactionEvent").default} event
|
|
333
|
+
*/
|
|
334
|
+
handleMouseEvent(coords, event) {
|
|
335
|
+
if (!this.isZoomable()) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// TODO: Extract a class or something
|
|
340
|
+
|
|
341
|
+
if (event.type == "wheel") {
|
|
342
|
+
event.uiEvent.preventDefault(); // TODO: Only if there was something to zoom
|
|
343
|
+
|
|
344
|
+
const wheelEvent = /** @type {WheelEvent} */ (event.uiEvent);
|
|
345
|
+
const wheelMultiplier = wheelEvent.deltaMode ? 120 : 1;
|
|
346
|
+
|
|
347
|
+
let { x, y } = event.point;
|
|
348
|
+
|
|
349
|
+
// Snapping to the hovered item:
|
|
350
|
+
// We find the currently hovered object and move the pointed coordinates
|
|
351
|
+
// to its center if the mark has only primary positional channels.
|
|
352
|
+
// This allows the user to rapidly zoom closer without having to
|
|
353
|
+
// continuously adjust the cursor position.
|
|
354
|
+
|
|
355
|
+
const hover = this.context.getCurrentHover();
|
|
356
|
+
if (hover) {
|
|
357
|
+
const viewCoords = coords.shrink(this.getEffectivePadding());
|
|
358
|
+
|
|
359
|
+
const e = hover.mark.encoders;
|
|
360
|
+
if (e.x && !e.x2) {
|
|
361
|
+
x = +e.x(hover.datum) * viewCoords.width + viewCoords.x;
|
|
362
|
+
}
|
|
363
|
+
if (e.y && !e.y2) {
|
|
364
|
+
y =
|
|
365
|
+
(1 - +e.y(hover.datum)) * viewCoords.height +
|
|
366
|
+
viewCoords.y;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (Math.abs(wheelEvent.deltaX) < Math.abs(wheelEvent.deltaY)) {
|
|
371
|
+
this._handleZoom(coords, {
|
|
372
|
+
x,
|
|
373
|
+
y,
|
|
374
|
+
xDelta: 0,
|
|
375
|
+
yDelta: 0,
|
|
376
|
+
zDelta: (wheelEvent.deltaY * wheelMultiplier) / 300,
|
|
377
|
+
});
|
|
378
|
+
} else {
|
|
379
|
+
this._handleZoom(coords, {
|
|
380
|
+
x,
|
|
381
|
+
y,
|
|
382
|
+
xDelta: -wheelEvent.deltaX * wheelMultiplier,
|
|
383
|
+
yDelta: 0,
|
|
384
|
+
zDelta: 0,
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
} else if (event.type == "mousedown" && event.uiEvent.button === 0) {
|
|
388
|
+
const mouseEvent = /** @type {MouseEvent} */ (event.uiEvent);
|
|
389
|
+
mouseEvent.preventDefault();
|
|
390
|
+
|
|
391
|
+
let prevMouseEvent = mouseEvent;
|
|
392
|
+
|
|
393
|
+
const onMousemove = /** @param {MouseEvent} moveEvent */ (
|
|
394
|
+
moveEvent
|
|
395
|
+
) => {
|
|
396
|
+
this._handleZoom(coords, {
|
|
397
|
+
x: prevMouseEvent.clientX,
|
|
398
|
+
y: prevMouseEvent.clientY,
|
|
399
|
+
xDelta: moveEvent.clientX - prevMouseEvent.clientX,
|
|
400
|
+
yDelta: moveEvent.clientY - prevMouseEvent.clientY,
|
|
401
|
+
zDelta: 0,
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
prevMouseEvent = moveEvent;
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
const onMouseup = /** @param {MouseEvent} upEvent */ (upEvent) => {
|
|
408
|
+
document.removeEventListener("mousemove", onMousemove);
|
|
409
|
+
document.removeEventListener("mouseup", onMouseup);
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
document.addEventListener("mouseup", onMouseup, false);
|
|
413
|
+
document.addEventListener("mousemove", onMousemove, false);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
isZoomable() {
|
|
418
|
+
return this._cache("zoomable", () =>
|
|
419
|
+
Object.values(this._getZoomableResolutions()).some(
|
|
420
|
+
(set) => set.size
|
|
421
|
+
)
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
_getZoomableResolutions() {
|
|
426
|
+
return this._cache("zoomableResolutions", () => {
|
|
427
|
+
/** @type {Record<import("../spec/channel").PositionalChannel, Set<import("./scaleResolution").default>>} */
|
|
428
|
+
const resolutions = {
|
|
429
|
+
x: new Set(),
|
|
430
|
+
y: new Set(),
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
// Find all resolutions (scales) that are candidates for zooming
|
|
434
|
+
this.child.visit((v) => {
|
|
435
|
+
for (const [channel, resolutionSet] of Object.entries(
|
|
436
|
+
resolutions
|
|
437
|
+
)) {
|
|
438
|
+
const resolution = v.getScaleResolution(channel);
|
|
439
|
+
if (resolution && resolution.isZoomable()) {
|
|
440
|
+
resolutionSet.add(resolution);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
return resolutions;
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
*
|
|
451
|
+
* @param {import("../utils/layout/rectangle").default} coords Coordinates
|
|
452
|
+
* @param {ZoomEvent} zoomEvent
|
|
453
|
+
*/
|
|
454
|
+
_handleZoom(coords, zoomEvent) {
|
|
455
|
+
for (const [channel, resolutionSet] of Object.entries(
|
|
456
|
+
this._getZoomableResolutions()
|
|
457
|
+
)) {
|
|
458
|
+
if (resolutionSet.size <= 0) {
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
const extents = this._getAxisExtents();
|
|
463
|
+
const childCoords = coords.shrink(
|
|
464
|
+
extents.add(this._getAxisOffsets())
|
|
465
|
+
);
|
|
466
|
+
|
|
467
|
+
const p = childCoords.normalizePoint(zoomEvent.x, zoomEvent.y);
|
|
468
|
+
const tp = childCoords.normalizePoint(
|
|
469
|
+
zoomEvent.x + zoomEvent.xDelta,
|
|
470
|
+
zoomEvent.y + zoomEvent.yDelta
|
|
471
|
+
);
|
|
472
|
+
|
|
473
|
+
const delta = {
|
|
474
|
+
x: tp.x - p.x,
|
|
475
|
+
y: tp.y - p.y,
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
for (const resolution of resolutionSet) {
|
|
479
|
+
resolution.zoom(
|
|
480
|
+
2 ** zoomEvent.zDelta,
|
|
481
|
+
channel == "y"
|
|
482
|
+
? 1 - p[/** @type {PositionalChannel} */ (channel)]
|
|
483
|
+
: p[/** @type {PositionalChannel} */ (channel)],
|
|
484
|
+
channel == "x" ? delta.x : -delta.y
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
this.context.animator.requestRender();
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* @param {import("../spec/view").ViewConfig} viewConfig
|
|
495
|
+
* @returns {import("../spec/view").UnitSpec}
|
|
496
|
+
*/
|
|
497
|
+
function createBackground(viewConfig) {
|
|
498
|
+
return {
|
|
499
|
+
configurableVisibility: false,
|
|
500
|
+
data: { values: [{}] },
|
|
501
|
+
mark: {
|
|
502
|
+
fill: null,
|
|
503
|
+
strokeWidth: 1.0,
|
|
504
|
+
...viewConfig,
|
|
505
|
+
type: "rect",
|
|
506
|
+
clip: false, // Shouldn't be needed
|
|
507
|
+
tooltip: null,
|
|
508
|
+
},
|
|
509
|
+
};
|
|
510
|
+
}
|