diff --git a/app/javascript/components/explore/ExploreDisplayTabs.jsx b/app/javascript/components/explore/ExploreDisplayTabs.jsx index 590fcbee4..804a0aee4 100644 --- a/app/javascript/components/explore/ExploreDisplayTabs.jsx +++ b/app/javascript/components/explore/ExploreDisplayTabs.jsx @@ -99,6 +99,14 @@ export function handleClusterSwitchForFiltering(cellFilteringSelection, newCellF } } +/** get the appropriate subsampling value, accounting for number of points & subsampling status **/ +export function getSubsampleThreshold(exploreParams, exploreInfo) { + if (exploreInfo?.cluster && !exploreInfo.cluster.isSubsampled) { + return null + } + return exploreParams?.subsample || (exploreInfo?.cluster?.numPoints > 100_000 ? 100_000 : null) +} + /** wrapper function with error handling/state setting for retrieving cell facet data */ function getCellFacetingData(cluster, annotation, setterFunctions, context, prevCellFaceting) { const [ @@ -122,7 +130,7 @@ function getCellFacetingData(cluster, annotation, setterFunctions, context, prev const allAnnots = exploreInfo?.annotationList.annotations if (allAnnots && allAnnots.length > 0) { if (!prevCellFaceting?.isFullyLoaded) { - const subsample = exploreParams?.subsample || (exploreInfo?.cluster?.numPoints > 100_000 ? 100_000 : null) + const subsample = getSubsampleThreshold(exploreParams, exploreInfo) initCellFaceting( cluster, annotation, studyAccession, allAnnots, prevCellFaceting, subsample ).then(newCellFaceting => { diff --git a/test/js/explore/explore-display-tabs.test.js b/test/js/explore/explore-display-tabs.test.js index da0c8c6d3..316b1414d 100644 --- a/test/js/explore/explore-display-tabs.test.js +++ b/test/js/explore/explore-display-tabs.test.js @@ -30,7 +30,7 @@ import React from 'react' import { render, screen, waitFor } from '@testing-library/react' import * as UserProvider from '~/providers/UserProvider' import ExploreDisplayTabs, { - getEnabledTabs, handleClusterSwitchForFiltering + getEnabledTabs, handleClusterSwitchForFiltering, getSubsampleThreshold } from 'components/explore/ExploreDisplayTabs' import ExploreDisplayPanelManager from '~/components/explore/ExploreDisplayPanelManager' import PlotTabs from 'components/explore/PlotTabs' @@ -499,4 +499,33 @@ describe('explore tabs are activated based on study info and parameters', () => }) ) }) + + it('Loads correct subsampling threshold', async () => { + const subsampleExploreInfo = { + cluster: { + isSubsampled: true, + numPoints: 212345 + } + } + const exploreInfo = { + cluster: { + isSubsampled: false, + numPoints: 212345 + } + } + const exploreWithSubsample = { + cluster: 'foo', + subsample: 100000 + } + const exploreWithoutSubsample = { cluster: 'foo'} + + let subsampleThreshold = getSubsampleThreshold(exploreWithSubsample, subsampleExploreInfo) + expect(subsampleThreshold).toEqual(exploreWithSubsample.subsample) + subsampleThreshold = getSubsampleThreshold(exploreWithoutSubsample, subsampleExploreInfo) + expect(subsampleThreshold).toEqual(100000) + subsampleThreshold = getSubsampleThreshold(exploreWithSubsample, exploreInfo) + expect(subsampleThreshold).toBeNull() + subsampleThreshold = getSubsampleThreshold(exploreWithoutSubsample, exploreInfo) + expect(subsampleThreshold).toBeNull() + }) })