From 3d88c7a5ebd661e99e7943e01cf8426c135732f7 Mon Sep 17 00:00:00 2001 From: Robin Hu Date: Mon, 16 Dec 2013 22:25:26 -0500 Subject: [PATCH] Added a 'noErrorCheck' method to cumulativeLineChart --- nv.d3.js | 10 +++++++++- src/models/cumulativeLineChart.js | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/nv.d3.js b/nv.d3.js index 288e2bb..1169fd4 100644 --- a/nv.d3.js +++ b/nv.d3.js @@ -2520,6 +2520,7 @@ nv.models.cumulativeLineChart = function() { , average = function(d) { return d.average } , dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState') , transitionDuration = 250 + , noErrorCheck = false //if set to TRUE, will bypass an error check in the indexify function. ; xAxis @@ -3202,6 +3203,12 @@ nv.models.cumulativeLineChart = function() { return chart; }; + chart.noErrorCheck = function(_) { + if (!arguments.length) return noErrorCheck; + noErrorCheck = _; + return chart; + }; + //============================================================ @@ -3218,8 +3225,9 @@ nv.models.cumulativeLineChart = function() { var v = lines.y()(line.values[idx], idx); //TODO: implement check below, and disable series if series loses 100% or more cause divide by 0 issue - if (v < -.95) { + if (v < -.95 && !noErrorCheck) { //if a series loses more than 100%, calculations fail.. anything close can cause major distortion (but is mathematically correct till it hits 100) + line.tempDisabled = true; return line; } diff --git a/src/models/cumulativeLineChart.js b/src/models/cumulativeLineChart.js index 6e8b751..9273144 100644 --- a/src/models/cumulativeLineChart.js +++ b/src/models/cumulativeLineChart.js @@ -38,6 +38,7 @@ nv.models.cumulativeLineChart = function() { , average = function(d) { return d.average } , dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState') , transitionDuration = 250 + , noErrorCheck = false //if set to TRUE, will bypass an error check in the indexify function. ; xAxis @@ -720,6 +721,12 @@ nv.models.cumulativeLineChart = function() { return chart; }; + chart.noErrorCheck = function(_) { + if (!arguments.length) return noErrorCheck; + noErrorCheck = _; + return chart; + }; + //============================================================ @@ -736,8 +743,9 @@ nv.models.cumulativeLineChart = function() { var v = lines.y()(line.values[idx], idx); //TODO: implement check below, and disable series if series loses 100% or more cause divide by 0 issue - if (v < -.95) { + if (v < -.95 && !noErrorCheck) { //if a series loses more than 100%, calculations fail.. anything close can cause major distortion (but is mathematically correct till it hits 100) + line.tempDisabled = true; return line; }