mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-09-21 19:38:12 +08:00
* add bp3 eslint plugin * first eslint runthrough + manual changes * small fixes * update snapshots * update h1 to h4 Co-authored-by: czimergebot <35308261+czimergebot@users.noreply.github.com>
155 lines
4.2 KiB
JavaScript
155 lines
4.2 KiB
JavaScript
import React from "react";
|
|
import { connect } from "react-redux";
|
|
import { useAsync } from "react-async";
|
|
import {
|
|
Button,
|
|
ButtonGroup,
|
|
H4,
|
|
Popover,
|
|
Position,
|
|
Radio,
|
|
RadioGroup,
|
|
Tooltip,
|
|
} from "@blueprintjs/core";
|
|
import * as globals from "../../globals";
|
|
import actions from "../../actions";
|
|
import { getDiscreteCellEmbeddingRowIndex } from "../../util/stateManager/viewStackHelpers";
|
|
|
|
@connect((state) => {
|
|
return {
|
|
layoutChoice: state.layoutChoice, // TODO: really should clean up naming, s/layout/embedding/g
|
|
schema: state.annoMatrix?.schema,
|
|
crossfilter: state.obsCrossfilter,
|
|
};
|
|
})
|
|
class Embedding extends React.PureComponent {
|
|
constructor(props) {
|
|
super(props);
|
|
this.state = {};
|
|
}
|
|
|
|
handleLayoutChoiceChange = (e) => {
|
|
const { dispatch } = this.props;
|
|
dispatch(actions.layoutChoiceAction(e.currentTarget.value));
|
|
};
|
|
|
|
render() {
|
|
const { layoutChoice, schema, crossfilter } = this.props;
|
|
const { annoMatrix } = crossfilter;
|
|
return (
|
|
<ButtonGroup
|
|
style={{
|
|
position: "absolute",
|
|
display: "inherit",
|
|
left: 8,
|
|
bottom: 8,
|
|
zIndex: 9999,
|
|
}}
|
|
>
|
|
<Popover
|
|
target={
|
|
<Tooltip
|
|
content="Select embedding for visualization"
|
|
position="top"
|
|
hoverOpenDelay={globals.tooltipHoverOpenDelay}
|
|
>
|
|
<Button
|
|
type="button"
|
|
data-testid="layout-choice"
|
|
icon="heatmap"
|
|
// minimal
|
|
id="embedding"
|
|
style={{
|
|
cursor: "pointer",
|
|
}}
|
|
>
|
|
{layoutChoice?.current}: {crossfilter.countSelected()} out of{" "}
|
|
{crossfilter.size()} cells
|
|
</Button>
|
|
</Tooltip>
|
|
}
|
|
// minimal /* removes arrow */
|
|
position={Position.TOP_LEFT}
|
|
content={
|
|
<div
|
|
style={{
|
|
display: "flex",
|
|
justifyContent: "flex-start",
|
|
alignItems: "flex-start",
|
|
flexDirection: "column",
|
|
padding: 10,
|
|
width: 400,
|
|
}}
|
|
>
|
|
<H4>Embedding Choice</H4>
|
|
<p style={{ fontStyle: "italic" }}>
|
|
There are {schema?.dataframe?.nObs} cells in the entire dataset.
|
|
</p>
|
|
<EmbeddingChoices
|
|
onChange={this.handleLayoutChoiceChange}
|
|
annoMatrix={annoMatrix}
|
|
layoutChoice={layoutChoice}
|
|
/>
|
|
</div>
|
|
}
|
|
/>
|
|
</ButtonGroup>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default Embedding;
|
|
|
|
const loadAllEmbeddingCounts = async ({ annoMatrix, available }) => {
|
|
const embeddings = await Promise.all(
|
|
available.map((name) => annoMatrix.base().fetch("emb", name))
|
|
);
|
|
return available.map((name, idx) => ({
|
|
embeddingName: name,
|
|
embedding: embeddings[idx],
|
|
discreteCellIndex: getDiscreteCellEmbeddingRowIndex(embeddings[idx]),
|
|
}));
|
|
};
|
|
|
|
const EmbeddingChoices = ({ onChange, annoMatrix, layoutChoice }) => {
|
|
const { available } = layoutChoice;
|
|
const { data, error, isPending } = useAsync({
|
|
promiseFn: loadAllEmbeddingCounts,
|
|
annoMatrix,
|
|
available,
|
|
});
|
|
|
|
if (error) {
|
|
/* log, as this is unexpected */
|
|
console.error(error);
|
|
}
|
|
if (error || isPending) {
|
|
/* still loading, or errored out - just omit counts (TODO: spinner?) */
|
|
return (
|
|
<RadioGroup onChange={onChange} selectedValue={layoutChoice.current}>
|
|
{layoutChoice.available.map((name) => (
|
|
<Radio label={`${name}`} value={name} key={name} />
|
|
))}
|
|
</RadioGroup>
|
|
);
|
|
}
|
|
if (data) {
|
|
return (
|
|
<RadioGroup onChange={onChange} selectedValue={layoutChoice.current}>
|
|
{data.map((summary) => {
|
|
const { discreteCellIndex, embeddingName } = summary;
|
|
const sizeHint = `${discreteCellIndex.size()} cells`;
|
|
return (
|
|
<Radio
|
|
label={`${embeddingName}: ${sizeHint}`}
|
|
value={embeddingName}
|
|
key={embeddingName}
|
|
/>
|
|
);
|
|
})}
|
|
</RadioGroup>
|
|
);
|
|
}
|
|
return null;
|
|
};
|