andreaferretti / paths-js

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

Stock API calculates NaN with y points of same value #21

Closed inuwan closed 9 years ago

inuwan commented 9 years ago

The Stock API calculates NaN for the line.centroid[1]

I pass in the following to pathsjs.Stock({ data: [ { "date": new Date("2015-01-09T07:00:00.000Z"), "netPay": 200.45 }, { "date": new Date("2015-01-23T07:00:00.000Z"), "netPay": 200.45 }, { "date": new Date("2015-02-06T07:00:00.000Z"), "netPay": 200.45 }, { "date": new Date("2015-02-20T07:00:00.000Z"), "netPay": 200.45 }, { "date": new Date("2015-03-06T07:00:00.000Z"), "netPay": 200.45 } ], xaccessor: function(x) {return x.date.valueOf();}, yaccessor: function(x){x.netPay;), width: 414, height: 80 })

The resulting paths.curves[0].line.centroid[0] is 207 and paths.curves[0].line.centroid[0] is NaN

andreaferretti commented 9 years ago

I have published version 0.3.4, where this should be fixed. What I was doing was rescale the y range over the screen coordinates range, which does not make much sense when the y range is reduced to a single point, as in your example. I have now added a slight padding when all y values are the same. I'm not sure this will be enough to handle degenerate cases, please comment here to let me know if you have any more problems, so that I can also expand my test suite.

andreaferretti commented 9 years ago

It seems to be fixed, so I am closing this. Please, reopen it if needed