From 58a9713bf21318094be61b8fec6e19f30ef39473 Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Mon, 16 Mar 2015 23:04:10 +0700 Subject: [PATCH] Keep chart item when switching dates --- app/scripts/src/charts/bar_chart.jsx | 4 +++- app/scripts/src/charts/stacked_area_chart.jsx | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/scripts/src/charts/bar_chart.jsx b/app/scripts/src/charts/bar_chart.jsx index 5fc1d71..47f4912 100644 --- a/app/scripts/src/charts/bar_chart.jsx +++ b/app/scripts/src/charts/bar_chart.jsx @@ -25,7 +25,9 @@ var BarChart = React.createClass({ componentWillReceiveProps: function(newProps) { this.setState({ - item: newProps.items[0], + item: (_.isEqual(newProps.items, this.props.items) + ? this.state.item + : newProps.items[0]), state: 'newProps' }, this.fetchData); }, diff --git a/app/scripts/src/charts/stacked_area_chart.jsx b/app/scripts/src/charts/stacked_area_chart.jsx index d96cec8..31b9240 100644 --- a/app/scripts/src/charts/stacked_area_chart.jsx +++ b/app/scripts/src/charts/stacked_area_chart.jsx @@ -38,7 +38,9 @@ var StackedAreaChart = React.createClass({ componentWillReceiveProps: function(newProps) { this.setState({ - item: newProps.items[0], + item: (_.isEqual(newProps.items, this.props.items) + ? this.state.item + : newProps.items[0]), state: 'newProps' }, this.fetchData); },