react-highcharts icon indicating copy to clipboard operation
react-highcharts copied to clipboard

Animation

Open ogreen111 opened this issue 8 years ago • 24 comments

It appears that the initial animation only works for line plots. I have tried column and pie with no success.

Using the demo at http://kirjs.github.io/react-highcharts/index.html

I added the below properties to the config object and get a bar chart but no animation.

 chart:{
    type: "column"
  },
  plotOptions: {
    series: {
      animation: {
        duration: 2000
      }
    }
  },

ogreen111 avatar Jul 20 '16 18:07 ogreen111

I added neverReflow={true} and the animation works. Not exactly sure why that has to be added to the column and pie charts and not the line.

ogreen111 avatar Jul 20 '16 18:07 ogreen111

This is weird indeed, can you provide examples?

kirjs avatar Jul 25 '16 00:07 kirjs

same here. adding neverReflow={true} works

amit1911 avatar Sep 15 '16 10:09 amit1911

I confirm this is an issue. This is trivial to reproduce but not easy to setup online. Setting neverReflow={true} is not acceptable as a workaround as I need reflows to animate when the configuration change. Any thoughts on what might be causing this?

acasaccia avatar Sep 22 '16 12:09 acasaccia

+1

rmemoria avatar Oct 11 '16 14:10 rmemoria

+1

hally9k avatar Nov 06 '16 04:11 hally9k

For some reason, the animation is suppressed due to the call to reflow in the renderChart function of the chartsFactory.jsx file. The reason it works if you set neverReflow={true} is because this never executes.

if (!this.props.neverReflow) {
        win.requestAnimationFrame && requestAnimationFrame(()=>{
          this.chart && this.chart.options && this.chart.reflow();
        });
      }

If you comment out only the && this.chart.reflow(), it works just fine.

Prior to submitting a pull that simply removes this, it would be good to understand the intent here. `

rcarek avatar Nov 08 '16 22:11 rcarek

+1

JakeHP avatar Dec 12 '16 21:12 JakeHP

+1

charliehavak avatar Dec 18 '16 12:12 charliehavak

Currently I overcame this with the following hack:

class Chart extends React.Component {

	componentDidUpdate() {
		let chart = this.refs.chart.getChart();
		chart.reflow = () => {};
	}

	render() {
		return (
			<HighchartsReact config={this.props.config} ref="chart"/>
		);
	}
}

charliehavak avatar Dec 18 '16 13:12 charliehavak

Thanks @charliehavak .. that was a nice workaround.. I realized that I still need reflow though for page resizing.. I added this and it seems to allow me to have both animations and reflow

  componentDidUpdate() {
    const chart = this.refs.chart ? this.refs.chart.getChart() : {}
    const chartReflow = chart.reflow
    chart.reflow = () => {}
    setTimeout(() => (chart.reflow = chartReflow))
  }

jordancardwell avatar Dec 19 '16 00:12 jordancardwell

Just realized that my solution had a flaw with somewhat of a race condition.. here is the slightly better (but no less hacky) solution

  import Highcharts from 'highcharts'
  let chartReflow = undefined;
...
  componentDidUpdate() {
    const chart = this.refs.chart ? this.refs.chart.getChart() : {}
    chartReflow = chartReflow || chart.reflow
    chart.reflow = () => {}
    setTimeout(() => (chart.reflow = chartReflow))
  }

my first solution didn't work for one of my charts.. componentDidUpdate seemed to be getting triggered before the timeout completed, so i then saved the reference to the empty chartReflow that we had just set an instant before..

this workaround makes sure to only ever save a reference to the legitimate reflow function ( @charliehavak ☝️ )

jordancardwell avatar Dec 21 '16 02:12 jordancardwell

Thanks for the workaround @jordancardwell.

Is anyone working on a real fix for this?

@kirjs: Do you know the answer to @rcarek's question from november? Would love to avoid the hack if I can.

erikfrisk avatar May 16 '17 10:05 erikfrisk

@erikfrisk I will have some time to look into that in a couple of weeks. Meanwhile PRs welcome.

kirjs avatar May 16 '17 11:05 kirjs

Awesome! Thanks @kirjs. I'll submit a PR if I can but I'm brand new to both react and highcharts 😄

erikfrisk avatar May 16 '17 11:05 erikfrisk

@kirjs did you get around issuing a fix? Otherwise @jordancardwell should I use your workaround?

adziashvili avatar Jun 18 '17 07:06 adziashvili

@adziashvili I'm still using the workaround in a production app.. works well enough :)

jordancardwell avatar Jun 18 '17 16:06 jordancardwell

Thanks for the workaround @jordancardwell! +1 for fix

Paden avatar Aug 01 '17 13:08 Paden

wow, this is still open?

kellyrmilligan avatar Feb 06 '18 20:02 kellyrmilligan

I have implemented the workaround, and the initial animation is still not triggering for me :(

kellyrmilligan avatar Feb 06 '18 20:02 kellyrmilligan

neverReflow is working for now. did you also have something that was triggering componentDidUpdate?

@jordancardwell

kellyrmilligan avatar Feb 06 '18 20:02 kellyrmilligan

Hi @kellyrmilligan , We will make a lot of changes in the 17th release. We plan to fix the bug with the animation. Make an example https://stackblitz.com/ .

ilyjs avatar Feb 06 '18 20:02 ilyjs

@kellyrmilligan we passed the data for the chart in as a prop of the component that wraps and renders the <ReactHighcharts ... /> component... so, in our case, whenever props.data changes, it re-renders and componentDidUpdate will get called after the render.

...possibly relevant to what you're doing: we also used the isPureConfig prop on the <ReactHighcharts ... /> component, so whenever a new config object is passed in it will re-render the chart.

jordancardwell avatar Feb 06 '18 20:02 jordancardwell

@jordancardwell It really works .... but maybe sometime it may this.refs is deprecated in react newer version ... so i implement ref like this


constructor(props) {
       super(props);
       this.chartRef = React.createRef();
   }

componentDidUpdate() {
	const chart = this.chartRef.current ? this.chartRef.current.getChart() : {}
       chartReflow = chartReflow || chart.reflow
       chart.reflow = () => {}
       setTimeout(() => (chart.reflow = chartReflow))
   }

<ReactHighcharts config={this.generateChartConfig(chartConfig)} ref={this.chartRef}></ReactHighcharts>

deshario avatar Jan 24 '19 03:01 deshario