-
-
Notifications
You must be signed in to change notification settings - Fork 7k
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: Prevent Legend Labels from Overlapping Diagram Elements in Journey Diagrams #6274
base: develop
Are you sure you want to change the base?
Changes from 6 commits
fbac4c6
5366e8b
db4ea02
d618b83
5f7c68d
27912be
9ef3554
5dab86a
1424127
a318ea3
50816a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,12 @@ export const setConf = function (cnf) { | |
}; | ||
|
||
const actors = {}; | ||
let maxWidth = 0; | ||
|
||
/** @param diagram - The diagram to draw to. */ | ||
function drawActorLegend(diagram) { | ||
const conf = getConfig().journey; | ||
maxWidth = 0; | ||
// Draw the actors | ||
let yPos = 60; | ||
Object.keys(actors).forEach((person) => { | ||
|
@@ -39,14 +41,18 @@ function drawActorLegend(diagram) { | |
text: person, | ||
textMargin: conf.boxTextMargin | 5, | ||
}; | ||
svgDraw.drawText(diagram, labelData); | ||
|
||
const textElement = svgDraw.drawText(diagram, labelData); | ||
const textLength = textElement.node().getBBox().width; | ||
if (textLength > maxWidth) { | ||
maxWidth = textLength; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not blocker: We should keep this dynamic width part, but should we split the text into more lines, if it's longer that a longer max limit? |
||
yPos += 20; | ||
}); | ||
} | ||
// TODO: Cleanup? | ||
const conf = getConfig().journey; | ||
const LEFT_MARGIN = conf.leftMargin; | ||
let leftMargin = 0; | ||
export const draw = function (text, id, version, diagObj) { | ||
const conf = getConfig().journey; | ||
|
||
|
@@ -84,31 +90,32 @@ export const draw = function (text, id, version, diagObj) { | |
}); | ||
|
||
drawActorLegend(diagram); | ||
bounds.insert(0, 0, LEFT_MARGIN, Object.keys(actors).length * 50); | ||
leftMargin = conf.leftMargin + maxWidth - 22.328125; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is |
||
bounds.insert(0, 0, leftMargin, Object.keys(actors).length * 50); | ||
drawTasks(diagram, tasks, 0); | ||
|
||
const box = bounds.getBounds(); | ||
if (title) { | ||
diagram | ||
.append('text') | ||
.text(title) | ||
.attr('x', LEFT_MARGIN) | ||
.attr('x', leftMargin) | ||
.attr('font-size', '4ex') | ||
.attr('font-weight', 'bold') | ||
.attr('y', 25); | ||
} | ||
|
||
const height = box.stopy - box.starty + 2 * conf.diagramMarginY; | ||
const width = LEFT_MARGIN + box.stopx + 2 * conf.diagramMarginX; | ||
const width = leftMargin + box.stopx + 2 * conf.diagramMarginX; | ||
|
||
configureSvgSize(diagram, height, width, conf.useMaxWidth); | ||
|
||
// Draw activity line | ||
diagram | ||
.append('line') | ||
.attr('x1', LEFT_MARGIN) | ||
.attr('x1', leftMargin) | ||
.attr('y1', conf.height * 4) // One section head + one task + margins | ||
.attr('x2', width - LEFT_MARGIN - 4) // Subtract stroke width so arrow point is retained | ||
.attr('x2', width - leftMargin - 4) // Subtract stroke width so arrow point is retained | ||
.attr('y2', conf.height * 4) | ||
.attr('stroke-width', 4) | ||
.attr('stroke', 'black') | ||
|
@@ -234,7 +241,7 @@ export const drawTasks = function (diagram, tasks, verticalPos) { | |
} | ||
|
||
const section = { | ||
x: i * conf.taskMargin + i * conf.width + LEFT_MARGIN, | ||
x: i * conf.taskMargin + i * conf.width + leftMargin, | ||
y: 50, | ||
text: task.section, | ||
fill, | ||
|
@@ -258,7 +265,7 @@ export const drawTasks = function (diagram, tasks, verticalPos) { | |
}, {}); | ||
|
||
// Add some rendering data to the object | ||
task.x = i * conf.taskMargin + i * conf.width + LEFT_MARGIN; | ||
task.x = i * conf.taskMargin + i * conf.width + leftMargin; | ||
task.y = taskPos; | ||
task.width = conf.diagramMarginX; | ||
task.height = conf.diagramMarginY; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the cy.then required, when it's not used in other functions?