fix: handle default 'cose-bilkent' layout in mindmap layer

on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
This commit is contained in:
darshanr0107
2025-08-28 11:43:40 +05:30
parent 4b63214a72
commit 21eddc3f23
3 changed files with 16 additions and 9 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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 };
}; };