@vitessce/scatterplot 2.0.3 → 3.0.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/{deflate.65a17097.mjs → deflate-24a61b7a.js} +2 -2
- package/dist/{index.8206952d.mjs → index-d78d4568.js} +61450 -51757
- package/dist/{index.mjs → index.js} +5 -5
- package/dist/{jpeg.4221d32f.mjs → jpeg-19791032.js} +1 -1
- package/dist/{lerc.8d649494.mjs → lerc-867fd2ef.js} +76 -5
- package/dist/{lzw.89350f4e.mjs → lzw-40577136.js} +1 -1
- package/dist/{packbits.986f9d9f.mjs → packbits-eab43a40.js} +1 -1
- package/dist/{pako.esm.4b234125.mjs → pako.esm-68f84e2a.js} +97 -15
- package/dist/{raw.1cc73933.mjs → raw-66364181.js} +1 -1
- package/dist/{webimage.be69a2d5.mjs → webimage-0fe27785.js} +1 -1
- package/dist-tsc/EmptyMessage.d.ts +2 -0
- package/dist-tsc/EmptyMessage.d.ts.map +1 -0
- package/dist-tsc/EmptyMessage.js +6 -0
- package/dist-tsc/Scatterplot.d.ts +10 -0
- package/dist-tsc/Scatterplot.d.ts.map +1 -0
- package/dist-tsc/Scatterplot.js +314 -0
- package/dist-tsc/ScatterplotOptions.d.ts +2 -0
- package/dist-tsc/ScatterplotOptions.d.ts.map +1 -0
- package/dist-tsc/ScatterplotOptions.js +56 -0
- package/dist-tsc/ScatterplotTooltipSubscriber.d.ts +2 -0
- package/dist-tsc/ScatterplotTooltipSubscriber.d.ts.map +1 -0
- package/dist-tsc/ScatterplotTooltipSubscriber.js +14 -0
- package/dist-tsc/index.d.ts +6 -0
- package/dist-tsc/index.d.ts.map +1 -0
- package/dist-tsc/index.js +5 -5
- package/dist-tsc/shared-spatial-scatterplot/AbstractSpatialOrScatterplot.d.ts +82 -0
- package/dist-tsc/shared-spatial-scatterplot/AbstractSpatialOrScatterplot.d.ts.map +1 -0
- package/dist-tsc/shared-spatial-scatterplot/AbstractSpatialOrScatterplot.js +218 -0
- package/dist-tsc/shared-spatial-scatterplot/ToolMenu.d.ts +4 -0
- package/dist-tsc/shared-spatial-scatterplot/ToolMenu.d.ts.map +1 -0
- package/dist-tsc/shared-spatial-scatterplot/ToolMenu.js +83 -0
- package/dist-tsc/shared-spatial-scatterplot/ToolMenu.test.d.ts +2 -0
- package/dist-tsc/shared-spatial-scatterplot/ToolMenu.test.d.ts.map +1 -0
- package/dist-tsc/shared-spatial-scatterplot/ToolMenu.test.js +23 -0
- package/dist-tsc/shared-spatial-scatterplot/cursor.d.ts +4 -0
- package/dist-tsc/shared-spatial-scatterplot/cursor.d.ts.map +1 -0
- package/dist-tsc/shared-spatial-scatterplot/cursor.js +22 -0
- package/dist-tsc/shared-spatial-scatterplot/dynamic-opacity.d.ts +3 -0
- package/dist-tsc/shared-spatial-scatterplot/dynamic-opacity.d.ts.map +1 -0
- package/dist-tsc/shared-spatial-scatterplot/dynamic-opacity.js +47 -0
- package/dist-tsc/shared-spatial-scatterplot/dynamic-opacity.test.d.ts +2 -0
- package/dist-tsc/shared-spatial-scatterplot/dynamic-opacity.test.d.ts.map +1 -0
- package/dist-tsc/shared-spatial-scatterplot/dynamic-opacity.test.js +28 -0
- package/dist-tsc/shared-spatial-scatterplot/force-collide-rects.d.ts +13 -0
- package/dist-tsc/shared-spatial-scatterplot/force-collide-rects.d.ts.map +1 -0
- package/dist-tsc/shared-spatial-scatterplot/force-collide-rects.js +169 -0
- package/dist-tsc/shared-spatial-scatterplot/force-collide-rects.test.d.ts +2 -0
- package/dist-tsc/shared-spatial-scatterplot/force-collide-rects.test.d.ts.map +1 -0
- package/dist-tsc/shared-spatial-scatterplot/force-collide-rects.test.js +58 -0
- package/dist-tsc/shared-spatial-scatterplot/index.d.ts +6 -0
- package/dist-tsc/shared-spatial-scatterplot/index.d.ts.map +1 -0
- package/dist-tsc/shared-spatial-scatterplot/index.js +5 -0
- package/dist-tsc/shared-spatial-scatterplot/quadtree.d.ts +10 -0
- package/dist-tsc/shared-spatial-scatterplot/quadtree.d.ts.map +1 -0
- package/dist-tsc/shared-spatial-scatterplot/quadtree.js +26 -0
- package/package.json +24 -12
- package/src/Scatterplot.js +13 -2
- package/src/ScatterplotOptions.js +27 -5
- package/src/index.js +5 -5
- package/src/shared-spatial-scatterplot/AbstractSpatialOrScatterplot.js +10 -4
- package/src/shared-spatial-scatterplot/ToolMenu.js +56 -18
- package/src/shared-spatial-scatterplot/ToolMenu.test.jsx +14 -6
- package/src/shared-spatial-scatterplot/dynamic-opacity.js +1 -1
- package/src/shared-spatial-scatterplot/dynamic-opacity.test.js +1 -1
- package/src/shared-spatial-scatterplot/force-collide-rects.test.js +1 -1
- package/src/shared-spatial-scatterplot/index.js +5 -5
- package/src/shared-spatial-scatterplot/quadtree.js +1 -1
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/* eslint-disable no-param-reassign */
|
|
3
|
+
import React, { forwardRef } from 'react';
|
|
4
|
+
import { forceSimulation } from 'd3-force';
|
|
5
|
+
import { deck, getSelectionLayers, ScaledExpressionExtension, SelectionExtension, } from '@vitessce/gl';
|
|
6
|
+
import { getDefaultColor } from '@vitessce/utils';
|
|
7
|
+
import { AbstractSpatialOrScatterplot, createQuadTree, forceCollideRects, getOnHoverCallback, } from './shared-spatial-scatterplot/index.js';
|
|
8
|
+
const CELLS_LAYER_ID = 'scatterplot';
|
|
9
|
+
const LABEL_FONT_FAMILY = "-apple-system, 'Helvetica Neue', Arial, sans-serif";
|
|
10
|
+
const NUM_FORCE_SIMULATION_TICKS = 100;
|
|
11
|
+
const LABEL_UPDATE_ZOOM_DELTA = 0.25;
|
|
12
|
+
// Default getter function props.
|
|
13
|
+
const makeDefaultGetCellColors = (cellColors, obsIndex, theme) => (object, { index }) => {
|
|
14
|
+
const [r, g, b, a] = (cellColors && obsIndex && cellColors.get(obsIndex[index]))
|
|
15
|
+
|| getDefaultColor(theme);
|
|
16
|
+
return [r, g, b, 255 * (a || 1)];
|
|
17
|
+
};
|
|
18
|
+
const makeDefaultGetObsCoords = obsEmbedding => i => ([
|
|
19
|
+
obsEmbedding.data[0][i],
|
|
20
|
+
obsEmbedding.data[1][i],
|
|
21
|
+
0,
|
|
22
|
+
]);
|
|
23
|
+
const makeFlippedGetObsCoords = obsEmbedding => i => ([
|
|
24
|
+
obsEmbedding.data[0][i],
|
|
25
|
+
-obsEmbedding.data[1][i],
|
|
26
|
+
0,
|
|
27
|
+
]);
|
|
28
|
+
const getPosition = (object, { index, data, target }) => {
|
|
29
|
+
target[0] = data.src.obsEmbedding.data[0][index];
|
|
30
|
+
target[1] = -data.src.obsEmbedding.data[1][index];
|
|
31
|
+
target[2] = 0;
|
|
32
|
+
return target;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* React component which renders a scatterplot from cell data.
|
|
36
|
+
* @param {object} props
|
|
37
|
+
* @param {string} props.uuid A unique identifier for this component.
|
|
38
|
+
* @param {string} props.theme The current vitessce theme.
|
|
39
|
+
* @param {object} props.viewState The deck.gl view state.
|
|
40
|
+
* @param {function} props.setViewState Function to call to update the deck.gl view state.
|
|
41
|
+
* @param {object} props.cells
|
|
42
|
+
* @param {string} props.mapping The name of the coordinate mapping field,
|
|
43
|
+
* for each cell, for example "PCA" or "t-SNE".
|
|
44
|
+
* @param {Map} props.cellColors Mapping of cell IDs to colors.
|
|
45
|
+
* @param {array} props.cellSelection Array of selected cell IDs.
|
|
46
|
+
* @param {array} props.cellFilter Array of filtered cell IDs. By default, null.
|
|
47
|
+
* @param {number} props.cellRadius The value for `radiusScale` to pass
|
|
48
|
+
* to the deck.gl cells ScatterplotLayer.
|
|
49
|
+
* @param {number} props.cellOpacity The value for `opacity` to pass
|
|
50
|
+
* to the deck.gl cells ScatterplotLayer.
|
|
51
|
+
* @param {function} props.getCellCoords Getter function for cell coordinates
|
|
52
|
+
* (used by the selection layer).
|
|
53
|
+
* @param {function} props.getCellPosition Getter function for cell [x, y, z] position.
|
|
54
|
+
* @param {function} props.getCellColor Getter function for cell color as [r, g, b] array.
|
|
55
|
+
* @param {function} props.getExpressionValue Getter function for cell expression value.
|
|
56
|
+
* @param {function} props.getCellIsSelected Getter function for cell layer isSelected.
|
|
57
|
+
* @param {function} props.setCellSelection
|
|
58
|
+
* @param {function} props.setCellHighlight
|
|
59
|
+
* @param {function} props.updateViewInfo
|
|
60
|
+
* @param {function} props.onToolChange Callback for tool changes
|
|
61
|
+
* (lasso/pan selection tools).
|
|
62
|
+
* @param {function} props.onCellClick Getter function for cell layer onClick.
|
|
63
|
+
* @param {object} props.originalViewState A viewState object to pass to
|
|
64
|
+
* setViewState upon clicking the recenter button.
|
|
65
|
+
*/
|
|
66
|
+
class Scatterplot extends AbstractSpatialOrScatterplot {
|
|
67
|
+
constructor(props) {
|
|
68
|
+
super(props);
|
|
69
|
+
// To avoid storing large arrays/objects
|
|
70
|
+
// in React state, this component
|
|
71
|
+
// uses instance variables.
|
|
72
|
+
// All instance variables used in this class:
|
|
73
|
+
this.cellsQuadTree = null;
|
|
74
|
+
this.cellsLayer = null;
|
|
75
|
+
this.cellsData = null;
|
|
76
|
+
this.cellSetsForceSimulation = forceCollideRects();
|
|
77
|
+
this.cellSetsLabelPrevZoom = null;
|
|
78
|
+
this.cellSetsLayers = [];
|
|
79
|
+
// Initialize data and layers.
|
|
80
|
+
this.onUpdateCellsData();
|
|
81
|
+
this.onUpdateCellsLayer();
|
|
82
|
+
this.onUpdateCellSetsLayers();
|
|
83
|
+
}
|
|
84
|
+
createCellsLayer() {
|
|
85
|
+
const { obsEmbeddingIndex: obsIndex, theme, cellRadius = 1.0, cellOpacity = 1.0,
|
|
86
|
+
// cellFilter,
|
|
87
|
+
cellSelection, setCellHighlight, setComponentHover, getCellIsSelected, cellColors, getCellColor = makeDefaultGetCellColors(cellColors, obsIndex, theme), getExpressionValue, onCellClick, geneExpressionColormap, geneExpressionColormapRange = [0.0, 1.0], cellColorEncoding, } = this.props;
|
|
88
|
+
return new deck.ScatterplotLayer({
|
|
89
|
+
id: CELLS_LAYER_ID,
|
|
90
|
+
// Note that the reference for the object passed to the data prop should not change,
|
|
91
|
+
// otherwise DeckGL will need to do a full re-render every time .createCellsLayer is called,
|
|
92
|
+
// which can be very often to handle cellOpacity and cellRadius updates for dynamic opacity.
|
|
93
|
+
data: this.cellsData,
|
|
94
|
+
coordinateSystem: deck.COORDINATE_SYSTEM.CARTESIAN,
|
|
95
|
+
visible: true,
|
|
96
|
+
pickable: true,
|
|
97
|
+
autoHighlight: true,
|
|
98
|
+
filled: true,
|
|
99
|
+
stroked: true,
|
|
100
|
+
backgroundColor: (theme === 'dark' ? [0, 0, 0] : [241, 241, 241]),
|
|
101
|
+
getCellIsSelected,
|
|
102
|
+
opacity: cellOpacity,
|
|
103
|
+
radiusScale: cellRadius,
|
|
104
|
+
radiusMinPixels: 1,
|
|
105
|
+
radiusMaxPixels: 30,
|
|
106
|
+
// Our radius pixel setters measure in pixels.
|
|
107
|
+
radiusUnits: 'pixels',
|
|
108
|
+
lineWidthUnits: 'pixels',
|
|
109
|
+
getPosition,
|
|
110
|
+
getFillColor: getCellColor,
|
|
111
|
+
getLineColor: getCellColor,
|
|
112
|
+
getRadius: 1,
|
|
113
|
+
getExpressionValue,
|
|
114
|
+
getLineWidth: 0,
|
|
115
|
+
extensions: [
|
|
116
|
+
new ScaledExpressionExtension(),
|
|
117
|
+
new SelectionExtension({ instanced: true }),
|
|
118
|
+
],
|
|
119
|
+
colorScaleLo: geneExpressionColormapRange[0],
|
|
120
|
+
colorScaleHi: geneExpressionColormapRange[1],
|
|
121
|
+
isExpressionMode: (cellColorEncoding === 'geneSelection'),
|
|
122
|
+
colormap: geneExpressionColormap,
|
|
123
|
+
onClick: (info) => {
|
|
124
|
+
if (onCellClick) {
|
|
125
|
+
onCellClick(info);
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
onHover: getOnHoverCallback(obsIndex, setCellHighlight, setComponentHover),
|
|
129
|
+
updateTriggers: {
|
|
130
|
+
getExpressionValue,
|
|
131
|
+
getFillColor: [cellColorEncoding, cellSelection, cellColors],
|
|
132
|
+
getLineColor: [cellColorEncoding, cellSelection, cellColors],
|
|
133
|
+
getCellIsSelected,
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
createCellSetsLayers() {
|
|
138
|
+
const { theme, cellSetPolygons, viewState, cellSetPolygonsVisible, cellSetLabelsVisible, cellSetLabelSize, } = this.props;
|
|
139
|
+
const result = [];
|
|
140
|
+
if (cellSetPolygonsVisible) {
|
|
141
|
+
result.push(new deck.PolygonLayer({
|
|
142
|
+
id: 'cell-sets-polygon-layer',
|
|
143
|
+
data: cellSetPolygons,
|
|
144
|
+
stroked: true,
|
|
145
|
+
filled: false,
|
|
146
|
+
wireframe: true,
|
|
147
|
+
lineWidthMaxPixels: 1,
|
|
148
|
+
getPolygon: d => d.hull,
|
|
149
|
+
getLineColor: d => d.color,
|
|
150
|
+
getLineWidth: 1,
|
|
151
|
+
}));
|
|
152
|
+
}
|
|
153
|
+
if (cellSetLabelsVisible) {
|
|
154
|
+
const { zoom } = viewState;
|
|
155
|
+
const nodes = cellSetPolygons.map(p => ({
|
|
156
|
+
x: p.centroid[0],
|
|
157
|
+
y: p.centroid[1],
|
|
158
|
+
label: p.name,
|
|
159
|
+
}));
|
|
160
|
+
const collisionForce = this.cellSetsForceSimulation
|
|
161
|
+
.size(d => ([
|
|
162
|
+
cellSetLabelSize * 1 / (2 ** zoom) * 4 * d.label.length,
|
|
163
|
+
cellSetLabelSize * 1 / (2 ** zoom) * 1.5,
|
|
164
|
+
]));
|
|
165
|
+
forceSimulation()
|
|
166
|
+
.nodes(nodes)
|
|
167
|
+
.force('collision', collisionForce)
|
|
168
|
+
.tick(NUM_FORCE_SIMULATION_TICKS);
|
|
169
|
+
result.push(new deck.TextLayer({
|
|
170
|
+
id: 'cell-sets-text-layer',
|
|
171
|
+
data: nodes,
|
|
172
|
+
getPosition: d => ([d.x, d.y]),
|
|
173
|
+
getText: d => d.label,
|
|
174
|
+
getColor: (theme === 'dark' ? [255, 255, 255] : [0, 0, 0]),
|
|
175
|
+
getSize: cellSetLabelSize,
|
|
176
|
+
getAngle: 0,
|
|
177
|
+
getTextAnchor: 'middle',
|
|
178
|
+
getAlignmentBaseline: 'center',
|
|
179
|
+
fontFamily: LABEL_FONT_FAMILY,
|
|
180
|
+
fontWeight: 'normal',
|
|
181
|
+
}));
|
|
182
|
+
}
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
createSelectionLayers() {
|
|
186
|
+
const { obsEmbeddingIndex: obsIndex, obsEmbedding, viewState, setCellSelection, } = this.props;
|
|
187
|
+
const { tool } = this.state;
|
|
188
|
+
const { cellsQuadTree } = this;
|
|
189
|
+
const flipYTooltip = true;
|
|
190
|
+
const getCellCoords = makeDefaultGetObsCoords(obsEmbedding);
|
|
191
|
+
return getSelectionLayers(tool, viewState.zoom, CELLS_LAYER_ID, getCellCoords, obsIndex, setCellSelection, cellsQuadTree, flipYTooltip);
|
|
192
|
+
}
|
|
193
|
+
getLayers() {
|
|
194
|
+
const { cellsLayer, cellSetsLayers, } = this;
|
|
195
|
+
return [
|
|
196
|
+
cellsLayer,
|
|
197
|
+
...cellSetsLayers,
|
|
198
|
+
...this.createSelectionLayers(),
|
|
199
|
+
];
|
|
200
|
+
}
|
|
201
|
+
onUpdateCellsData() {
|
|
202
|
+
const { obsEmbedding } = this.props;
|
|
203
|
+
if (obsEmbedding) {
|
|
204
|
+
const getCellCoords = makeDefaultGetObsCoords(obsEmbedding);
|
|
205
|
+
this.cellsQuadTree = createQuadTree(obsEmbedding, getCellCoords);
|
|
206
|
+
this.cellsData = {
|
|
207
|
+
src: {
|
|
208
|
+
obsEmbedding,
|
|
209
|
+
},
|
|
210
|
+
length: obsEmbedding.shape[1],
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
onUpdateCellsLayer() {
|
|
215
|
+
const { obsEmbeddingIndex, obsEmbedding } = this.props;
|
|
216
|
+
if (obsEmbeddingIndex && obsEmbedding) {
|
|
217
|
+
this.cellsLayer = this.createCellsLayer();
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
this.cellsLayer = null;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
onUpdateCellSetsLayers(onlyViewStateChange) {
|
|
224
|
+
// Because the label sizes for the force simulation depend on the zoom level,
|
|
225
|
+
// we _could_ run the simulation every time the zoom level changes.
|
|
226
|
+
// However, this has a performance impact in firefox.
|
|
227
|
+
if (onlyViewStateChange) {
|
|
228
|
+
const { viewState, cellSetLabelsVisible } = this.props;
|
|
229
|
+
const { zoom } = viewState;
|
|
230
|
+
const { cellSetsLabelPrevZoom } = this;
|
|
231
|
+
// Instead, we can just check if the zoom level has changed
|
|
232
|
+
// by some relatively large delta, to be more conservative
|
|
233
|
+
// about re-running the force simulation.
|
|
234
|
+
if (cellSetLabelsVisible
|
|
235
|
+
&& (cellSetsLabelPrevZoom === null
|
|
236
|
+
|| Math.abs(cellSetsLabelPrevZoom - zoom) > LABEL_UPDATE_ZOOM_DELTA)) {
|
|
237
|
+
this.cellSetsLayers = this.createCellSetsLayers();
|
|
238
|
+
this.cellSetsLabelPrevZoom = zoom;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
// Otherwise, something more substantial than just
|
|
243
|
+
// the viewState has changed, such as the label array
|
|
244
|
+
// itself, so we always want to update the layer
|
|
245
|
+
// in this case.
|
|
246
|
+
this.cellSetsLayers = this.createCellSetsLayers();
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
viewInfoDidUpdate() {
|
|
250
|
+
const { obsEmbeddingIndex, obsEmbedding, } = this.props;
|
|
251
|
+
super.viewInfoDidUpdate(obsEmbeddingIndex, obsEmbedding, makeFlippedGetObsCoords);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Here, asynchronously check whether props have
|
|
255
|
+
* updated which require re-computing memoized variables,
|
|
256
|
+
* followed by a re-render.
|
|
257
|
+
* This function does not follow React conventions or paradigms,
|
|
258
|
+
* it is only implemented this way to try to squeeze out
|
|
259
|
+
* performance.
|
|
260
|
+
* @param {object} prevProps The previous props to diff against.
|
|
261
|
+
*/
|
|
262
|
+
componentDidUpdate(prevProps) {
|
|
263
|
+
this.viewInfoDidUpdate();
|
|
264
|
+
const shallowDiff = propName => (prevProps[propName] !== this.props[propName]);
|
|
265
|
+
let forceUpdate = false;
|
|
266
|
+
if (['obsEmbedding'].some(shallowDiff)) {
|
|
267
|
+
// Cells data changed.
|
|
268
|
+
this.onUpdateCellsData();
|
|
269
|
+
forceUpdate = true;
|
|
270
|
+
}
|
|
271
|
+
if ([
|
|
272
|
+
'obsEmbeddingIndex', 'obsEmbedding', 'cellFilter', 'cellSelection', 'cellColors',
|
|
273
|
+
'cellRadius', 'cellOpacity', 'cellRadiusMode', 'geneExpressionColormap',
|
|
274
|
+
'geneExpressionColormapRange', 'geneSelection', 'cellColorEncoding',
|
|
275
|
+
'getExpressionValue',
|
|
276
|
+
].some(shallowDiff)) {
|
|
277
|
+
// Cells layer props changed.
|
|
278
|
+
this.onUpdateCellsLayer();
|
|
279
|
+
forceUpdate = true;
|
|
280
|
+
}
|
|
281
|
+
if ([
|
|
282
|
+
'cellSetPolygons', 'cellSetPolygonsVisible',
|
|
283
|
+
'cellSetLabelsVisible', 'cellSetLabelSize',
|
|
284
|
+
].some(shallowDiff)) {
|
|
285
|
+
// Cell sets layer props changed.
|
|
286
|
+
this.onUpdateCellSetsLayers(false);
|
|
287
|
+
forceUpdate = true;
|
|
288
|
+
}
|
|
289
|
+
if (shallowDiff('viewState')) {
|
|
290
|
+
// The viewState prop has changed (due to zoom or pan).
|
|
291
|
+
this.onUpdateCellSetsLayers(true);
|
|
292
|
+
forceUpdate = true;
|
|
293
|
+
}
|
|
294
|
+
if (forceUpdate) {
|
|
295
|
+
this.forceUpdate();
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
recenter() {
|
|
299
|
+
const { originalViewState, setViewState } = this.props;
|
|
300
|
+
if (Array.isArray(originalViewState?.target) && typeof originalViewState?.zoom === 'number') {
|
|
301
|
+
setViewState(originalViewState);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Need this wrapper function here,
|
|
307
|
+
* since we want to pass a forwardRef
|
|
308
|
+
* so that outer components can
|
|
309
|
+
* access the grandchild DeckGL ref,
|
|
310
|
+
* but we are using a class component.
|
|
311
|
+
*/
|
|
312
|
+
const ScatterplotWrapper = forwardRef((props, deckRef) => (_jsx(Scatterplot, { ...props, deckRef: deckRef })));
|
|
313
|
+
ScatterplotWrapper.displayName = 'ScatterplotWrapper';
|
|
314
|
+
export default ScatterplotWrapper;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScatterplotOptions.d.ts","sourceRoot":"","sources":["../src/ScatterplotOptions.js"],"names":[],"mappings":"AASA,oEAmQC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { useCallback } from 'react';
|
|
3
|
+
import { debounce } from 'lodash-es';
|
|
4
|
+
import { Checkbox, Slider, TableCell, TableRow } from '@material-ui/core';
|
|
5
|
+
import { capitalize } from '@vitessce/utils';
|
|
6
|
+
import { usePlotOptionsStyles, CellColorEncodingOption, OptionsContainer, OptionSelect, } from '@vitessce/vit-s';
|
|
7
|
+
import { GLSL_COLORMAPS } from '@vitessce/gl';
|
|
8
|
+
export default function ScatterplotOptions(props) {
|
|
9
|
+
const { children, observationsLabel, cellRadius, setCellRadius, cellRadiusMode, setCellRadiusMode, cellOpacity, setCellOpacity, cellOpacityMode, setCellOpacityMode, cellSetLabelsVisible, setCellSetLabelsVisible, tooltipsVisible, setTooltipsVisible, cellSetLabelSize, setCellSetLabelSize, cellSetPolygonsVisible, setCellSetPolygonsVisible, cellColorEncoding, setCellColorEncoding, geneExpressionColormap, setGeneExpressionColormap, geneExpressionColormapRange, setGeneExpressionColormapRange, } = props;
|
|
10
|
+
const observationsLabelNice = capitalize(observationsLabel);
|
|
11
|
+
const classes = usePlotOptionsStyles();
|
|
12
|
+
function handleCellRadiusModeChange(event) {
|
|
13
|
+
setCellRadiusMode(event.target.value);
|
|
14
|
+
}
|
|
15
|
+
function handleCellOpacityModeChange(event) {
|
|
16
|
+
setCellOpacityMode(event.target.value);
|
|
17
|
+
}
|
|
18
|
+
function handleRadiusChange(event, value) {
|
|
19
|
+
setCellRadius(value);
|
|
20
|
+
}
|
|
21
|
+
function handleOpacityChange(event, value) {
|
|
22
|
+
setCellOpacity(value);
|
|
23
|
+
}
|
|
24
|
+
function handleLabelVisibilityChange(event) {
|
|
25
|
+
setCellSetLabelsVisible(event.target.checked);
|
|
26
|
+
}
|
|
27
|
+
function handleTooltipsVisibilityChange(event) {
|
|
28
|
+
setTooltipsVisible(event.target.checked);
|
|
29
|
+
}
|
|
30
|
+
function handleLabelSizeChange(event, value) {
|
|
31
|
+
setCellSetLabelSize(value);
|
|
32
|
+
}
|
|
33
|
+
function handlePolygonVisibilityChange(event) {
|
|
34
|
+
setCellSetPolygonsVisible(event.target.checked);
|
|
35
|
+
}
|
|
36
|
+
function handleGeneExpressionColormapChange(event) {
|
|
37
|
+
setGeneExpressionColormap(event.target.value);
|
|
38
|
+
}
|
|
39
|
+
function handleColormapRangeChange(event, value) {
|
|
40
|
+
setGeneExpressionColormapRange(value);
|
|
41
|
+
}
|
|
42
|
+
const handleColormapRangeChangeDebounced = useCallback(debounce(handleColormapRangeChange, 5, { trailing: true }), [handleColormapRangeChange]);
|
|
43
|
+
return (_jsxs(OptionsContainer, { children: [children, _jsx(CellColorEncodingOption, { observationsLabel: observationsLabel, cellColorEncoding: cellColorEncoding, setCellColorEncoding: setCellColorEncoding }), _jsxs(TableRow, { children: [_jsxs(TableCell, { className: classes.labelCell, children: [observationsLabelNice, " Set Labels Visible"] }), _jsx(TableCell, { className: classes.inputCell, children: _jsx(Checkbox, { className: classes.checkbox, checked: cellSetLabelsVisible, onChange: handleLabelVisibilityChange, name: "scatterplot-option-cell-set-labels", color: "default" }) })] }), _jsxs(TableRow, { children: [_jsx(TableCell, { className: classes.labelCell, children: "Tooltips Visible" }), _jsx(TableCell, { className: classes.inputCell, children: _jsx(Checkbox, { className: classes.checkbox,
|
|
44
|
+
/**
|
|
45
|
+
* We have to use "checked" here, not "value".
|
|
46
|
+
* The checkbox state is not persisting with value.
|
|
47
|
+
* For reference, https://v4.mui.com/api/checkbox/
|
|
48
|
+
*/
|
|
49
|
+
checked: tooltipsVisible, onChange: handleTooltipsVisibilityChange, name: "scatterplot-option-toltip-visibility", color: "default" }) })] }), _jsxs(TableRow, { children: [_jsxs(TableCell, { className: classes.labelCell, children: [observationsLabelNice, " Set Label Size"] }), _jsx(TableCell, { className: classes.inputCell, children: _jsx(Slider, { disabled: !cellSetLabelsVisible, classes: { root: classes.slider, valueLabel: classes.sliderValueLabel }, value: cellSetLabelSize, onChange: handleLabelSizeChange, "aria-labelledby": "cell-set-label-size-slider", valueLabelDisplay: "auto", step: 1, min: 8, max: 36 }) })] }), _jsxs(TableRow, { children: [_jsxs(TableCell, { className: classes.labelCell, children: [observationsLabelNice, " Set Polygons Visible"] }), _jsx(TableCell, { className: classes.inputCell, children: _jsx(Checkbox, { className: classes.checkbox, checked: cellSetPolygonsVisible, onChange: handlePolygonVisibilityChange, name: "scatterplot-option-cell-set-polygons", color: "default" }) })] }), _jsxs(TableRow, { children: [_jsxs(TableCell, { className: classes.labelCell, htmlFor: "cell-radius-mode-select", children: [observationsLabelNice, " Radius Mode"] }), _jsx(TableCell, { className: classes.inputCell, children: _jsxs(OptionSelect, { className: classes.select, value: cellRadiusMode, onChange: handleCellRadiusModeChange, inputProps: {
|
|
50
|
+
id: 'cell-radius-mode-select',
|
|
51
|
+
}, children: [_jsx("option", { value: "auto", children: "Auto" }), _jsx("option", { value: "manual", children: "Manual" })] }) })] }), _jsxs(TableRow, { children: [_jsxs(TableCell, { className: classes.labelCell, children: [observationsLabelNice, " Radius"] }), _jsx(TableCell, { className: classes.inputCell, children: _jsx(Slider, { disabled: cellRadiusMode !== 'manual', classes: { root: classes.slider, valueLabel: classes.sliderValueLabel }, value: cellRadius, onChange: handleRadiusChange, "aria-labelledby": "cell-radius-slider", valueLabelDisplay: "auto", step: 0.01, min: 0.01, max: 10 }) })] }), _jsxs(TableRow, { children: [_jsxs(TableCell, { className: classes.labelCell, htmlFor: "cell-opacity-mode-select", children: [observationsLabelNice, " Opacity Mode"] }), _jsx(TableCell, { className: classes.inputCell, children: _jsxs(OptionSelect, { className: classes.select, value: cellOpacityMode, onChange: handleCellOpacityModeChange, inputProps: {
|
|
52
|
+
id: 'cell-opacity-mode-select',
|
|
53
|
+
}, children: [_jsx("option", { value: "auto", children: "Auto" }), _jsx("option", { value: "manual", children: "Manual" })] }) })] }), _jsxs(TableRow, { children: [_jsxs(TableCell, { className: classes.labelCell, children: [observationsLabelNice, " Opacity"] }), _jsx(TableCell, { className: classes.inputCell, children: _jsx(Slider, { disabled: cellOpacityMode !== 'manual', classes: { root: classes.slider, valueLabel: classes.sliderValueLabel }, value: cellOpacity, onChange: handleOpacityChange, "aria-labelledby": "cell-opacity-slider", valueLabelDisplay: "auto", step: 0.05, min: 0.0, max: 1.0 }) })] }), _jsxs(TableRow, { children: [_jsx(TableCell, { className: classes.labelCell, htmlFor: "gene-expression-colormap-select", children: "Gene Expression Colormap" }), _jsx(TableCell, { className: classes.inputCell, children: _jsx(OptionSelect, { className: classes.select, value: geneExpressionColormap, onChange: handleGeneExpressionColormapChange, inputProps: {
|
|
54
|
+
id: 'gene-expression-colormap-select',
|
|
55
|
+
}, children: GLSL_COLORMAPS.map(cmap => (_jsx("option", { value: cmap, children: cmap }, cmap))) }) })] }), _jsxs(TableRow, { children: [_jsx(TableCell, { className: classes.labelCell, children: "Gene Expression Colormap Range" }), _jsx(TableCell, { className: classes.inputCell, children: _jsx(Slider, { classes: { root: classes.slider, valueLabel: classes.sliderValueLabel }, value: geneExpressionColormapRange, onChange: handleColormapRangeChangeDebounced, "aria-labelledby": "gene-expression-colormap-range-slider", valueLabelDisplay: "auto", step: 0.005, min: 0.0, max: 1.0 }) })] })] }));
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScatterplotTooltipSubscriber.d.ts","sourceRoot":"","sources":["../src/ScatterplotTooltipSubscriber.js"],"names":[],"mappings":"AAIA,qFAiCC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Tooltip2D, TooltipContent } from '@vitessce/tooltip';
|
|
4
|
+
import { useComponentHover, useComponentViewInfo } from '@vitessce/vit-s';
|
|
5
|
+
export default function ScatterplotTooltipSubscriber(props) {
|
|
6
|
+
const { parentUuid, obsHighlight, width, height, getObsInfo, } = props;
|
|
7
|
+
const sourceUuid = useComponentHover();
|
|
8
|
+
const viewInfo = useComponentViewInfo(parentUuid);
|
|
9
|
+
const [cellInfo, x, y] = (obsHighlight && getObsInfo ? ([
|
|
10
|
+
getObsInfo(obsHighlight),
|
|
11
|
+
...(viewInfo && viewInfo.project ? viewInfo.project(obsHighlight) : [null, null]),
|
|
12
|
+
]) : ([null, null, null]));
|
|
13
|
+
return ((cellInfo ? (_jsx(Tooltip2D, { x: x, y: y, parentUuid: parentUuid, sourceUuid: sourceUuid, parentWidth: width, parentHeight: height, children: _jsx(TooltipContent, { info: cellInfo }) })) : null));
|
|
14
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as Scatterplot } from "./Scatterplot.js";
|
|
2
|
+
export { default as ScatterplotOptions } from "./ScatterplotOptions.js";
|
|
3
|
+
export { default as ScatterplotTooltipSubscriber } from "./ScatterplotTooltipSubscriber.js";
|
|
4
|
+
export { default as EmptyMessage } from "./EmptyMessage.js";
|
|
5
|
+
export { getPointSizeDevicePixels, getPointOpacity, getOnHoverCallback, createQuadTree, AbstractSpatialOrScatterplot } from "./shared-spatial-scatterplot/index.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":""}
|
package/dist-tsc/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { default as Scatterplot } from './Scatterplot';
|
|
2
|
-
export { default as ScatterplotOptions } from './ScatterplotOptions';
|
|
3
|
-
export { default as ScatterplotTooltipSubscriber } from './ScatterplotTooltipSubscriber';
|
|
4
|
-
export { default as EmptyMessage } from './EmptyMessage';
|
|
5
|
-
export { getPointSizeDevicePixels, getPointOpacity, getOnHoverCallback, createQuadTree, AbstractSpatialOrScatterplot, } from './shared-spatial-scatterplot/index';
|
|
1
|
+
export { default as Scatterplot } from './Scatterplot.js';
|
|
2
|
+
export { default as ScatterplotOptions } from './ScatterplotOptions.js';
|
|
3
|
+
export { default as ScatterplotTooltipSubscriber } from './ScatterplotTooltipSubscriber.js';
|
|
4
|
+
export { default as EmptyMessage } from './EmptyMessage.js';
|
|
5
|
+
export { getPointSizeDevicePixels, getPointOpacity, getOnHoverCallback, createQuadTree, AbstractSpatialOrScatterplot, } from './shared-spatial-scatterplot/index.js';
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract class component intended to be inherited by
|
|
3
|
+
* the Spatial and Scatterplot class components.
|
|
4
|
+
* Contains a common constructor, common DeckGL callbacks,
|
|
5
|
+
* and common render function.
|
|
6
|
+
*/
|
|
7
|
+
export default class AbstractSpatialOrScatterplot {
|
|
8
|
+
constructor(props: any);
|
|
9
|
+
state: {
|
|
10
|
+
gl: null;
|
|
11
|
+
tool: null;
|
|
12
|
+
};
|
|
13
|
+
viewport: object | null;
|
|
14
|
+
/**
|
|
15
|
+
* Called by DeckGL upon a viewState change,
|
|
16
|
+
* for example zoom or pan interaction.
|
|
17
|
+
* Emit the new viewState to the `setViewState`
|
|
18
|
+
* handler prop.
|
|
19
|
+
* @param {object} params
|
|
20
|
+
* @param {object} params.viewState The next deck.gl viewState.
|
|
21
|
+
*/
|
|
22
|
+
onViewStateChange({ viewState: nextViewState }: {
|
|
23
|
+
viewState: object;
|
|
24
|
+
}): void;
|
|
25
|
+
/**
|
|
26
|
+
* Called by DeckGL upon viewport
|
|
27
|
+
* initialization.
|
|
28
|
+
* @param {object} viewState
|
|
29
|
+
* @param {object} viewState.viewport
|
|
30
|
+
*/
|
|
31
|
+
onInitializeViewInfo({ viewport }: {
|
|
32
|
+
viewport: object;
|
|
33
|
+
}): void;
|
|
34
|
+
/**
|
|
35
|
+
* Called by DeckGL upon initialization,
|
|
36
|
+
* helps to understand when to pass layers
|
|
37
|
+
* to the DeckGL component.
|
|
38
|
+
* @param {object} gl The WebGL context object.
|
|
39
|
+
*/
|
|
40
|
+
onWebGLInitialized(gl: object): void;
|
|
41
|
+
/**
|
|
42
|
+
* Called by the ToolMenu buttons.
|
|
43
|
+
* Emits the new tool value to the
|
|
44
|
+
* `onToolChange` prop.
|
|
45
|
+
* @param {string} tool Name of tool.
|
|
46
|
+
*/
|
|
47
|
+
onToolChange(tool: string): void;
|
|
48
|
+
onHover(info: any): null | undefined;
|
|
49
|
+
/** Intended to be overridden by descendants.
|
|
50
|
+
* Resets the view type to its original position.
|
|
51
|
+
*/
|
|
52
|
+
recenter(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Create the DeckGL layers.
|
|
55
|
+
* @returns {object[]} Array of
|
|
56
|
+
* DeckGL layer objects.
|
|
57
|
+
* Intended to be overriden by descendants.
|
|
58
|
+
*/
|
|
59
|
+
getLayers(): object[];
|
|
60
|
+
/**
|
|
61
|
+
* Emits a function to project from the
|
|
62
|
+
* cell ID space to the scatterplot or
|
|
63
|
+
* spatial coordinate space, via the
|
|
64
|
+
* `updateViewInfo` prop.
|
|
65
|
+
*/
|
|
66
|
+
viewInfoDidUpdate(obsIndex: any, obsLocations: any, makeGetObsCoords: any): void;
|
|
67
|
+
/**
|
|
68
|
+
* Intended to be overridden by descendants.
|
|
69
|
+
*/
|
|
70
|
+
componentDidUpdate(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Intended to be overridden by descendants.
|
|
73
|
+
* @returns {boolean} Whether or not any layers are 3D.
|
|
74
|
+
*/
|
|
75
|
+
use3d(): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* A common render function for both Spatial
|
|
78
|
+
* and Scatterplot components.
|
|
79
|
+
*/
|
|
80
|
+
render(): JSX.Element;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=AbstractSpatialOrScatterplot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbstractSpatialOrScatterplot.d.ts","sourceRoot":"","sources":["../../src/shared-spatial-scatterplot/AbstractSpatialOrScatterplot.js"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH;IACE,wBAeC;IAZC;;;MAGC;IAED,wBAAoB;IAStB;;;;;;;OAOG;IACH;QAF0B,SAAS,EAAxB,MAAM;aAYhB;IAED;;;;;OAKG;IACH;QAF6B,QAAQ,EAA1B,MAAM;aAIhB;IAED;;;;;OAKG;IACH,uBAFW,MAAM,QAIhB;IAED;;;;;OAKG;IACH,mBAFW,MAAM,QAQhB;IAcD,qCAkEC;IAuCD;;MAEE;IAEF,iBAAa;IAzHb;;;;;OAKG;IAEH,aALa,MAAM,EAAE,CAOpB;IAuED;;;;;OAKG;IACH,iFAqBC;IAED;;OAEG;IAEH,2BAEC;IAQD;;;OAGG;IAEH,SAHa,OAAO,CAKnB;IAED;;;OAGG;IACH,sBA2DC;CACF"}
|