Skip to content

Commit

Permalink
added Dave's suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
bobular committed May 22, 2023
1 parent 6f83513 commit 6d69a76
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -468,7 +468,7 @@ function BarplotViz(props: VisualizationProps<Options>) {
);

return grayOutLastSeries(
substituteUnselectedToken1(
substituteUnselectedToken(
reorderData(
barplotResponseToData(
response,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -537,7 +537,7 @@ function BoxplotViz(props: VisualizationProps<Options>) {
facetVariable
);
return grayOutLastSeries(
substituteUnselectedToken1(
substituteUnselectedToken(
reorderData(
boxplotResponseToData(
response,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -536,7 +536,7 @@ function HistogramViz(props: VisualizationProps<Options>) {
facetVariable
);
return grayOutLastSeries(
substituteUnselectedToken1(
substituteUnselectedToken(
reorderData(
histogramResponseToData(
response,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ import {
vocabularyWithMissingData,
hasIncompleteCases,
assertValidInputVariables,
substituteUnselectedToken2,
substituteUnselectedToken,
} from '../../../utils/visualization';
import { gray } from '../colors';
import {
Expand Down Expand Up @@ -1965,7 +1965,7 @@ export function lineplotResponseToData(
})),
};
return {
dataSetProcess: substituteUnselectedToken2(dataSetProcess!),
dataSetProcess: substituteUnselectedToken(dataSetProcess!),
// calculated y axis limits
xMin,
xMinPos,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ import {
fixVarIdLabel,
getVariableLabel,
assertValidInputVariables,
substituteUnselectedToken2,
substituteUnselectedToken,
} from '../../../utils/visualization';
import { gray } from '../colors';
import {
Expand Down Expand Up @@ -2236,7 +2236,7 @@ export function scatterplotResponseToData(
);

return {
dataSetProcess: substituteUnselectedToken2(dataSetProcess),
dataSetProcess: substituteUnselectedToken(dataSetProcess),
xMin,
xMinPos,
xMax,
Expand Down
33 changes: 5 additions & 28 deletions packages/libs/eda/src/lib/core/utils/visualization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,39 +80,16 @@ type NamedSeries = {
}[];
};

// boxplot, barplot, histogram
export function substituteUnselectedToken1<T extends NamedSeries>(
data: T | MaybeFacetedSeriesWithStatistics<T>
): T | MaybeFacetedSeriesWithStatistics<T> {
export function substituteUnselectedToken<
T extends NamedSeries,
Data extends T | FacetedData<T> | MaybeFacetedSeriesWithStatistics<T>
>(data: Data): Data {
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>(
data: T | FacetedData<T>
): T | FacetedData<T> {
if (isFaceted(data)) {
return {
...data,
facets: data.facets.map((facet) => ({
...facet,
data: substituteUnselectedToken2(data) as T,
data: substituteUnselectedToken(data) as T,
})),
};
} else {
Expand Down

0 comments on commit 6d69a76

Please sign in to comment.