Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/fruity-ghosts-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'mermaid': patch
---

fix: Arrow blocks in block-beta diagrams not spanning the specified number of columns when using :n syntax.
22 changes: 22 additions & 0 deletions cypress/integration/rendering/block.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,28 @@ columns 3
{}
);
});

it('BL35: block arrow should span multiple columns when widthInColumns is set', () => {
imgSnapshotTest(
`block-beta
columns 10

arrow<["span 10"]>(x):10
A
B
C
D
E
F
G
H
I
J
`,
{}
);
});

it('BL35: mixed column spans should not shrink column widths (issue #7503)', () => {
imgSnapshotTest(
`block-beta
Expand Down
6 changes: 4 additions & 2 deletions packages/mermaid/src/dagre-wrapper/blockArrowHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const expandAndDeduplicateDirections = (directions: Direction[]) => {
export const getArrowPoints = (
duplicatedDirections: Direction[],
bbox: { width: number; height: number },
node: any
node: any,
totalWidth?: number
) => {
// Expand and deduplicate the provided directions.
// for instance: x, right => right, left
Expand All @@ -38,7 +39,8 @@ export const getArrowPoints = (
// Midpoint calculation based on height.
const midpoint = height / f;
// Calculated width of the bounding box, accounting for additional width and node padding.
const width = bbox.width + 2 * midpoint + node.padding;
// When totalWidth is provided
const width = totalWidth ?? bbox.width + 2 * midpoint + node.padding;
// Padding to use, half of the node padding.
const padding = node.padding / 2;

Expand Down
7 changes: 5 additions & 2 deletions packages/mermaid/src/dagre-wrapper/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,12 @@ const block_arrow = async (parent, node) => {
const f = 2;
const h = bbox.height + 2 * node.padding;
const m = h / f;
const w = bbox.width + 2 * m + node.padding;
const naturalW = bbox.width + 2 * m + node.padding;
// Only use the layout-computed width when the block explicitly spans multiple columns
const isSpanning = node.positioned && (node.widthInColumns ?? 1) > 1 && node.width > naturalW;
const w = isSpanning ? node.width : naturalW;

const points = getArrowPoints(node.directions, bbox, node);
const points = getArrowPoints(node.directions, bbox, node, w);

const blockArrow = insertPolygonShape(shapeSvg, w, h, points);
blockArrow.attr('style', node.style);
Expand Down
1 change: 1 addition & 0 deletions packages/mermaid/src/diagrams/block/renderHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function getNodeFromBlock(block: Block, db: BlockDB, positioned = false) {
intersect: undefined,
type: vertex.type,
padding: padding ?? getConfig()?.block?.padding ?? 0,
widthInColumns: vertex.widthInColumns ?? 1,
};
return node;
}
Expand Down
Loading