[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
This commit is contained in:
Gery Debongnie 2013-11-23 11:19:22 +01:00
parent 1e32b763f0
commit ebf46e668d
3 changed files with 14 additions and 25 deletions

View File

@ -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;
});
},
};

View File

@ -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);
}
},

View File

@ -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;