diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/hourglass.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/hourglass.ts index e8407df0e..503a452c3 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/hourglass.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/hourglass.ts @@ -14,8 +14,8 @@ export const hourglass = async (parent: SVGAElement, node: Node) => { node.labelStyle = labelStyles; const { shapeSvg } = await labelHelper(parent, node, getNodeClasses(node)); - const w = 100; - const h = 100; + const w = Math.max(30, node?.width ?? 0); + const h = Math.max(30, node?.height ?? 0); const { cssStyles } = node; diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/lightningBolt.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/lightningBolt.ts index 75f5b7b20..ca6065572 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/lightningBolt.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/lightningBolt.ts @@ -19,9 +19,9 @@ export const lightningBolt = (parent: SVG, node: Node) => { .attr('class', getNodeClasses(node)) .attr('id', node.domId ?? node.id); const { cssStyles } = node; - const height = 80; - const width = 80; - const gap = 16; + const width = Math.max(35, node?.width ?? 0); + const height = Math.max(35, node?.height ?? 0); + const gap = 7; const points = [ { x: width, y: 0 }, diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/linedCylinder.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/linedCylinder.ts index 25fffbf9c..04f403e6a 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/linedCylinder.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/linedCylinder.ts @@ -97,7 +97,7 @@ export const linedCylinder = async (parent: SVGAElement, node: Node) => { Math.abs(pos.y - (node.y ?? 0)) > (node.height ?? 0) / 2 - ry)) ) { let y = ry * ry * (1 - (x * x) / (rx * rx)); - if (y != 0) { + if (y > 0) { y = Math.sqrt(y); } y = ry - y; diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/trapezoidalPentagon.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/trapezoidalPentagon.ts index b9f97f349..ae729debc 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/trapezoidalPentagon.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/trapezoidalPentagon.ts @@ -11,9 +11,10 @@ export const trapezoidalPentagon = async (parent: SVGAElement, node: Node) => { const { labelStyles, nodeStyles } = styles2String(node); node.labelStyle = labelStyles; const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node)); - const widthMultiplier = bbox.width < 40 ? 3 : 1.25; - const w = (bbox.width + node.padding) * widthMultiplier; - const h = bbox.height + node.padding; + const minWidth = 60, + minHeight = 20; + const w = Math.max(minWidth, bbox.width + (node.padding ?? 0) * 2, node?.width ?? 0); + const h = Math.max(minHeight, bbox.height + (node.padding ?? 0) * 2, node?.height ?? 0); const { cssStyles } = node; // @ts-ignore - rough is not typed @@ -25,16 +26,13 @@ export const trapezoidalPentagon = async (parent: SVGAElement, node: Node) => { options.fillStyle = 'solid'; } - const topOffset = 30; - const slopeHeight = 15; - const points = [ - { x: topOffset, y: 0 }, - { x: w - topOffset, y: 0 }, - { x: w, y: slopeHeight }, - { x: w, y: h }, - { x: 0, y: h }, - { x: 0, y: slopeHeight }, + { x: (-w / 2) * 0.8, y: -h / 2 }, + { x: (w / 2) * 0.8, y: -h / 2 }, + { x: w / 2, y: (-h / 2) * 0.6 }, + { x: w / 2, y: h / 2 }, + { x: -w / 2, y: h / 2 }, + { x: -w / 2, y: (-h / 2) * 0.6 }, ]; const pathData = createPathFromPoints(points); @@ -51,8 +49,6 @@ export const trapezoidalPentagon = async (parent: SVGAElement, node: Node) => { polygon.selectChildren('path').attr('style', nodeStyles); } - polygon.attr('transform', `translate(${-w / 2}, ${-h / 2})`); - updateNodeBounds(node, polygon); node.intersect = function (point) {