Comments (8)
The workaround used in d3/d3#2524 still applies:
eps=1e-15;
range(0, 64).forEach(function(m){rmax=Math.pow(2,m);
range(1, 1000).forEach( function(d) {rmax=Math.pow(2,m);
if (range(0, rmax*(1-eps), rmax/d).length !== d) {console.log(d) ;}})})
does not find mismatches in firefox; still need to test in chrome.
This suggests a similar fix, eg. adjust stop by (1-eps) * stop .
Thinking a bit more about it, it is probably necessary to adjust the difference between start and stop, rather than just stop; eg. use (stop - start)*(1-eps) to determine n.
from d3-array.
Here is a gist which does some checks of the range() function.
http://bl.ocks.org/andreasplesch/ada4b4e89738d4e5d4af
It turns out the workaround is useful but not very good for larger offsets (larger numbers) even when using the (stop-start)*(1-eps) adjustment .
from d3-array.
Well, I decided to go back to integer ranges.
Perhaps it is worthwhile to add to the documentation that if the number of elements in the generated array is expected to be exactly n, then one should use something like
// var step = (stop - start)/n;
var step = mystep;
d3.array(0, n).map( function(d) {return start + d * step;};
or perhaps provide this as another range function, say d3.nrange(), which takes start, step and number of elements n.
from d3-array.
Hmm. I’m tempted to remove the scale hack entirely, since it only works for some cases and makes the behavior harder to understand.
In general, you shouldn’t expect range(0, 1, 1/n)
to return exactly n
results because of the limitations of floating point. Using range(0, n).map(function(i) { return i / n; })
is recommended, and I’m in favor of documenting this recommendation.
from d3-array.
Related d3/d3#494, D3 version 2.7.5, commit d3/d3@87f48b7.
from d3-array.
Perhaps with the original commit above I now can understand what the conversion to integer is about but it did make the behaviour more opaque. I would say remove it, and perhaps emphasize the limitations a bit more in the documentation.
It took me a little to figure out that the range() behaviour was the issue when I originally used it for
http://bl.ocks.org/andreasplesch/49b2130b15425c1eebc0/
and got some weird results.
So documentation would be great. I tried to keep the additions in my pull request #6 concise but feel free of course to edit as you feel appropriate. I left the start value in there since for some it may not be too trivial to have seen in an example.
from d3-array.
Re-opening this request, because I think you are right that we should remove the fancy behavior.
from d3-array.
Fixed in 0.1.2; see d2364d4.
from d3-array.
Related Issues (20)
- BUG: d3-array/dist/d3-array.js: Unexpected token (139:15) HOT 4
- fix(babel): cumsum HOT 1
- binary ticks increments on linear scale HOT 2
- D3-array produces ERR_REQUIRE_ESM with node >= 15 HOT 3
- bisectCenter naming HOT 1
- quantile returns undefined on an empty array, differs from extent HOT 1
- Docs: define the bin thresholds with array HOT 2
- First and last thresholds are set to data extent (not explicitly stated limits) HOT 2
- bisector no longer supports two-argument (object, value) comparator HOT 12
- Testing a lib using `d3-array` HOT 1
- d3.blur HOT 1
- Incorrect results for binary search on large arrays due to miscomputation of midpoint HOT 11
- d3.bin can mutate the user-specified thresholds
- About the sorting problem of d3.rank HOT 2
- Insecure Randomness for the useof Math.random() in shuffle API (security vulnerability) HOT 1
- d3.thresholdScott returns NaN for single-element arrays
- Feature request: `find` / `findValue` methods
- groupSort should use ascendingDefined instead of ascending
- medianIndex/quantileIndex doesn’t handle missing data HOT 3
- can d3-array also support BigInt numbers? 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-array.