Flot: dramatic performance improvements

Redraws graphs in place instead of recomputing them from scratch on each
new time index.
This commit is contained in:
Kyle Kingsbury 2014-01-03 14:45:38 -08:00
parent 6a7711376b
commit afa779685d

View file

@ -49,7 +49,8 @@
this.clockSub = clock.subscribe(function(t) {
self.trimData(t);
self.setupGraph(t);
self.updateTime(t);
// self.setupGraph(t);
});
// Subscribe to our query
@ -70,7 +71,10 @@
FlotView.prototype.setupGraph = function(t) {
if (this.container.width() === 0 ||
this.container.height() === 0) {
if (this.graph != null) {
this.graph.shutdown();
this.graph = null;
}
return;
}
@ -100,6 +104,21 @@
});
};
// Called as the clock advances to new times.
FlotView.prototype.updateTime = function(t) {
if (this.graph == null) {
console.log("first initialization");
this.setupGraph(t);
return;
}
var axis = this.graph.getOptions().xaxes[0];
axis.min = t - this.timeRange;
axis.max = t;
this.graph.setupGrid();
this.graph.draw();
}
// Re-order the data list and series index to be in sorted order by label.
FlotView.prototype.resortSeries = function() {
// Shorten labels