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

[Documentation Request]: Animation #27

Open
SumNeuron opened this issue Nov 28, 2019 · 4 comments
Open

[Documentation Request]: Animation #27

SumNeuron opened this issue Nov 28, 2019 · 4 comments

Comments

@SumNeuron
Copy link

Please provide a minimal example of animation with your wrapper. I have data dynamically bound, but it seems to just have plotly redraw, when animation is specified in options

@SumNeuron
Copy link
Author

Since the owner of the repo seems silent on addressing issues, i'll address two main issues here for others to reference.

Animation

As is, the component doesn't support animation. Why? Two reasons.

  1. the author of the component does not expose Plotly.animate anywhere.
  2. the author of the component explicitly uses Plotly.react to do all updating. This means if your data changes, it will call this.react() twice and since the data is now where it is would be, even if you manually call Plotly.animate you will see no animation.

How can you get around this? (for those that need a one-and-done, not a reusable solution)

  1. copy-paste the component to your own Plotly.vue file
  2. above export default add your transition specification:
const transitionSpec = {
  transition: {
    duration: 500,
    easing: 'cubic-in-out',
  },
  frame: {
    duration: 500,
    redraw: false
  }
}
  1. in the mounted lifecycle hook, change the this.$watch functions that call this.react to a function called `this.reactAnimate()
  2. in methods define a function animatePlot
animatePlot() {
      try {
        return Plotly.animate(
          this.$refs.container,
          {
            data: this.data,
            layout: this.internalLayout,
            config: {
              ...this.getOptions(),
              animationAttributes: transitionSpec, // <--- hardcoded above 
              displaylogo: false
            }
          },
        )
      }
      catch (error) {
         // maybe fall back here to this.react()
        console.log('error',  error)
      }
    },
  1. in methods define the function reactAnimate
reactAnimate() {
      let dr = this.internalLayout.datarevision
      if (dr === 1) {
        this.react()
      }
      else {
        this.animatePlot()
      }
    },

This will work because react will create a plot if it doesn't already exist. Since this component updates the data revisions, every time the data changes, if it is not the first time, it will animate instead.

If you want to make it more reusable, add a prop to the component for the animation configuration.

Resize

If you specify autoResize inside options or layout, it will not work. You need to specify on the component that you want it to resize:

<Plotly :autoResize="true"/>

This must be set on the components creation, as the function initEvents will only add a debounced resize option if set to true!

NOTE if you made my above changes for animation, you do not need to change the debounced function. Leave this as this.react so your plot will snap correctly when resizing occurs (reactAnimate will only call react once!)

This was referenced Feb 13, 2020
@datainvestor
Copy link

So how do you call the animation in the component? Is the plot automatically animated after adding those extra lines of codes above?

@datainvestor
Copy link

Heads up, the solution posted above does not work.

@yishiy
Copy link

yishiy commented Nov 19, 2020

can someone help with this issue? would be super nice if the animation feature works!

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

3 participants