mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-21 00:09:51 +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\` |
|
| Data Input/Output | Lean Left | \`lean-l\` | Represents output or input | \`lean-left\`, \`out-in\` |
|
||||||
| Database | Cylinder | \`cyl\` | Database storage | \`cylinder\`, \`database\`, \`db\` |
|
| Database | Cylinder | \`cyl\` | Database storage | \`cylinder\`, \`database\`, \`db\` |
|
||||||
| Decision | Diamond | \`diam\` | Decision-making step | \`decision\`, \`diamond\`, \`question\` |
|
| 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\` |
|
| Delay | Half-Rounded Rectangle | \`delay\` | Represents a delay | \`half-rounded-rectangle\` |
|
||||||
| Direct Access Storage | Horizontal Cylinder | \`h-cyl\` | Direct access storage | \`das\`, \`horizontal-cylinder\` |
|
| Direct Access Storage | Horizontal Cylinder | \`h-cyl\` | Direct access storage | \`das\`, \`horizontal-cylinder\` |
|
||||||
| Disk Storage | Lined Cylinder | \`lin-cyl\` | Disk storage | \`disk\`, \`lined-cylinder\` |
|
| Disk Storage | Lined Cylinder | \`lin-cyl\` | Disk storage | \`disk\`, \`lined-cylinder\` |
|
||||||
|
@@ -214,6 +214,8 @@ export interface MermaidConfig {
|
|||||||
wrap?: boolean;
|
wrap?: boolean;
|
||||||
fontSize?: number;
|
fontSize?: number;
|
||||||
markdownAutoWrap?: boolean;
|
markdownAutoWrap?: boolean;
|
||||||
|
padding?: number;
|
||||||
|
useMaxWidth?: boolean;
|
||||||
/**
|
/**
|
||||||
* Suppresses inserting 'Syntax error' diagram in the DOM.
|
* Suppresses inserting 'Syntax error' diagram in the DOM.
|
||||||
* This is useful when you want to control how to handle syntax errors in your application.
|
* 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 type { DrawDefinition } from '../../diagram-api/types.js';
|
||||||
import { log } from '../../logger.js';
|
import { log } from '../../logger.js';
|
||||||
import { getDiagramElement } from '../../rendering-util/insertElementsForSize.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) => {
|
export const draw: DrawDefinition = async (text, id, _version, diagObj) => {
|
||||||
log.debug('Rendering mindmap diagram\n' + text);
|
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
|
// Draw the nodes first to get their dimensions, then update the layout data
|
||||||
const db = diagObj.db as MindmapDB;
|
const db = diagObj.db as MindmapDB;
|
||||||
@@ -42,7 +40,7 @@ export const draw: DrawDefinition = async (text, id, _version, diagObj) => {
|
|||||||
const data4Layout = db.getData();
|
const data4Layout = db.getData();
|
||||||
|
|
||||||
// Create the root SVG - the element is the div containing the SVG element
|
// 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.type = diagObj.type;
|
||||||
data4Layout.layoutAlgorithm = getRegisteredLayoutAlgorithm(data4Layout.config.layout, {
|
data4Layout.layoutAlgorithm = getRegisteredLayoutAlgorithm(data4Layout.config.layout, {
|
||||||
@@ -55,6 +53,7 @@ export const draw: DrawDefinition = async (text, id, _version, diagObj) => {
|
|||||||
if (!mm) {
|
if (!mm) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
data4Layout.nodes.forEach((node) => {
|
data4Layout.nodes.forEach((node) => {
|
||||||
if (node.shape === 'rounded') {
|
if (node.shape === 'rounded') {
|
||||||
node.radius = 15;
|
node.radius = 15;
|
||||||
@@ -69,14 +68,16 @@ export const draw: DrawDefinition = async (text, id, _version, diagObj) => {
|
|||||||
node.padding = 10;
|
node.padding = 10;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Use the unified rendering system
|
// Use the unified rendering system
|
||||||
await render(data4Layout, svg);
|
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(
|
setupViewPortForSVG(
|
||||||
svg,
|
svg,
|
||||||
conf?.padding ?? defaultConfig.mindmap.padding,
|
data4Layout.config.padding ?? defaultConfig.mindmap.padding,
|
||||||
'mindmapDiagram',
|
'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', () => {
|
describe('Cytoscape Setup', () => {
|
||||||
let mockNodes: Node[];
|
let mockNodes: Node[];
|
||||||
let mockEdges: Edge[];
|
let mockEdges: Edge[];
|
||||||
|
@@ -6,6 +6,7 @@ import type { MermaidConfig } from '../../../config.type.js';
|
|||||||
import type { LayoutData } from '../../types.js';
|
import type { LayoutData } from '../../types.js';
|
||||||
|
|
||||||
// Mock cytoscape and cytoscape-cose-bilkent before importing the modules
|
// Mock cytoscape and cytoscape-cose-bilkent before importing the modules
|
||||||
|
|
||||||
vi.mock('cytoscape', () => {
|
vi.mock('cytoscape', () => {
|
||||||
const mockCy = {
|
const mockCy = {
|
||||||
add: vi.fn(),
|
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', () => {
|
describe('Cose-Bilkent Layout Algorithm', () => {
|
||||||
let mockConfig: MermaidConfig;
|
let mockConfig: MermaidConfig;
|
||||||
let mockRootNode: MindmapNode;
|
let mockRootNode: MindmapNode;
|
||||||
|
@@ -147,14 +147,6 @@ 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',
|
||||||
@@ -506,7 +498,7 @@ const generateShapeMap = () => {
|
|||||||
|
|
||||||
//Mindmap diagram
|
//Mindmap diagram
|
||||||
mindmapCircle,
|
mindmapCircle,
|
||||||
|
defaultMindmapNode,
|
||||||
// class diagram
|
// class diagram
|
||||||
classBox,
|
classBox,
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user