You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constdiagram=awaitmermaidAPI.getDiagramFromText(text);// ^? const diagram: Diagramif(isFlowchartDiagram(diagram)){const{ db, text }=diagram;// ^? const db: FlowchartDb// type-safety & auto-completion ✅constvertices=db.getVertices();constedges=db.getEdges();// do something with it}
Furthermore, it would be a nice addition if the diagram DB can import JavaScript objects like what's discussed in #518 and #3100.
Motivation
Currently, mermaid-js has been underutilized due to the absence of specific types on Diagram and DiagramDb. It's true that you can getAccTitle with the current interface
Here we can get the vertices or edges without rendering the SVG. This enables us to apply some manipulations to it before rendering the SVG back.
All in all, the usage of mermaidAPI is limited, but merely because the Diagram is any typed. If we have type guards to check the diagram type, we can access each property of the diagram DBs.
Workarounds
Although the solution above would greatly improve overall developer experience, it does not mean that we could not manipulate the nodes right now.
The following code makes every node adds another node connecting to it without any configuration. Here, pre is the Ref object in Vue.js.
However, this is a post-render processing. It would be nice if we could manipulate something after parsing but before rendering to add custom "add-ons" or "middlewares".
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Objective
I would like to achieve something like:
Furthermore, it would be a nice addition if the diagram DB can import JavaScript objects like what's discussed in #518 and #3100.
Motivation
Currently, mermaid-js has been underutilized due to the absence of specific types on Diagram and DiagramDb. It's true that you can
getAccTitle
with the current interfaceHowever, if we take a look at
flowDb.js
, the internal API is more capable than it is!Here we can get the vertices or edges without rendering the SVG. This enables us to apply some manipulations to it before rendering the SVG back.
All in all, the usage of mermaidAPI is limited, but merely because the Diagram is
any
typed. If we have type guards to check the diagram type, we can access each property of the diagram DBs.Workarounds
Although the solution above would greatly improve overall developer experience, it does not mean that we could not manipulate the nodes right now.
The following code makes every node adds another node connecting to it without any configuration. Here,
pre
is the Ref object in Vue.js.However, this is a post-render processing. It would be nice if we could manipulate something after parsing but before rendering to add custom "add-ons" or "middlewares".
Beta Was this translation helpful? Give feedback.
All reactions