mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-15 02:04:08 +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 { getConfig } from '../../diagram-api/diagramAPI.js';
|
||||||
|
import { v4 } from 'uuid';
|
||||||
import type { D3Element } from '../../types.js';
|
import type { D3Element } from '../../types.js';
|
||||||
import { sanitizeText } from '../../diagrams/common/common.js';
|
import { sanitizeText } from '../../diagrams/common/common.js';
|
||||||
import { log } from '../../logger.js';
|
import { log } from '../../logger.js';
|
||||||
@@ -329,11 +330,9 @@ export class MindmapDB {
|
|||||||
const userDefinedConfig = getUserDefinedConfig();
|
const userDefinedConfig = getUserDefinedConfig();
|
||||||
const hasUserDefinedLayout = userDefinedConfig.layout !== undefined;
|
const hasUserDefinedLayout = userDefinedConfig.layout !== undefined;
|
||||||
|
|
||||||
const finalConfig = { ...config };
|
const finalConfig = config;
|
||||||
if (!hasUserDefinedLayout) {
|
if (!hasUserDefinedLayout) {
|
||||||
finalConfig.layout = 'cose-bilkent';
|
finalConfig.layout = 'cose-bilkent';
|
||||||
} else {
|
|
||||||
finalConfig.layout = userDefinedConfig.layout;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mindmapRoot) {
|
if (!mindmapRoot) {
|
||||||
@@ -377,7 +376,7 @@ export class MindmapDB {
|
|||||||
// Store the root node for mindmap-specific layout algorithms
|
// Store the root node for mindmap-specific layout algorithms
|
||||||
rootNode: mindmapRoot,
|
rootNode: mindmapRoot,
|
||||||
// Properties required by dagre layout algorithm
|
// 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
|
direction: 'TB', // Top-to-bottom direction for mindmaps
|
||||||
nodeSpacing: 50, // Default spacing between nodes
|
nodeSpacing: 50, // Default spacing between nodes
|
||||||
rankSpacing: 50, // Default spacing between ranks
|
rankSpacing: 50, // Default spacing between ranks
|
||||||
@@ -385,7 +384,7 @@ export class MindmapDB {
|
|||||||
shapes: Object.fromEntries(shapes),
|
shapes: Object.fromEntries(shapes),
|
||||||
// Additional properties that layout algorithms might expect
|
// Additional properties that layout algorithms might expect
|
||||||
type: 'mindmap',
|
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, {
|
data4Layout.layoutAlgorithm = getRegisteredLayoutAlgorithm(data4Layout.config.layout, {
|
||||||
fallback: 'cose-bilkent',
|
fallback: 'cose-bilkent',
|
||||||
});
|
});
|
||||||
// For mindmap diagrams, prioritize mindmap-specific layout algorithm configuration
|
|
||||||
|
|
||||||
data4Layout.diagramId = id;
|
data4Layout.diagramId = id;
|
||||||
|
|
||||||
// Ensure required properties are set for compatibility with different layout algorithms
|
|
||||||
data4Layout.markers = ['point'];
|
|
||||||
data4Layout.direction = 'TB';
|
|
||||||
|
|
||||||
const mm = db.getMindmap();
|
const mm = db.getMindmap();
|
||||||
if (!mm) {
|
if (!mm) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user