Skip to content

Commit

Permalink
use new mermaid startOnLoad behavior and update js
Browse files Browse the repository at this point in the history
  • Loading branch information
timelyportfolio committed Jan 6, 2015
1 parent 8c8cb73 commit 3763ce3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
30 changes: 29 additions & 1 deletion inst/htmlwidgets/DiagrammeR.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ HTMLWidgets.widget({
as soon as class of the div is set to "mermaid"
*/

/* to prevent auto init() by mermaid
not documented but
see lines https://github.com/knsv/mermaid/blob/master/src/main.js#L100-L109
mermaid_config in global with mermaid_config.startOnLoad = false
appears to turn off the auto init behavior
allowing us to callback after manually init and then callback
after complete
*/
window.mermaid.startOnLoad = false;

return {
// TODO: add instance fields as required
}
Expand All @@ -33,16 +43,34 @@ HTMLWidgets.widget({
el.style.display = "";
//again if dynamic such as shiny
// explicitly run mermaid.init()
mermaid.init();
} else {
// set display to none
// should we remove instead??
el.style.display = "none";
}

this.manualRender( function(){
var svg = el.getElementsByTagName("svg")[0]
if(svg.width) {svg.removeAttribute("width")};
if(svg.height) {svg.removeAttribute("height")};
svg.style.width = "100%";
svg.style.height = "100%";
} );
},

resize: function(el, width, height, instance) {

},

manualRender: function( callback ){
/* not optimal way to manually run and wait for
mermaid.init() before other steps
*/
mermaid.init();
// currently just using to make "responsive" svg
// but could apply to a list of callbacks / behaviors
callback();
}


});
Loading

0 comments on commit 3763ce3

Please # to comment.