mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-20 07:49:43 +02:00
fix: handle default 'cose-bilkent' layout in mindmap layer
on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import { log } from '../../logger.js';
|
|||||||
import type { MindmapNode } from './mindmapTypes.js';
|
import type { MindmapNode } from './mindmapTypes.js';
|
||||||
import defaultConfig from '../../defaultConfig.js';
|
import defaultConfig from '../../defaultConfig.js';
|
||||||
import type { LayoutData, Node, Edge } from '../../rendering-util/types.js';
|
import type { LayoutData, Node, Edge } from '../../rendering-util/types.js';
|
||||||
|
import { getUserDefinedConfig } from '../../config.js';
|
||||||
|
|
||||||
// Extend Node type for mindmap-specific properties
|
// Extend Node type for mindmap-specific properties
|
||||||
export type MindmapLayoutNode = Node & {
|
export type MindmapLayoutNode = Node & {
|
||||||
@@ -325,11 +326,21 @@ export class MindmapDB {
|
|||||||
const mindmapRoot = this.getMindmap();
|
const mindmapRoot = this.getMindmap();
|
||||||
const config = getConfig();
|
const config = getConfig();
|
||||||
|
|
||||||
|
const userDefinedConfig = getUserDefinedConfig();
|
||||||
|
const hasUserDefinedLayout = userDefinedConfig.layout !== undefined;
|
||||||
|
|
||||||
|
const finalConfig = { ...config };
|
||||||
|
if (!hasUserDefinedLayout) {
|
||||||
|
finalConfig.layout = 'cose-bilkent';
|
||||||
|
} else {
|
||||||
|
finalConfig.layout = userDefinedConfig.layout;
|
||||||
|
}
|
||||||
|
|
||||||
if (!mindmapRoot) {
|
if (!mindmapRoot) {
|
||||||
return {
|
return {
|
||||||
nodes: [],
|
nodes: [],
|
||||||
edges: [],
|
edges: [],
|
||||||
config,
|
config: finalConfig,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
log.debug('getData: mindmapRoot', mindmapRoot, config);
|
log.debug('getData: mindmapRoot', mindmapRoot, config);
|
||||||
@@ -362,7 +373,7 @@ export class MindmapDB {
|
|||||||
return {
|
return {
|
||||||
nodes: processedNodes,
|
nodes: processedNodes,
|
||||||
edges: processedEdges,
|
edges: processedEdges,
|
||||||
config,
|
config: finalConfig,
|
||||||
// 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
|
||||||
|
@@ -32,7 +32,7 @@ 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, layout } = getConfig();
|
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;
|
||||||
@@ -45,7 +45,7 @@ export const draw: DrawDefinition = async (text, id, _version, diagObj) => {
|
|||||||
const svg = getDiagramElement(id, securityLevel);
|
const svg = getDiagramElement(id, securityLevel);
|
||||||
|
|
||||||
data4Layout.type = diagObj.type;
|
data4Layout.type = diagObj.type;
|
||||||
data4Layout.layoutAlgorithm = getRegisteredLayoutAlgorithm(layout, {
|
data4Layout.layoutAlgorithm = getRegisteredLayoutAlgorithm(data4Layout.config.layout, {
|
||||||
fallback: 'cose-bilkent',
|
fallback: 'cose-bilkent',
|
||||||
});
|
});
|
||||||
// For mindmap diagrams, prioritize mindmap-specific layout algorithm configuration
|
// For mindmap diagrams, prioritize mindmap-specific layout algorithm configuration
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
import { cleanupComments } from './diagram-api/comments.js';
|
import { cleanupComments } from './diagram-api/comments.js';
|
||||||
import { detectType } from './diagram-api/detectType.js';
|
|
||||||
import { extractFrontMatter } from './diagram-api/frontmatter.js';
|
import { extractFrontMatter } from './diagram-api/frontmatter.js';
|
||||||
import type { DiagramMetadata } from './diagram-api/types.js';
|
import type { DiagramMetadata } from './diagram-api/types.js';
|
||||||
import utils, { cleanAndMerge, removeDirectives } from './utils.js';
|
import utils, { cleanAndMerge, removeDirectives } from './utils.js';
|
||||||
@@ -19,7 +18,6 @@ const cleanupText = (code: string) => {
|
|||||||
|
|
||||||
const processFrontmatter = (code: string) => {
|
const processFrontmatter = (code: string) => {
|
||||||
const { text, metadata } = extractFrontMatter(code);
|
const { text, metadata } = extractFrontMatter(code);
|
||||||
const diagramType = detectType(text);
|
|
||||||
const { displayMode, title, config = {} } = metadata;
|
const { displayMode, title, config = {} } = metadata;
|
||||||
if (displayMode) {
|
if (displayMode) {
|
||||||
// Needs to be supported for legacy reasons
|
// Needs to be supported for legacy reasons
|
||||||
@@ -28,9 +26,7 @@ const processFrontmatter = (code: string) => {
|
|||||||
}
|
}
|
||||||
config.gantt.displayMode = displayMode;
|
config.gantt.displayMode = displayMode;
|
||||||
}
|
}
|
||||||
if (diagramType === 'mindmap' && !config.layout) {
|
|
||||||
config.layout = 'cose-bilkent'; // Default layout for mindmap
|
|
||||||
}
|
|
||||||
return { title, config, text };
|
return { title, config, text };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user