UNPKG

@visactor/vchart

Version:

charts lib based @visactor/VGrammar

53 lines (46 loc) 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.registerElementActive = exports.ElementActive = void 0; const factory_1 = require("../../core/factory"), base_1 = require("./base"), interface_1 = require("../../compile/mark/interface"), defaultOptions = { state: interface_1.STATE_VALUE_ENUM.STATE_ACTIVE, trigger: "pointerover", triggerOff: "pointerout" }; class ElementActive extends base_1.BaseTrigger { constructor(options) { super(options), this.type = "element-active", this.handleStart = e => { this.start(e.item); }, this.handleReset = e => { this.reset(e.item); }, this.options = Object.assign({}, defaultOptions, options), this.updateMarkIdByState([ this.options.state ]); } getEvents() { return [ { type: this.options.trigger, handler: this.handleStart }, { type: this.options.triggerOff, handler: this.handleReset } ]; } getStartState() { return this.options.state; } start(g) { if (g) { const {state: state, interaction: interaction} = this.options; this.isGraphicInStateMark(g, state) && (g.addState(state, !0), interaction.setStatedGraphics(this, [ g ])); } } reset(graphic) { const {interaction: interaction, state: state} = this.options, statedGraphics = interaction.getStatedGraphics(this), g = null != graphic ? graphic : null == statedGraphics ? void 0 : statedGraphics[0]; g && statedGraphics.includes(g) && (g.removeState(state), interaction.setStatedGraphics(this, statedGraphics.filter((sg => sg !== g)))); } } exports.ElementActive = ElementActive, ElementActive.type = "element-active", ElementActive.defaultOptions = defaultOptions; const registerElementActive = () => { factory_1.Factory.registerInteractionTrigger(ElementActive.type, ElementActive); }; exports.registerElementActive = registerElementActive; //# sourceMappingURL=element-active.js.map