summaryrefslogtreecommitdiff
path: root/addons/web_graph/static/src/js
diff options
context:
space:
mode:
authorGery Debongnie <ged@openerp.com>2013-11-23 11:19:22 +0100
committerGery Debongnie <ged@openerp.com>2013-11-23 11:19:22 +0100
commitebf46e668d6f0ae9695eb693b8ffb6b1498ba6c4 (patch)
treec4ff52345f03ef5a969f837b5cd86d19f70bc471 /addons/web_graph/static/src/js
parent1e32b763f0e1da669d835b02fbf680f2deea0f65 (diff)
[REF] moves the data formatting for charts to the charts file (instead of pivot) in addon web_graph
bzr revid: ged@openerp.com-20131123101922-xi429dmnwpqlfsiq
Diffstat (limited to 'addons/web_graph/static/src/js')
-rw-r--r--addons/web_graph/static/src/js/charts.js27
-rw-r--r--addons/web_graph/static/src/js/graph.js2
-rw-r--r--addons/web_graph/static/src/js/pivot.js10
3 files changed, 14 insertions, 25 deletions
diff --git a/addons/web_graph/static/src/js/charts.js b/addons/web_graph/static/src/js/charts.js
index 0ecd15d1daf..2fb0cd7b380 100644
--- a/addons/web_graph/static/src/js/charts.js
+++ b/addons/web_graph/static/src/js/charts.js
@@ -1,17 +1,16 @@
-var formatter = function (measure) {
- return function (datapt) {
- var val = datapt.attributes;
- return {
- x: datapt.attributes.value[1],
- y: measure ? val.aggregates[measure] : val.length,
- };
- };
-};
+function format_chart_data (pivot) {
+ var values = _.map(pivot.rows[0].children.reverse(), function (pt) {
+ var val = pivot.get_value(pt.id, 2);
+ return {x: pt.name, y: val};
+ });
+ return [{key: 'Bar chart', values: values}];
+};
var Charts = {
- bar_chart : function (data) {
+ bar_chart : function (pivot) {
+ var data = format_chart_data(pivot);
nv.addGraph(function () {
var chart = nv.models.discreteBarChart()
.tooltips(false)
@@ -31,7 +30,8 @@ var Charts = {
});
},
- line_chart: function (data) {
+ line_chart: function (pivot) {
+ data = format_chart_data(pivot);
nv.addGraph(function () {
var chart = nv.models.lineChart()
.x(function (d,u) { return u; })
@@ -49,7 +49,8 @@ var Charts = {
});
},
- pie_chart: function (data) {
+ pie_chart: function (pivot) {
+ data = format_chart_data(pivot);
nv.addGraph(function () {
var chart = nv.models.pieChart()
.color(d3.scale.category10().range())
@@ -67,6 +68,4 @@ var Charts = {
return chart;
});
},
-
-
}; \ No newline at end of file
diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js
index da3f4257b33..4d74ad71121 100644
--- a/addons/web_graph/static/src/js/graph.js
+++ b/addons/web_graph/static/src/js/graph.js
@@ -172,7 +172,7 @@ instance.web_graph.GraphView = instance.web.View.extend({
this.svg.remove();
this.svg = $('<div><svg></svg></div>');
this.$el.filter('.graph_main_content').append(this.svg);
- Charts[mode](this.pivot_table.get_chart_data());
+ Charts[mode](this.pivot_table);
}
},
diff --git a/addons/web_graph/static/src/js/pivot.js b/addons/web_graph/static/src/js/pivot.js
index 288bd14436e..a5a3af78ae9 100644
--- a/addons/web_graph/static/src/js/pivot.js
+++ b/addons/web_graph/static/src/js/pivot.js
@@ -179,16 +179,6 @@ var PivotTable = openerp.web.Class.extend({
});
},
- get_chart_data: function () {
- var self = this;
- var values = _.map(this.rows[0].children, function (pt) {
- var val = self.get_value(pt.id, 2);
- return {x: pt.name, y: val};
- });
- return [{key: 'Bar chart', values: values}];
-
- },
-
swap_axis: function () {
var temp = this.rows;
this.rows = this.cols;