@genome-spy/core 0.29.0 → 0.30.2
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 +16373 -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 -784
- 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 -489
- 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 -488
- 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 -791
- 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
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
mapToPixelCoords,
|
|
4
|
-
getMinimumSize,
|
|
5
|
-
getLargestSize,
|
|
6
|
-
isStretching,
|
|
7
|
-
parseSizeDef,
|
|
8
|
-
} from "./flexLayout";
|
|
9
|
-
|
|
10
|
-
test("parseSize", () => {
|
|
11
|
-
expect(parseSizeDef(10)).toEqual({ px: 10, grow: 0 });
|
|
12
|
-
expect(parseSizeDef({ px: 20, grow: 2 })).toEqual({ px: 20, grow: 2 });
|
|
13
|
-
expect(parseSizeDef(undefined)).toEqual({ px: 0, grow: 1 });
|
|
14
|
-
expect(parseSizeDef(null)).toEqual({ px: 0, grow: 1 });
|
|
15
|
-
expect(parseSizeDef("container")).toEqual({ px: 0, grow: 1 });
|
|
16
|
-
expect(() => parseSizeDef({})).toThrow();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
describe("Basic flex functionality", () => {
|
|
20
|
-
test("Absolute sizes", () => {
|
|
21
|
-
const items = [10, 30, 20].map((x) => ({ px: x }));
|
|
22
|
-
const containerSize = 100;
|
|
23
|
-
|
|
24
|
-
const mapped = mapToPixelCoords(items, containerSize);
|
|
25
|
-
|
|
26
|
-
expect(mapped[0]).toEqual({ location: 0, size: 10 });
|
|
27
|
-
expect(mapped[1]).toEqual({ location: 10, size: 30 });
|
|
28
|
-
expect(mapped[2]).toEqual({ location: 40, size: 20 });
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test("Absolute sizes with spacing", () => {
|
|
32
|
-
const items = [10, 30, 20].map((x) => ({ px: x }));
|
|
33
|
-
const containerSize = 100;
|
|
34
|
-
|
|
35
|
-
const mapped = mapToPixelCoords(items, containerSize, { spacing: 10 });
|
|
36
|
-
|
|
37
|
-
expect(mapped[0]).toEqual({ location: 0, size: 10 });
|
|
38
|
-
expect(mapped[1]).toEqual({ location: 20, size: 30 });
|
|
39
|
-
expect(mapped[2]).toEqual({ location: 60, size: 20 });
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test("Absolute sizes with spacing, reversed", () => {
|
|
43
|
-
const items = [10, 30, 20].map((x) => ({ px: x }));
|
|
44
|
-
const containerSize = 100;
|
|
45
|
-
|
|
46
|
-
const mapped = mapToPixelCoords(items, containerSize, {
|
|
47
|
-
spacing: 10,
|
|
48
|
-
reverse: true,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
expect(mapped[0]).toEqual({ location: 90, size: 10 });
|
|
52
|
-
expect(mapped[1]).toEqual({ location: 50, size: 30 });
|
|
53
|
-
expect(mapped[2]).toEqual({ location: 20, size: 20 });
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test("Absolute sizes with spacing, reversed and insufficient containerSize", () => {
|
|
57
|
-
const items = [10, 30, 20].map((x) => ({ px: x }));
|
|
58
|
-
const containerSize = 0;
|
|
59
|
-
|
|
60
|
-
const mapped = mapToPixelCoords(items, containerSize, {
|
|
61
|
-
spacing: 10,
|
|
62
|
-
reverse: true,
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
expect(mapped[0]).toEqual({ location: 70, size: 10 });
|
|
66
|
-
expect(mapped[1]).toEqual({ location: 30, size: 30 });
|
|
67
|
-
expect(mapped[2]).toEqual({ location: 0, size: 20 });
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test("Growing sizes", () => {
|
|
71
|
-
const items = [10, 20, 70].map((x) => ({ grow: x }));
|
|
72
|
-
const containerSize = 200;
|
|
73
|
-
|
|
74
|
-
const mapped = mapToPixelCoords(items, containerSize);
|
|
75
|
-
|
|
76
|
-
expect(mapped[0]).toEqual({ location: 0, size: 20 });
|
|
77
|
-
expect(mapped[1]).toEqual({ location: 20, size: 40 });
|
|
78
|
-
expect(mapped[2]).toEqual({ location: 60, size: 140 });
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test("Growing sizes with spacing", () => {
|
|
82
|
-
const items = [10, 20, 70].map((x) => ({ grow: x }));
|
|
83
|
-
const containerSize = 220;
|
|
84
|
-
const mapped = mapToPixelCoords(items, containerSize, { spacing: 10 });
|
|
85
|
-
|
|
86
|
-
expect(mapped[0]).toEqual({ location: 0, size: 20 });
|
|
87
|
-
expect(mapped[1]).toEqual({ location: 30, size: 40 });
|
|
88
|
-
expect(mapped[2]).toEqual({ location: 80, size: 140 });
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
test("Mixed absolute and relative sizes", () => {
|
|
92
|
-
const items = [{ px: 100 }, { grow: 1 }, { grow: 9 }, { px: 200 }];
|
|
93
|
-
const containerSize = 1100;
|
|
94
|
-
const mapped = mapToPixelCoords(items, containerSize);
|
|
95
|
-
|
|
96
|
-
expect(mapped[0]).toEqual({ location: 0, size: 100 });
|
|
97
|
-
expect(mapped[1]).toEqual({ location: 100, size: 80 });
|
|
98
|
-
expect(mapped[2]).toEqual({ location: 180, size: 720 });
|
|
99
|
-
expect(mapped[3]).toEqual({ location: 900, size: 200 });
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
test("Sizes having both absolute and growing components", () => {
|
|
103
|
-
const items = [
|
|
104
|
-
{ px: 1 },
|
|
105
|
-
{ px: 2 },
|
|
106
|
-
{ px: 3, grow: 2 },
|
|
107
|
-
{ px: 4, grow: 1 },
|
|
108
|
-
];
|
|
109
|
-
const containerSize = 16;
|
|
110
|
-
const mapped = mapToPixelCoords(items, containerSize);
|
|
111
|
-
|
|
112
|
-
expect(mapped[0]).toEqual({ location: 0, size: 1 });
|
|
113
|
-
expect(mapped[1]).toEqual({ location: 1, size: 2 });
|
|
114
|
-
expect(mapped[2]).toEqual({ location: 3, size: 7 });
|
|
115
|
-
expect(mapped[3]).toEqual({ location: 10, size: 6 });
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
test("Zero sizes return zero coords", () => {
|
|
119
|
-
const items = [{ grow: 0 }, { grow: 0 }];
|
|
120
|
-
|
|
121
|
-
const mapped = mapToPixelCoords(items, 0);
|
|
122
|
-
expect(mapped[0]).toEqual({ location: 0, size: 0 });
|
|
123
|
-
expect(mapped[1]).toEqual({ location: 0, size: 0 });
|
|
124
|
-
|
|
125
|
-
const mapped2 = mapToPixelCoords(items, 1);
|
|
126
|
-
expect(mapped2[0]).toEqual({ location: 0, size: 0 });
|
|
127
|
-
expect(mapped2[1]).toEqual({ location: 0, size: 0 });
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
test("Offset is added", () => {
|
|
131
|
-
const items = [10, 30, 20].map((x) => ({ px: x }));
|
|
132
|
-
const containerSize = 100;
|
|
133
|
-
|
|
134
|
-
const mapped = mapToPixelCoords(items, containerSize, { offset: 5 });
|
|
135
|
-
|
|
136
|
-
expect(mapped[0]).toEqual({ location: 5, size: 10 });
|
|
137
|
-
expect(mapped[1]).toEqual({ location: 15, size: 30 });
|
|
138
|
-
expect(mapped[2]).toEqual({ location: 45, size: 20 });
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
describe("Collapse gaps when items have zero px and grow", () => {
|
|
143
|
-
test("Zero as first", () => {
|
|
144
|
-
const items = [0, 30, 20].map((x) => ({ px: x }));
|
|
145
|
-
const containerSize = 100;
|
|
146
|
-
|
|
147
|
-
const mapped = mapToPixelCoords(items, containerSize, { spacing: 10 });
|
|
148
|
-
|
|
149
|
-
expect(mapped[0]).toEqual({ location: 0, size: 0 });
|
|
150
|
-
expect(mapped[1]).toEqual({ location: 0, size: 30 });
|
|
151
|
-
expect(mapped[2]).toEqual({ location: 40, size: 20 });
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
test("Zero in the middle", () => {
|
|
155
|
-
const items = [10, 0, 20].map((x) => ({ px: x }));
|
|
156
|
-
const containerSize = 100;
|
|
157
|
-
|
|
158
|
-
const mapped = mapToPixelCoords(items, containerSize, { spacing: 10 });
|
|
159
|
-
|
|
160
|
-
expect(mapped[0]).toEqual({ location: 0, size: 10 });
|
|
161
|
-
expect(mapped[1]).toEqual({ location: 15, size: 0 });
|
|
162
|
-
expect(mapped[2]).toEqual({ location: 20, size: 20 });
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
test("Multiple zeroes in the middle", () => {
|
|
166
|
-
const items = [10, 0, 0, 0, 20].map((x) => ({ px: x }));
|
|
167
|
-
const containerSize = 100;
|
|
168
|
-
|
|
169
|
-
const mapped = mapToPixelCoords(items, containerSize, { spacing: 10 });
|
|
170
|
-
|
|
171
|
-
expect(mapped[0]).toEqual({ location: 0, size: 10 });
|
|
172
|
-
expect(mapped[1]).toEqual({ location: 12.5, size: 0 });
|
|
173
|
-
expect(mapped[2]).toEqual({ location: 15, size: 0 });
|
|
174
|
-
expect(mapped[3]).toEqual({ location: 17.5, size: 0 });
|
|
175
|
-
expect(mapped[4]).toEqual({ location: 20, size: 20 });
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
test("Zero as last", () => {
|
|
179
|
-
const items = [10, 30, 0].map((x) => ({ px: x }));
|
|
180
|
-
const containerSize = 100;
|
|
181
|
-
|
|
182
|
-
const mapped = mapToPixelCoords(items, containerSize, { spacing: 10 });
|
|
183
|
-
|
|
184
|
-
expect(mapped[0]).toEqual({ location: 0, size: 10 });
|
|
185
|
-
expect(mapped[1]).toEqual({ location: 20, size: 30 });
|
|
186
|
-
expect(mapped[2]).toEqual({ location: 50, size: 0 });
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
test("Only a zero", () => {
|
|
190
|
-
const items = [0].map((x) => ({ px: x }));
|
|
191
|
-
const containerSize = 100;
|
|
192
|
-
|
|
193
|
-
const mapped = mapToPixelCoords(items, containerSize, { spacing: 10 });
|
|
194
|
-
|
|
195
|
-
expect(mapped[0]).toEqual({ location: 0, size: 0 });
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
describe("Collapse gaps when items have zero px and grow, reversed", () => {
|
|
200
|
-
test("Zero as first", () => {
|
|
201
|
-
const items = [0, 30, 20].map((x) => ({ px: x }));
|
|
202
|
-
const containerSize = 100;
|
|
203
|
-
|
|
204
|
-
const mapped = mapToPixelCoords(items, containerSize, {
|
|
205
|
-
spacing: 10,
|
|
206
|
-
reverse: true,
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
expect(mapped[0]).toEqual({ location: 100, size: 0 });
|
|
210
|
-
expect(mapped[1]).toEqual({ location: 70, size: 30 });
|
|
211
|
-
expect(mapped[2]).toEqual({ location: 40, size: 20 });
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
test("Zero in the middle", () => {
|
|
215
|
-
const items = [10, 0, 20].map((x) => ({ px: x }));
|
|
216
|
-
const containerSize = 100;
|
|
217
|
-
|
|
218
|
-
const mapped = mapToPixelCoords(items, containerSize, {
|
|
219
|
-
spacing: 10,
|
|
220
|
-
reverse: true,
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
expect(mapped[0]).toEqual({ location: 90, size: 10 });
|
|
224
|
-
expect(mapped[1]).toEqual({ location: 85, size: 0 });
|
|
225
|
-
expect(mapped[2]).toEqual({ location: 60, size: 20 });
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
test("Multiple zeroes in the middle", () => {
|
|
229
|
-
const items = [10, 0, 0, 0, 20].map((x) => ({ px: x }));
|
|
230
|
-
const containerSize = 100;
|
|
231
|
-
|
|
232
|
-
const mapped = mapToPixelCoords(items, containerSize, {
|
|
233
|
-
spacing: 10,
|
|
234
|
-
reverse: true,
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
expect(mapped[0]).toEqual({ location: 90, size: 10 });
|
|
238
|
-
expect(mapped[1]).toEqual({ location: 87.5, size: 0 });
|
|
239
|
-
expect(mapped[2]).toEqual({ location: 85, size: 0 });
|
|
240
|
-
expect(mapped[3]).toEqual({ location: 82.5, size: 0 });
|
|
241
|
-
expect(mapped[4]).toEqual({ location: 60, size: 20 });
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
test("Zero as last", () => {
|
|
245
|
-
const items = [10, 30, 0].map((x) => ({ px: x }));
|
|
246
|
-
const containerSize = 100;
|
|
247
|
-
|
|
248
|
-
const mapped = mapToPixelCoords(items, containerSize, {
|
|
249
|
-
spacing: 10,
|
|
250
|
-
reverse: true,
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
expect(mapped[0]).toEqual({ location: 90, size: 10 });
|
|
254
|
-
expect(mapped[1]).toEqual({ location: 50, size: 30 });
|
|
255
|
-
expect(mapped[2]).toEqual({ location: 50, size: 0 });
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
test("Only a zero", () => {
|
|
259
|
-
const items = [0].map((x) => ({ px: x }));
|
|
260
|
-
const containerSize = 100;
|
|
261
|
-
|
|
262
|
-
const mapped = mapToPixelCoords(items, containerSize, {
|
|
263
|
-
spacing: 10,
|
|
264
|
-
reverse: true,
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
expect(mapped[0]).toEqual({ location: 100, size: 0 });
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
describe("Utility fuctions", () => {
|
|
272
|
-
test("getMinimumSize", () => {
|
|
273
|
-
const items = [{ px: 100 }, { grow: 1 }, { grow: 9 }, { px: 200 }];
|
|
274
|
-
|
|
275
|
-
expect(getMinimumSize(items)).toEqual(300);
|
|
276
|
-
|
|
277
|
-
expect(getMinimumSize(items, { spacing: 10 })).toEqual(330);
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
test("getMinimumSize, items include zeroes", () => {
|
|
281
|
-
const items = [
|
|
282
|
-
{ px: 100 },
|
|
283
|
-
{ px: 0, grow: 0 },
|
|
284
|
-
{ grow: 1 },
|
|
285
|
-
{ grow: 9 },
|
|
286
|
-
{ px: 200 },
|
|
287
|
-
];
|
|
288
|
-
|
|
289
|
-
expect(getMinimumSize(items)).toEqual(300);
|
|
290
|
-
|
|
291
|
-
expect(getMinimumSize(items, { spacing: 10 })).toEqual(330);
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
test("getLargestSize", () => {
|
|
295
|
-
const items = [
|
|
296
|
-
{ px: 100 },
|
|
297
|
-
{ px: 0, grow: 0 },
|
|
298
|
-
{ grow: 1 },
|
|
299
|
-
{ grow: 9 },
|
|
300
|
-
{ px: 200 },
|
|
301
|
-
{ px: 50 },
|
|
302
|
-
];
|
|
303
|
-
|
|
304
|
-
expect(getLargestSize(items)).toEqual({ px: 200, grow: 9 });
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
test("isStretching", () => {
|
|
308
|
-
expect(isStretching([{ grow: 1 }])).toBeTruthy();
|
|
309
|
-
expect(isStretching([{ px: 1 }])).toBeFalsy();
|
|
310
|
-
});
|
|
311
|
-
});
|
package/src/utils/layout/grid.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* An utility class for indexing cells in a wrapping grid layout
|
|
3
|
-
*/
|
|
4
|
-
export default class Grid {
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* @param {number} nChildren
|
|
8
|
-
* @param {number} [maxCols]
|
|
9
|
-
*/
|
|
10
|
-
constructor(nChildren, maxCols) {
|
|
11
|
-
this.n = nChildren;
|
|
12
|
-
this.maxCols = maxCols ?? Infinity;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
get nRows() {
|
|
16
|
-
return this.maxCols == Infinity ? 1 : Math.ceil(this.n / this.maxCols);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
get nCols() {
|
|
20
|
-
return Math.min(this.n, this.maxCols);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
get rowIndices() {
|
|
24
|
-
/** @type {number[][]} */
|
|
25
|
-
const rows = [];
|
|
26
|
-
|
|
27
|
-
const nCols = this.nCols;
|
|
28
|
-
const nRows = this.nRows;
|
|
29
|
-
|
|
30
|
-
for (let row = 0; row < nRows; row++) {
|
|
31
|
-
/** @type {number[]} */
|
|
32
|
-
const arr = [];
|
|
33
|
-
rows.push(arr);
|
|
34
|
-
for (let col = 0; col < nCols; col++) {
|
|
35
|
-
const i = row * nCols + col;
|
|
36
|
-
if (i < this.n) {
|
|
37
|
-
arr.push(i);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return rows;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
get colIndices() {
|
|
45
|
-
/** @type {number[][]} */
|
|
46
|
-
const cols = [];
|
|
47
|
-
|
|
48
|
-
const nCols = this.nCols;
|
|
49
|
-
const nRows = this.nRows;
|
|
50
|
-
|
|
51
|
-
for (let col = 0; col < nCols; col++) {
|
|
52
|
-
/** @type {number[]} */
|
|
53
|
-
const arr = [];
|
|
54
|
-
cols.push(arr);
|
|
55
|
-
for (let row = 0; row < nRows; row++) {
|
|
56
|
-
const i = row * nCols + col;
|
|
57
|
-
if (i < this.n) {
|
|
58
|
-
arr.push(i);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return cols;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* @param {number} col
|
|
67
|
-
* @param {number} row
|
|
68
|
-
*/
|
|
69
|
-
getCellIndex(col, row) {
|
|
70
|
-
let i = 0;
|
|
71
|
-
|
|
72
|
-
if (this.maxCols == Infinity) {
|
|
73
|
-
i = row == 0 ? col : undefined;
|
|
74
|
-
} else if (col >= this.maxCols) {
|
|
75
|
-
return undefined;
|
|
76
|
-
} else {
|
|
77
|
-
i = row * this.nCols + col;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return i < this.n ? i : undefined;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
*
|
|
85
|
-
* @param {number} index
|
|
86
|
-
* @returns {[number, number]}
|
|
87
|
-
*/
|
|
88
|
-
getCellCoords(index) {
|
|
89
|
-
if (index < 0 || index >= this.n) {
|
|
90
|
-
return undefined;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return [index % this.nCols, Math.floor(index / this.nCols)];
|
|
94
|
-
}
|
|
95
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { expect, test, describe } from "vitest";
|
|
2
|
-
|
|
3
|
-
import Grid from "./grid";
|
|
4
|
-
|
|
5
|
-
describe("Grid indexing", () => {
|
|
6
|
-
test("Single row", () => {
|
|
7
|
-
const g = new Grid(3);
|
|
8
|
-
|
|
9
|
-
expect(g.maxCols).toEqual(Infinity);
|
|
10
|
-
expect(g.nCols).toEqual(3);
|
|
11
|
-
expect(g.nRows).toEqual(1);
|
|
12
|
-
expect(g.colIndices).toEqual([[0], [1], [2]]);
|
|
13
|
-
expect(g.rowIndices).toEqual([[0, 1, 2]]);
|
|
14
|
-
expect(g.getCellIndex(1, 0)).toEqual(1);
|
|
15
|
-
expect(g.getCellIndex(1, 1)).toBeUndefined();
|
|
16
|
-
expect(g.getCellCoords(1)).toEqual([1, 0]);
|
|
17
|
-
expect(g.getCellCoords(-1)).toBeUndefined();
|
|
18
|
-
expect(g.getCellCoords(3)).toBeUndefined();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test("Single column", () => {
|
|
22
|
-
const g = new Grid(3, 1);
|
|
23
|
-
|
|
24
|
-
expect(g.maxCols).toEqual(1);
|
|
25
|
-
expect(g.nCols).toEqual(1);
|
|
26
|
-
expect(g.nRows).toEqual(3);
|
|
27
|
-
expect(g.colIndices).toEqual([[0, 1, 2]]);
|
|
28
|
-
expect(g.rowIndices).toEqual([[0], [1], [2]]);
|
|
29
|
-
expect(g.getCellIndex(0, 1)).toEqual(1);
|
|
30
|
-
expect(g.getCellIndex(1, 1)).toBeUndefined();
|
|
31
|
-
expect(g.getCellCoords(1)).toEqual([0, 1]);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test("Two columns", () => {
|
|
35
|
-
const g = new Grid(6, 2);
|
|
36
|
-
|
|
37
|
-
expect(g.maxCols).toEqual(2);
|
|
38
|
-
expect(g.nCols).toEqual(2);
|
|
39
|
-
expect(g.nRows).toEqual(3);
|
|
40
|
-
expect(g.colIndices).toEqual([
|
|
41
|
-
[0, 2, 4],
|
|
42
|
-
[1, 3, 5],
|
|
43
|
-
]);
|
|
44
|
-
expect(g.rowIndices).toEqual([
|
|
45
|
-
[0, 1],
|
|
46
|
-
[2, 3],
|
|
47
|
-
[4, 5],
|
|
48
|
-
]);
|
|
49
|
-
expect(g.getCellIndex(1, 0)).toEqual(1);
|
|
50
|
-
expect(g.getCellIndex(0, 1)).toEqual(2);
|
|
51
|
-
expect(g.getCellIndex(1, 1)).toEqual(3);
|
|
52
|
-
expect(g.getCellCoords(3)).toEqual([1, 1]);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test("Two columns, second is partial", () => {
|
|
56
|
-
const g = new Grid(5, 2);
|
|
57
|
-
|
|
58
|
-
expect(g.maxCols).toEqual(2);
|
|
59
|
-
expect(g.nCols).toEqual(2);
|
|
60
|
-
expect(g.nRows).toEqual(3);
|
|
61
|
-
expect(g.colIndices).toEqual([
|
|
62
|
-
[0, 2, 4],
|
|
63
|
-
[1, 3],
|
|
64
|
-
]);
|
|
65
|
-
expect(g.rowIndices).toEqual([[0, 1], [2, 3], [4]]);
|
|
66
|
-
expect(g.getCellIndex(1, 0)).toEqual(1);
|
|
67
|
-
expect(g.getCellIndex(0, 1)).toEqual(2);
|
|
68
|
-
expect(g.getCellIndex(1, 2)).toBeUndefined();
|
|
69
|
-
expect(g.getCellCoords(3)).toEqual([1, 1]);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A class for handing paddings, borders, margins, etc.
|
|
3
|
-
*
|
|
4
|
-
* @typedef {import("../../spec/view").Paddings} Paddings
|
|
5
|
-
* @typedef {import("../../spec/view").PaddingConfig} PaddingConfig
|
|
6
|
-
*/
|
|
7
|
-
export default class Padding {
|
|
8
|
-
/**
|
|
9
|
-
* @param {number} top
|
|
10
|
-
* @param {number} right
|
|
11
|
-
* @param {number} bottom
|
|
12
|
-
* @param {number} left
|
|
13
|
-
*/
|
|
14
|
-
constructor(top, right, bottom, left) {
|
|
15
|
-
/** @readonly */ this.top = top || 0;
|
|
16
|
-
/** @readonly */ this.right = right || 0;
|
|
17
|
-
/** @readonly */ this.bottom = bottom || 0;
|
|
18
|
-
/** @readonly */ this.left = left || 0;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Returns the sum of left and right
|
|
23
|
-
*/
|
|
24
|
-
get width() {
|
|
25
|
-
return this.left + this.right;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Returns the sum of top and bottom
|
|
30
|
-
*/
|
|
31
|
-
get height() {
|
|
32
|
-
return this.top + this.bottom;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @param {number} amount In pixels
|
|
37
|
-
*/
|
|
38
|
-
expand(amount) {
|
|
39
|
-
if (amount <= 0) {
|
|
40
|
-
return this;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return new Padding(
|
|
44
|
-
this.top + amount,
|
|
45
|
-
this.right + amount,
|
|
46
|
-
this.bottom + amount,
|
|
47
|
-
this.left + amount
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
*
|
|
53
|
-
* @param {Padding} padding padding to add
|
|
54
|
-
*/
|
|
55
|
-
add(padding) {
|
|
56
|
-
return new Padding(
|
|
57
|
-
this.top + padding.top,
|
|
58
|
-
this.right + padding.right,
|
|
59
|
-
this.bottom + padding.bottom,
|
|
60
|
-
this.left + padding.left
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
*
|
|
66
|
-
* @param {Padding} padding padding to subtract
|
|
67
|
-
*/
|
|
68
|
-
subtract(padding) {
|
|
69
|
-
return new Padding(
|
|
70
|
-
this.top - padding.top,
|
|
71
|
-
this.right - padding.right,
|
|
72
|
-
this.bottom - padding.bottom,
|
|
73
|
-
this.left - padding.left
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
*
|
|
79
|
-
* @param {PaddingConfig} config
|
|
80
|
-
*/
|
|
81
|
-
static createFromConfig(config) {
|
|
82
|
-
if (typeof config == "number") {
|
|
83
|
-
return this.createUniformPadding(config);
|
|
84
|
-
} else if (config) {
|
|
85
|
-
return this.createFromRecord(config);
|
|
86
|
-
} else {
|
|
87
|
-
return zeroPadding;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* @param {Paddings} paddings
|
|
93
|
-
*/
|
|
94
|
-
static createFromRecord(paddings) {
|
|
95
|
-
return new Padding(
|
|
96
|
-
paddings.top,
|
|
97
|
-
paddings.right,
|
|
98
|
-
paddings.bottom,
|
|
99
|
-
paddings.left
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Returns a zeroed padding.
|
|
105
|
-
*/
|
|
106
|
-
static zero() {
|
|
107
|
-
return zeroPadding;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
*
|
|
112
|
-
* @param {number} value
|
|
113
|
-
*/
|
|
114
|
-
static createUniformPadding(value) {
|
|
115
|
-
return new Padding(value, value, value, value);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const zeroPadding = Padding.createUniformPadding(0);
|
|
120
|
-
Object.freeze(zeroPadding);
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export default class Point {
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
* @param {number} x
|
|
5
|
-
* @param {number} y
|
|
6
|
-
*/
|
|
7
|
-
constructor(x, y) {
|
|
8
|
-
/** @readonly */ this.x = x;
|
|
9
|
-
/** @readonly */ this.y = y;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* @param {Point} point
|
|
15
|
-
*/
|
|
16
|
-
equals(point) {
|
|
17
|
-
if (!point) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return point === this || (point.x === this.x && point.y === this.y);
|
|
22
|
-
}
|
|
23
|
-
}
|