lumean / svg-graph2

SVG:::Graph is a pure Ruby library for generating charts, which are a type of graph where the values of one axis are not scalar. SVG::Graph has a verry similar API to the Perl library SVG::TT::Graph, and the resulting charts also look the same. This isn't surprising, because SVG::Graph started as a loose port of SVG::TT::Graph.
Other
50 stars 20 forks source link

Formatting issue with years as labels #2

Closed adamalbrecht closed 7 years ago

adamalbrecht commented 7 years ago

After I updated to the latest, I noticed that the years along the x axis in one of my graphs were now displaying as 2015.00, 2016.00, etc even though I was passing them in as strings ("2015", "2016", etc).

I think the issue is this line of code: https://github.com/lumean/svg-graph2/blob/master/lib/SVG/Graph/Graph.rb#L592

which is formatting anything that can be parsed as a float as a number with decimal places, including strings. I fixed it by setting the number_format option to "%g", but I could see other people getting tripped up by this as the default behavior. I think this is a perfectly fine default for numeric data types, but strings should probably be displayed as-is.

Thanks!

lumean commented 7 years ago

Hi Adam, thanks for pointing out. I'll change the numeric check to a is_a? Numeric instead of casting to Float which also affects strings containing only numbers. Let me do a couple of tests to make sure it doesn't break something else, before I release a patch. Think will be able to publish the gem by end of the week. Cheers Manuel

lumean commented 7 years ago

sorry for the delay, was quite busy the last few months.. will release a new version the next days, beta is already available.

gem install svg-graph --pre

there are some more changes, see https://github.com/lumean/svg-graph2/blob/master/History.txt Strings should no longer be autoformatted.