mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-22 08:50:13 +02:00
fix: remove diagram-specific logic from generic rendering utils
on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
This commit is contained in:
@@ -61,14 +61,17 @@ export const draw: DrawDefinition = async (text, id, _version, diagObj) => {
|
||||
return;
|
||||
}
|
||||
data4Layout.nodes.forEach((node) => {
|
||||
node.from = 'mindmap';
|
||||
if (node.shape === 'rounded') {
|
||||
node.radius = 15;
|
||||
node.taper = 15;
|
||||
node.stroke = 'none';
|
||||
node.width = 0;
|
||||
node.padding = 15;
|
||||
} else if (node.shape === 'circle') {
|
||||
node.padding = 10;
|
||||
} else if (node.shape === 'rect') {
|
||||
node.height = 46;
|
||||
node.width = 92;
|
||||
node.width = 0;
|
||||
node.padding = 10;
|
||||
}
|
||||
});
|
||||
// Use the unified rendering system
|
||||
|
@@ -11,9 +11,8 @@ export async function circle<T extends SVGGraphicsElement>(parent: D3Selection<T
|
||||
const { labelStyles, nodeStyles } = styles2String(node);
|
||||
node.labelStyle = labelStyles;
|
||||
const { shapeSvg, bbox, halfPadding } = await labelHelper(parent, node, getNodeClasses(node));
|
||||
|
||||
const radius =
|
||||
node.from === 'mindmap' ? bbox.width / 2 + halfPadding * 2 : bbox.width / 2 + halfPadding;
|
||||
const padding = node.padding ?? halfPadding;
|
||||
const radius = bbox.width / 2 + padding;
|
||||
let circleElem;
|
||||
const { cssStyles } = node;
|
||||
|
||||
|
@@ -19,10 +19,7 @@ export async function drawRect<T extends SVGGraphicsElement>(
|
||||
const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node));
|
||||
|
||||
const totalWidth = Math.max(bbox.width + options.labelPaddingX * 2, node?.width || 0);
|
||||
const totalHeight = Math.max(
|
||||
bbox.height + (node.from === 'mindmap' ? options.labelPaddingY : options.labelPaddingY * 2),
|
||||
node?.height || 0
|
||||
);
|
||||
const totalHeight = Math.max(bbox.height + options.labelPaddingY * 2, node?.height || 0);
|
||||
const x = -totalWidth / 2;
|
||||
const y = -totalHeight / 2;
|
||||
|
||||
|
@@ -95,15 +95,9 @@ export async function roundedRect<T extends SVGGraphicsElement>(
|
||||
|
||||
const labelPaddingX = node?.padding ?? 0;
|
||||
const labelPaddingY = node?.padding ?? 0;
|
||||
let w;
|
||||
let h;
|
||||
if (node.from === 'mindmap') {
|
||||
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 w = (node?.width ? node?.width : bbox.width) + labelPaddingX * 2;
|
||||
const h = (node?.height ? node?.height : bbox.height) + labelPaddingY * 2;
|
||||
const radius = node.radius || 5;
|
||||
const taper = node.taper || 5; // Taper width for the rounded corners
|
||||
const { cssStyles } = node;
|
||||
|
@@ -7,7 +7,7 @@ export async function squareRect<T extends SVGGraphicsElement>(parent: D3Selecti
|
||||
rx: 0,
|
||||
ry: 0,
|
||||
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,
|
||||
} as RectOptions;
|
||||
return drawRect(parent, node, options);
|
||||
|
@@ -60,6 +60,8 @@ interface BaseNode {
|
||||
borderStyle?: string;
|
||||
borderWidth?: number;
|
||||
labelTextColor?: string;
|
||||
labelPaddingX?: number;
|
||||
labelPaddingY?: number;
|
||||
|
||||
// Flowchart specific properties
|
||||
x?: number;
|
||||
|
Reference in New Issue
Block a user