Skip to content

Commit

Permalink
Merge branch 'main' into fix/zero-for-undefined-values
Browse files Browse the repository at this point in the history
  • Loading branch information
noahonyejese authored Nov 25, 2024
2 parents c304641 + f119df0 commit 2370553
Show file tree
Hide file tree
Showing 32 changed files with 584 additions and 314 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ You can also check the

# Unreleased

Nothing yet.

# [5.0.0] - 2024-11-25

Bumped to a new major version to celebrate all the improvements and new features
introduced since v4.0.0 🎉

- Features
- Allowed previewing of charts in states different than CONFIGURING_CHART
(iframe `/preview` page)
Expand All @@ -22,6 +29,7 @@ You can also check the
application will try to use dual-line chart with measures from different
cubes)
- Added tooltip that explains why a given chart type can't be selected
- Added support for confidence intervals
- Fixes
- Introduced a `componentId` concept which makes the dimensions and measures
unique by adding an unversioned cube iri to the unversioned component iri on
Expand All @@ -30,6 +38,7 @@ You can also check the
- Map legend is now correctly updated (in some cases it was rendered
incorrectly on the initial render)
- Vertical Axis measure names are now correctly displayed in the left panel
- Uncertainties are now correctly displayed in map symbol layer tooltip
- Performance
- We no longer load non-key dimensions when initializing a chart
- Maintenance
Expand Down
5 changes: 5 additions & 0 deletions app/charts/chart-config-ui-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ type EncodingOption<T extends ChartConfig = ChartConfig> =
| {
field: "showStandardError";
}
| {
field: "showConfidenceInterval";
}
| {
field: "sorting";
}
Expand Down Expand Up @@ -643,6 +646,7 @@ const chartConfigOptionsUISpec: ChartSpecs = {
},
options: {
showStandardError: {},
showConfidenceInterval: {},
},
},
{
Expand Down Expand Up @@ -776,6 +780,7 @@ const chartConfigOptionsUISpec: ChartSpecs = {
filters: false,
options: {
showStandardError: {},
showConfidenceInterval: {},
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion app/charts/column/columns-grouped-state-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const useColumnsGroupedStateVariables = (
measuresById,
});
const numericalYErrorVariables = useNumericalYErrorVariables(y, {
numericalYVariables,
getValue: numericalYVariables.getY,
dimensions,
measures,
});
Expand Down
16 changes: 3 additions & 13 deletions app/charts/column/columns-grouped-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,8 @@ const useColumnsGroupedState = (
yMeasure,
getY,
getMinY,
showYStandardError,
yErrorMeasure,
getYError,
getYErrorRange,
getFormattedYUncertainty,
segmentDimension,
segmentsByAbbreviationOrLabel,
getSegment,
Expand Down Expand Up @@ -398,14 +396,6 @@ const useColumnsGroupedState = (
topAnchor: !fields.segment,
});

const getError = (d: Observation) => {
if (!showYStandardError || !getYError || getYError(d) == null) {
return;
}

return `${getYError(d)}${yErrorMeasure?.unit ?? ""}`;
};

return {
xAnchor: xAnchorRaw + (placement.x === "right" ? 0.5 : -0.5) * bw,
yAnchor,
Expand All @@ -414,15 +404,15 @@ const useColumnsGroupedState = (
datum: {
label: fields.segment && getSegmentAbbreviationOrLabel(datum),
value: yValueFormatter(getY(datum)),
error: getError(datum),
error: getFormattedYUncertainty(datum),
color: colors(getSegment(datum)) as string,
},
values: sortedTooltipValues.map((td) => ({
label: getSegmentAbbreviationOrLabel(td),
value: yMeasure.unit
? `${formatNumber(getY(td))}${yMeasure.unit}`
: formatNumber(getY(td)),
error: getError(td),
error: getFormattedYUncertainty(td),
color: colors(getSegment(td)) as string,
})),
};
Expand Down
13 changes: 6 additions & 7 deletions app/charts/column/columns-grouped.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
import { useChartState } from "@/charts/shared/chart-state";
import {
RenderWhiskerDatum,
filterWithoutErrors,
renderContainer,
renderWhiskers,
} from "@/charts/shared/rendering-utils";
Expand All @@ -20,24 +19,24 @@ export const ErrorWhiskers = () => {
xScale,
xScaleIn,
getYErrorRange,
getYError,
getYErrorPresent,
yScale,
getSegment,
grouped,
showYStandardError,
showYUncertainty,
} = useChartState() as GroupedColumnsState;
const { margins, width, height } = bounds;
const ref = useRef<SVGGElement>(null);
const enableTransition = useTransitionStore((state) => state.enable);
const transitionDuration = useTransitionStore((state) => state.duration);
const renderData: RenderWhiskerDatum[] = useMemo(() => {
if (!getYErrorRange || !showYStandardError) {
if (!getYErrorRange || !showYUncertainty) {
return [];
}

const bandwidth = xScaleIn.bandwidth();
return grouped
.filter((d) => d[1].some(filterWithoutErrors(getYError)))
.filter((d) => d[1].some(getYErrorPresent))
.flatMap(([segment, observations]) =>
observations.map((d) => {
const x0 = xScaleIn(getSegment(d)) as number;
Expand All @@ -56,9 +55,9 @@ export const ErrorWhiskers = () => {
}, [
getSegment,
getYErrorRange,
getYError,
getYErrorPresent,
grouped,
showYStandardError,
showYUncertainty,
xScale,
xScaleIn,
yScale,
Expand Down
2 changes: 1 addition & 1 deletion app/charts/column/columns-state-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const useColumnsStateVariables = (
measuresById,
});
const numericalYErrorVariables = useNumericalYErrorVariables(y, {
numericalYVariables,
getValue: numericalYVariables.getY,
dimensions,
measures,
});
Expand Down
15 changes: 2 additions & 13 deletions app/charts/column/columns-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,8 @@ const useColumnsState = (
yMeasure,
getY,
getMinY,
showYStandardError,
yErrorMeasure,
getYError,
getYErrorRange,
getFormattedYUncertainty,
} = variables;
const { chartData, scalesData, timeRangeData, paddingData, allData } = data;
const { fields, interactiveFiltersConfig } = chartConfig;
Expand Down Expand Up @@ -245,15 +243,6 @@ const useColumnsState = (
formatters[yMeasure.id] ?? formatNumber,
yMeasure.unit
);

const getError = (d: Observation) => {
if (!showYStandardError || !getYError || getYError(d) === null) {
return;
}

return `${getYError(d)}${yErrorMeasure?.unit ?? ""}`;
};

const y = getY(d);

return {
Expand All @@ -264,7 +253,7 @@ const useColumnsState = (
datum: {
label: undefined,
value: y !== null && isNaN(y) ? "-" : `${yValueFormatter(getY(d))}`,
error: getError(d),
error: getFormattedYUncertainty(d),
color: "",
},
values: undefined,
Expand Down
13 changes: 6 additions & 7 deletions app/charts/column/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
import { useChartState } from "@/charts/shared/chart-state";
import {
RenderWhiskerDatum,
filterWithoutErrors,
renderContainer,
renderWhiskers,
} from "@/charts/shared/rendering-utils";
Expand All @@ -19,25 +18,25 @@ import { useTheme } from "@/themes";
export const ErrorWhiskers = () => {
const {
getX,
getYError,
getYErrorPresent,
getYErrorRange,
chartData,
yScale,
xScale,
showYStandardError,
showYUncertainty,
bounds,
} = useChartState() as ColumnsState;
const { margins, width, height } = bounds;
const ref = useRef<SVGGElement>(null);
const enableTransition = useTransitionStore((state) => state.enable);
const transitionDuration = useTransitionStore((state) => state.duration);
const renderData: RenderWhiskerDatum[] = useMemo(() => {
if (!getYErrorRange || !showYStandardError) {
if (!getYErrorRange || !showYUncertainty) {
return [];
}

const bandwidth = xScale.bandwidth();
return chartData.filter(filterWithoutErrors(getYError)).map((d, i) => {
return chartData.filter(getYErrorPresent).map((d, i) => {
const x0 = xScale(getX(d)) as number;
const barWidth = Math.min(bandwidth, 15);
const [y1, y2] = getYErrorRange(d);
Expand All @@ -53,9 +52,9 @@ export const ErrorWhiskers = () => {
}, [
chartData,
getX,
getYError,
getYErrorPresent,
getYErrorRange,
showYStandardError,
showYUncertainty,
xScale,
yScale,
width,
Expand Down
2 changes: 1 addition & 1 deletion app/charts/line/lines-state-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const useLinesStateVariables = (
measuresById,
});
const numericalYErrorVariables = useNumericalYErrorVariables(y, {
numericalYVariables,
getValue: numericalYVariables.getY,
dimensions,
measures,
});
Expand Down
14 changes: 2 additions & 12 deletions app/charts/line/lines-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,8 @@ const useLinesState = (
getXAsString,
yMeasure,
getY,
showYStandardError,
getYError,
getYErrorRange,
yErrorMeasure,
getFormattedYUncertainty,
getMinY,
segmentDimension,
segmentsByAbbreviationOrLabel,
Expand Down Expand Up @@ -279,14 +277,6 @@ const useLinesState = (
yMeasure.unit
);

const getError = (d: Observation) => {
if (!showYStandardError || !getYError || getYError(d) === null) {
return;
}

return `${getYError(d)}${yErrorMeasure?.unit ?? ""}`;
};

return {
xAnchor,
yAnchor,
Expand All @@ -295,7 +285,7 @@ const useLinesState = (
datum: {
label: fields.segment && getSegmentAbbreviationOrLabel(datum),
value: yValueFormatter(getY(datum)),
error: getError(datum),
error: getFormattedYUncertainty(datum),
color: colors(getSegment(datum)) as string,
},
values: sortedTooltipValues.map((td) => ({
Expand Down
17 changes: 10 additions & 7 deletions app/charts/line/lines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { LinesState } from "@/charts/line/lines-state";
import { useChartState } from "@/charts/shared/chart-state";
import {
RenderWhiskerDatum,
filterWithoutErrors,
renderContainer,
renderWhiskers,
} from "@/charts/shared/rendering-utils";
Expand All @@ -15,12 +14,13 @@ import { useTransitionStore } from "@/stores/transition";
export const ErrorWhiskers = () => {
const {
getX,
getYError,
getY,
getYErrorPresent,
getYErrorRange,
chartData,
yScale,
xScale,
showYStandardError,
showYUncertainty,
colors,
getSegment,
bounds,
Expand All @@ -30,18 +30,20 @@ export const ErrorWhiskers = () => {
const enableTransition = useTransitionStore((state) => state.enable);
const transitionDuration = useTransitionStore((state) => state.duration);
const renderData: RenderWhiskerDatum[] = useMemo(() => {
if (!getYErrorRange || !showYStandardError) {
if (!getYErrorRange || !showYUncertainty) {
return [];
}

return chartData.filter(filterWithoutErrors(getYError)).map((d, i) => {
return chartData.filter(getYErrorPresent).map((d, i) => {
const x0 = xScale(getX(d)) as number;
const segment = getSegment(d);
const barWidth = 15;
const y = getY(d) as number;
const [y1, y2] = getYErrorRange(d);
return {
key: `${i}`,
x: x0 - barWidth / 2,
y: yScale(y),
y1: yScale(y1),
y2: yScale(y2),
width: barWidth,
Expand All @@ -54,9 +56,10 @@ export const ErrorWhiskers = () => {
colors,
getSegment,
getX,
getYError,
getY,
getYErrorPresent,
getYErrorRange,
showYStandardError,
showYUncertainty,
xScale,
yScale,
]);
Expand Down
Loading

0 comments on commit 2370553

Please sign in to comment.