Skip to content

Commit

Permalink
feat: adjust interval
Browse files Browse the repository at this point in the history
  • Loading branch information
cycgit committed Jun 16, 2020
1 parent b7c6099 commit f4ea6de
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/chart/chart.js
Expand Up @@ -420,7 +420,6 @@ class Chart extends Base {

// 更新geoms里的数据
this._changeGeomsData();
this._adjustScale();
});

// 大小变化后的一些更新
Expand Down Expand Up @@ -583,6 +582,7 @@ class Chart extends Base {
// 已经渲染过
if (rendered) {
this._initGeoms();
this._adjustScale();
} else {
this.init();
this.set('rendered', true);
Expand Down
1 change: 1 addition & 0 deletions src/geom/base.js
Expand Up @@ -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();
}
Expand Down
79 changes: 78 additions & 1 deletion test/unit/geom/geom-init-spec.js
Expand Up @@ -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', {
Expand All @@ -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);
});

});

0 comments on commit f4ea6de

Please sign in to comment.