diff --git a/packages/mermaid-layout-tidy-tree/src/layout.ts b/packages/mermaid-layout-tidy-tree/src/layout.ts index 0f2e24930..669d65d59 100644 --- a/packages/mermaid-layout-tidy-tree/src/layout.ts +++ b/packages/mermaid-layout-tidy-tree/src/layout.ts @@ -1,12 +1,13 @@ +import type { LayoutData, MermaidConfig } from 'mermaid'; +import type { Bounds, Point } from 'mermaid/src/types.js'; import { BoundingBox, Layout } from 'non-layered-tidy-tree-layout'; -import type { MermaidConfig, LayoutData } from 'mermaid'; import type { - LayoutResult, - TidyTreeNode, - PositionedNode, - PositionedEdge, - Node, Edge, + LayoutResult, + Node, + PositionedEdge, + PositionedNode, + TidyTreeNode, } from './types.js'; /** @@ -46,29 +47,18 @@ export function executeTidyTreeLayout( let leftResult = null; let rightResult = null; - let leftBoundingBox = null; - let rightBoundingBox = null; if (leftTree) { const leftLayoutResult = layout.layout(leftTree); leftResult = leftLayoutResult.result; - leftBoundingBox = leftLayoutResult.boundingBox; } if (rightTree) { const rightLayoutResult = layout.layout(rightTree); rightResult = rightLayoutResult.result; - rightBoundingBox = rightLayoutResult.boundingBox; } - const positionedNodes = combineAndPositionTrees( - rootNode, - leftResult, - rightResult, - leftBoundingBox, - rightBoundingBox, - data - ); + const positionedNodes = combineAndPositionTrees(rootNode, leftResult, rightResult); const positionedEdges = calculateEdgePositions( data.edges, positionedNodes, @@ -202,10 +192,7 @@ function convertNodeToTidyTreeTransposed( function combineAndPositionTrees( rootNode: TidyTreeNode, leftResult: TidyTreeNode | null, - rightResult: TidyTreeNode | null, - _leftBoundingBox: any, - _rightBoundingBox: any, - _data: LayoutData + rightResult: TidyTreeNode | null ): PositionedNode[] { const positionedNodes: PositionedNode[] = []; @@ -383,9 +370,9 @@ function positionRightTreeBidirectional( * @returns The intersection point */ function computeCircleEdgeIntersection( - circle: { x: number; y: number; width: number; height: number }, - lineStart: { x: number; y: number }, - lineEnd: { x: number; y: number } + circle: Bounds, + lineStart: Point, + lineEnd: Point ): { x: number; y: number } { const radius = Math.min(circle.width, circle.height) / 2; diff --git a/packages/mermaid/src/diagrams/mindmap/mindmapDb.ts b/packages/mermaid/src/diagrams/mindmap/mindmapDb.ts index 66259157e..c14fe26e0 100644 --- a/packages/mermaid/src/diagrams/mindmap/mindmapDb.ts +++ b/packages/mermaid/src/diagrams/mindmap/mindmapDb.ts @@ -4,7 +4,6 @@ import { sanitizeText } from '../../diagrams/common/common.js'; import { log } from '../../logger.js'; import type { MindmapNode } from './mindmapTypes.js'; import defaultConfig from '../../defaultConfig.js'; - import type { LayoutData, Node, Edge } from '../../rendering-util/types.js'; // Extend Node type for mindmap-specific properties diff --git a/packages/mermaid/src/diagrams/mindmap/mindmapRenderer.ts b/packages/mermaid/src/diagrams/mindmap/mindmapRenderer.ts index 26482ca60..910bc740b 100644 --- a/packages/mermaid/src/diagrams/mindmap/mindmapRenderer.ts +++ b/packages/mermaid/src/diagrams/mindmap/mindmapRenderer.ts @@ -6,27 +6,9 @@ import { getRegisteredLayoutAlgorithm, render } from '../../rendering-util/rende import { setupViewPortForSVG } from '../../rendering-util/setupViewPortForSVG.js'; import type { LayoutData } from '../../rendering-util/types.js'; import type { FilledMindMapNode } from './mindmapTypes.js'; -import { drawNode } from './svgDraw.js'; import defaultConfig from '../../defaultConfig.js'; import type { MindmapDB } from './mindmapDb.js'; -async function _drawNodes( - db: MindmapDB, - svg: any, - mindmap: FilledMindMapNode, - section: number, - conf: any -) { - await drawNode(db, svg, mindmap, section, conf); - if (mindmap.children) { - await Promise.all( - mindmap.children.map((child, index) => - _drawNodes(db, svg, child, section < 0 ? index : section, conf) - ) - ); - } -} - /** * Update the layout data with actual node dimensions after drawing */ @@ -42,9 +24,7 @@ function _updateNodeDimensions(data4Layout: LayoutData, mindmapRoot: FilledMindM } // Recursively update children - if (node.children) { - node.children.forEach(updateNode); - } + node.children?.forEach(updateNode); }; updateNode(mindmapRoot); @@ -81,20 +61,16 @@ export const draw: DrawDefinition = async (text, id, _version, diagObj) => { return; } data4Layout.nodes.forEach((node) => { + node.from = 'mindmap'; if (node.shape === 'rounded') { node.radius = 15; node.taper = 15; node.stroke = 'none'; - node.from = 'mindmap'; } else if (node.shape === 'rect') { node.height = 46; node.width = 92; - node.from = 'mindmap'; - } else if (node.shape === 'circle') { - node.from = 'mindmap'; } }); - // Use the unified rendering system await render(data4Layout, svg); // Setup the view box and size of the svg element diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/cose-bilkent/layout.test.ts b/packages/mermaid/src/rendering-util/layout-algorithms/cose-bilkent/layout.test.ts index 6b7dfdf83..66ee311c3 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/cose-bilkent/layout.test.ts +++ b/packages/mermaid/src/rendering-util/layout-algorithms/cose-bilkent/layout.test.ts @@ -1,4 +1,9 @@ import { describe, it, expect, beforeEach, vi } from 'vitest'; +import { validateLayoutData, executeCoseBilkentLayout } from './layout.js'; +import type { LayoutResult } from './types.js'; +import type { MindmapNode } from '../../../diagrams/mindmap/mindmapTypes.js'; +import type { MermaidConfig } from '../../../config.type.js'; +import type { LayoutData } from '../../types.js'; // Mock cytoscape and cytoscape-cose-bilkent before importing the modules vi.mock('cytoscape', () => { @@ -74,13 +79,6 @@ vi.mock('d3', () => ({ })), })); -// Import modules after mocks -import { validateLayoutData, executeCoseBilkentLayout } from './layout.js'; -import type { LayoutResult } from './types.js'; -import type { MindmapNode } from '../../../diagrams/mindmap/mindmapTypes.js'; -import type { MermaidConfig } from '../../../config.type.js'; -import type { LayoutData } from '../../types.js'; - describe('Cose-Bilkent Layout Algorithm', () => { let mockConfig: MermaidConfig; let mockRootNode: MindmapNode; diff --git a/packages/mermaid/src/rendering-util/rendering-elements/edges.js b/packages/mermaid/src/rendering-util/rendering-elements/edges.js index 9833f65ac..3292b3811 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/edges.js +++ b/packages/mermaid/src/rendering-util/rendering-elements/edges.js @@ -485,7 +485,6 @@ export const insertEdge = function (elem, edge, clusterDb, diagramType, startNod } let lineData = points.filter((p) => !Number.isNaN(p.y)); - //lineData = adjustForArrowHeads(lineData); lineData = fixCorners(lineData); let curve = curveBasis; curve = curveLinear;