Skip to content

Commit

Permalink
fix: when data changed, the padding should be recalculated.
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ committed Jun 8, 2018
1 parent 0d04a1d commit fe7c221
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/chart/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,8 @@ class Chart extends Base {
return this;
}

repaint() {
repaint(isDataChanged) {
this.set('dataChanged', isDataChanged);
this.set('isUpdate', true);
Chart.plugins.notify(this, 'repaint');
this._clearInner();
Expand All @@ -533,7 +534,7 @@ class Chart extends Base {

changeData(data) {
this.set('data', data);
this.repaint();
this.repaint(true);
}

changeSize(width, height) {
Expand Down Expand Up @@ -708,6 +709,9 @@ class Chart extends Base {
}

_isAutoPadding() {
if (this.get('_padding')) {
return false;
}
const padding = this.get('padding');
if (Util.isArray(padding)) {
return padding.indexOf('auto') !== -1;
Expand Down
4 changes: 2 additions & 2 deletions src/chart/controller/axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class AxisController {

const axes = this.axes;
const chart = self.chart;
if (chart._isAutoPadding()) {
if (chart._isAutoPadding() || chart.get('dataChanged')) { // 数据变更时需要重新计算
const userPadding = Util.parsePadding(chart.get('padding'));
const appendPadding = chart.get('appendPadding');
const legendRange = chart.get('legendRange') || {
Expand Down Expand Up @@ -277,7 +277,7 @@ class AxisController {
padding[2] += maxHeight + labelOffset;
}
}
chart.set('padding', padding); // TODO, 需要判断下,changeData 时不变换
chart.set('_padding', padding); // 不改变原始的 padding 属性值,将计算后的 padding 存储在 _padding 属性中
chart._updateLayout(padding);
}

Expand Down

0 comments on commit fe7c221

Please sign in to comment.