Skip to content

Commit fe07e9d

Browse files
authored
Merge pull request #5102 from mermaid-js/5100_SankeyViewbox
fix: #5100 Add viewbox to sankey
2 parents a9610d3 + 160c7d3 commit fe07e9d

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

demos/sankey.html

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ <h2>Energy flow</h2>
3333
---
3434
config:
3535
sankey:
36+
useMaxWidth: true
3637
showValues: false
3738
width: 1200
3839
height: 600

packages/mermaid/src/diagrams/sankey/sankeyRenderer.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
sankeyCenter as d3SankeyCenter,
1717
sankeyJustify as d3SankeyJustify,
1818
} from 'd3-sankey';
19-
import { configureSvgSize } from '../../setupGraphViewbox.js';
19+
import { setupGraphViewbox } from '../../setupGraphViewbox.js';
2020
import { Uid } from '../../rendering-util/uid.js';
2121
import type { SankeyNodeAlignment } from '../../config.type.js';
2222

@@ -70,12 +70,6 @@ export const draw = function (text: string, id: string, _version: string, diagOb
7070
const suffix = conf?.suffix ?? defaultSankeyConfig.suffix!;
7171
const showValues = conf?.showValues ?? defaultSankeyConfig.showValues!;
7272

73-
// FIX: using max width prevents height from being set, is it intended?
74-
// to add height directly one can use `svg.attr('height', height)`
75-
//
76-
// @ts-ignore TODO: svg type vs selection mismatch
77-
configureSvgSize(svg, height, width, useMaxWidth);
78-
7973
// Prepare data for construction based on diagObj.db
8074
// This must be a mutable object with `nodes` and `links` properties:
8175
//
@@ -208,6 +202,8 @@ export const draw = function (text: string, id: string, _version: string, diagOb
208202
.attr('d', d3SankeyLinkHorizontal())
209203
.attr('stroke', coloring)
210204
.attr('stroke-width', (d: any) => Math.max(1, d.width));
205+
206+
setupGraphViewbox(undefined, svg, 0, useMaxWidth);
211207
};
212208

213209
export default {

packages/mermaid/src/setupGraphViewbox.js

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const configureSvgSize = function (svgElem, height, width, useMaxWidth) {
4545
d3Attrs(svgElem, attrs);
4646
};
4747

48+
// TODO v11: Remove the graph parameter. It is not used.
4849
export const setupGraphViewbox = function (graph, svgElem, padding, useMaxWidth) {
4950
const svgBounds = svgElem.node().getBBox();
5051
const sWidth = svgBounds.width;

0 commit comments

Comments
 (0)