summaryrefslogtreecommitdiff
path: root/addons/web_graph/static/src
diff options
context:
space:
mode:
authorGery Debongnie <ged@openerp.com>2013-12-11 12:08:36 +0100
committerGery Debongnie <ged@openerp.com>2013-12-11 12:08:36 +0100
commit3453d9da01dc22c704181942530e8abf7dcab95b (patch)
treefac89e5d2cde22cc40ee675c85f243b10ae258da /addons/web_graph/static/src
parent4ab861699179e35e513c2cd6ac2c0e77c8e513bb (diff)
[REF] improves the charting code by using get_rows_depth and get_columns_depth methods (addon web_graph)
bzr revid: ged@openerp.com-20131211110836-8sq83pcksjm5sboq
Diffstat (limited to 'addons/web_graph/static/src')
-rw-r--r--addons/web_graph/static/src/js/charts.js59
1 files changed, 22 insertions, 37 deletions
diff --git a/addons/web_graph/static/src/js/charts.js b/addons/web_graph/static/src/js/charts.js
index f0025510f9c..42bb7599912 100644
--- a/addons/web_graph/static/src/js/charts.js
+++ b/addons/web_graph/static/src/js/charts.js
@@ -36,13 +36,11 @@ openerp.web_graph.bar_chart = function (pivot, svg, measure_label) {
});
// Only column groupbys ****************************************************
} else if ((dim_x === 0) && (dim_y >= 1)){
- _.each(pivot.cols.headers, function (header) {
- if (header.path.length === 1) {
- data.push({
- key: header.title,
- values: [{x:header.root.main.title, y: pivot.get_total(header)}]
- });
- }
+ data = _.map(pivot.get_columns_depth(1), function (header) {
+ return {
+ key: header.title,
+ values: [{x:header.root.main.title, y: pivot.get_total(header)}]
+ };
});
nv.addGraph(function() {
var chart = nv.models.multiBarChart()
@@ -93,20 +91,14 @@ openerp.web_graph.bar_chart = function (pivot, svg, measure_label) {
});
// 1 row groupby and some col groupbys**************************************
} else if ((dim_x === 1) && (dim_y >= 1)) {
- data = [];
- _.each(pivot.cols.headers, function (colhdr) {
- if (colhdr.path.length === 1) {
- var values = [];
- _.each(pivot.rows.headers, function (header) {
- if (header.path.length === 1) {
- values.push({
- x: header.title || 'Undefined',
- y: pivot.get_value(header.id, colhdr.id, 0)
- });
- }
- });
- data.push({key: colhdr.title || 'Undefined', values: values});
- }
+ data = _.map(pivot.get_columns_depth(1), function (colhdr) {
+ var values = _.map(pivot.get_rows_depth(1), function (header) {
+ return {
+ x: header.title || 'Undefined',
+ y: pivot.get_value(header.id, colhdr.id, 0)
+ };
+ });
+ return {key: colhdr.title || 'Undefined', values: values};
});
nv.addGraph(function () {
@@ -128,26 +120,19 @@ openerp.web_graph.bar_chart = function (pivot, svg, measure_label) {
});
// At least two row groupby*************************************************
} else {
- data = [];
- var keys = _.uniq(_.map(_.filter(pivot.rows.headers, function (hdr) {
- return hdr.path.length === 2;
- }), function (hdr) {
+ var keys = _.uniq(_.map(pivot.get_rows_depth(2), function (hdr) {
return hdr.title || 'Undefined';
}));
data = _.map(keys, function (key) {
- var values = [];
- _.each(pivot.rows.headers, function (hdr) {
- if (hdr.path.length === 1) {
- var subhdr = _.find(hdr.children, function (child) {
- return ((child.title === key) || ((child.title === undefined) && (key === 'Undefined')));
- });
- values.push({
- x: hdr.title || 'Undefined',
- y: (subhdr) ? pivot.get_total(subhdr) : 0
- });
- }
+ var values = _.map(pivot.get_rows_depth(1), function (hdr) {
+ var subhdr = _.find(hdr.children, function (child) {
+ return ((child.title === key) || ((child.title === undefined) && (key === 'Undefined')));
+ });
+ return {
+ x: hdr.title || 'Undefined',
+ y: (subhdr) ? pivot.get_total(subhdr) : 0
+ };
});
-
return {key:key, values: values};
});