Skip to content

Commit

Permalink
feat: Disable no-unit measures in multi line combo charts
Browse files Browse the repository at this point in the history
  • Loading branch information
bprusinowski committed Oct 18, 2023
1 parent 61c0eb1 commit e4e00c0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
23 changes: 12 additions & 11 deletions app/charts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ export const getInitialConfig = (
case "comboLineSingle": {
// It's guaranteed by getPossibleChartTypes that there are at least two units.
const mostCommonUnit = rollups(
numericalMeasures,
numericalMeasures.filter((d) => d.unit),
(v) => v.length,
(d) => d.unit
).sort((a, b) => descending(a[1], b[1]))[0][0];
Expand All @@ -556,7 +556,7 @@ export const getInitialConfig = (
case "comboLineDual": {
// It's guaranteed by getPossibleChartTypes that there are at least two units.
const [firstUnit, secondUnit] = Array.from(
new Set(numericalMeasures.map((d) => d.unit))
new Set(numericalMeasures.filter((d) => d.unit).map((d) => d.unit))
);

return {
Expand All @@ -582,7 +582,7 @@ export const getInitialConfig = (
case "comboLineColumn": {
// It's guaranteed by getPossibleChartTypes that there are at least two units.
const [firstUnit, secondUnit] = Array.from(
new Set(numericalMeasures.map((d) => d.unit))
new Set(numericalMeasures.filter((d) => d.unit).map((d) => d.unit))
);

return {
Expand Down Expand Up @@ -1292,16 +1292,17 @@ const chartConfigsAdjusters: ChartConfigsAdjusters = {
},
y: {
componentIris: ({ oldValue, newChartConfig, measures }) => {
const numericalMeasures = measures.filter(isNumericalMeasure);
const availableMeasureIris = numericalMeasures.map((d) => d.iri);
const measure = numericalMeasures.find(
(d) => d.iri === (oldValue ?? availableMeasureIris[0])
) as NumericalMeasure;
const numericalMeasures = measures.filter(
(d) => isNumericalMeasure(d) && d.unit
);
const { unit } =
numericalMeasures.find((d) => d.iri === oldValue) ??
numericalMeasures[0];

return produce(newChartConfig, (draft) => {
draft.fields.y = {
componentIris: numericalMeasures
.filter((d) => d.unit === measure.unit)
.filter((d) => d.unit === unit)
.map((d) => d.iri),
};
});
Expand Down Expand Up @@ -1814,12 +1815,12 @@ export const getPossibleChartTypes = ({

if (temporalDimensions.length > 0) {
const uniqueUnits = Array.from(
new Set(numericalMeasures.map((d) => d.unit))
new Set(numericalMeasures.filter((d) => d.unit).map((d) => d.unit))
);

if (uniqueUnits.length > 1) {
possibles.push(...comboChartTypes);
} else {
} else if (uniqueUnits.length > 0) {
possibles.push("comboLineSingle");
}
}
Expand Down
6 changes: 4 additions & 2 deletions app/configurator/components/chart-options-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -616,10 +616,12 @@ const ChartComboLineSingleYField = (
} = {}
) => {
const options = getComboOptionGroups(numericalMeasures, (m) => {
return enableAll
return !m.unit
? true
: enableAll
? false
: m.unit !== unit ||
(y.componentIris.includes(m.iri) && m.iri !== iri);
(y.componentIris.includes(m.iri) && m.iri !== iri);
});

if (allowNone) {
Expand Down

0 comments on commit e4e00c0

Please sign in to comment.