Merge branch 'master' into gh-pages
This commit is contained in:
117
recline.js
117
recline.js
@@ -131,14 +131,13 @@ this.recline.Model = this.recline.Model || {};
|
|||||||
|
|
||||||
// ## A Dataset model
|
// ## A Dataset model
|
||||||
//
|
//
|
||||||
// A model must have the following (Backbone) attributes:
|
// A model has the following (non-Backbone) attributes:
|
||||||
//
|
//
|
||||||
// * fields: (aka columns) is a FieldList listing all the fields on this
|
// * fields: (aka columns) is a FieldList listing all the fields on this
|
||||||
// Dataset (this can be set explicitly, or, on fetch() of Dataset
|
// Dataset (this can be set explicitly, or, will be set by Dataset.fetch() or Dataset.query()
|
||||||
// information from the backend, or as is perhaps most common on the first
|
// * currentDocuments: a DocumentList containing the Documents we have
|
||||||
// query)
|
// currently loaded for viewing (you update currentDocuments by calling query)
|
||||||
// * currentDocuments: a DocumentList containing the Documents we have currently loaded for viewing (you update currentDocuments by calling getRows)
|
// * docCount: total number of documents in this dataset
|
||||||
// * docCount: total number of documents in this dataset (obtained on a fetch for this Dataset)
|
|
||||||
my.Dataset = Backbone.Model.extend({
|
my.Dataset = Backbone.Model.extend({
|
||||||
__type__: 'Dataset',
|
__type__: 'Dataset',
|
||||||
initialize: function(model, backend) {
|
initialize: function(model, backend) {
|
||||||
@@ -553,11 +552,9 @@ my.FlotGraph = Backbone.View.extend({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
var series = this.createSeries();
|
var series = this.createSeries();
|
||||||
var options = this.graphOptions[this.chartConfig.graphType];
|
var options = this.getGraphOptions(this.chartConfig.graphType);
|
||||||
this.plot = $.plot(this.$graph, series, options);
|
this.plot = $.plot(this.$graph, series, options);
|
||||||
if (this.chartConfig.graphType in { 'points': '', 'lines-and-points': '' }) {
|
this.setupTooltips();
|
||||||
this.setupTooltips();
|
|
||||||
}
|
|
||||||
// create this.plot and cache it
|
// create this.plot and cache it
|
||||||
// if (!this.plot) {
|
// if (!this.plot) {
|
||||||
// this.plot = $.plot(this.$graph, series, options);
|
// this.plot = $.plot(this.$graph, series, options);
|
||||||
@@ -570,40 +567,63 @@ my.FlotGraph = Backbone.View.extend({
|
|||||||
// }
|
// }
|
||||||
},
|
},
|
||||||
|
|
||||||
graphOptions: {
|
// needs to be function as can depend on state
|
||||||
lines: {
|
getGraphOptions: function(typeId) {
|
||||||
series: {
|
var self = this;
|
||||||
lines: { show: true }
|
var tickFormatter = function (val) {
|
||||||
}
|
if (self.model.currentDocuments.models[val]) {
|
||||||
}
|
var out = self.model.currentDocuments.models[val].get(self.chartConfig.group);
|
||||||
, points: {
|
// if the x-axis value was in fact a number we want that not the
|
||||||
series: {
|
if (typeof(out) == 'number') {
|
||||||
points: { show: true }
|
return val;
|
||||||
},
|
} else {
|
||||||
grid: { hoverable: true, clickable: true }
|
return out;
|
||||||
}
|
}
|
||||||
, 'lines-and-points': {
|
}
|
||||||
series: {
|
return val;
|
||||||
points: { show: true },
|
}
|
||||||
lines: { show: true }
|
// TODO: we should really use tickFormatter and 1 interval ticks if (and
|
||||||
},
|
// only if) x-axis values are non-numeric
|
||||||
grid: { hoverable: true, clickable: true }
|
// However, that is non-trivial to work out from a dataset (datasets may
|
||||||
}
|
// have no field type info). Thus at present we only do this for bars.
|
||||||
, bars: {
|
var options = {
|
||||||
series: {
|
lines: {
|
||||||
lines: {show: false},
|
series: {
|
||||||
bars: {
|
lines: { show: true }
|
||||||
show: true,
|
}
|
||||||
barWidth: 1,
|
}
|
||||||
align: "left",
|
, points: {
|
||||||
fill: true
|
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: "center",
|
||||||
|
fill: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
grid: { hoverable: true, clickable: true },
|
||||||
|
xaxis: {
|
||||||
|
tickSize: 1,
|
||||||
|
tickLength: 1,
|
||||||
|
tickFormatter: tickFormatter
|
||||||
}
|
}
|
||||||
},
|
|
||||||
xaxis: {
|
|
||||||
tickSize: 1,
|
|
||||||
tickLength: 1,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return options[typeId];
|
||||||
},
|
},
|
||||||
|
|
||||||
setupTooltips: function() {
|
setupTooltips: function() {
|
||||||
@@ -624,12 +644,19 @@ my.FlotGraph = Backbone.View.extend({
|
|||||||
var previousPoint = null;
|
var previousPoint = null;
|
||||||
this.$graph.bind("plothover", function (event, pos, item) {
|
this.$graph.bind("plothover", function (event, pos, item) {
|
||||||
if (item) {
|
if (item) {
|
||||||
if (previousPoint != item.dataIndex) {
|
if (previousPoint != item.datapoint) {
|
||||||
previousPoint = item.dataIndex;
|
previousPoint = item.datapoint;
|
||||||
|
|
||||||
$("#flot-tooltip").remove();
|
$("#flot-tooltip").remove();
|
||||||
var x = item.datapoint[0].toFixed(2),
|
var x = item.datapoint[0];
|
||||||
y = item.datapoint[1].toFixed(2);
|
var y = item.datapoint[1];
|
||||||
|
// convert back from 'index' value on x-axis (e.g. in cases where non-number values)
|
||||||
|
if (self.model.currentDocuments.models[x]) {
|
||||||
|
x = self.model.currentDocuments.models[x].get(self.chartConfig.group);
|
||||||
|
} else {
|
||||||
|
x = x.toFixed(2);
|
||||||
|
}
|
||||||
|
y = y.toFixed(2);
|
||||||
|
|
||||||
var content = _.template('<%= group %> = <%= x %>, <%= series %> = <%= y %>', {
|
var content = _.template('<%= group %> = <%= x %>, <%= series %> = <%= y %>', {
|
||||||
group: self.chartConfig.group,
|
group: self.chartConfig.group,
|
||||||
|
|||||||
Reference in New Issue
Block a user