-
Notifications
You must be signed in to change notification settings - Fork 19
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
C2S doesn't work with new version of Chart.js : Attempted to apply path command to node g #25
Comments
Seems to be related to this issue : gliffy#44 |
It seems that the issue is when Chart.js is trying to draw lines. I found a dirty dirty workaroud : instead of just drawing a line, drawing 2 lines and ask Charts JS to fill the space between the 2 to make a line... that's dirty... but it works. I'll post the workaround here, but I think fixing C2S still would be great. |
A little workaround function that does the trick until C2S is fixed. There are little artifacts as I need to do better segment merging
|
With better segment merging to remove the artifacts. Hopes it'll help someone someday ;)
|
@denis-migdal Thanks very much for posting this. I'm using chart.js and jsPdf, and the PDF quality is good when printed (I use chart.js option devicePixelRatio: 2), but not great when viewing PDF on screen and zooming PDF. I'm considering SvgCanvas, but I see you found issues. Did your latest patch code work OK, or did you find more issues? I have scatter and bar charts, and only 1 chart with line (bar/line combo). |
@denis-migdal I tried to replicate the same solution, but did not work in my case. Still the library gives same error for line and Radar chart. This is the SVG which is getting generated in my case, |
For my usage it seemed to work OK. |
Can you provide a minimal example of your code reproducing it so I can test it ? |
I won't be able to share the code here but when I tried to debug this code further in my case, I found following, As we have referred scales as, Another approach, I tried to initailized scales with, Could you please help me understand what should be passed as inside scales for this logic to work correctly in my case? |
I think you made a mistake when copying my code. Indeed, I do : let data = line_cfg.data.map( (point: [number,number]) => [
scales.x.getPixelForValue(point[0]),
scales.y.getPixelForValue(point[1])
]); But you wrote : let data = line_cfg.data.map( (point: [number,number]) => {[
scales.x.getPixelForValue(point[0]),
scales.y.getPixelForValue(point[1])
]}); Yeah took me quite sometime to see it xD. |
Not a mistake, I was debugging the code and to add the debugger Ihad added brackets to make it a function but anyways even after removing, It gives same error. |
If you add bracket you also need to add a
To be fair I do not really understand how C2S is working internally, I just noticed lines weren't printed but area fill was, so I replaced the lines by area filling. I'll advise you to try using it on empty graph, then adding elements little by little to see exactly what is causing the issue. |
Sure will try to figure out the exact problem and solve it. Thanks! |
See my comment in the original repo for an alternative on how to hotfix this: gliffy#44 (comment) |
Thanks, I'll try to test that someday. I think gliffy gave up on C2S, as it's been years since the repo has been updated. I don't know which repository is the new maintained one. |
Yes maintining a repo is time consuming and not worth it if you don't use it anymore in your job. zenozeng also has pretty much abandoned the repo. Can't blame any of them. I'd like to fork and create a TS version of it, so at least contributing would be easier but it would probably become an additional unmaintained repo over time 😄 Back to the fix, my alternative is just an hotfix, not a proper fix, but it seems to work well for me and I work on a complex Miro-like collaborative canvas. |
It'll be easier if someone created a C2S organization so that the owner(s) would just have to manage the rights, i.e. add or remove users to the organization members. |
It's a bit clearer in this version https://github.com/insinfo/canvas2svg/blob/b877064ae0e4c8d05be4a4aa0fec6cd6b449a8f1/canvas2svg.js#L1131 I think the error messages are a red herring and that the issue is chart.js is communicating lines via a Path2D object passed via canvas.stroke(path) rather than directly calling moveTo/lineTo on the canvas. Path2D is opaque - and C2S doesn't have a way of interpreting and so does nothing. I've monkey patched Path2D in my local project to record invocations to subsequently be applied by C2S, but it's not really a proper way to go about it. |
I got several issue trying to use C2S to export a graph generated with Chart.js
On stackoverflow, I found out that C2S was lacking some method (getContext, style, getAttribute, and addEventListener) (cf below).
However, new versions of Chart.js still seems to be doing something that C2S doesn't like.
Initially I used a npm package that seems to work (but without any git associated) at the exception of setTransform and resetTransform that weren't implemented ( https://www.npmjs.com/package/canvas-to-svg ). This npm package seems to be maintained by @rob-gordon (https://github.com/rob-gordon), and I think is from this git https://github.com/tone-row/canvas-to-svg
I then tried several versions of C2S. Yours seems to be one of the most maintained. Only the grid is drawn, and I don't see any error in the console (cf below) : "Attempted to apply path command to node g"
Would you know how I could make it works ?
Missing methods :
Minimal example :
Expected :
Result :
The text was updated successfully, but these errors were encountered: