From 9f2280bee7526f14561ccf8607bb9dd0eef23ff3 Mon Sep 17 00:00:00 2001 From: Robin Hu Date: Wed, 14 Aug 2013 09:08:51 -0400 Subject: [PATCH] Fixing issue #219. Moving the jitter logic to after the scatter point's scale has been determined. Added line chart and scatter chart tests. --- src/models/scatter.js | 8 ++++---- test/ScatterChartTest.html | 19 ++++++++++++++++++- test/lineChartTest.html | 16 ++++++++++++++++ 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/models/scatter.js b/src/models/scatter.js index af710a4..c2afdff 100644 --- a/src/models/scatter.js +++ b/src/models/scatter.js @@ -167,11 +167,11 @@ nv.models.scatter = function() { // *Injecting series and point index for reference /* *Adding a 'jitter' to the points, because there's an issue in d3.geom.voronoi. */ - var pX = getX(point,pointIndex) + Math.random() * 1e-7; - var pY = getY(point,pointIndex) + Math.random() * 1e-7; + var pX = getX(point,pointIndex); + var pY = getY(point,pointIndex); - return [x(pX), - y(pY), + return [x(pX)+ Math.random() * 1e-7, + y(pY)+ Math.random() * 1e-7, groupIndex, pointIndex, point]; //temp hack to add noise untill I think of a better way so there are no duplicates }) diff --git a/test/ScatterChartTest.html b/test/ScatterChartTest.html index ae7f2f6..843da37 100644 --- a/test/ScatterChartTest.html +++ b/test/ScatterChartTest.html @@ -75,7 +75,10 @@ Scatter chart: duplicate x values - +
+ Scatter chart: extremely small data points (1e-10) + +
@@ -131,6 +134,8 @@ defaultChartTest("test15",[ } ]); +defaultChartTest("test16",tinyPoints()); + function defaultChartTest(container, data, margin) { nv.addGraph(function() { var chart; @@ -219,4 +224,16 @@ function randomDataSloped(slope,intercept) { //# groups,# points per group return data; } + + +function tinyPoints() { + var rval = {key: "Tiny points", values: []}; + for(var i =1; i < 20; i++) { + rval.values.push({ + x: Math.random() * 1e-10, + y: Math.random() * 1e-10 + }); + } + return [rval]; +} diff --git a/test/lineChartTest.html b/test/lineChartTest.html index 25a7c63..027e633 100644 --- a/test/lineChartTest.html +++ b/test/lineChartTest.html @@ -100,6 +100,10 @@ What if there are null, Infinity and NaN values in points? +
+ Chart with very small, 1e-10, points (old tooltips) + +
@@ -162,6 +166,7 @@ defaultChartConfig("chart13",hyperbole(), true, false, {width: 700, height: 400} defaultChartConfig("chart14",hyperbole(), false, false, {width: 700, height: 400}); defaultChartConfig("chart15", withNaNs()); defaultChartConfig("chart16", duplicateY(), false); +defaultChartConfig("chart17", tinyPoints(), false); function defaultChartConfig(containerid, data, guideline, useDates, auxOptions) { if (auxOptions === undefined) auxOptions = {}; @@ -400,4 +405,15 @@ function withNaNs() { } ] } + +function tinyPoints() { + var rval = {key: "Tiny points", values: []}; + for(var i =1; i < 20; i++) { + rval.values.push({ + x: i, + y: Math.random() * 1e-10 + }); + } + return [rval]; +}