UNPKG

@visactor/vchart

Version:

charts lib based @visactor/VGrammar

74 lines (67 loc) 3.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.registerElementHighlightByGroup = exports.ElementHighlightByGroup = void 0; const factory_1 = require("../../core/factory"), base_1 = require("./base"), vutils_1 = require("@visactor/vutils"), util_1 = require("./util"), type = "element-highlight-by-group"; class ElementHighlightByGroup extends base_1.BaseTrigger { constructor(options) { super(options), this.type = type, this.handleStart = e => { this.start(e.item); }, this.handleReset = e => { const g = e.item; g && this.isGraphicInMark(g) && this.resetAll(); }, this.options = Object.assign({}, util_1.highlightDefaultOptions, options), this.updateMarkIdByState([ this.options.highlightState, this.options.blurState ]); } getStartState() { return this.options.highlightState; } getResetState() { return this.options.blurState; } getEvents() { return [ { type: this.options.trigger, handler: this.handleStart }, { type: this.options.triggerOff, handler: this.handleReset } ]; } resetAll() { const {interaction: interaction, highlightState: highlightState, blurState: blurState} = this.options; interaction.clearAllStatesOfTrigger(this, highlightState, blurState), interaction.setStatedGraphics(this, []); } _getHightlightKey(g) { var _a; return null === (_a = g.context) || void 0 === _a ? void 0 : _a.groupKey; } start(g) { if (g && this.isGraphicInMark(g)) { const highlightKey = this._getHightlightKey(g); if ((0, vutils_1.isNil)(highlightKey)) return; const {interaction: interaction, highlightState: highlightState, blurState: blurState} = this.options, statedGraphics = interaction.getStatedGraphics(this), newStatedGraphics = []; this.getMarks().forEach((m => { var _a; null === (_a = m.getGraphics()) || void 0 === _a || _a.forEach((g => { this._getHightlightKey(g) === highlightKey && newStatedGraphics.push(g); })); })), interaction.updateStates(this, newStatedGraphics, statedGraphics, highlightState, blurState), interaction.setStatedGraphics(this, newStatedGraphics); } } reset(g) { if (g) { if (this.isGraphicInMark(g)) { const {interaction: interaction} = this.options, statedGraphics = interaction.getStatedGraphics(this); g.removeState([ this.options.highlightState, this.options.blurState ]), interaction.setStatedGraphics(this, statedGraphics.filter((sg => sg !== g))); } } else this.resetAll(); } } exports.ElementHighlightByGroup = ElementHighlightByGroup, ElementHighlightByGroup.type = type, ElementHighlightByGroup.defaultOptions = util_1.highlightDefaultOptions; const registerElementHighlightByGroup = () => { factory_1.Factory.registerInteractionTrigger(type, ElementHighlightByGroup); }; exports.registerElementHighlightByGroup = registerElementHighlightByGroup; //# sourceMappingURL=element-highlight-by-group.js.map