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: Combo charts measure changes #1235

Merged
merged 3 commits into from
Oct 25, 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
123 changes: 112 additions & 11 deletions app/charts/chart-config-ui-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import {
isTemporalOrdinalDimension,
} from "@/domain/data";
import { DimensionMetadataFragment } from "@/graphql/query-hooks";
import { getDefaultCategoricalPaletteName } from "@/palettes";
import { getDefaultCategoricalPaletteName, getPalette } from "@/palettes";

/**
* This module controls chart controls displayed in the UI.
Expand Down Expand Up @@ -113,9 +113,31 @@ type EncodingOption<T extends ChartConfig = ChartConfig> =
| {
field: "useAbbreviations";
}
// TODO: As these are quite chart type specific, they might be handled in
// some other way.
| {
field: "lineAxisOrientation";
onChange: OnEncodingOptionChange<"left" | "right", ComboLineColumnConfig>;
}
| {
field: "componentIris";
onChange: OnEncodingOptionChange<string[], ComboLineSingleConfig>;
}
| {
field: "leftAxisComponentIri";
onChange: OnEncodingOptionChange<string, ComboLineDualConfig>;
}
| {
field: "rightAxisComponentIri";
onChange: OnEncodingOptionChange<string, ComboLineDualConfig>;
}
| {
field: "lineComponentIri";
onChange: OnEncodingOptionChange<string, ComboLineColumnConfig>;
}
| {
field: "columnComponentIri";
onChange: OnEncodingOptionChange<string, ComboLineColumnConfig>;
};

const onColorComponentScaleTypeChange: OnEncodingOptionChange<
Expand Down Expand Up @@ -894,6 +916,20 @@ const chartConfigOptionsUISpec: ChartSpecs = {
customComponent: true,
componentTypes: ["NumericalMeasure"],
filters: false,
options: {
componentIris: {
onChange: (iris, options) => {
const { chartConfig } = options;
const { fields } = chartConfig;
const { y } = fields;
const palette = getPalette(y.palette);
const newColorMapping = Object.fromEntries(
iris.map((iri, i) => [iri, y.colorMapping[i] ?? palette[i]])
);
chartConfig.fields.y.colorMapping = newColorMapping;
},
},
},
},
{
field: "x",
Expand All @@ -913,6 +949,32 @@ const chartConfigOptionsUISpec: ChartSpecs = {
customComponent: true,
componentTypes: ["NumericalMeasure"],
filters: false,
options: {
leftAxisComponentIri: {
onChange: (iri, options) => {
const { chartConfig } = options;
const { fields } = chartConfig;
const { y } = fields;
chartConfig.fields.y.colorMapping = {
[iri]: y.colorMapping[y.leftAxisComponentIri],
[y.rightAxisComponentIri]:
y.colorMapping[y.rightAxisComponentIri],
};
},
},
rightAxisComponentIri: {
onChange: (iri, options) => {
const { chartConfig } = options;
const { fields } = chartConfig;
const { y } = fields;
chartConfig.fields.y.colorMapping = {
[y.leftAxisComponentIri]:
y.colorMapping[y.leftAxisComponentIri],
[iri]: y.colorMapping[y.rightAxisComponentIri],
};
},
},
},
},
{
field: "x",
Expand All @@ -933,22 +995,51 @@ const chartConfigOptionsUISpec: ChartSpecs = {
componentTypes: ["NumericalMeasure"],
filters: false,
options: {
lineComponentIri: {
onChange: (iri, options) => {
const { chartConfig } = options;
const { fields } = chartConfig;
const { y } = fields;
const lineColor = y.colorMapping[y.lineComponentIri];
const columnColor = y.colorMapping[y.columnComponentIri];

chartConfig.fields.y.colorMapping =
y.lineAxisOrientation === "left"
? { [iri]: lineColor, [y.columnComponentIri]: columnColor }
: { [y.columnComponentIri]: columnColor, [iri]: lineColor };
},
},
columnComponentIri: {
onChange: (iri, options) => {
const { chartConfig } = options;
const { fields } = chartConfig;
const { y } = fields;
const columnColor = y.colorMapping[y.columnComponentIri];
const lineColor = y.colorMapping[y.lineComponentIri];

chartConfig.fields.y.colorMapping =
y.lineAxisOrientation === "left"
? { [y.lineComponentIri]: lineColor, [iri]: columnColor }
: { [iri]: columnColor, [y.lineComponentIri]: lineColor };
},
},
lineAxisOrientation: {
onChange: (_, options) => {
const { chartConfig } = options;
const { fields } = chartConfig;
const { y } = fields;
const lineAxisLeft = y.lineAxisOrientation === "left";
// Need the correct order to not enable "Reset color palette" button.
const firstIri =
chartConfig.fields.y.lineAxisOrientation === "left"
? chartConfig.fields.y.columnComponentIri
: chartConfig.fields.y.lineComponentIri;
const secondIri =
chartConfig.fields.y.lineAxisOrientation === "left"
? chartConfig.fields.y.lineComponentIri
: chartConfig.fields.y.columnComponentIri;
const firstIri = lineAxisLeft
? y.columnComponentIri
: y.lineComponentIri;
const secondIri = lineAxisLeft
? y.lineComponentIri
: y.columnComponentIri;

chartConfig.fields.y.colorMapping = {
[firstIri]: chartConfig.fields.y.colorMapping[secondIri],
[secondIri]: chartConfig.fields.y.colorMapping[firstIri],
[firstIri]: y.colorMapping[secondIri],
[secondIri]: y.colorMapping[firstIri],
};
},
},
Expand Down Expand Up @@ -992,7 +1083,17 @@ export const getChartFieldOptionChangeSideEffect = (
case "areaLayer.color.scaleType":
case "symbolLayer.color.scaleType":
return get(encoding, "options.colorComponent.onScaleTypeChange");
case "y.componentIris":
return get(encoding, "options.componentIris.onChange");
case "y.lineAxisOrientation":
return get(encoding, "options.lineAxisOrientation.onChange");
case "y.leftAxisComponentIri":
return get(encoding, "options.leftAxisComponentIri.onChange");
case "y.rightAxisComponentIri":
return get(encoding, "options.rightAxisComponentIri.onChange");
case "y.lineComponentIri":
return get(encoding, "options.lineComponentIri.onChange");
case "y.columnComponentIri":
return get(encoding, "options.columnComponentIri.onChange");
}
};
11 changes: 10 additions & 1 deletion app/components/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ButtonBase,
FormControlLabel,
FormControlLabelProps,
InputLabel,
InputProps,
ListSubheader,
Checkbox as MUICheckbox,
Expand Down Expand Up @@ -391,7 +392,15 @@ export const Select = ({
width: "100%",
}}
>
<span>{selectedOption.label}</span>
<InputLabel
sx={{
typography: "body2",
color: "secondary.active",
pointerEvents: "none",
}}
>
{selectedOption.label}
</InputLabel>
{hint && <DisabledMessageIcon message={hint} />}
</Box>
);
Expand Down
4 changes: 3 additions & 1 deletion app/themes/federal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,11 @@ theme.components = {
MuiSelect: {
styleOverrides: {
select: {
display: "flex",
alignItems: "center",
boxSizing: "border-box",
height: "40px",
padding: "8px 14px",
padding: "8px 12px",
color: theme.palette.grey[700],
textOverflow: "ellipsis",
fontSize: theme.typography.body2.fontSize,
Expand Down
Loading