Skip to content

Commit

Permalink
Merge branch 'main' of github.com:visualize-admin/visualization-tool …
Browse files Browse the repository at this point in the history
…into feat/dashboards-1
  • Loading branch information
bprusinowski committed Sep 27, 2023
2 parents f747245 + e67e7fb commit 1b99589
Show file tree
Hide file tree
Showing 26 changed files with 245 additions and 140 deletions.
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,26 @@ You can also check the [release page](https://github.com/visualize-admin/visuali

## Unreleased

Nothing yet.
- Fixes
- Cube checker now correctly checks if dimensions are present
- It's now possible to change the chart type for copied, non-hierarchical charts without having to open an options panel first
- Interactive filters are now aligned correctly (y axis)

# [3.22.6] - 2023-09-19

- Features
- Animated charts now show latest data as default
- Fixes
- Table docs now work correctly again
- Cascading mode now works correctly for hierarchical dimensions used as interactive filters
- Changing the locale when previewing a larger cube no longer triggers multiple locale switches

# [3.22.5] - 2023-09-12

- Fixes
- It's now again possible to map all colors for hierarchical dimensions used as segmentation
- Misc
- Improved `langString` error message

# [3.22.4] - 2023-09-06

Expand Down
2 changes: 1 addition & 1 deletion app/browse/datatable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export const DataSetPreviewTable = ({
title: string;
dimensions: DimensionMetadataFragment[];
measures: DimensionMetadataFragment[];
observations: Observation[];
observations: Observation[] | undefined;
}) => {
const headers = useMemo(() => {
return getSortedColumns([...dimensions, ...measures]);
Expand Down
14 changes: 7 additions & 7 deletions app/browser/dataset-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ export const DataSetPreview = ({
window.scrollTo({ top: 0 });
}, []);

if (metadata?.dataCubeByIri) {
if (fetching) {
return (
<Flex className={classes.loadingWrapper}>
<Loading />
</Flex>
);
} else if (metadata?.dataCubeByIri) {
const { dataCubeByIri } = metadata;

return (
Expand Down Expand Up @@ -188,12 +194,6 @@ export const DataSetPreview = ({
</Paper>
</Flex>
);
} else if (fetching) {
return (
<Flex className={classes.loadingWrapper}>
<Loading />
</Flex>
);
} else {
return (
<Flex className={classes.loadingWrapper}>
Expand Down
23 changes: 17 additions & 6 deletions app/charts/area/areas-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,14 @@ const useAreasState = (
getSegmentAbbreviationOrLabel,
} = variables;
const getIdentityY = useGetIdentityY(yMeasure.iri);
const { chartData, scalesData, segmentData, timeRangeData, allData } = data;
const {
chartData,
scalesData,
segmentData,
timeRangeData,
paddingData,
allData,
} = data;
const { fields, interactiveFiltersConfig } = chartConfig;

const width = useWidth();
Expand Down Expand Up @@ -281,12 +288,12 @@ const useAreasState = (
});
}, [scalesData, normalize, getXAsString, getY]);

const allYScale = useMemo(() => {
const paddingYScale = useMemo(() => {
// When the user can toggle between absolute and relative values, we use the
// absolute values to calculate the yScale domain, so that the yScale doesn't
// change when the user toggles between absolute and relative values.
if (interactiveFiltersConfig?.calculation.active) {
const scale = getStackedYScale(allData, {
const scale = getStackedYScale(paddingData, {
normalize: false,
getX: getXAsString,
getY,
Expand All @@ -299,9 +306,13 @@ const useAreasState = (
return scale;
}

return getStackedYScale(allData, { normalize, getX: getXAsString, getY });
return getStackedYScale(paddingData, {
normalize,
getX: getXAsString,
getY,
});
}, [
allData,
paddingData,
getXAsString,
getY,
interactiveFiltersConfig?.calculation.active,
Expand All @@ -310,7 +321,7 @@ const useAreasState = (

/** Dimensions */
const { left, bottom } = useChartPadding({
allYScale,
yScale: paddingYScale,
width,
aspectRatio,
interactiveFiltersConfig,
Expand Down
2 changes: 1 addition & 1 deletion app/charts/chart-config-ui-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ const defaultSegmentOnChange: OnEncodingChange<
);
const colorMapping = mapValueIrisToColor({
palette,
dimensionValues: selectedValues,
dimensionValues: component ? component.values : selectedValues,
});
const multiFilter = makeMultiFilter(selectedValues.map((d) => d.value));

Expand Down
35 changes: 23 additions & 12 deletions app/charts/column/columns-grouped-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,14 @@ const useColumnsGroupedState = (
getSegment,
getSegmentAbbreviationOrLabel,
} = variables;
const { chartData, scalesData, segmentData, timeRangeData, allData } = data;
const {
chartData,
scalesData,
segmentData,
timeRangeData,
paddingData,
allData,
} = data;
const { fields, interactiveFiltersConfig } = chartConfig;

const width = useWidth();
Expand Down Expand Up @@ -170,7 +177,7 @@ const useColumnsGroupedState = (
xTimeRangeDomainLabels,
colors,
yScale,
allYScale,
paddingYScale,
interactiveXTimeRangeScale,
xScale,
xScaleIn,
Expand Down Expand Up @@ -247,22 +254,26 @@ const useColumnsGroupedState = (
);
const yScale = scaleLinear().domain([minValue, maxValue]).nice();

const allMinValue = Math.min(
min(allData, (d) => (getYErrorRange ? getYErrorRange(d)[0] : getY(d))) ??
0,
const minPaddingValue = Math.min(
min(paddingData, (d) =>
getYErrorRange ? getYErrorRange(d)[0] : getY(d)
) ?? 0,
0
);
const allMaxValue = Math.max(
max(allData, (d) => (getYErrorRange ? getYErrorRange(d)[1] : getY(d))) ??
0,
const maxPaddingValue = Math.max(
max(paddingData, (d) =>
getYErrorRange ? getYErrorRange(d)[1] : getY(d)
) ?? 0,
0
);
const allYScale = scaleLinear().domain([allMinValue, allMaxValue]).nice();
const paddingYScale = scaleLinear()
.domain([minPaddingValue, maxPaddingValue])
.nice();

return {
colors,
yScale,
allYScale,
paddingYScale,
interactiveXTimeRangeScale,
xScale,
xScaleIn,
Expand All @@ -282,7 +293,7 @@ const useColumnsGroupedState = (
getXLabel,
segments,
timeRangeData,
allData,
paddingData,
allSegments,
segmentsByAbbreviationOrLabel,
segmentsByValue,
Expand Down Expand Up @@ -320,7 +331,7 @@ const useColumnsGroupedState = (
}, [getSegment, getX, chartData, segmentSortingOrder, segments, xScale]);

const { left, bottom } = useChartPadding({
allYScale,
yScale: paddingYScale,
width,
aspectRatio,
interactiveFiltersConfig,
Expand Down
19 changes: 13 additions & 6 deletions app/charts/column/columns-stacked-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,14 @@ const useColumnsStackedState = (
getSegmentAbbreviationOrLabel,
} = variables;
const getIdentityY = useGetIdentityY(yMeasure.iri);
const { chartData, scalesData, segmentData, timeRangeData, allData } = data;
const {
chartData,
scalesData,
segmentData,
timeRangeData,
paddingData,
allData,
} = data;
const { fields, interactiveFiltersConfig } = chartConfig;

const width = useWidth();
Expand Down Expand Up @@ -312,12 +319,12 @@ const useColumnsStackedState = (
});
}, [scalesData, normalize, getX, getY, getAnimation]);

const allYScale = useMemo(() => {
const paddingYScale = useMemo(() => {
// When the user can toggle between absolute and relative values, we use the
// absolute values to calculate the yScale domain, so that the yScale doesn't
// change when the user toggles between absolute and relative values.
if (interactiveFiltersConfig?.calculation.active) {
const scale = getStackedYScale(allData, {
const scale = getStackedYScale(paddingData, {
normalize: false,
getX,
getY,
Expand All @@ -331,15 +338,15 @@ const useColumnsStackedState = (
return scale;
}

return getStackedYScale(allData, {
return getStackedYScale(paddingData, {
normalize,
getX,
getY,
getTime: getAnimation,
});
}, [
interactiveFiltersConfig?.calculation.active,
allData,
paddingData,
normalize,
getX,
getY,
Expand Down Expand Up @@ -373,7 +380,7 @@ const useColumnsStackedState = (

/** Chart dimensions */
const { left, bottom } = useChartPadding({
allYScale,
yScale: paddingYScale,
width,
aspectRatio,
interactiveFiltersConfig,
Expand Down
28 changes: 16 additions & 12 deletions app/charts/column/columns-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const useColumnsState = (
getYError,
getYErrorRange,
} = variables;
const { chartData, scalesData, timeRangeData, allData } = data;
const { chartData, scalesData, timeRangeData, paddingData, allData } = data;
const { fields, interactiveFiltersConfig } = chartConfig;

const width = useWidth();
Expand All @@ -99,7 +99,7 @@ const useColumnsState = (
const {
xScale,
yScale,
allYScale,
paddingYScale,
interactiveXTimeRangeScale,
xScaleInteraction,
xTimeRangeDomainLabels,
Expand Down Expand Up @@ -151,22 +151,26 @@ const useColumnsState = (
);
const yScale = scaleLinear().domain([minValue, maxValue]).nice();

const allMinValue = Math.min(
min(allData, (d) => (getYErrorRange ? getYErrorRange(d)[0] : getY(d))) ??
0,
const paddingMinValue = Math.min(
min(paddingData, (d) =>
getYErrorRange ? getYErrorRange(d)[0] : getY(d)
) ?? 0,
0
);
const allMaxValue = Math.max(
max(allData, (d) => (getYErrorRange ? getYErrorRange(d)[1] : getY(d))) ??
0,
const paddingMaxValue = Math.max(
max(paddingData, (d) =>
getYErrorRange ? getYErrorRange(d)[1] : getY(d)
) ?? 0,
0
);
const allYScale = scaleLinear().domain([allMinValue, allMaxValue]).nice();
const paddingYScale = scaleLinear()
.domain([paddingMinValue, paddingMaxValue])
.nice();

return {
xScale,
yScale,
allYScale,
paddingYScale,
interactiveXTimeRangeScale,
xScaleInteraction,
xTimeRangeDomainLabels,
Expand All @@ -178,7 +182,7 @@ const useColumnsState = (
getY,
getYErrorRange,
scalesData,
allData,
paddingData,
timeRangeData,
fields.x.sorting,
fields.x.useAbbreviations,
Expand All @@ -188,7 +192,7 @@ const useColumnsState = (
]);

const { left, bottom } = useChartPadding({
allYScale,
yScale: paddingYScale,
width,
aspectRatio,
interactiveFiltersConfig,
Expand Down
20 changes: 14 additions & 6 deletions app/charts/line/lines-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,14 @@ const useLinesState = (
getSegment,
getSegmentAbbreviationOrLabel,
} = variables;
const { chartData, scalesData, segmentData, timeRangeData, allData } = data;
const {
chartData,
scalesData,
segmentData,
timeRangeData,
paddingData,
allData,
} = data;
const { fields, interactiveFiltersConfig } = chartConfig;

const width = useWidth();
Expand Down Expand Up @@ -132,10 +139,11 @@ const useLinesState = (
const yDomain = [minValue, maxValue];
const yScale = scaleLinear().domain(yDomain).nice();

const allMinValue = Math.min(min(allData, getY) ?? 0, 0);
const allMaxValue = max(allData, getY) ?? 0;
const allYDomain = [allMinValue, allMaxValue];
const allYScale = scaleLinear().domain(allYDomain).nice();
const paddingMinValue = Math.min(min(paddingData, getY) ?? 0, 0);
const paddingMaxValue = max(paddingData, getY) ?? 0;
const paddingYScale = scaleLinear()
.domain([paddingMinValue, paddingMaxValue])
.nice();

// segments
const segmentFilter = segmentDimension?.iri
Expand Down Expand Up @@ -195,7 +203,7 @@ const useLinesState = (

// Dimensions
const { left, bottom } = useChartPadding({
allYScale,
yScale: paddingYScale,
width,
aspectRatio,
interactiveFiltersConfig,
Expand Down
Loading

0 comments on commit 1b99589

Please sign in to comment.