mermaid-js / mermaid

Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown
https://mermaid.js.org
MIT License
71.58k stars 6.48k forks source link

Update graph #311

Closed LeonardoRamos closed 6 years ago

LeonardoRamos commented 8 years ago

Hi, I have a question, I have a graph in my page that is loaded as soon the page is fully loaded. I have some menus that allow the user to add nodes and remove nodes, manipulating the graph definition that is inside a textarea, but I'm having difficulties trying to "redraw" the graph. I tried calling "init" again, I tried calling the API, but I have no success in both options. So my question is, how can I re-render the graph?

LeonardoRamos commented 8 years ago

Actually, it works in Firefox, it's not re-rendering the graph only in chrome (I'm using chrome 48) and I tested mermaid versions 5.7, 5.6 and 4.0, none of them worked, only a very old version worked fine (The one used in the editor folder).

knsv commented 8 years ago

Are you using the API for this rendering? It sounds like you should use the render function for this.

Se example in the docs: http://knsv.github.io/mermaid/#api-usage

I hope that helps.

radmilabord commented 7 years ago

Render function works only ones. Did anyone found solution for this? I'm facing same problem.

knsv commented 7 years ago

Looking at this one.

radmilabord commented 7 years ago

I solved it by removing div with graph, adding it back, setting text, calling init method. Same approach is done in "try it" demo. However if rerender function could work, it would be great.

knsv commented 7 years ago

OK. Will continue with it anyway then.

roidayan commented 7 years ago

i know its old but wanted to say i do not delete the entire div but remove the attribute "data-processed". after that calling init on it again seems to work.

radmilabord commented 7 years ago

Thanks! That sounds like a less intrusive approach.

dianaeneida commented 7 years ago

roidayan, ¿could you expose the complete solution here?, please

roidayan commented 7 years ago

my html is:

<div id="mermaid"></div>

and in js I do this on init and each time my data in node.data.graph changes:

$('#mermaid').html(node.data.graph).removeAttr('data-processed');
mermaid.init(undefined, $("#mermaid"));
tylerlong commented 6 years ago

@roidayan 's solution works and I use it too.

hikari-He commented 1 year ago

my html is:

<div id="mermaid"></div>

and in js I do this on init and each time my data in node.data.graph changes:

$('#mermaid').html(node.data.graph).removeAttr('data-processed');
mermaid.init(undefined, $("#mermaid"));

You solved my problem. In addition, this method can work in mermaid 9.1.0, but not work in mermaid 9.4.3.

eduo commented 4 months ago

my html is:

<div id="mermaid"></div>

and in js I do this on init and each time my data in node.data.graph changes:

$('#mermaid').html(node.data.graph).removeAttr('data-processed');
mermaid.init(undefined, $("#mermaid"));

You solved my problem. In addition, this method can work in mermaid 9.1.0, but not work in mermaid 9.4.3.

Did you find a solution? It also doesn't seem to work in mermaid 10, to which I'm trying to migrate. I can't find if it's not explicitly covered in 10.

hikari-He commented 4 months ago

@eduo I didn't find solution, my solution is use mermaid 9.1.0. My front-end skills are limited so I don't quite understand the reasons that why mermaid 9.1.0 can work but other version can't.