@vitessce/utils 4.0.10 → 4.1.0
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.js +9 -0
- package/dist-tsc/annotation.d.ts +23 -0
- package/dist-tsc/annotation.d.ts.map +1 -1
- package/dist-tsc/annotation.js +24 -0
- package/dist-tsc/annotation.js.map +1 -1
- package/dist-tsc/annotation.test.js +21 -1
- package/dist-tsc/annotation.test.js.map +1 -1
- package/dist-tsc/index.d.ts +1 -1
- package/dist-tsc/index.d.ts.map +1 -1
- package/dist-tsc/index.js +1 -1
- package/dist-tsc/index.js.map +1 -1
- package/package.json +2 -2
- package/src/annotation.test.ts +46 -1
- package/src/annotation.ts +42 -0
- package/src/index.ts +4 -1
package/dist/index.js
CHANGED
|
@@ -1007,6 +1007,14 @@ function getAnnotationFrameCoordinationValues(annotationStory, annotationFrameIn
|
|
|
1007
1007
|
}
|
|
1008
1008
|
return annotationStory?.frames?.[annotationFrameIndex]?.layout?.find((v) => v.uid === viewUid)?.coordinationValues;
|
|
1009
1009
|
}
|
|
1010
|
+
const TRANSITION_VIEW_STATE_KEYS = ["zoom", "targetX", "targetY"];
|
|
1011
|
+
function isAnnotationFrameViewStateChange(prevViewState, nextViewState, frameViewState) {
|
|
1012
|
+
if (!frameViewState) {
|
|
1013
|
+
return false;
|
|
1014
|
+
}
|
|
1015
|
+
const changedKeys = TRANSITION_VIEW_STATE_KEYS.filter((key) => prevViewState[key] !== nextViewState[key]);
|
|
1016
|
+
return changedKeys.length > 0 && changedKeys.every((key) => typeof prevViewState[key] === "number" && typeof nextViewState[key] === "number" && frameViewState[key] === nextViewState[key]);
|
|
1017
|
+
}
|
|
1010
1018
|
export {
|
|
1011
1019
|
COLORMAP_OPTIONS,
|
|
1012
1020
|
DEFAULT_DARK_COLOR,
|
|
@@ -1048,6 +1056,7 @@ export {
|
|
|
1048
1056
|
getNextScope,
|
|
1049
1057
|
getNextScopeNumeric,
|
|
1050
1058
|
getValueTransformFunction,
|
|
1059
|
+
isAnnotationFrameViewStateChange,
|
|
1051
1060
|
normalizeAggregatedFeatureArray,
|
|
1052
1061
|
pluralize,
|
|
1053
1062
|
unnestMap
|
package/dist-tsc/annotation.d.ts
CHANGED
|
@@ -17,5 +17,28 @@ type AnnotationStory = {
|
|
|
17
17
|
* or undefined if no frame is active or the frame does not include the view.
|
|
18
18
|
*/
|
|
19
19
|
export declare function getAnnotationFrameCoordinationValues(annotationStory: AnnotationStory | null | undefined, annotationFrameIndex: number | null | undefined, viewUid: string): Record<string, unknown> | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* The 2D view state values which can be animated
|
|
22
|
+
* when transitioning between annotation frames.
|
|
23
|
+
*/
|
|
24
|
+
export type AnnotationTransitionViewState = {
|
|
25
|
+
zoom: number | null | undefined;
|
|
26
|
+
targetX: number | null | undefined;
|
|
27
|
+
targetY: number | null | undefined;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Determine whether a change in the view state was caused by
|
|
31
|
+
* applying the current annotation frame (as opposed to, e.g., the user
|
|
32
|
+
* panning/zooming, or a linked view), and should therefore be animated.
|
|
33
|
+
* The change is attributed to the frame when at least one value changed,
|
|
34
|
+
* and every value that changed is defined by the frame and
|
|
35
|
+
* now matches the frame's value.
|
|
36
|
+
* @param prevViewState The previous view state values.
|
|
37
|
+
* @param nextViewState The next view state values.
|
|
38
|
+
* @param frameViewState The view state values that the current frame defines
|
|
39
|
+
* for the view. Values which the frame does not define should be undefined.
|
|
40
|
+
* @returns Whether the change should be animated.
|
|
41
|
+
*/
|
|
42
|
+
export declare function isAnnotationFrameViewStateChange(prevViewState: AnnotationTransitionViewState, nextViewState: AnnotationTransitionViewState, frameViewState: Partial<AnnotationTransitionViewState> | null | undefined): boolean;
|
|
20
43
|
export {};
|
|
21
44
|
//# sourceMappingURL=annotation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"annotation.d.ts","sourceRoot":"","sources":["../src/annotation.ts"],"names":[],"mappings":"AAAA,KAAK,mBAAmB,GAAG;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC9C,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,MAAM,CAAC,EAAE,mBAAmB,EAAE,CAAA;KAAE,CAAC,CAAC;CACpD,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,oCAAoC,CAClD,eAAe,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,EACnD,oBAAoB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC/C,OAAO,EAAE,MAAM,GACd,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAOrC"}
|
|
1
|
+
{"version":3,"file":"annotation.d.ts","sourceRoot":"","sources":["../src/annotation.ts"],"names":[],"mappings":"AAAA,KAAK,mBAAmB,GAAG;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC9C,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,MAAM,CAAC,EAAE,mBAAmB,EAAE,CAAA;KAAE,CAAC,CAAC;CACpD,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,oCAAoC,CAClD,eAAe,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,EACnD,oBAAoB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC/C,OAAO,EAAE,MAAM,GACd,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAOrC;AAED;;;GAGG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC1C,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAChC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACnC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CACpC,CAAC;AAIF;;;;;;;;;;;;GAYG;AACH,wBAAgB,gCAAgC,CAC9C,aAAa,EAAE,6BAA6B,EAC5C,aAAa,EAAE,6BAA6B,EAC5C,cAAc,EAAE,OAAO,CAAC,6BAA6B,CAAC,GAAG,IAAI,GAAG,SAAS,GACxE,OAAO,CAWT"}
|
package/dist-tsc/annotation.js
CHANGED
|
@@ -15,4 +15,28 @@ export function getAnnotationFrameCoordinationValues(annotationStory, annotation
|
|
|
15
15
|
?.find(v => v.uid === viewUid)
|
|
16
16
|
?.coordinationValues;
|
|
17
17
|
}
|
|
18
|
+
const TRANSITION_VIEW_STATE_KEYS = ['zoom', 'targetX', 'targetY'];
|
|
19
|
+
/**
|
|
20
|
+
* Determine whether a change in the view state was caused by
|
|
21
|
+
* applying the current annotation frame (as opposed to, e.g., the user
|
|
22
|
+
* panning/zooming, or a linked view), and should therefore be animated.
|
|
23
|
+
* The change is attributed to the frame when at least one value changed,
|
|
24
|
+
* and every value that changed is defined by the frame and
|
|
25
|
+
* now matches the frame's value.
|
|
26
|
+
* @param prevViewState The previous view state values.
|
|
27
|
+
* @param nextViewState The next view state values.
|
|
28
|
+
* @param frameViewState The view state values that the current frame defines
|
|
29
|
+
* for the view. Values which the frame does not define should be undefined.
|
|
30
|
+
* @returns Whether the change should be animated.
|
|
31
|
+
*/
|
|
32
|
+
export function isAnnotationFrameViewStateChange(prevViewState, nextViewState, frameViewState) {
|
|
33
|
+
if (!frameViewState) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
const changedKeys = TRANSITION_VIEW_STATE_KEYS
|
|
37
|
+
.filter(key => prevViewState[key] !== nextViewState[key]);
|
|
38
|
+
return changedKeys.length > 0 && changedKeys.every(key => (typeof prevViewState[key] === 'number'
|
|
39
|
+
&& typeof nextViewState[key] === 'number'
|
|
40
|
+
&& frameViewState[key] === nextViewState[key]));
|
|
41
|
+
}
|
|
18
42
|
//# sourceMappingURL=annotation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"annotation.js","sourceRoot":"","sources":["../src/annotation.ts"],"names":[],"mappings":"AASA;;;;;;;;GAQG;AACH,MAAM,UAAU,oCAAoC,CAClD,eAAmD,EACnD,oBAA+C,EAC/C,OAAe;IAEf,IAAI,OAAO,oBAAoB,KAAK,QAAQ,EAAE,CAAC;QAC7C,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,eAAe,EAAE,MAAM,EAAE,CAAC,oBAAoB,CAAC,EAAE,MAAM;QAC5D,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,OAAO,CAAC;QAC9B,EAAE,kBAAkB,CAAC;AACzB,CAAC"}
|
|
1
|
+
{"version":3,"file":"annotation.js","sourceRoot":"","sources":["../src/annotation.ts"],"names":[],"mappings":"AASA;;;;;;;;GAQG;AACH,MAAM,UAAU,oCAAoC,CAClD,eAAmD,EACnD,oBAA+C,EAC/C,OAAe;IAEf,IAAI,OAAO,oBAAoB,KAAK,QAAQ,EAAE,CAAC;QAC7C,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,eAAe,EAAE,MAAM,EAAE,CAAC,oBAAoB,CAAC,EAAE,MAAM;QAC5D,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,OAAO,CAAC;QAC9B,EAAE,kBAAkB,CAAC;AACzB,CAAC;AAYD,MAAM,0BAA0B,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,CAAU,CAAC;AAE3E;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,gCAAgC,CAC9C,aAA4C,EAC5C,aAA4C,EAC5C,cAAyE;IAEzE,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,WAAW,GAAG,0BAA0B;SAC3C,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5D,OAAO,WAAW,CAAC,MAAM,GAAG,CAAC,IAAI,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CACxD,OAAO,aAAa,CAAC,GAAG,CAAC,KAAK,QAAQ;WACnC,OAAO,aAAa,CAAC,GAAG,CAAC,KAAK,QAAQ;WACtC,cAAc,CAAC,GAAG,CAAC,KAAK,aAAa,CAAC,GAAG,CAAC,CAC9C,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { getAnnotationFrameCoordinationValues } from './annotation.js';
|
|
2
|
+
import { getAnnotationFrameCoordinationValues, isAnnotationFrameViewStateChange, } from './annotation.js';
|
|
3
3
|
const story = {
|
|
4
4
|
uid: 'story',
|
|
5
5
|
frames: [
|
|
@@ -26,4 +26,24 @@ describe('getAnnotationFrameCoordinationValues', () => {
|
|
|
26
26
|
expect(getAnnotationFrameCoordinationValues(null, 0, 'spatial')).toBeUndefined();
|
|
27
27
|
});
|
|
28
28
|
});
|
|
29
|
+
describe('isAnnotationFrameViewStateChange', () => {
|
|
30
|
+
const prev = { zoom: 0, targetX: 10, targetY: 20 };
|
|
31
|
+
it('returns true when the changed values match the frame values', () => {
|
|
32
|
+
expect(isAnnotationFrameViewStateChange(prev, { zoom: -2, targetX: 5, targetY: 20 }, { zoom: -2, targetX: 5, targetY: undefined })).toBe(true);
|
|
33
|
+
});
|
|
34
|
+
it('returns false when a changed value is not defined by the frame', () => {
|
|
35
|
+
// E.g., the user panned while a frame which only defines zoom is active.
|
|
36
|
+
expect(isAnnotationFrameViewStateChange(prev, { zoom: 0, targetX: 11, targetY: 20 }, { zoom: 0, targetX: undefined, targetY: undefined })).toBe(false);
|
|
37
|
+
});
|
|
38
|
+
it('returns false when a changed value does not match the frame value', () => {
|
|
39
|
+
expect(isAnnotationFrameViewStateChange(prev, { zoom: -1, targetX: 10, targetY: 20 }, { zoom: -2, targetX: undefined, targetY: undefined })).toBe(false);
|
|
40
|
+
});
|
|
41
|
+
it('returns false when nothing changed or no frame is active', () => {
|
|
42
|
+
expect(isAnnotationFrameViewStateChange(prev, { ...prev }, { zoom: 0 })).toBe(false);
|
|
43
|
+
expect(isAnnotationFrameViewStateChange(prev, { ...prev, zoom: -2 }, null)).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
it('returns false when the previous value was not initialized', () => {
|
|
46
|
+
expect(isAnnotationFrameViewStateChange({ zoom: null, targetX: null, targetY: null }, { zoom: -2, targetX: 5, targetY: 6 }, { zoom: -2, targetX: 5, targetY: 6 })).toBe(false);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
29
49
|
//# sourceMappingURL=annotation.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"annotation.test.js","sourceRoot":"","sources":["../src/annotation.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,
|
|
1
|
+
{"version":3,"file":"annotation.test.js","sourceRoot":"","sources":["../src/annotation.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EACL,oCAAoC,EACpC,gCAAgC,GACjC,MAAM,iBAAiB,CAAC;AAEzB,MAAM,KAAK,GAAG;IACZ,GAAG,EAAE,OAAO;IACZ,MAAM,EAAE;QACN;YACE,GAAG,EAAE,SAAS;YACd,MAAM,EAAE;gBACN,EAAE,GAAG,EAAE,SAAS,EAAE,kBAAkB,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE;aAC5D;SACF;QACD,EAAE,GAAG,EAAE,SAAS,EAAE;K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,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAC5C,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,EACpC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CACrC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist-tsc/index.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export { getValueTransformFunction, VALUE_TRANSFORM_OPTIONS, } from './gating.js
|
|
|
4
4
|
export { default as Pool } from './Pool.js';
|
|
5
5
|
export { DEFAULT_MAX_ALLOCATION_BYTES, getJsHeapSizeLimit, getAllocationBudgetBytes, exceedsAllocationBudget, } from './memory.js';
|
|
6
6
|
export { aggregateFeatureArrays, normalizeAggregatedFeatureArray, filterValidExpressionArrays, } from './expr.js';
|
|
7
|
-
export { getAnnotationFrameCoordinationValues } from './annotation.js';
|
|
7
|
+
export { getAnnotationFrameCoordinationValues, isAnnotationFrameViewStateChange, } from './annotation.js';
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist-tsc/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,UAAU,EACV,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,EACnB,iCAAiC,EACjC,iCAAiC,EACjC,+BAA+B,EAC/B,SAAS,EACT,yBAAyB,GAC1B,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,yBAAyB,EACzB,OAAO,EACP,cAAc,EACd,iBAAiB,EACjB,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,EAClB,yBAAyB,EACzB,iCAAiC,EACjC,6BAA6B,EAC7B,6BAA6B,EAC7B,8BAA8B,EAC9B,2BAA2B,EAC3B,4BAA4B,EAC5B,cAAc,EACd,UAAU,EACV,WAAW,GACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,sBAAsB,EACtB,+BAA+B,EAC/B,2BAA2B,GAC5B,MAAM,WAAW,CAAC;AACnB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,UAAU,EACV,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,EACnB,iCAAiC,EACjC,iCAAiC,EACjC,+BAA+B,EAC/B,SAAS,EACT,yBAAyB,GAC1B,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,yBAAyB,EACzB,OAAO,EACP,cAAc,EACd,iBAAiB,EACjB,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,EAClB,yBAAyB,EACzB,iCAAiC,EACjC,6BAA6B,EAC7B,6BAA6B,EAC7B,8BAA8B,EAC9B,2BAA2B,EAC3B,4BAA4B,EAC5B,cAAc,EACd,UAAU,EACV,WAAW,GACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,sBAAsB,EACtB,+BAA+B,EAC/B,2BAA2B,GAC5B,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,oCAAoC,EACpC,gCAAgC,GACjC,MAAM,iBAAiB,CAAC"}
|
package/dist-tsc/index.js
CHANGED
|
@@ -6,5 +6,5 @@ export { getValueTransformFunction, VALUE_TRANSFORM_OPTIONS, } from './gating.js
|
|
|
6
6
|
export { default as Pool } from './Pool.js';
|
|
7
7
|
export { DEFAULT_MAX_ALLOCATION_BYTES, getJsHeapSizeLimit, getAllocationBudgetBytes, exceedsAllocationBudget, } from './memory.js';
|
|
8
8
|
export { aggregateFeatureArrays, normalizeAggregatedFeatureArray, filterValidExpressionArrays, } from './expr.js';
|
|
9
|
-
export { getAnnotationFrameCoordinationValues } from './annotation.js';
|
|
9
|
+
export { getAnnotationFrameCoordinationValues, isAnnotationFrameViewStateChange, } from './annotation.js';
|
|
10
10
|
//# sourceMappingURL=index.js.map
|
package/dist-tsc/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,OAAO,EACL,WAAW,EACX,UAAU,EACV,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,EACnB,iCAAiC,EACjC,iCAAiC,EACjC,+BAA+B,EAC/B,SAAS,EACT,yBAAyB,GAC1B,MAAM,WAAW,CAAC;AACnB,gEAAgE;AAChE,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,yBAAyB,EACzB,OAAO,EACP,cAAc,EACd,iBAAiB,EACjB,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,EAClB,yBAAyB,EACzB,iCAAiC,EACjC,6BAA6B,EAC7B,6BAA6B,EAC7B,8BAA8B,EAC9B,2BAA2B,EAC3B,4BAA4B,EAC5B,cAAc,EACd,UAAU,EACV,WAAW,GACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,sBAAsB,EACtB,+BAA+B,EAC/B,2BAA2B,GAC5B,MAAM,WAAW,CAAC;AACnB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,OAAO,EACL,WAAW,EACX,UAAU,EACV,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,EACnB,iCAAiC,EACjC,iCAAiC,EACjC,+BAA+B,EAC/B,SAAS,EACT,yBAAyB,GAC1B,MAAM,WAAW,CAAC;AACnB,gEAAgE;AAChE,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,yBAAyB,EACzB,OAAO,EACP,cAAc,EACd,iBAAiB,EACjB,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,EAClB,yBAAyB,EACzB,iCAAiC,EACjC,6BAA6B,EAC7B,6BAA6B,EAC7B,8BAA8B,EAC9B,2BAA2B,EAC3B,4BAA4B,EAC5B,cAAc,EACd,UAAU,EACV,WAAW,GACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,sBAAsB,EACtB,+BAA+B,EAC/B,2BAA2B,GAC5B,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,oCAAoC,EACpC,gCAAgC,GACjC,MAAM,iBAAiB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitessce/utils",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"author": "HIDIVE Lab at HMS",
|
|
5
5
|
"homepage": "http://vitessce.io",
|
|
6
6
|
"repository": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"lz-string": "^1.4.4",
|
|
22
22
|
"pluralize": "^8.0.0",
|
|
23
23
|
"d3-array": "^2.4.0",
|
|
24
|
-
"@vitessce/globals": "4.0
|
|
24
|
+
"@vitessce/globals": "4.1.0"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
27
|
"bundle": "pnpm exec vite build -c ../../../scripts/vite.config.mjs",
|
package/src/annotation.test.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
getAnnotationFrameCoordinationValues,
|
|
4
|
+
isAnnotationFrameViewStateChange,
|
|
5
|
+
} from './annotation.js';
|
|
3
6
|
|
|
4
7
|
const story = {
|
|
5
8
|
uid: 'story',
|
|
@@ -30,3 +33,45 @@ describe('getAnnotationFrameCoordinationValues', () => {
|
|
|
30
33
|
expect(getAnnotationFrameCoordinationValues(null, 0, 'spatial')).toBeUndefined();
|
|
31
34
|
});
|
|
32
35
|
});
|
|
36
|
+
|
|
37
|
+
describe('isAnnotationFrameViewStateChange', () => {
|
|
38
|
+
const prev = { zoom: 0, targetX: 10, targetY: 20 };
|
|
39
|
+
|
|
40
|
+
it('returns true when the changed values match the frame values', () => {
|
|
41
|
+
expect(isAnnotationFrameViewStateChange(
|
|
42
|
+
prev,
|
|
43
|
+
{ zoom: -2, targetX: 5, targetY: 20 },
|
|
44
|
+
{ zoom: -2, targetX: 5, targetY: undefined },
|
|
45
|
+
)).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('returns false when a changed value is not defined by the frame', () => {
|
|
49
|
+
// E.g., the user panned while a frame which only defines zoom is active.
|
|
50
|
+
expect(isAnnotationFrameViewStateChange(
|
|
51
|
+
prev,
|
|
52
|
+
{ zoom: 0, targetX: 11, targetY: 20 },
|
|
53
|
+
{ zoom: 0, targetX: undefined, targetY: undefined },
|
|
54
|
+
)).toBe(false);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('returns false when a changed value does not match the frame value', () => {
|
|
58
|
+
expect(isAnnotationFrameViewStateChange(
|
|
59
|
+
prev,
|
|
60
|
+
{ zoom: -1, targetX: 10, targetY: 20 },
|
|
61
|
+
{ zoom: -2, targetX: undefined, targetY: undefined },
|
|
62
|
+
)).toBe(false);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('returns false when nothing changed or no frame is active', () => {
|
|
66
|
+
expect(isAnnotationFrameViewStateChange(prev, { ...prev }, { zoom: 0 })).toBe(false);
|
|
67
|
+
expect(isAnnotationFrameViewStateChange(prev, { ...prev, zoom: -2 }, null)).toBe(false);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('returns false when the previous value was not initialized', () => {
|
|
71
|
+
expect(isAnnotationFrameViewStateChange(
|
|
72
|
+
{ zoom: null, targetX: null, targetY: null },
|
|
73
|
+
{ zoom: -2, targetX: 5, targetY: 6 },
|
|
74
|
+
{ zoom: -2, targetX: 5, targetY: 6 },
|
|
75
|
+
)).toBe(false);
|
|
76
|
+
});
|
|
77
|
+
});
|
package/src/annotation.ts
CHANGED
|
@@ -28,3 +28,45 @@ export function getAnnotationFrameCoordinationValues(
|
|
|
28
28
|
?.find(v => v.uid === viewUid)
|
|
29
29
|
?.coordinationValues;
|
|
30
30
|
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The 2D view state values which can be animated
|
|
34
|
+
* when transitioning between annotation frames.
|
|
35
|
+
*/
|
|
36
|
+
export type AnnotationTransitionViewState = {
|
|
37
|
+
zoom: number | null | undefined;
|
|
38
|
+
targetX: number | null | undefined;
|
|
39
|
+
targetY: number | null | undefined;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const TRANSITION_VIEW_STATE_KEYS = ['zoom', 'targetX', 'targetY'] as const;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Determine whether a change in the view state was caused by
|
|
46
|
+
* applying the current annotation frame (as opposed to, e.g., the user
|
|
47
|
+
* panning/zooming, or a linked view), and should therefore be animated.
|
|
48
|
+
* The change is attributed to the frame when at least one value changed,
|
|
49
|
+
* and every value that changed is defined by the frame and
|
|
50
|
+
* now matches the frame's value.
|
|
51
|
+
* @param prevViewState The previous view state values.
|
|
52
|
+
* @param nextViewState The next view state values.
|
|
53
|
+
* @param frameViewState The view state values that the current frame defines
|
|
54
|
+
* for the view. Values which the frame does not define should be undefined.
|
|
55
|
+
* @returns Whether the change should be animated.
|
|
56
|
+
*/
|
|
57
|
+
export function isAnnotationFrameViewStateChange(
|
|
58
|
+
prevViewState: AnnotationTransitionViewState,
|
|
59
|
+
nextViewState: AnnotationTransitionViewState,
|
|
60
|
+
frameViewState: Partial<AnnotationTransitionViewState> | null | undefined,
|
|
61
|
+
): boolean {
|
|
62
|
+
if (!frameViewState) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
const changedKeys = TRANSITION_VIEW_STATE_KEYS
|
|
66
|
+
.filter(key => prevViewState[key] !== nextViewState[key]);
|
|
67
|
+
return changedKeys.length > 0 && changedKeys.every(key => (
|
|
68
|
+
typeof prevViewState[key] === 'number'
|
|
69
|
+
&& typeof nextViewState[key] === 'number'
|
|
70
|
+
&& frameViewState[key] === nextViewState[key]
|
|
71
|
+
));
|
|
72
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -52,4 +52,7 @@ export {
|
|
|
52
52
|
normalizeAggregatedFeatureArray,
|
|
53
53
|
filterValidExpressionArrays,
|
|
54
54
|
} from './expr.js';
|
|
55
|
-
export {
|
|
55
|
+
export {
|
|
56
|
+
getAnnotationFrameCoordinationValues,
|
|
57
|
+
isAnnotationFrameViewStateChange,
|
|
58
|
+
} from './annotation.js';
|