Fix problem to create png svg in node.js with 3D plots #391
+283
−24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR attempts to fix #257 by using a more modern SVG renderer called resvg-js.
The problem
The original renderer used by
jsrootisnode-canvaswhich depends onlibrsvgon Linux. The issue arises when the user runsnpm installto installjsrootas this causesnode-canvasto fetch and link its binary to an outdated (and broken) version of
librsvg.This causes SVG to PNG conversion to be buggy often rendering empty plots. See the full discussion.
The solution
resvg-jswas added as anpmdependency ofjsroot, hence the changes inpackage.jsonandpackage-lock.json.In order leverage it, a refactoring had to be made in
jsroot's painting base module (BasePainter.mjs).Now, the code has two branches for converting SVGs to PNGs: the first one uses
resvg-jsand the secondnode-canvas.However, the former shall be taken in all cases as the feature flag that mandates whether the module uses
resvg-jsis hardcoded totrue.Results
Before the change, the test of running
demo/node/make_image.jsyielded alego.pngwithout the 3D plot.Now, it correctly generates it. Further tests should be made to assure this change is safe. In any case, it can be readily turned off by setting
RESVG_FEATURE_FLAGtofalse.I hope this helps!