@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.
- package/dist/index.es.js +16379 -0
- package/dist/index.js +43 -43
- package/package.json +10 -7
- package/src/data/collector.js +0 -183
- package/src/data/collector.test.js +0 -84
- package/src/data/dataFlow.js +0 -148
- package/src/data/dataFlow.test.js +0 -5
- package/src/data/facetNode.js +0 -17
- package/src/data/flow.test.js +0 -72
- package/src/data/flowBatch.d.ts +0 -40
- package/src/data/flowNode.js +0 -283
- package/src/data/flowNode.test.js +0 -50
- package/src/data/flowOptimizer.js +0 -123
- package/src/data/flowOptimizer.test.js +0 -193
- package/src/data/flowTestUtils.js +0 -63
- package/src/data/formats/fasta.js +0 -32
- package/src/data/formats/fasta.test.js +0 -27
- package/src/data/sources/dataSource.js +0 -22
- package/src/data/sources/dataSourceFactory.js +0 -24
- package/src/data/sources/dataUtils.js +0 -78
- package/src/data/sources/dynamicCallbackSource.js +0 -57
- package/src/data/sources/dynamicSource.js +0 -37
- package/src/data/sources/inlineSource.js +0 -67
- package/src/data/sources/inlineSource.test.js +0 -56
- package/src/data/sources/namedSource.js +0 -79
- package/src/data/sources/sequenceSource.js +0 -46
- package/src/data/sources/sequenceSource.test.js +0 -46
- package/src/data/sources/urlSource.js +0 -74
- package/src/data/transforms/aggregate.js +0 -70
- package/src/data/transforms/clone.js +0 -40
- package/src/data/transforms/clone.test.js +0 -11
- package/src/data/transforms/coverage.js +0 -187
- package/src/data/transforms/coverage.test.js +0 -123
- package/src/data/transforms/filter.js +0 -37
- package/src/data/transforms/filter.test.js +0 -18
- package/src/data/transforms/filterScoredLabels.js +0 -134
- package/src/data/transforms/flattenCompressedExons.js +0 -57
- package/src/data/transforms/flattenDelimited.js +0 -74
- package/src/data/transforms/flattenDelimited.test.js +0 -87
- package/src/data/transforms/flattenSequence.js +0 -39
- package/src/data/transforms/flattenSequence.test.js +0 -34
- package/src/data/transforms/formula.js +0 -39
- package/src/data/transforms/formula.test.js +0 -19
- package/src/data/transforms/identifier.js +0 -108
- package/src/data/transforms/identifier.test.js +0 -83
- package/src/data/transforms/linearizeGenomicCoordinate.js +0 -101
- package/src/data/transforms/measureText.js +0 -44
- package/src/data/transforms/pileup.js +0 -128
- package/src/data/transforms/pileup.test.js +0 -70
- package/src/data/transforms/project.js +0 -41
- package/src/data/transforms/project.test.js +0 -32
- package/src/data/transforms/regexExtract.js +0 -61
- package/src/data/transforms/regexExtract.test.js +0 -67
- package/src/data/transforms/regexFold.js +0 -141
- package/src/data/transforms/regexFold.test.js +0 -160
- package/src/data/transforms/sample.js +0 -101
- package/src/data/transforms/sample.test.js +0 -38
- package/src/data/transforms/stack.js +0 -137
- package/src/data/transforms/stack.test.js +0 -91
- package/src/data/transforms/transformFactory.js +0 -60
- package/src/embedApi.d.ts +0 -67
- package/src/encoder/accessor.js +0 -82
- package/src/encoder/accessor.test.js +0 -47
- package/src/encoder/encoder.js +0 -394
- package/src/encoder/encoder.test.js +0 -98
- package/src/fonts/Lato-Regular.json +0 -1267
- package/src/fonts/Lato-Regular.png +0 -0
- package/src/fonts/OFL.txt +0 -93
- package/src/fonts/README.md +0 -3
- package/src/fonts/bmFont.d.ts +0 -58
- package/src/fonts/bmFontManager.js +0 -357
- package/src/fonts/bmFontMetrics.js +0 -108
- package/src/genome/genome.js +0 -317
- package/src/genome/genome.test.js +0 -188
- package/src/genome/genomeStore.js +0 -54
- package/src/genome/locusFormat.js +0 -31
- package/src/genome/scaleIndex.d.ts +0 -38
- package/src/genome/scaleIndex.js +0 -166
- package/src/genome/scaleIndex.test.js +0 -78
- package/src/genome/scaleLocus.d.ts +0 -11
- package/src/genome/scaleLocus.js +0 -108
- package/src/genome/scaleLocus.test.js +0 -4
- package/src/genomeSpy.js +0 -785
- package/src/gl/arrayBuilder.js +0 -199
- package/src/gl/dataToVertices.js +0 -636
- package/src/gl/includes/common.glsl +0 -63
- package/src/gl/includes/picking.fragment.glsl +0 -1
- package/src/gl/includes/picking.vertex.glsl +0 -27
- package/src/gl/includes/sampleFacet.glsl +0 -107
- package/src/gl/includes/scales.glsl +0 -112
- package/src/gl/link.fragment.glsl +0 -18
- package/src/gl/link.vertex.glsl +0 -111
- package/src/gl/point.fragment.glsl +0 -123
- package/src/gl/point.vertex.glsl +0 -129
- package/src/gl/rect.fragment.glsl +0 -51
- package/src/gl/rect.vertex.glsl +0 -114
- package/src/gl/rule.fragment.glsl +0 -52
- package/src/gl/rule.vertex.glsl +0 -89
- package/src/gl/text.fragment.glsl +0 -31
- package/src/gl/text.vertex.glsl +0 -246
- package/src/gl/webGLHelper.js +0 -504
- package/src/img/bowtie.svg +0 -1
- package/src/img/genomespy-favicon.svg +0 -34
- package/src/index.html +0 -11
- package/src/index.js +0 -128
- package/src/marks/link.js +0 -175
- package/src/marks/mark.js +0 -975
- package/src/marks/markUtils.js +0 -125
- package/src/marks/pointMark.js +0 -251
- package/src/marks/rectMark.js +0 -241
- package/src/marks/rule.js +0 -250
- package/src/marks/text.js +0 -278
- package/src/node_modules/.vitest/results.json +0 -1
- package/src/scale/colorUtils.js +0 -184
- package/src/scale/glslScaleGenerator.js +0 -502
- package/src/scale/scale.js +0 -451
- package/src/scale/scale.test.js +0 -324
- package/src/scale/ticks.js +0 -203
- package/src/scale/ticks.test.js +0 -40
- package/src/singlePageApp.js +0 -13
- package/src/spec/axis.d.ts +0 -296
- package/src/spec/channel.d.ts +0 -430
- package/src/spec/data.d.ts +0 -196
- package/src/spec/font.d.ts +0 -15
- package/src/spec/genome.d.ts +0 -35
- package/src/spec/mark.d.ts +0 -429
- package/src/spec/root.d.ts +0 -17
- package/src/spec/sampleView.d.ts +0 -180
- package/src/spec/scale.d.ts +0 -273
- package/src/spec/title.d.ts +0 -102
- package/src/spec/tooltip.d.ts +0 -9
- package/src/spec/transform.d.ts +0 -479
- package/src/spec/view.d.ts +0 -201
- package/src/styles/genome-spy.scss +0 -153
- package/src/tooltip/dataTooltipHandler.js +0 -64
- package/src/tooltip/refseqGeneTooltipHandler.js +0 -78
- package/src/tooltip/tooltipHandler.ts +0 -12
- package/src/types/filetypes.d.ts +0 -14
- package/src/types/flatqueue.d.ts +0 -53
- package/src/types/glsl.d.ts +0 -4
- package/src/types/internmap.d.ts +0 -22
- package/src/types/object.d.ts +0 -21
- package/src/types/vega-loader.d.ts +0 -1
- package/src/types/vega-scale.d.ts +0 -60
- package/src/utils/addBaseUrl.js +0 -19
- package/src/utils/addBaseUrl.test.js +0 -22
- package/src/utils/animator.js +0 -83
- package/src/utils/arrayUtils.js +0 -61
- package/src/utils/binnedIndex.js +0 -167
- package/src/utils/binnedIndex.test.js +0 -155
- package/src/utils/clamp.js +0 -8
- package/src/utils/cloner.js +0 -34
- package/src/utils/cloner.test.js +0 -24
- package/src/utils/coalesce.js +0 -11
- package/src/utils/coalesce.test.js +0 -16
- package/src/utils/concatIterables.js +0 -26
- package/src/utils/concatIterables.test.js +0 -8
- package/src/utils/debounce.js +0 -37
- package/src/utils/domainArray.js +0 -216
- package/src/utils/domainArray.test.js +0 -130
- package/src/utils/eerp.js +0 -13
- package/src/utils/expression.js +0 -32
- package/src/utils/field.js +0 -28
- package/src/utils/formatObject.js +0 -31
- package/src/utils/indexer.js +0 -43
- package/src/utils/indexer.test.js +0 -47
- package/src/utils/inertia.js +0 -124
- package/src/utils/interactionEvent.js +0 -33
- package/src/utils/iterateNestedMaps.js +0 -21
- package/src/utils/iterateNestedMaps.test.js +0 -33
- package/src/utils/kWayMerge.js +0 -42
- package/src/utils/kWayMerge.test.js +0 -26
- package/src/utils/layout/flexLayout.js +0 -368
- package/src/utils/layout/flexLayout.test.js +0 -311
- package/src/utils/layout/grid.js +0 -95
- package/src/utils/layout/grid.test.js +0 -71
- package/src/utils/layout/padding.js +0 -120
- package/src/utils/layout/point.js +0 -23
- package/src/utils/layout/rectangle.js +0 -288
- package/src/utils/layout/rectangle.test.js +0 -172
- package/src/utils/mergeObjects.js +0 -99
- package/src/utils/mergeObjects.test.js +0 -42
- package/src/utils/numberExtractor.js +0 -24
- package/src/utils/numberExtractor.test.js +0 -6
- package/src/utils/point.js +0 -14
- package/src/utils/propertyCacher.js +0 -70
- package/src/utils/propertyCacher.test.js +0 -85
- package/src/utils/propertyCoalescer.js +0 -42
- package/src/utils/propertyCoalescer.test.js +0 -22
- package/src/utils/reservationMap.js +0 -103
- package/src/utils/reservationMap.test.js +0 -20
- package/src/utils/scaleNull.js +0 -19
- package/src/utils/setOperations.js +0 -75
- package/src/utils/smoothstep.js +0 -10
- package/src/utils/throttle.js +0 -34
- package/src/utils/topK.js +0 -76
- package/src/utils/topK.test.js +0 -64
- package/src/utils/transition.js +0 -74
- package/src/utils/ui/tooltip.js +0 -189
- package/src/utils/url.js +0 -22
- package/src/utils/variableTools.js +0 -24
- package/src/utils/variableTools.test.js +0 -13
- package/src/view/axisResolution.js +0 -140
- package/src/view/axisResolution.test.js +0 -201
- package/src/view/axisView.js +0 -747
- package/src/view/concatView.js +0 -45
- package/src/view/containerView.js +0 -159
- package/src/view/facetView.js +0 -491
- package/src/view/flowBuilder.js +0 -367
- package/src/view/flowBuilder.test.js +0 -125
- package/src/view/gridView.js +0 -786
- package/src/view/implicitRootView.js +0 -14
- package/src/view/importView.js +0 -19
- package/src/view/layerView.js +0 -74
- package/src/view/rendering.d.ts +0 -44
- package/src/view/renderingContext/compositeViewRenderingContext.js +0 -51
- package/src/view/renderingContext/deferredViewRenderingContext.js +0 -176
- package/src/view/renderingContext/layoutRecorderViewRenderingContext.js +0 -128
- package/src/view/renderingContext/simpleViewRenderingContext.js +0 -64
- package/src/view/renderingContext/svgViewRenderingContext.js +0 -125
- package/src/view/renderingContext/viewRenderingContext.js +0 -41
- package/src/view/scaleResolution.js +0 -797
- package/src/view/scaleResolution.test.js +0 -572
- package/src/view/scaleResolutionApi.d.ts +0 -40
- package/src/view/testUtils.js +0 -51
- package/src/view/title.js +0 -165
- package/src/view/unitView.js +0 -382
- package/src/view/view.js +0 -612
- package/src/view/view.test.js +0 -214
- package/src/view/viewContext.d.ts +0 -62
- package/src/view/viewFactory.js +0 -181
- package/src/view/viewFactory.test.js +0 -17
- package/src/view/viewUtils.js +0 -327
- package/src/view/zoom.js +0 -89
package/src/view/view.test.js
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "vitest";
|
|
2
|
-
import UnitView from "./unitView";
|
|
3
|
-
import LayerView from "./layerView";
|
|
4
|
-
|
|
5
|
-
import { create, createAndInitialize } from "./testUtils";
|
|
6
|
-
import { toRegularArray as r } from "../utils/domainArray";
|
|
7
|
-
import ConcatView from "./concatView";
|
|
8
|
-
import PointMark from "../marks/pointMark";
|
|
9
|
-
import View from "./view";
|
|
10
|
-
|
|
11
|
-
describe("Trivial creations and initializations", () => {
|
|
12
|
-
test("Fails on empty spec", () => {
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
expect(() => create({}, View)).toThrow();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test("Parses a trivial spec", () => {
|
|
18
|
-
expect(create({ mark: "point" }, View)).toBeInstanceOf(UnitView);
|
|
19
|
-
expect(create({ layer: [] }, View)).toBeInstanceOf(LayerView);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test("Parses a more comples spec", () => {
|
|
23
|
-
const view = create(
|
|
24
|
-
{
|
|
25
|
-
concat: [
|
|
26
|
-
{
|
|
27
|
-
layer: [{ mark: "point" }, { mark: "rect" }],
|
|
28
|
-
},
|
|
29
|
-
{ mark: "rect" },
|
|
30
|
-
],
|
|
31
|
-
},
|
|
32
|
-
ConcatView
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
expect(view).toBeInstanceOf(ConcatView);
|
|
36
|
-
expect(view.children[0]).toBeInstanceOf(LayerView);
|
|
37
|
-
expect(view.children[0].children[0]).toBeInstanceOf(UnitView);
|
|
38
|
-
expect(view.children[0].children[0].mark).toBeInstanceOf(PointMark);
|
|
39
|
-
expect(view.children[1]).toBeInstanceOf(UnitView);
|
|
40
|
-
expect(view.children[2]).toBeUndefined();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test("Parses and initializes a trivial spec", () => {
|
|
44
|
-
const spec = {
|
|
45
|
-
data: { values: [1] },
|
|
46
|
-
mark: "point",
|
|
47
|
-
encoding: {
|
|
48
|
-
x: { field: "data", type: "quantitative" },
|
|
49
|
-
y: { field: "data", type: "quantitative" },
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
expect(createAndInitialize(spec, View)).resolves.toBeInstanceOf(
|
|
54
|
-
UnitView
|
|
55
|
-
);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe("Test domain handling", () => {
|
|
60
|
-
const dataSpec = {
|
|
61
|
-
values: [
|
|
62
|
-
{ a: 1, b: 3 },
|
|
63
|
-
{ a: 2, b: 4 },
|
|
64
|
-
{ a: 3, b: 5 },
|
|
65
|
-
],
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
test("Uses domain from the scale properties", () => {
|
|
69
|
-
const spec = {
|
|
70
|
-
data: dataSpec,
|
|
71
|
-
mark: "point",
|
|
72
|
-
encoding: {
|
|
73
|
-
x: { field: "a", type: "quantitative" },
|
|
74
|
-
y: {
|
|
75
|
-
field: "a",
|
|
76
|
-
type: "quantitative",
|
|
77
|
-
scale: { domain: [0, 1000] },
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
return createAndInitialize(spec, UnitView).then((view) =>
|
|
83
|
-
expect(r(view.getConfiguredDomain("y"))).toEqual([0, 1000])
|
|
84
|
-
);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test("Includes a constant in the data domain", () => {
|
|
88
|
-
const spec = {
|
|
89
|
-
data: dataSpec,
|
|
90
|
-
mark: "point",
|
|
91
|
-
encoding: {
|
|
92
|
-
x: { datum: 123, type: "quantitative" },
|
|
93
|
-
y: { field: "a", type: "quantitative" },
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
return createAndInitialize(spec, UnitView).then((view) =>
|
|
98
|
-
expect(r(view.extractDataDomain("x"))).toEqual([123, 123])
|
|
99
|
-
);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
test("Extracts domain from the data", () => {
|
|
103
|
-
const spec = {
|
|
104
|
-
data: dataSpec,
|
|
105
|
-
mark: "point",
|
|
106
|
-
encoding: {
|
|
107
|
-
x: { field: "a", type: "quantitative" },
|
|
108
|
-
y: { field: "a", type: "quantitative" },
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
return createAndInitialize(spec, UnitView).then((view) =>
|
|
113
|
-
expect(r(view.extractDataDomain("y"))).toEqual([1, 3])
|
|
114
|
-
);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
test("Extracts domain from the data when a secondary channel is being used", () => {
|
|
118
|
-
const spec = {
|
|
119
|
-
data: dataSpec,
|
|
120
|
-
mark: "rect",
|
|
121
|
-
encoding: {
|
|
122
|
-
x: { field: "a", type: "quantitative" },
|
|
123
|
-
y: { field: "a", type: "quantitative" },
|
|
124
|
-
y2: { field: "b", type: "quantitative" },
|
|
125
|
-
},
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
return createAndInitialize(spec, UnitView).then((view) =>
|
|
129
|
-
expect(r(view.extractDataDomain("y"))).toEqual([1, 5])
|
|
130
|
-
);
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
describe("Utility methods", () => {
|
|
135
|
-
test("BaseUrl is handled correctly", async () => {
|
|
136
|
-
createAndInitialize(
|
|
137
|
-
{
|
|
138
|
-
layer: [],
|
|
139
|
-
},
|
|
140
|
-
LayerView
|
|
141
|
-
).then((view) => expect(view.getBaseUrl()).toBeUndefined());
|
|
142
|
-
|
|
143
|
-
await createAndInitialize(
|
|
144
|
-
{
|
|
145
|
-
baseUrl: "blaa",
|
|
146
|
-
layer: [],
|
|
147
|
-
},
|
|
148
|
-
LayerView
|
|
149
|
-
).then((view) => expect(view.getBaseUrl()).toEqual("blaa"));
|
|
150
|
-
|
|
151
|
-
await createAndInitialize(
|
|
152
|
-
{
|
|
153
|
-
baseUrl: "https://site.com",
|
|
154
|
-
layer: [],
|
|
155
|
-
},
|
|
156
|
-
LayerView
|
|
157
|
-
).then((view) => expect(view.getBaseUrl()).toEqual("https://site.com"));
|
|
158
|
-
|
|
159
|
-
await createAndInitialize(
|
|
160
|
-
{
|
|
161
|
-
baseUrl: "https://site.com",
|
|
162
|
-
layer: [
|
|
163
|
-
{
|
|
164
|
-
baseUrl: "blaa",
|
|
165
|
-
layer: [],
|
|
166
|
-
},
|
|
167
|
-
],
|
|
168
|
-
},
|
|
169
|
-
LayerView
|
|
170
|
-
).then((view) =>
|
|
171
|
-
expect(view.children[0].getBaseUrl()).toEqual(
|
|
172
|
-
"https://site.com/blaa"
|
|
173
|
-
)
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
await createAndInitialize(
|
|
177
|
-
{
|
|
178
|
-
baseUrl: "https://site.com",
|
|
179
|
-
layer: [
|
|
180
|
-
{
|
|
181
|
-
baseUrl: "https://another-site.com",
|
|
182
|
-
layer: [],
|
|
183
|
-
},
|
|
184
|
-
],
|
|
185
|
-
},
|
|
186
|
-
LayerView
|
|
187
|
-
).then((view) =>
|
|
188
|
-
expect(view.children[0].getBaseUrl()).toEqual(
|
|
189
|
-
"https://another-site.com"
|
|
190
|
-
)
|
|
191
|
-
);
|
|
192
|
-
|
|
193
|
-
await createAndInitialize(
|
|
194
|
-
{
|
|
195
|
-
baseUrl: "https://site.com",
|
|
196
|
-
layer: [
|
|
197
|
-
{
|
|
198
|
-
layer: [
|
|
199
|
-
{
|
|
200
|
-
baseUrl: "blaa",
|
|
201
|
-
layer: [],
|
|
202
|
-
},
|
|
203
|
-
],
|
|
204
|
-
},
|
|
205
|
-
],
|
|
206
|
-
},
|
|
207
|
-
LayerView
|
|
208
|
-
).then((view) =>
|
|
209
|
-
expect(view.children[0].children[0].getBaseUrl()).toEqual(
|
|
210
|
-
"https://site.com/blaa"
|
|
211
|
-
)
|
|
212
|
-
);
|
|
213
|
-
});
|
|
214
|
-
});
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { TemplateResult } from "lit-html";
|
|
2
|
-
import View from "./view";
|
|
3
|
-
import DataFlow from "../data/dataFlow";
|
|
4
|
-
import AccessorFactory from "../encoder/accessor";
|
|
5
|
-
import WebGLHelper from "../gl/webGLHelper";
|
|
6
|
-
import Animator from "../utils/animator";
|
|
7
|
-
import GenomeStore from "../genome/genomeStore";
|
|
8
|
-
import BmFontManager from "../fonts/bmFontManager";
|
|
9
|
-
import Mark from "../marks/mark";
|
|
10
|
-
import { Datum } from "../data/flowNode";
|
|
11
|
-
import { ViewSpec } from "../spec/view";
|
|
12
|
-
import ContainerView from "./containerView";
|
|
13
|
-
|
|
14
|
-
export interface Hover {
|
|
15
|
-
mark: Mark;
|
|
16
|
-
datum: Datum;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* ViewContext provides essential data and interfaces to View classes.
|
|
21
|
-
*/
|
|
22
|
-
export default interface ViewContext {
|
|
23
|
-
dataFlow: DataFlow<View>;
|
|
24
|
-
accessorFactory: AccessorFactory;
|
|
25
|
-
glHelper: WebGLHelper;
|
|
26
|
-
animator: Animator;
|
|
27
|
-
genomeStore?: GenomeStore;
|
|
28
|
-
fontManager: BmFontManager;
|
|
29
|
-
|
|
30
|
-
requestLayoutReflow: () => void;
|
|
31
|
-
|
|
32
|
-
updateTooltip: <T>(
|
|
33
|
-
datum: T,
|
|
34
|
-
converter?: (datum: T) => Promise<TemplateResult>
|
|
35
|
-
) => void;
|
|
36
|
-
|
|
37
|
-
getCurrentHover: () => Hover;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Adds a keyboard event listener to the document. Cleanup is performed automatically
|
|
41
|
-
* when GenomeSpy is finalized.
|
|
42
|
-
*
|
|
43
|
-
* TODO: Listeners should be called only when the mouse pointer is inside the
|
|
44
|
-
* container or the app covers the full document.
|
|
45
|
-
*/
|
|
46
|
-
addKeyboardListener: (
|
|
47
|
-
type: "keydown" | "keyup",
|
|
48
|
-
listener: (event: KeyboardEvent) => void
|
|
49
|
-
) => void;
|
|
50
|
-
|
|
51
|
-
getNamedDataFromProvider: (name: string) => any[];
|
|
52
|
-
|
|
53
|
-
isViewVisible: (view: View) => boolean;
|
|
54
|
-
|
|
55
|
-
isViewSpec: (spec: any) => boolean;
|
|
56
|
-
|
|
57
|
-
createView: (
|
|
58
|
-
spec: ViewSpec,
|
|
59
|
-
parent?: ContainerView,
|
|
60
|
-
defaultName?: string
|
|
61
|
-
) => View;
|
|
62
|
-
}
|
package/src/view/viewFactory.js
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line no-unused-vars
|
|
2
|
-
import View from "./view";
|
|
3
|
-
|
|
4
|
-
import UnitView from "./unitView";
|
|
5
|
-
import ImportView from "./importView";
|
|
6
|
-
import LayerView from "./layerView";
|
|
7
|
-
import ConcatView from "./concatView";
|
|
8
|
-
import { isArray, isObject, isString } from "vega-util";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @typedef {import("./viewContext").default} ViewContext
|
|
12
|
-
* @typedef {import("../spec/view").UnitSpec} UnitSpec
|
|
13
|
-
* @typedef {import("../spec/view").ViewSpec} ViewSpec
|
|
14
|
-
* @typedef {import("../spec/view").LayerSpec} LayerSpec
|
|
15
|
-
* @typedef {import("../spec/view").ImportSpec} ImportSpec
|
|
16
|
-
* @typedef {import("../spec/view").SampleSpec} SampleSpec
|
|
17
|
-
* @typedef {import("../spec/view").VConcatSpec} VConcatSpec
|
|
18
|
-
* @typedef {import("../spec/view").HConcatSpec} HConcatSpec
|
|
19
|
-
* @typedef {import("../spec/view").ConcatSpec} ConcatSpec
|
|
20
|
-
* @typedef {VConcatSpec | HConcatSpec | ConcatSpec} AnyConcatSpec
|
|
21
|
-
*
|
|
22
|
-
* @typedef {(spec: ViewSpec) => boolean} specGuard
|
|
23
|
-
* @typedef {(spec: ViewSpec, context: ViewContext, parent?: import("./containerView").default, defaultName?: string) => View} factory
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
export class ViewFactory {
|
|
27
|
-
constructor() {
|
|
28
|
-
/** @type {{specGuard: specGuard, factory: factory}[]} */
|
|
29
|
-
this.types = [];
|
|
30
|
-
|
|
31
|
-
const makeDefaultFactory =
|
|
32
|
-
(/** @type {typeof View} */ ViewClass) =>
|
|
33
|
-
/** @type {factory} */
|
|
34
|
-
(spec, context, parent, defaultName) =>
|
|
35
|
-
/** @type {View} */ (
|
|
36
|
-
new ViewClass(
|
|
37
|
-
spec,
|
|
38
|
-
context,
|
|
39
|
-
parent,
|
|
40
|
-
spec.name ?? defaultName
|
|
41
|
-
)
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
this.addViewType(isImportSpec, makeDefaultFactory(ImportView));
|
|
45
|
-
this.addViewType(isLayerSpec, makeDefaultFactory(LayerView));
|
|
46
|
-
this.addViewType(isUnitSpec, makeDefaultFactory(UnitView));
|
|
47
|
-
this.addViewType(isVConcatSpec, makeDefaultFactory(ConcatView));
|
|
48
|
-
this.addViewType(isHConcatSpec, makeDefaultFactory(ConcatView));
|
|
49
|
-
this.addViewType(isConcatSpec, makeDefaultFactory(ConcatView));
|
|
50
|
-
//this.addViewType(isFacetSpec, makeDefaultFactory(FacetView));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* @param {specGuard} specGuard
|
|
55
|
-
* @param {factory} factory
|
|
56
|
-
*/
|
|
57
|
-
addViewType(specGuard, factory) {
|
|
58
|
-
this.types.push({ specGuard, factory });
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* @param {ViewSpec} spec
|
|
63
|
-
* @param {ViewContext} context
|
|
64
|
-
* @param {import("./containerView").default} [parent]
|
|
65
|
-
* @param {string} [defaultName]
|
|
66
|
-
*/
|
|
67
|
-
createView(spec, context, parent, defaultName) {
|
|
68
|
-
const type = this.types.find((type) => type.specGuard(spec));
|
|
69
|
-
if (type) {
|
|
70
|
-
return type.factory(
|
|
71
|
-
spec,
|
|
72
|
-
context,
|
|
73
|
-
parent,
|
|
74
|
-
defaultName ?? "unnamed"
|
|
75
|
-
);
|
|
76
|
-
} else {
|
|
77
|
-
throw new Error(
|
|
78
|
-
"Invalid spec, cannot figure out the view type from the properties: " +
|
|
79
|
-
JSON.stringify([...Object.keys(spec)])
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
*
|
|
86
|
-
* @param {ViewSpec} spec
|
|
87
|
-
* @returns {spec is ViewSpec}
|
|
88
|
-
*/
|
|
89
|
-
isViewSpec(spec) {
|
|
90
|
-
const matches = this.types.filter((type) => type.specGuard(spec));
|
|
91
|
-
|
|
92
|
-
if (matches.length > 1) {
|
|
93
|
-
throw new Error("Ambiguous spec. Cannot create a view!");
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return matches.length == 1;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
*
|
|
102
|
-
* @param {ViewSpec} spec
|
|
103
|
-
* @returns {spec is UnitSpec}
|
|
104
|
-
*/
|
|
105
|
-
export function isUnitSpec(spec) {
|
|
106
|
-
return "mark" in spec && (isString(spec.mark) || isObject(spec.mark));
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
*
|
|
111
|
-
* @param {ViewSpec} spec
|
|
112
|
-
* @returns {spec is LayerSpec}
|
|
113
|
-
*/
|
|
114
|
-
export function isLayerSpec(spec) {
|
|
115
|
-
return "layer" in spec && isObject(spec.layer);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
*
|
|
120
|
-
* @param {ViewSpec} spec
|
|
121
|
-
* @returns {spec is LayerSpec}
|
|
122
|
-
*/
|
|
123
|
-
export function isFacetSpec(spec) {
|
|
124
|
-
return (
|
|
125
|
-
"facet" in spec &&
|
|
126
|
-
// @ts-expect-error
|
|
127
|
-
isObject(spec.facet) &&
|
|
128
|
-
"spec" in spec &&
|
|
129
|
-
// @ts-expect-error
|
|
130
|
-
isObject(spec.spec)
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
*
|
|
136
|
-
* @param {ViewSpec} spec
|
|
137
|
-
* @returns {spec is import("../spec/view").AggregateSamplesSpec}
|
|
138
|
-
*/
|
|
139
|
-
export function isAggregateSamplesSpec(spec) {
|
|
140
|
-
return (
|
|
141
|
-
spec &&
|
|
142
|
-
(isUnitSpec(spec) || isLayerSpec(spec)) &&
|
|
143
|
-
"aggregateSamples" in spec
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
*
|
|
149
|
-
* @param {object} spec
|
|
150
|
-
* @returns {spec is ImportSpec}
|
|
151
|
-
*/
|
|
152
|
-
export function isImportSpec(spec) {
|
|
153
|
-
return "import" in spec;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
*
|
|
158
|
-
* @param {ViewSpec} spec
|
|
159
|
-
* @returns {spec is VConcatSpec}
|
|
160
|
-
*/
|
|
161
|
-
export function isVConcatSpec(spec) {
|
|
162
|
-
return "vconcat" in spec && isArray(spec.vconcat);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
*
|
|
167
|
-
* @param {ViewSpec} spec
|
|
168
|
-
* @returns {spec is HConcatSpec}
|
|
169
|
-
*/
|
|
170
|
-
export function isHConcatSpec(spec) {
|
|
171
|
-
return "hconcat" in spec && isArray(spec.hconcat);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
*
|
|
176
|
-
* @param {ViewSpec} spec
|
|
177
|
-
* @returns {spec is ConcatSpec}
|
|
178
|
-
*/
|
|
179
|
-
export function isConcatSpec(spec) {
|
|
180
|
-
return "concat" in spec && isArray(spec.concat);
|
|
181
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "vitest";
|
|
2
|
-
import { ViewFactory } from "./viewFactory";
|
|
3
|
-
|
|
4
|
-
test("isViewSpec", () => {
|
|
5
|
-
const factory = new ViewFactory();
|
|
6
|
-
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
expect(factory.isViewSpec({})).toBeFalsy();
|
|
9
|
-
|
|
10
|
-
expect(factory.isViewSpec({ mark: "rect" })).toBeTruthy();
|
|
11
|
-
expect(factory.isViewSpec({ layer: [] })).toBeTruthy();
|
|
12
|
-
expect(factory.isViewSpec({ hconcat: [] })).toBeTruthy();
|
|
13
|
-
expect(factory.isViewSpec({ vconcat: [] })).toBeTruthy();
|
|
14
|
-
expect(factory.isViewSpec({ concat: [] })).toBeTruthy();
|
|
15
|
-
|
|
16
|
-
expect(() => factory.isViewSpec({ mark: "rect", layer: [] })).toThrow();
|
|
17
|
-
});
|