diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/crossedCircle.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/crossedCircle.ts index f05e2a985..93a69d16f 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/crossedCircle.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/crossedCircle.ts @@ -42,18 +42,17 @@ export const crossedCircle = async (parent: SVGAElement, node: Node) => { const linePath = createLine(radius); const lineNode = rc.path(linePath, options); - const crossedCircle = shapeSvg.insert('g', ':first-child'); - crossedCircle.insert(() => circleNode, ':first-child'); + const crossedCircle = shapeSvg.insert(() => circleNode, ':first-child'); crossedCircle.insert(() => lineNode); crossedCircle.attr('class', 'basic label-container'); - if (cssStyles) { - crossedCircle.attr('style', cssStyles); + if (cssStyles && node.look !== 'handDrawn') { + crossedCircle.selectAll('path').attr('style', cssStyles); } - if (nodeStyles) { - crossedCircle.attr('style', nodeStyles); + if (nodeStyles && node.look !== 'handDrawn') { + crossedCircle.selectAll('path').attr('style', nodeStyles); } updateNodeBounds(node, crossedCircle); diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/curvedTrapezoid.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/curvedTrapezoid.ts index af512870f..e997d5f15 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/curvedTrapezoid.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/curvedTrapezoid.ts @@ -54,11 +54,12 @@ export const curvedTrapezoid = async (parent: SVGAElement, node: Node) => { const polygon = shapeSvg.insert(() => shapeNode, ':first-child'); polygon.attr('class', 'basic label-container'); - if (cssStyles) { - polygon.attr('style', cssStyles); + if (cssStyles && node.look !== 'handDrawn') { + polygon.selectChildren('path').attr('style', cssStyles); } - if (nodeStyles) { - polygon.attr('style', nodeStyles); + + if (nodeStyles && node.look !== 'handDrawn') { + polygon.selectChildren('path').attr('style', nodeStyles); } polygon.attr('transform', `translate(${-w / 2}, ${-h / 2})`); diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/dividedRect.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/dividedRect.ts index aa0b5493b..69bb59237 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/dividedRect.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/dividedRect.ts @@ -7,41 +7,16 @@ import { } from '$root/rendering-util/rendering-elements/shapes/handDrawnShapeStyles.js'; import rough from 'roughjs'; -export function createDividedRectPathD( - x: number, - y: number, - totalWidth: number, - totalHeight: number -) { - const w = totalWidth; - const firstRectHeight = totalHeight * 0.3; - const secondRectHeight = totalHeight * 0.6 + firstRectHeight; - - const rect1stPoints = [ - { x: x, y }, - { x: x + w, y }, - { x: x + w, y: y + firstRectHeight }, - { x: x, y: y + firstRectHeight }, - ]; - - const rect2ndPoints = [ - { x: x, y: y + firstRectHeight }, - { x: x + w, y: y + firstRectHeight }, - { x: x + w, y: y + firstRectHeight + secondRectHeight }, - { x: x, y: y + firstRectHeight + secondRectHeight }, - ]; - const rect1stPath = createPathFromPoints(rect1stPoints); - const rect2ndPath = createPathFromPoints(rect2ndPoints); - const finalPath = `${rect1stPath} ${rect2ndPath}`; - return finalPath; -} - export const dividedRect = async (parent: SVGAElement, node: Node) => { const { labelStyles, nodeStyles } = styles2String(node); node.labelStyle = labelStyles; - const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node)); + const { shapeSvg, bbox, label } = await labelHelper(parent, node, getNodeClasses(node)); const w = bbox.width + node.padding; const h = bbox.height + node.padding; + const rectOffset = h * 0.2; + + const x = -w / 2; + const y = -h / 2 - rectOffset / 2; const { cssStyles } = node; @@ -52,25 +27,43 @@ export const dividedRect = async (parent: SVGAElement, node: Node) => { options.roughness = 0; options.fillStyle = 'solid'; } - const pathData = createDividedRectPathD(0, 0, w, h); - const shapeNode = rc.path(pathData, options); - const polygon = shapeSvg.insert(() => shapeNode, ':first-child'); + const outerPathPoints = [ + { x, y: y }, + { x, y: -y }, + { x: -x, y: -y }, + { x: -x, y: y }, + ]; + const innerPathPoints = [ + { x: x, y: y + rectOffset }, + { x: -x, y: y + rectOffset }, + ]; + const outerPathData = createPathFromPoints(outerPathPoints); + const outerNode = rc.path(outerPathData, options); + const innerPathData = createPathFromPoints(innerPathPoints); + const innerNode = rc.path(innerPathData, options); + + const polygon = shapeSvg.insert(() => outerNode, ':first-child'); + polygon.insert(() => innerNode); polygon.attr('class', 'basic label-container'); - if (cssStyles) { - polygon.attr('style', cssStyles); - } - if (nodeStyles) { - polygon.attr('style', nodeStyles); + if (cssStyles && node.look !== 'handDrawn') { + polygon.selectAll('path').attr('style', cssStyles); } - polygon.attr('transform', `translate(${-w / 2}, ${-h / 1.3})`); + if (nodeStyles && node.look !== 'handDrawn') { + polygon.selectAll('path').attr('style', nodeStyles); + } + + label.attr( + 'transform', + `translate(${x + (node.padding ?? 0) / 2}, ${y + rectOffset + (node.padding ?? 0) / 2})` + ); updateNodeBounds(node, polygon); node.intersect = function (point) { - const pos = intersect.polygon(node, point); + const pos = intersect.polygon(node, outerPathPoints, point); return pos; }; diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/filledCircle.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/filledCircle.ts index a7fdd9c23..5a2888ebe 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/filledCircle.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/filledCircle.ts @@ -27,17 +27,16 @@ export const filledCircle = async (parent: SVGAElement, node: Node) => { const circleNode = rc.circle(0, 0, radius * 2, options); - const filledCircle = shapeSvg.insert('g', ':first-child'); - filledCircle.insert(() => circleNode, ':first-child'); + const filledCircle = shapeSvg.insert(() => circleNode, ':first-child'); filledCircle.attr('class', 'basic label-container'); - if (cssStyles) { - filledCircle.attr('style', cssStyles); + if (cssStyles && node.look !== 'handDrawn') { + filledCircle.selectAll('path').attr('style', cssStyles); } - if (nodeStyles) { - filledCircle.attr('style', nodeStyles); + if (nodeStyles && node.look !== 'handDrawn') { + filledCircle.selectAll('path').attr('style', nodeStyles); } updateNodeBounds(node, filledCircle); diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/halfRoundedRectangle.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/halfRoundedRectangle.ts index 50d49146f..813748bc8 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/halfRoundedRectangle.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/halfRoundedRectangle.ts @@ -41,12 +41,12 @@ export const halfRoundedRectangle = async (parent: SVGAElement, node: Node) => { const polygon = shapeSvg.insert(() => shapeNode, ':first-child'); polygon.attr('class', 'basic label-container'); - if (cssStyles) { - polygon.attr('style', cssStyles); + if (cssStyles && node.look !== 'handDrawn') { + polygon.selectChildren('path').attr('style', cssStyles); } - if (nodeStyles) { - polygon.attr('style', nodeStyles); + if (nodeStyles && node.look !== 'handDrawn') { + polygon.selectChildren('path').attr('style', nodeStyles); } polygon.attr('transform', `translate(${-rx / 2 - (node.padding ?? 0) * 2}, 0)`); 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 42679f044..e8407df0e 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/hourglass.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/hourglass.ts @@ -40,12 +40,12 @@ export const hourglass = async (parent: SVGAElement, node: Node) => { const polygon = shapeSvg.insert(() => shapeNode, ':first-child'); polygon.attr('class', 'basic label-container'); - if (cssStyles) { - polygon.attr('style', cssStyles); + if (cssStyles && node.look !== 'handDrawn') { + polygon.selectChildren('path').attr('style', cssStyles); } - if (nodeStyles) { - polygon.attr('style', nodeStyles); + if (nodeStyles && node.look !== 'handDrawn') { + polygon.selectChildren('path').attr('style', nodeStyles); } polygon.attr('transform', `translate(${-w / 2}, ${-h / 2})`); 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 d69967b82..48ac31037 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/lightningBolt.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/lightningBolt.ts @@ -40,18 +40,18 @@ export const lightningBolt = async (parent: SVGAElement, node: Node) => { const linePath = createPathFromPoints(points); const lineNode = rc.path(linePath, options); - const lightningBolt = shapeSvg.insert('g', ':first-child'); - lightningBolt.insert(() => lineNode, ':first-child'); + const lightningBolt = shapeSvg.insert(() => lineNode, ':first-child'); lightningBolt.attr('class', 'basic label-container'); - if (cssStyles) { - lightningBolt.attr('style', cssStyles); + if (cssStyles && node.look !== 'handDrawn') { + lightningBolt.selectAll('path').attr('style', cssStyles); } - if (nodeStyles) { - lightningBolt.attr('style', nodeStyles); + if (nodeStyles && node.look !== 'handDrawn') { + lightningBolt.selectAll('path').attr('style', nodeStyles); } + lightningBolt.attr('transform', `translate(-${width / 2},${-height})`); updateNodeBounds(node, lightningBolt); 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 d531c8744..2eb8f3536 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/linedCylinder.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/linedCylinder.ts @@ -42,7 +42,7 @@ export const linedCylinder = async (parent: SVGAElement, node: Node) => { // @ts-ignore - rough is not typed const rc = rough.svg(shapeSvg); const options = userNodeOverrides(node, {}); - const pathData = createCylinderPathWithInnerArcD(0, ry, w, h, rx, ry, outerOffset); + const pathData = createCylinderPathWithInnerArcD(0, 0, w, h, rx, ry, outerOffset); const innerLine = rc.path(pathData, options); cylinder = shapeSvg.insert(() => innerLine, ':first-child'); diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/multiRect.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/multiRect.ts index 9bd90d91a..dbb96a242 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/multiRect.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/multiRect.ts @@ -46,7 +46,7 @@ export const multiRect = async (parent: SVGAElement, node: Node) => { { x, y }, ]; - if (node.look !== 'handdrawn') { + if (node.look !== 'handDrawn') { options.roughness = 0; options.fillStyle = 'solid'; } @@ -56,18 +56,17 @@ export const multiRect = async (parent: SVGAElement, node: Node) => { const innerPath = createPathFromPoints(innerPathPoints); const innerNode = rc.path(innerPath, options); - const taggedRect = shapeSvg.insert('g', ':first-child'); - taggedRect.insert(() => innerNode, ':first-child'); - taggedRect.insert(() => outerNode, ':first-child'); + const multiRect = shapeSvg.insert(() => innerNode, ':first-child'); + multiRect.insert(() => outerNode, ':first-child'); - taggedRect.attr('class', 'basic label-container'); + multiRect.attr('class', 'basic label-container'); - if (cssStyles) { - taggedRect.attr('style', cssStyles); + if (cssStyles && node.look !== 'handDrawn') { + multiRect.selectAll('path').attr('style', cssStyles); } - if (nodeStyles) { - taggedRect.attr('style', nodeStyles); + if (nodeStyles && node.look !== 'handDrawn') { + multiRect.selectAll('path').attr('style', nodeStyles); } label.attr( @@ -75,7 +74,7 @@ export const multiRect = async (parent: SVGAElement, node: Node) => { `translate(${-(bbox.width / 2) - rectOffset}, ${-(bbox.height / 2) + rectOffset})` ); - updateNodeBounds(node, taggedRect); + updateNodeBounds(node, multiRect); node.intersect = function (point) { const pos = intersect.polygon(node, outerPathPoints, point); diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/slopedRect.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/slopedRect.ts index 0003a502f..2745f27cd 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/slopedRect.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/slopedRect.ts @@ -40,12 +40,12 @@ export const slopedRect = async (parent: SVGAElement, node: Node) => { const polygon = shapeSvg.insert(() => shapeNode, ':first-child'); polygon.attr('class', 'basic label-container'); - if (cssStyles) { - polygon.attr('style', cssStyles); + if (cssStyles && node.look !== 'handDrawn') { + polygon.selectChildren('path').attr('style', cssStyles); } - if (nodeStyles) { - polygon.attr('style', nodeStyles); + if (nodeStyles && node.look !== 'handDrawn') { + polygon.selectChildren('path').attr('style', nodeStyles); } polygon.attr('transform', `translate(0, ${h / 4})`); diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/taggedRect.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/taggedRect.ts index c360ea0ca..22419d388 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/taggedRect.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/taggedRect.ts @@ -47,21 +47,22 @@ export const taggedRect = async (parent: SVGAElement, node: Node) => { const tagPath = createPathFromPoints(tagPoints); const tagNode = rc.path(tagPath, options); - const taggedRect = shapeSvg.insert('g', ':first-child'); - taggedRect.insert(() => tagNode, ':first-child'); + const taggedRect = shapeSvg.insert(() => tagNode, ':first-child'); taggedRect.insert(() => rectNode, ':first-child'); taggedRect.attr('class', 'basic label-container'); - if (cssStyles) { - taggedRect.attr('style', cssStyles); + if (cssStyles && node.look !== 'handDrawn') { + taggedRect.selectAll('path').attr('style', cssStyles); } - if (nodeStyles) { - taggedRect.attr('style', nodeStyles); + if (nodeStyles && node.look !== 'handDrawn') { + taggedRect.selectAll('path').attr('style', nodeStyles); } taggedRect.attr('transform', `translate(${tagWidth / 2}, 0)`); + taggedRect.attr('transform', `translate(${tagWidth / 2}, 0)`); + updateNodeBounds(node, taggedRect); node.intersect = function (point) { diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/tiltedCylinder.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/tiltedCylinder.ts index 9a52c9681..ed05a4f6d 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/tiltedCylinder.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/tiltedCylinder.ts @@ -38,17 +38,16 @@ export const tiltedCylinder = async (parent: SVGAElement, node: Node) => { const cylinderPath = createCylinderPathD(rx, ry, w, h); const cylinderNode = rc.path(cylinderPath, options); - const tiltedCylinder = shapeSvg.insert('g', ':first-child'); - tiltedCylinder.insert(() => cylinderNode, ':first-child'); + const tiltedCylinder = shapeSvg.insert(() => cylinderNode, ':first-child'); tiltedCylinder.attr('class', 'basic label-container'); - if (cssStyles) { - tiltedCylinder.attr('style', cssStyles); + if (cssStyles && node.look !== 'handDrawn') { + tiltedCylinder.selectChildren('path').attr('style', cssStyles); } - if (nodeStyles) { - tiltedCylinder.attr('style', nodeStyles); + if (nodeStyles && node.look !== 'handDrawn') { + tiltedCylinder.selectChildren('path').attr('style', nodeStyles); } updateNodeBounds(node, tiltedCylinder); 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 cb548607e..b9f97f349 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/trapezoidalPentagon.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/trapezoidalPentagon.ts @@ -7,21 +7,6 @@ import { } from '$root/rendering-util/rendering-elements/shapes/handDrawnShapeStyles.js'; import rough from 'roughjs'; -function createTrapezoidalPentagonPathD(width = 100, height = 80) { - const topOffset = 30, - slopeHeight = 15; - - const points = [ - { x: topOffset, y: 0 }, - { x: width - topOffset, y: 0 }, - { x: width, y: slopeHeight }, - { x: width, y: height }, - { x: 0, y: height }, - { x: 0, y: slopeHeight }, - ]; - return createPathFromPoints(points); -} - export const trapezoidalPentagon = async (parent: SVGAElement, node: Node) => { const { labelStyles, nodeStyles } = styles2String(node); node.labelStyle = labelStyles; @@ -40,17 +25,30 @@ export const trapezoidalPentagon = async (parent: SVGAElement, node: Node) => { options.fillStyle = 'solid'; } - const pathData = createTrapezoidalPentagonPathD(w, h); + 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 }, + ]; + + const pathData = createPathFromPoints(points); const shapeNode = rc.path(pathData, options); const polygon = shapeSvg.insert(() => shapeNode, ':first-child'); polygon.attr('class', 'basic label-container'); - if (cssStyles) { - polygon.attr('style', cssStyles); + if (cssStyles && node.look !== 'handDrawn') { + polygon.selectChildren('path').attr('style', cssStyles); } - if (nodeStyles) { - polygon.attr('style', nodeStyles); + + if (nodeStyles && node.look !== 'handDrawn') { + polygon.selectChildren('path').attr('style', nodeStyles); } polygon.attr('transform', `translate(${-w / 2}, ${-h / 2})`); @@ -58,7 +56,7 @@ export const trapezoidalPentagon = async (parent: SVGAElement, node: Node) => { updateNodeBounds(node, polygon); node.intersect = function (point) { - const pos = intersect.rect(node, point); + const pos = intersect.polygon(node, points, point); return pos; }; diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/triangle.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/triangle.ts index 1072e10dd..46017523b 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/triangle.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/triangle.ts @@ -40,12 +40,12 @@ export const triangle = async (parent: SVGAElement, node: Node): Promise roughNode, ':first-child') .attr('transform', `translate(${-h / 2}, ${h / 2})`); - if (cssStyles) { - polygon.attr('style', cssStyles); + if (cssStyles && node.look !== 'handDrawn') { + polygon.selectChildren('path').attr('style', cssStyles); } - if (nodeStyles) { - polygon.attr('style', nodeStyles); + if (nodeStyles && node.look !== 'handDrawn') { + polygon.selectChildren('path').attr('style', nodeStyles); } node.width = w; diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/windowPane.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/windowPane.ts index 9d59ff164..610c02177 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/windowPane.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/windowPane.ts @@ -39,7 +39,7 @@ export const windowPane = async (parent: SVGAElement, node: Node) => { { x, y: y + h }, ]; - if (node.look !== 'handdrawn') { + if (node.look !== 'handDrawn') { options.roughness = 0; options.fillStyle = 'solid'; } @@ -51,20 +51,19 @@ export const windowPane = async (parent: SVGAElement, node: Node) => { const innerSecondPath = createPathFromPoints(innerSecondPathPoints); const innerSecondNode = rc.path(innerSecondPath, options); - const windowPane = shapeSvg.insert('g', ':first-child'); - windowPane.insert(() => innerNode, ':first-child'); + const windowPane = shapeSvg.insert(() => innerNode, ':first-child'); windowPane.insert(() => innerSecondNode, ':first-child'); windowPane.insert(() => outerNode, ':first-child'); windowPane.attr('transform', `translate(${rectOffset / 2}, ${rectOffset / 2})`); windowPane.attr('class', 'basic label-container'); - if (cssStyles) { - windowPane.attr('style', cssStyles); + if (cssStyles && node.look !== 'handDrawn') { + windowPane.selectAll('path').attr('style', cssStyles); } - if (nodeStyles) { - windowPane.attr('style', nodeStyles); + if (nodeStyles && node.look !== 'handDrawn') { + windowPane.selectAll('path').attr('style', nodeStyles); } label.attr(