diff --git a/packages/mermaid/src/diagrams/mindmap/mindmapDb.ts b/packages/mermaid/src/diagrams/mindmap/mindmapDb.ts index 92426a7bb..66259157e 100644 --- a/packages/mermaid/src/diagrams/mindmap/mindmapDb.ts +++ b/packages/mermaid/src/diagrams/mindmap/mindmapDb.ts @@ -235,6 +235,7 @@ export class MindmapDB { case nodeType.HEXAGON: return 'hexagon'; case nodeType.DEFAULT: + return 'defaultMindmapNode'; case nodeType.NO_BORDER: default: return 'rect'; diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes.ts index 2a25ba559..c4d5f04a6 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes.ts @@ -63,6 +63,7 @@ import { requirementBox } from './shapes/requirementBox.js'; import { kanbanItem } from './shapes/kanbanItem.js'; import { bang } from './shapes/bang.js'; import { cloud } from './shapes/cloud.js'; +import { defaultMindmapNode } from './shapes/defaultMindmapNode.js'; type ShapeHandler = ( parent: D3Selection, @@ -145,6 +146,14 @@ export const shapesDefs = [ aliases: ['bang'], handler: bang, }, + { + semanticName: 'Default Mindmap Node', + name: 'defaultMindmapNode', + shortName: 'default-mindmap', + description: 'defaultMindmapNode', + aliases: ['default-mindmap', 'defaultMindmapNode'], + handler: defaultMindmapNode, + }, { semanticName: 'Cloud', name: 'Cloud', diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/defaultMindmapNode.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/defaultMindmapNode.ts new file mode 100644 index 000000000..f30c80844 --- /dev/null +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/defaultMindmapNode.ts @@ -0,0 +1,64 @@ +import type { Bounds, D3Selection, Point } from '../../../types.js'; +import type { Node } from '../../types.js'; +import intersect from '../intersect/index.js'; +import { styles2String } from './handDrawnShapeStyles.js'; +import { getNodeClasses, labelHelper, updateNodeBounds } from './util.js'; + +export async function defaultMindmapNode( + parent: D3Selection, + node: Node +) { + const { labelStyles, nodeStyles } = styles2String(node); + node.labelStyle = labelStyles; + + const { shapeSvg, bbox, halfPadding, label } = await labelHelper( + parent, + node, + getNodeClasses(node) + ); + + const w = bbox.width + 8 * halfPadding; + const h = bbox.height + 2 * halfPadding; + const rd = 5; + + const rectPath = ` + M${-w / 2} ${h / 2 - rd} + v${-h + 2 * rd} + q0,-${rd} ${rd},-${rd} + h${w - 2 * rd} + q${rd},0 ${rd},${rd} + v${h - 2 * rd} + q0,${rd} -${rd},${rd} + h${-w + 2 * rd} + q-${rd},0 -${rd},-${rd} + Z + `; + + const bg = shapeSvg + .append('path') + .attr('id', 'node-' + node.id) + .attr('class', 'node-bkg node-' + node.type) + .attr('style', nodeStyles) + .attr('d', rectPath); + + shapeSvg + .append('line') + .attr('class', 'node-line-') + .attr('x1', -w / 2) + .attr('y1', h / 2) + .attr('x2', w / 2) + .attr('y2', h / 2); + + label.attr('transform', `translate(${-bbox.width / 2}, ${-bbox.height / 2})`); + shapeSvg.append(() => label.node()); + + updateNodeBounds(node, bg); + node.calcIntersect = function (bounds: Bounds, point: Point) { + return intersect.rect(bounds, point); + }; + node.intersect = function (point) { + return intersect.rect(node, point); + }; + + return shapeSvg; +}