@vitessce/scatterplot-embedding 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/{deflate-CHWmGKzs.js → deflate-rRUHMvv4.js} +1 -1
- package/dist/{index-DoXbfOn2.js → index-BPLMRXHR.js} +8157 -4244
- package/dist/index.js +1 -1
- package/dist/{jpeg-DfpY4ESw.js → jpeg-BozBiXDf.js} +1 -1
- package/dist/{lerc-zU6xDjk2.js → lerc-DcLEOuuO.js} +1 -1
- package/dist/{lzw-qjsUiTV8.js → lzw-DFI2LUrc.js} +1 -1
- package/dist/{packbits-DpcvKlj_.js → packbits-CHsbj-XL.js} +1 -1
- package/dist/{raw-DWdrKuNt.js → raw-D55mTiBU.js} +1 -1
- package/dist/{webimage-DP9dgaA0.js → webimage-mVfjCoPU.js} +1 -1
- package/dist-tsc/EmbeddingScatterplotSubscriber.d.ts.map +1 -1
- package/dist-tsc/EmbeddingScatterplotSubscriber.js +24 -8
- package/dist-tsc/EmbeddingScatterplotSubscriber.js.map +1 -1
- package/dist-tsc/EmbeddingScatterplotSubscriber.test.d.ts +2 -0
- package/dist-tsc/EmbeddingScatterplotSubscriber.test.d.ts.map +1 -0
- package/dist-tsc/EmbeddingScatterplotSubscriber.test.js +103 -0
- package/dist-tsc/EmbeddingScatterplotSubscriber.test.js.map +1 -0
- package/package.json +8 -8
- package/src/EmbeddingScatterplotSubscriber.js +40 -5
- package/src/EmbeddingScatterplotSubscriber.test.jsx +105 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { it, expect, vi } from 'vitest';
|
|
3
|
+
import { render, act } from '@testing-library/react';
|
|
4
|
+
import { Scatterplot } from '@vitessce/scatterplot';
|
|
5
|
+
import { EmbeddingScatterplotSubscriber } from './EmbeddingScatterplotSubscriber.js';
|
|
6
|
+
|
|
7
|
+
const state = vi.hoisted(() => ({
|
|
8
|
+
values: {}, setters: {}, index: [], embedding: null, sets: null,
|
|
9
|
+
}));
|
|
10
|
+
vi.mock('@vitessce/vit-s', () => ({
|
|
11
|
+
TitleInfo: ({ children }) => children,
|
|
12
|
+
useReady: () => true,
|
|
13
|
+
useUrls: () => [],
|
|
14
|
+
useDeckCanvasSize: () => [0, 0, null],
|
|
15
|
+
useUint8FeatureSelection: () => ({}),
|
|
16
|
+
useExpressionValueGetter: () => () => 0,
|
|
17
|
+
useGetObsInfo: () => () => ({}),
|
|
18
|
+
useObsEmbeddingData: () => [{ obsIndex: state.index, obsEmbedding: state.embedding }, 'success', [], null],
|
|
19
|
+
useObsSetsData: () => [{ obsSets: state.sets }, 'success', [], null],
|
|
20
|
+
useAnnotationStoryData: () => [{}, 'success', [], null],
|
|
21
|
+
useAnnotationFrameCoordination: () => {},
|
|
22
|
+
useAnnotationEditingForView: () => ({}),
|
|
23
|
+
useFeatureSelection: () => [null, [], 'success', []],
|
|
24
|
+
useObsFeatureMatrixIndices: () => [{ obsIndex: state.index }, 'success', [], null],
|
|
25
|
+
useFeatureLabelsData: () => [{}, 'success', [], null],
|
|
26
|
+
useMultiObsLabels: () => [[], [], [], [], []],
|
|
27
|
+
useSampleSetsData: () => [{}, 'success', [], null],
|
|
28
|
+
useSampleEdgesData: () => [{}, 'success', [], null],
|
|
29
|
+
useCoordination: () => [state.values, state.setters],
|
|
30
|
+
useLoaders: () => ({}),
|
|
31
|
+
useSetComponentHover: () => () => {},
|
|
32
|
+
useSetComponentViewInfo: () => () => {},
|
|
33
|
+
useInitialCoordination: () => ({ embeddingZoom: 0, embeddingTargetX: 0, embeddingTargetY: 0 }),
|
|
34
|
+
useExpandedFeatureLabelsMap: () => [null, 'success'],
|
|
35
|
+
useViewMapping: () => [{}, {}, {}],
|
|
36
|
+
}));
|
|
37
|
+
vi.mock('@vitessce/scatterplot', () => ({
|
|
38
|
+
Scatterplot: vi.fn(() => null),
|
|
39
|
+
ScatterplotTooltipSubscriber: () => null,
|
|
40
|
+
ScatterplotOptions: () => null,
|
|
41
|
+
getPointSizeDevicePixels: () => 1,
|
|
42
|
+
getPointOpacity: () => 1,
|
|
43
|
+
useAnnotationFrameTransition: () => ({}),
|
|
44
|
+
}));
|
|
45
|
+
vi.mock('@vitessce/legend', () => ({ Legend: () => null }));
|
|
46
|
+
|
|
47
|
+
it('switches from feature value coloring to a lasso selection without showing the previous selection', () => {
|
|
48
|
+
state.index = Array.from({ length: 1000 }, (_, i) => `cell-${i}`);
|
|
49
|
+
state.embedding = {
|
|
50
|
+
shape: [2, state.index.length],
|
|
51
|
+
data: [
|
|
52
|
+
Float32Array.from(state.index, (_, i) => i % 32),
|
|
53
|
+
Float32Array.from(state.index, (_, i) => Math.floor(i / 32)),
|
|
54
|
+
],
|
|
55
|
+
};
|
|
56
|
+
state.sets = {
|
|
57
|
+
version: '0.1.3',
|
|
58
|
+
tree: [{
|
|
59
|
+
name: 'Types',
|
|
60
|
+
children: [{ name: 'All', set: state.index.map(id => [id, null]) }],
|
|
61
|
+
}],
|
|
62
|
+
};
|
|
63
|
+
// Coloring by feature values, with a previous set selection still stored.
|
|
64
|
+
state.values = {
|
|
65
|
+
dataset: 'A',
|
|
66
|
+
obsType: 'cell',
|
|
67
|
+
embeddingType: 'UMAP',
|
|
68
|
+
embeddingZoom: 0,
|
|
69
|
+
embeddingTargetX: 0,
|
|
70
|
+
embeddingTargetY: 0,
|
|
71
|
+
embeddingPointsVisible: true,
|
|
72
|
+
embeddingContoursVisible: false,
|
|
73
|
+
obsSetSelection: [['Types', 'All']],
|
|
74
|
+
additionalObsSets: null,
|
|
75
|
+
obsSetColor: [{ path: ['Types', 'All'], color: [0, 0, 255] }],
|
|
76
|
+
obsColorEncoding: 'geneSelection',
|
|
77
|
+
};
|
|
78
|
+
state.setters = Object.fromEntries([
|
|
79
|
+
'AdditionalObsSets', 'ObsSetSelection', 'ObsSetColor', 'ObsColorEncoding',
|
|
80
|
+
].map(name => [`set${name}`, (value) => {
|
|
81
|
+
state.values = { ...state.values, [name[0].toLowerCase() + name.slice(1)]: value };
|
|
82
|
+
}]));
|
|
83
|
+
const props = { uuid: 'umap', theme: 'dark' };
|
|
84
|
+
const { rerender } = render(<EmbeddingScatterplotSubscriber {...props} />);
|
|
85
|
+
const initialColorIndices = Scatterplot.mock.lastCall[0].obsColorIndices;
|
|
86
|
+
const currentSelect = Scatterplot.mock.lastCall[0].setCellSelection;
|
|
87
|
+
Scatterplot.mockClear();
|
|
88
|
+
|
|
89
|
+
act(() => {
|
|
90
|
+
// The same callback the selection layer calls after its hit test.
|
|
91
|
+
currentSelect(state.index.slice(0, 600));
|
|
92
|
+
rerender(<EmbeddingScatterplotSubscriber {...props} />);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const lastPlot = Scatterplot.mock.lastCall[0];
|
|
96
|
+
expect(lastPlot.cellColorEncoding).toEqual('cellSetSelection');
|
|
97
|
+
expect(lastPlot.obsColorIndices).not.toBe(initialColorIndices);
|
|
98
|
+
// Set selection coloring is only shown together with the new colors. Showing
|
|
99
|
+
// it with the previous colors would color every cell by the previous selection.
|
|
100
|
+
Scatterplot.mock.calls.forEach(([plot]) => {
|
|
101
|
+
if (plot.cellColorEncoding === 'cellSetSelection') {
|
|
102
|
+
expect(plot.obsSetSelection).toEqual(state.values.obsSetSelection);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|