diff --git a/src/chart/chart.js b/src/chart/chart.js index af636802f..3cc82221f 100644 --- a/src/chart/chart.js +++ b/src/chart/chart.js @@ -420,7 +420,6 @@ class Chart extends Base { // 更新geoms里的数据 this._changeGeomsData(); - this._adjustScale(); }); // 大小变化后的一些更新 @@ -583,6 +582,7 @@ class Chart extends Base { // 已经渲染过 if (rendered) { this._initGeoms(); + this._adjustScale(); } else { this.init(); this.set('rendered', true); diff --git a/src/geom/base.js b/src/geom/base.js index 1ebd4081f..0c18544ca 100644 --- a/src/geom/base.js +++ b/src/geom/base.js @@ -801,6 +801,7 @@ class Geom extends Base { this.set('data', data); // 改变数据后,情况度量,因为需要重新实例化 this.set('scales', {}); + if (!this.get('isInit')) return; this.set('isInit', false); this.init(); } diff --git a/test/unit/geom/geom-init-spec.js b/test/unit/geom/geom-init-spec.js index e76d9a2d7..696e1b57f 100644 --- a/test/unit/geom/geom-init-spec.js +++ b/test/unit/geom/geom-init-spec.js @@ -40,6 +40,35 @@ describe('Geom init', function() { } ]; + const data2 = [ + { + date: '2020-05-10', + dailyProfit: '0.00', + profit: -15.69 + }, + { + date: '2020-05-20', + dailyProfit: '0.00', + profit: 15.69 + }, + { + date: '2020-06-10', + dailyProfit: '0.00', + profit: 115.69 + }, + { + date: '2020-07-10', + dailyProfit: '0.00', + profit: 215.69 + }, + { + date: '2020-08-10', + dailyProfit: '0.00', + profit: -20.69 + } + + ]; + chart.source(data); chart.axis('date', { @@ -53,9 +82,57 @@ describe('Geom init', function() { expect(chart.get('geoms')[0].get('isInit')).to.be.true; chart.line().position('date*profit'); chart.render(); - expect(chart.get('geoms').length).equal(2); + chart.line().position('date*profit'); + chart.changeData(data2); + expect(chart.get('geoms').length).equal(3); + + }); + + + it('interval adjust', function() { + + chart = new Chart({ + el: canvas + }); + const data = [ + { + date: '2020-05-10', + dailyProfit: '0.00', + profit: 25.69 + }, + { + date: '2020-05-20', + dailyProfit: '0.00', + profit: 15.69 + } + ]; + + const changeData = [ + { + date: '2020-05-10', + dailyProfit: '0.00', + profit: 25.69 + }, + { + date: '2020-05-20', + dailyProfit: '0.00', + profit: 15.69 + }, + { + date: '2020-06-10', + dailyProfit: '0.00', + profit: 115.69 + } + ]; + + chart.source(data); + chart.interval().position('date*profit'); + chart.render(); + chart.interval().position('date*profit'); + chart.changeData(changeData); + expect(chart.get('data').length).equal(3); }); });