added graph.resample method to prevent browser crash from trying to plot too many points

master
Helene Moorman 2015-02-21 23:27:19 -08:00
rodzic c1208f0e60
commit a83eb21d05
1 zmienionych plików z 26 dodań i 0 usunięć

Wyświetl plik

@ -150,7 +150,33 @@ var tempgraph = (function(module) {
this.y.domain(extent);
this.draw();
}
module.Graph.prototype.resample = function(data) {
var npoints = 1000;
var idxs = []
for (var i=0;i<data.length;i++)
idxs.push(i);
var within = [];
var within_idx = [];
for (var i=0; i<data.length; i++) {
if (data[i].x>=this.xlim()[0] && data[i].x<=this.xlim()[1]) {
within.push(data[i]);
within_idx.push(idxs[i]);
}
}
if (within.length>npoints) {
md = Math.floor(within.length/npoints);
var fin = []
for (var i=0; i<within.length; i++) {
if (within_idx[i]%md==0)
fin.push(within[i]);
}
return fin;
}
else
return within;
}
module.Graph.prototype.update = function(className, data) {
var data = this.resample(data);
this.lines[className].data = data;
this.axes.select("path."+className).datum(data)
.attr("d", this.lines[className].line);