Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAM - fix floater overlay order #217

Merged
merged 5 commits into from
May 22, 2023
Merged

Conversation

bobular
Copy link
Member

@bobular bobular commented May 12, 2023

Resolves #218

Also moved the __UNSELECTED__ token stuff to a more central location

Tested for categorical and continuous.

Continuous doesn't work yet for scatterplot - the back end response may be malformed. See VEuPathDB/EdaDataService#285

@bobular bobular marked this pull request as draft May 12, 2023 23:31
@dmfalke
Copy link
Member

dmfalke commented May 22, 2023

Try this, for getting rid of substituteUnselectedToken1 and substituteUnselectedToken2. It makes use of function overloads.

diff --git a/packages/libs/eda/src/lib/core/components/visualizations/implementations/BarplotVisualization.tsx b/packages/libs/eda/src/lib/core/components/visualizations/implementations/BarplotVisualization.tsx
index c500566bd..87148667a 100755
--- a/packages/libs/eda/src/lib/core/components/visualizations/implementations/BarplotVisualization.tsx
+++ b/packages/libs/eda/src/lib/core/components/visualizations/implementations/BarplotVisualization.tsx
@@ -53,7 +53,7 @@ import {
   nonUniqueWarning,
   hasIncompleteCases,
   assertValidInputVariables,
-  substituteUnselectedToken1,
+  substituteUnselectedToken,
 } from '../../../utils/visualization';
 import { VariablesByInputName } from '../../../utils/data-element-constraints';
 // use lodash instead of Math.min/max
@@ -468,7 +468,7 @@ function BarplotViz(props: VisualizationProps<Options>) {
       );
 
       return grayOutLastSeries(
-        substituteUnselectedToken1(
+        substituteUnselectedToken(
           reorderData(
             barplotResponseToData(
               response,
diff --git a/packages/libs/eda/src/lib/core/components/visualizations/implementations/BoxplotVisualization.tsx b/packages/libs/eda/src/lib/core/components/visualizations/implementations/BoxplotVisualization.tsx
index 97afc036d..ac514f1b6 100755
--- a/packages/libs/eda/src/lib/core/components/visualizations/implementations/BoxplotVisualization.tsx
+++ b/packages/libs/eda/src/lib/core/components/visualizations/implementations/BoxplotVisualization.tsx
@@ -61,7 +61,7 @@ import {
   fixVarIdLabel,
   getVariableLabel,
   assertValidInputVariables,
-  substituteUnselectedToken1,
+  substituteUnselectedToken,
 } from '../../../utils/visualization';
 import { VariablesByInputName } from '../../../utils/data-element-constraints';
 import { StudyEntity, Variable } from '../../../types/study';
@@ -537,7 +537,7 @@ function BoxplotViz(props: VisualizationProps<Options>) {
         facetVariable
       );
       return grayOutLastSeries(
-        substituteUnselectedToken1(
+        substituteUnselectedToken(
           reorderData(
             boxplotResponseToData(
               response,
diff --git a/packages/libs/eda/src/lib/core/components/visualizations/implementations/HistogramVisualization.tsx b/packages/libs/eda/src/lib/core/components/visualizations/implementations/HistogramVisualization.tsx
index f92b34cb3..e473228da 100755
--- a/packages/libs/eda/src/lib/core/components/visualizations/implementations/HistogramVisualization.tsx
+++ b/packages/libs/eda/src/lib/core/components/visualizations/implementations/HistogramVisualization.tsx
@@ -64,7 +64,7 @@ import {
   variablesAreUnique,
   nonUniqueWarning,
   assertValidInputVariables,
-  substituteUnselectedToken1,
+  substituteUnselectedToken,
 } from '../../../utils/visualization';
 import { useUpdateThumbnailEffect } from '../../../hooks/thumbnails';
 // import variable's metadata-based independent axis range utils
@@ -536,7 +536,7 @@ function HistogramViz(props: VisualizationProps<Options>) {
         facetVariable
       );
       return grayOutLastSeries(
-        substituteUnselectedToken1(
+        substituteUnselectedToken(
           reorderData(
             histogramResponseToData(
               response,
diff --git a/packages/libs/eda/src/lib/core/components/visualizations/implementations/LineplotVisualization.tsx b/packages/libs/eda/src/lib/core/components/visualizations/implementations/LineplotVisualization.tsx
index b38df9d7d..727315c8f 100755
--- a/packages/libs/eda/src/lib/core/components/visualizations/implementations/LineplotVisualization.tsx
+++ b/packages/libs/eda/src/lib/core/components/visualizations/implementations/LineplotVisualization.tsx
@@ -85,7 +85,7 @@ import {
   vocabularyWithMissingData,
   hasIncompleteCases,
   assertValidInputVariables,
-  substituteUnselectedToken2,
+  substituteUnselectedToken,
 } from '../../../utils/visualization';
 import { gray } from '../colors';
 import {
@@ -1965,7 +1965,7 @@ export function lineplotResponseToData(
           })),
         };
   return {
-    dataSetProcess: substituteUnselectedToken2(dataSetProcess!),
+    dataSetProcess: substituteUnselectedToken(dataSetProcess!),
     // calculated y axis limits
     xMin,
     xMinPos,
diff --git a/packages/libs/eda/src/lib/core/components/visualizations/implementations/ScatterplotVisualization.tsx b/packages/libs/eda/src/lib/core/components/visualizations/implementations/ScatterplotVisualization.tsx
index 32ae45d18..8d7c1ab61 100755
--- a/packages/libs/eda/src/lib/core/components/visualizations/implementations/ScatterplotVisualization.tsx
+++ b/packages/libs/eda/src/lib/core/components/visualizations/implementations/ScatterplotVisualization.tsx
@@ -78,7 +78,7 @@ import {
   fixVarIdLabel,
   getVariableLabel,
   assertValidInputVariables,
-  substituteUnselectedToken2,
+  substituteUnselectedToken,
 } from '../../../utils/visualization';
 import { gray } from '../colors';
 import {
@@ -2236,7 +2236,7 @@ export function scatterplotResponseToData(
       );
 
     return {
-      dataSetProcess: substituteUnselectedToken2(dataSetProcess),
+      dataSetProcess: substituteUnselectedToken(dataSetProcess),
       xMin,
       xMinPos,
       xMax,
diff --git a/packages/libs/eda/src/lib/core/utils/visualization.ts b/packages/libs/eda/src/lib/core/utils/visualization.ts
index 476da4acf..96df39f94 100644
--- a/packages/libs/eda/src/lib/core/utils/visualization.ts
+++ b/packages/libs/eda/src/lib/core/utils/visualization.ts
@@ -80,39 +80,21 @@ type NamedSeries = {
   }[];
 };
 
-// boxplot, barplot, histogram
-export function substituteUnselectedToken1<T extends NamedSeries>(
+export function substituteUnselectedToken<T extends NamedSeries>(
   data: T | MaybeFacetedSeriesWithStatistics<T>
-): T | MaybeFacetedSeriesWithStatistics<T> {
-  if (isFaceted(data)) {
-    return {
-      ...data,
-      facets: data.facets.map((facet) => ({
-        ...facet,
-        data: substituteUnselectedToken1(data) as T,
-      })),
-    };
-  } else {
-    return {
-      ...data,
-      series: data.series.map((s) => ({
-        ...s,
-        name: s.name === UNSELECTED_TOKEN ? UNSELECTED_DISPLAY_TEXT : s.name,
-      })),
-    };
-  }
-}
-
-// lineplot, scatterplot
-export function substituteUnselectedToken2<T extends NamedSeries>(
+): T | MaybeFacetedSeriesWithStatistics<T>
+export function substituteUnselectedToken<T extends NamedSeries>(
   data: T | FacetedData<T>
-): T | FacetedData<T> {
+): T | FacetedData<T>
+export function substituteUnselectedToken<T extends NamedSeries>(
+  data: T | FacetedData<T> | MaybeFacetedSeriesWithStatistics<T>
+): T | FacetedData<T> | MaybeFacetedSeriesWithStatistics<T> {
   if (isFaceted(data)) {
     return {
       ...data,
       facets: data.facets.map((facet) => ({
         ...facet,
-        data: substituteUnselectedToken2(data) as T,
+        data: substituteUnselectedToken(data) as T,
       })),
     };
   } else {

@bobular
Copy link
Member Author

bobular commented May 22, 2023

Thanks @dmfalke and also for the two-parameter generic that solves it without overloads!

@bobular bobular merged commit 1a98b97 into sam-wire-floaters May 22, 2023
@bobular bobular deleted the sam-floater-overlay-order branch May 22, 2023 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: SAM legend and plot colors can be reversed, depending on how filters are added
2 participants