-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
To SVG Export #146
Comments
I can see how such function would be useful and I am all for making integration easier. A bit tricky to achive though as the DOM is used when creating the SVG. Perhaps the shadow DOM could be used or some fake DOM. There is another approach also being discussed where you instead of running init call with a list of the elements you want processed. This way will be available sooner then the toSVG function. So I am all for this but further down the roadmap unless someone whats to help out with it. |
I see. I guess, something like mermaid.render(text: string, el: HTMLEement); Then we could get rid of the |
And maybe if var svg = mermaid.render(text: string): HTMLElement; |
I like that idea! It does need to work stand alone as well though. But it would make sense to separate the actual core of mermaid from the code that is used for the standard integration on a website. This way an API could make functionality available for integrators without the parts that are no required in that context.
|
👍 for .render(); |
Why is the DOM needed to generate the diagrams? Could it work with something like cheerio? |
@unindented I guess, because it uses |
@streamich But
|
I think it should be possible but will need some re-work. For instance d3.select is used in some occasions, per default the selection will look in the DOM for the element. Those needs to be redirected to the virtual DOM instead etc. This will also simplify rendering tests. |
Did a POC using jsdom that managed to render the code. The library too quite a leap in size though so this probably not a good option in this case. We have a DOM in the browser so why mock it? Thinking that using a shadow DOM or a hidden element in the DOM for the rendering is a better alternative. The shadow DOM seems still to have low browser support though. That leaves us with the option of rendering the svg in a new hidden element where it will only be during the generation. Once the generation is done the svg code could be extracted from the element and returned. The element would then be removed. Not as clean us using cheerio or jsdom I guess but more practical. Any reassons not to use this approach? If so what are the better options? |
@knsv Because of my use case (generating graphs in node.js), I'd rather not rely on the browser for anything. Spinning up PhantomJS for each diagram is super heavy. Could we do feature detection, where if the library is running in the browser it uses its DOM, and if not it loads jsdom? I guess |
@knsv Ah, it doesn't do feature detection: http://stackoverflow.com/questions/19080929/d3js-how-to-generate-standalone-svg-files-nodejs |
@knsv Ok, I found the answer. They seem to rely on the |
how about this... In the rendering code mermaid checks to see if there is a document object available. If the document object is available it is used. jsdom is put as an external dependency meaning that the code using it needs to installing via npm in that project. |
Sounds reasonable to me. |
Ran into a pit, it seems jsdom wont to the trick either: It is tempting to start using dagre instead of dagre-d3 but that is a larger project. Will try with phantomjs just to see if it works even though it is super heavy. At least the render method will be in place. I am open for alternatives ideas though. |
Damn. Thank you for looking into it though. |
…text Updated build scripts New way for bundling content in dist, tobe tested, currently to be considered beta
A fix for this has been released in version 0.5.0. Will however open a new issue to implement the render function using phantomjs for the server side environment. |
is there a solution for easy transform of test to svg on the server, now? |
I've got this working with https://github.com/exupero/saveSvgAsPng |
How to use mermaid on node.js restful api? I'm not an expert with javascript. Below is how I did it. const express = require('express'); app.get('/chart', (req, res) => { res.status(200).json('.svg or .png file path here!'); |
Guys, please check this project: https://github.com/mermaidjs/mermaid.cli |
That's nice it seems to work, what isn't nice is having to relay in puppeteer just to export some svg : https://github.com/mermaid-js/mermaid-cli/blob/master/package.json#L19 |
Is there a way to compile text to SVG? Like this:
This is by far the most necessary function for this library. Other stuff, like including the full
he
library and traversing DOM on everymermaid.init()
call and attachingdata-processed
tags to elements is really overkill, makes the library much bigger unnecessarily. The integration specifics should be left to the plugin developers...The text was updated successfully, but these errors were encountered: