@visactor/vrender-components
Version:
components library for dp visualization
59 lines (53 loc) • 2.73 kB
JavaScript
import { isValid, normalizePadding } from "@visactor/vutils";
import { graphicCreator } from "@visactor/vrender-core";
import { AbstractComponent } from "../core/base";
import { Tag } from "../tag";
import { LEGEND_ELEMENT_NAME } from "./constant";
export class LegendBase extends AbstractComponent {
constructor() {
super(...arguments), this.name = "legend", this._title = null;
}
render() {
this.removeAllChild(!0);
const {interactive: interactive = !0, title: title, padding: padding = 0} = this.attribute;
this._parsedPadding = normalizePadding(padding);
const innerView = graphicCreator.group({
x: this._parsedPadding[3],
y: this._parsedPadding[0],
pickable: interactive,
childrenPickable: interactive
});
innerView.name = LEGEND_ELEMENT_NAME.innerView, this.add(innerView), this._innerView = innerView,
(null == title ? void 0 : title.visible) && this._renderTitle(title), this._renderContent(),
this._adjustLayout(), interactive && this._bindEvents();
const viewBounds = this._innerView.AABBBounds;
this.attribute.width = viewBounds.width() + this._parsedPadding[1] + this._parsedPadding[3],
this.attribute.height = viewBounds.height() + this._parsedPadding[0] + this._parsedPadding[2];
}
_renderTitle(title) {
const {text: text = "", textStyle: textStyle, padding: padding = 0, background: background, minWidth: minWidth, maxWidth: maxWidth, shape: shape} = title, tagAttrs = {
x: 0,
y: 0,
text: text,
textStyle: textStyle,
padding: normalizePadding(padding),
minWidth: minWidth,
maxWidth: maxWidth
};
shape && shape.visible && (tagAttrs.shape = Object.assign({
visible: !0
}, shape.style), isValid(shape.space) && (tagAttrs.space = shape.space)), background && background.visible && (tagAttrs.panel = Object.assign({
visible: !0
}, background.style));
const titleTag = new Tag(tagAttrs);
titleTag.name = LEGEND_ELEMENT_NAME.title, this._title = titleTag, this._innerView.add(titleTag);
}
_adjustLayout() {
var _a;
if (this._title) {
const innerViewWidth = this._innerView.AABBBounds.width(), titleWidth = this._title.AABBBounds.width(), align = null === (_a = this.attribute.title) || void 0 === _a ? void 0 : _a.align;
"center" === align ? this._title.setAttribute("x", (innerViewWidth - titleWidth) / 2) : "end" === align && this._title.setAttribute("x", innerViewWidth - titleWidth);
}
}
}
//# sourceMappingURL=base.js.map