@visactor/vchart
Version:
charts lib based @visactor/VGrammar
51 lines (44 loc) • 1.83 kB
JavaScript
import { Factory } from "../../core/factory";
import { BaseTrigger } from "./base";
import { STATE_VALUE_ENUM } from "../../compile/mark/interface";
const defaultOptions = {
state: STATE_VALUE_ENUM.STATE_ACTIVE,
trigger: "pointerover",
triggerOff: "pointerout"
};
export class ElementActive extends 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))));
}
}
ElementActive.type = "element-active", ElementActive.defaultOptions = defaultOptions;
export const registerElementActive = () => {
Factory.registerInteractionTrigger(ElementActive.type, ElementActive);
};
//# sourceMappingURL=element-active.js.map