@vitessce/statistical-plots 2.0.3 → 3.0.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.
Files changed (38) hide show
  1. package/dist/{index.mjs → index.js} +20520 -10837
  2. package/dist-tsc/CellSetExpressionPlot.d.ts +33 -0
  3. package/dist-tsc/CellSetExpressionPlot.d.ts.map +1 -0
  4. package/dist-tsc/CellSetExpressionPlot.js +248 -0
  5. package/dist-tsc/CellSetExpressionPlotOptions.d.ts +2 -0
  6. package/dist-tsc/CellSetExpressionPlotOptions.d.ts.map +1 -0
  7. package/dist-tsc/CellSetExpressionPlotOptions.js +30 -0
  8. package/dist-tsc/CellSetExpressionPlotSubscriber.d.ts +16 -0
  9. package/dist-tsc/CellSetExpressionPlotSubscriber.d.ts.map +1 -0
  10. package/dist-tsc/CellSetExpressionPlotSubscriber.js +111 -0
  11. package/dist-tsc/CellSetSizesPlot.d.ts +29 -0
  12. package/dist-tsc/CellSetSizesPlot.d.ts.map +1 -0
  13. package/dist-tsc/CellSetSizesPlot.js +149 -0
  14. package/dist-tsc/CellSetSizesPlotSubscriber.d.ts +18 -0
  15. package/dist-tsc/CellSetSizesPlotSubscriber.d.ts.map +1 -0
  16. package/dist-tsc/CellSetSizesPlotSubscriber.js +75 -0
  17. package/dist-tsc/ExpressionHistogram.d.ts +34 -0
  18. package/dist-tsc/ExpressionHistogram.d.ts.map +1 -0
  19. package/dist-tsc/ExpressionHistogram.js +93 -0
  20. package/dist-tsc/ExpressionHistogramSubscriber.d.ts +16 -0
  21. package/dist-tsc/ExpressionHistogramSubscriber.d.ts.map +1 -0
  22. package/dist-tsc/ExpressionHistogramSubscriber.js +72 -0
  23. package/dist-tsc/index.d.ts +7 -0
  24. package/dist-tsc/index.d.ts.map +1 -0
  25. package/dist-tsc/index.js +6 -6
  26. package/dist-tsc/styles.d.ts +2 -0
  27. package/dist-tsc/styles.d.ts.map +1 -0
  28. package/dist-tsc/styles.js +8 -0
  29. package/package.json +21 -12
  30. package/src/CellSetExpressionPlot.js +3 -3
  31. package/src/CellSetExpressionPlotOptions.js +1 -3
  32. package/src/CellSetExpressionPlotSubscriber.js +19 -23
  33. package/src/CellSetSizesPlot.js +90 -13
  34. package/src/CellSetSizesPlotSubscriber.js +69 -25
  35. package/src/ExpressionHistogram.js +58 -3
  36. package/src/ExpressionHistogramSubscriber.js +43 -21
  37. package/src/index.js +6 -6
  38. package/src/styles.js +1 -1
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Gene expression histogram displayed as a bar chart,
3
+ * implemented with the VegaPlot component.
4
+ * @param {object} props
5
+ * @param {object[]} props.data The expression data, an array
6
+ * of objects with properties `value`, `gene`, and `set`.
7
+ * @param {number} props.domainMax The maximum gene expression value.
8
+ * @param {object[]} props.colors An object for each
9
+ * cell set, with properties `name` and `color`.
10
+ * @param {string} props.theme The name of the current Vitessce theme.
11
+ * @param {number} props.width The container width.
12
+ * @param {number} props.height The container height.
13
+ * @param {number} props.marginRight The size of the margin
14
+ * on the right side of the plot, to account for the vega menu button.
15
+ * By default, 90.
16
+ * @param {number} props.marginBottom The size of the margin
17
+ * on the bottom of the plot, to account for long x-axis labels.
18
+ * Default is allowing the component to automatically determine the margin.
19
+ * @param {string|null} props.featureValueTransformName A name
20
+ * for the feature value transformation function.
21
+ */
22
+ export default function CellSetExpressionPlot(props: {
23
+ data: object[];
24
+ domainMax: number;
25
+ colors: object[];
26
+ theme: string;
27
+ width: number;
28
+ height: number;
29
+ marginRight: number;
30
+ marginBottom: number;
31
+ featureValueTransformName: string | null;
32
+ }): JSX.Element;
33
+ //# sourceMappingURL=CellSetExpressionPlot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CellSetExpressionPlot.d.ts","sourceRoot":"","sources":["../src/CellSetExpressionPlot.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH;IAjB2B,IAAI,EAApB,MAAM,EAAE;IAEM,SAAS,EAAvB,MAAM;IACU,MAAM,EAAtB,MAAM,EAAE;IAEM,KAAK,EAAnB,MAAM;IACQ,KAAK,EAAnB,MAAM;IACQ,MAAM,EAApB,MAAM;IACQ,WAAW,EAAzB,MAAM;IAGQ,YAAY,EAA1B,MAAM;IAGa,yBAAyB,EAA5C,MAAM,GAAC,IAAI;gBA6PrB"}
@@ -0,0 +1,248 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import React from 'react';
3
+ import { clamp } from 'lodash-es';
4
+ import { VegaPlot, VEGA_THEMES, DATASET_NAME } from '@vitessce/vega';
5
+ import { colorArrayToString } from '@vitessce/sets-utils';
6
+ import { capitalize } from '@vitessce/utils';
7
+ /**
8
+ * Gene expression histogram displayed as a bar chart,
9
+ * implemented with the VegaPlot component.
10
+ * @param {object} props
11
+ * @param {object[]} props.data The expression data, an array
12
+ * of objects with properties `value`, `gene`, and `set`.
13
+ * @param {number} props.domainMax The maximum gene expression value.
14
+ * @param {object[]} props.colors An object for each
15
+ * cell set, with properties `name` and `color`.
16
+ * @param {string} props.theme The name of the current Vitessce theme.
17
+ * @param {number} props.width The container width.
18
+ * @param {number} props.height The container height.
19
+ * @param {number} props.marginRight The size of the margin
20
+ * on the right side of the plot, to account for the vega menu button.
21
+ * By default, 90.
22
+ * @param {number} props.marginBottom The size of the margin
23
+ * on the bottom of the plot, to account for long x-axis labels.
24
+ * Default is allowing the component to automatically determine the margin.
25
+ * @param {string|null} props.featureValueTransformName A name
26
+ * for the feature value transformation function.
27
+ */
28
+ export default function CellSetExpressionPlot(props) {
29
+ const { domainMax = 100, colors, data, theme, width, height, marginRight = 90, marginBottom, obsType, featureValueType, featureValueTransformName, } = props;
30
+ // Get the max characters in an axis label for autsizing the bottom margin.
31
+ const maxCharactersForLabel = data.reduce((acc, val) => {
32
+ // eslint-disable-next-line no-param-reassign
33
+ acc = acc === undefined || val.set.length > acc ? val.set.length : acc;
34
+ return acc;
35
+ }, 0);
36
+ // Use a square-root term because the angle of the labels is 45 degrees (see below)
37
+ // so the perpendicular distance to the bottom of the labels is proportional to the
38
+ // square root of the length of the labels along the imaginary hypotenuse.
39
+ // 30 is an estimate of the pixel size of a given character and seems to work well.
40
+ const autoMarginBottom = marginBottom
41
+ || 30 + Math.sqrt(maxCharactersForLabel / 2) * 30;
42
+ // Manually set the color scale so that Vega-Lite does
43
+ // not choose the colors automatically.
44
+ const colorScale = {
45
+ domain: colors.map(d => d.name),
46
+ range: colors.map(d => colorArrayToString(d.color)),
47
+ };
48
+ const plotWidth = clamp(width - marginRight, 10, Infinity);
49
+ const plotHeight = clamp(height - autoMarginBottom, 10, Infinity);
50
+ const numBands = colors.length;
51
+ const bandWidth = plotWidth / numBands;
52
+ const rectColor = (theme === 'dark' ? 'white' : 'black');
53
+ const spec = {
54
+ $schema: 'https://vega.github.io/schema/vega/v5.json',
55
+ description: `A violin plot showing distributions of expression levels for selected ${obsType} sets.`,
56
+ width: plotWidth,
57
+ height: plotHeight,
58
+ config: {
59
+ ...VEGA_THEMES[theme],
60
+ axisBand: {
61
+ bandPosition: 1,
62
+ tickExtra: true,
63
+ tickOffset: 0,
64
+ },
65
+ },
66
+ signals: [
67
+ { name: 'bandWidth', value: bandWidth },
68
+ { name: 'width', value: plotWidth },
69
+ { name: 'height', value: plotHeight },
70
+ { name: 'trim', value: true },
71
+ ],
72
+ data: [
73
+ {
74
+ name: 'density',
75
+ source: DATASET_NAME,
76
+ transform: [
77
+ {
78
+ type: 'kde',
79
+ field: 'value',
80
+ groupby: ['set'],
81
+ bandwidth: 0,
82
+ extent: [0, domainMax],
83
+ },
84
+ ],
85
+ },
86
+ {
87
+ name: 'stats',
88
+ source: DATASET_NAME,
89
+ transform: [
90
+ {
91
+ type: 'aggregate',
92
+ groupby: ['set'],
93
+ fields: ['value', 'value', 'value'],
94
+ ops: ['q1', 'median', 'q3'],
95
+ as: ['q1', 'median', 'q3'],
96
+ },
97
+ ],
98
+ },
99
+ ],
100
+ scales: [
101
+ {
102
+ name: 'layout',
103
+ type: 'band',
104
+ range: 'width',
105
+ domain: { data: DATASET_NAME, field: 'set' },
106
+ },
107
+ {
108
+ name: 'yscale',
109
+ type: 'linear',
110
+ range: 'height',
111
+ domain: [0, domainMax],
112
+ },
113
+ {
114
+ name: 'wscale',
115
+ type: 'linear',
116
+ range: [0, { signal: 'bandWidth' }],
117
+ domain: { data: 'density', field: 'density' },
118
+ },
119
+ {
120
+ name: 'wscaleReversed',
121
+ type: 'linear',
122
+ reverse: true,
123
+ range: [0, { signal: 'bandWidth' }],
124
+ domain: { data: 'density', field: 'density' },
125
+ },
126
+ {
127
+ name: 'color',
128
+ type: 'ordinal',
129
+ ...colorScale,
130
+ },
131
+ ],
132
+ axes: [
133
+ {
134
+ orient: 'left',
135
+ scale: 'yscale',
136
+ zindex: 1,
137
+ title: (featureValueTransformName && featureValueTransformName !== 'None')
138
+ ? [`${featureValueTransformName}-Transformed`, `${capitalize(featureValueType)} Values`]
139
+ : `${capitalize(featureValueType)} Values`,
140
+ },
141
+ {
142
+ orient: 'bottom',
143
+ scale: 'layout',
144
+ tickCount: 5,
145
+ zindex: 1,
146
+ title: `${capitalize(obsType)} Set`,
147
+ labelAngle: -45,
148
+ labelAlign: 'right',
149
+ },
150
+ ],
151
+ marks: [
152
+ {
153
+ type: 'group',
154
+ from: {
155
+ facet: {
156
+ data: 'density',
157
+ name: 'violin',
158
+ groupby: 'set',
159
+ },
160
+ },
161
+ encode: {
162
+ enter: {
163
+ xc: { scale: 'layout', field: 'set', band: 0.5 },
164
+ width: { signal: 'bandWidth' },
165
+ height: { signal: 'height' },
166
+ },
167
+ },
168
+ data: [
169
+ {
170
+ name: 'summary',
171
+ source: 'stats',
172
+ transform: [
173
+ {
174
+ type: 'filter',
175
+ expr: 'datum.set === parent.set',
176
+ },
177
+ ],
178
+ },
179
+ ],
180
+ marks: [
181
+ {
182
+ type: 'area',
183
+ orient: 'vertical',
184
+ from: { data: 'violin' },
185
+ encode: {
186
+ enter: {
187
+ fill: { scale: 'color', field: { parent: 'set' } },
188
+ },
189
+ update: {
190
+ width: { scale: 'wscale', field: 'density' },
191
+ xc: { signal: 'bandWidth / 2' },
192
+ y2: { scale: 'yscale', field: 'value' },
193
+ y: { scale: 'yscale', value: 0 },
194
+ },
195
+ },
196
+ },
197
+ {
198
+ type: 'area',
199
+ orient: 'vertical',
200
+ from: { data: 'violin' },
201
+ encode: {
202
+ enter: {
203
+ fill: { scale: 'color', field: { parent: 'set' } },
204
+ },
205
+ update: {
206
+ width: { scale: 'wscaleReversed', field: 'density' },
207
+ xc: { signal: 'bandWidth' },
208
+ y2: { scale: 'yscale', field: 'value' },
209
+ y: { scale: 'yscale', value: 0 },
210
+ },
211
+ },
212
+ },
213
+ {
214
+ type: 'rect',
215
+ from: { data: 'summary' },
216
+ encode: {
217
+ enter: {
218
+ fill: { value: rectColor },
219
+ width: { value: 2 },
220
+ },
221
+ update: {
222
+ y: { scale: 'yscale', field: 'q1' },
223
+ y2: { scale: 'yscale', field: 'q3' },
224
+ xc: { signal: 'bandWidth / 2' },
225
+ },
226
+ },
227
+ },
228
+ {
229
+ type: 'rect',
230
+ from: { data: 'summary' },
231
+ encode: {
232
+ enter: {
233
+ fill: { value: rectColor },
234
+ height: { value: 2 },
235
+ width: { value: 8 },
236
+ },
237
+ update: {
238
+ y: { scale: 'yscale', field: 'median' },
239
+ xc: { signal: 'bandWidth / 2' },
240
+ },
241
+ },
242
+ },
243
+ ],
244
+ },
245
+ ],
246
+ };
247
+ return (_jsx(VegaPlot, { data: data, spec: spec }));
248
+ }
@@ -0,0 +1,2 @@
1
+ export default function CellSetExpressionPlotOptions(props: any): JSX.Element;
2
+ //# sourceMappingURL=CellSetExpressionPlotOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CellSetExpressionPlotOptions.d.ts","sourceRoot":"","sources":["../src/CellSetExpressionPlotOptions.js"],"names":[],"mappings":"AAIA,8EAoEC"}
@@ -0,0 +1,30 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import React from 'react';
3
+ import { TableCell, TableRow, TextField } from '@material-ui/core';
4
+ import { usePlotOptionsStyles, OptionsContainer, OptionSelect } from '@vitessce/vit-s';
5
+ export default function CellSetExpressionPlotOptions(props) {
6
+ const { featureValueTransform, setFeatureValueTransform, featureValueTransformCoefficient, setFeatureValueTransformCoefficient, transformOptions, } = props;
7
+ const classes = usePlotOptionsStyles();
8
+ const handleTransformChange = (event) => {
9
+ setFeatureValueTransform(event.target.value === '' ? null : event.target.value);
10
+ };
11
+ // Feels a little hacky, but I think this is the best way to handle
12
+ // the limitations of the v4 material-ui number input.
13
+ const handleTransformCoefficientChange = (event) => {
14
+ const { value } = event.target;
15
+ if (!value) {
16
+ setFeatureValueTransformCoefficient(value);
17
+ }
18
+ else {
19
+ const newCoefficient = Number(value);
20
+ if (!Number.isNaN(newCoefficient) && newCoefficient >= 0) {
21
+ setFeatureValueTransformCoefficient(value);
22
+ }
23
+ }
24
+ };
25
+ return (_jsxs(OptionsContainer, { children: [_jsxs(TableRow, { children: [_jsx(TableCell, { className: classes.labelCell, children: "Transform" }), _jsx(TableCell, { className: classes.inputCell, children: _jsx(OptionSelect, { className: classes.select, value: featureValueTransform === null ? '' : featureValueTransform, onChange: handleTransformChange, inputProps: {
26
+ id: 'scatterplot-transform-select',
27
+ }, children: transformOptions.map(opt => (_jsx("option", { value: opt.value === null ? '' : opt.value, children: opt.name }, opt.name))) }, "gating-transform-select") })] }), _jsxs(TableRow, { children: [_jsx(TableCell, { className: classes.labelCell, children: "Transform Coefficient" }), _jsx(TableCell, { className: classes.inputCell, children: _jsx(TextField, { label: "Number", type: "number", onChange: handleTransformCoefficientChange, value: featureValueTransformCoefficient, InputLabelProps: {
28
+ shrink: true,
29
+ } }) })] }, "transform-coefficient-option-row")] }));
30
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * A subscriber component for `CellSetExpressionPlot`,
3
+ * which listens for gene selection updates and
4
+ * `GRID_RESIZE` events.
5
+ * @param {object} props
6
+ * @param {function} props.removeGridComponent The grid component removal function.
7
+ * @param {object} props.coordinationScopes An object mapping coordination
8
+ * types to coordination scopes.
9
+ * @param {string} props.theme The name of the current Vitessce theme.
10
+ */
11
+ export function CellSetExpressionPlotSubscriber(props: {
12
+ removeGridComponent: Function;
13
+ coordinationScopes: object;
14
+ theme: string;
15
+ }): JSX.Element;
16
+ //# sourceMappingURL=CellSetExpressionPlotSubscriber.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CellSetExpressionPlotSubscriber.d.ts","sourceRoot":"","sources":["../src/CellSetExpressionPlotSubscriber.js"],"names":[],"mappings":"AAiGA;;;;;;;;;GASG;AACH;IAL2B,mBAAmB;IACrB,kBAAkB,EAAhC,MAAM;IAEQ,KAAK,EAAnB,MAAM;gBAsHhB"}
@@ -0,0 +1,111 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import React, { useMemo } from 'react';
3
+ import { TitleInfo, useCoordination, useLoaders, useUrls, useReady, useGridItemSize, useFeatureSelection, useObsSetsData, useObsFeatureMatrixIndices, useFeatureLabelsData, } from '@vitessce/vit-s';
4
+ import { ViewType, COMPONENT_COORDINATION_TYPES } from '@vitessce/constants-internal';
5
+ import { VALUE_TRANSFORM_OPTIONS, capitalize, getValueTransformFunction } from '@vitessce/utils';
6
+ import { treeToObjectsBySetNames, treeToSetSizesBySetNames, mergeObsSets } from '@vitessce/sets-utils';
7
+ import CellSetExpressionPlotOptions from './CellSetExpressionPlotOptions.js';
8
+ import CellSetExpressionPlot from './CellSetExpressionPlot.js';
9
+ import { useStyles } from './styles.js';
10
+ /**
11
+ * Get expression data for the cells
12
+ * in the selected cell sets.
13
+ * @param {object} expressionMatrix
14
+ * @param {string[]} expressionMatrix.rows Cell IDs.
15
+ * @param {string[]} expressionMatrix.cols Gene names.
16
+ * @param {Uint8Array} expressionMatrix.matrix The
17
+ * flattened expression matrix as a typed array.
18
+ * @param {object} cellSets The cell sets from the dataset.
19
+ * @param {object} additionalCellSets The user-defined cell sets
20
+ * from the coordination space.
21
+ * @param {array} geneSelection Array of selected genes.
22
+ * @param {array} cellSetSelection Array of selected cell set paths.
23
+ * @param {object[]} cellSetColor Array of objects with properties
24
+ * @param {string|null} featureValueTransform The name of the
25
+ * feature value transform function.
26
+ * @param {number} featureValueTransformCoefficient A coefficient
27
+ * to be used in the transform function.
28
+ * @param {string} theme "light" or "dark" for the vitessce theme
29
+ * `path` and `color`.
30
+ */
31
+ function useExpressionByCellSet(expressionData, obsIndex, cellSets, additionalCellSets, geneSelection, cellSetSelection, cellSetColor, featureValueTransform, featureValueTransformCoefficient, theme) {
32
+ const mergedCellSets = useMemo(() => mergeObsSets(cellSets, additionalCellSets), [cellSets, additionalCellSets]);
33
+ // From the expression matrix and the list of selected genes / cell sets,
34
+ // generate the array of data points for the plot.
35
+ const [expressionArr, expressionMax] = useMemo(() => {
36
+ if (mergedCellSets && cellSetSelection
37
+ && geneSelection && geneSelection.length >= 1
38
+ && expressionData) {
39
+ const cellObjects = treeToObjectsBySetNames(mergedCellSets, cellSetSelection, cellSetColor, theme);
40
+ const firstGeneSelected = geneSelection[0];
41
+ // Create new cellColors map based on the selected gene.
42
+ let exprMax = -Infinity;
43
+ const cellIndices = {};
44
+ for (let i = 0; i < obsIndex.length; i += 1) {
45
+ cellIndices[obsIndex[i]] = i;
46
+ }
47
+ const exprValues = cellObjects.map((cell) => {
48
+ const cellIndex = cellIndices[cell.obsId];
49
+ const value = expressionData[0][cellIndex];
50
+ const transformFunction = getValueTransformFunction(featureValueTransform, featureValueTransformCoefficient);
51
+ const transformedValue = transformFunction(value);
52
+ exprMax = Math.max(transformedValue, exprMax);
53
+ return { value: transformedValue, gene: firstGeneSelected, set: cell.name };
54
+ });
55
+ return [exprValues, exprMax];
56
+ }
57
+ return [null, null];
58
+ }, [expressionData, obsIndex, geneSelection, theme,
59
+ mergedCellSets, cellSetSelection, cellSetColor,
60
+ featureValueTransform, featureValueTransformCoefficient,
61
+ ]);
62
+ // From the cell sets hierarchy and the list of selected cell sets,
63
+ // generate the array of set sizes data points for the bar plot.
64
+ const setArr = useMemo(() => (mergedCellSets && cellSetSelection && cellSetColor
65
+ ? treeToSetSizesBySetNames(mergedCellSets, cellSetSelection, cellSetSelection, cellSetColor, theme)
66
+ : []), [mergedCellSets, cellSetSelection, cellSetColor, theme]);
67
+ return [expressionArr, setArr, expressionMax];
68
+ }
69
+ /**
70
+ * A subscriber component for `CellSetExpressionPlot`,
71
+ * which listens for gene selection updates and
72
+ * `GRID_RESIZE` events.
73
+ * @param {object} props
74
+ * @param {function} props.removeGridComponent The grid component removal function.
75
+ * @param {object} props.coordinationScopes An object mapping coordination
76
+ * types to coordination scopes.
77
+ * @param {string} props.theme The name of the current Vitessce theme.
78
+ */
79
+ export function CellSetExpressionPlotSubscriber(props) {
80
+ const { coordinationScopes, removeGridComponent, theme, } = props;
81
+ const classes = useStyles();
82
+ const loaders = useLoaders();
83
+ // Get "props" from the coordination space.
84
+ const [{ dataset, obsType, featureType, featureValueType, featureSelection: geneSelection, featureValueTransform, featureValueTransformCoefficient, obsSetSelection: cellSetSelection, obsSetColor: cellSetColor, additionalObsSets: additionalCellSets, }, { setFeatureValueTransform, setFeatureValueTransformCoefficient, }] = useCoordination(COMPONENT_COORDINATION_TYPES[ViewType.OBS_SET_FEATURE_VALUE_DISTRIBUTION], coordinationScopes);
85
+ const [width, height, containerRef] = useGridItemSize();
86
+ const transformOptions = VALUE_TRANSFORM_OPTIONS;
87
+ // Get data from loaders using the data hooks.
88
+ // eslint-disable-next-line no-unused-vars
89
+ const [expressionData, loadedFeatureSelection, featureSelectionStatus] = useFeatureSelection(loaders, dataset, false, geneSelection, { obsType, featureType, featureValueType });
90
+ // TODO: support multiple feature labels using featureLabelsType coordination values.
91
+ const [{ featureLabelsMap }, featureLabelsStatus, featureLabelsUrls] = useFeatureLabelsData(loaders, dataset, false, {}, {}, { featureType });
92
+ const [{ obsIndex }, matrixIndicesStatus, matrixIndicesUrls] = useObsFeatureMatrixIndices(loaders, dataset, false, { obsType, featureType, featureValueType });
93
+ const [{ obsSets: cellSets }, obsSetsStatus, obsSetsUrls] = useObsSetsData(loaders, dataset, true, {}, {}, { obsType });
94
+ const isReady = useReady([
95
+ featureSelectionStatus,
96
+ matrixIndicesStatus,
97
+ obsSetsStatus,
98
+ featureLabelsStatus,
99
+ ]);
100
+ const urls = useUrls([
101
+ featureLabelsUrls,
102
+ matrixIndicesUrls,
103
+ obsSetsUrls,
104
+ ]);
105
+ const [expressionArr, setArr, expressionMax] = useExpressionByCellSet(expressionData, obsIndex, cellSets, additionalCellSets, geneSelection, cellSetSelection, cellSetColor, featureValueTransform, featureValueTransformCoefficient, theme);
106
+ const firstGeneSelected = geneSelection && geneSelection.length >= 1
107
+ ? (featureLabelsMap?.get(geneSelection[0]) || geneSelection[0])
108
+ : null;
109
+ const selectedTransformName = transformOptions.find(o => o.value === featureValueTransform)?.name;
110
+ return (_jsx(TitleInfo, { title: `Expression by ${capitalize(obsType)} Set${(firstGeneSelected ? ` (${firstGeneSelected})` : '')}`, removeGridComponent: removeGridComponent, urls: urls, theme: theme, isReady: isReady, options: (_jsx(CellSetExpressionPlotOptions, { featureValueTransform: featureValueTransform, setFeatureValueTransform: setFeatureValueTransform, featureValueTransformCoefficient: featureValueTransformCoefficient, setFeatureValueTransformCoefficient: setFeatureValueTransformCoefficient, transformOptions: transformOptions })), children: _jsx("div", { ref: containerRef, className: classes.vegaContainer, children: expressionArr ? (_jsx(CellSetExpressionPlot, { domainMax: expressionMax, colors: setArr, data: expressionArr, theme: theme, width: width, height: height, obsType: obsType, featureValueType: featureValueType, featureValueTransformName: selectedTransformName })) : (_jsxs("span", { children: ["Select a ", featureType, "."] })) }) }));
111
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Cell set sizes displayed as a bar chart,
3
+ * implemented with the VegaPlot component.
4
+ * @param {object} props
5
+ * @param {object[]} props.data The set size data, an array
6
+ * of objects with properties `name`, `key`, `color`, and `size`.
7
+ * @param {string} props.theme The name of the current Vitessce theme.
8
+ * @param {number} props.width The container width.
9
+ * @param {number} props.height The container height.
10
+ * @param {number} props.marginRight The size of the margin
11
+ * on the right side of the plot, to account for the vega menu button.
12
+ * By default, 90.
13
+ * @param {number} props.marginBottom The size of the margin
14
+ * on the bottom of the plot, to account for long x-axis labels.
15
+ * By default, 120.
16
+ * @param {number} props.keyLength The length of the `key` property of
17
+ * each data point. Assumes all key strings have the same length.
18
+ * By default, 36.
19
+ */
20
+ export default function CellSetSizesPlot(props: {
21
+ data: object[];
22
+ theme: string;
23
+ width: number;
24
+ height: number;
25
+ marginRight: number;
26
+ marginBottom: number;
27
+ keyLength: number;
28
+ }): JSX.Element;
29
+ //# sourceMappingURL=CellSetSizesPlot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CellSetSizesPlot.d.ts","sourceRoot":"","sources":["../src/CellSetSizesPlot.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;GAkBG;AACH;IAf2B,IAAI,EAApB,MAAM,EAAE;IAEM,KAAK,EAAnB,MAAM;IACQ,KAAK,EAAnB,MAAM;IACQ,MAAM,EAApB,MAAM;IACQ,WAAW,EAAzB,MAAM;IAGQ,YAAY,EAA1B,MAAM;IAGQ,SAAS,EAAvB,MAAM;gBAuJhB"}
@@ -0,0 +1,149 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import React, { useCallback } from 'react';
3
+ import { clamp } from 'lodash-es';
4
+ import { VegaPlot, VEGA_THEMES } from '@vitessce/vega';
5
+ import { colorArrayToString } from '@vitessce/sets-utils';
6
+ import { capitalize, getDefaultColor } from '@vitessce/utils';
7
+ /**
8
+ * Cell set sizes displayed as a bar chart,
9
+ * implemented with the VegaPlot component.
10
+ * @param {object} props
11
+ * @param {object[]} props.data The set size data, an array
12
+ * of objects with properties `name`, `key`, `color`, and `size`.
13
+ * @param {string} props.theme The name of the current Vitessce theme.
14
+ * @param {number} props.width The container width.
15
+ * @param {number} props.height The container height.
16
+ * @param {number} props.marginRight The size of the margin
17
+ * on the right side of the plot, to account for the vega menu button.
18
+ * By default, 90.
19
+ * @param {number} props.marginBottom The size of the margin
20
+ * on the bottom of the plot, to account for long x-axis labels.
21
+ * By default, 120.
22
+ * @param {number} props.keyLength The length of the `key` property of
23
+ * each data point. Assumes all key strings have the same length.
24
+ * By default, 36.
25
+ */
26
+ export default function CellSetSizesPlot(props) {
27
+ const { data: rawData, theme, width, height, marginRight = 90, marginBottom = 120, keyLength = 36, obsType, onBarSelect, } = props;
28
+ // Add a property `keyName` which concatenates the key and the name,
29
+ // which is both unique and can easily be converted
30
+ // back to the name by taking a substring.
31
+ // Add a property `colorString` which contains the `[r, g, b]` color
32
+ // after converting to a color hex string.
33
+ const data = rawData.map(d => ({
34
+ ...d,
35
+ keyName: d.key + d.name,
36
+ colorString: colorArrayToString(d.color),
37
+ }));
38
+ // Get an array of keys for sorting purposes.
39
+ const keys = data.map(d => d.keyName);
40
+ const colorScale = {
41
+ // Manually set the color scale so that Vega-Lite does
42
+ // not choose the colors automatically.
43
+ domain: data.map(d => d.key),
44
+ range: data.map((d) => {
45
+ const [r, g, b] = !d.isGrayedOut ? d.color : getDefaultColor(theme);
46
+ return `rgba(${r}, ${g}, ${b}, 1)`;
47
+ }),
48
+ };
49
+ const captializedObsType = capitalize(obsType);
50
+ const spec = {
51
+ mark: { type: 'bar', stroke: 'black', cursor: 'pointer' },
52
+ params: [
53
+ {
54
+ name: 'highlight',
55
+ select: {
56
+ type: 'point',
57
+ on: 'mouseover',
58
+ },
59
+ },
60
+ {
61
+ name: 'select',
62
+ select: 'point',
63
+ },
64
+ {
65
+ name: 'bar_select',
66
+ select: {
67
+ type: 'point',
68
+ on: 'click[event.shiftKey === false]',
69
+ fields: ['setNamePath', 'isGrayedOut'],
70
+ empty: 'none',
71
+ },
72
+ },
73
+ {
74
+ name: 'shift_bar_select',
75
+ select: {
76
+ type: 'point',
77
+ on: 'click[event.shiftKey]',
78
+ fields: ['setNamePath', 'isGrayedOut'],
79
+ empty: 'none',
80
+ },
81
+ },
82
+ ],
83
+ encoding: {
84
+ x: {
85
+ field: 'keyName',
86
+ type: 'nominal',
87
+ axis: { labelExpr: `substring(datum.label, ${keyLength})` },
88
+ title: 'Cell Set',
89
+ sort: keys,
90
+ },
91
+ y: {
92
+ field: 'size',
93
+ type: 'quantitative',
94
+ title: `${captializedObsType} Set Size`,
95
+ },
96
+ color: {
97
+ field: 'key',
98
+ type: 'nominal',
99
+ scale: colorScale,
100
+ legend: null,
101
+ },
102
+ tooltip: {
103
+ field: 'size',
104
+ type: 'quantitative',
105
+ },
106
+ fillOpacity: {
107
+ condition: {
108
+ param: 'select',
109
+ value: 1,
110
+ },
111
+ value: 0.3,
112
+ },
113
+ strokeWidth: {
114
+ condition: [
115
+ {
116
+ param: 'select',
117
+ empty: false,
118
+ value: 1,
119
+ },
120
+ {
121
+ param: 'highlight',
122
+ empty: false,
123
+ value: 2,
124
+ },
125
+ ],
126
+ value: 0,
127
+ },
128
+ },
129
+ width: clamp(width - marginRight, 10, Infinity),
130
+ height: clamp(height - marginBottom, 10, Infinity),
131
+ config: VEGA_THEMES[theme],
132
+ };
133
+ const handleSignal = (name, value) => {
134
+ if (name === 'bar_select') {
135
+ onBarSelect(value.setNamePath, value.isGrayedOut[0]);
136
+ }
137
+ else if (name === 'shift_bar_select') {
138
+ const isGrayedOut = false;
139
+ const selectOnlyEnabled = true;
140
+ onBarSelect(value.setNamePath, isGrayedOut, selectOnlyEnabled);
141
+ }
142
+ };
143
+ const signalListeners = { bar_select: handleSignal, shift_bar_select: handleSignal };
144
+ const getTooltipText = useCallback(item => ({
145
+ [`${captializedObsType} Set`]: item.datum.name,
146
+ [`${captializedObsType} Set Size`]: item.datum.size,
147
+ }), [captializedObsType]);
148
+ return (_jsx(VegaPlot, { data: data, spec: spec, signalListeners: signalListeners, getTooltipText: getTooltipText }));
149
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * A subscriber component for `CellSetSizePlot`,
3
+ * which listens for cell sets data updates and
4
+ * `GRID_RESIZE` events.
5
+ * @param {object} props
6
+ * @param {function} props.removeGridComponent The grid component removal function.
7
+ * @param {function} props.onReady The function to call when the subscriptions
8
+ * have been made.
9
+ * @param {string} props.theme The name of the current Vitessce theme.
10
+ * @param {string} props.title The component title.
11
+ */
12
+ export function CellSetSizesPlotSubscriber(props: {
13
+ removeGridComponent: Function;
14
+ onReady: Function;
15
+ theme: string;
16
+ title: string;
17
+ }): JSX.Element;
18
+ //# sourceMappingURL=CellSetSizesPlotSubscriber.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CellSetSizesPlotSubscriber.d.ts","sourceRoot":"","sources":["../src/CellSetSizesPlotSubscriber.js"],"names":[],"mappings":"AAgBA;;;;;;;;;;GAUG;AACH;IAN2B,mBAAmB;IACnB,OAAO;IAET,KAAK,EAAnB,MAAM;IACQ,KAAK,EAAnB,MAAM;gBA2HhB"}