summaryrefslogtreecommitdiff
path: root/addons/web_graph/static/src/js/graph.js
diff options
context:
space:
mode:
authorGery Debongnie <ged@openerp.com>2013-12-20 12:02:43 +0100
committerGery Debongnie <ged@openerp.com>2013-12-20 12:02:43 +0100
commit828d06f174b6892cfbe11fe454eb659589b17720 (patch)
treede113e2db86ae9fbffba5936bda29ca67f2fbc08 /addons/web_graph/static/src/js/graph.js
parent2dffdc7c96643a0e970462ada59beaeb6a3289b0 (diff)
[IMP] makes the graph view accept a new way to define graphs (supports type='col', type='row' and type='measure' attributes to fields, also supports 'stacked' attribute in <graph> (addon web_graph)
bzr revid: ged@openerp.com-20131220110243-sccxichm0mgm21uz
Diffstat (limited to 'addons/web_graph/static/src/js/graph.js')
-rw-r--r--addons/web_graph/static/src/js/graph.js42
1 files changed, 29 insertions, 13 deletions
diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js
index 189ce801732..4eeaec194eb 100644
--- a/addons/web_graph/static/src/js/graph.js
+++ b/addons/web_graph/static/src/js/graph.js
@@ -50,26 +50,43 @@ instance.web_graph.GraphView = instance.web.View.extend({
view_loading: function (fields_view_get) {
var self = this,
- measure = null;
+ arch = fields_view_get.arch,
+ measure = null,
+ stacked = false;
- if (fields_view_get.arch.attrs.type === 'bar') {
+ if (arch.attrs.type === 'bar' || !_.has(arch.attrs, 'type')) {
this.graph_widget.mode = 'bar_chart';
}
+ if (arch.attrs.stacked === "True") {
+ stacked = true;
+ }
- _.each(fields_view_get.arch.children, function (field) {
- if ('name' in field.attrs) {
+ _.each(arch.children, function (field) {
+ if (_.has(field.attrs, 'type')) {
+ switch (field.attrs.type) {
+ case "row":
+ self.default_row_groupby.push(field.attrs.name);
+ break;
+ case "col":
+ self.default_col_groupby.push(field.attrs.name);
+ break;
+ case "measure":
+ measure = field.attrs.name;
+ break;
+ }
+ } else { // old style, kept for backward compatibility
if ('operator' in field.attrs) {
measure = field.attrs.name;
} else {
- if (measure) {
- self.default_col_groupby.push(field.attrs.name);
- } else {
- self.default_row_groupby.push(field.attrs.name);
- }
+ self.default_row_groupby.push(field.attrs.name);
}
}
});
- this.graph_widget.pivot.config({measure:measure, update:false});
+ this.graph_widget.config({
+ measure:measure,
+ update:false,
+ bar_ui: (stacked) ? 'stack' : 'group'
+ });
},
do_search: function (domain, context, group_by) {
@@ -249,7 +266,6 @@ instance.web_graph.Graph = instance.web.Widget.extend({
},
display_data: function () {
- var pivot = this.pivot;
this.$('.graph_main_content svg').remove();
this.table.empty();
@@ -258,7 +274,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({
} else {
this.$('.graph_header').css('display', 'none');
}
- if (pivot.no_data) {
+ if (this.pivot.no_data) {
var msg = 'No data available. Try to remove any filter or add some data.';
this.table.append($('<tr><td>' + msg + '</td></tr>'));
} else {
@@ -555,7 +571,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({
.tooltips(false)
.width(self.width)
.height(self.height)
- .stacked(self.bar_ui === 'stacked')
+ .stacked(self.bar_ui === 'stack')
.staggerLabels(true);
d3.select(self.svg)