Skip to content

Commit

Permalink
feat #5042: Add flowchart.maxEdges config.
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthv96 committed Nov 28, 2023
1 parent 4499926 commit fdf9988
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions packages/mermaid/src/config.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
7 changes: 3 additions & 4 deletions packages/mermaid/src/diagrams/flowchart/flowDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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.`);

Check warning on line 165 in packages/mermaid/src/diagrams/flowchart/flowDb.js

View check run for this annotation

Codecov / codecov/patch

packages/mermaid/src/diagrams/flowchart/flowDb.js#L165

Added line #L165 was not covered by tests
}
};
export const addLink = function (_start, _end, type) {
Expand Down Expand Up @@ -460,6 +458,7 @@ export const clear = function (ver = 'gen-1') {
tooltips = {};
firstGraphFlag = true;
version = ver;
config = getConfig();
commonClear();
};
export const setGen = (ver) => {
Expand Down
6 changes: 6 additions & 0 deletions packages/mermaid/src/schemas/config.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fdf9988

Please sign in to comment.