UNPKG

@visactor/vchart

Version:

charts lib based @visactor/VGrammar

63 lines (58 loc) 3.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.DimensionHoverEvent = void 0; const env_1 = require("../../../util/env"), base_1 = require("./base"), common_1 = require("./util/common"), event_1 = require("../../../constant/event"); class DimensionHoverEvent extends base_1.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) => !(0, common_1.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_1.Event_Source_Type.chart }), callback: this.onMouseMove }), this._eventDispatcher.register("pointerout", { query: Object.assign(Object.assign({}, handler.query), { source: event_1.Event_Source_Type.canvas }), callback: this.onMouseOut }), (0, env_1.isMobileLikeMode)(this._mode) && this._eventDispatcher.register("pointerdown", { query: Object.assign(Object.assign({}, handler.query), { source: event_1.Event_Source_Type.chart }), callback: this.onMouseMove }); } unregister() { this._eventDispatcher.unregister("pointermove", { query: null, callback: this.onMouseMove }), (0, env_1.isMobileLikeMode)(this._mode) && this._eventDispatcher.unregister("pointerdown", { query: null, callback: this.onMouseMove }); } } exports.DimensionHoverEvent = DimensionHoverEvent; //# sourceMappingURL=dimension-hover.js.map