react-plotly.js icon indicating copy to clipboard operation
react-plotly.js copied to clipboard

Update animations w/ react-plotly

Open BG687 opened this issue 6 years ago • 25 comments

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

BG687 avatar Sep 12 '18 18:09 BG687

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

nicolaskruchten avatar Sep 12 '18 18:09 nicolaskruchten

@nicolaskruchten any update on this?

GrahamWilsdon avatar Feb 08 '19 14:02 GrahamWilsdon

@GrahamWilsdon Some transitions are possible now, see the info in the PR that closed the mentioned issue: https://github.com/plotly/plotly.js/pull/3217#issue-228521121

dmt0 avatar Feb 08 '19 14:02 dmt0

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}
    />
  )
}

billyhunt avatar Aug 28 '19 14:08 billyhunt

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

nicolaskruchten avatar Aug 28 '19 17:08 nicolaskruchten

@nicolaskruchten Do we already have Bar chart animations?

CarlosAmaral avatar Jun 11 '20 10:06 CarlosAmaral

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

nicolaskruchten avatar Jun 11 '20 13:06 nicolaskruchten

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

CarlosAmaral avatar Jun 11 '20 13:06 CarlosAmaral

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

nicolaskruchten avatar Jun 11 '20 19:06 nicolaskruchten

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

CarlosAmaral avatar Jun 12 '20 05:06 CarlosAmaral

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

nicolaskruchten avatar Jun 12 '20 12:06 nicolaskruchten

Is there any example of animating the scatter plot?

qidian99 avatar Jun 15 '20 06:06 qidian99

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

CarlosAmaral avatar Jun 15 '20 06:06 CarlosAmaral

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

nicolaskruchten avatar Jun 15 '20 12:06 nicolaskruchten

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

CarlosAmaral avatar Jun 15 '20 15:06 CarlosAmaral

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

nicolaskruchten avatar Jun 15 '20 15:06 nicolaskruchten

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

CarlosAmaral avatar Jun 15 '20 16:06 CarlosAmaral

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

joan780 avatar Jul 23 '20 00:07 joan780

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

CarlosAmaral avatar Jul 26 '20 11:07 CarlosAmaral

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

joan780 avatar Jul 28 '20 17:07 joan780

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

CarlosAmaral avatar Jul 29 '20 06:07 CarlosAmaral

@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!

joan780 avatar Jul 29 '20 14:07 joan780

@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

tony avatar Jan 02 '21 17:01 tony

any update on this?

AlexBlack2202 avatar Sep 07 '22 07:09 AlexBlack2202

Is there any example of animating the scatter plot?

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

openSourcerer9000 avatar Mar 29 '23 16:03 openSourcerer9000