mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-10-07 16:19:38 +02:00
chore: fix review feedback in tidy-tree and mindmap (types, cleanup)
on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user