[IMP] makes line charts smarter when multiple columns exists, in graph view (addon web_graph)

bzr revid: ged@openerp.com-20131211101224-eul3hvm0dt7kdz41
This commit is contained in:
Gery Debongnie 2013-12-11 11:12:24 +01:00
parent 28f27da638
commit 4416acaa53
3 changed files with 35 additions and 13 deletions

View File

@ -1,10 +1,10 @@
openerp.web_graph.draw_chart = function (mode, pivot, svg) {
openerp.web_graph[mode](pivot, svg);
openerp.web_graph.draw_chart = function (mode, pivot, svg, measure_label) {
openerp.web_graph[mode](pivot, svg, measure_label);
};
openerp.web_graph.bar_chart = function (pivot, svg) {
openerp.web_graph.bar_chart = function (pivot, svg, measure_label) {
var dim_x = pivot.rows.groupby.length,
dim_y = pivot.cols.groupby.length,
data = [];
@ -156,7 +156,6 @@ openerp.web_graph.bar_chart = function (pivot, svg) {
.stacked(true)
.staggerLabels(true)
.tooltips(false)
.transitionDuration(0)
.width(650)
.height(400);
@ -165,7 +164,6 @@ openerp.web_graph.bar_chart = function (pivot, svg) {
.attr('width', 650)
.attr('height', 400)
.call(chart);
debugger;
nv.utils.windowResize(chart.update);
return chart;
@ -174,12 +172,22 @@ openerp.web_graph.bar_chart = function (pivot, svg) {
};
openerp.web_graph.line_chart = function (pivot, svg) {
var data = _.map(pivot.rows.main.children, function (pt) {
var value = pivot.get_value(pt.id, pivot.cols.main.id),
title = (pt.title !== undefined) ? pt.title : 'Undefined';
return {x: title, y: value};
});
openerp.web_graph.line_chart = function (pivot, svg, measure_label) {
var data = [],
dim_x = pivot.rows.groupby.length,
dim_y = pivot.cols.groupby.length;
if (dim_y === 0) {
pivot.cols.main.title = measure_label;
}
_.each(pivot.cols.headers, function (col) {
if (!col.is_expanded) {
var values = _.map(pivot.get_rows_depth(dim_x), function (row) {
return {x: row.title, y: pivot.get_value(row.id,col.id, 0)};
});
data.push({values: values, key: col.title || 'Undefined'});
}
});
nv.addGraph(function () {
var chart = nv.models.lineChart()
@ -191,7 +199,7 @@ openerp.web_graph.line_chart = function (pivot, svg) {
d3.select(svg)
.attr('width', 600)
.attr('height', 300)
.datum([{key: 'Bar chart', values: data}])
.datum(data)
.call(chart);
return chart;

View File

@ -172,7 +172,7 @@ instance.web_graph.GraphView = instance.web.View.extend({
} else {
this.$('.graph_main_content').append($('<div><svg></svg></div>'));
var svg = this.$('.graph_main_content svg')[0];
openerp.web_graph.draw_chart(this.mode, this.pivot_table, svg);
openerp.web_graph.draw_chart(this.mode, this.pivot_table, svg, this.measure_label());
}
}
}

View File

@ -100,6 +100,20 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
});
},
// return all columns with a path length of 'depth'
get_columns_depth: function (depth) {
return _.filter(this.cols.headers, function (hdr) {
return hdr.path.length === depth;
});
},
// return all rows with a path length of 'depth'
get_rows_depth: function (depth) {
return _.filter(this.rows.headers, function (hdr) {
return hdr.path.length === depth;
});
},
fold: function (header) {
var list = [];
function tree_traversal(tree) {