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

[charts] Add line animation #11620

Merged
merged 35 commits into from
Jan 30, 2024
Merged

Conversation

alexfauquette
Copy link
Member

@alexfauquette alexfauquette commented Jan 9, 2024

How animation works

Animating a line means modifying a lot of points. To avoid modifying too many data point, I took the approach of Nivo which is:

Have a value animated from 0 to 1 and then perform an interpolation of the path between it previous d value to its next one.

In addition, each element is wrapped with a clip path that goes from left to right when the component is created

Tricks

  1. The marks reuse the line clip path. I did not wanted to introduce a new intermediate component for Marks, so all marks are render at once, which makes it impossible to create a clipPath per series. So I just reused the one of the line chart with the idea that the mark plot will never be used without the line plot
  2. I reversed the area order. That's to avoid the following issue where area overflow each over while they are transitioning to their final position. what you see is not an interpolation bug, it's just that the top area is on to of the middle one which is on top of the bottom one. And lines are on top of all areas.

Screenshot from 2024-01-25 11-29-05

  1. I introduce a chartId that I store with the drawing area. This id is used to define clip path ids. Otherwise, two charts with same series ids would have same clipPath id which will lead to inconsistent behavior.

changelog

The line chart now have animation by default.
You can disable them with skipAnimation prop.
See next.mui.com/x/react-charts/lines/#animation for more information.

@mui-bot
Copy link

mui-bot commented Jan 9, 2024

Deploy preview: https://deploy-preview-11620--material-ui-x.netlify.app/

Updated pages:

Generated by 🚫 dangerJS against 6fa4b07

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 10, 2024
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 22, 2024
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 24, 2024
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@alexfauquette alexfauquette marked this pull request as ready for review January 24, 2024 14:42
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 24, 2024
Pick<AreaElementProps, 'slots' | 'slotProps'> {}
Pick<AreaElementProps, 'slots' | 'slotProps' | 'skipAnimation'> {}

const useCompletedData = () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an extraction of the data computation to keep props propagation as clean as possible.

The initial reason was a debugging session, where I suspected to have a forgotten props somwhere

@zannager zannager added the component: charts This is the name of the generic UI component, not the React module! label Jan 26, 2024
Copy link
Member

@LukasTy LukasTy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! 👍 💯
LGTM, leaving some suggestion and nitpicks. 🙈

By the way, do you really think that it is worth treating it as a breaking change? 🤔
Is there something that will no longer work or be completely different after this change?

docs/data/charts/lines/lines.md Outdated Show resolved Hide resolved
docs/data/charts/lines/lines.md Outdated Show resolved Hide resolved
packages/x-charts/src/LineChart/AreaElement.tsx Outdated Show resolved Hide resolved
packages/x-charts/src/LineChart/AreaPlot.tsx Show resolved Hide resolved
docs/data/charts/lines/ConnectNulls.tsx Show resolved Hide resolved
packages/x-charts/src/LineChart/LineElement.tsx Outdated Show resolved Hide resolved
packages/x-charts/src/LineChart/LineElement.tsx Outdated Show resolved Hide resolved
packages/x-charts/src/LineChart/MarkPlot.tsx Outdated Show resolved Hide resolved
packages/x-charts/src/context/DrawingProvider.tsx Outdated Show resolved Hide resolved
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 29, 2024
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@alexfauquette
Copy link
Member Author

Is there something that will no longer work or be completely different after this change?

The slot was getting the animated path. So d was not a string but a string interpolation made by spring.

I modified the code to avoid this modification. THe adventage is that if you don't want the animation, you could use the slots.line to replace AnimatedLine by a path and it should work

  • LinePlot
    • LineElement
      • AnimatedLine (New element that can be replaced by a slot)
        • animated.path

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 29, 2024
@alexfauquette alexfauquette merged commit 8392f53 into mui:next Jan 30, 2024
17 checks passed
thomasmoon pushed a commit to thomasmoon/mui-x that referenced this pull request Sep 9, 2024
Signed-off-by: Alexandre Fauquette <[email protected]>
Co-authored-by: Lukas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: charts This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants