summaryrefslogtreecommitdiff
path: root/addons/web_graph/static/src/js
diff options
context:
space:
mode:
authorGery Debongnie <ged@openerp.com>2013-12-11 11:12:24 +0100
committerGery Debongnie <ged@openerp.com>2013-12-11 11:12:24 +0100
commit4416acaa5391860a010a03a05d82fa7c5f6b9b57 (patch)
treeff98df339ba2814659278c0060a291bca415ca30 /addons/web_graph/static/src/js
parent28f27da6387b3f852cc2bc0408e2fd9f21b88d0a (diff)
[IMP] makes line charts smarter when multiple columns exists, in graph view (addon web_graph)
bzr revid: ged@openerp.com-20131211101224-eul3hvm0dt7kdz41
Diffstat (limited to 'addons/web_graph/static/src/js')
-rw-r--r--addons/web_graph/static/src/js/charts.js32
-rw-r--r--addons/web_graph/static/src/js/graph.js2
-rw-r--r--addons/web_graph/static/src/js/pivot.js14
3 files changed, 35 insertions, 13 deletions
diff --git a/addons/web_graph/static/src/js/charts.js b/addons/web_graph/static/src/js/charts.js
index b714e42392e..7478668865c 100644
--- a/addons/web_graph/static/src/js/charts.js
+++ b/addons/web_graph/static/src/js/charts.js
@@ -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;
diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js
index e35b8516dd4..07c0e578b83 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({
} 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());
}
}
}
diff --git a/addons/web_graph/static/src/js/pivot.js b/addons/web_graph/static/src/js/pivot.js
index b73939193a0..78f95548106 100644
--- a/addons/web_graph/static/src/js/pivot.js
+++ b/addons/web_graph/static/src/js/pivot.js
@@ -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) {