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

Update animations w/ react-plotly #101

Open
BG687 opened this issue Sep 12, 2018 · 25 comments
Open

Update animations w/ react-plotly #101

BG687 opened this issue Sep 12, 2018 · 25 comments

Comments

@BG687
Copy link

BG687 commented Sep 12, 2018

I would like to animate my stacked area chart when the data updates (so the transition from the old data to the new data is smooth). Right now, when the data updates the chart just instantly changes to reflect the new data.

I don't see an animate function on the Plotly react component or its prototype. What is the best way to go about animating these charts? Is this possible?

Thanks

@nicolaskruchten
Copy link
Member

This isn't currently possible within react-plotly.js but we're working on adding support for it in the underlying plotly.js library: plotly/plotly.js#1849

@GrahamWilsdon
Copy link

@nicolaskruchten any update on this?

@dmt0
Copy link
Contributor

dmt0 commented Feb 8, 2019

@GrahamWilsdon Some transitions are possible now, see the info in the PR that closed the mentioned issue: plotly/plotly.js#3217 (comment)

@billyhunt
Copy link

billyhunt commented Aug 28, 2019

Are bar chart animations available? I was having trouble getting one to work.

I am doing something like

const HistogramComponent: FunctionComponent<{
  timeAggregation: any
  unitOfTime: any
}> = () => {

  const determineTickFormat = (interval: UnitOfTime) => {
    let tickFormat = '%y/%m'

    switch (interval) {
      case 'daily':
        tickFormat = '%d/%m/%Y'
        break
      case 'weekly':
        tickFormat = '%m/%Y'
        break
      case 'monthly':
        tickFormat = '%b %Y'
        break
      case 'yearly':
      default:
        tickFormat = '%Y'
        break
    }
    return tickFormat
  }

  let data: Partial<PlotData>[]
  let layout = {}

  const transition = {
    duration: 2000,
    easing: 'cubic-in-out'
  }

  const layout = {
    autosize: true,
    transition,
    margin: {
      l: 30,
      r: 30,
      b: 30,
      t: 15
    },
    font: {
      family: 'Heebo, Overpass, sans-serif',
      color: theme.fgGrey
    },
    xaxis: {
      ticklen: 5,
      tickwidth: 1,
      tickcolor: theme.fgGreyLight,
      ticks: 'outside',
      lineWidth: 1,
      fixedrange: true // disables zooming on x axis
    },
    yaxis: {
      lineWidth: 1,
      zerolinecolor: theme.fgGreyLight,
      fixedrange: true // disables zooming on y axis
    }
  }

  return (
    <StyledPlot
      data={data}
      layout={layout}
      useResizeHandler={true}
      config={config}
    />
  )
}

@nicolaskruchten
Copy link
Member

No, bar chart animations are not merged yet... coming soon!

@CarlosAmaral
Copy link

@nicolaskruchten Do we already have Bar chart animations?

@nicolaskruchten
Copy link
Member

Bar chart transitions are supported in recent versions of Plotly.js, yes.

@CarlosAmaral
Copy link

@nicholas-esterer I used the same code as @billyhunt. Didn't work. Do you have an example that you can share? Thank you!

@nicolaskruchten
Copy link
Member

@CarlosAmaral which version of plotly.js are you using? Try 1.54.2 :)

@CarlosAmaral
Copy link

@nicholas-esterer I did that. Same outcome. No animation.

@nicolaskruchten
Copy link
Member

Can you provide a full running example in a codepen or something for me to help you debug?

@qidian99
Copy link

Is there any example of animating the scatter plot?

@CarlosAmaral
Copy link

@nicolaskruchten https://264b4.codesandbox.io/ sorry for the delay

@nicolaskruchten
Copy link
Member

@CarlosAmaral thanks! What part of this is meant to be animated?

@CarlosAmaral
Copy link

CarlosAmaral commented Jun 15, 2020

Thank you, @nicolaskruchten. Good question, the bars going up for example?

@nicolaskruchten
Copy link
Member

You mean an on-load transition where the bars grow from zero? Or in response to user input or... ?

@CarlosAmaral
Copy link

CarlosAmaral commented Jun 15, 2020

@nicolaskruchten yes, on loading, just making the bars go from zero to their value.

@joan780
Copy link

joan780 commented Jul 23, 2020

@nicolaskruchten I run into the same problem. Is there any update?

@CarlosAmaral
Copy link

It actually works if you switch data. In my case: I was expecting an animation when opening a modal, probably it rendered before.

@joan780
Copy link

joan780 commented Jul 28, 2020

I also need animation when the chart is loading at first. Do you happen to have examples to share?

@CarlosAmaral
Copy link

@joan780 No, that's something that I wasn't yet able to accomplish but I'm looking into that.

@joan780
Copy link

joan780 commented Jul 29, 2020

@CarlosAmaral I just figured out a way of doing it but probably not a best practice though. Here it is -
https://codesandbox.io/s/red-shape-bb5y8?file=/src/plotly/plotly.js
Would like feedback about it!

@tony
Copy link

tony commented Jan 2, 2021

@joan780 When I try the example, I get this:

TypeError: Cannot read property 'document' of undefined

image

Not sure if it's related to the code itself, or codesandbox

@AlexBlack2202
Copy link

any update on this?

@openSourcerer9000
Copy link

Is there any example of animating the scatter plot?

Following this - it would be great to have a starting place to go off

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests