feat #5042: Add `flowchart.maxEdges` config.

This commit is contained in:
Sidharth Vinod 2023-11-28 19:07:10 +05:30
parent 4499926453
commit fdf9988af1
No known key found for this signature in database
GPG Key ID: FB5CCD378D3907CD
3 changed files with 14 additions and 4 deletions

View File

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

View File

@ -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) => {

View File

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