fix: remove diagram-specific logic from generic rendering utils

on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
This commit is contained in:
darshanr0107
2025-08-28 16:34:07 +05:30
parent 21eddc3f23
commit 65d225cb2c
6 changed files with 15 additions and 20 deletions

View File

@@ -61,14 +61,17 @@ export const draw: DrawDefinition = async (text, id, _version, diagObj) => {
return; return;
} }
data4Layout.nodes.forEach((node) => { data4Layout.nodes.forEach((node) => {
node.from = 'mindmap';
if (node.shape === 'rounded') { if (node.shape === 'rounded') {
node.radius = 15; node.radius = 15;
node.taper = 15; node.taper = 15;
node.stroke = 'none'; node.stroke = 'none';
node.width = 0;
node.padding = 15;
} else if (node.shape === 'circle') {
node.padding = 10;
} else if (node.shape === 'rect') { } else if (node.shape === 'rect') {
node.height = 46; node.width = 0;
node.width = 92; node.padding = 10;
} }
}); });
// Use the unified rendering system // Use the unified rendering system

View File

@@ -11,9 +11,8 @@ export async function circle<T extends SVGGraphicsElement>(parent: D3Selection<T
const { labelStyles, nodeStyles } = styles2String(node); const { labelStyles, nodeStyles } = styles2String(node);
node.labelStyle = labelStyles; node.labelStyle = labelStyles;
const { shapeSvg, bbox, halfPadding } = await labelHelper(parent, node, getNodeClasses(node)); const { shapeSvg, bbox, halfPadding } = await labelHelper(parent, node, getNodeClasses(node));
const padding = node.padding ?? halfPadding;
const radius = const radius = bbox.width / 2 + padding;
node.from === 'mindmap' ? bbox.width / 2 + halfPadding * 2 : bbox.width / 2 + halfPadding;
let circleElem; let circleElem;
const { cssStyles } = node; const { cssStyles } = node;

View File

@@ -19,10 +19,7 @@ export async function drawRect<T extends SVGGraphicsElement>(
const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node)); const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node));
const totalWidth = Math.max(bbox.width + options.labelPaddingX * 2, node?.width || 0); const totalWidth = Math.max(bbox.width + options.labelPaddingX * 2, node?.width || 0);
const totalHeight = Math.max( const totalHeight = Math.max(bbox.height + options.labelPaddingY * 2, node?.height || 0);
bbox.height + (node.from === 'mindmap' ? options.labelPaddingY : options.labelPaddingY * 2),
node?.height || 0
);
const x = -totalWidth / 2; const x = -totalWidth / 2;
const y = -totalHeight / 2; const y = -totalHeight / 2;

View File

@@ -95,15 +95,9 @@ export async function roundedRect<T extends SVGGraphicsElement>(
const labelPaddingX = node?.padding ?? 0; const labelPaddingX = node?.padding ?? 0;
const labelPaddingY = node?.padding ?? 0; const labelPaddingY = node?.padding ?? 0;
let w;
let h; const w = (node?.width ? node?.width : bbox.width) + labelPaddingX * 2;
if (node.from === 'mindmap') { const h = (node?.height ? node?.height : bbox.height) + labelPaddingY * 2;
w = bbox.width + labelPaddingX * 2;
h = bbox.height + labelPaddingY;
} else {
w = (node?.width ? node?.width : bbox.width) + labelPaddingX * 2;
h = (node?.height ? node?.height : bbox.height) + labelPaddingY * 2;
}
const radius = node.radius || 5; const radius = node.radius || 5;
const taper = node.taper || 5; // Taper width for the rounded corners const taper = node.taper || 5; // Taper width for the rounded corners
const { cssStyles } = node; const { cssStyles } = node;

View File

@@ -7,7 +7,7 @@ export async function squareRect<T extends SVGGraphicsElement>(parent: D3Selecti
rx: 0, rx: 0,
ry: 0, ry: 0,
classes: '', classes: '',
labelPaddingX: node.from === 'mindmap' ? (node?.padding || 0) * 1 : (node?.padding || 0) * 2, labelPaddingX: node.labelPaddingX ?? (node?.padding || 0) * 2,
labelPaddingY: (node?.padding || 0) * 1, labelPaddingY: (node?.padding || 0) * 1,
} as RectOptions; } as RectOptions;
return drawRect(parent, node, options); return drawRect(parent, node, options);

View File

@@ -60,6 +60,8 @@ interface BaseNode {
borderStyle?: string; borderStyle?: string;
borderWidth?: number; borderWidth?: number;
labelTextColor?: string; labelTextColor?: string;
labelPaddingX?: number;
labelPaddingY?: number;
// Flowchart specific properties // Flowchart specific properties
x?: number; x?: number;