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 ( } // minimal /* removes arrow */ position={Position.TOP_LEFT} content={

Embedding Choice

There are {schema?.dataframe?.nObs} cells in the entire dataset.

} />
); } } 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 ( {layoutChoice.available.map((name) => ( ))} ); } if (data) { return ( {data.map((summary) => { const { discreteCellIndex, embeddingName } = summary; const sizeHint = `${discreteCellIndex.size()} cells`; return ( ); })} ); } return null; };