@vitessce/vit-s 4.0.7 → 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 (42) hide show
  1. package/dist/index.js +560 -65
  2. package/dist-tsc/VitS.d.ts +3 -0
  3. package/dist-tsc/VitS.d.ts.map +1 -1
  4. package/dist-tsc/VitS.js +4 -2
  5. package/dist-tsc/VitS.js.map +1 -1
  6. package/dist-tsc/VitessceGrid.d.ts.map +1 -1
  7. package/dist-tsc/VitessceGrid.js +2 -2
  8. package/dist-tsc/VitessceGrid.js.map +1 -1
  9. package/dist-tsc/data-hooks.d.ts +13 -0
  10. package/dist-tsc/data-hooks.d.ts.map +1 -1
  11. package/dist-tsc/data-hooks.js +15 -0
  12. package/dist-tsc/data-hooks.js.map +1 -1
  13. package/dist-tsc/hooks.d.ts +6 -1
  14. package/dist-tsc/hooks.d.ts.map +1 -1
  15. package/dist-tsc/hooks.js +52 -22
  16. package/dist-tsc/hooks.js.map +1 -1
  17. package/dist-tsc/hooks.test.js +100 -3
  18. package/dist-tsc/hooks.test.js.map +1 -1
  19. package/dist-tsc/index.d.ts +2 -2
  20. package/dist-tsc/index.js +2 -2
  21. package/dist-tsc/index.js.map +1 -1
  22. package/dist-tsc/state/annotation-frames.test.d.ts +2 -0
  23. package/dist-tsc/state/annotation-frames.test.d.ts.map +1 -0
  24. package/dist-tsc/state/annotation-frames.test.js +171 -0
  25. package/dist-tsc/state/annotation-frames.test.js.map +1 -0
  26. package/dist-tsc/state/hooks.d.ts +101 -4
  27. package/dist-tsc/state/hooks.d.ts.map +1 -1
  28. package/dist-tsc/state/hooks.js +344 -13
  29. package/dist-tsc/state/hooks.js.map +1 -1
  30. package/dist-tsc/vitessce-grid-layout/VitessceGridLayout.d.ts.map +1 -1
  31. package/dist-tsc/vitessce-grid-layout/VitessceGridLayout.js +4 -4
  32. package/dist-tsc/vitessce-grid-layout/VitessceGridLayout.js.map +1 -1
  33. package/package.json +13 -13
  34. package/src/VitS.js +4 -0
  35. package/src/VitessceGrid.js +2 -0
  36. package/src/data-hooks.js +23 -0
  37. package/src/hooks.js +55 -23
  38. package/src/hooks.test.jsx +114 -3
  39. package/src/index.js +4 -0
  40. package/src/state/annotation-frames.test.js +185 -0
  41. package/src/state/hooks.js +395 -9
  42. package/src/vitessce-grid-layout/VitessceGridLayout.js +4 -2
@@ -0,0 +1,185 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { cloneDeep } from 'lodash-es';
3
+ import { applyAnnotationFrameToViewConfig, getAnnotationFrameUpdate } from './hooks.js';
4
+
5
+ function makeConfig() {
6
+ return {
7
+ coordinationSpace: {
8
+ spatialZoom: { A: -5 },
9
+ spatialTargetX: { A: 100 },
10
+ annotationShapes: { A: null, B: null },
11
+ imageLayer: { OLD_L: '__dummy__' },
12
+ fileUid: { OLD_L: 'img' },
13
+ metaCoordinationScopes: {
14
+ META: { imageLayer: ['OLD_L'] },
15
+ },
16
+ metaCoordinationScopesBy: {
17
+ META: {
18
+ imageLayer: { fileUid: { OLD_L: 'OLD_L' } },
19
+ },
20
+ },
21
+ },
22
+ layout: [
23
+ {
24
+ uid: 'spatial',
25
+ component: 'spatialBeta',
26
+ coordinationScopes: {
27
+ spatialZoom: 'A',
28
+ spatialTargetX: 'A',
29
+ annotationShapes: 'A',
30
+ metaCoordinationScopes: ['META'],
31
+ metaCoordinationScopesBy: ['META'],
32
+ },
33
+ coordinationValues: {
34
+ spatialTargetY: 7,
35
+ },
36
+ },
37
+ {
38
+ uid: 'layer-controller',
39
+ component: 'layerControllerBeta',
40
+ coordinationScopes: {
41
+ spatialZoom: 'A',
42
+ metaCoordinationScopes: ['META'],
43
+ metaCoordinationScopesBy: ['META'],
44
+ },
45
+ },
46
+ ],
47
+ };
48
+ }
49
+
50
+ describe('applyAnnotationFrameToViewConfig', () => {
51
+ it('writes single-level values into the scopes of the view', () => {
52
+ const shapes = [{ uid: 's1', type: 'rectangle', x: 0, y: 0, width: 1, height: 1 }];
53
+ const result = applyAnnotationFrameToViewConfig(makeConfig(), 'spatial', {
54
+ spatialZoom: -2,
55
+ annotationShapes: shapes,
56
+ }, 'prefix_');
57
+ expect(result.coordinationSpace.spatialZoom).toEqual({ A: -2 });
58
+ expect(result.coordinationSpace.spatialTargetX).toEqual({ A: 100 });
59
+ expect(result.coordinationSpace.annotationShapes).toEqual({ A: shapes, B: null });
60
+ });
61
+
62
+ it('writes values in-place when the view defines them directly', () => {
63
+ const result = applyAnnotationFrameToViewConfig(makeConfig(), 'spatial', {
64
+ spatialTargetY: 50,
65
+ }, 'prefix_');
66
+ expect(result.layout[0].coordinationValues).toEqual({ spatialTargetY: 50 });
67
+ expect(result.coordinationSpace.spatialTargetY).toBeUndefined();
68
+ });
69
+
70
+ it('writes values on the view when it is not mapped to a scope', () => {
71
+ const result = applyAnnotationFrameToViewConfig(makeConfig(), 'spatial', {
72
+ spatialRotationX: 30,
73
+ }, 'prefix_');
74
+ expect(result.layout[0].coordinationValues.spatialRotationX).toEqual(30);
75
+ });
76
+
77
+ it('expands multi-level values into new scopes and re-points the meta-coordination scopes', () => {
78
+ const result = applyAnnotationFrameToViewConfig(makeConfig(), 'spatial', {
79
+ imageLayer: {
80
+ $CL: [{
81
+ fileUid: 'img',
82
+ spatialLayerOpacity: 0.5,
83
+ imageChannel: {
84
+ $CL: [
85
+ { spatialTargetC: 0, spatialChannelColor: [255, 0, 0] },
86
+ { spatialTargetC: 2 },
87
+ ],
88
+ },
89
+ }],
90
+ },
91
+ }, 'prefix_');
92
+ const { coordinationSpace } = result;
93
+ // The meta scope shared with the layer controller now points to the new layer scopes.
94
+ const newLayerScopes = coordinationSpace.metaCoordinationScopes.META.imageLayer;
95
+ expect(newLayerScopes).toEqual(['prefix_0']);
96
+ expect(coordinationSpace.spatialLayerOpacity.prefix_0).toEqual(0.5);
97
+ const layerScopesBy = coordinationSpace.metaCoordinationScopesBy.META.imageLayer;
98
+ expect(layerScopesBy.imageChannel.prefix_0).toEqual(['prefix_0', 'prefix_1']);
99
+ const channelScopesBy = coordinationSpace.metaCoordinationScopesBy.META.imageChannel;
100
+ expect(coordinationSpace.spatialTargetC[channelScopesBy.spatialTargetC.prefix_1]).toEqual(2);
101
+ expect(coordinationSpace.spatialChannelColor[channelScopesBy.spatialChannelColor.prefix_0])
102
+ .toEqual([255, 0, 0]);
103
+ // The previous scopes remain in the coordination space, and the view mapping is unchanged.
104
+ expect(coordinationSpace.fileUid.OLD_L).toEqual('img');
105
+ expect(result.layout[0].coordinationScopes.metaCoordinationScopes).toEqual(['META']);
106
+ });
107
+
108
+ it('does not modify the input view config or frame values', () => {
109
+ const config = makeConfig();
110
+ const frameCoordinationValues = {
111
+ spatialZoom: -2,
112
+ imageLayer: { $CL: [{ fileUid: 'img' }] },
113
+ };
114
+ const configBefore = cloneDeep(config);
115
+ const frameBefore = cloneDeep(frameCoordinationValues);
116
+ applyAnnotationFrameToViewConfig(config, 'spatial', frameCoordinationValues, 'prefix_');
117
+ expect(config).toEqual(configBefore);
118
+ expect(frameCoordinationValues).toEqual(frameBefore);
119
+ });
120
+
121
+ it('returns the same view config when the view is not in the layout', () => {
122
+ const config = makeConfig();
123
+ expect(applyAnnotationFrameToViewConfig(config, 'other', { spatialZoom: 1 }, 'prefix_'))
124
+ .toBe(config);
125
+ });
126
+ });
127
+
128
+ describe('getAnnotationFrameUpdate', () => {
129
+ const story = {
130
+ uid: 'story',
131
+ frames: [
132
+ { uid: 'frame-0', layout: [{ uid: 'spatial', coordinationValues: { spatialZoom: -2 } }] },
133
+ { uid: 'frame-1' },
134
+ ],
135
+ };
136
+
137
+ it('returns the frame values for the view when a frame is active', () => {
138
+ expect(getAnnotationFrameUpdate(story, undefined, 0, 'spatial')).toEqual({
139
+ frameCoordinationValues: { annotationShapes: null, spatialZoom: -2 },
140
+ scopePrefix: 'annotation_story_frame-0_spatial_',
141
+ });
142
+ });
143
+
144
+ it('uses the annotationShapes of the frame when defined', () => {
145
+ const shapes = [{ uid: 's1', type: 'line', x1: 0, y1: 0, x2: 1, y2: 1 }];
146
+ const storyWithShapes = {
147
+ uid: 'story',
148
+ frames: [{ uid: 'frame-0', layout: [{ uid: 'spatial', coordinationValues: { annotationShapes: shapes } }] }],
149
+ };
150
+ expect(getAnnotationFrameUpdate(storyWithShapes, undefined, 0, 'spatial').frameCoordinationValues)
151
+ .toEqual({ annotationShapes: shapes });
152
+ });
153
+
154
+ it('clears annotationShapes when the active frame does not define them for the view', () => {
155
+ expect(getAnnotationFrameUpdate(story, 0, 1, 'spatial').frameCoordinationValues)
156
+ .toEqual({ annotationShapes: null });
157
+ expect(getAnnotationFrameUpdate(story, undefined, 0, 'scatterplot').frameCoordinationValues)
158
+ .toEqual({ annotationShapes: null });
159
+ });
160
+
161
+ it('does nothing when the story is not (yet) loaded', () => {
162
+ expect(getAnnotationFrameUpdate(null, undefined, 0, 'spatial')).toBeNull();
163
+ });
164
+
165
+ it('clears annotationShapes when the frame index becomes null', () => {
166
+ expect(getAnnotationFrameUpdate(story, 1, null, 'spatial')).toEqual({
167
+ frameCoordinationValues: { annotationShapes: null },
168
+ scopePrefix: '',
169
+ });
170
+ });
171
+
172
+ it('does nothing when the frame index is (and was) null', () => {
173
+ expect(getAnnotationFrameUpdate(story, undefined, null, 'spatial')).toBeNull();
174
+ expect(getAnnotationFrameUpdate(story, null, null, 'spatial')).toBeNull();
175
+ });
176
+
177
+ it('clears the shapes in the scope of the view when applied', () => {
178
+ const config = makeConfig();
179
+ config.coordinationSpace.annotationShapes.A = [{ uid: 's1', type: 'line', x1: 0, y1: 0, x2: 1, y2: 1 }];
180
+ const { frameCoordinationValues, scopePrefix } = getAnnotationFrameUpdate(story, 0, null, 'spatial');
181
+ const result = applyAnnotationFrameToViewConfig(config, 'spatial', frameCoordinationValues, scopePrefix);
182
+ expect(result.coordinationSpace.annotationShapes).toEqual({ A: null, B: null });
183
+ expect(result.coordinationSpace.spatialZoom).toEqual({ A: -5 });
184
+ });
185
+ });