Make a start on sparse data for line charts

This commit is contained in:
Nick Downie 2014-07-08 22:40:32 +01:00
parent e25fd5e37c
commit 2f59921f7a

View File

@ -98,8 +98,6 @@
helpers.each(dataset.data,function(dataPoint,index){ helpers.each(dataset.data,function(dataPoint,index){
//Best way to do this? or in draw sequence...?
if (helpers.isNumber(dataPoint)){
//Add a new point for each piece of data, passing any required data to draw. //Add a new point for each piece of data, passing any required data to draw.
datasetObject.points.push(new this.PointClass({ datasetObject.points.push(new this.PointClass({
value : dataPoint, value : dataPoint,
@ -110,7 +108,6 @@
highlightFill : dataset.pointHighlightFill || dataset.pointColor, highlightFill : dataset.pointHighlightFill || dataset.pointColor,
highlightStroke : dataset.pointHighlightStroke || dataset.pointStrokeColor highlightStroke : dataset.pointHighlightStroke || dataset.pointStrokeColor
})); }));
}
},this); },this);
this.buildScale(data.labels); this.buildScale(data.labels);
@ -217,7 +214,6 @@
//Map the values array for each of the datasets //Map the values array for each of the datasets
helpers.each(valuesArray,function(value,datasetIndex){ helpers.each(valuesArray,function(value,datasetIndex){
if (helpers.isNumber(value)){
//Add a new point for each piece of data, passing any required data to draw. //Add a new point for each piece of data, passing any required data to draw.
this.datasets[datasetIndex].points.push(new this.PointClass({ this.datasets[datasetIndex].points.push(new this.PointClass({
value : value, value : value,
@ -227,7 +223,6 @@
strokeColor : this.datasets[datasetIndex].pointStrokeColor, strokeColor : this.datasets[datasetIndex].pointStrokeColor,
fillColor : this.datasets[datasetIndex].pointColor fillColor : this.datasets[datasetIndex].pointColor
})); }));
}
},this); },this);
this.scale.addXLabel(label); this.scale.addXLabel(label);
@ -264,10 +259,12 @@
//We can use this extra loop to calculate the control points of this dataset also in this loop //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){ helpers.each(dataset.points,function(point,index){
if (helpers.isNumber(point.value)){
point.transition({ point.transition({
y : this.scale.calculateY(point.value), y : this.scale.calculateY(point.value),
x : this.scale.calculateX(index) x : this.scale.calculateX(index)
}, easingDecimal); }, easingDecimal);
}
},this); },this);
@ -296,6 +293,7 @@
ctx.strokeStyle = dataset.strokeColor; ctx.strokeStyle = dataset.strokeColor;
ctx.beginPath(); ctx.beginPath();
helpers.each(dataset.points,function(point,index){ helpers.each(dataset.points,function(point,index){
if (helpers.isNumber(point.value)){
if (index>0){ if (index>0){
if(this.options.bezierCurve){ if(this.options.bezierCurve){
ctx.bezierCurveTo( ctx.bezierCurveTo(
@ -315,6 +313,7 @@
else{ else{
ctx.moveTo(point.x,point.y); ctx.moveTo(point.x,point.y);
} }
}
},this); },this);
ctx.stroke(); ctx.stroke();
@ -332,7 +331,9 @@
//A little inefficient double looping, but better than the line //A little inefficient double looping, but better than the line
//lagging behind the point positions //lagging behind the point positions
helpers.each(dataset.points,function(point){ helpers.each(dataset.points,function(point){
if (helpers.isNumber(point.value)){
point.draw(); point.draw();
}
}); });
},this); },this);