Skip to content

Commit

Permalink
Users can configure markers
Browse files Browse the repository at this point in the history
  • Loading branch information
adnauseum committed Apr 27, 2023
1 parent 8cd7340 commit c951e89
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 46 deletions.
103 changes: 58 additions & 45 deletions packages/libs/eda/src/lib/map/analysis/MapAnalysis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,58 @@ function MapAnalysisImpl(props: Props & CompleteAppState) {
findEntityAndVariable(selectedVariables.overlay) ?? {};

const filters = analysisState.analysis?.descriptor.subset.descriptor;

const [markerConfigurations, setMarkerConfigurations] = useState<
MarkerConfiguration[]
>([
{
type: 'pie',
selectedVariable: selectedVariables.overlay || {
entityId: '',
variableId: '',
},
},
{
type: 'barplot',
selectedPlotMode: 'count',
selectedVariable: selectedVariables.overlay || {
entityId: '',
variableId: '',
},
},
]);

function updateMarkerConfigurations(
updatedConfiguration: MarkerConfiguration
) {
setMarkerConfigurations((configurations) =>
configurations.map((configuration) => {
if (configuration.type === updatedConfiguration.type) {
return updatedConfiguration;
}
return configuration;
})
);
}

const [activeMarkerConfigurationType, setActiveMarkerConfigurationType] =
useState<MarkerConfiguration['type']>('pie');

const activeMarkerConfiguration = markerConfigurations.find(
(markerConfig) => markerConfig.type === activeMarkerConfigurationType
);

const adaptedMarkerTypename = (() => {
if (!activeMarkerConfiguration?.type) return 'pie';

if (activeMarkerConfiguration.type === 'barplot') {
// The marker type is either 'barplot' or 'count'
return activeMarkerConfiguration.selectedPlotMode;
}

return activeMarkerConfiguration.type;
})();

/**
* Keep track of which marker type is active. `markerType` -> activeMarkerType `xAxisVariable`: selectedVariables.overlay
*/
Expand All @@ -195,9 +247,10 @@ function MapAnalysisImpl(props: Props & CompleteAppState) {
geoConfig: geoConfig,
studyId: studyMetadata.id,
filters,
xAxisVariable: selectedVariables.overlay,
xAxisVariable:
activeMarkerConfiguration?.selectedVariable || selectedVariables.overlay,
computationType: 'pass',
markerType: 'pie',
markerType: adaptedMarkerTypename,
checkedLegendItems: undefined,
//TO DO: maybe dependentAxisLogScale
});
Expand Down Expand Up @@ -422,47 +475,6 @@ function MapAnalysisImpl(props: Props & CompleteAppState) {
marginLeft: '0.5rem',
};

const [markerConfigurations, setMarkerConfigurations] = useState<
MarkerConfiguration[]
>([
{
type: 'pie',
selectedVariable: selectedVariables.overlay || {
entityId: '',
variableId: '',
},
},
{
type: 'barplot',
selectedPlotMode: 'count',
selectedVariable: selectedVariables.overlay || {
entityId: '',
variableId: '',
},
},
]);

function updateMarkerConfigurations(
updatedConfiguration: MarkerConfiguration
) {
setMarkerConfigurations((configurations) =>
configurations.map((configuration) => {
if (configuration.type === updatedConfiguration.type) {
return updatedConfiguration;
}
return configuration;
})
);
}

const [activeMarkerConfigurationType, setActiveMarkerConfigurationType] =
useState<MarkerConfiguration['type']>('barplot');

const activeMarkerConfiguration = markerConfigurations.find(
(markerConfig) => markerConfig.type === activeMarkerConfigurationType
);
const [barPlotMode, setBarPlotMode] = useState('count');

const filteredEntities = uniq(filters?.map((f) => f.entityId));
const getDefaultVariableId = useGetDefaultVariableIdCallback();

Expand Down Expand Up @@ -517,8 +529,9 @@ function MapAnalysisImpl(props: Props & CompleteAppState) {
[]
}
toggleStarredVariable={toggleStarredVariable}
onPlotSelected={setBarPlotMode}
selectedPlotMode={barPlotMode}
selectedPlotMode={
activeMarkerConfiguration.selectedPlotMode
}
configuration={activeMarkerConfiguration}
/>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ interface Props
'onChange' | 'selectedVariables' | 'selectedPlotMode' | 'onPlotSelected'
> {
selectedPlotMode: string;
onPlotSelected: (plotType: string) => void;
onChange: (configuration: BarPlotMarkerConfiguration) => void;
configuration: BarPlotMarkerConfiguration;
}
Expand Down

0 comments on commit c951e89

Please sign in to comment.