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

Animate plugin #35

Open
iddan opened this issue Mar 5, 2017 · 9 comments
Open

Animate plugin #35

iddan opened this issue Mar 5, 2017 · 9 comments

Comments

@iddan
Copy link

iddan commented Mar 5, 2017

When working with React we don't update data manually but pass it through the props.
Is there a way to activate animated updates? like:

chart.animateData(newData, { duration: 1000 });

Maybe an animated prop can suit this case?

@bleachdugu
Copy link

@iddan you need to add a state or a parameter for your component to store the previously changed newData, then pass the previous changed data to dataProvider in amchart config.

and pass the latest newData to chart.animateData(newData, { duration: 1000 });
things is this animation api need the temp data stored in your component to trigger the anim

@iddan
Copy link
Author

iddan commented Mar 7, 2017

Storing chart's data in a component state is obvious. The thing is unless I use ref I can't access the chart's methods (i.e animteData()). So I'm trying to figure if it's possible to use some kind of attribute to make it work or, if you will, provide a HOC to do so.

@RahavLussato
Copy link
Contributor

@iddan i added animate support to my PR #30

you'll need to :

  1. import 'amcharts3-animate';.
  2. add newDataProvider to the config.
  3. add isAnimate={true} to props of AmCharts.React

@iddan
Copy link
Author

iddan commented Mar 7, 2017

@RahavLussato You are genuinely amazing.
I would refactor to animated or animate prop name.
Tip: JSX it's better writing: <MyComponent prop /> than <MyComponent prop={true} />.

@RahavLussato
Copy link
Contributor

@iddan thanks.
i agree with your tip but it also depends on your's eslint config :)

@iddan
Copy link
Author

iddan commented Mar 7, 2017

Would you mind refactor @RahavLussato?

@RahavLussato
Copy link
Contributor

RahavLussato commented Mar 7, 2017

@iddan done, changed to animated.

@Pauan
Copy link
Collaborator

Pauan commented Apr 3, 2017

@iddan I'm sorry for the delay. I plan to make some changes to the animate plugin which will allow for a declarative API.

In the meantime, you can use the solution created by @RahavLussato, or alternatively you can use the init event to store the chart object, allowing you to call all of the AmCharts methods:

class App extends React.Component {
  constructor(props) {
    super(props);

    this.state = {};

    this.chart = null;
  }

  render() {
    let config = {
      "listeners": [{
        "event": "init",
        "method": (e) => {
          this.chart = e.chart;
        }
      }]
    };

    return <AmCharts.React {...config} />;
  }

  animateData(newData) {
    if (this.chart !== null) {
      this.chart.animateData(newData, { duration: 1000 });
    }
  }
}

@iddan
Copy link
Author

iddan commented Apr 4, 2017

@Pauan yeah I figured out but it will be good to have an official declarative API. I'll be looking up for it

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

4 participants