]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Refactor logic into shared Element method
authorNick Downie <hello@nickdownie.com>
Tue, 8 Jul 2014 21:44:55 +0000 (22:44 +0100)
committerNick Downie <hello@nickdownie.com>
Tue, 8 Jul 2014 21:44:55 +0000 (22:44 +0100)
src/Chart.Bar.js
src/Chart.Core.js
src/Chart.Line.js

index 0f29a3df53276719486d5a30299360ec3db858ee..fafe74a49d85fefc7848a99af9e3f980ec342332 100644 (file)
                        //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({
index 7c1276a913769b3ff3362ce173855b3d6e4f3e80..4bdf45552fe483b26d5d43ca6cdbd945bad556cc 100755 (executable)
                                                                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]);
                                                                }
                                                        });
                                x : this.x,
                                y : this.y
                        };
+               },
+               hasValue: function(){
+                       return isNumber(this.value);
                }
        });
 
index 08160153174042be44bd2ed765726ad1ebe1ba24..322095af63477c1bc717a2dcd795ea3b0a4274b0 100644 (file)
                                //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)
                                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(
                                //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();
                                        }
                                });