Bring data to life with SVG, Canvas and HTML. 📊📈🎉
Перейти к файлу
Jason Davies a4429fa041 Fix #2039: improve [un]interpolateNumber precision.
* uninterpolate:

The use of a reciprocal in d3_uninterpolateNumber to avoid division
results in a small loss of precision (the following is a paraphrase):

  function d3_uninterpolateNumber(a, b) {
    var k = b - a ? 1 / (b - a) : 0;
    return function(x) { return (x - a) * k; };
  }

For x = a, there is no problem, since u = (a - a) * k = 0 * k = 0 as
expected.  For x = b, we have u = (b - a) * k, and since k cannot
represent 1 / (b - a) exactly, we don’t get u = 1, but something very
close to 1.

Instead, if we perform the division within the generated function, we
can ensure we always get u = 1 for x = b:

  function d3_uninterpolateNumber(a, b) {
    var k = b - a || Infinity;
    return function(x) { return (x - a) / k; };
  }

Again, for x = a, we simply have u = (a - a) / k = 0.  For x = b, we
have u = (b - a) / k = (b - a) / (b - a) = 1.

* interpolate:

Similarly, for d3_interpolateNumber, we have a small loss of precision,
this time due to subtraction.  Paraphrased:

  function d3_interpolateNumber(a, b) {
    var d = b - a;
    return function(t) { return a + t * d; };
  }

There is no issue for t = 0, because we always get i = a + 0 * d = a.
However, for t = 1, we get i = a + d, which might not be exactly equal
to b as desired.  The following will return precisely b for t = 1:

  function d3_interpolateNumber(a, b) {
    return function(t) { return a * (1 - t) + b * t; };
  }
2014-10-10 10:40:59 +01:00
bin Merge branch 'locale' into 3.4 2014-01-09 16:43:32 -08:00
lib Remove obsolete license. 2013-10-05 14:18:31 -07:00
src Fix #2039: improve [un]interpolateNumber precision. 2014-10-10 10:40:59 +01:00
test Fix #2039: improve [un]interpolateNumber precision. 2014-10-10 10:40:59 +01:00
.gitignore Add .DS_Store to .gitignore. 2011-11-03 09:06:04 -07:00
.npmignore add _site 2014-01-20 18:51:51 -08:00
.spmignore Add spm support 2014-05-22 18:31:22 +08:00
.travis.yml use node 0.10 for travis 2013-04-11 23:10:08 +08:00
CONTRIBUTING.md Add CONTRIBUTING. 2013-11-18 14:08:13 -08:00
LICENSE Copyright year should be a range? 2014-03-09 11:14:50 -07:00
Makefile Add d3.zip target. 2014-10-08 08:45:31 -07:00
README.md Update README.md 2013-11-20 15:25:24 -08:00
bower.json Bump version. 2014-10-08 08:09:42 -07:00
component.json Bump version. 2014-10-08 08:09:42 -07:00
composer.json corrects package name to include vendor 2014-01-15 08:14:28 +01:00
d3.js Fix #2039: improve [un]interpolateNumber precision. 2014-10-10 10:40:59 +01:00
d3.min.js Fix #2039: improve [un]interpolateNumber precision. 2014-10-10 10:40:59 +01:00
index.js Update to JSDom 1.0.0 2014-10-02 13:28:44 +02:00
package.json Bump version. 2014-10-08 08:09:42 -07:00

README.md

Data-Driven Documents

D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to life using HTML, SVG and CSS. D3s emphasis on web standards gives you the full capabilities of modern browsers without tying yourself to a proprietary framework, combining powerful visualization components and a data-driven approach to DOM manipulation.

Want to learn more? See the wiki.

For examples, see the gallery and mbostocks bl.ocks.