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

tutorial for creating new type of graph/layout #44

Closed
NeomMob opened this issue Dec 10, 2014 · 2 comments
Closed

tutorial for creating new type of graph/layout #44

NeomMob opened this issue Dec 10, 2014 · 2 comments
Labels
Type: Other Not an enhancement or a bug

Comments

@NeomMob
Copy link

NeomMob commented Dec 10, 2014

Hello,

Could you tell us how (even quickly) the steps to create a new type of diagram/layout?

Thanks for your help!

@knsv
Copy link
Collaborator

knsv commented Dec 10, 2014

Sure!

Hope the text below helps. Will add this to the wiki as well. Don't hesitate to add to that text if there are steps that could be better explained.

Things to be done for a new diagram type:

Step 1: Grammar & Parsing

Grammar

This would be to define a jison grammar for the new diagram type. That should start with a way to identify that the text in the mermaid tag is a diagram of that type. This leads us to step 2.

Store data found during parsing

There are some jison specific sub steps here where the parser stores the data encountered when parsing the diagram, this data is later used by the renderer.

Step 2: Rendering

Write a renderer that given the data found during parsing renders the diagram. To look at an example look at sequendeRenderer.js rather then the flowchart renderer as this is a more generic example.

Step 3: Detection of the new diagram type

The second thing to do is to add the capability to detect the new new diagram to type to the detectType in utils.js. The detection should return a key for the new diagram type.

Step 4: The final piece - triggering the renderinging

At this point when mermaid is trying to render the diagram it will detect it as being of the new type but there will be no match when trying to render the diagram. To fix this add a new case in the switch statement in main.js:init this should match the diagram type returned from step num 2. The code in this new case statement should call the renderer for the diagram type with the data found by the parser as an argument

@knsv knsv added the Type: Other Not an enhancement or a bug label Dec 13, 2014
@knsv
Copy link
Collaborator

knsv commented Dec 15, 2014

Its in the wikie. Closing this. Let me know if anything is unclear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Other Not an enhancement or a bug
Projects
None yet
Development

No branches or pull requests

2 participants