refactor: remove diagram specific checks from utils

on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
This commit is contained in:
darshanr0107
2025-10-09 18:18:20 +05:30
parent e351a7a488
commit a53c0d4305
5 changed files with 14 additions and 45 deletions

View File

@@ -92,7 +92,9 @@ export class FlowDB implements DiagramDB {
case 'text':
return labelType;
default:
return 'markdown';
// For flowcharts, default to 'text' (v10 behavior: only explicit markdown is rendered)
// This is different from v11 where undefined defaulted to 'markdown'
return 'text';
}
}
@@ -1043,7 +1045,6 @@ You have to call mermaid.initialize.`
assetWidth: vertex.assetWidth,
assetHeight: vertex.assetHeight,
constraint: vertex.constraint,
diagramType: 'flowchart', // Add diagram type for rendering decisions
};
if (isGroup) {
nodes.push({
@@ -1111,7 +1112,6 @@ You have to call mermaid.initialize.`
dir: subGraph.dir,
isGroup: true,
look: config.look,
diagramType: 'flowchart', // Add diagram type for rendering decisions
});
}
@@ -1158,7 +1158,6 @@ You have to call mermaid.initialize.`
animate: rawEdge.animate,
animation: rawEdge.animation,
curve: rawEdge.interpolate || this.edges.defaultInterpolate || config.flowchart?.curve,
diagramType: 'flowchart', // Add diagram type for rendering decisions
};
edges.push(edge);

View File

@@ -10,16 +10,6 @@ import createLabel from './createLabel.js';
import { createRoundedRectPathD } from './shapes/roundedRectPath.ts';
import { styles2String, userNodeOverrides } from './shapes/handDrawnShapeStyles.js';
function shouldRenderClusterLabelAsMarkdown(node) {
const diagramType = node.diagramType;
if (diagramType === 'flowchart') {
return node.labelType === 'markdown';
}
return node.labelType !== 'text' && node.labelType !== 'string';
}
const rect = async (parent, node) => {
log.info('Creating subgraph rect for ', node.id, node);
const siteConfig = getConfig();
@@ -41,7 +31,7 @@ const rect = async (parent, node) => {
const labelEl = shapeSvg.insert('g').attr('class', 'cluster-label ');
let text;
if (shouldRenderClusterLabelAsMarkdown(node)) {
if (node.labelType === 'markdown') {
text = await createText(labelEl, node.label, {
style: node.labelStyle,
useHtmlLabels,

View File

@@ -44,27 +44,18 @@ export const getLabelStyles = (styleArray) => {
return styles;
};
function shouldRenderEdgeLabelAsMarkdown(edge) {
const diagramType = edge.diagramType;
if (diagramType === 'flowchart') {
return edge.labelType === 'markdown';
}
return edge.labelType !== 'text' && edge.labelType !== 'string';
}
export const insertEdgeLabel = async (elem, edge) => {
let useHtmlLabels = evaluate(getConfig().flowchart.htmlLabels);
const labelElement = shouldRenderEdgeLabelAsMarkdown(edge)
? await createText(elem, edge.label, {
style: getLabelStyles(edge.labelStyle),
useHtmlLabels,
addSvgBackground: true,
isNode: false,
})
: await createLabel(edge.label, getLabelStyles(edge.labelStyle), undefined, false);
const labelElement =
edge.labelType === 'markdown'
? await createText(elem, edge.label, {
style: getLabelStyles(edge.labelStyle),
useHtmlLabels,
addSvgBackground: true,
isNode: false,
})
: await createLabel(edge.label, getLabelStyles(edge.labelStyle), undefined, false);
log.info('abc82', edge, edge.labelType);

View File

@@ -8,15 +8,6 @@ import { evaluate, sanitizeText } from '../../../diagrams/common/common.js';
import { decodeEntities, handleUndefinedAttr, parseFontSize } from '../../../utils.js';
import type { D3Selection, Point } from '../../../types.js';
function shouldRenderAsMarkdown(node: Node): boolean {
const diagramType = node.diagramType;
if (diagramType === 'flowchart') {
return node.labelType === 'markdown';
}
return node.labelType !== 'text' && node.labelType !== 'string';
}
export const labelHelper = async <T extends SVGGraphicsElement>(
parent: D3Selection<T>,
node: Node,
@@ -51,7 +42,7 @@ export const labelHelper = async <T extends SVGGraphicsElement>(
}
let text;
if (shouldRenderAsMarkdown(node)) {
if (node.labelType === 'markdown') {
text = await createText(labelEl, sanitizeText(decodeEntities(label), getConfig()), {
useHtmlLabels,
width: node.width || getConfig().flowchart?.wrappingWidth,

View File

@@ -32,7 +32,6 @@ interface BaseNode {
labelType?: string; // REMOVE? Always use markdown string, need to check for KaTeX - ⏳ wait with this one
domId?: string; // When you create the node in the getData function you do not have the domId yet
diagramType?: string; // Used to determine diagram-specific rendering behavior
// Rendering specific properties for both Flowchart and State Diagram nodes
dir?: string; // Only relevant for isGroup true, i.e. a sub-graph or composite state.
haveCallback?: boolean;
@@ -146,7 +145,6 @@ export interface Edge {
source?: string;
target?: string;
depth?: number;
diagramType?: string; // Used to determine diagram-specific rendering behavior
}
export interface RectOptions {