Comments (3)
Not sure if we can do anything better here. Feel free to open a pull request if you have a suggestion for a change to the ticks algorithm.
from d3-scale.
JavaScript has native support for big integers now, so we could use that, but I don’t think I’d want to use big integers in the common path (since it’s rare that the domain is so big or so small). And it would need to be a new major version since it would reduce compatibility of d3-array with older JavaScript environments. So I probably don’t think this is worth it unless there is more evidence of demand.
from d3-scale.
Yep, it's floating points issues.
// Problem
r0 + i * step;
0 + 3 * 2e+23; // This returns 5.9999999999999995e+23
It looks like using Big in the ticks method solve the issue. But maybe you don't prefer to use another dependencies to solve it ? I don't know.
Big(2e+23).mul(3).toString(); // 6e+23 Nice result !!
The ticks method
function ticks(start, stop, count) {
var reverse,
i = -1,
n,
ticks,
step;
stop = +stop, start = +start, count = +count;
if (start === stop && count > 0) return [start];
if (reverse = stop < start) n = start, start = stop, stop = n;
if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];
if (step > 0) {
let r0 = Math.round(start / step), r1 = Math.round(stop / step);
console.log(start, stop, step)
console.log(r0, r1)
if (r0 * step < start) ++r0;
console.log(r0, r1)
if (r1 * step > stop) --r1;
console.log(r0, r1)
ticks = new Array(n = r1 - r0 + 1);
console.log(ticks, n)
while (++i < n) ticks[i] = Number(Big(r0).add(i).mul(step).toString());
} else {
step = -step;
let r0 = Math.round(start * step), r1 = Math.round(stop * step);
if (r0 / step < start) ++r0;
if (r1 / step > stop) --r1;
ticks = new Array(n = r1 - r0 + 1);
while (++i < n) ticks[i] = Number(Big(r0).add(i).div(step).toString());
}
if (reverse) ticks.reverse();
return ticks;
}
from d3-scale.
Related Issues (20)
- TypeError: scale.domain is not a function HOT 1
- scaleDiverging for domain [1,1,0] produces wrong results HOT 1
- get HEX color HOT 1
- d3.scale.quantile() error in 7.3.0 that works in 3.5.5 HOT 1
- ScaleTime ticks reset at the beginning of the month HOT 1
- Time Scale: How could one provide a custom irregular spacing of ticks? HOT 1
- d3.scaleTime() axis ticks are not aligned with scale outputs? HOT 2
- Difficult debugging on invalid scale.range arguments
- Invert function does not work correctly on scaleTime HOT 2
- d3 dependency tree depends on a security vulnerable version of d3-color HOT 2
- Security vulnerability fix for d3-color required in 2.x
- Possible Bug in log implementation HOT 1
- Microseconds are not supported? HOT 1
- Snyk checks request a fixed version of d3-color HOT 1
- Update d3-interpolate dependency to v3 HOT 5
- Numerical instability with invert HOT 1
- Feature request: exp scale
- Feature proposal: logit scale
- scaleTime() ticks issue HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from d3-scale.