@visactor/vtable
Version:
canvas table width high performance
21 lines (17 loc) • 1.14 kB
JavaScript
import { getProp } from "./get-prop";
import { getQuadProps } from "./padding";
export function getTextPos(padding, textAlign, textBaseline, width, height) {
let textX = padding[3] || 10;
"right" === textAlign || "end" === textAlign ? textX = width - 0 - (padding[1] || 10) : "center" === textAlign && (textX = 0 + (width - 0 + (padding[3] || 10) - (padding[1] || 10)) / 2);
let textY = 0 + (padding[0] || 10);
return "bottom" === textBaseline || "alphabetic" === textBaseline || "ideographic" === textBaseline ? textY = height - 0 - (padding[2] || 10) : "middle" === textBaseline && (textY = 0 + (height - 0 - (padding[0] || 10) - (padding[2] || 10)) / 2 + (padding[0] || 10)),
{
x: textX,
y: textY
};
}
export function updateTextPose(table, cell, col, row, theme) {
const headerStyle = table._getCellStyle(col, row), padding = getQuadProps(getProp("padding", headerStyle, col, row, table));
cell.getChildByName("text").setAttributes(getTextPos(padding, theme.text.textAlign, theme.text.textBaseline, cell.attribute.width, cell.attribute.height));
}
//# sourceMappingURL=text-pos.js.map