UNPKG

@visactor/vchart

Version:

charts lib based @visactor/VGrammar

60 lines (55 loc) 3.03 kB
import { isMobileLikeMode } from "../../../util/env"; import { DimensionEvent } from "./base"; import { isSameDimensionInfo } from "./util/common"; import { Event_Source_Type } from "../../../constant/event"; export class DimensionHoverEvent extends DimensionEvent { constructor() { super(...arguments), this._cacheDimensionInfo = null, this.onMouseMove = params => { if (!params) return; const x = params.event.viewX, y = params.event.viewY, targetDimensionInfo = this.getTargetDimensionInfo(x, y); null === targetDimensionInfo && null !== this._cacheDimensionInfo ? (this._callback.call(null, Object.assign(Object.assign({}, params), { action: "leave", dimensionInfo: this._cacheDimensionInfo.slice() })), this._cacheDimensionInfo = targetDimensionInfo) : null === targetDimensionInfo || null !== this._cacheDimensionInfo && targetDimensionInfo.length === this._cacheDimensionInfo.length && !targetDimensionInfo.some(((info, i) => !isSameDimensionInfo(info, this._cacheDimensionInfo[i]))) ? null !== targetDimensionInfo && this._callback.call(null, Object.assign(Object.assign({}, params), { action: "move", dimensionInfo: targetDimensionInfo.slice() })) : (this._callback.call(null, Object.assign(Object.assign({}, params), { action: "enter", dimensionInfo: targetDimensionInfo.slice() })), this._cacheDimensionInfo = targetDimensionInfo); }, this.onMouseOut = params => { params && (this._callback.call(null, Object.assign(Object.assign({}, params), { action: "leave", dimensionInfo: this._cacheDimensionInfo ? this._cacheDimensionInfo.slice() : [] })), this._cacheDimensionInfo = null); }; } register(eType, handler) { this._callback = handler.callback, this._eventDispatcher.register("pointermove", { query: Object.assign(Object.assign({}, handler.query), { source: Event_Source_Type.chart }), callback: this.onMouseMove }), this._eventDispatcher.register("pointerout", { query: Object.assign(Object.assign({}, handler.query), { source: Event_Source_Type.canvas }), callback: this.onMouseOut }), isMobileLikeMode(this._mode) && this._eventDispatcher.register("pointerdown", { query: Object.assign(Object.assign({}, handler.query), { source: Event_Source_Type.chart }), callback: this.onMouseMove }); } unregister() { this._eventDispatcher.unregister("pointermove", { query: null, callback: this.onMouseMove }), isMobileLikeMode(this._mode) && this._eventDispatcher.unregister("pointerdown", { query: null, callback: this.onMouseMove }); } } //# sourceMappingURL=dimension-hover.js.map