andreaferretti / paths-js

Generate SVG paths for geometric shapes :bar_chart:
http://andreaferretti.github.io/paths-js-react-demo/
Apache License 2.0
1.72k stars 84 forks source link

Serverside and client side output is diffrent #20

Closed isilweo closed 9 years ago

isilweo commented 9 years ago

Hi,

I'm trying to make React Isomorphic app with charts rendering using Paths. However there is diffrent output from calculations done by browser and server side. The only reason I can think of it is that server side and browser side are using diffrent Number bit resolution (32bit vs 64bit). React tells me about diffrence between serverside markup and browser markup.

This one is using smoothline source code from http://andreaferretti.github.io/paths-js-react-demo/

(client) 556554 C 1.2368633799195998 317.72517853 (server) 556554 C 1.2368633791238002 317.72517853

However even with simpler one (using Stock example from wiki) I have diffrent results

(client) ath d="M 0 180 L 155 200 L 300 140" fill (server) ath d="M 0 180 L 155.00000002797069 200

Server is on IOJS 1.7.2 and Browser is Chrome 41

Maybe it would be enough to add some number rounding somewhere where you do calculations?

andreaferretti commented 9 years ago

I could round the coordinates, but I am no sure what precision to use. In theory I could round them to the nearest integer, but this would lose precision when used inside a SVG element which is scaled up.

I think it would be safe to round to a few decimals. Let me think about this for a moment, and I will have it fixed in a few days.

andreaferretti commented 9 years ago

It should be fixed with release 0.3.3 - let me know if it works fine

andreaferretti commented 9 years ago

It seems it is fixed, so I am closing this - please reopen it if needed