mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-19 23:39:50 +02:00
fix: address review comments to clean up unused mocks, remove default mindmap shape from global shape registry
on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
This commit is contained in:
@@ -183,7 +183,6 @@ This Markdown should be kept.
|
||||
| Data Input/Output | Lean Left | \`lean-l\` | Represents output or input | \`lean-left\`, \`out-in\` |
|
||||
| Database | Cylinder | \`cyl\` | Database storage | \`cylinder\`, \`database\`, \`db\` |
|
||||
| Decision | Diamond | \`diam\` | Decision-making step | \`decision\`, \`diamond\`, \`question\` |
|
||||
| Default Mindmap Node | defaultMindmapNode | \`default-mindmap\` | defaultMindmapNode | \`default-mindmap\`, \`defaultMindmapNode\` |
|
||||
| Delay | Half-Rounded Rectangle | \`delay\` | Represents a delay | \`half-rounded-rectangle\` |
|
||||
| Direct Access Storage | Horizontal Cylinder | \`h-cyl\` | Direct access storage | \`das\`, \`horizontal-cylinder\` |
|
||||
| Disk Storage | Lined Cylinder | \`lin-cyl\` | Disk storage | \`disk\`, \`lined-cylinder\` |
|
||||
|
@@ -214,6 +214,8 @@ export interface MermaidConfig {
|
||||
wrap?: boolean;
|
||||
fontSize?: number;
|
||||
markdownAutoWrap?: boolean;
|
||||
padding?: number;
|
||||
useMaxWidth?: boolean;
|
||||
/**
|
||||
* Suppresses inserting 'Syntax error' diagram in the DOM.
|
||||
* This is useful when you want to control how to handle syntax errors in your application.
|
||||
|
@@ -1,4 +1,3 @@
|
||||
import { getConfig } from '../../diagram-api/diagramAPI.js';
|
||||
import type { DrawDefinition } from '../../diagram-api/types.js';
|
||||
import { log } from '../../logger.js';
|
||||
import { getDiagramElement } from '../../rendering-util/insertElementsForSize.js';
|
||||
@@ -32,7 +31,6 @@ function _updateNodeDimensions(data4Layout: LayoutData, mindmapRoot: FilledMindM
|
||||
|
||||
export const draw: DrawDefinition = async (text, id, _version, diagObj) => {
|
||||
log.debug('Rendering mindmap diagram\n' + text);
|
||||
const { securityLevel, mindmap: conf } = getConfig();
|
||||
|
||||
// Draw the nodes first to get their dimensions, then update the layout data
|
||||
const db = diagObj.db as MindmapDB;
|
||||
@@ -42,7 +40,7 @@ export const draw: DrawDefinition = async (text, id, _version, diagObj) => {
|
||||
const data4Layout = db.getData();
|
||||
|
||||
// Create the root SVG - the element is the div containing the SVG element
|
||||
const svg = getDiagramElement(id, securityLevel);
|
||||
const svg = getDiagramElement(id, data4Layout.config.securityLevel);
|
||||
|
||||
data4Layout.type = diagObj.type;
|
||||
data4Layout.layoutAlgorithm = getRegisteredLayoutAlgorithm(data4Layout.config.layout, {
|
||||
@@ -55,6 +53,7 @@ export const draw: DrawDefinition = async (text, id, _version, diagObj) => {
|
||||
if (!mm) {
|
||||
return;
|
||||
}
|
||||
|
||||
data4Layout.nodes.forEach((node) => {
|
||||
if (node.shape === 'rounded') {
|
||||
node.radius = 15;
|
||||
@@ -69,14 +68,16 @@ export const draw: DrawDefinition = async (text, id, _version, diagObj) => {
|
||||
node.padding = 10;
|
||||
}
|
||||
});
|
||||
|
||||
// Use the unified rendering system
|
||||
await render(data4Layout, svg);
|
||||
// Setup the view box and size of the svg element
|
||||
|
||||
// Setup the view box and size of the svg element using config from data4Layout
|
||||
setupViewPortForSVG(
|
||||
svg,
|
||||
conf?.padding ?? defaultConfig.mindmap.padding,
|
||||
data4Layout.config.padding ?? defaultConfig.mindmap.padding,
|
||||
'mindmapDiagram',
|
||||
conf?.useMaxWidth ?? defaultConfig.mindmap.useMaxWidth
|
||||
data4Layout.config.useMaxWidth ?? defaultConfig.mindmap.useMaxWidth
|
||||
);
|
||||
};
|
||||
|
||||
|
@@ -22,10 +22,6 @@ vi.mock('cytoscape', () => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock('cytoscape-cose-bilkent', () => ({
|
||||
default: vi.fn(),
|
||||
}));
|
||||
|
||||
describe('Cytoscape Setup', () => {
|
||||
let mockNodes: Node[];
|
||||
let mockEdges: Edge[];
|
||||
|
@@ -6,6 +6,7 @@ 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', () => {
|
||||
const mockCy = {
|
||||
add: vi.fn(),
|
||||
@@ -63,22 +64,6 @@ vi.mock('cytoscape', () => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock('cytoscape-cose-bilkent', () => ({
|
||||
default: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('d3', () => ({
|
||||
select: vi.fn(() => ({
|
||||
append: vi.fn(() => ({
|
||||
attr: vi.fn(() => ({
|
||||
attr: vi.fn(() => ({
|
||||
remove: vi.fn(),
|
||||
})),
|
||||
})),
|
||||
})),
|
||||
})),
|
||||
}));
|
||||
|
||||
describe('Cose-Bilkent Layout Algorithm', () => {
|
||||
let mockConfig: MermaidConfig;
|
||||
let mockRootNode: MindmapNode;
|
||||
|
@@ -147,14 +147,6 @@ 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',
|
||||
@@ -506,7 +498,7 @@ const generateShapeMap = () => {
|
||||
|
||||
//Mindmap diagram
|
||||
mindmapCircle,
|
||||
|
||||
defaultMindmapNode,
|
||||
// class diagram
|
||||
classBox,
|
||||
|
||||
|
Reference in New Issue
Block a user