Skip to content

Y-axis rounding and display bug fixes.

Sebastien Binet requested to merge Scorpiokat:master into master

Created by: Scorpiokat

Hi again:)

This is my third attempt to fixing the issue #366 (closed). I hope the most successful one. Thank you @sbinet for your advice and support.

Here are the changes made: 1.) I have changed the way of making Ticks.

Now it is more "float64-based" rather than the "strings" one (before).

Method (briefly): DisplayPrecision should not be a constant, as we have figured out earlier. So, to find out which one will be the perfect one, first of all, the array of y-values is created. Then the precision of one is taken, applied to all the values in the array and checked if all of them are different. If they are - the right level of precision is found and Ticks can be already made, if not - precision level is increased by one and the checking process starts again, until all the ticks in the array are different.

For implementing this method - two functions have been added - RemoveDuplicates (removes duplicates from an array and returns one with just unique numbers) and FindRightLevelOfPrecision (find the right level of precision and returns an array with unique numbers truncated to that precision level) In the second function 2 methods were used (for small and very large numbers). floats.Round was not used here as unluckily it did not work for large numbers.

2.) logscale_golden.png has been replaced under plotter/testdata, as I do really think that the same level of precision should be applied to all the Ticks. Now it does.

3.) New test precision_test.go under plotter has been created to test the precision issue (like the one we are now trying to fix). precision_golden.png has been added to the testdata folder which contains all the plots to be compared to.

4.) Some more test cases were added to axis_test.go, so that the test covers almost 100% of lines in func (DefaultTicks)Ticks. Just one test for max<=min is left uncovered though.

5.) math.Nextafter have been removed twice from the code, as these cases can take place if and only if majorDelta = 0, which can be true only when min = max (and this case has been caught by 'panic (illegal range)'.

Merge request reports