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: Add Animation for Column, Pie and Scatter charts #940

Merged
merged 34 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6f713fc
refactor: Time slider -> Animation
bprusinowski Jan 19, 2023
18e7343
feat: Add Animation icon
bprusinowski Jan 19, 2023
cc40a66
feat: Use Animation icon for time slider
bprusinowski Jan 19, 2023
0f2b62b
refactor: Make label optional
bprusinowski Jan 20, 2023
9b5562d
feat: Add animation field to types and migrations
bprusinowski Jan 20, 2023
e7eb303
feat: Handle animation field changes
bprusinowski Jan 20, 2023
c63e799
chore: Remove TimeSlider UI elements
bprusinowski Jan 20, 2023
e6786ec
feat: Hide animation field behind a flag
bprusinowski Jan 20, 2023
4d2d62f
feat: Add label
bprusinowski Jan 20, 2023
2fb1ddb
feat: Consider animation time range filter
bprusinowski Jan 20, 2023
e90d7f3
refactor: Remove interactiveFiltersConfig.timeSlider in favor of Anim…
bprusinowski Jan 20, 2023
a4e56e3
chore: Merge main
bprusinowski Jan 20, 2023
02c7c6b
fix: Lint
bprusinowski Jan 20, 2023
55eee5c
fix: Only migrate timeSlider to charts that support it
bprusinowski Jan 20, 2023
1400d72
feat: Enable Animation field for Pie and Scatterplot
bprusinowski Jan 23, 2023
0b24e50
Merge branch 'main' of github.com:visualize-admin/visualization-tool …
bprusinowski May 8, 2023
76e54d5
fix: Imports
bprusinowski May 8, 2023
c04ceb6
fix: Align optional label with label (field)
bprusinowski May 8, 2023
9121a38
feat: Remove flag from Animation field
bprusinowski May 8, 2023
a753244
feat: Consolidate Add… translations
bprusinowski May 8, 2023
526120e
refactor: Move icons closer to the component that needs them
bprusinowski May 9, 2023
2910e83
refactor: Improve types
bprusinowski May 9, 2023
1f8d086
feat: Add an option to show / hide play button
bprusinowski May 9, 2023
774114b
chore: Remove unused translations
bprusinowski May 9, 2023
68fe8d9
feat: Add an option to control animation duration
bprusinowski May 9, 2023
beb6139
feat: Only show animation duration options when play button is shown
bprusinowski May 9, 2023
48cec8a
feat: Add animation types
bprusinowski May 9, 2023
73ae545
feat: Add animation to ChartConfigAdjusters
bprusinowski May 9, 2023
d0673ea
fix: Type
bprusinowski May 9, 2023
767bf9a
feat: Animate columns in column chart
bprusinowski May 9, 2023
f236df3
docs: Update CHANGELOG
bprusinowski May 9, 2023
6aac288
feat: Add a 10s option to Animation
bprusinowski May 15, 2023
8eb8833
Merge branch 'main' of github.com:visualize-admin/visualization-tool …
bprusinowski May 15, 2023
14df0b1
fix: Lint
bprusinowski May 15, 2023
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
3 changes: 3 additions & 0 deletions app/charts/column/chart-column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export const ChartColumns = memo(
dimensions={dimensions}
showPlayButton={fields.animation.showPlayButton}
animationDuration={fields.animation.duration}
animationType={fields.animation.type}
/>
)}
</StackedColumnsChart>
Expand Down Expand Up @@ -169,6 +170,7 @@ export const ChartColumns = memo(
dimensions={dimensions}
showPlayButton={fields.animation.showPlayButton}
animationDuration={fields.animation.duration}
animationType={fields.animation.type}
/>
)}
</GroupedColumnChart>
Expand Down Expand Up @@ -198,6 +200,7 @@ export const ChartColumns = memo(
dimensions={dimensions}
showPlayButton={fields.animation.showPlayButton}
animationDuration={fields.animation.duration}
animationType={fields.animation.type}
/>
)}
</ColumnChart>
Expand Down
1 change: 1 addition & 0 deletions app/charts/pie/chart-pie.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export const ChartPie = memo(
dimensions={dimensions}
showPlayButton={fields.animation.showPlayButton}
animationDuration={fields.animation.duration}
animationType={fields.animation.type}
/>
)}
</PieChart>
Expand Down
1 change: 1 addition & 0 deletions app/charts/scatterplot/chart-scatterplot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export const ChartScatterplot = memo(
dimensions={dimensions}
showPlayButton={fields.animation.showPlayButton}
animationDuration={fields.animation.duration}
animationType={fields.animation.type}
/>
)}
</ScatterplotChart>
Expand Down
73 changes: 52 additions & 21 deletions app/configurator/components/chart-options-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -475,29 +475,60 @@ const ChartFieldAnimation = ({ field }: { field: AnimationField }) => {
path="showPlayButton"
/>
{field.showPlayButton && (
<Box component="fieldset" mt={4}>
<FieldSetLegend
legendTitle={
<Trans id="controls.section.animation.duration">
Animation Duration
</Trans>
}
/>
<Flex sx={{ justifyContent: "flex-start" }}>
<ChartOptionRadioField
label="30s"
field="animation"
path="duration"
value={30}
<>
<Box component="fieldset" mt={4}>
<FieldSetLegend
legendTitle={
<Trans id="controls.section.animation.duration">
Animation Duration
</Trans>
}
/>
<ChartOptionRadioField
label="60s"
field="animation"
path="duration"
value={60}
<Flex sx={{ justifyContent: "flex-start" }}>
<ChartOptionRadioField
label="30s"
field="animation"
path="duration"
value={30}
/>
bprusinowski marked this conversation as resolved.
Show resolved Hide resolved
<ChartOptionRadioField
label="60s"
field="animation"
path="duration"
value={60}
/>
</Flex>
</Box>
<Box component="fieldset" mt={4}>
<FieldSetLegend
legendTitle={
<Trans id="controls.section.animation.type">
Animation Type
</Trans>
}
/>
</Flex>
</Box>
<Flex sx={{ justifyContent: "flex-start" }}>
<ChartOptionRadioField
label={t({
id: "controls.section.animation.type.continuous",
message: "Continuous",
})}
field="animation"
path="type"
value="continuous"
/>
<ChartOptionRadioField
label={t({
id: "controls.section.animation.type.stepped",
message: "Stepped",
})}
field="animation"
path="type"
value="stepped"
/>
</Flex>
</Box>
</>
)}
</ControlSectionContent>
</ControlSection>
Expand Down
9 changes: 8 additions & 1 deletion app/configurator/config-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,16 @@ const GenericSegmentField = t.intersection([
]);
export type GenericSegmentField = t.TypeOf<typeof GenericSegmentField>;

const AnimationType = t.union([t.literal("continuous"), t.literal("stepped")]);
export type AnimationType = t.TypeOf<typeof AnimationType>;

const AnimationField = t.intersection([
GenericField,
t.type({ showPlayButton: t.boolean, duration: t.number }),
t.type({
showPlayButton: t.boolean,
duration: t.number,
type: AnimationType,
}),
]);
export type AnimationField = t.TypeOf<typeof AnimationField>;

Expand Down
2 changes: 2 additions & 0 deletions app/configurator/configurator-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ export const handleChartFieldChanged = (
componentIri,
showPlayButton: true,
duration: 30,
type: "continuous",
};
} else if (field === "segment") {
// FIXME: This should be more chart specific
Expand Down Expand Up @@ -877,6 +878,7 @@ export const handleChartFieldChanged = (
showPlayButton:
draft.chartConfig.fields.animation?.showPlayButton ?? true,
duration: draft.chartConfig.fields.animation?.duration ?? 30,
type: draft.chartConfig.fields.animation?.type ?? "continuous",
};
} else if (
field === "segment" &&
Expand Down
12 changes: 10 additions & 2 deletions app/configurator/interactive-filters/time-slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useInteractiveFilters } from "@/charts/shared/use-interactive-filters";
import { TableChartState } from "@/charts/table/table-state";
import { Slider as GenericSlider } from "@/components/form";
import { parseDate } from "@/configurator/components/ui-helpers";
import { AnimationType } from "@/configurator/config-types";
import { useTimeFormatUnit } from "@/formatters";
import { DimensionMetadataFragment, TimeUnit } from "@/graphql/query-hooks";
import { TemporalDimension } from "@/graphql/resolver-types";
Expand Down Expand Up @@ -35,12 +36,14 @@ export const TimeSlider = ({
dimensions,
showPlayButton,
animationDuration,
animationType,
}: {
componentIri?: string;
dimensions: DimensionMetadataFragment[];
showPlayButton: boolean;
/** Animation duration in seconds. */
animationDuration: number;
animationType: AnimationType;
}) => {
const component = React.useMemo(() => {
return dimensions.find((d) => d.iri === componentIri) as
Expand Down Expand Up @@ -82,8 +85,13 @@ export const TimeSlider = ({
]);

const timeline = React.useMemo(() => {
return new Timeline(animationDuration * 1000, timelineData, formatDate);
}, [animationDuration, timelineData, formatDate]);
return new Timeline({
type: animationType,
msDuration: animationDuration * 1000,
msValues: timelineData,
formatMsValue: formatDate,
});
}, [animationType, animationDuration, timelineData, formatDate]);

return (
<TimelineContext.Provider value={timeline}>
Expand Down
12 changes: 12 additions & 0 deletions app/locales/de/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,18 @@ msgstr "Animation Einstellungen"
msgid "controls.section.animation.show-play-button"
msgstr "Schaltfläche Abspielen anzeigen"

#: app/configurator/components/chart-options-selector.tsx
msgid "controls.section.animation.type"
msgstr "Animation Typ"

#: app/configurator/components/chart-options-selector.tsx
msgid "controls.section.animation.type.continuous"
msgstr "Kontinuierlich"

#: app/configurator/components/chart-options-selector.tsx
msgid "controls.section.animation.type.stepped"
msgstr "Abgestuft"

#: app/configurator/components/chart-configurator.tsx
msgid "controls.section.chart.options"
msgstr "Diagramm-Einstellungen"
Expand Down
12 changes: 12 additions & 0 deletions app/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,18 @@ msgstr "Animation Settings"
msgid "controls.section.animation.show-play-button"
msgstr "Show Play button"

#: app/configurator/components/chart-options-selector.tsx
msgid "controls.section.animation.type"
msgstr "Animation Type"

#: app/configurator/components/chart-options-selector.tsx
msgid "controls.section.animation.type.continuous"
msgstr "Continuous"

#: app/configurator/components/chart-options-selector.tsx
msgid "controls.section.animation.type.stepped"
msgstr "Stepped"

#: app/configurator/components/chart-configurator.tsx
msgid "controls.section.chart.options"
msgstr "Chart Options"
Expand Down
12 changes: 12 additions & 0 deletions app/locales/fr/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,18 @@ msgstr "Paramètres d'animation"
msgid "controls.section.animation.show-play-button"
msgstr "Bouton Afficher la lecture"

#: app/configurator/components/chart-options-selector.tsx
msgid "controls.section.animation.type"
msgstr "Type d'animation"

#: app/configurator/components/chart-options-selector.tsx
msgid "controls.section.animation.type.continuous"
msgstr "En continu"

#: app/configurator/components/chart-options-selector.tsx
msgid "controls.section.animation.type.stepped"
msgstr "En escalier"

#: app/configurator/components/chart-configurator.tsx
msgid "controls.section.chart.options"
msgstr "Paramètres graphiques"
Expand Down
12 changes: 12 additions & 0 deletions app/locales/it/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,18 @@ msgstr "Impostazioni dell'animazione"
msgid "controls.section.animation.show-play-button"
msgstr "Mostra il pulsante di riproduzione"

#: app/configurator/components/chart-options-selector.tsx
msgid "controls.section.animation.type"
msgstr "Tipo di animazione"

#: app/configurator/components/chart-options-selector.tsx
msgid "controls.section.animation.type.continuous"
msgstr "Continuo"

#: app/configurator/components/chart-options-selector.tsx
msgid "controls.section.animation.type.stepped"
msgstr "A gradini"

#: app/configurator/components/chart-configurator.tsx
msgid "controls.section.chart.options"
msgstr "Opzioni del grafico"
Expand Down
1 change: 1 addition & 0 deletions app/utils/chart-config/versioning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ const migrations: Migration[] = [
...timeSlider,
showPlayButton: true,
duration: 30,
type: "continuous",
};
}
});
Expand Down
Loading