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

feat: Dashboards improvements #1324

Merged
merged 27 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9d1784e
feat: Make Tall layout responsive
bprusinowski Jan 31, 2024
a016b76
style: Improve width of published view
bprusinowski Jan 31, 2024
bf96c96
fix: Table preview in dashboard layout
bprusinowski Jan 31, 2024
f5fed56
style: Update max width for published charts
bprusinowski Jan 31, 2024
6f82d08
feat: Move filters below the chart
bprusinowski Jan 31, 2024
26ce2cb
fix: Interactive filters in preview mode
bprusinowski Jan 31, 2024
e06a49e
feat: Keep chart filters in footnotes
bprusinowski Jan 31, 2024
4b53255
chore: Remove unused
bprusinowski Jan 31, 2024
c0a04f4
Merge branch 'main' of github.com:visualize-admin/visualization-tool …
bprusinowski Feb 1, 2024
5428e53
fix: Bring Description back
bprusinowski Feb 1, 2024
111b45e
style: Make drag overlay more similar to actual chart preview
bprusinowski Feb 1, 2024
5c2615e
refactor: Rename + update styles
bprusinowski Feb 1, 2024
5564484
refactor: Clean up
bprusinowski Feb 1, 2024
6ee96b8
refactor: Use React components instead of CSS to render Tall layout
bprusinowski Feb 1, 2024
01069c4
feat: Add logic to align chart elements
bprusinowski Feb 1, 2024
f0ae6ae
feat: Move interactive filters up, so they are taken into account whe…
bprusinowski Feb 1, 2024
3e5c14d
feat: Align chart SVGs
bprusinowski Feb 1, 2024
79ee22a
feat: Align chart footnotes to the bottom
bprusinowski Feb 1, 2024
1b32081
style: Break words in chart header
bprusinowski Feb 1, 2024
2057cb6
fix: Sizing issues
bprusinowski Feb 1, 2024
3284ff8
refactor: Move function to utils
bprusinowski Feb 1, 2024
0083c8c
refactor: Extract TallLayoutRows
bprusinowski Feb 1, 2024
ad74a74
fix: Loading state in published charts
bprusinowski Feb 1, 2024
75b76f9
feat: Use new layouts in published charts
bprusinowski Feb 1, 2024
bf76983
refactor: Extract chart alignment helpers to another file
bprusinowski Feb 1, 2024
58b390e
feat: Update chart elements alignment on window resize
bprusinowski Feb 1, 2024
170989b
fix: Prevent charts from jumping when updating alignment during windo…
bprusinowski Feb 1, 2024
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
74 changes: 36 additions & 38 deletions app/charts/pie/chart-pie.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,44 +75,42 @@ export const ChartPieVisualization = ({
);
};

export const ChartPie = memo(
(props: ChartProps<PieConfig> & { published: boolean }) => {
const { chartConfig, observations, dimensions, published } = props;
const { fields, interactiveFiltersConfig } = chartConfig;
const somePositive = observations.some(
(d) => (d[fields?.y?.componentIri] as number) > 0
);
const filters = useChartConfigFilters(chartConfig);
export const ChartPie = memo((props: ChartProps<PieConfig>) => {
const { chartConfig, observations, dimensions } = props;
const { fields, interactiveFiltersConfig } = chartConfig;
const somePositive = observations.some(
(d) => (d[fields?.y?.componentIri] as number) > 0
);
const filters = useChartConfigFilters(chartConfig);

if (!somePositive) {
return <OnlyNegativeDataHint />;
}
if (!somePositive) {
return <OnlyNegativeDataHint />;
}

return (
<PieChart aspectRatio={published ? 1 : 0.4} {...props}>
<ChartContainer>
<ChartSvg>
<Pie />
</ChartSvg>
<Tooltip type="single" />
</ChartContainer>
<ChartControlsContainer>
{fields.animation && (
<TimeSlider
filters={filters}
dimensions={dimensions}
{...fields.animation}
/>
)}
<LegendColor
chartConfig={chartConfig}
symbol="square"
interactive={
fields.segment && interactiveFiltersConfig?.legend.active
}
return (
<PieChart aspectRatio={0.4} {...props}>
<ChartContainer>
<ChartSvg>
<Pie />
</ChartSvg>
<Tooltip type="single" />
</ChartContainer>
<ChartControlsContainer>
{fields.animation && (
<TimeSlider
filters={filters}
dimensions={dimensions}
{...fields.animation}
/>
</ChartControlsContainer>
</PieChart>
);
}
);
)}
<LegendColor
chartConfig={chartConfig}
symbol="square"
interactive={
fields.segment && interactiveFiltersConfig?.legend.active
}
/>
</ChartControlsContainer>
</PieChart>
);
});
78 changes: 38 additions & 40 deletions app/charts/scatterplot/chart-scatterplot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,44 +87,42 @@ export const ChartScatterplotVisualization = ({
);
};

export const ChartScatterplot = memo(
(props: ChartProps<ScatterPlotConfig> & { published: boolean }) => {
const { chartConfig, dimensions, published } = props;
const { fields, interactiveFiltersConfig } = chartConfig;
const filters = useChartConfigFilters(chartConfig);
export const ChartScatterplot = memo((props: ChartProps<ScatterPlotConfig>) => {
const { chartConfig, dimensions } = props;
const { fields, interactiveFiltersConfig } = chartConfig;
const filters = useChartConfigFilters(chartConfig);

return (
<ScatterplotChart aspectRatio={published ? 1 : 0.4} {...props}>
<ChartContainer>
<ChartSvg>
<AxisWidthLinear />
<AxisHeightLinear />
<AxisWidthLinearDomain />
<AxisHeightLinearDomain />
<Scatterplot />
<InteractionVoronoi />
</ChartSvg>
<Tooltip type="single" />
</ChartContainer>
{(fields.animation || fields.segment) && (
<ChartControlsContainer>
{fields.animation && (
<TimeSlider
filters={filters}
dimensions={dimensions}
{...fields.animation}
/>
)}
{fields.segment && (
<LegendColor
chartConfig={chartConfig}
symbol="circle"
interactive={interactiveFiltersConfig?.legend.active}
/>
)}
</ChartControlsContainer>
)}
</ScatterplotChart>
);
}
);
return (
<ScatterplotChart aspectRatio={0.4} {...props}>
<ChartContainer>
<ChartSvg>
<AxisWidthLinear />
<AxisHeightLinear />
<AxisWidthLinearDomain />
<AxisHeightLinearDomain />
<Scatterplot />
<InteractionVoronoi />
</ChartSvg>
<Tooltip type="single" />
</ChartContainer>
{(fields.animation || fields.segment) && (
<ChartControlsContainer>
{fields.animation && (
<TimeSlider
filters={filters}
dimensions={dimensions}
{...fields.animation}
/>
)}
{fields.segment && (
<LegendColor
chartConfig={chartConfig}
symbol="circle"
interactive={interactiveFiltersConfig?.legend.active}
/>
)}
</ChartControlsContainer>
)}
</ScatterplotChart>
);
});
31 changes: 16 additions & 15 deletions app/charts/shared/chart-data-filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { useClient } from "urql";

import { useQueryFilters } from "@/charts/shared/chart-helpers";
import { useLoadingState } from "@/charts/shared/chart-loading-state";
import { ChartFiltersList } from "@/components/chart-filters-list";
import Flex from "@/components/flex";
import { Select } from "@/components/form";
import { Loading } from "@/components/hint";
Expand Down Expand Up @@ -132,39 +131,41 @@ export const ChartDataFilters = (props: ChartDataFiltersProps) => {
</Trans>
</Typography>
) : (
<Flex sx={{ flexDirection: "column", my: 4 }}>
<Flex sx={{ flexDirection: "column", mt: 4 }}>
<Flex
sx={{
justifyContent: "space-between",
justifyContent: "flex-end",
alignItems: "flex-start",
gap: 3,
minHeight: 20,
}}
>
<ChartFiltersList
dataSource={dataSource}
chartConfig={chartConfig}
dimensions={dimensions}
measures={measures}
/>

{componentIris.length > 0 && (
<Button
variant="text"
endIcon={<Icon name={filtersVisible ? "close" : "add"} size={15} />}
endIcon={
<Icon
name="add"
size={16}
style={{
transform: filtersVisible ? "rotate(45deg)" : "rotate(0deg)",
transition: "transform 0.2s ease-in-out",
}}
/>
}
sx={{
display: "flex",
fontSize: ["0.75rem", "0.75rem", "0.75rem"],
alignItems: "center",
gap: 2,
minWidth: "fit-content",
minHeight: 36,
px: 3,
minHeight: 0,
px: 2,
py: 1,
}}
onClick={() => setFiltersVisible(!filtersVisible)}
>
{loading && (
<span style={{ marginTop: "0.1rem" }}>
<span style={{ marginTop: "0.1rem", marginRight: "0.5rem" }}>
<LoadingIndicator />
</span>
)}
Expand Down
21 changes: 20 additions & 1 deletion app/charts/shared/containers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, { ReactNode } from "react";

import { useChartState } from "@/charts/shared/chart-state";
import { CalculationToggle } from "@/charts/shared/interactive-filter-calculation-toggle";
import { useAlignChartElements } from "@/components/chart-helpers";
import { useTransitionStore } from "@/stores/transition";

export const ChartContainer = ({ children }: { children: ReactNode }) => {
Expand All @@ -12,6 +13,7 @@ export const ChartContainer = ({ children }: { children: ReactNode }) => {
const transitionDuration = useTransitionStore((state) => state.duration);
const { bounds } = useChartState();
const { width, height } = bounds;
const alignChartElements = useAlignChartElements();

React.useEffect(() => {
if (ref.current) {
Expand All @@ -27,8 +29,25 @@ export const ChartContainer = ({ children }: { children: ReactNode }) => {
}
}, [height, enableTransition, transitionDuration]);

React.useEffect(() => {
if (height > alignChartElements.maxChartHeight) {
alignChartElements.setMaxChartHeight(height);
}
}, [height, alignChartElements]);

return (
<div ref={ref} aria-hidden="true" style={{ position: "relative", width }}>
<div
ref={ref}
aria-hidden="true"
style={{
position: "relative",
width,
marginBottom: `${Math.max(
alignChartElements.maxChartHeight - height,
0
)}px`,
}}
>
{children}
</div>
);
Expand Down
14 changes: 12 additions & 2 deletions app/components/chart-filters-list.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Trans } from "@lingui/macro";
import { Box, Typography } from "@mui/material";
import React, { Fragment } from "react";

Expand Down Expand Up @@ -144,10 +145,19 @@ export const ChartFiltersList = (props: ChartFiltersListProps) => {
return allFilters.length ? (
<Typography
component="div"
variant="body2"
sx={{ mb: 4, color: "grey.800" }}
variant="caption"
color="grey.600"
data-testid="chart-filters-list"
>
<Typography
component="span"
variant="inherit"
fontWeight="bold"
color="grey.600"
sx={{ mr: 2 }}
>
<Trans id="controls.section.data.filters">Filters</Trans>:
</Typography>
{allFilters.map(({ dimension, value }, i) => (
<Fragment key={dimension.iri}>
<Box component="span" fontWeight="bold">
Expand Down
11 changes: 9 additions & 2 deletions app/components/chart-footnotes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
extractChartConfigComponentIris,
useQueryFilters,
} from "@/charts/shared/chart-helpers";
import { ChartFiltersList } from "@/components/chart-filters-list";
import { useChartTablePreview } from "@/components/chart-table-preview";
import { DataDownloadMenu, RunSparqlQuery } from "@/components/data-download";
import { ChartConfig, DataSource } from "@/configurator";
Expand Down Expand Up @@ -112,7 +113,13 @@ export const ChartFootnotes = ({
] = useEmbedOptions();

return (
<>
<div>
<ChartFiltersList
dataSource={dataSource}
chartConfig={chartConfig}
dimensions={dimensions}
measures={measures}
/>
{data?.dataCubesMetadata
? data.dataCubesMetadata.map((dataCubeMetadata) => {
const cubeLink = makeOpenDataLink(locale, dataCubeMetadata);
Expand Down Expand Up @@ -274,7 +281,7 @@ export const ChartFootnotes = ({
);
})
: null}
</>
</div>
);
};

Expand Down
Loading
Loading