Skip to content

Commit

Permalink
feat(view): 支持 plot 上的移动事件触发
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ authored and hustcc committed Apr 2, 2020
1 parent 59db3b5 commit 4a86b08
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions src/chart/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1441,26 +1441,28 @@ export class View extends Base {
const TYPE = `plot:${type}`; // 组合 plot 事件
e.type = TYPE;
this.emit(TYPE, e);
if (type === 'mouseleave') { // 在plot 内部却离开画布
if (type === 'mouseleave' || type === 'touchend') { // 在plot 内部却离开画布
this.isPreMouseInPlot = false;
}
}

// 对于 mouseenter, mouseleave 的计算处理
if (type === 'mousemove') {
if (type === 'mousemove' || type === 'touchmove') {
if (this.isPreMouseInPlot && !currentInPlot) {
e.type = PLOT_EVENTS.MOUSE_LEAVE;
this.emit(PLOT_EVENTS.MOUSE_LEAVE, e);
const eventName = type === 'mousemove' ? PLOT_EVENTS.MOUSE_LEAVE : PLOT_EVENTS.TOUCH_END;
e.type = eventName;
this.emit(eventName, e);
} else if (!this.isPreMouseInPlot && currentInPlot) {
e.type = PLOT_EVENTS.MOUSE_ENTER;
this.emit(PLOT_EVENTS.MOUSE_ENTER, e);
}
// 赋新的状态值
this.isPreMouseInPlot = currentInPlot;
} else if (type === 'mouseleave') { // 可能不在 currentInPlot 中
} else if (type === 'mouseleave' || type === 'touchend') { // 可能不在 currentInPlot 中
if (this.isPreMouseInPlot) {
e.type = PLOT_EVENTS.MOUSE_LEAVE;
this.emit(PLOT_EVENTS.MOUSE_LEAVE, e);
const eventName = type === 'mouseleave' ? PLOT_EVENTS.MOUSE_LEAVE : PLOT_EVENTS.TOUCH_END;
e.type = eventName;
this.emit(eventName, e);
this.isPreMouseInPlot = false;
}
}
Expand Down Expand Up @@ -1762,15 +1764,6 @@ export class View extends Base {
private getScaleKey(field: string): string {
return `${this.id}-${field}`;
}

/**
* 添加一个 geometry 到画布。
* @param geometry geometry 实例
* @returns void
*/
private addGeometry(geometry: Geometry) {
this.geometries.push(geometry);
}
}

/**
Expand All @@ -1794,7 +1787,7 @@ export function registerGeometry(name: string, Ctor: any) {
};

const geometry = new Ctor(props);
this.addGeometry(geometry);
this.geometries.push(geometry);

return geometry;
};
Expand Down

0 comments on commit 4a86b08

Please sign in to comment.