@vitessce/neuroglancer 3.6.18 → 3.7.1
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/{ReactNeuroglancer-Crquekcy.js → ReactNeuroglancer-C0i-a6Cw.js} +717 -1268
- package/dist/{index-BNCfoEHv.js → index-w8xI9TWU.js} +2211 -478
- package/dist/index.js +1 -1
- package/dist-tsc/Neuroglancer.d.ts +5 -3
- package/dist-tsc/Neuroglancer.d.ts.map +1 -1
- package/dist-tsc/Neuroglancer.js +31 -72
- package/dist-tsc/NeuroglancerSubscriber.d.ts.map +1 -1
- package/dist-tsc/NeuroglancerSubscriber.js +329 -93
- package/dist-tsc/ReactNeuroglancer.d.ts +147 -2
- package/dist-tsc/ReactNeuroglancer.d.ts.map +1 -1
- package/dist-tsc/ReactNeuroglancer.js +819 -5
- package/dist-tsc/styles.d.ts.map +1 -1
- package/dist-tsc/styles.js +3 -1
- package/dist-tsc/utils.d.ts +41 -0
- package/dist-tsc/utils.d.ts.map +1 -0
- package/dist-tsc/utils.js +117 -0
- package/dist-tsc/utils.test.d.ts +2 -0
- package/dist-tsc/utils.test.d.ts.map +1 -0
- package/dist-tsc/utils.test.js +34 -0
- package/package.json +12 -12
- package/src/Neuroglancer.js +32 -91
- package/src/NeuroglancerSubscriber.js +400 -108
- package/src/ReactNeuroglancer.js +912 -6
- package/src/styles.js +3 -1
- package/src/utils.js +156 -0
- package/src/utils.test.js +44 -0
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export class
|
|
1
|
+
export class NeuroglancerComp {
|
|
2
2
|
constructor(props: any);
|
|
3
3
|
bundleRoot: any;
|
|
4
|
-
|
|
4
|
+
cellColorMapping: any;
|
|
5
5
|
justReceivedExternalUpdate: boolean;
|
|
6
6
|
prevElement: any;
|
|
7
7
|
prevClickHandler: ((event: any) => void) | null;
|
|
@@ -9,7 +9,9 @@ export class Neuroglancer {
|
|
|
9
9
|
prevHoverHandler: (() => void) | null;
|
|
10
10
|
onViewerStateChanged(nextState: any): void;
|
|
11
11
|
onRef(viewerRef: any): void;
|
|
12
|
-
|
|
12
|
+
latestOnSegmentClick: any;
|
|
13
|
+
latestOnSelectHoveredCoords: any;
|
|
14
|
+
componentDidUpdate(prevProps: any): void;
|
|
13
15
|
render(): JSX.Element;
|
|
14
16
|
}
|
|
15
17
|
//# sourceMappingURL=Neuroglancer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Neuroglancer.d.ts","sourceRoot":"","sources":["../src/Neuroglancer.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Neuroglancer.d.ts","sourceRoot":"","sources":["../src/Neuroglancer.js"],"names":[],"mappings":"AAUA;IACE,wBAcC;IAZC,gBAAgC;IAChC,sBAA8C;IAC9C,oCAAuC;IACvC,iBAAuB;IACvB,gDAA4B;IAC5B,2BAAiC;IACjC,sCAA4B;IAsD9B,2CAGC;IAjDD,4BA4CC;IAhDC,0BAAgD;IAChD,iCAA8D;IAsDhE,yCAQC;IAED,sBAoBC;CACF"}
|
package/dist-tsc/Neuroglancer.js
CHANGED
|
@@ -2,62 +2,16 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
2
2
|
/* eslint-disable react-refresh/only-export-components */
|
|
3
3
|
import React, { PureComponent, Suspense } from 'react';
|
|
4
4
|
import { ChunkWorker } from '@vitessce/neuroglancer-workers';
|
|
5
|
-
import { isEqualWith, pick } from 'lodash-es';
|
|
6
5
|
import { NeuroglancerGlobalStyles } from './styles.js';
|
|
7
6
|
const LazyReactNeuroglancer = React.lazy(() => import('./ReactNeuroglancer.js'));
|
|
8
7
|
function createWorker() {
|
|
9
8
|
return new ChunkWorker();
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
* Is this a valid viewerState object?
|
|
13
|
-
* @param {object} viewerState
|
|
14
|
-
* @returns {boolean}
|
|
15
|
-
*/
|
|
16
|
-
function isValidState(viewerState) {
|
|
17
|
-
const { projectionScale, projectionOrientation, position, dimensions } = viewerState || {};
|
|
18
|
-
return (dimensions !== undefined
|
|
19
|
-
&& typeof projectionScale === 'number'
|
|
20
|
-
&& Array.isArray(projectionOrientation)
|
|
21
|
-
&& projectionOrientation.length === 4
|
|
22
|
-
&& Array.isArray(position)
|
|
23
|
-
&& position.length === 3);
|
|
24
|
-
}
|
|
25
|
-
// TODO: Do we want to use the same epsilon value
|
|
26
|
-
// for every viewstate property being compared?
|
|
27
|
-
const EPSILON = 1e-7;
|
|
28
|
-
const VIEWSTATE_KEYS = ['projectionScale', 'projectionOrientation', 'position'];
|
|
29
|
-
// Custom numeric comparison function
|
|
30
|
-
// for isEqualWith, to be able to set a custom epsilon.
|
|
31
|
-
function customizer(a, b) {
|
|
32
|
-
if (typeof a === 'number' && typeof b === 'number') {
|
|
33
|
-
// Returns true if the values are equivalent, else false.
|
|
34
|
-
return Math.abs(a - b) > EPSILON;
|
|
35
|
-
}
|
|
36
|
-
// Return undefined to fallback to the default
|
|
37
|
-
// comparison function.
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Returns true if the two states are equal, or false if not.
|
|
42
|
-
* @param {object} prevState Previous viewer state.
|
|
43
|
-
* @param {object} nextState Next viewer state.
|
|
44
|
-
* @returns
|
|
45
|
-
*/
|
|
46
|
-
function compareViewerState(prevState, nextState) {
|
|
47
|
-
if (isValidState(nextState)) {
|
|
48
|
-
// Subset the viewerState objects to only the keys
|
|
49
|
-
// that we want to use for comparison.
|
|
50
|
-
const prevSubset = pick(prevState, VIEWSTATE_KEYS);
|
|
51
|
-
const nextSubset = pick(nextState, VIEWSTATE_KEYS);
|
|
52
|
-
return isEqualWith(prevSubset, nextSubset, customizer);
|
|
53
|
-
}
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
export class Neuroglancer extends PureComponent {
|
|
10
|
+
export class NeuroglancerComp extends PureComponent {
|
|
57
11
|
constructor(props) {
|
|
58
12
|
super(props);
|
|
59
13
|
this.bundleRoot = createWorker();
|
|
60
|
-
this.
|
|
14
|
+
this.cellColorMapping = props.cellColorMapping;
|
|
61
15
|
this.justReceivedExternalUpdate = false;
|
|
62
16
|
this.prevElement = null;
|
|
63
17
|
this.prevClickHandler = null;
|
|
@@ -65,65 +19,70 @@ export class Neuroglancer extends PureComponent {
|
|
|
65
19
|
this.prevHoverHandler = null;
|
|
66
20
|
this.onViewerStateChanged = this.onViewerStateChanged.bind(this);
|
|
67
21
|
this.onRef = this.onRef.bind(this);
|
|
22
|
+
// To avoid closure for onSegmentClick(), to update the selection
|
|
23
|
+
this.latestOnSegmentClick = props.onSegmentClick;
|
|
24
|
+
this.latestOnSelectHoveredCoords = props.onSelectHoveredCoords;
|
|
68
25
|
}
|
|
69
26
|
onRef(viewerRef) {
|
|
70
27
|
// Here, we have access to the viewerRef.viewer object,
|
|
71
28
|
// which we can use to add/remove event handlers.
|
|
72
|
-
const { onSegmentClick, onSelectHoveredCoords, } = this.props;
|
|
73
29
|
if (viewerRef) {
|
|
74
30
|
// Mount
|
|
75
31
|
const { viewer } = viewerRef;
|
|
76
32
|
this.prevElement = viewer.element;
|
|
77
33
|
this.prevMouseStateChanged = viewer.mouseState.changed;
|
|
34
|
+
viewer.inputEventBindings.sliceView.set('at:dblclick0', () => { });
|
|
35
|
+
viewer.inputEventBindings.perspectiveView.set('at:dblclick0', () => { });
|
|
78
36
|
this.prevClickHandler = (event) => {
|
|
79
37
|
if (event.button === 0) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
38
|
+
// Wait for mouseState to update
|
|
39
|
+
requestAnimationFrame(() => {
|
|
40
|
+
const { pickedValue, pickedRenderLayer } = viewer.mouseState;
|
|
41
|
+
// Only trigger selection when a segment is clicked rather than any click on the view
|
|
42
|
+
if (pickedValue && pickedValue.low !== undefined && pickedRenderLayer) {
|
|
43
|
+
this.latestOnSegmentClick?.(pickedValue.low);
|
|
84
44
|
}
|
|
85
|
-
}
|
|
45
|
+
});
|
|
86
46
|
}
|
|
87
47
|
};
|
|
88
|
-
viewer.element.addEventListener('mousedown', this.prevClickHandler);
|
|
89
48
|
this.prevHoverHandler = () => {
|
|
90
49
|
if (viewer.mouseState.pickedValue !== undefined) {
|
|
91
50
|
const pickedSegment = viewer.mouseState.pickedValue;
|
|
92
|
-
|
|
51
|
+
this.latestOnSelectHoveredCoords?.(pickedSegment?.low);
|
|
93
52
|
}
|
|
94
53
|
};
|
|
54
|
+
viewer.element.addEventListener('mouseup', this.prevClickHandler);
|
|
95
55
|
viewer.mouseState.changed.add(this.prevHoverHandler);
|
|
96
56
|
}
|
|
97
57
|
else {
|
|
98
58
|
// Unmount (viewerRef is null)
|
|
99
59
|
if (this.prevElement && this.prevClickHandler) {
|
|
100
|
-
this.prevElement.removeEventListener('
|
|
60
|
+
this.prevElement.removeEventListener('mouseup', this.prevClickHandler);
|
|
61
|
+
this.prevClickHandler = null;
|
|
101
62
|
}
|
|
102
63
|
if (this.prevMouseStateChanged && this.prevHoverHandler) {
|
|
103
64
|
this.prevMouseStateChanged.remove(this.prevHoverHandler);
|
|
65
|
+
this.prevHoverHandler = null;
|
|
104
66
|
}
|
|
67
|
+
this.prevElement = null;
|
|
68
|
+
this.prevMouseStateChanged = null;
|
|
105
69
|
}
|
|
106
70
|
}
|
|
107
71
|
onViewerStateChanged(nextState) {
|
|
108
72
|
const { setViewerState } = this.props;
|
|
109
|
-
|
|
110
|
-
if (!this.justReceivedExternalUpdate && !compareViewerState(prevState, nextState)) {
|
|
111
|
-
this.viewerState = nextState;
|
|
112
|
-
this.justReceivedExternalUpdate = false;
|
|
113
|
-
setViewerState(nextState);
|
|
114
|
-
}
|
|
73
|
+
setViewerState(nextState);
|
|
115
74
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
this.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
75
|
+
componentDidUpdate(prevProps) {
|
|
76
|
+
const { onSegmentClick, onSelectHoveredCoords } = this.props;
|
|
77
|
+
if (prevProps.onSegmentClick !== onSegmentClick) {
|
|
78
|
+
this.latestOnSegmentClick = onSegmentClick;
|
|
79
|
+
}
|
|
80
|
+
if (prevProps.onSelectHoveredCoords !== onSelectHoveredCoords) {
|
|
81
|
+
this.latestOnSelectHoveredCoords = onSelectHoveredCoords;
|
|
123
82
|
}
|
|
124
83
|
}
|
|
125
84
|
render() {
|
|
126
|
-
const { classes, } = this.props;
|
|
127
|
-
return (_jsxs(_Fragment, { children: [_jsx(NeuroglancerGlobalStyles, { classes: classes }), _jsx("div", { className: classes.neuroglancerWrapper, children: _jsx(Suspense, { fallback: _jsx("div", { children: "Loading..." }), children: _jsx(LazyReactNeuroglancer, { brainMapsClientId: "NOT_A_VALID_ID", viewerState:
|
|
85
|
+
const { classes, viewerState, cellColorMapping } = this.props;
|
|
86
|
+
return (_jsxs(_Fragment, { children: [_jsx(NeuroglancerGlobalStyles, { classes: classes }), _jsx("div", { className: classes.neuroglancerWrapper, children: _jsx(Suspense, { fallback: _jsx("div", { children: "Loading..." }), children: _jsx(LazyReactNeuroglancer, { brainMapsClientId: "NOT_A_VALID_ID", viewerState: viewerState, onViewerStateChanged: this.onViewerStateChanged, bundleRoot: this.bundleRoot, cellColorMapping: cellColorMapping, ref: this.onRef }) }) })] }));
|
|
128
87
|
}
|
|
129
88
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NeuroglancerSubscriber.d.ts","sourceRoot":"","sources":["../src/NeuroglancerSubscriber.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"NeuroglancerSubscriber.d.ts","sourceRoot":"","sources":["../src/NeuroglancerSubscriber.js"],"names":[],"mappings":"AAiDA,gEA2dC"}
|