Open bwklein opened 8 years ago
The key here will be to detect we're running outside of the browser process and generate an SVG instead of kicking it to the browser.
The chart extension shares a lot in common with Asciidoctor Diagram. I think we certainly should consider migrating this extension to an independent repository, named asciidoctor-chart, perhaps even sharing some code with Asciidoctor Diagram.
@pepijnve do you share that opinion or do you have another idea for where the chart extension should go?
I tend to pass the attribute "pdf" from the cli when building a version that would require a rendered image instead of an interactive javascript based chart. This is what I would key on to determine which way to handle a chart object.
If you are building the document using Asciidoctor PDF, you can check for the attribute backend-pdf
, which is automatically set by that converter.
Related issue: https://github.com/Mogztter/asciidoctor-chart/issues/1
The main challenge is that most charting libraries rely on JavaScript/DOM. Is there any pure Ruby charting library? I found https://github.com/topfunky/gruff but it relies on ImageMagick...
Would it be acceptable to use https://github.com/rubycdp/ferrum to interact with a Chrome headless instance and generate SVG? When transpiling to JavaScript we could implement the same logic using Puppeteer (i.e., replace Ferrum by Puppeteer).
Since Ferrum claims to be a pure Ruby library, it might also works seamlessly on the JVM with JRuby.
Is there any news on rendering chart inside PDF document ?
Nope, I haven't found a good solution to implement this feature... using a Chrome instance seems a bit heavyweight! If you have a better idea, feel free to suggest it or even better submit a pull request.
As an alternative, you can try https://github.com/mogztter/asciidoctor-web-pdf which relies on web technologies to produce a PDF.
Please see this page for a working example. Render SVG Charts Server-side With D3.js
If this could be used to take a chart to svg file and then insert it into a document, it would be a great solution for both the HTML output and to PDF files.