@genome-spy/core 0.30.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 -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
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param {number} value
|
|
3
|
-
* @returns {Accessor}
|
|
4
|
-
*/
|
|
5
|
-
function constant(value) {
|
|
6
|
-
return () => value;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* An immutable rectangle with a scene-graph -like hierarchy.
|
|
11
|
-
* Allows for implementing scrolling viewports etc.
|
|
12
|
-
*
|
|
13
|
-
* @typedef {("x" | "y" | "width" | "height")} Prop
|
|
14
|
-
* @typedef {import("./padding").default } Padding
|
|
15
|
-
* @typedef {() => number} Accessor
|
|
16
|
-
*/
|
|
17
|
-
export default class Rectangle {
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
* @param {number} x
|
|
21
|
-
* @param {number} y
|
|
22
|
-
* @param {number} width
|
|
23
|
-
* @param {number} height
|
|
24
|
-
*/
|
|
25
|
-
static create(x, y, width, height) {
|
|
26
|
-
return new Rectangle(
|
|
27
|
-
constant(x),
|
|
28
|
-
constant(y),
|
|
29
|
-
constant(width),
|
|
30
|
-
constant(height)
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
static ZERO = Rectangle.create(0, 0, 0, 0);
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @param {Prop} prop
|
|
38
|
-
* @param {number | function():number} value
|
|
39
|
-
* @returns {Accessor}
|
|
40
|
-
*/
|
|
41
|
-
_offset(prop, value) {
|
|
42
|
-
// @ts-ignore
|
|
43
|
-
const accessor = this["_" + prop];
|
|
44
|
-
if (value === 0) {
|
|
45
|
-
return accessor;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
switch (typeof value) {
|
|
49
|
-
case "number":
|
|
50
|
-
return () => accessor() + value;
|
|
51
|
-
case "function":
|
|
52
|
-
return () => accessor() + value();
|
|
53
|
-
default:
|
|
54
|
-
throw new Error("Not a number of function");
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @param {Prop} prop
|
|
60
|
-
*/
|
|
61
|
-
_passThrough(prop) {
|
|
62
|
-
return this._offset(prop, 0);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
*
|
|
67
|
-
* @param {Accessor} x
|
|
68
|
-
* @param {Accessor} y
|
|
69
|
-
* @param {Accessor} width
|
|
70
|
-
* @param {Accessor} height
|
|
71
|
-
*/
|
|
72
|
-
constructor(x, y, width, height) {
|
|
73
|
-
/** @readonly */ this._x = x;
|
|
74
|
-
/** @readonly */ this._y = y;
|
|
75
|
-
/** @readonly */ this._width = width;
|
|
76
|
-
/** @readonly */ this._height = height;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* @returns {number}
|
|
81
|
-
*/
|
|
82
|
-
get x() {
|
|
83
|
-
return this._x();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* @returns {number}
|
|
88
|
-
*/
|
|
89
|
-
get y() {
|
|
90
|
-
return this._y();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* @returns {number}
|
|
95
|
-
*/
|
|
96
|
-
get width() {
|
|
97
|
-
return this._width();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* @returns {number}
|
|
102
|
-
*/
|
|
103
|
-
get height() {
|
|
104
|
-
return this._height();
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
get x2() {
|
|
108
|
-
return this._x() + this._width();
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
get y2() {
|
|
112
|
-
return this._y() + this._height();
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Returns true if the given rectangle is the same or equal rectangle.
|
|
117
|
-
*
|
|
118
|
-
* @param {Rectangle} rectangle
|
|
119
|
-
*/
|
|
120
|
-
equals(rectangle) {
|
|
121
|
-
if (!rectangle) {
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return (
|
|
126
|
-
this === rectangle ||
|
|
127
|
-
(this.x === rectangle.x &&
|
|
128
|
-
this.y === rectangle.y &&
|
|
129
|
-
this.width === rectangle.width &&
|
|
130
|
-
this.height === rectangle.height)
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
*
|
|
136
|
-
* @param {Partial<Record<Prop, number | function():number>>} props
|
|
137
|
-
*/
|
|
138
|
-
modify(props) {
|
|
139
|
-
if (!Object.keys(props).length) {
|
|
140
|
-
return this;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/** @param {Prop} prop */
|
|
144
|
-
const map = (prop) => {
|
|
145
|
-
const v = props[prop];
|
|
146
|
-
return typeof v == "number"
|
|
147
|
-
? constant(v)
|
|
148
|
-
: typeof v == "function"
|
|
149
|
-
? v
|
|
150
|
-
: this._passThrough(prop);
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
return new Rectangle(map("x"), map("y"), map("width"), map("height"));
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
*
|
|
158
|
-
* @param {number | function():number} x
|
|
159
|
-
* @param {number | function():number} y
|
|
160
|
-
*/
|
|
161
|
-
translate(x, y) {
|
|
162
|
-
if (x === 0 && y === 0) {
|
|
163
|
-
return this;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return new Rectangle(
|
|
167
|
-
this._offset("x", x),
|
|
168
|
-
this._offset("y", y),
|
|
169
|
-
this._passThrough("width"),
|
|
170
|
-
this._passThrough("height")
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Returns a copy of this rectangle translated by the given rectangle.
|
|
176
|
-
*
|
|
177
|
-
* @param {Rectangle} rectangle
|
|
178
|
-
*/
|
|
179
|
-
translateBy(rectangle) {
|
|
180
|
-
// TODO: Make dynamic
|
|
181
|
-
return this.translate(rectangle.x, rectangle.y);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
*
|
|
186
|
-
* @param {Padding} padding
|
|
187
|
-
*/
|
|
188
|
-
expand(padding, direction = 1) {
|
|
189
|
-
if (
|
|
190
|
-
padding.left == 0 &&
|
|
191
|
-
padding.top == 0 &&
|
|
192
|
-
padding.right == 0 &&
|
|
193
|
-
padding.bottom == 0
|
|
194
|
-
) {
|
|
195
|
-
return this;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return new Rectangle(
|
|
199
|
-
padding.left
|
|
200
|
-
? this._offset("x", -padding.left * direction)
|
|
201
|
-
: this._passThrough("x"),
|
|
202
|
-
padding.top
|
|
203
|
-
? this._offset("y", -padding.top * direction)
|
|
204
|
-
: this._passThrough("y"),
|
|
205
|
-
padding.width
|
|
206
|
-
? this._offset("width", padding.width * direction)
|
|
207
|
-
: this._passThrough("width"),
|
|
208
|
-
padding.height
|
|
209
|
-
? this._offset("height", padding.height * direction)
|
|
210
|
-
: this._passThrough("height")
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
*
|
|
216
|
-
* @param {Padding} padding
|
|
217
|
-
*/
|
|
218
|
-
shrink(padding) {
|
|
219
|
-
return this.expand(padding, -1);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Returns an intersection of this and the other rectangle.
|
|
224
|
-
*
|
|
225
|
-
* @param {Rectangle} rectangle
|
|
226
|
-
*/
|
|
227
|
-
intersect(rectangle) {
|
|
228
|
-
if (this === rectangle) {
|
|
229
|
-
return this;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
return new Rectangle(
|
|
233
|
-
() => Math.max(this.x, rectangle.x),
|
|
234
|
-
() => Math.max(this.y, rectangle.y),
|
|
235
|
-
() =>
|
|
236
|
-
Math.min(this.x2, rectangle.x2) - Math.max(this.x, rectangle.x),
|
|
237
|
-
() =>
|
|
238
|
-
Math.min(this.y2, rectangle.y2) - Math.max(this.y, rectangle.y)
|
|
239
|
-
);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Returns true if width and height are greater than equal to zero.
|
|
244
|
-
*/
|
|
245
|
-
isDefined() {
|
|
246
|
-
return this.width >= 0 && this.height >= 0;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Returns a flattened rectangle, i.e., drops the hierarchy and materializes
|
|
251
|
-
* the parameters.
|
|
252
|
-
*/
|
|
253
|
-
flatten() {
|
|
254
|
-
return new Rectangle(
|
|
255
|
-
constant(this.x),
|
|
256
|
-
constant(this.y),
|
|
257
|
-
constant(this.width),
|
|
258
|
-
constant(this.height)
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Tests whether the rectangle contains the given point. Uses half open intervals.
|
|
264
|
-
*
|
|
265
|
-
* @param {number} x
|
|
266
|
-
* @param {number} y
|
|
267
|
-
*/
|
|
268
|
-
containsPoint(x, y) {
|
|
269
|
-
return x >= this.x && x < this.x2 && y >= this.y && y < this.y2;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Normalizes a point with respect to this rectangle
|
|
274
|
-
*
|
|
275
|
-
* @param {number} x
|
|
276
|
-
* @param {number} y
|
|
277
|
-
*/
|
|
278
|
-
normalizePoint(x, y) {
|
|
279
|
-
return {
|
|
280
|
-
x: (x - this.x) / this.width,
|
|
281
|
-
y: (y - this.y) / this.height,
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
toString() {
|
|
286
|
-
return `Rectangle: x: ${this.x}, y: ${this.y}, width: ${this.width}, height: ${this.height}`;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "vitest";
|
|
2
|
-
import Rectangle from "./rectangle";
|
|
3
|
-
import Padding from "./padding";
|
|
4
|
-
|
|
5
|
-
test("Rectangle creation", () => {
|
|
6
|
-
const r = Rectangle.create(1, 2, 3, 4);
|
|
7
|
-
expect(r.x).toEqual(1);
|
|
8
|
-
expect(r.y).toEqual(2);
|
|
9
|
-
expect(r.width).toEqual(3);
|
|
10
|
-
expect(r.height).toEqual(4);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
test("equals", () => {
|
|
14
|
-
const r = Rectangle.create(1, 2, 3, 4);
|
|
15
|
-
expect(r.equals(r)).toBeTruthy();
|
|
16
|
-
expect(r.equals(Rectangle.create(1, 2, 3, 4))).toBeTruthy();
|
|
17
|
-
expect(r.equals(undefined)).toBeFalsy();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test("x2 and y2 calculation", () => {
|
|
21
|
-
const r = Rectangle.create(1, 2, 3, 4);
|
|
22
|
-
expect(r.x2).toEqual(4);
|
|
23
|
-
expect(r.y2).toEqual(6);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test("translate", () => {
|
|
27
|
-
const r = Rectangle.create(1, 2, 3, 4).translate(2, 3);
|
|
28
|
-
expect(r.x).toEqual(3);
|
|
29
|
-
expect(r.y).toEqual(5);
|
|
30
|
-
expect(r.width).toEqual(3);
|
|
31
|
-
expect(r.height).toEqual(4);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test("Dynamic translate", () => {
|
|
35
|
-
let tx = 0;
|
|
36
|
-
let ty = 0;
|
|
37
|
-
|
|
38
|
-
const r = Rectangle.create(1, 2, 3, 4)
|
|
39
|
-
.translate(
|
|
40
|
-
() => tx,
|
|
41
|
-
() => ty
|
|
42
|
-
)
|
|
43
|
-
.translate(2, 3);
|
|
44
|
-
|
|
45
|
-
expect(r.x).toEqual(3);
|
|
46
|
-
expect(r.y).toEqual(5);
|
|
47
|
-
expect(r.width).toEqual(3);
|
|
48
|
-
expect(r.height).toEqual(4);
|
|
49
|
-
|
|
50
|
-
tx = 1;
|
|
51
|
-
ty = 2;
|
|
52
|
-
|
|
53
|
-
expect(r.x).toEqual(4);
|
|
54
|
-
expect(r.y).toEqual(7);
|
|
55
|
-
expect(r.width).toEqual(3);
|
|
56
|
-
expect(r.height).toEqual(4);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test("expand", () => {
|
|
60
|
-
const r = Rectangle.create(1, 2, 3, 4).expand(
|
|
61
|
-
Padding.createFromRecord({ top: 2, right: 3, bottom: 4, left: 5 })
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
expect(r.x).toEqual(-4);
|
|
65
|
-
expect(r.width).toEqual(11);
|
|
66
|
-
expect(r.y).toEqual(0);
|
|
67
|
-
expect(r.height).toEqual(10);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test("shrink", () => {
|
|
71
|
-
const r = Rectangle.create(1, 2, 3, 4).shrink(
|
|
72
|
-
Padding.createUniformPadding(1)
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
expect(r.x).toEqual(2);
|
|
76
|
-
expect(r.width).toEqual(1);
|
|
77
|
-
expect(r.y).toEqual(3);
|
|
78
|
-
expect(r.height).toEqual(2);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test("modify", () => {
|
|
82
|
-
const r = Rectangle.create(1, 2, 3, 4);
|
|
83
|
-
const m = r.modify({ x: 5 });
|
|
84
|
-
|
|
85
|
-
expect(m.equals(r)).toBeFalsy();
|
|
86
|
-
expect(m.equals(Rectangle.create(5, 2, 3, 4))).toBeTruthy();
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
test("Dynamic modify", () => {
|
|
90
|
-
let x = 1;
|
|
91
|
-
const r = Rectangle.create(1, 2, 3, 4);
|
|
92
|
-
const m = r.modify({ x: () => x });
|
|
93
|
-
|
|
94
|
-
expect(m.equals(r)).toBeTruthy();
|
|
95
|
-
expect(m.equals(Rectangle.create(1, 2, 3, 4))).toBeTruthy();
|
|
96
|
-
|
|
97
|
-
x = 5;
|
|
98
|
-
|
|
99
|
-
expect(m.equals(r)).toBeFalsy();
|
|
100
|
-
expect(m.equals(Rectangle.create(5, 2, 3, 4))).toBeTruthy();
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
test("intersect", () => {
|
|
104
|
-
const a = Rectangle.create(1, 1, 6, 3);
|
|
105
|
-
const b = Rectangle.create(5, 2, 3, 4);
|
|
106
|
-
const c = Rectangle.create(5, 2, 2, 2);
|
|
107
|
-
|
|
108
|
-
expect(a.intersect(b).equals(c)).toBeTruthy();
|
|
109
|
-
expect(a.intersect(b).isDefined()).toBeTruthy();
|
|
110
|
-
|
|
111
|
-
const x = Rectangle.create(1, 1, 1, 1);
|
|
112
|
-
const y = Rectangle.create(3, 3, 1, 1);
|
|
113
|
-
|
|
114
|
-
expect(x.intersect(y).isDefined()).toBeFalsy();
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
test("isDefined", () => {
|
|
118
|
-
expect(Rectangle.create(0, 0, 1, 1).isDefined()).toBeTruthy();
|
|
119
|
-
expect(Rectangle.create(0, 0, 0, 0).isDefined()).toBeTruthy();
|
|
120
|
-
|
|
121
|
-
expect(Rectangle.create(0, 0, -1, 0).isDefined()).toBeFalsy();
|
|
122
|
-
expect(Rectangle.create(0, 0, 0, -1).isDefined()).toBeFalsy();
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
test("flatten", () => {
|
|
126
|
-
let tx = 0;
|
|
127
|
-
let ty = 0;
|
|
128
|
-
|
|
129
|
-
const r = Rectangle.create(1, 2, 3, 4).translate(
|
|
130
|
-
() => tx,
|
|
131
|
-
() => ty
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
const flattened = r.flatten();
|
|
135
|
-
|
|
136
|
-
tx = -1;
|
|
137
|
-
ty = -2;
|
|
138
|
-
|
|
139
|
-
expect(r.equals(Rectangle.create(0, 0, 3, 4)));
|
|
140
|
-
expect(flattened.equals(Rectangle.create(1, 2, 3, 4)));
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
test("containsPoint", () => {
|
|
144
|
-
const r = Rectangle.create(1, 2, 3, 4);
|
|
145
|
-
|
|
146
|
-
expect(r.containsPoint(0, 0)).toBeFalsy();
|
|
147
|
-
expect(r.containsPoint(0, 10)).toBeFalsy();
|
|
148
|
-
expect(r.containsPoint(10, 0)).toBeFalsy();
|
|
149
|
-
expect(r.containsPoint(10, 10)).toBeFalsy();
|
|
150
|
-
|
|
151
|
-
expect(r.containsPoint(2, 0)).toBeFalsy();
|
|
152
|
-
expect(r.containsPoint(2, 10)).toBeFalsy();
|
|
153
|
-
expect(r.containsPoint(0, 3)).toBeFalsy();
|
|
154
|
-
expect(r.containsPoint(10, 3)).toBeFalsy();
|
|
155
|
-
|
|
156
|
-
// Inclusive corner
|
|
157
|
-
expect(r.containsPoint(1, 2)).toBeTruthy();
|
|
158
|
-
|
|
159
|
-
// Inside
|
|
160
|
-
expect(r.containsPoint(2, 3)).toBeTruthy();
|
|
161
|
-
|
|
162
|
-
// Exclusive corner
|
|
163
|
-
expect(r.containsPoint(4, 6)).toBeFalsy();
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
test("normalizePoint", () => {
|
|
167
|
-
const r = Rectangle.create(1, 2, 6, 4);
|
|
168
|
-
|
|
169
|
-
expect(r.normalizePoint(1, 2)).toEqual({ x: 0, y: 0 });
|
|
170
|
-
expect(r.normalizePoint(7, 2)).toEqual({ x: 1, y: 0 });
|
|
171
|
-
expect(r.normalizePoint(4, 4)).toEqual({ x: 0.5, y: 0.5 });
|
|
172
|
-
});
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-depth */
|
|
2
|
-
import { isObject } from "vega-util";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Deep merge.
|
|
6
|
-
*
|
|
7
|
-
* A boolean true and an object are compatible. The object survives, the boolean is overwritten.
|
|
8
|
-
*
|
|
9
|
-
* TODO: Support arrays. Should accept identical arrays and complain about others.
|
|
10
|
-
*
|
|
11
|
-
* @param {T[]} objects Objects to merge
|
|
12
|
-
* @param {string} propertyOf What are we merging? Used in warning messages
|
|
13
|
-
* @param {string[]} [skip] Fields to skip. TODO: Support nested fields.
|
|
14
|
-
* @returns {T}
|
|
15
|
-
* @template T
|
|
16
|
-
*/
|
|
17
|
-
export default function mergeObjects(objects, propertyOf, skip) {
|
|
18
|
-
skip = skip || [];
|
|
19
|
-
|
|
20
|
-
if (objects.some((d) => d === null)) {
|
|
21
|
-
if (objects.every((d) => d === null)) {
|
|
22
|
-
return null;
|
|
23
|
-
} else {
|
|
24
|
-
console.warn(objects);
|
|
25
|
-
throw new Error("Cannot merge objects with nulls!");
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** @type {any} */
|
|
30
|
-
const target = {};
|
|
31
|
-
|
|
32
|
-
/** @type {function(any, any):boolean} */
|
|
33
|
-
const compatible = (a, b) =>
|
|
34
|
-
a === b ||
|
|
35
|
-
(isPlainObject(a) && isPlainObject(b)) ||
|
|
36
|
-
(isPlainObject(a) && b === true) ||
|
|
37
|
-
(a === true && isObject(b));
|
|
38
|
-
|
|
39
|
-
/** @param {any} obj */
|
|
40
|
-
const merger = (obj) => {
|
|
41
|
-
// eslint-disable-next-line guard-for-in
|
|
42
|
-
for (let prop in obj) {
|
|
43
|
-
const sourceValue = obj[prop];
|
|
44
|
-
if (!skip.includes(prop) && sourceValue !== undefined) {
|
|
45
|
-
if (
|
|
46
|
-
target[prop] !== undefined &&
|
|
47
|
-
!compatible(target[prop], sourceValue)
|
|
48
|
-
) {
|
|
49
|
-
console.warn(
|
|
50
|
-
`Conflicting property ${prop} of ${propertyOf}: (${JSON.stringify(
|
|
51
|
-
target[prop]
|
|
52
|
-
)} and ${JSON.stringify(
|
|
53
|
-
obj[prop]
|
|
54
|
-
)}). Using ${JSON.stringify(target[prop])}.`
|
|
55
|
-
);
|
|
56
|
-
} else {
|
|
57
|
-
const targetValue = target[prop];
|
|
58
|
-
|
|
59
|
-
if (isPlainObject(targetValue)) {
|
|
60
|
-
if (isPlainObject(sourceValue)) {
|
|
61
|
-
// Object merged to object
|
|
62
|
-
target[prop] = mergeObjects(
|
|
63
|
-
[targetValue, sourceValue],
|
|
64
|
-
prop
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
} else if (isPlainObject(sourceValue)) {
|
|
68
|
-
if (
|
|
69
|
-
!(targetValue === true || targetValue === undefined)
|
|
70
|
-
) {
|
|
71
|
-
throw new Error(
|
|
72
|
-
"Bug in merge! Target is: " + targetValue
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
// Object replaces "true"
|
|
76
|
-
target[prop] = mergeObjects([{}, sourceValue], prop);
|
|
77
|
-
} else {
|
|
78
|
-
// Scalar
|
|
79
|
-
target[prop] = sourceValue;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
for (const o of objects) {
|
|
87
|
-
merger(o);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return target;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
*
|
|
95
|
-
* @param {any} x
|
|
96
|
-
*/
|
|
97
|
-
function isPlainObject(x) {
|
|
98
|
-
return isObject(x) && !Array.isArray(x);
|
|
99
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "vitest";
|
|
2
|
-
import mergeObjects from "./mergeObjects";
|
|
3
|
-
|
|
4
|
-
test("Merges non-conflicting properties", () => {
|
|
5
|
-
expect(mergeObjects([{ a: 1 }, { b: 2 }], "test")).toEqual({ a: 1, b: 2 });
|
|
6
|
-
|
|
7
|
-
expect(mergeObjects([{ a: [0, 1] }, { b: [2, 3] }], "test")).toEqual({
|
|
8
|
-
a: [0, 1],
|
|
9
|
-
b: [2, 3],
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
test("Skips conflicting properties", () => {
|
|
14
|
-
expect(
|
|
15
|
-
mergeObjects(
|
|
16
|
-
[
|
|
17
|
-
{ a: 1, b: 2, c: 3 },
|
|
18
|
-
{ b: 5, d: 4 },
|
|
19
|
-
],
|
|
20
|
-
"test"
|
|
21
|
-
)
|
|
22
|
-
).toEqual({ a: 1, b: 2, c: 3, d: 4 });
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test("Null is handled correctly", () => {
|
|
26
|
-
expect(mergeObjects([null, null, null], "test")).toBeNull();
|
|
27
|
-
expect(() => mergeObjects([{ a: 1 }, null, { b: 2 }], "test")).toThrow();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test("Nested objects are merged", () => {
|
|
31
|
-
expect(
|
|
32
|
-
mergeObjects([{ nested: { a: 1 } }, { nested: { b: 2 } }], "test")
|
|
33
|
-
).toEqual({ nested: { a: 1, b: 2 } });
|
|
34
|
-
|
|
35
|
-
expect(
|
|
36
|
-
mergeObjects([{ nested: { a: 1 } }, { nested: true }], "test")
|
|
37
|
-
).toEqual({ nested: { a: 1 } });
|
|
38
|
-
|
|
39
|
-
expect(
|
|
40
|
-
mergeObjects([{ nested: true }, { nested: { a: 1 } }], "test")
|
|
41
|
-
).toEqual({ nested: { a: 1 } });
|
|
42
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const zero = "0".charCodeAt(0);
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Extract numbers from a delimited string. Does not do any error checking.
|
|
5
|
-
*
|
|
6
|
-
* This is roughly 25% faster than using String.split and parseInt (on Chrome).
|
|
7
|
-
*
|
|
8
|
-
* @param {string} string
|
|
9
|
-
*/
|
|
10
|
-
export default function* numberExtractor(string, delimiter = ",") {
|
|
11
|
-
const delCode = delimiter.charCodeAt(0);
|
|
12
|
-
|
|
13
|
-
let acc = 0;
|
|
14
|
-
for (let i = 0; i < string.length; i++) {
|
|
15
|
-
const charCode = string.charCodeAt(i);
|
|
16
|
-
if (charCode == delCode) {
|
|
17
|
-
yield acc;
|
|
18
|
-
acc = 0;
|
|
19
|
-
} else {
|
|
20
|
-
acc = acc * 10 + charCode - zero;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
yield acc;
|
|
24
|
-
}
|
package/src/utils/point.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adapted from: https://github.com/d3/d3-selection/blob/master/src/point.js
|
|
3
|
-
*
|
|
4
|
-
* @param {HTMLElement} node
|
|
5
|
-
* @param {MouseEvent} event
|
|
6
|
-
* @returns {[number, number]}
|
|
7
|
-
*/
|
|
8
|
-
export default function (node, event) {
|
|
9
|
-
var rect = node.getBoundingClientRect();
|
|
10
|
-
return [
|
|
11
|
-
event.clientX - rect.left - node.clientLeft,
|
|
12
|
-
event.clientY - rect.top - node.clientTop,
|
|
13
|
-
];
|
|
14
|
-
}
|