From b501b7123cd6d598d3f9b179f0fc096271383c69 Mon Sep 17 00:00:00 2001 From: User Date: Thu, 8 Nov 2012 12:31:05 -0500 Subject: [PATCH 1/3] Added ability to extend graph options with state parameter 'graphOptions' --- src/view.graph.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/view.graph.js b/src/view.graph.js index bcde3e57..8ad75391 100644 --- a/src/view.graph.js +++ b/src/view.graph.js @@ -247,7 +247,14 @@ my.Graph = Backbone.View.extend({ }, grid: { hoverable: true, clickable: true } }; - return optionsPerGraphType[typeId]; + + if ("graphOptions" in self.state.attributes){ + return _.extend(optionsPerGraphType[typeId], + self.state.attributes.graphOptions + ) + }else{ + return optionsPerGraphType[typeId]; + } }, createSeries: function() { From c74c329c21ef51a7a8ff7b41eeecfa1a33963842 Mon Sep 17 00:00:00 2001 From: User Date: Thu, 8 Nov 2012 13:02:49 -0500 Subject: [PATCH 2/3] Added a line to document graphOptions, changed attribute access method --- src/view.graph.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/view.graph.js b/src/view.graph.js index 8ad75391..d0371d69 100644 --- a/src/view.graph.js +++ b/src/view.graph.js @@ -15,9 +15,10 @@ this.recline.View = this.recline.View || {}; // { // group: {column name for x-axis}, // series: [{column name for series A}, {column name series B}, ... ], -// graphType: 'line' +// graphType: 'line', +// graphOptions: {custom [Flotr2 options](http://www.humblesoftware.com/flotr2/documentation#configuration)} // } -// +// // NB: should *not* provide an el argument to the view but must let the view // generate the element itself (you can then append view.el to the DOM. my.Graph = Backbone.View.extend({ @@ -248,9 +249,9 @@ my.Graph = Backbone.View.extend({ grid: { hoverable: true, clickable: true } }; - if ("graphOptions" in self.state.attributes){ + if (self.state.get('graphOptions')){ return _.extend(optionsPerGraphType[typeId], - self.state.attributes.graphOptions + self.state.get('graphOptions') ) }else{ return optionsPerGraphType[typeId]; From 94c56e1d10511ce850a95d60e397fb8ec10c3ab4 Mon Sep 17 00:00:00 2001 From: User Date: Fri, 9 Nov 2012 12:55:54 -0500 Subject: [PATCH 3/3] Added test case for 'graphOptions' --- test/view.graph.test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/view.graph.test.js b/test/view.graph.test.js index d7de87c5..25a04d6c 100644 --- a/test/view.graph.test.js +++ b/test/view.graph.test.js @@ -69,3 +69,18 @@ test('GraphControls basics', function () { view.remove(); }); +test('Overriding graph options', function () { + var dataset = Fixture.getDataset(); + var randomWidth = Math.random(); + var view = new recline.View.Graph({ + model: dataset, + state: { + 'graphType': 'bars', + 'group': 'date', + 'series': ['y', 'z'], + 'graphOptions': { bars: {barWidth: randomWidth}} + } + }); + equal(view.getGraphOptions('bars').bars.barWidth, randomWidth) + view.remove(); +}); \ No newline at end of file