Documentation of usage of the mermaidAPI and binding user interaction events

This commit is contained in:
knsv 2015-10-03 16:53:27 +02:00
parent 8bc3bdd300
commit cb5e88c2f1
3 changed files with 36 additions and 1 deletions

3
dist/www/index.html vendored
View File

@ -49,6 +49,9 @@
$(function () {
setupLanguages(["shell", "javascript", "html", "css","mermaid"]);
});
var callback = function(){
alert('A callback was triggered');
}
</script>
</head>

View File

@ -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

View File

@ -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;
@ -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.