mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-14 17:54:13 +01:00
fix: address review comments to simplify config handling and improve ID generation
on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { getConfig } from '../../diagram-api/diagramAPI.js';
|
||||
import { v4 } from 'uuid';
|
||||
import type { D3Element } from '../../types.js';
|
||||
import { sanitizeText } from '../../diagrams/common/common.js';
|
||||
import { log } from '../../logger.js';
|
||||
@@ -329,11 +330,9 @@ export class MindmapDB {
|
||||
const userDefinedConfig = getUserDefinedConfig();
|
||||
const hasUserDefinedLayout = userDefinedConfig.layout !== undefined;
|
||||
|
||||
const finalConfig = { ...config };
|
||||
const finalConfig = config;
|
||||
if (!hasUserDefinedLayout) {
|
||||
finalConfig.layout = 'cose-bilkent';
|
||||
} else {
|
||||
finalConfig.layout = userDefinedConfig.layout;
|
||||
}
|
||||
|
||||
if (!mindmapRoot) {
|
||||
@@ -377,7 +376,7 @@ export class MindmapDB {
|
||||
// Store the root node for mindmap-specific layout algorithms
|
||||
rootNode: mindmapRoot,
|
||||
// Properties required by dagre layout algorithm
|
||||
markers: [], // Mindmaps don't use markers
|
||||
markers: ['point'], // Mindmaps don't use markers
|
||||
direction: 'TB', // Top-to-bottom direction for mindmaps
|
||||
nodeSpacing: 50, // Default spacing between nodes
|
||||
rankSpacing: 50, // Default spacing between ranks
|
||||
@@ -385,7 +384,7 @@ export class MindmapDB {
|
||||
shapes: Object.fromEntries(shapes),
|
||||
// Additional properties that layout algorithms might expect
|
||||
type: 'mindmap',
|
||||
diagramId: 'mindmap-' + Date.now(),
|
||||
diagramId: 'mindmap-' + v4(),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -48,14 +48,9 @@ export const draw: DrawDefinition = async (text, id, _version, diagObj) => {
|
||||
data4Layout.layoutAlgorithm = getRegisteredLayoutAlgorithm(data4Layout.config.layout, {
|
||||
fallback: 'cose-bilkent',
|
||||
});
|
||||
// For mindmap diagrams, prioritize mindmap-specific layout algorithm configuration
|
||||
|
||||
data4Layout.diagramId = id;
|
||||
|
||||
// Ensure required properties are set for compatibility with different layout algorithms
|
||||
data4Layout.markers = ['point'];
|
||||
data4Layout.direction = 'TB';
|
||||
|
||||
const mm = db.getMindmap();
|
||||
if (!mm) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user