fix: shape for default mindmap node

on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
This commit is contained in:
darshanr0107
2025-08-14 16:31:48 +05:30
parent 91edfa40f7
commit ba9ad9385b
3 changed files with 74 additions and 0 deletions

View File

@@ -235,6 +235,7 @@ export class MindmapDB {
case nodeType.HEXAGON:
return 'hexagon';
case nodeType.DEFAULT:
return 'defaultMindmapNode';
case nodeType.NO_BORDER:
default:
return 'rect';

View File

@@ -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 = <T extends SVGGraphicsElement>(
parent: D3Selection<T>,
@@ -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',

View File

@@ -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<T extends SVGGraphicsElement>(
parent: D3Selection<T>,
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;
}