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: Interactive color legend #1059

Merged
merged 2 commits into from
Jun 6, 2023
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
2 changes: 1 addition & 1 deletion app/charts/area/areas-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const useAreasState = (
// No animation yet for areas
animationField: undefined,
getX,
getSegment,
getSegment: getSegmentAbbreviationOrLabel,
});

const chartWideData = useMemo(() => {
Expand Down
4 changes: 2 additions & 2 deletions app/charts/column/columns-grouped-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import {
} from "@/charts/column/constants";
import {
getLabelWithUnit,
useDataAfterInteractiveFilters,
getMaybeTemporalDimensionValues,
useDataAfterInteractiveFilters,
useOptionalNumericVariable,
usePlottableData,
useTemporalVariable,
Expand Down Expand Up @@ -189,7 +189,7 @@ const useGroupedColumnsState = (
interactiveFiltersConfig,
animationField: fields.animation,
getX: getXAsDate,
getSegment,
getSegment: getSegmentAbbreviationOrLabel,
});

// segments
Expand Down
31 changes: 23 additions & 8 deletions app/charts/column/columns-stacked-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import {
} from "@/charts/column/constants";
import {
getLabelWithUnit,
getMaybeTemporalDimensionValues,
getWideData,
useDataAfterInteractiveFilters,
getMaybeTemporalDimensionValues,
useOptionalNumericVariable,
usePlottableData,
useTemporalVariable,
Expand Down Expand Up @@ -202,7 +202,7 @@ const useColumnsStackedState = (
interactiveFiltersConfig,
animationField: fields.animation,
getX: getXAsDate,
getSegment,
getSegment: getSegmentAbbreviationOrLabel,
});

const preparedDataGroupedByX = useMemo(
Expand Down Expand Up @@ -244,9 +244,12 @@ const useColumnsStackedState = (
const segmentFilter = segmentDimension?.iri
? chartConfig.filters[segmentDimension?.iri]
: undefined;
const segments = useMemo(() => {
const uniqueSegments = Array.from(
new Set(plottableSortedData.map((d) => getSegment(d)))
const { segments, plottableSegments } = useMemo(() => {
const allUniqueSegments = Array.from(
new Set(plottableSortedData.map(getSegment))
);
const allPlottableSegments = Array.from(
new Set(preparedData.map(getSegment))
);

const sorting = fields?.segment?.sorting;
Expand All @@ -257,9 +260,21 @@ const useColumnsStackedState = (
dimensionFilter: segmentFilter,
});

return orderBy(uniqueSegments, sorters, getSortingOrders(sorters, sorting));
const allSegments = orderBy(
allUniqueSegments,
sorters,
getSortingOrders(sorters, sorting)
);

return {
segments: allSegments,
plottableSegments: allSegments.filter((d) =>
allPlottableSegments.includes(d)
),
};
bprusinowski marked this conversation as resolved.
Show resolved Hide resolved
}, [
plottableSortedData,
preparedData,
segmentDimension,
fields.segment?.sorting,
fields.segment?.useAbbreviations,
Expand Down Expand Up @@ -393,15 +408,15 @@ const useColumnsStackedState = (
const stacked = stack()
.order(stackOrder)
.offset(stackOffsetDiverging)
.keys(segments);
.keys(plottableSegments);

const series = stacked(
chartWideData as {
[key: string]: number;
}[]
);
return series;
}, [chartWideData, fields.segment?.sorting, segments]);
}, [chartWideData, fields.segment?.sorting, plottableSegments]);

/** Chart dimensions */
const { left, bottom } = useChartPadding(
Expand Down
2 changes: 1 addition & 1 deletion app/charts/line/lines-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ const useLinesState = (
// No animation yet for lines
animationField: undefined,
getX,
getSegment,
getSegment: getSegmentAbbreviationOrLabel,
});

const preparedDataGroupedBySegment = useMemo(
Expand Down
2 changes: 1 addition & 1 deletion app/charts/pie/pie-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const usePieState = (
sortedData: plottableData,
interactiveFiltersConfig,
animationField: fields.animation,
getSegment,
getSegment: getSegmentAbbreviationOrLabel,
});

// Map ordered segments to colors
Expand Down
2 changes: 1 addition & 1 deletion app/charts/scatterplot/scatterplot-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const useScatterplotState = ({
interactiveFiltersConfig,
// No animation yet for scatterplot
animationField: undefined,
getSegment,
getSegment: getSegmentAbbreviationOrLabel,
});
const xMeasure = measures.find((d) => d.iri === fields.x.componentIri);

Expand Down
2 changes: 1 addition & 1 deletion app/charts/shared/chart-helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import {
InteractiveFiltersLegend,
InteractiveFiltersTimeRange,
isAreaConfig,
QueryFilters,
MapConfig,
QueryFilters,
} from "@/configurator/config-types";
import { FIELD_VALUE_NONE } from "@/configurator/constants";
import { isTemporalDimension, Observation } from "@/domain/data";
Expand Down