Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: restore curve type configuration functionality for flowcharts #6408

Merged
merged 2 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/curve-interpolation-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'mermaid': minor
---

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:

- Config
- Init directive (%%{ init: { 'flowchart': { 'curve': '...' } } }%%)
- LinkStyle command (linkStyle default interpolate ...)
14 changes: 13 additions & 1 deletion packages/mermaid/src/config.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,19 @@ export interface FlowchartDiagramConfig extends BaseDiagramConfig {
* Defines how mermaid renders curves for flowcharts.
*
*/
curve?: 'basis' | 'linear' | 'cardinal';
curve?:
| 'basis'
| 'bumpX'
| 'bumpY'
| 'cardinal'
| 'catmullRom'
| 'linear'
| 'monotoneX'
| 'monotoneY'
| 'natural'
| 'step'
| 'stepAfter'
| 'stepBefore';
/**
* Represents the padding between the labels and the shape
*
Expand Down
28 changes: 28 additions & 0 deletions packages/mermaid/src/diagrams/flowchart/flowDb.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,31 @@ describe('flow db class', () => {
}
});
});

describe('flow db getData', () => {
let flowDb: FlowDB;
beforeEach(() => {
flowDb = new FlowDB();
});

it('should use defaultInterpolate for edges without specific interpolate', () => {
flowDb.addVertex('A', { text: 'A', type: 'text' }, undefined, [], [], '', {}, undefined);
flowDb.addVertex('B', { text: 'B', type: 'text' }, undefined, [], [], '', {}, undefined);
flowDb.addLink(['A'], ['B'], {});
flowDb.updateLinkInterpolate(['default'], 'stepBefore');

const { edges } = flowDb.getData();
expect(edges[0].curve).toBe('stepBefore');
});

it('should prioritize edge-specific interpolate over defaultInterpolate', () => {
flowDb.addVertex('A', { text: 'A', type: 'text' }, undefined, [], [], '', {}, undefined);
flowDb.addVertex('B', { text: 'B', type: 'text' }, undefined, [], [], '', {}, undefined);
flowDb.addLink(['A'], ['B'], {});
flowDb.updateLinkInterpolate(['default'], 'stepBefore');
flowDb.updateLinkInterpolate([0], 'basis');

const { edges } = flowDb.getData();
expect(edges[0].curve).toBe('basis');
});
});
2 changes: 2 additions & 0 deletions packages/mermaid/src/diagrams/flowchart/flowDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ export class FlowDB implements DiagramDB {
labelType: 'text',
classes: [],
isUserDefinedId: false,
interpolate: this.edges.defaultInterpolate,
};
log.info('abc78 Got edge...', edge);
const linkTextObj = type.text;
Expand Down Expand Up @@ -1124,6 +1125,7 @@ You have to call mermaid.initialize.`
look: config.look,
animate: rawEdge.animate,
animation: rawEdge.animation,
curve: rawEdge.interpolate || this.edges.defaultInterpolate || config.flowchart?.curve,
};

edges.push(edge);
Expand Down
44 changes: 43 additions & 1 deletion packages/mermaid/src/rendering-util/rendering-elements/edges.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,22 @@ import utils from '../../utils.js';
import { getLineFunctionsWithOffset } from '../../utils/lineWithOffset.js';
import { getSubGraphTitleMargins } from '../../utils/subGraphTitleMargins.js';

import { curveBasis, curveLinear, curveCardinal, line, select } from 'd3';
import {
curveBasis,
curveLinear,
curveCardinal,
curveBumpX,
curveBumpY,
curveCatmullRom,
curveMonotoneX,
curveMonotoneY,
curveNatural,
curveStep,
curveStepAfter,
curveStepBefore,
line,
select,
} from 'd3';
import rough from 'roughjs';
import createLabel from './createLabel.js';
import { addEdgeMarkers } from './edgeMarker.ts';
Expand Down Expand Up @@ -484,6 +499,33 @@ export const insertEdge = function (elem, edge, clusterDb, diagramType, startNod
case 'cardinal':
curve = curveCardinal;
break;
case 'bumpX':
curve = curveBumpX;
break;
case 'bumpY':
curve = curveBumpY;
break;
case 'catmullRom':
curve = curveCatmullRom;
break;
case 'monotoneX':
curve = curveMonotoneX;
break;
case 'monotoneY':
curve = curveMonotoneY;
break;
case 'natural':
curve = curveNatural;
break;
case 'step':
curve = curveStep;
break;
case 'stepAfter':
curve = curveStepAfter;
break;
case 'stepBefore':
curve = curveStepBefore;
break;
default:
curve = curveBasis;
}
Expand Down
16 changes: 15 additions & 1 deletion packages/mermaid/src/schemas/config.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2066,7 +2066,21 @@ $defs: # JSON Schema definition (maybe we should move these to a separate file)
description: |
Defines how mermaid renders curves for flowcharts.
type: string
enum: ['basis', 'linear', 'cardinal']
enum:
[
'basis',
'bumpX',
'bumpY',
'cardinal',
'catmullRom',
'linear',
'monotoneX',
'monotoneY',
'natural',
'step',
'stepAfter',
'stepBefore',
]
default: 'basis'
padding:
description: |
Expand Down
Loading