Skip to content

Commit 40b85c3

Browse files
Merge pull request mermaid-js#6408 from mermaid-js/fix/6193-curve-interpolation
fix: restore curve type configuration functionality for flowcharts
2 parents 9b9cec9 + f8e329f commit 40b85c3

File tree

6 files changed

+110
-3
lines changed

6 files changed

+110
-3
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'mermaid': minor
3+
---
4+
5+
fix: restore curve type configuration functionality for flowcharts. This fixes the issue where curve type settings were not being applied when configured through any of the following methods:
6+
7+
- Config
8+
- Init directive (%%{ init: { 'flowchart': { 'curve': '...' } } }%%)
9+
- LinkStyle command (linkStyle default interpolate ...)

packages/mermaid/src/config.type.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,19 @@ export interface FlowchartDiagramConfig extends BaseDiagramConfig {
262262
* Defines how mermaid renders curves for flowcharts.
263263
*
264264
*/
265-
curve?: 'basis' | 'linear' | 'cardinal';
265+
curve?:
266+
| 'basis'
267+
| 'bumpX'
268+
| 'bumpY'
269+
| 'cardinal'
270+
| 'catmullRom'
271+
| 'linear'
272+
| 'monotoneX'
273+
| 'monotoneY'
274+
| 'natural'
275+
| 'step'
276+
| 'stepAfter'
277+
| 'stepBefore';
266278
/**
267279
* Represents the padding between the labels and the shape
268280
*

packages/mermaid/src/diagrams/flowchart/flowDb.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,31 @@ describe('flow db class', () => {
9898
}
9999
});
100100
});
101+
102+
describe('flow db getData', () => {
103+
let flowDb: FlowDB;
104+
beforeEach(() => {
105+
flowDb = new FlowDB();
106+
});
107+
108+
it('should use defaultInterpolate for edges without specific interpolate', () => {
109+
flowDb.addVertex('A', { text: 'A', type: 'text' }, undefined, [], [], '', {}, undefined);
110+
flowDb.addVertex('B', { text: 'B', type: 'text' }, undefined, [], [], '', {}, undefined);
111+
flowDb.addLink(['A'], ['B'], {});
112+
flowDb.updateLinkInterpolate(['default'], 'stepBefore');
113+
114+
const { edges } = flowDb.getData();
115+
expect(edges[0].curve).toBe('stepBefore');
116+
});
117+
118+
it('should prioritize edge-specific interpolate over defaultInterpolate', () => {
119+
flowDb.addVertex('A', { text: 'A', type: 'text' }, undefined, [], [], '', {}, undefined);
120+
flowDb.addVertex('B', { text: 'B', type: 'text' }, undefined, [], [], '', {}, undefined);
121+
flowDb.addLink(['A'], ['B'], {});
122+
flowDb.updateLinkInterpolate(['default'], 'stepBefore');
123+
flowDb.updateLinkInterpolate([0], 'basis');
124+
125+
const { edges } = flowDb.getData();
126+
expect(edges[0].curve).toBe('basis');
127+
});
128+
});

packages/mermaid/src/diagrams/flowchart/flowDb.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ export class FlowDB implements DiagramDB {
252252
labelType: 'text',
253253
classes: [],
254254
isUserDefinedId: false,
255+
interpolate: this.edges.defaultInterpolate,
255256
};
256257
log.info('abc78 Got edge...', edge);
257258
const linkTextObj = type.text;
@@ -1124,6 +1125,7 @@ You have to call mermaid.initialize.`
11241125
look: config.look,
11251126
animate: rawEdge.animate,
11261127
animation: rawEdge.animation,
1128+
curve: rawEdge.interpolate || this.edges.defaultInterpolate || config.flowchart?.curve,
11271129
};
11281130

11291131
edges.push(edge);

packages/mermaid/src/rendering-util/rendering-elements/edges.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,22 @@ import utils from '../../utils.js';
66
import { getLineFunctionsWithOffset } from '../../utils/lineWithOffset.js';
77
import { getSubGraphTitleMargins } from '../../utils/subGraphTitleMargins.js';
88

9-
import { curveBasis, curveLinear, curveCardinal, line, select } from 'd3';
9+
import {
10+
curveBasis,
11+
curveLinear,
12+
curveCardinal,
13+
curveBumpX,
14+
curveBumpY,
15+
curveCatmullRom,
16+
curveMonotoneX,
17+
curveMonotoneY,
18+
curveNatural,
19+
curveStep,
20+
curveStepAfter,
21+
curveStepBefore,
22+
line,
23+
select,
24+
} from 'd3';
1025
import rough from 'roughjs';
1126
import createLabel from './createLabel.js';
1227
import { addEdgeMarkers } from './edgeMarker.ts';
@@ -484,6 +499,33 @@ export const insertEdge = function (elem, edge, clusterDb, diagramType, startNod
484499
case 'cardinal':
485500
curve = curveCardinal;
486501
break;
502+
case 'bumpX':
503+
curve = curveBumpX;
504+
break;
505+
case 'bumpY':
506+
curve = curveBumpY;
507+
break;
508+
case 'catmullRom':
509+
curve = curveCatmullRom;
510+
break;
511+
case 'monotoneX':
512+
curve = curveMonotoneX;
513+
break;
514+
case 'monotoneY':
515+
curve = curveMonotoneY;
516+
break;
517+
case 'natural':
518+
curve = curveNatural;
519+
break;
520+
case 'step':
521+
curve = curveStep;
522+
break;
523+
case 'stepAfter':
524+
curve = curveStepAfter;
525+
break;
526+
case 'stepBefore':
527+
curve = curveStepBefore;
528+
break;
487529
default:
488530
curve = curveBasis;
489531
}

packages/mermaid/src/schemas/config.schema.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2066,7 +2066,21 @@ $defs: # JSON Schema definition (maybe we should move these to a separate file)
20662066
description: |
20672067
Defines how mermaid renders curves for flowcharts.
20682068
type: string
2069-
enum: ['basis', 'linear', 'cardinal']
2069+
enum:
2070+
[
2071+
'basis',
2072+
'bumpX',
2073+
'bumpY',
2074+
'cardinal',
2075+
'catmullRom',
2076+
'linear',
2077+
'monotoneX',
2078+
'monotoneY',
2079+
'natural',
2080+
'step',
2081+
'stepAfter',
2082+
'stepBefore',
2083+
]
20702084
default: 'basis'
20712085
padding:
20722086
description: |

0 commit comments

Comments
 (0)