Skip to content

Commit 2d583b1

Browse files
fix some pixel issues
Co-authored-by: pranavm2109 <mishrap@dickinson.edu>
1 parent b322392 commit 2d583b1

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

cypress/integration/rendering/journey.spec.js

+4-9
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ section Checkout from website
169169
{ journey: { useMaxWidth: true } }
170170
);
171171

172-
let diagramStartX;
172+
let diagramStartX, maxLineWidth;
173173

174174
// Get the diagram's left edge
175175
cy.contains('foreignobject', 'Sign Up')
@@ -178,22 +178,17 @@ section Checkout from website
178178
})
179179
.then(() => {
180180
cy.get('text.legend').then(($lines) => {
181-
// Check that there are two lines
181+
// Check that there are multiple lines
182182
expect($lines.length).to.be.equal(9);
183183

184184
// Check that all lines are under the max width
185185
$lines.each((index, el) => {
186186
const bbox = el.getBBox();
187187
expect(bbox.width).to.be.lte(320);
188+
maxLineWidth = Math.max(maxLineWidth || 0, bbox.width);
188189
});
189190

190-
// check baseline margin between diagram and legend is maintained
191-
const longestBBox = $lines.get(7).getBBox(); // longest Line's bbox
192-
if (diagramStartX && longestBBox) {
193-
const legendRightEdge = longestBBox.x + longestBBox.width;
194-
const margin = diagramStartX - legendRightEdge;
195-
expect(margin).to.be.closeTo(150, 2);
196-
}
191+
expect(diagramStartX - 150).to.be.closeTo(maxLineWidth, 2);
197192
});
198193
});
199194
});

packages/mermaid/src/diagrams/user-journey/journeyRenderer.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function drawActorLegend(diagram) {
3636

3737
// First, measure the full text width without wrapping.
3838
let measureText = diagram.append('text').attr('visibility', 'hidden').text(person);
39-
const fullTextWidth = measureText.node().getBBox().width;
39+
const fullTextWidth = measureText.node().getBoundingClientRect().width;
4040
measureText.remove();
4141

4242
let lines = [];
@@ -54,7 +54,7 @@ function drawActorLegend(diagram) {
5454
// check the width of the line with the new word.
5555
const testLine = currentLine ? `${currentLine} ${word}` : word;
5656
measureText.text(testLine);
57-
const textWidth = measureText.node().getBBox().width;
57+
const textWidth = measureText.node().getBoundingClientRect().width;
5858

5959
if (textWidth > maxLabelWidth) {
6060
// If adding the new word exceeds max width, push the current line.
@@ -65,12 +65,12 @@ function drawActorLegend(diagram) {
6565

6666
// If the word itself is too long, break it with a hyphen.
6767
measureText.text(word);
68-
if (measureText.node().getBBox().width > maxLabelWidth) {
68+
if (measureText.node().getBoundingClientRect().width > maxLabelWidth) {
6969
let brokenWord = '';
7070
for (const char of word) {
7171
brokenWord += char;
7272
measureText.text(brokenWord + '-');
73-
if (measureText.node().getBBox().width > maxLabelWidth) {
73+
if (measureText.node().getBoundingClientRect().width > maxLabelWidth) {
7474
// Push the broken part with a hyphen.
7575
lines.push(brokenWord.slice(0, -1) + '-');
7676
brokenWord = char;
@@ -102,7 +102,7 @@ function drawActorLegend(diagram) {
102102

103103
// Draw the text and measure the width.
104104
const textElement = svgDraw.drawText(diagram, labelData);
105-
const lineWidth = textElement.node().getBBox().width;
105+
const lineWidth = textElement.node().getBoundingClientRect().width;
106106

107107
// Use conf.leftMargin as the initial spacing baseline,
108108
// but expand maxWidth if the line is wider.

0 commit comments

Comments
 (0)