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

fix: Retrieval of geo coordinates for shared dimensions #1327

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions app/charts/map/map-state-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ export const useMapStateVariables = (
);
}

const { getValue: getArea } = useDimensionWithAbbreviations(
areaLayerDimension,
{ observations, field: areaLayer }
);

const symbolLayerDimension = dimensions.find(
(d) => d.iri === symbolLayer?.componentIri
);
Expand All @@ -70,17 +65,18 @@ export const useMapStateVariables = (
);
}

const { getValue: getSymbol } = useDimensionWithAbbreviations(
symbolLayerDimension,
{ observations, field: symbolLayer }
);
const { getValue: getSymbol, getLabel: getSymbolLabel } =
useDimensionWithAbbreviations(symbolLayerDimension, {
observations,
field: symbolLayer,
});

return {
...baseVariables,
areaLayerDimension,
getArea,
symbolLayerDimension,
getSymbol,
getSymbolLabel,
};
};

Expand All @@ -96,7 +92,12 @@ export const useMapStateData = (
variables: MapStateVariables
): MapStateData => {
const { chartConfig, observations, shapes, coordinates } = chartProps;
const { areaLayerDimension, symbolLayerDimension, getSymbol } = variables;
const {
areaLayerDimension,
symbolLayerDimension,
getSymbol,
getSymbolLabel,
} = variables;
const filters = useChartConfigFilters(chartConfig);
// No need to sort the data for map.
const plottableData = usePlottableData(observations, {});
Expand Down Expand Up @@ -134,8 +135,9 @@ export const useMapStateData = (
const coordsByLabel = keyBy(coordinates, (d) => d.label);

data.chartData.forEach((d) => {
const label = getSymbol(d);
const coords = coordsByLabel[label];
const value = getSymbol(d);
const label = getSymbolLabel(value);
const coords = coordsByLabel[value] ?? coordsByLabel[label];

if (coords) {
const { iri, label, latitude, longitude } = coords;
Expand Down Expand Up @@ -182,6 +184,7 @@ export const useMapStateData = (
}, [
symbolLayerDimension,
getSymbol,
getSymbolLabel,
data.chartData,
shapes,
coordinates,
Expand Down
2 changes: 1 addition & 1 deletion app/charts/shared/chart-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ export const useSegmentVariables = (

export type AreaLayerVariables = {
areaLayerDimension: GeoShapesDimension | undefined;
getArea: StringValueGetter;
};

export type SymbolLayerVariables = {
Expand All @@ -339,6 +338,7 @@ export type SymbolLayerVariables = {
| GeoCoordinatesDimension
| undefined;
getSymbol: StringValueGetter;
getSymbolLabel: (d: string) => string;
};

export type ChartStateData = {
Expand Down
Loading