[view/graph][s]: make sure we do not try to draw if graph not yet properly configured.

* Was encountering a bug where data loads triggering a redraw but nothing yet properly configured. (This has been previously hidden by fact we don't draw if graph view is hidden -- which I had temporarily turned off).
This commit is contained in:
Rufus Pollock
2012-05-08 16:20:53 +01:00
parent 749d6190ca
commit b6664e9292

View File

@@ -111,7 +111,7 @@ my.Graph = Backbone.View.extend({
var stateData = _.extend({ var stateData = _.extend({
group: null, group: null,
// so that at least one series chooser box shows up // so that at least one series chooser box shows up
series: [""], series: [],
graphType: 'lines-and-points' graphType: 'lines-and-points'
}, },
options.state options.state
@@ -134,7 +134,12 @@ my.Graph = Backbone.View.extend({
if (this.state.get('group')) { if (this.state.get('group')) {
this._selectOption('.editor-group', this.state.get('group')); this._selectOption('.editor-group', this.state.get('group'));
} }
_.each(this.state.get('series'), function(series, idx) { // ensure at least one series box shows up
var tmpSeries = [""];
if (this.state.get('series').length > 0) {
tmpSeries = this.state.get('series');
}
_.each(tmpSeries, function(series, idx) {
self.addSeries(idx); self.addSeries(idx);
self._selectOption('.editor-series.js-series-' + idx, series); self._selectOption('.editor-series.js-series-' + idx, series);
}); });
@@ -182,20 +187,13 @@ my.Graph = Backbone.View.extend({
if ((!areWeVisible || this.model.currentDocuments.length === 0)) { if ((!areWeVisible || this.model.currentDocuments.length === 0)) {
return; return;
} }
var series = this.createSeries(); // check we have something to plot
var options = this.getGraphOptions(this.state.attributes.graphType); if (this.state.get('group') && this.state.get('series')) {
this.plot = $.plot(this.$graph, series, options); var series = this.createSeries();
this.setupTooltips(); var options = this.getGraphOptions(this.state.attributes.graphType);
// create this.plot and cache it this.plot = $.plot(this.$graph, series, options);
// if (!this.plot) { this.setupTooltips();
// this.plot = $.plot(this.$graph, series, options); }
// } else {
// this.plot.parseOptions(options);
// this.plot.setData(this.createSeries());
// this.plot.resize();
// this.plot.setupGrid();
// this.plot.draw();
// }
}, },
// ### getGraphOptions // ### getGraphOptions