mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-10-11 10:09:39 +02:00
refactor: remove diagram specific checks from utils
on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
This commit is contained in:
@@ -92,7 +92,9 @@ export class FlowDB implements DiagramDB {
|
|||||||
case 'text':
|
case 'text':
|
||||||
return labelType;
|
return labelType;
|
||||||
default:
|
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,
|
assetWidth: vertex.assetWidth,
|
||||||
assetHeight: vertex.assetHeight,
|
assetHeight: vertex.assetHeight,
|
||||||
constraint: vertex.constraint,
|
constraint: vertex.constraint,
|
||||||
diagramType: 'flowchart', // Add diagram type for rendering decisions
|
|
||||||
};
|
};
|
||||||
if (isGroup) {
|
if (isGroup) {
|
||||||
nodes.push({
|
nodes.push({
|
||||||
@@ -1111,7 +1112,6 @@ You have to call mermaid.initialize.`
|
|||||||
dir: subGraph.dir,
|
dir: subGraph.dir,
|
||||||
isGroup: true,
|
isGroup: true,
|
||||||
look: config.look,
|
look: config.look,
|
||||||
diagramType: 'flowchart', // Add diagram type for rendering decisions
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1158,7 +1158,6 @@ You have to call mermaid.initialize.`
|
|||||||
animate: rawEdge.animate,
|
animate: rawEdge.animate,
|
||||||
animation: rawEdge.animation,
|
animation: rawEdge.animation,
|
||||||
curve: rawEdge.interpolate || this.edges.defaultInterpolate || config.flowchart?.curve,
|
curve: rawEdge.interpolate || this.edges.defaultInterpolate || config.flowchart?.curve,
|
||||||
diagramType: 'flowchart', // Add diagram type for rendering decisions
|
|
||||||
};
|
};
|
||||||
|
|
||||||
edges.push(edge);
|
edges.push(edge);
|
||||||
|
@@ -10,16 +10,6 @@ import createLabel from './createLabel.js';
|
|||||||
import { createRoundedRectPathD } from './shapes/roundedRectPath.ts';
|
import { createRoundedRectPathD } from './shapes/roundedRectPath.ts';
|
||||||
import { styles2String, userNodeOverrides } from './shapes/handDrawnShapeStyles.js';
|
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) => {
|
const rect = async (parent, node) => {
|
||||||
log.info('Creating subgraph rect for ', node.id, node);
|
log.info('Creating subgraph rect for ', node.id, node);
|
||||||
const siteConfig = getConfig();
|
const siteConfig = getConfig();
|
||||||
@@ -41,7 +31,7 @@ const rect = async (parent, node) => {
|
|||||||
const labelEl = shapeSvg.insert('g').attr('class', 'cluster-label ');
|
const labelEl = shapeSvg.insert('g').attr('class', 'cluster-label ');
|
||||||
|
|
||||||
let text;
|
let text;
|
||||||
if (shouldRenderClusterLabelAsMarkdown(node)) {
|
if (node.labelType === 'markdown') {
|
||||||
text = await createText(labelEl, node.label, {
|
text = await createText(labelEl, node.label, {
|
||||||
style: node.labelStyle,
|
style: node.labelStyle,
|
||||||
useHtmlLabels,
|
useHtmlLabels,
|
||||||
|
@@ -44,27 +44,18 @@ export const getLabelStyles = (styleArray) => {
|
|||||||
return styles;
|
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) => {
|
export const insertEdgeLabel = async (elem, edge) => {
|
||||||
let useHtmlLabels = evaluate(getConfig().flowchart.htmlLabels);
|
let useHtmlLabels = evaluate(getConfig().flowchart.htmlLabels);
|
||||||
|
|
||||||
const labelElement = shouldRenderEdgeLabelAsMarkdown(edge)
|
const labelElement =
|
||||||
? await createText(elem, edge.label, {
|
edge.labelType === 'markdown'
|
||||||
style: getLabelStyles(edge.labelStyle),
|
? await createText(elem, edge.label, {
|
||||||
useHtmlLabels,
|
style: getLabelStyles(edge.labelStyle),
|
||||||
addSvgBackground: true,
|
useHtmlLabels,
|
||||||
isNode: false,
|
addSvgBackground: true,
|
||||||
})
|
isNode: false,
|
||||||
: await createLabel(edge.label, getLabelStyles(edge.labelStyle), undefined, false);
|
})
|
||||||
|
: await createLabel(edge.label, getLabelStyles(edge.labelStyle), undefined, false);
|
||||||
|
|
||||||
log.info('abc82', edge, edge.labelType);
|
log.info('abc82', edge, edge.labelType);
|
||||||
|
|
||||||
|
@@ -8,15 +8,6 @@ import { evaluate, sanitizeText } from '../../../diagrams/common/common.js';
|
|||||||
import { decodeEntities, handleUndefinedAttr, parseFontSize } from '../../../utils.js';
|
import { decodeEntities, handleUndefinedAttr, parseFontSize } from '../../../utils.js';
|
||||||
import type { D3Selection, Point } from '../../../types.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>(
|
export const labelHelper = async <T extends SVGGraphicsElement>(
|
||||||
parent: D3Selection<T>,
|
parent: D3Selection<T>,
|
||||||
node: Node,
|
node: Node,
|
||||||
@@ -51,7 +42,7 @@ export const labelHelper = async <T extends SVGGraphicsElement>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let text;
|
let text;
|
||||||
if (shouldRenderAsMarkdown(node)) {
|
if (node.labelType === 'markdown') {
|
||||||
text = await createText(labelEl, sanitizeText(decodeEntities(label), getConfig()), {
|
text = await createText(labelEl, sanitizeText(decodeEntities(label), getConfig()), {
|
||||||
useHtmlLabels,
|
useHtmlLabels,
|
||||||
width: node.width || getConfig().flowchart?.wrappingWidth,
|
width: node.width || getConfig().flowchart?.wrappingWidth,
|
||||||
|
@@ -32,7 +32,6 @@ interface BaseNode {
|
|||||||
labelType?: string; // REMOVE? Always use markdown string, need to check for KaTeX - ⏳ wait with this one
|
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
|
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
|
// 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.
|
dir?: string; // Only relevant for isGroup true, i.e. a sub-graph or composite state.
|
||||||
haveCallback?: boolean;
|
haveCallback?: boolean;
|
||||||
@@ -146,7 +145,6 @@ export interface Edge {
|
|||||||
source?: string;
|
source?: string;
|
||||||
target?: string;
|
target?: string;
|
||||||
depth?: number;
|
depth?: number;
|
||||||
diagramType?: string; // Used to determine diagram-specific rendering behavior
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RectOptions {
|
export interface RectOptions {
|
||||||
|
Reference in New Issue
Block a user