Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This continues #765. Currently, links don’t cover the full node area, just a line within the foreignObject. This PR changes that.
Design
I don’t pass
labelType
to the renderer anymore, but construct SVG in all cases. I useaddHtmlLabel
fromdagre-d3-renderer
instead of duplicating its code for this.That’s necessary because
dagre-d3-renderer
doesn’t offer a hook to postprocess rendered SVG nodes – if it did, we could simply use that hook to wrap the SVG group in an SVG link.TODOs
Unfortunately this needs to render the vertices in a live SVG instead of delaying that to the renderer: I had to add a parameter to
addVertices
to achieve that, I hope that’s acceptable. The reason is that inaddHtmlLabel
, the renderer needs to retrieve the bounding box of the foreignObject contents in order to set the node size. Without a live SVG there’s no bounding box, so if we want to calladdHtmlLabel
ourselves instead of letting the renderer do it, we need the live SVG.I’m not sure if we do
labelType: text
, but if we do, I need to adapt this PR for it (currently it’s not handled I think)Finally, the sizes aren’t perfectly determined for clickable non-link nodes. I don’t know what causes that, maybe someone can help:
(note the g in „Shopping“)
Alternatives
We do some postprocessing, so instead of this, we could save the link into a node’s
data-link
attribute and wrap the nodes in a postprocessing step herehttps://github.com/knsv/mermaid/blob/12b58a17e10988b1cc7790f721e4e59fc6150d52/src/diagrams/flowchart/flowRenderer.js#L405-L410
That would be easier but less elegant and less performant. (we’d have to touch each label, replace it with a link node, and insert it below that link node again. Many many DOM manipulations)
We could enhance
dagre-d3-renderer
with first-class link support or a postprocessing hook. The hook has the same problem as alternative 1 and it’s unclear if enhancing it by a link property has a place in the current dagre node model. Would need some investigation.Tests
By introducing ES6 imports from
node_modules
, I had to change the way the babel config is loaded (see d78b33c). What I did is described here.