adrai / flowchart.js

Draws simple SVG flow chart diagrams from textual representation of the diagram
http://flowchart.js.org/
MIT License
8.57k stars 1.21k forks source link

How to do clickeable elements? #143

Open webserveis opened 6 years ago

hilvarenbeek commented 6 years ago

You add :> and the link after the text, like start=>start: Begin:>https://www.example.org

sarankup commented 6 years ago

Hi, Instead of clickable links to some web pages, is it possible to call a function? For example, start=>start: Begin:>myfoo(1)

adrai commented 6 years ago

https://github.com/adrai/flowchart.js/issues/148#issuecomment-386868790

ChiragSSinghal commented 6 years ago

One way I did it was by selecting the svg elements by their id in js and caliing the addEventListener function. "cond=>condition: Yes or No?\n" This creates an HTML element with id="cond" for the box and id="condt" for "Yes or No?". You can select the object:

var box = document.querySelector("#cond");
var boxText = document.queerySelector("#condt");
box.addEventListener('click', fun() {});
boxText.addEventListener('click', fun() {});

Hope this helps.

mfrey777 commented 5 years ago

If you just use the following syntax, you can call a javascript function: start=>start: Start:>javascript:test('foo');

Is there a security concern with this option ?

adrai commented 5 years ago

In theory yes: XSS => https://github.com/adrai/flowchart.js/issues/176

mfrey777 commented 5 years ago

Thank you for answer. I plan to generate the flowchart definition in a python backend api. So to be safe, I would have to generate the javascript to set onClick eventlistener on all my dom objects (I would prefer not to have to generate javascript code in the backend). It would be great if there was a way to set the onClick function instead of setting the "href"(so to have the option to set an href or a function on onClick eventlistener as a link, that would really make this framework perfect for SPA (reactjs, angular, ...)