Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Display ints as ints Issue 541 #57

Closed
wants to merge 1 commit into from

2 participants

@yaelelmatad

Fixed bug that displayed ints as floats when unnecessary.

Issue #541 on google code:
http://code.google.com/p/flot/issues/detail?can=2&q=541&colspec=ID%20Type%20Status%20Reporter%20Summary&id=541

@yaelelmatad yaelelmatad Dislay ints as ints Issue 541
Fixed bug that displayed ints as floats when unnecessary
4fe722a
@dnschnur
Owner

I pulled your changes to my local repo for testing, and was surprised to find that I could no longer reproduce the original problem! After a little investigation I realized that pull request #50, which I just merged earlier today, had the unexpected side-effect of fixing this decimal issue.

It looks like the bug actually originates from floating point issues in JavaScript's toFixed, which is used in the default label formatter. Pull request #50 replaces it with a much faster alternative using Math.round, which happens to also avoid the problem entirely.

I did test your fix separately, and it doesn't appear to work, at least using the example provided by lizka in issue #541 on Chrome 20; the decimals still show up. Did you test against that example, or a different one?

In any case, I'm closing this pull request, since the issue is resolved. But I am thankful that you took the time to work on this; otherwise it might have been months before we realized that the problem was already solved, and it would have been very difficult at that point to figure out why.

@dnschnur dnschnur closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 10, 2012
  1. @yaelelmatad

    Dislay ints as ints Issue 541

    yaelelmatad authored
    Fixed bug that displayed ints as floats when unnecessary
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 1 deletion.
  1. +8 −1 jquery.flot.js
View
9 jquery.flot.js
@@ -1196,10 +1196,17 @@
size = 10;
size *= magn;
-
+
if (opts.minTickSize != null && size < opts.minTickSize)
size = opts.minTickSize;
+ //add a checker to determine if we really have a decimeal or integer. if axis.delta = int, dec =0
+ var integerChecker = axis.delta - Math.floor(axis.delta);
+
+ if (integerChecker < 0.00000001 || integerChecker > 0.999999999)
+ dec = 0;
+ //axis.delta is within floating point error of an integer
+
axis.tickDecimals = Math.max(0, maxDec != null ? maxDec : dec);
axis.tickSize = opts.tickSize || size;
Something went wrong with that request. Please try again.