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

sequenceDiagram Links #1279

Open
guyellis opened this issue Feb 26, 2020 · 20 comments · May be fixed by #6158
Open

sequenceDiagram Links #1279

guyellis opened this issue Feb 26, 2020 · 20 comments · May be fixed by #6158
Labels
Graph: Sequence Status: Approved Is ready to be worked on Type: Enhancement New feature or request

Comments

@guyellis
Copy link
Contributor

sequenceDiagram Links

In searching through the docs and trying this out it seems that many of the diagrams support both anchor and JS "links." However, I can't find how to add a link to sequenceDiagram. Basically I want a sequenceDiagram to have one or more clickable links to static pages.

Are links already implemented for sequenceDiagram? If so what are the basics and I'll do a PR to add this to the docs?

If links are not part of sequenceDiagrams do you expect this to be difficult to add and if I wanted to PR this in which file would I first poke around to make this change?

Thanks.

@guyellis guyellis added Contributor needed Type: Other Not an enhancement or a bug labels Feb 26, 2020
@github-actions github-actions bot added the Status: Triage Needs to be verified, categorized, etc label Feb 26, 2020
@guyellis
Copy link
Contributor Author

A quick look at https://github.com/mermaid-js/mermaid/blob/develop/src/diagrams/sequence/parser/sequenceDiagram.jison and also at https://github.com/mermaid-js/mermaid/blob/develop/src/diagrams/gantt/parser/gantt.jison seems to indicate that the latter has it implemented but not the former.

I think that answers my first question.

What would be the "level of effort" required for somebody who does not have experience with this parsing syntax to implement something like this?

@jgreywolf jgreywolf added Type: Enhancement New feature or request and removed Type: Other Not an enhancement or a bug labels Feb 2, 2021
@angularsen
Copy link

I would love to link from parts of a sequence diagram to source code:

  • Actor
  • Message (arrows)
  • Note
  • Loop
  • Alt
  • Parallel

This way I could add links to file/line number in source code for particular interactions.

Taking it further, hidden notes:

  • Add a note with markdown syntax to an actor, message etc.
  • A small indicator shows that a note is available.
  • Clicking the indicator, or the actor/message itself, would show the note in some popup.

The current Note support is very limited in the visual space it is allowed to take up, at least for sequence diagrams.

@Cussa
Copy link

Cussa commented May 24, 2021

Hi, is there any idea if this would be implemented?

@codewicked
Copy link

+1 on adding links to notes and messages

@mwlang
Copy link

mwlang commented Feb 17, 2022

+1 -- this would be really useful

@krzysztofwysocki
Copy link

+1 this would be useful and consistent with other types of diagrams.
Possible syntax would be for example adding this at the end of diagram:

class A,B internal-link;

@jgreywolf
Copy link
Contributor

If possible the syntax should be the same as it is in other diagrams. I will look into this over the weekend

@jgreywolf jgreywolf self-assigned this Feb 10, 2023
@davenforce
Copy link

I would also love this.

@jgreywolf jgreywolf added Status: Approved Is ready to be worked on Graph: Sequence and removed Contributor needed Status: Triage Needs to be verified, categorized, etc labels Mar 7, 2023
@gfranxman
Copy link

This would be super useful. I don't know about everyone else, but I use sequence diagrams for describing what happened for failure analysis, and would like to be able to link to supporting evidence. Things like logs, run books, source code, etc. If not on the messages, then maybe the activations.

@dagadbm
Copy link

dagadbm commented Jun 1, 2023

this could also be useful to separate and hide complexity in diagrams something like

 A->>B: complexOperation

and then clicking it would show anchor to the corresponding complexOperation diagram.

@oaxlin
Copy link

oaxlin commented Jun 6, 2023

I would love this as well. But mostly so I can link from one diagram to another.

Basically having a larger overarching diagram that links to a smaller diagram. Especially if that smaller diagram is used in many places.

@kamalraghav81
Copy link

Add a small pop-up of the link. Could be linked to a requirement page.

@TrentBrown
Copy link

+1 for adding links to sequence diagrams. If y'all have any spare cycles, this is a lot of bang for the buck. Takes sequence diagrams to the next level

@liamhalemccarty
Copy link

+1!

@krzysztofwysocki
Copy link

krzysztofwysocki commented Feb 1, 2024

+1! truly needed. I plan to link messages to data model elements. Imagine that you can click message and see diagram of linked data structure. That would make sequence diagram part of system design rather than standalone set of pictures.

@THONGJI
Copy link

THONGJI commented Feb 2, 2024

Found a way to use hyperlink in the sequence diagram.
Hope there is an elegant way to do this.
Below is the sample code, click on the link and redirect to another diagram:

image
image
image

SD - Get Users (Cloud).html

<html lang="en">
	<head>
		<style>
			.hyplink {
				font-weight: bolder;
				font-style: italic;
				text-decoration: underline;
			}
		</style>
	</head>
	<body>
		<pre class="mermaid">
			sequenceDiagram
				participant APP AS MOBILE APP
				participant BFF AS BFF
				participant SRC AS SOURCE SYSTEM
				APP->>BFF: GET /users
				BFF->>SRC: <a class="hyplink" href="./SD - Get Users (Source System).html" target="blank">GET /user/list</a>
				SRC-->>BFF: User[] (id, name, identificationNumber)
				BFF-->>BFF: Remove or mask User[] sensitive data
				BFF-->>APP: User[] (maskedName, maskedIdentificationNumber)
		</pre>
		<script type="module">
			import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';

			// Wait for render
			setTimeout(() => {
				var encodedHtmlEntitiesRegex = /(&lt;|&gt;|&amp;|&#39;|&quot;)/g;
				var elems = document.getElementsByClassName('messageText');
				for (var i = 0; i < elems.length; i++) {
					// Replace encoded values.
					elems[i].innerHTML = elems[i]?.innerHTML?.replace(encodedHtmlEntitiesRegex, 
						tag => ({
							'&amp;': '&',
							'&lt;': '<',
							'&gt;': '>',
							'&#39;': "'",
							'&quot;': '"'
						}[tag]));
				}
			}, 100); // Add more value here if fail to replace encoded value.
		</script>
	</body>
</html>```

SD - Get Users (Source System).html
```<!DOCTYPE html>
<html lang="en">
	<head>
		<style>
			.hyplink {
				font-weight: bolder;
				font-style: italic;
				text-decoration: underline;
			}
		</style>
	</head>
	<body>
		<pre class="mermaid">
			sequenceDiagram
				participant ANY AS ANY SYSTEM
				participant SRC AS SOURCE SYSTEM
				participant PGDB AS POSTGRES DB
				ANY->>SRC: GET /user/list
				SRC->>PGDB: SELECT * FROM <a class="hyplink" href="./ERD - PGDB - USER.html" target="blank">USER</a>;
				PGDB-->>SRC: User[] (id, name, identificationNumber)
				SRC-->>ANY: User[] (id, name, identificationNumber)
		</pre>
		<script type="module">
			import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';

			// Wait for render
			setTimeout(() => {
				var encodedHtmlEntitiesRegex = /(&lt;|&gt;|&amp;|&#39;|&quot;)/g;
				var elems = document.getElementsByClassName('messageText');
				for (var i = 0; i < elems.length; i++) {
					// Replace encoded values.
					elems[i].innerHTML = elems[i]?.innerHTML?.replace(encodedHtmlEntitiesRegex, 
						tag => ({
							'&amp;': '&',
							'&lt;': '<',
							'&gt;': '>',
							'&#39;': "'",
							'&quot;': '"'
						}[tag]));
				}
			}, 100); // Add more value here if fail to replace encoded value.
		</script>
	</body>
</html>```

ERD - PGDB - USER.html
```<!DOCTYPE html>
<html lang="en">
	<head>
		<style>
			.hyplink {
				font-weight: bolder;
				font-style: italic;
				text-decoration: underline;
			}
		</style>
	</head>
	<body>
		<pre class="mermaid">
			erDiagram
				USER {
					string id
					string name
					string identificationNumber
				}
		</pre>
		<script type="module">
			import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';

			// Wait for render
			setTimeout(() => {
				var encodedHtmlEntitiesRegex = /(&lt;|&gt;|&amp;|&#39;|&quot;)/g;
				var elems = document.getElementsByClassName('messageText');
				for (var i = 0; i < elems.length; i++) {
					// Replace encoded values.
					elems[i].innerHTML = elems[i]?.innerHTML?.replace(encodedHtmlEntitiesRegex, 
						tag => ({
							'&amp;': '&',
							'&lt;': '<',
							'&gt;': '>',
							'&#39;': "'",
							'&quot;': '"'
						}[tag]));
				}
			}, 100); // Add more value here if fail to replace encoded value.
		</script>
	</body>
</html>```

@awangatsanjel
Copy link

Is this feature being worked on? I am looking forward to it.

@moddx
Copy link

moddx commented Oct 10, 2024

While @THONGJI 's solution works I end up with diagrams that are much too wide, because the width of the lines/rects are calculated with the length of the original content and are then fixed.

I tried to dig through https://github.com/mermaid-js/mermaid/blob/develop/packages/mermaid/src/diagrams/sequence/ to find where the html elements get escaped, but could not find it.
Mermaid allows you to pass a DompurifyConfig straight to DomPurify, but that did not seem to help for sequenceDiagrams either.

I'm thinking of creating a custom SequenceDiagram type that allows html/svg Elements (mostly interested in honestly) in the messageText.

Does anyone know where the html gets escaped/purified?

@DanielSmithGK
Copy link

Our company goes the markdown way when it comes to documentation, including mermaid diagrams. This feature would greatly help with thinning out procedure descriptions by being able to link directly from the diagram instead of having to add the links below the diagram additionally. This could greatly reduce possible misunderstandings / increase intuitiveness.

While technically @THONGJI's workaround may work, it is nothing that could be used as a widespread alternative that I can suggest to other teams that face the same challenge. Maintaining/updating this way poses an additional challenge. This is simply beyond the intended markdown editing scope for many.

Is there any update on the progress or at least a timeframe when this issue will be tackled? Any help is greatly appreciated.

Thanks and regards
Daniel

@jgreywolf jgreywolf removed their assignment Dec 20, 2024
@ryanwjackson ryanwjackson linked a pull request Dec 29, 2024 that will close this issue
4 tasks
@ryanwjackson
Copy link

I've taken a stab at a solution in PR #6158, which add's markdown-style linking capability to arrow message and note text. One known limitation is that the code is not rendering target="_blank" so that clicks open a new tab/window. I tried to replicate where links are rendered elsewhere, but admittedly I'm not an expert at SVG rendering. So any tips are welcome!

I also may have not done this in the appropriate spots, but I tried to make it reusable in case there's desire to render links in other types of diagrams or parts of sequence diagrams.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Graph: Sequence Status: Approved Is ready to be worked on Type: Enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.