UNPKG

@visactor/vchart

Version:

charts lib based @visactor/VGrammar

65 lines (60 loc) 3.82 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 => { 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) => !(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 => { 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_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