@visactor/vrender-components
Version:
components library for dp visualization
60 lines (55 loc) • 2.91 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.LegendBase = void 0;
const vutils_1 = require("@visactor/vutils"), vrender_core_1 = require("@visactor/vrender-core"), base_1 = require("../core/base"), tag_1 = require("../tag"), constant_1 = require("./constant");
class LegendBase extends base_1.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 = (0, vutils_1.normalizePadding)(padding);
const innerView = vrender_core_1.graphicCreator.group({
x: this._parsedPadding[3],
y: this._parsedPadding[0],
pickable: interactive,
childrenPickable: interactive
});
innerView.name = constant_1.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: (0, vutils_1.normalizePadding)(padding),
minWidth: minWidth,
maxWidth: maxWidth
};
shape && shape.visible && (tagAttrs.shape = Object.assign({
visible: !0
}, shape.style), (0, vutils_1.isValid)(shape.space) && (tagAttrs.space = shape.space)),
background && background.visible && (tagAttrs.panel = Object.assign({
visible: !0
}, background.style));
const titleTag = new tag_1.Tag(tagAttrs);
titleTag.name = constant_1.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);
}
}
}
exports.LegendBase = LegendBase;
//# sourceMappingURL=base.js.map