Live data from Hacker News

Flowchart.js – Simple SVG flow chart diagrams from textual representation

adrai.github.io

21–26 of 26 posts

Re: Flowchart.js – Simple SVG flow chart diagrams from textual representation

#21

Earlier quoted context omitted.

You could use this to convert from SVG to a Canvas element and then from Canvas to an image (via canvas.toDataURL("image/png")): https://github.com/gabelerner/canvg Still needs a very newish browser however. No IE 6-8 (& 9?) support.

I would prefer the SVG itself but this is an ideal short term solution. Thank you very much!

I have written two ways of exporting SVG that you can inspect here: http://staticresource.com/sketch.html

One takes the SVG from the browser, encodes it and sends the as the body of an email (inlined, not as an attachment). Here's the relevant part:

    function render() {
      var link = document.createElement('a'),
          time = Date.now();
      link.href = 'mailto:?  subject=exported%20sketch&body=%3C%3Fxml%20version%3D%221.0%22%20standalone%3D%22no%22%3F%3E%3C!DOCTYPE%20svg%20PUBLIC%20%22-%2F%2FW3C%2F%2FDTD%20SVG%201.1%2F%2FEN%22%20%22http%3A%2F%2Fwww.w3.org%2FGraphics%2FSVG%2F1.1%2FDTD%2Fsvg11.dtd%22%3E'+encodeURIComponent(new XMLSerializer().serializeToString(board));
      link.id = time;
      document.body.appendChild(link);
      document.getElementById(time).dispatchEvent(new MouseEvent('click'));
      document.getElementById(time).parentNode.removeChild(document.getElementById(time));
    }
The other prepares it as a file and creates a download link (not seen on screen) and programmatically clicks that link to download it:

    function download() {
      var link = document.createElement('a'),
          time = Date.now(),
          svg = ''+new XMLSerializer().serializeToString(board);
      link.id = time;
      link.setAttribute('download','sketch.svg');
      link.href = 'data:text/html;charset=utf-8,' + encodeURIComponent(svg);
      document.body.appendChild(link);
      document.getElementById(time).dispatchEvent(new MouseEvent('click'));
      document.getElementById(time).parentNode.removeChild(document.getElementById(time));
    }
But be forewarned, since SVG uses XML namespaces instead of HTML, using things like '.innerHTML' won't work in certain browsers (iOS Mobile Safari for example) while innerHTML does tend to work as you would expect on most desktop browsers!

Canvas would work for exporting a bitmapped snapshot of the vector, but lacks the following:

- filesize: SVG is vector, but Canvas renders a bitmap

- non-destructive: SVG is human-editable after the fact, bitmaps only 'remember' the value of the top-most pixel and 'forgets' everything that has overlapped

- human-editable: Though not pretty, SVG's can be read and edited by hand, bitmaps require a graphics tool to edit easily

Re: Flowchart.js – Simple SVG flow chart diagrams from textual representation

#22
post #5

This is a wonderful tool for simple flow charting. I agree with other posters that a little more documentation would be nice and would also like to request the ability to export the underlying SVG (I'm still browsing source to see if that exists). I'm willing to help add both, thank you for this!

SVG Crowbar might be useful for pulling out the SVG images (unfortunately it's for Chrome only):

http://nytimes.github.io/svg-crowbar/

Re: Flowchart.js – Simple SVG flow chart diagrams from textual representation

#24

Is there something similar to this for making server infrastructure maps? Just something where one can define db, web, network device, whatever, and then make a layout diagram with maybe name and IP address thrown in there? And apologies for another "is there something like this for X" comment!

Check out http://blockdiag.com/ and siblings (seqdiag, actdiag, nwdiag).

They have an interactive shell for it - experiment with http://interactive.blockdiag.com/nwdiag/.

Re: Flowchart.js – Simple SVG flow chart diagrams from textual representation

#26
post #24

Is there something similar to this for making server infrastructure maps? Just something where one can define db, web, network device, whatever, and then make a layout diagram with maybe name and IP address thrown in there? And apologies for another "is there something like this for X" comment!

Check out http://blockdiag.com/ and siblings (seqdiag, actdiag, nwdiag). They have an interactive shell for it - experiment with http://interactive.blockdiag.com/nwdiag/ .

Thanks for this link. I was going to say that graphviz covers it, but blockdiag is much simpler (and with extra features)
Post reply on HN