UNPKG

vitessce

Version:

Vitessce app and React component library

101 lines (90 loc) 3.27 kB
import React, { useMemo, useEffect } from 'react'; import TitleInfo from '../TitleInfo'; import { useCoordination, useLoaders } from '../../app/state/hooks'; import { COMPONENT_COORDINATION_TYPES } from '../../app/state/coordination'; import { useUrls, useReady, useGridItemSize } from '../hooks'; import { mergeCellSets } from '../utils'; import { useCellSetsData } from '../data-hooks'; import { treeToSetSizesBySetNames } from './cell-set-utils'; import CellSetSizesPlot from './CellSetSizesPlot'; const CELL_SET_SIZES_DATA_TYPES = ['cell-sets']; /** * A subscriber component for `CellSetSizePlot`, * which listens for cell sets data updates and * `GRID_RESIZE` events. * @param {object} props * @param {function} props.removeGridComponent The grid component removal function. * @param {function} props.onReady The function to call when the subscriptions * have been made. * @param {string} props.theme The name of the current Vitessce theme. * @param {string} props.title The component title. */ export default function CellSetSizesPlotSubscriber(props) { const { coordinationScopes, removeGridComponent, theme, title = 'Cell Set Sizes', } = props; const loaders = useLoaders(); // Get "props" from the coordination space. const [{ dataset, obsSetSelection: cellSetSelection, obsSetColor: cellSetColor, additionalObsSets: additionalCellSets, }, { setObsSetSelection: setCellSetSelection, setObsSetColor: setCellSetColor, }] = useCoordination(COMPONENT_COORDINATION_TYPES.cellSetSizes, coordinationScopes); const [width, height, containerRef] = useGridItemSize(); const [urls, addUrl, resetUrls] = useUrls(); const [ isReady, setItemIsReady, setItemIsNotReady, // eslint-disable-line no-unused-vars resetReadyItems, ] = useReady( CELL_SET_SIZES_DATA_TYPES, ); // Reset file URLs and loader progress when the dataset has changed. useEffect(() => { resetUrls(); resetReadyItems(); // eslint-disable-next-line react-hooks/exhaustive-deps }, [loaders, dataset]); // Get data from loaders using the data hooks. const [cellSets] = useCellSetsData( loaders, dataset, setItemIsReady, addUrl, true, { setObsSetSelection: setCellSetSelection, setObsSetColor: setCellSetColor }, { obsSetSelection: cellSetSelection, obsSetColor: cellSetColor }, ); const mergedCellSets = useMemo( () => mergeCellSets(cellSets, additionalCellSets), [cellSets, additionalCellSets], ); // From the cell sets hierarchy and the list of selected cell sets, // generate the array of set sizes data points for the bar plot. const data = useMemo(() => (mergedCellSets && cellSetSelection && cellSetColor ? treeToSetSizesBySetNames(mergedCellSets, cellSetSelection, cellSetColor, theme) : [] ), [mergedCellSets, cellSetSelection, cellSetColor, theme]); return ( <TitleInfo title={title} removeGridComponent={removeGridComponent} urls={urls} theme={theme} isReady={isReady} > <div ref={containerRef} className="vega-container"> <CellSetSizesPlot data={data} theme={theme} width={width} height={height} /> </div> </TitleInfo> ); }