Skip to content

Commit

Permalink
Merge pull request #1327 from visualize-admin/fix/geo-coords-shared-d…
Browse files Browse the repository at this point in the history
…imensions

fix: Retrieval of geo coordinates for shared dimensions
  • Loading branch information
bprusinowski authored Feb 2, 2024
2 parents 6dfaa73 + 4a1784d commit cca9946
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
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

0 comments on commit cca9946

Please sign in to comment.