Skip to content

Commit

Permalink
Added tests. Cut execution time for big graphs down 100xish
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Ownbey committed Oct 30, 2009
1 parent 877c3f4 commit a8f6b48
Show file tree
Hide file tree
Showing 5 changed files with 550 additions and 19 deletions.
21 changes: 12 additions & 9 deletions dygraph-canvas.js
Expand Up @@ -182,7 +182,10 @@ DateGraphCanvasRenderer.prototype._renderLineChart = function() {
first_point = false;
}
};
MochiKit.Iter.forEach(this.layout.points, partial(addPoint, ctx), this);
for(var x = 0; x < this.layout.points.length; x++) {
addPoint(ctx, this.layout.points[x]);
}
//MochiKit.Iter.forEach(this.layout.points, partial(addPoint, ctx), this);
if (this.layout.options.shouldFill) {
ctx.lineTo(this.area.x + this.area.w, this.area.y + this.area.h);
ctx.closePath();
Expand All @@ -196,6 +199,7 @@ DateGraphCanvasRenderer.prototype._renderLineChart = function() {
};

var makeErrorBars = function(ctx) {
console.log("Called");
for (var i = 0; i < setCount; i++) {
var setName = setNames[i];
var color = colorScheme[i % colorCount];
Expand Down Expand Up @@ -229,17 +233,16 @@ DateGraphCanvasRenderer.prototype._renderLineChart = function() {
}
};
// should be same color as the lines
if (errorBars) {
var err_color = color.colorWithAlpha(0.15);
ctx.fillStyle = err_color.toRGBString();
ctx.beginPath();
MochiKit.Iter.forEach(this.layout.points, partial(errorTrapezoid, ctx), this);
ctx.fill();
}
var err_color = color.colorWithAlpha(0.15);
ctx.fillStyle = err_color.toRGBString();
ctx.beginPath();
MochiKit.Iter.forEach(this.layout.points, partial(errorTrapezoid, ctx), this);
ctx.fill();
}
};

if (this.layout.options.dataHasErrorBars) {
if (errorBars) {
console.log("Error bars?");
bind(makeErrorBars, this)(context);
}
bind(makePath, this)(context);
Expand Down
14 changes: 8 additions & 6 deletions dygraph-combined.js
Expand Up @@ -4723,7 +4723,9 @@ _34.lineTo(_31.canvasx,_31.canvasy);
_32=false;
}
};
MochiKit.Iter.forEach(this.layout.points,_24(_33,ctx),this);
for(var x=0;x<this.layout.points.length;x++){
_33(ctx,this.layout.points[x]);
}
if(this.layout.options.shouldFill){
ctx.lineTo(this.area.x+this.area.w,this.area.y+this.area.h);
ctx.closePath();
Expand All @@ -4736,6 +4738,7 @@ ctx.fill();
}
};
var _35=function(ctx){
console.log("Called");
for(var i=0;i<_22;i++){
var _36=_20[i];
var _37=_19[i%_18];
Expand Down Expand Up @@ -4765,16 +4768,15 @@ _40[1]=_46[1];
_39=_45.canvasx;
}
};
if(_21){
var _47=_37.colorWithAlpha(0.15);
ctx.fillStyle=_47.toRGBString();
ctx.beginPath();
MochiKit.Iter.forEach(this.layout.points,_24(_43,ctx),this);
ctx.fill();
}
}
};
if(this.layout.options.dataHasErrorBars){
if(_21){
console.log("Error bars?");
_23(_35,this)(_17);
}
_23(_27,this)(_17);
Expand Down Expand Up @@ -5131,7 +5133,9 @@ DateGraph.prototype.loadedEvent_=function(data){
if(typeof (jQuery)!="undefined"){
jQuery(document).trigger("graph.loaded");
}
if(!this.rawData_){
this.rawData_=this.parseCSV_(data);
}
this.drawGraph_(this.rawData_);
};
DateGraph.prototype.months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
Expand Down Expand Up @@ -5618,10 +5622,8 @@ var req=new XMLHttpRequest();
var _209=this;
req.onreadystatechange=function(){
if(req.readyState==4){
if(req.status==200){
_209.loadedEvent_(req.responseText);
}
}
};
req.open("GET",this.file_,true);
req.send(null);
Expand Down
7 changes: 3 additions & 4 deletions dygraph.js
Expand Up @@ -630,7 +630,8 @@ DateGraph.prototype.round_ = function(num, places) {
DateGraph.prototype.loadedEvent_ = function(data) {
if (typeof(jQuery) != "undefined")
jQuery(document).trigger('graph.loaded');
this.rawData_ = this.parseCSV_(data);
if(!this.rawData_)
this.rawData_ = this.parseCSV_(data);
this.drawGraph_(this.rawData_);
};

Expand Down Expand Up @@ -1275,9 +1276,7 @@ DateGraph.prototype.start_ = function() {
var caller = this;
req.onreadystatechange = function () {
if (req.readyState == 4) {
if (req.status == 200) {
caller.loadedEvent_(req.responseText);
}
caller.loadedEvent_(req.responseText);
}
};

Expand Down

0 comments on commit a8f6b48

Please sign in to comment.