[#58,flot-graph][s]: support for new types of graph: bars, points and points and lines.

This commit is contained in:
Rufus Pollock
2012-03-14 22:32:40 +00:00
parent eb601dc2f3
commit a9b65b4d1d

View File

@@ -37,7 +37,10 @@ my.FlotGraph = Backbone.View.extend({
<label>Graph Type</label> \ <label>Graph Type</label> \
<div class="input editor-type"> \ <div class="input editor-type"> \
<select> \ <select> \
<option value="line">Line</option> \ <option value="lines-and-points">Lines and Points</option> \
<option value="lines">Lines</option> \
<option value="points">Points</option> \
<option value="bars">Bars</option> \
</select> \ </select> \
</div> \ </div> \
<label>Group Column (x-axis)</label> \ <label>Group Column (x-axis)</label> \
@@ -98,7 +101,7 @@ my.FlotGraph = Backbone.View.extend({
this.chartConfig = _.extend({ this.chartConfig = _.extend({
group: null, group: null,
series: [], series: [],
graphType: 'line' graphType: 'lines-and-points'
}, },
configFromHash, configFromHash,
config config
@@ -120,7 +123,13 @@ my.FlotGraph = Backbone.View.extend({
onEditorSubmit: function(e) { onEditorSubmit: function(e) {
var select = this.el.find('.editor-group select'); var select = this.el.find('.editor-group select');
this._getEditorData(); $editor = this;
var series = this.$series.map(function () {
return $(this).val();
});
this.chartConfig.series = $.makeArray(series)
this.chartConfig.group = this.el.find('.editor-group select').val();
this.chartConfig.graphType = this.el.find('.editor-type select').val();
// update navigation // update navigation
var qs = my.parseHashQueryString(); var qs = my.parseHashQueryString();
qs['graph'] = JSON.stringify(this.chartConfig); qs['graph'] = JSON.stringify(this.chartConfig);
@@ -139,28 +148,55 @@ my.FlotGraph = Backbone.View.extend({
if ((!areWeVisible || this.model.currentDocuments.length == 0)) { if ((!areWeVisible || this.model.currentDocuments.length == 0)) {
return return
} }
var series = this.createSeries();
var options = this.graphOptions[this.chartConfig.graphType];
this.plot = $.plot(this.$graph, series, options);
// create this.plot and cache it // create this.plot and cache it
if (!this.plot) { // if (!this.plot) {
// only lines for the present // this.plot = $.plot(this.$graph, series, options);
options = { // } else {
id: 'line', // this.plot.parseOptions(options);
name: 'Line Chart' // this.plot.setData(this.createSeries());
}; // this.plot.resize();
this.plot = $.plot(this.$graph, this.createSeries(), options); // this.plot.setupGrid();
} // this.plot.draw();
this.plot.setData(this.createSeries()); // }
this.plot.resize();
this.plot.setupGrid();
this.plot.draw();
}, },
_getEditorData: function() { graphOptions: {
$editor = this lines: {
var series = this.$series.map(function () { series: {
return $(this).val(); lines: { show: true }
}); }
this.chartConfig.series = $.makeArray(series) }
this.chartConfig.group = this.el.find('.editor-group select').val(); , points: {
series: {
points: { show: true }
},
grid: { hoverable: true, clickable: true }
}
, 'lines-and-points': {
series: {
points: { show: true },
lines: { show: true }
},
grid: { hoverable: true, clickable: true }
}
, bars: {
series: {
lines: {show: false},
bars: {
show: true,
barWidth: 1,
align: "left",
fill: true
}
},
xaxis: {
tickSize: 1,
tickLength: 1,
}
}
}, },
createSeries: function () { createSeries: function () {