diff --git a/packages/mermaid/src/config.type.ts b/packages/mermaid/src/config.type.ts index 402d9a4d86..34cc3b5650 100644 --- a/packages/mermaid/src/config.type.ts +++ b/packages/mermaid/src/config.type.ts @@ -1431,6 +1431,11 @@ export interface FlowchartDiagramConfig extends BaseDiagramConfig { * */ htmlLabels?: boolean; + /** + * Defines the maximum number of edges that can be drawn in a graph. + * + */ + maxEdges?: number; /** * Defines the spacing between nodes on the same level * diff --git a/packages/mermaid/src/diagrams/flowchart/flowDb.js b/packages/mermaid/src/diagrams/flowchart/flowDb.js index 9a693aabf5..aaaa6cd8cd 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowDb.js +++ b/packages/mermaid/src/diagrams/flowchart/flowDb.js @@ -12,7 +12,6 @@ import { setDiagramTitle, getDiagramTitle, } from '../common/commonDb.js'; -import errorDiagram from '../error/errorDiagram.js'; const MERMAID_DOM_ID_PREFIX = 'flowchart-'; let vertexCounter = 0; @@ -92,7 +91,6 @@ export const addVertex = function (_id, textObj, type, style, classes, dir, prop if (txt[0] === '"' && txt[txt.length - 1] === '"') { txt = txt.substring(1, txt.length - 1); } - vertices[id].text = txt; } else { if (vertices[id].text === undefined) { @@ -160,11 +158,11 @@ export const addSingleLink = function (_start, _end, type) { if (edge?.length > 10) { edge.length = 10; } - if (edges.length < 280) { + if (edges.length < (config.flowchart.maxEdges ?? 500)) { log.info('abc78 pushing edge...'); edges.push(edge); } else { - throw new Error('Too many edges'); + throw new Error(`Edge limit exceeded. Increase config.flowchart.maxEdges to allow more edges.`); } }; export const addLink = function (_start, _end, type) { @@ -460,6 +458,7 @@ export const clear = function (ver = 'gen-1') { tooltips = {}; firstGraphFlag = true; version = ver; + config = getConfig(); commonClear(); }; export const setGen = (ver) => { diff --git a/packages/mermaid/src/schemas/config.schema.yaml b/packages/mermaid/src/schemas/config.schema.yaml index 2791c32d4b..30d6a6024c 100644 --- a/packages/mermaid/src/schemas/config.schema.yaml +++ b/packages/mermaid/src/schemas/config.schema.yaml @@ -1900,6 +1900,12 @@ $defs: # JSON Schema definition (maybe we should move these to a separate file) Flag for setting whether or not a html tag should be used for rendering labels on the edges. type: boolean default: true + maxEdges: + description: | + Defines the maximum number of edges that can be drawn in a graph. + type: integer + default: 500 + minimum: 0 nodeSpacing: description: | Defines the spacing between nodes on the same level