@vitessce/gl 4.0.8 → 4.0.9

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 (37) hide show
  1. package/dist/{deflate-DNngSh3q.js → deflate-DD4d--xe.js} +1 -1
  2. package/dist/{index-_UASQg2S.js → index-D4C8DA1x.js} +1324 -109
  3. package/dist/index.js +18 -13
  4. package/dist/{jpeg-BrGNk507.js → jpeg-CZeZBc_8.js} +1 -1
  5. package/dist/{lerc-A9bnCzoN.js → lerc-Ct7C32yr.js} +1 -1
  6. package/dist/{lzw-_IYIPfiq.js → lzw-BgdxJ7Qg.js} +1 -1
  7. package/dist/{packbits-CxQQOChS.js → packbits-BhOBFsGy.js} +1 -1
  8. package/dist/{raw-ti2YIR09.js → raw-B5_2TWMK.js} +1 -1
  9. package/dist/{webimage-DgRcFzf_.js → webimage-DcEapRkY.js} +1 -1
  10. package/dist-tsc/AnnotationLayer.d.ts +91 -0
  11. package/dist-tsc/AnnotationLayer.d.ts.map +1 -0
  12. package/dist-tsc/AnnotationLayer.js +71 -0
  13. package/dist-tsc/AnnotationLayer.js.map +1 -0
  14. package/dist-tsc/AnnotationLayer.test.d.ts +2 -0
  15. package/dist-tsc/AnnotationLayer.test.d.ts.map +1 -0
  16. package/dist-tsc/AnnotationLayer.test.js +59 -0
  17. package/dist-tsc/AnnotationLayer.test.js.map +1 -0
  18. package/dist-tsc/annotation-layer-utils.d.ts +25 -0
  19. package/dist-tsc/annotation-layer-utils.d.ts.map +1 -0
  20. package/dist-tsc/annotation-layer-utils.js +1110 -0
  21. package/dist-tsc/annotation-layer-utils.js.map +1 -0
  22. package/dist-tsc/annotation-layer-utils.test.d.ts +2 -0
  23. package/dist-tsc/annotation-layer-utils.test.d.ts.map +1 -0
  24. package/dist-tsc/annotation-layer-utils.test.js +153 -0
  25. package/dist-tsc/annotation-layer-utils.test.js.map +1 -0
  26. package/dist-tsc/deck.js +2 -2
  27. package/dist-tsc/deck.js.map +1 -1
  28. package/dist-tsc/index.d.ts +2 -0
  29. package/dist-tsc/index.js +2 -0
  30. package/dist-tsc/index.js.map +1 -1
  31. package/package.json +4 -3
  32. package/src/AnnotationLayer.js +91 -0
  33. package/src/AnnotationLayer.test.js +67 -0
  34. package/src/annotation-layer-utils.js +1137 -0
  35. package/src/annotation-layer-utils.test.js +180 -0
  36. package/src/deck.js +2 -1
  37. package/src/index.js +2 -0
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Attribution: Originally written by @RPSeaman
3
+ * Reference: https://github.com/vitessce/vitessce/pull/2528
4
+ */
5
+ import { describe, it, expect } from 'vitest';
6
+ import { computeArrowhead, createAnnotationLayers, createPreviewLayer } from './annotation-layer-utils.js';
7
+
8
+ describe('computeArrowhead', () => {
9
+ it('returns null for a zero-length direction vector', () => {
10
+ expect(computeArrowhead(0, 0, 0, 0, 10)).toBeNull();
11
+ });
12
+
13
+ it('places the tip at (tipX, tipY) for a rightward line', () => {
14
+ // Line pointing right: dir = (1, 0)
15
+ const triangle = computeArrowhead(10, 0, 1, 0, 4);
16
+ expect(triangle).not.toBeNull();
17
+ // First vertex is the tip
18
+ expect(triangle[0]).toEqual([10, 0]);
19
+ });
20
+
21
+ it('produces a triangle whose base is perpendicular to the direction', () => {
22
+ // Rightward arrow: base vertices should differ only in Y (perpendicular axis)
23
+ const size = 4;
24
+ const triangle = computeArrowhead(10, 0, 1, 0, size);
25
+ const [, p1, p2] = triangle;
26
+ // Both base points share the same X (base is at tip - size along X)
27
+ expect(p1[0]).toBeCloseTo(10 - size, 5);
28
+ expect(p2[0]).toBeCloseTo(10 - size, 5);
29
+ // Base points are symmetric around Y = 0
30
+ expect(p1[1]).toBeCloseTo(-p2[1], 5);
31
+ });
32
+ });
33
+
34
+ describe('createAnnotationLayers', () => {
35
+ it('returns an empty array when given no shapes', () => {
36
+ expect(createAnnotationLayers([], 0)).toHaveLength(0);
37
+ });
38
+
39
+ it('returns a PolygonLayer for a rectangle with fillOpacity: 0 (not filled)', () => {
40
+ const shapes = [{ uid: 'r1', type: 'rectangle', x: 0, y: 0, width: 100, height: 50, fillOpacity: 0 }];
41
+ const layers = createAnnotationLayers(shapes, 0);
42
+ expect(layers).toHaveLength(1);
43
+ expect(layers[0].props.filled).toBe(false);
44
+ });
45
+
46
+ it('returns a PolygonLayer that is filled when fillOpacity > 0', () => {
47
+ const shapes = [{ uid: 'r2', type: 'rectangle', x: 0, y: 0, width: 100, height: 50, fillOpacity: 0.5 }];
48
+ const layers = createAnnotationLayers(shapes, 0);
49
+ expect(layers[0].props.filled).toBe(true);
50
+ });
51
+
52
+ it('returns a LineLayer plus an arrowhead PolygonLayer for a line with markerEnd: Arrow', () => {
53
+ const shapes = [{ uid: 'l1', type: 'line', x1: 0, y1: 0, x2: 10, y2: 0, markerEnd: 'Arrow' }];
54
+ const layers = createAnnotationLayers(shapes, 0);
55
+ // LineLayer (shaft) + PolygonLayer (arrowhead)
56
+ expect(layers).toHaveLength(2);
57
+ });
58
+
59
+ it('returns shaft + two arrowhead layers for markerStart and markerEnd', () => {
60
+ const shapes = [{ uid: 'l2', type: 'line', x1: 0, y1: 0, x2: 10, y2: 0, markerStart: 'Arrow', markerEnd: 'Arrow' }];
61
+ const layers = createAnnotationLayers(shapes, 0);
62
+ expect(layers).toHaveLength(3);
63
+ });
64
+
65
+ it('returns a PolygonLayer for an ellipse', () => {
66
+ const shapes = [{ uid: 'e1', type: 'ellipse', x1: 0, y1: 0, radiusX: 50, radiusY: 30 }];
67
+ const layers = createAnnotationLayers(shapes, 0);
68
+ expect(layers).toHaveLength(1);
69
+ // 64-vertex polygon approximation
70
+ expect(layers[0].props.data[0].polygon).toHaveLength(64);
71
+ });
72
+
73
+ it('returns a PolygonLayer for a polygon with 3+ points', () => {
74
+ const shapes = [{ uid: 'p1', type: 'polygon', points: [[0, 0], [10, 0], [5, 10]] }];
75
+ const layers = createAnnotationLayers(shapes, 0);
76
+ expect(layers).toHaveLength(1);
77
+ });
78
+
79
+ it('skips a polygon with fewer than 3 points', () => {
80
+ const shapes = [{ uid: 'p2', type: 'polygon', points: [[0, 0], [10, 0]] }];
81
+ expect(createAnnotationLayers(shapes, 0)).toHaveLength(0);
82
+ });
83
+
84
+ it('returns a PathLayer for a polyline', () => {
85
+ const shapes = [{ uid: 'pl1', type: 'polyline', points: [[0, 0], [5, 5], [10, 0]] }];
86
+ const layers = createAnnotationLayers(shapes, 0);
87
+ expect(layers).toHaveLength(1);
88
+ });
89
+
90
+ it('returns PathLayer + arrowhead for polyline with markerEnd', () => {
91
+ const shapes = [{ uid: 'pl2', type: 'polyline', points: [[0, 0], [5, 5], [10, 0]], markerEnd: 'Arrow' }];
92
+ const layers = createAnnotationLayers(shapes, 0);
93
+ expect(layers).toHaveLength(2);
94
+ });
95
+
96
+ it('skips a polyline with fewer than 2 points', () => {
97
+ const shapes = [{ uid: 'pl3', type: 'polyline', points: [[0, 0]] }];
98
+ expect(createAnnotationLayers(shapes, 0)).toHaveLength(0);
99
+ });
100
+
101
+ it('adds PathStyleExtension to a rectangle when strokeDashArray is set', () => {
102
+ const shapes = [{ uid: 'r3', type: 'rectangle', x: 0, y: 0, width: 10, height: 10, strokeDashArray: '10 5' }];
103
+ const layers = createAnnotationLayers(shapes, 0);
104
+ expect(layers[0].props.extensions).toHaveLength(1);
105
+ expect(layers[0].props.getDashArray).toEqual([10, 5]);
106
+ });
107
+
108
+ it('does not set getDashArray when strokeDashArray is "none"', () => {
109
+ const shapes = [{ uid: 'r4', type: 'rectangle', x: 0, y: 0, width: 10, height: 10, strokeDashArray: 'none' }];
110
+ const layers = createAnnotationLayers(shapes, 0);
111
+ expect(layers[0].props.getDashArray).toBeUndefined();
112
+ });
113
+
114
+ it('uses only the first two values of a longer dash pattern', () => {
115
+ const shapes = [{ uid: 'r5', type: 'rectangle', x: 0, y: 0, width: 10, height: 10, strokeDashArray: '10 20 30 10' }];
116
+ const layers = createAnnotationLayers(shapes, 0);
117
+ expect(layers[0].props.getDashArray).toEqual([10, 20]);
118
+ });
119
+
120
+ it('returns null when no vertices', () => {
121
+ expect(createPreviewLayer({ type: 'rectangle', vertices: [] }, [5, 5])).toBeNull();
122
+ });
123
+
124
+ it('returns null when inProgress is null', () => {
125
+ expect(createPreviewLayer(null, [5, 5])).toBeNull();
126
+ });
127
+
128
+ it('returns a PathLayer preview for rectangle with one vertex + hover', () => {
129
+ const layer = createPreviewLayer({ type: 'rectangle', vertices: [[0, 0]] }, [10, 10]);
130
+ expect(layer).not.toBeNull();
131
+ expect(layer.props.data[0].path).toHaveLength(5); // 4 corners + close
132
+ });
133
+
134
+ it('returns a PathLayer preview for line with one vertex + hover', () => {
135
+ const layer = createPreviewLayer({ type: 'line', vertices: [[0, 0]] }, [10, 5]);
136
+ expect(layer).not.toBeNull();
137
+ expect(layer.props.data[0].path).toHaveLength(2);
138
+ });
139
+
140
+ it('returns a PathLayer for polygon preview that closes back to start', () => {
141
+ const layer = createPreviewLayer({ type: 'polygon', vertices: [[0, 0], [10, 0], [5, 10]] }, [3, 3]);
142
+ expect(layer).not.toBeNull();
143
+ const { path } = layer.props.data[0];
144
+ // vertices + cursor + close = 3 + 1 + 1 = 5
145
+ expect(path).toHaveLength(5);
146
+ // Last point closes to first vertex
147
+ expect(path[path.length - 1]).toEqual([0, 0]);
148
+ });
149
+
150
+ it('returns a PathLayer for polyline preview without closing', () => {
151
+ const layer = createPreviewLayer({ type: 'polyline', vertices: [[0, 0], [10, 0]] }, [15, 5]);
152
+ expect(layer).not.toBeNull();
153
+ const { path } = layer.props.data[0];
154
+ // vertices + cursor = 2 + 1 = 3 (no close)
155
+ expect(path).toHaveLength(3);
156
+ });
157
+
158
+ it('scales arrowhead size with zoom (larger at negative zoom)', () => {
159
+ // ARROW_SCREEN_PX=14, strokeWidth=1 so arrowScreenPx = max(14, 4) = 14
160
+ // zoom=0 → arrowDataSize = 14 / 2^0 = 14
161
+ // zoom=-3 → arrowDataSize = 14 / 2^(-3) = 14 * 8 = 112
162
+ const shape = { uid: 'l3', type: 'line', x1: 0, y1: 0, x2: 1000, y2: 0, markerEnd: 'Arrow' };
163
+
164
+ const layersZoom0 = createAnnotationLayers([shape], 0);
165
+ const layersZoomNeg3 = createAnnotationLayers([shape], -3);
166
+
167
+ const arrowAt0 = layersZoom0[1]; // arrowhead PolygonLayer
168
+ const arrowAtNeg3 = layersZoomNeg3[1];
169
+
170
+ // The arrowhead data (polygon vertices) should be further from the tip at zoom=-3
171
+ const tip0 = arrowAt0.props.data[0].polygon[0];
172
+ const base0 = arrowAt0.props.data[0].polygon[1];
173
+ const tip3 = arrowAtNeg3.props.data[0].polygon[0];
174
+ const base3 = arrowAtNeg3.props.data[0].polygon[1];
175
+
176
+ const size0 = Math.abs(tip0[0] - base0[0]);
177
+ const size3 = Math.abs(tip3[0] - base3[0]);
178
+ expect(size3).toBeGreaterThan(size0);
179
+ });
180
+ });
package/src/deck.js CHANGED
@@ -2,6 +2,7 @@ export { default as DeckGL } from 'deck.gl';
2
2
  export { COORDINATE_SYSTEM } from '@deck.gl/core';
3
3
  export {
4
4
  PolygonLayer,
5
+ PathLayer,
5
6
  TextLayer,
6
7
  ScatterplotLayer,
7
8
  LineLayer,
@@ -9,4 +10,4 @@ export {
9
10
  export { TileLayer } from '@deck.gl/geo-layers';
10
11
  export { OrthographicView, OrbitView } from '@deck.gl/core';
11
12
  export { ContourLayer } from '@deck.gl/aggregation-layers';
12
- export { DataFilterExtension } from '@deck.gl/extensions';
13
+ export { DataFilterExtension, PathStyleExtension } from '@deck.gl/extensions';
package/src/index.js CHANGED
@@ -18,6 +18,7 @@ export { default as SelectionExtension } from './SelectionExtension/index.js';
18
18
  export { default as BitmaskLayer } from './BitmaskLayer.js';
19
19
  export { default as BitmaskLayerBeta } from './BitmaskLayerBeta.js';
20
20
  export { default as ContourLayerWithText } from './ContourLayerWithText.js';
21
+ export { default as AnnotationLayer } from './AnnotationLayer.js';
21
22
 
22
23
  export {
23
24
  TILE_SIZE, MAX_ROW_AGG, MIN_ROW_AGG,
@@ -37,5 +38,6 @@ export * as viv from './viv.js';
37
38
  export * as luma from './luma.js';
38
39
  // eslint-disable-next-line react-refresh/only-export-components
39
40
  export * as deck from './deck.js';
41
+ export { createAnnotationLayers, createPreviewLayer, computeArrowhead, getMeasurementLabel } from './annotation-layer-utils.js';
40
42
  // eslint-disable-next-line react-refresh/only-export-components
41
43
  export * as math from './math.js';