Skip to content

Commit

Permalink
Documentation of usage of the mermaidAPI and binding user interaction…
Browse files Browse the repository at this point in the history
… events
  • Loading branch information
knsv committed Oct 3, 2015
1 parent 8bc3bdd commit cb5e88c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
3 changes: 3 additions & 0 deletions dist/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
$(function () {
setupLanguages(["shell", "javascript", "html", "css","mermaid"]);
});
var callback = function(){
alert('A callback was triggered');
}
</script>
</head>

Expand Down
2 changes: 2 additions & 0 deletions docs/content/flowchart.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ graph LR;
```
<aside class="success">The tooltip functionality and the ability to link to urls are available from version 0.5.2.</aside>

When integration mermaid using the mermaidAPI #mermaidapi the function that binds the events need to be run when the finished graph has been added to the page. This is described in the [API usage](#api-usage) section.

## Styling and classes

### Styling links
Expand Down
32 changes: 31 additions & 1 deletion docs/content/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ could be used. The example just logs the resulting svg to the javascript console
});
&lt;/script&gt;
```
##Sample of API usage together with browserify
## Sample of API usage together with browserify
```
$ = require('jquery');
mermaidAPI = require('mermaid').mermaidAPI;
Expand All @@ -170,6 +170,36 @@ $(function(){
});
```

### Binding events

Sometimes the generated graph also has defined interactions like tooltip and click events. When using the API one must
add those events after the graph has been inserted into the DOM.

The example code below is an extract of wheat mermaid does when using the API. The example show how it is possible to
bind events to a svg when using the API for rendering.

```
var insertSvg = function(svgCode, bindFunctions){
element.innerHTML = svgCode;
if(typeof callback !== 'undefined'){
callback(id);
}
bindFunctions(element);
};
var id = 'theGraph';
mermaidAPI.render(id,txt,insertSvg, element);
```

1. The graph is generated using the render call.
2. After generation the render function calls the provided callback function, in this case its called insertSvg.
3. The callback function is called with two parameters, the svg code of the generated graph and a function. This
function binds events to the svg **after** it is inserted into the DOM.
4. Insert the svg code into the DOM for presentation
5. Call the binding function that bainds the events

## Example of a marked renderer

This is the renderer used for transforming the documentation from markdown to html with mermaid diagrams in the html.
Expand Down

0 comments on commit cb5e88c

Please sign in to comment.