From 769474d43db4eb44f594fa3e4ed5c4efbf3d6440 Mon Sep 17 00:00:00 2001 From: Leonardo Donelli Date: Thu, 8 Jan 2015 13:06:08 +0100 Subject: [PATCH 1/3] New module: web_graph_improved. --- web_graph_improved/README.md | 7 ++ web_graph_improved/__init__.py | 1 + web_graph_improved/__openerp__.py | 33 +++++++ .../static/src/js/web_graph_improved.js | 89 +++++++++++++++++++ .../view/graph_improved_view.xml | 17 ++++ 5 files changed, 147 insertions(+) create mode 100644 web_graph_improved/README.md create mode 100644 web_graph_improved/__init__.py create mode 100644 web_graph_improved/__openerp__.py create mode 100644 web_graph_improved/static/src/js/web_graph_improved.js create mode 100644 web_graph_improved/view/graph_improved_view.xml diff --git a/web_graph_improved/README.md b/web_graph_improved/README.md new file mode 100644 index 00000000..da0a19c7 --- /dev/null +++ b/web_graph_improved/README.md @@ -0,0 +1,7 @@ +Charts, Improved. +================= + +Various improvements to the graph view: + + * Bar: can plot multiple variables (called measures in the odoo client) + when there is only one row group diff --git a/web_graph_improved/__init__.py b/web_graph_improved/__init__.py new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/web_graph_improved/__init__.py @@ -0,0 +1 @@ + diff --git a/web_graph_improved/__openerp__.py b/web_graph_improved/__openerp__.py new file mode 100644 index 00000000..71468c8d --- /dev/null +++ b/web_graph_improved/__openerp__.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Leonardo Donelli @ Creativi Quadrati +# Copyright (C) 2014 Leonardo Donelli +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +{ + 'name': 'Better Charts', + 'version': '0.1', + 'category': 'Web', + 'summary': 'Improves graph views.', + 'author': 'Leonardo Donelli', + 'website': 'http://learts.glaucus.in', + 'depends': ['web_graph'], + 'data': ['view/graph_improved_view.xml'], + 'installable': True, + 'auto_install': False, +} diff --git a/web_graph_improved/static/src/js/web_graph_improved.js b/web_graph_improved/static/src/js/web_graph_improved.js new file mode 100644 index 00000000..608c9fbb --- /dev/null +++ b/web_graph_improved/static/src/js/web_graph_improved.js @@ -0,0 +1,89 @@ +openerp.web_graph_improved = function(instance) { + + instance.web_graph.Graph.include({ + bar: function() { + var self = this, + dim_x = this.pivot.rows.groupby.length, + dim_y = this.pivot.cols.groupby.length, + show_controls = (this.width > 400 && this.height > 300 && dim_x + dim_y >=2), + data; + + // No groupby + if ((dim_x === 0) && (dim_y === 0)) { + data = [{key: _t('Total'), values:[{ + x: _t('Total'), + y: this.pivot.get_total()[0], + }]}]; + // Only column groupbys + } else if ((dim_x === 0) && (dim_y >= 1)){ + data = _.map(this.pivot.get_cols_with_depth(1), function (header) { + return { + key: header.title, + values: [{x:header.title, y: self.pivot.get_total(header)[0]}] + }; + }); + // Just 1 row groupby + } else if ((dim_x === 1) && (dim_y === 0)) { + data = _.map(self.pivot.measures, function(measure, i) { + var series = _.map(self.pivot.main_row().children, function (pt) { + var value = self.pivot.get_total(pt)[i], + title = (pt.title !== undefined) ? pt.title : _t('Undefined'); + return {x: title, y: value}; + }); + return {key: self.pivot.measures[i].string, values:series}; + }); + // 1 row groupby and some col groupbys + } else if ((dim_x === 1) && (dim_y >= 1)) { + data = _.map(this.pivot.get_cols_with_depth(1), function (colhdr) { + var values = _.map(self.pivot.get_rows_with_depth(1), function (header) { + return { + x: header.title || _t('Undefined'), + y: self.pivot.get_values(header.id, colhdr.id)[0] || 0 + }; + }); + return {key: colhdr.title || _t('Undefined'), values: values}; + }); + // At least two row groupby + } else { + var keys = _.uniq(_.map(this.pivot.get_rows_with_depth(2), function (hdr) { + return hdr.title || _t('Undefined'); + })); + data = _.map(keys, function (key) { + var values = _.map(self.pivot.get_rows_with_depth(1), function (hdr) { + var subhdr = _.find(hdr.children, function (child) { + return ((child.title === key) || ((child.title === undefined) && (key === _t('Undefined')))); + }); + return { + x: hdr.title || _t('Undefined'), + y: (subhdr) ? self.pivot.get_total(subhdr)[0] : 0 + }; + }); + return {key:key, values: values}; + }); + } + + nv.addGraph(function () { + var chart = nv.models.multiBarChart() + // .reduceXTicks(false) + .stacked(self.bar_ui === 'stack') + .showControls(show_controls); + + // if (self.width / data[0].values.length < 80) { + // chart.rotateLabels(-15); + // chart.reduceXTicks(true); + // chart.margin({bottom:40}); + // } + + d3.select(self.svg) + .datum(data) + .attr('width', self.width) + .attr('height', self.height) + .call(chart); + + nv.utils.windowResize(chart.update); + return chart; + }); + + } + }); +} diff --git a/web_graph_improved/view/graph_improved_view.xml b/web_graph_improved/view/graph_improved_view.xml new file mode 100644 index 00000000..5131e37f --- /dev/null +++ b/web_graph_improved/view/graph_improved_view.xml @@ -0,0 +1,17 @@ + + + + + + + + + From 253053346863e4259823d52bcda9064b3767fbee Mon Sep 17 00:00:00 2001 From: Leonardo Donelli Date: Mon, 12 Jan 2015 17:04:46 +0100 Subject: [PATCH 2/3] Better README. --- web_graph_improved/README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/web_graph_improved/README.md b/web_graph_improved/README.md index da0a19c7..e9632a40 100644 --- a/web_graph_improved/README.md +++ b/web_graph_improved/README.md @@ -1,7 +1,15 @@ Charts, Improved. ================= -Various improvements to the graph view: +Improve the charting capabilities of Odoo. - * Bar: can plot multiple variables (called measures in the odoo client) - when there is only one row group +Implemented features: + * Plot multiple variables (called measures in the odoo client) with bar charts + using grouped bars. + +Planned: + * Plot multiple measures on line charts + * Scatter/Bubble chart + * Sunburst ("grouped Pie chart") + * Bullet Chart + * Stacked bar chart From ecfd38fc95fad3c8c03d44ef6bf7a6d81d35c268 Mon Sep 17 00:00:00 2001 From: Leonardo Donelli Date: Tue, 17 Feb 2015 16:34:09 +0100 Subject: [PATCH 3/3] Remove commented lines, put license in manifest file. --- web_graph_improved/__openerp__.py | 1 + web_graph_improved/static/src/js/web_graph_improved.js | 7 ------- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/web_graph_improved/__openerp__.py b/web_graph_improved/__openerp__.py index 71468c8d..6d0c1548 100644 --- a/web_graph_improved/__openerp__.py +++ b/web_graph_improved/__openerp__.py @@ -25,6 +25,7 @@ 'category': 'Web', 'summary': 'Improves graph views.', 'author': 'Leonardo Donelli', + 'license': 'AGPL-3', 'website': 'http://learts.glaucus.in', 'depends': ['web_graph'], 'data': ['view/graph_improved_view.xml'], diff --git a/web_graph_improved/static/src/js/web_graph_improved.js b/web_graph_improved/static/src/js/web_graph_improved.js index 608c9fbb..56cfc575 100644 --- a/web_graph_improved/static/src/js/web_graph_improved.js +++ b/web_graph_improved/static/src/js/web_graph_improved.js @@ -64,16 +64,9 @@ openerp.web_graph_improved = function(instance) { nv.addGraph(function () { var chart = nv.models.multiBarChart() - // .reduceXTicks(false) .stacked(self.bar_ui === 'stack') .showControls(show_controls); - // if (self.width / data[0].values.length < 80) { - // chart.rotateLabels(-15); - // chart.reduceXTicks(true); - // chart.margin({bottom:40}); - // } - d3.select(self.svg) .datum(data) .attr('width', self.width)