@visactor/vrender-components
Version:
components library for dp visualization
66 lines (62 loc) • 2.54 kB
JavaScript
import { Generator } from "@visactor/vrender-core";
export class PopTipPluginBase {
constructor() {
this.activeEvent = "onRegister", this._uid = Generator.GenAutoIncrementId(), this.poptip = e => {
const graphic = e.target;
this.needHide(graphic) ? this.unpoptip(e) : graphic !== this.activeGraphic && (this.needShow(graphic) && (graphic.setAttributes({}),
graphic._showPoptip = 1), this.activeGraphic && (this.activeGraphic.setAttributes({}),
this.activeGraphic._showPoptip = 2), this.setActiveGraphic(graphic, !0));
}, this.unpoptip = e => {
this.activeGraphic && (this.activeGraphic.setAttributes({}), this.activeGraphic._showPoptip = 2,
this.setActiveGraphic(null, !0));
};
}
activate(context) {
this.pluginService = context;
const {stage: stage} = this.pluginService;
stage.addEventListener("pointerover", this.poptip);
}
needHide(graphic) {
return graphic.isContainer || !graphic.attribute;
}
needShow(graphic) {
return !!graphic.attribute.poptip;
}
setActiveGraphic(graphic, rerender) {
this.activeGraphic = graphic, this.pluginService.stage.renderNextFrame();
}
deactivate(context) {
const {stage: stage} = this.pluginService;
stage.removeEventListener("pointerover", this.poptip);
}
}
export class PopTipPlugin extends PopTipPluginBase {
constructor() {
super(...arguments), this.name = "poptip", this.key = this.name + this._uid;
}
}
export class PopTipForClipedTextPlugin extends PopTipPluginBase {
constructor() {
super(...arguments), this.name = "poptipForText", this.key = this.name + this._uid,
this.pointerlave = e => {
const {stage: stage} = this.pluginService;
e.target === stage && this.unpoptip(e);
};
}
activate(context) {
super.activate(context);
const {stage: stage} = this.pluginService;
stage.addEventListener("pointerleave", this.pointerlave);
}
needHide(graphic) {
return "text" !== graphic.type || !graphic.cliped || graphic.isContainer || !graphic.attribute || graphic.attribute.disableAutoClipedPoptip;
}
needShow(graphic) {
return !0;
}
deactivate(context) {
const {stage: stage} = this.pluginService;
super.deactivate(context), stage.removeEventListener("pointerleave", this.pointerlave);
}
}
//# sourceMappingURL=poptip-plugin.js.map