@visactor/vtable-gantt
Version:
canvas table width high performance
66 lines (62 loc) • 4.04 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.GanttTaskBarNode = void 0;
const vrender_1 = require("@visactor/vtable/es/vrender"), gantt_helper_1 = require("../gantt-helper"), util_1 = require("../tools/util"), vutils_1 = require("@visactor/vutils"), vtable_1 = require("@visactor/vtable");
class GanttTaskBarNode extends vrender_1.Group {
constructor(attrs) {
super(attrs), this._lastWidth = attrs.width, this._lastHeight = attrs.height, this._lastX = attrs.x,
this._lastY = attrs.y;
}
updateTextPosition() {
var _a, _b, _c;
if (!this.textLabel || !this.barRect) return;
const labelStyle = this.labelStyle || {}, {textAlign: textAlign = "left", textBaseline: textBaseline = "middle", textOverflow: textOverflow, color: color = "#333333", outsideColor: outsideColor = "#333333", padding: rawPadding = 8} = labelStyle, padding = Array.isArray(rawPadding) ? rawPadding[3] : rawPadding, barWidth = this.barRect.attribute.width, barHeight = this.barRect.attribute.height, fontSize = this.textLabel.attribute.fontSize || 12, fontFamily = this.textLabel.attribute.fontFamily || "Arial", text = String(this.textLabel.attribute.text || ""), textFitsInBar = vtable_1.textMeasure.measureTextWidth(text, {
fontSize: fontSize,
fontFamily: fontFamily
}) + 2 * padding <= barWidth, defaultPosition = (0, gantt_helper_1.getTextPos)((0,
util_1.toBoxArray)(padding), textAlign, textBaseline, barWidth, barHeight), textPosition = labelStyle.orient || (!textFitsInBar && labelStyle.orientHandleWithOverflow ? labelStyle.orientHandleWithOverflow : null);
if (this.textLabel.setAttribute("visible", !0), this.textLabel.setAttribute("textBaseline", textBaseline),
textPosition) {
null === (_a = this.textLabel.parent) || void 0 === _a || _a.removeChild(this.textLabel),
this.appendChild(this.textLabel), this.textLabel.setAttribute("fill", outsideColor),
this.textLabel.setAttribute("ellipsis", void 0), this.textLabel.setAttribute("maxLineWidth", void 0),
this.textLabel.setAttribute("zIndex", 1e4), this.setAttribute("zIndex", 1e4);
const pos = {
left: {
x: -padding,
y: barHeight / 2,
align: "right",
baseline: "middle"
},
right: {
x: barWidth + padding,
y: barHeight / 2,
align: "left",
baseline: "middle"
},
top: {
x: barWidth / 2,
y: -padding,
align: "center",
baseline: "bottom"
},
bottom: {
x: barWidth / 2,
y: barHeight + padding,
align: "center",
baseline: "top"
}
}[textPosition];
pos && (this.textLabel.setAttribute("x", pos.x), this.textLabel.setAttribute("y", pos.y),
this.textLabel.setAttribute("textAlign", pos.align), this.textLabel.setAttribute("textBaseline", pos.baseline));
} else null === (_b = this.textLabel.parent) || void 0 === _b || _b.removeChild(this.textLabel),
null === (_c = this.clipGroupBox) || void 0 === _c || _c.appendChild(this.textLabel),
this.textLabel.setAttribute("x", defaultPosition.x), this.textLabel.setAttribute("y", defaultPosition.y),
this.textLabel.setAttribute("textAlign", textAlign), this.textLabel.setAttribute("fill", color),
this.textLabel.setAttribute("maxLineWidth", barWidth - padding), this.textLabel.setAttribute("ellipsis", "clip" === textOverflow ? "" : "ellipsis" === textOverflow ? "..." : (0,
vutils_1.isValid)(textOverflow) ? textOverflow : void 0);
}
}
exports.GanttTaskBarNode = GanttTaskBarNode;
//# sourceMappingURL=gantt-node.js.map