UNPKG

@visactor/vchart

Version:

charts lib based @visactor/VGrammar

62 lines (57 loc) 3.63 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 => { var _a, _b, _c, _d; if (!params || (null === (_d = null === (_c = null === (_b = null === (_a = params.chart) || void 0 === _a ? void 0 : _a.getOption()) || void 0 === _b ? void 0 : _b.globalInstance) || void 0 === _c ? void 0 : _c.disableDimensionHoverEvent) || void 0 === _d ? void 0 : _d.call(_c))) 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 => { var _a, _b, _c, _d; params && !(null === (_d = null === (_c = null === (_b = null === (_a = params.chart) || void 0 === _a ? void 0 : _a.getOption()) || void 0 === _b ? void 0 : _b.globalInstance) || void 0 === _c ? void 0 : _c.disableDimensionHoverEvent) || void 0 === _d ? void 0 : _d.call(_c)) && (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