@genome-spy/core 0.30.0 → 0.30.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/dist/index.es.js +16379 -0
  2. package/dist/index.js +43 -43
  3. package/package.json +10 -7
  4. package/src/data/collector.js +0 -183
  5. package/src/data/collector.test.js +0 -84
  6. package/src/data/dataFlow.js +0 -148
  7. package/src/data/dataFlow.test.js +0 -5
  8. package/src/data/facetNode.js +0 -17
  9. package/src/data/flow.test.js +0 -72
  10. package/src/data/flowBatch.d.ts +0 -40
  11. package/src/data/flowNode.js +0 -283
  12. package/src/data/flowNode.test.js +0 -50
  13. package/src/data/flowOptimizer.js +0 -123
  14. package/src/data/flowOptimizer.test.js +0 -193
  15. package/src/data/flowTestUtils.js +0 -63
  16. package/src/data/formats/fasta.js +0 -32
  17. package/src/data/formats/fasta.test.js +0 -27
  18. package/src/data/sources/dataSource.js +0 -22
  19. package/src/data/sources/dataSourceFactory.js +0 -24
  20. package/src/data/sources/dataUtils.js +0 -78
  21. package/src/data/sources/dynamicCallbackSource.js +0 -57
  22. package/src/data/sources/dynamicSource.js +0 -37
  23. package/src/data/sources/inlineSource.js +0 -67
  24. package/src/data/sources/inlineSource.test.js +0 -56
  25. package/src/data/sources/namedSource.js +0 -79
  26. package/src/data/sources/sequenceSource.js +0 -46
  27. package/src/data/sources/sequenceSource.test.js +0 -46
  28. package/src/data/sources/urlSource.js +0 -74
  29. package/src/data/transforms/aggregate.js +0 -70
  30. package/src/data/transforms/clone.js +0 -40
  31. package/src/data/transforms/clone.test.js +0 -11
  32. package/src/data/transforms/coverage.js +0 -187
  33. package/src/data/transforms/coverage.test.js +0 -123
  34. package/src/data/transforms/filter.js +0 -37
  35. package/src/data/transforms/filter.test.js +0 -18
  36. package/src/data/transforms/filterScoredLabels.js +0 -134
  37. package/src/data/transforms/flattenCompressedExons.js +0 -57
  38. package/src/data/transforms/flattenDelimited.js +0 -74
  39. package/src/data/transforms/flattenDelimited.test.js +0 -87
  40. package/src/data/transforms/flattenSequence.js +0 -39
  41. package/src/data/transforms/flattenSequence.test.js +0 -34
  42. package/src/data/transforms/formula.js +0 -39
  43. package/src/data/transforms/formula.test.js +0 -19
  44. package/src/data/transforms/identifier.js +0 -108
  45. package/src/data/transforms/identifier.test.js +0 -83
  46. package/src/data/transforms/linearizeGenomicCoordinate.js +0 -101
  47. package/src/data/transforms/measureText.js +0 -44
  48. package/src/data/transforms/pileup.js +0 -128
  49. package/src/data/transforms/pileup.test.js +0 -70
  50. package/src/data/transforms/project.js +0 -41
  51. package/src/data/transforms/project.test.js +0 -32
  52. package/src/data/transforms/regexExtract.js +0 -61
  53. package/src/data/transforms/regexExtract.test.js +0 -67
  54. package/src/data/transforms/regexFold.js +0 -141
  55. package/src/data/transforms/regexFold.test.js +0 -160
  56. package/src/data/transforms/sample.js +0 -101
  57. package/src/data/transforms/sample.test.js +0 -38
  58. package/src/data/transforms/stack.js +0 -137
  59. package/src/data/transforms/stack.test.js +0 -91
  60. package/src/data/transforms/transformFactory.js +0 -60
  61. package/src/embedApi.d.ts +0 -67
  62. package/src/encoder/accessor.js +0 -82
  63. package/src/encoder/accessor.test.js +0 -47
  64. package/src/encoder/encoder.js +0 -394
  65. package/src/encoder/encoder.test.js +0 -98
  66. package/src/fonts/Lato-Regular.json +0 -1267
  67. package/src/fonts/Lato-Regular.png +0 -0
  68. package/src/fonts/OFL.txt +0 -93
  69. package/src/fonts/README.md +0 -3
  70. package/src/fonts/bmFont.d.ts +0 -58
  71. package/src/fonts/bmFontManager.js +0 -357
  72. package/src/fonts/bmFontMetrics.js +0 -108
  73. package/src/genome/genome.js +0 -317
  74. package/src/genome/genome.test.js +0 -188
  75. package/src/genome/genomeStore.js +0 -54
  76. package/src/genome/locusFormat.js +0 -31
  77. package/src/genome/scaleIndex.d.ts +0 -38
  78. package/src/genome/scaleIndex.js +0 -166
  79. package/src/genome/scaleIndex.test.js +0 -78
  80. package/src/genome/scaleLocus.d.ts +0 -11
  81. package/src/genome/scaleLocus.js +0 -108
  82. package/src/genome/scaleLocus.test.js +0 -4
  83. package/src/genomeSpy.js +0 -785
  84. package/src/gl/arrayBuilder.js +0 -199
  85. package/src/gl/dataToVertices.js +0 -636
  86. package/src/gl/includes/common.glsl +0 -63
  87. package/src/gl/includes/picking.fragment.glsl +0 -1
  88. package/src/gl/includes/picking.vertex.glsl +0 -27
  89. package/src/gl/includes/sampleFacet.glsl +0 -107
  90. package/src/gl/includes/scales.glsl +0 -112
  91. package/src/gl/link.fragment.glsl +0 -18
  92. package/src/gl/link.vertex.glsl +0 -111
  93. package/src/gl/point.fragment.glsl +0 -123
  94. package/src/gl/point.vertex.glsl +0 -129
  95. package/src/gl/rect.fragment.glsl +0 -51
  96. package/src/gl/rect.vertex.glsl +0 -114
  97. package/src/gl/rule.fragment.glsl +0 -52
  98. package/src/gl/rule.vertex.glsl +0 -89
  99. package/src/gl/text.fragment.glsl +0 -31
  100. package/src/gl/text.vertex.glsl +0 -246
  101. package/src/gl/webGLHelper.js +0 -504
  102. package/src/img/bowtie.svg +0 -1
  103. package/src/img/genomespy-favicon.svg +0 -34
  104. package/src/index.html +0 -11
  105. package/src/index.js +0 -128
  106. package/src/marks/link.js +0 -175
  107. package/src/marks/mark.js +0 -975
  108. package/src/marks/markUtils.js +0 -125
  109. package/src/marks/pointMark.js +0 -251
  110. package/src/marks/rectMark.js +0 -241
  111. package/src/marks/rule.js +0 -250
  112. package/src/marks/text.js +0 -278
  113. package/src/node_modules/.vitest/results.json +0 -1
  114. package/src/scale/colorUtils.js +0 -184
  115. package/src/scale/glslScaleGenerator.js +0 -502
  116. package/src/scale/scale.js +0 -451
  117. package/src/scale/scale.test.js +0 -324
  118. package/src/scale/ticks.js +0 -203
  119. package/src/scale/ticks.test.js +0 -40
  120. package/src/singlePageApp.js +0 -13
  121. package/src/spec/axis.d.ts +0 -296
  122. package/src/spec/channel.d.ts +0 -430
  123. package/src/spec/data.d.ts +0 -196
  124. package/src/spec/font.d.ts +0 -15
  125. package/src/spec/genome.d.ts +0 -35
  126. package/src/spec/mark.d.ts +0 -429
  127. package/src/spec/root.d.ts +0 -17
  128. package/src/spec/sampleView.d.ts +0 -180
  129. package/src/spec/scale.d.ts +0 -273
  130. package/src/spec/title.d.ts +0 -102
  131. package/src/spec/tooltip.d.ts +0 -9
  132. package/src/spec/transform.d.ts +0 -479
  133. package/src/spec/view.d.ts +0 -201
  134. package/src/styles/genome-spy.scss +0 -153
  135. package/src/tooltip/dataTooltipHandler.js +0 -64
  136. package/src/tooltip/refseqGeneTooltipHandler.js +0 -78
  137. package/src/tooltip/tooltipHandler.ts +0 -12
  138. package/src/types/filetypes.d.ts +0 -14
  139. package/src/types/flatqueue.d.ts +0 -53
  140. package/src/types/glsl.d.ts +0 -4
  141. package/src/types/internmap.d.ts +0 -22
  142. package/src/types/object.d.ts +0 -21
  143. package/src/types/vega-loader.d.ts +0 -1
  144. package/src/types/vega-scale.d.ts +0 -60
  145. package/src/utils/addBaseUrl.js +0 -19
  146. package/src/utils/addBaseUrl.test.js +0 -22
  147. package/src/utils/animator.js +0 -83
  148. package/src/utils/arrayUtils.js +0 -61
  149. package/src/utils/binnedIndex.js +0 -167
  150. package/src/utils/binnedIndex.test.js +0 -155
  151. package/src/utils/clamp.js +0 -8
  152. package/src/utils/cloner.js +0 -34
  153. package/src/utils/cloner.test.js +0 -24
  154. package/src/utils/coalesce.js +0 -11
  155. package/src/utils/coalesce.test.js +0 -16
  156. package/src/utils/concatIterables.js +0 -26
  157. package/src/utils/concatIterables.test.js +0 -8
  158. package/src/utils/debounce.js +0 -37
  159. package/src/utils/domainArray.js +0 -216
  160. package/src/utils/domainArray.test.js +0 -130
  161. package/src/utils/eerp.js +0 -13
  162. package/src/utils/expression.js +0 -32
  163. package/src/utils/field.js +0 -28
  164. package/src/utils/formatObject.js +0 -31
  165. package/src/utils/indexer.js +0 -43
  166. package/src/utils/indexer.test.js +0 -47
  167. package/src/utils/inertia.js +0 -124
  168. package/src/utils/interactionEvent.js +0 -33
  169. package/src/utils/iterateNestedMaps.js +0 -21
  170. package/src/utils/iterateNestedMaps.test.js +0 -33
  171. package/src/utils/kWayMerge.js +0 -42
  172. package/src/utils/kWayMerge.test.js +0 -26
  173. package/src/utils/layout/flexLayout.js +0 -368
  174. package/src/utils/layout/flexLayout.test.js +0 -311
  175. package/src/utils/layout/grid.js +0 -95
  176. package/src/utils/layout/grid.test.js +0 -71
  177. package/src/utils/layout/padding.js +0 -120
  178. package/src/utils/layout/point.js +0 -23
  179. package/src/utils/layout/rectangle.js +0 -288
  180. package/src/utils/layout/rectangle.test.js +0 -172
  181. package/src/utils/mergeObjects.js +0 -99
  182. package/src/utils/mergeObjects.test.js +0 -42
  183. package/src/utils/numberExtractor.js +0 -24
  184. package/src/utils/numberExtractor.test.js +0 -6
  185. package/src/utils/point.js +0 -14
  186. package/src/utils/propertyCacher.js +0 -70
  187. package/src/utils/propertyCacher.test.js +0 -85
  188. package/src/utils/propertyCoalescer.js +0 -42
  189. package/src/utils/propertyCoalescer.test.js +0 -22
  190. package/src/utils/reservationMap.js +0 -103
  191. package/src/utils/reservationMap.test.js +0 -20
  192. package/src/utils/scaleNull.js +0 -19
  193. package/src/utils/setOperations.js +0 -75
  194. package/src/utils/smoothstep.js +0 -10
  195. package/src/utils/throttle.js +0 -34
  196. package/src/utils/topK.js +0 -76
  197. package/src/utils/topK.test.js +0 -64
  198. package/src/utils/transition.js +0 -74
  199. package/src/utils/ui/tooltip.js +0 -189
  200. package/src/utils/url.js +0 -22
  201. package/src/utils/variableTools.js +0 -24
  202. package/src/utils/variableTools.test.js +0 -13
  203. package/src/view/axisResolution.js +0 -140
  204. package/src/view/axisResolution.test.js +0 -201
  205. package/src/view/axisView.js +0 -747
  206. package/src/view/concatView.js +0 -45
  207. package/src/view/containerView.js +0 -159
  208. package/src/view/facetView.js +0 -491
  209. package/src/view/flowBuilder.js +0 -367
  210. package/src/view/flowBuilder.test.js +0 -125
  211. package/src/view/gridView.js +0 -786
  212. package/src/view/implicitRootView.js +0 -14
  213. package/src/view/importView.js +0 -19
  214. package/src/view/layerView.js +0 -74
  215. package/src/view/rendering.d.ts +0 -44
  216. package/src/view/renderingContext/compositeViewRenderingContext.js +0 -51
  217. package/src/view/renderingContext/deferredViewRenderingContext.js +0 -176
  218. package/src/view/renderingContext/layoutRecorderViewRenderingContext.js +0 -128
  219. package/src/view/renderingContext/simpleViewRenderingContext.js +0 -64
  220. package/src/view/renderingContext/svgViewRenderingContext.js +0 -125
  221. package/src/view/renderingContext/viewRenderingContext.js +0 -41
  222. package/src/view/scaleResolution.js +0 -797
  223. package/src/view/scaleResolution.test.js +0 -572
  224. package/src/view/scaleResolutionApi.d.ts +0 -40
  225. package/src/view/testUtils.js +0 -51
  226. package/src/view/title.js +0 -165
  227. package/src/view/unitView.js +0 -382
  228. package/src/view/view.js +0 -612
  229. package/src/view/view.test.js +0 -214
  230. package/src/view/viewContext.d.ts +0 -62
  231. package/src/view/viewFactory.js +0 -181
  232. package/src/view/viewFactory.test.js +0 -17
  233. package/src/view/viewUtils.js +0 -327
  234. package/src/view/zoom.js +0 -89
@@ -1,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
- }
@@ -1,6 +0,0 @@
1
- import { expect, test } from "vitest";
2
- import numberExtractor from "./numberExtractor";
3
-
4
- test("NumberExtractor parses delimited integers", () => {
5
- expect([...numberExtractor("23,12345,2345")]).toEqual([23, 12345, 2345]);
6
- });
@@ -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
- }