Fixed sizing of diamond shape

This commit is contained in:
Knut Sveidqvist
2024-10-03 07:59:55 +02:00
parent 31c01b1795
commit b52b54086e
3 changed files with 8 additions and 8 deletions

View File

@@ -18,8 +18,9 @@ function applyStyle(dom, styleFn) {
}
}
async function addHtmlSpan(element, node, width, classes, addBackground = false) {
async function addHtmlSpan(element, node, _width, classes, addBackground = false) {
const fo = element.append('foreignObject');
const width = _width < 0 ? 0 : _width;
// This is not the final width but used in order to make sure the foreign
// object in firefox gets a width at all. The final width is fetched from the div
fo.attr('width', `${10 * width}px`);

View File

@@ -21,15 +21,15 @@ export const question = async (parent: SVGAElement, node: Node): Promise<SVGAEle
node.labelStyle = labelStyles;
const padding = node.padding ?? 0;
if (node.width || node.height) {
node.width = (node?.width ?? 0) - padding * 8;
if (node.width < 10) {
if ((node.width ?? 10) < 10) {
node.width = 10;
}
node.width = (node?.width ?? 0) - padding * 8;
node.height = (node?.height ?? 0) - padding * 8;
if (node.height < 10) {
if ((node.height ?? 10) < 10) {
node.height = 10;
}
node.height = (node?.height ?? 0) - padding * 8;
}
const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node));

View File

@@ -34,7 +34,7 @@ export const labelHelper = async (parent, node, _classes) => {
let text;
text = await createText(labelEl, sanitizeText(decodeEntities(label), getConfig()), {
useHtmlLabels,
width: node.width || getConfig().flowchart.wrappingWidth,
width: node.width < 0 ? 0 : node.width || getConfig().flowchart.wrappingWidth,
cssClasses: 'markdown-node-label',
style: node.labelStyle,
addSvgBackground: !!node.icon || !!node.img,
@@ -88,11 +88,10 @@ export const labelHelper = async (parent, node, _classes) => {
)
);
}
bbox = div.getBoundingClientRect();
dv.attr('width', bbox.width);
if (node.height && node.height < bbox.height) {
bbox.height = node.height;
bbox.height = node.height < 0 ? 0 : node.height;
}
dv.attr('height', bbox.height);
}