@visactor/vgrammar-core
Version:
VGrammar is a visual grammar library
60 lines (55 loc) • 2.64 kB
JavaScript
import { AABBBounds, throttle } from "@visactor/vutils";
import { BaseTooltip, generateTooltipAttributes } from "./base-tooltip";
import { invokeFunctionType } from "../parse/util";
export class Tooltip extends BaseTooltip {
constructor(view, options) {
super(view, options), this.type = Tooltip.type, this.handleTooltipShow = throttle((event => {
if (!this._tooltipComponent) return;
const element = event.element;
if (!this._marks.includes(null == element ? void 0 : element.mark)) return void this._tooltipComponent.hideAll();
this._tooltipComponent.showAll();
const groupGraphicItem = this.view.rootMark.getGroupGraphicItem(), point = {
x: 0,
y: 0
};
if (groupGraphicItem.globalTransMatrix.transformPoint(event.canvas, point), element === this._lastElement) return void this._tooltipComponent.setAttributes({
pointerX: point.x,
pointerY: point.y
});
const boundsStart = {
x: 0,
y: 0
};
groupGraphicItem.globalTransMatrix.transformPoint({
x: 0,
y: 0
}, boundsStart);
const boundsEnd = {
x: 0,
y: 0
};
groupGraphicItem.globalTransMatrix.transformPoint({
x: this.view.getSignalById("width").getValue(),
y: this.view.getSignalById("height").getValue()
}, boundsEnd);
const bounds = (new AABBBounds).set(boundsStart.x, boundsStart.y, boundsEnd.x, boundsEnd.y), {title: title, content: content} = this._computeTitleContent(element.getDatum()), theme = this.view.getCurrentTheme(), addition = invokeFunctionType(this.options.attributes, this.parameters(), element.getDatum()), attributes = generateTooltipAttributes(point, title, content, bounds, theme, addition);
this._tooltipComponent.setAttributes(attributes);
}), 10), this.handleTooltipHide = event => {
this._tooltipComponent && this._tooltipComponent.hideAll();
}, this.options = Object.assign({}, Tooltip.defaultOptions, options);
}
getEvents() {
return [ {
type: this.options.trigger,
handler: this.handleTooltipShow
}, {
type: this.options.triggerOff,
handler: this.handleTooltipHide
} ];
}
}
Tooltip.type = "tooltip", Tooltip.defaultOptions = {
trigger: "pointermove",
triggerOff: "pointerleave"
};
//# sourceMappingURL=tooltip.js.map