-
-
Notifications
You must be signed in to change notification settings - Fork 6.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
Allow underscore as an "anonymous indentifier" #6073
Comments
@Hi-Angel Even if those nodes are not being referenced elsewhere, there may come a time when they are. Mermaid does not know if they are going to be referenced later, so all nodes need some sort of ID. If there are two nodes defined with the same ID, the last one will overwrite any of the ones prior, so you will only see one box. I dont think it makes sense given the overall structure of the syntax to have "anonymous" boxes. They need an ID in order to be rendered |
I'm not sure I understand. If "time comes that the node become referenced", this means the user has to replace |
As a side-note, I think this warrants a warning, because if a user has overwritten one node with another, that implies the first node could as well not exist, which in turn implies there's some sort of mistake on the user's part: either they created an unnecessary node, or they accidentally created a name that overlaps with existing one. |
@jgreywolf hello, can you please remove tags "Awaiting for Reply" and "Close after 30 days" since they're no longer relevant |
@sidharthv96 @knsv Can one of you look at this and make a recommendation? |
Sorry, isn't this project the mermaid? Is there another "mermaid" project?
I presume here you're talking about how would that be handled internally by mermaid-js. I don't see how that would break existing diagrams. The side-effect from adding such feature (that would influence existing diagrams) is that if someone named two elements with That is, for an existing diagram to break by such feature you need someone to be naming more than one element with underscore |
…now that I posted, my another hypothesis that you meant to say that if you handle the feature by generating an internal ID by doing an increment, such ID may collide with an existing ID. In that case the solution seems simple: just peek at the list of IDs before assigning a new name to check that such name doesn't exist. If you save existing ID's in a hashset or hashtable, then search is a O(1) operation, so very fast. Also, rather than increment, you can randomly generate the name. |
The screenshot I posted was of TypeScript, I was pointing out that programming languages also does not allow multiple
Yup
By break, I mean render differently. They might've used the eg: The following chart would be rendered differently, if we started attaching internal IDs for every
|
Ah, well, of course not every existing lang allows it, but many modern ones do. Offhand: Go, Rust, Haskell, Elisp, PureScript…
I see. You can avoid this problem by internally naming the first underscore |
This is not addressing the concern for existing diagrams, but something that I think Sid is saying here is that if you have multiple elements that are just _, and then we try to assign a "random" "unique" id to each of those, they will all be treated as separate entities, even if, in theory, some of them may be referring to the same object. |
As I noted above, I don't see a legitimate case for a diagram with multiple elements named the same. Do you know one? Besides, in this feature we're not talking about "any diagram with multiple elements with same name", but exactly about a diagram "with multiple elements named Besides, is it even a documented behavior that repeating identifier declaration overwrites previous one? |
Proposal
Not every block in the diagram has to be referenced. For example, given this one:
FOO1
,FOO2
,BAR1
andBAR2
are unused. So reading the sources would be simpler if the variables weren't created, because it becomes immediately clear which parts don't have any references to them.In modern programming languages that's usually achieved by replacing the identifier name to a underscore
_
. However when doing the same to the diagram above, almost every block just disappears from the diagram:Example
Screenshots
No response
The text was updated successfully, but these errors were encountered: