@@ -13,8 +13,12 @@ function omit(obj, keysToRemove) {
1313function deepEqual ( obj1 , obj2 , visited = new WeakSet ( ) ) {
1414 if ( obj1 === obj2 ) return true ;
1515
16- if ( typeof obj1 !== 'object' || obj1 === null ||
17- typeof obj2 !== 'object' || obj2 === null ) {
16+ if (
17+ typeof obj1 !== 'object' ||
18+ obj1 === null ||
19+ typeof obj2 !== 'object' ||
20+ obj2 === null
21+ ) {
1822 return false ;
1923 }
2024
@@ -63,26 +67,33 @@ export default function Charts({
6367 const prevOptions = chart . current . options ;
6468 const prevSeries = chart . current . series ;
6569
66- if (
70+ const seriesChanged = ! deepEqual ( prevSeries , series ) ;
71+ const optionsChanged =
6772 ! deepEqual ( prevOptions , options ) ||
68- ! deepEqual ( prevSeries , series ) ||
6973 height !== chart . current . height ||
70- width !== chart . current . width
71- ) {
72- if ( deepEqual ( prevSeries , series ) ) {
74+ width !== chart . current . width ;
75+
76+ if ( seriesChanged || optionsChanged ) {
77+ if ( ! seriesChanged ) {
78+ // series has not changed, but options or size have changed
7379 chart . current . updateOptions ( getConfig ( ) ) ;
74- } else {
80+ } else if ( ! optionsChanged ) {
81+ // options or size have not changed, just the series has changed
7582 chart . current . updateSeries ( series ) ;
83+ } else {
84+ // both might be changed
85+ chart . current . updateOptions ( getConfig ( ) ) ;
7686 }
7787 }
88+
7889 } , [ options , series , height , width ] ) ;
7990
8091 const getConfig = ( ) => {
8192 const newOptions = {
8293 chart : { type, height, width } ,
8394 series
8495 } ;
85-
96+
8697 return extend ( options , newOptions ) ;
8798 } ;
8899
0 commit comments