Skip to content
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

Add support for changing the length of edges #1613

Merged
merged 1 commit into from
Aug 15, 2020
Merged

Add support for changing the length of edges #1613

merged 1 commit into from
Aug 15, 2020

Conversation

matteodelabre
Copy link
Contributor

@matteodelabre matteodelabre commented Aug 13, 2020

📑 Summary

There is currently no way of influencing the length of (i.e. the number of ranks spanned by) a particular link in a flowchart. A workaround that uses invisible nodes has been proposed in #637. This PR provides an extension of the edge syntax that enables users to request a minimum length for any edge. The length of an edge can be extended by adding extra characters in its definition, as follows:

Length 1 2 3
Normal --- ---- -----
Normal with arrow --> ---> ---->
Thick === ==== =====
Thick with arrow ==> ===> ====>
Dotted -.- -..- -...-
Dotted with arrow -.-> -..-> -...->

Note that this is change backwards compatible, because the syntax for length-1 edges coincides with the existing syntax which already generated length-1 edges. This feature leverages the minlen option exposed by Dagre which was not previously available when using Mermaid.

Resolves #637, resolves #1495.

📏 Design Decisions

The Jison grammar for edges was refactored to avoid handling each combination of edge and arrow types separately. This makes the implementation of the new feature simpler and facilitates the addition of new edge and arrow types. The destructLink and destructStartLink parsing functions were modified accordingly.

A length attribute, containing the length of each parsed edge, is added their internal representation. This attribute’s value is passed down to Dagre in the renderer via the minlen option.

📋 Tasks

Make sure you

  • 📖 have read the contribution guidelines
  • 💻 have added unit/e2e tests (if appropriate)
  • 🔖 targeted develop branch

Resolves #637, resolves #1495.

The syntax for edges is extended to allow for extra
dashes/equals signs/dots (depending on the edge type). Each added
character increases the length of the edge by one rank level, as
follows:

Length            |    1   |    2    |     3    |
------------------|:------:|:-------:|:--------:|
Normal            |  `---` |  `----` |  `-----` |
Normal with arrow |  `-->` |  `--->` |  `---->` |
Thick             |  `===` |  `====` |  `=====` |
Thick with arrow  |  `==>` |  `===>` |  `====>` |
Dotted            |  `-.-` |  `-..-` |  `-...-` |
Dotted with arrow | `-.->` | `-..->` | `-...->` |

This features leverages the `minlen` property exposed by Dagre which was
not previously available when using Mermaid.
@knsv
Copy link
Collaborator

knsv commented Aug 14, 2020

@matteodelabre Nice job Mattéo! I will check this out more closely this weekend!

Copy link
Collaborator

@knsv knsv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! I appreciate that you took your time to add documentation as well as additional tests. This ensures adaption by the userbase and makes sure that the function wont break down the line.

In particular I like what you did in flowDb with determining the link type and in flow.jison with the lexing of links! Also good that the grammar still supports the multi directional arrows that is supported by the new renderer.

But now the beta renderer needs length functionality as well...

Thanks!

@knsv knsv merged commit 93c6272 into mermaid-js:develop Aug 15, 2020
@AndrewScribner
Copy link

if would be great if there was a way to adjust spacing between nodes and line length. This could be a setting (linkStyle maybe) that would allow the length of a line to be adjusted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set depth level for nodes Possible to ensure two items are on the same level/add a sibling connector?
3 participants