From fdfa9912e844582a5b39bf656cdb51b8fd9659ae Mon Sep 17 00:00:00 2001 From: Nick Downie Date: Tue, 8 Jul 2014 22:44:55 +0100 Subject: [PATCH] Refactor logic into shared Element method --- src/Chart.Bar.js | 2 +- src/Chart.Core.js | 5 ++++- src/Chart.Line.js | 6 +++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Chart.Bar.js b/src/Chart.Bar.js index 0f29a3df5..fafe74a49 100644 --- a/src/Chart.Bar.js +++ b/src/Chart.Bar.js @@ -275,7 +275,7 @@ //Draw all the bars for each dataset helpers.each(this.datasets,function(dataset,datasetIndex){ helpers.each(dataset.bars,function(bar,index){ - if (helpers.isNumber(bar.value)){ + if (bar.hasValue()){ bar.base = this.scale.endPoint; //Transition then draw bar.transition({ diff --git a/src/Chart.Core.js b/src/Chart.Core.js index 7c1276a91..4bdf45552 100755 --- a/src/Chart.Core.js +++ b/src/Chart.Core.js @@ -873,7 +873,7 @@ yMin; helpers.each(this.datasets, function(dataset){ dataCollection = dataset.points || dataset.bars || dataset.segments; - if (dataCollection[dataIndex] && helpers.isNumber(dataCollection[dataIndex].value)){ + if (dataCollection[dataIndex] && dataCollection[dataIndex].hasValue()){ Elements.push(dataCollection[dataIndex]); } }); @@ -1037,6 +1037,9 @@ x : this.x, y : this.y }; + }, + hasValue: function(){ + return isNumber(this.value); } }); diff --git a/src/Chart.Line.js b/src/Chart.Line.js index 081601531..322095af6 100644 --- a/src/Chart.Line.js +++ b/src/Chart.Line.js @@ -259,7 +259,7 @@ //We can use this extra loop to calculate the control points of this dataset also in this loop helpers.each(dataset.points,function(point,index){ - if (helpers.isNumber(point.value)){ + if (point.hasValue()){ point.transition({ y : this.scale.calculateY(point.value), x : this.scale.calculateX(index) @@ -293,7 +293,7 @@ ctx.strokeStyle = dataset.strokeColor; ctx.beginPath(); helpers.each(dataset.points,function(point,index){ - if (helpers.isNumber(point.value)){ + if (point.hasValue()){ if (index>0){ if(this.options.bezierCurve){ ctx.bezierCurveTo( @@ -331,7 +331,7 @@ //A little inefficient double looping, but better than the line //lagging behind the point positions helpers.each(dataset.points,function(point){ - if (helpers.isNumber(point.value)){ + if (point.hasValue()){ point.draw(); } });