mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-16 13:59:54 +02:00
fix: shape for default mindmap node
on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
This commit is contained in:
@@ -235,6 +235,7 @@ export class MindmapDB {
|
|||||||
case nodeType.HEXAGON:
|
case nodeType.HEXAGON:
|
||||||
return 'hexagon';
|
return 'hexagon';
|
||||||
case nodeType.DEFAULT:
|
case nodeType.DEFAULT:
|
||||||
|
return 'defaultMindmapNode';
|
||||||
case nodeType.NO_BORDER:
|
case nodeType.NO_BORDER:
|
||||||
default:
|
default:
|
||||||
return 'rect';
|
return 'rect';
|
||||||
|
@@ -63,6 +63,7 @@ import { requirementBox } from './shapes/requirementBox.js';
|
|||||||
import { kanbanItem } from './shapes/kanbanItem.js';
|
import { kanbanItem } from './shapes/kanbanItem.js';
|
||||||
import { bang } from './shapes/bang.js';
|
import { bang } from './shapes/bang.js';
|
||||||
import { cloud } from './shapes/cloud.js';
|
import { cloud } from './shapes/cloud.js';
|
||||||
|
import { defaultMindmapNode } from './shapes/defaultMindmapNode.js';
|
||||||
|
|
||||||
type ShapeHandler = <T extends SVGGraphicsElement>(
|
type ShapeHandler = <T extends SVGGraphicsElement>(
|
||||||
parent: D3Selection<T>,
|
parent: D3Selection<T>,
|
||||||
@@ -145,6 +146,14 @@ export const shapesDefs = [
|
|||||||
aliases: ['bang'],
|
aliases: ['bang'],
|
||||||
handler: bang,
|
handler: bang,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
semanticName: 'Default Mindmap Node',
|
||||||
|
name: 'defaultMindmapNode',
|
||||||
|
shortName: 'default-mindmap',
|
||||||
|
description: 'defaultMindmapNode',
|
||||||
|
aliases: ['default-mindmap', 'defaultMindmapNode'],
|
||||||
|
handler: defaultMindmapNode,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
semanticName: 'Cloud',
|
semanticName: 'Cloud',
|
||||||
name: 'Cloud',
|
name: 'Cloud',
|
||||||
|
@@ -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;
|
||||||
|
}
|
Reference in New Issue
Block a user