Skip to content

Commit

Permalink
feat: 添加geom draw 事件
Browse files Browse the repository at this point in the history
  • Loading branch information
zengyue committed May 18, 2020
1 parent 7a6aaa7 commit b52f708
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/chart/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
EVENT_AFTER_DATA_CHANGE,
EVENT_AFTER_SIZE_CHANGE,
EVENT_AFTER_GEOM_INIT,
EVENT_BEFORE_GEOM_DRAW,
EVENT_AFTER_GEOM_DRAW,
EVENT_CLEAR,
EVENT_CLEAR_INNER
} from './const';
Expand Down Expand Up @@ -592,12 +594,14 @@ class Chart extends Base {
middlePlot.attr('clip', clip);
}

this.emit(EVENT_BEFORE_GEOM_DRAW);
for (let i = 0, length = geoms.length; i < length; i++) {
const geom = geoms[i];
geom.paint();
}

this.emit(EVENT_AFTER_GEOM_DRAW);
Chart.plugins.notify(this, 'afterGeomDraw');

canvas.sort();
this.get('frontPlot').sort();
Chart.plugins.notify(this, 'beforeCanvasDraw');
Expand Down
4 changes: 4 additions & 0 deletions src/chart/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const EVENT_AFTER_DATA_CHANGE = 'afterdatachange';
const EVENT_AFTER_SIZE_CHANGE = '_aftersizechange';

const EVENT_AFTER_GEOM_INIT = '_aftergeominit';
const EVENT_BEFORE_GEOM_DRAW = 'beforegeomdraw';
const EVENT_AFTER_GEOM_DRAW = 'aftergeomdraw';

const EVENT_CLEAR = 'clear';
const EVENT_CLEAR_INNER = 'clearinner';
Expand All @@ -21,6 +23,8 @@ export {
EVENT_AFTER_DATA_CHANGE,
EVENT_AFTER_SIZE_CHANGE,
EVENT_AFTER_GEOM_INIT,
EVENT_BEFORE_GEOM_DRAW,
EVENT_AFTER_GEOM_DRAW,
EVENT_CLEAR,
EVENT_CLEAR_INNER
};
2 changes: 1 addition & 1 deletion src/chart/controller/scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class ScaleController {
}
} else {
// 为了让图形居中,所以才设置range
offset = 1 / count * 1 / 2;
offset = 1 / count * 0.5; // 这里可能用0.25会更合理
cfg.range = [ offset, 1 - offset ];
}
}
Expand Down

0 comments on commit b52f708

Please sign in to comment.