From b6564900adb67531b08bf7ab1b6ae8c435380855 Mon Sep 17 00:00:00 2001 From: "vda (OpenERP)" Date: Fri, 15 Apr 2011 12:12:41 +0530 Subject: [FIX] Graph According to type. bzr revid: vda@tinyerp.com-20110415064241-3rq913vloy9mchc1 --- addons/base_graph/static/src/js/graph.js | 265 +++++++++++++++++++++++++++++++ 1 file changed, 265 insertions(+) create mode 100644 addons/base_graph/static/src/js/graph.js (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js new file mode 100644 index 00000000000..b7e82c58279 --- /dev/null +++ b/addons/base_graph/static/src/js/graph.js @@ -0,0 +1,265 @@ +/*--------------------------------------------------------- + * OpenERP base_graph + *---------------------------------------------------------*/ + +openerp.base_graph = function (openerp) { +QWeb.add_template('/base_graph/static/src/xml/base_graph.xml'); +openerp.base.views.add('graph', 'openerp.base_graph.GraphView'); +openerp.base_graph.GraphView = openerp.base.Controller.extend({ + + init: function(view_manager, session, element_id, dataset, view_id) { + + this._super(session, element_id); + this.view_manager = view_manager; + this.dataset = dataset; + this.model = this.dataset.model; + this.view_id = view_id; + }, + do_show: function () { + // TODO: re-trigger search + this.$element.show(); + }, + do_hide: function () { + this.$element.hide(); + }, + start: function() { + this.rpc("/base_graph/graphview/load", {"model": this.model, "view_id": this.view_id}, this.on_loaded); + }, + on_loaded: function(data) { + var self = this; + this.fields_view = data.fields_view; + this.name = this.fields_view.name || this.fields_view.arch.attrs.string; + this.view_id = this.fields_view.view_id; + this.chart = this.fields_view.arch.attrs.type || 'pie'; + this.fields = this.fields_view.fields; + this.chart_info_fields = []; + this.operator_field = ''; + this.group_field = ''; + this.orientation = this.fields_view.arch.attrs.orientation || ''; + for(fld in this.fields_view.arch.children) { + if (this.fields_view.arch.children[fld].attrs.operator) { + this.operator_field = this.fields_view.arch.children[fld].attrs.name; + } + else if (this.fields_view.arch.children[fld].attrs.group) { + this.group_field = this.fields_view.arch.children[fld].attrs.name + } + else { + this.chart_info_fields.push(this.fields_view.arch.children[fld].attrs.name) + } + } + + this.load_chart(); + }, + + load_chart: function() { + var self = this; + this.dataset.read_ids( + this.dataset.ids, + this.fields, + function(result) { + self.schedule_chart(result) + } + ) + }, + + schedule_chart: function(result) { + + this.$element.html(QWeb.render("GraphView", {"fields_view": this.fields_view, "chart": this.chart})); + + console.log('fields view >>>>>>',this.fields_view) + + for(res in result) { + for(fld in result[res]) { + if(typeof result[res][fld] == 'object') { + result[res][fld] = result[res][fld][result[res][fld].length - 1] + } + } + } + if(this.chart == 'bar') { + var xAxis = {}; + var yAxis = {}; + + if (this.orientation && this.orientation == 'horizontal') { + this.chart = "barH"; + xAxis:{template:"#"+this.operator_field+"#"}; + yAxis:{title: this.chart_info_fields[0]}; + } else { + xAxis:{template:"#"+this.chart_info_fields[0]+"#"}; + yAxis:{title: this.operator_field}; + } + return this.schedule_bar(result, xAxis, yAxis, "barchart") + } else if(this.chart == "pie") { + return this.schedule_pie(result, "piechart"); + } + + }, + + + schedule_bar: function(result, xAxis, yAxis, container) { + var chart = new dhtmlXChart({ + view: this.chart, + container: container, + value: "#"+this.operator_field+"#", + color:"#d2ed7e", + width:30, + gradient:"3d", + tooltip: "#"+this.chart_info_fields[0]+"#", + xAxis: xAxis, + yAxis: yAxis, + legend: { + align:"right", + valign:"top", + marker:{ + type:"round", + width:12 + }, + template:"#"+this.chart_info_fields[0]+"#" + } + }); + if(this.group_field) { +// var map_fld = this.chart_info_fields[0]; +// chart.group({ +// by: "#"+this.group_field+"#", +// map:{ +// map_fld :["#"+this.operator_field+"#", "sum"] +// } +// }); + } + chart.parse(result, "json"); + }, + + schedule_pie: function(result, container) { + var chart = new dhtmlXChart({ + view:"pie", + container:container, + value:"#"+this.operator_field+"#", + color:"#d2ed7e", + label:"#"+this.chart_info_fields[0]+"#", + pieInnerText:"#"+this.operator_field+"#", + gradient:"3d", + legend: { + width: 100, + align:"right", + valign:"top", + marker:{ + type:"round", + width:12 + }, + template:"#"+this.chart_info_fields[0]+"#" + } + }); + chart.parse(result,"json"); + }, + + create_graph: function(res) { + //if (this.graph_type == "bar"){ + var barChart = new dhtmlXChart({ + view:"bar", + container:"barchart", + value:"#"+this.fields['total']+"#", + color:"#9abe00", + width:40, + tooltip: "#"+this.fields['id']+"#", + xAxis:{ + template:"#"+this.fields['id']+"#" + }, + yAxis:{ + title: "Total" + } + }); + barChart.parse(res, "json"); + //} + var pieChart = new dhtmlXChart({ + view: "pie", + container: "piechart", + value: "#"+this.fields['total']+"#", + label: "#"+this.fields['id']+"#", + pieInnerText: "#"+this.fields['total']+"#", + gradient: true, + radius: 90, + x: 280, + y: 150 + }); + pieChart.parse(res, "json"); + + /*static data for stackedbar chart*/ + var data = [{ + total: "2.0", + total1: "0.0", + stage: "Lost" + }, { + total: "1.0", + total1: "2.0", + stage: "Negotiation" + }, { + total: "4.0", + total1: "2.0", + stage: "New" + }, { + total: "3.0", + total1: "0.0", + stage: "Proposition" + }, { + total: "1.0", + total1: "1.0", + stage: "Qualification" + }, { + total: "1.0", + total1: "0.0", + stage: "Won" + }]; + + var stackedChart = new dhtmlXChart({ + view: "stackedBar", + container: "stackedchart", + value: "#total#", + label: "#total#", + width: 60, + tooltip: { + template: "#total#" + }, + xAxis: { + template: "#stage#" + }, + yAxis: { + title: "User" + }, + gradient: "3d", + color: "#66cc33", + legend: { + values: [{ + text: "Administrator", + color: "#66cc33" + }, { + text: "Demo User", + color: "#ff9933" + }], + valign: "top", + align: "right", + width: 120, + layout: "y", + marker: { + width: 15, + type: "round" + } + } + }); + stackedChart.addSeries({ + value: "#total1#", + color: "#ff9933", + label: "#total1#", + tooltip: { + template: "#total1#" + } + }); + stackedChart.parse(data, "json"); + }, + + +}); + +// here you may tweak globals object, if any, and play with on_* or do_* callbacks on them + +}; + +// vim:et fdc=0 fdl=0: -- cgit v1.2.3 From 7b37f593173193452347cb12e4c3c241ba3b1c55 Mon Sep 17 00:00:00 2001 From: "vda (OpenERP)" Date: Mon, 18 Apr 2011 11:22:28 +0530 Subject: [IMP] Improved bar chart.decompressed dhtmlxchar js because we using dhtmlx library for graph,calendar and grant and dhtmlx object conflicts.so changed dhtmlx to dhtmlxchart. bzr revid: vda@tinyerp.com-20110418055228-kmyskjruyohckpsk --- addons/base_graph/static/src/js/graph.js | 205 ++++++++++--------------------- 1 file changed, 62 insertions(+), 143 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index b7e82c58279..86ce064acbc 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -66,70 +66,77 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ this.$element.html(QWeb.render("GraphView", {"fields_view": this.fields_view, "chart": this.chart})); - console.log('fields view >>>>>>',this.fields_view) - for(res in result) { for(fld in result[res]) { - if(typeof result[res][fld] == 'object') { - result[res][fld] = result[res][fld][result[res][fld].length - 1] + if (fld != 'state') { + if (typeof result[res][fld] == 'object') { + result[res][fld] = result[res][fld][result[res][fld].length - 1]; + } + } } } if(this.chart == 'bar') { - var xAxis = {}; - var yAxis = {}; - - if (this.orientation && this.orientation == 'horizontal') { - this.chart = "barH"; - xAxis:{template:"#"+this.operator_field+"#"}; - yAxis:{title: this.chart_info_fields[0]}; - } else { - xAxis:{template:"#"+this.chart_info_fields[0]+"#"}; - yAxis:{title: this.operator_field}; - } - return this.schedule_bar(result, xAxis, yAxis, "barchart") + return this.schedule_bar(result, "barchart") } else if(this.chart == "pie") { return this.schedule_pie(result, "piechart"); } }, - - schedule_bar: function(result, xAxis, yAxis, container) { - var chart = new dhtmlXChart({ - view: this.chart, - container: container, - value: "#"+this.operator_field+"#", - color:"#d2ed7e", - width:30, - gradient:"3d", - tooltip: "#"+this.chart_info_fields[0]+"#", - xAxis: xAxis, - yAxis: yAxis, - legend: { + schedule_bar: function(result, container) { + var self = this; + this.chart = this.orientation == 'horizontal'? 'barH' : this.chart || 'bar'; + + var bar_chart = new dhtmlxchartChart({ + view: this.chart, + container: container, + gradient: "3d", + border: false, + value: "#"+this.operator_field+"#", + label: self.orientation == 'horizontal' ? '#'+this.operator_field+'#' : "#"+this.chart_info_fields[0]+'#', + width: 30, + tooltip: self.orientation == 'horizontal' ? "#"+this.chart_info_fields[0]+'#': "#"+this.operator_field+"#", + origin:0, + legend: { align:"right", valign:"top", marker:{ type:"round", width:12 }, - template:"#"+this.chart_info_fields[0]+"#" + template: self.fields[this.operator_field]['string'] } }); - if(this.group_field) { -// var map_fld = this.chart_info_fields[0]; -// chart.group({ -// by: "#"+this.group_field+"#", -// map:{ -// map_fld :["#"+this.operator_field+"#", "sum"] -// } -// }); + + if(this.chart == 'barH') { + bar_chart.define("xAxis",{ + title: this.fields[this.operator_field]['string'], + lines: true + }); + + bar_chart.define("yAxis",{ + template: "#"+this.chart_info_fields[0]+'#', + title: this.fields[this.chart_info_fields[0]]['string'], + lines: true + }); + } else { + bar_chart.define("xAxis",{ + template:"#"+this.chart_info_fields[0]+"#", + title: this.fields[this.chart_info_fields[0]]['string'], + lines: true + }); + + bar_chart.define("yAxis",{ + title: this.fields[this.operator_field]['string'], + lines: true, + }); } - chart.parse(result, "json"); + bar_chart.parse(result,"json"); }, schedule_pie: function(result, container) { - var chart = new dhtmlXChart({ + var chart = new dhtmlxchartChart({ view:"pie", container:container, value:"#"+this.operator_field+"#", @@ -151,109 +158,21 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ chart.parse(result,"json"); }, - create_graph: function(res) { - //if (this.graph_type == "bar"){ - var barChart = new dhtmlXChart({ - view:"bar", - container:"barchart", - value:"#"+this.fields['total']+"#", - color:"#9abe00", - width:40, - tooltip: "#"+this.fields['id']+"#", - xAxis:{ - template:"#"+this.fields['id']+"#" - }, - yAxis:{ - title: "Total" - } - }); - barChart.parse(res, "json"); - //} - var pieChart = new dhtmlXChart({ - view: "pie", - container: "piechart", - value: "#"+this.fields['total']+"#", - label: "#"+this.fields['id']+"#", - pieInnerText: "#"+this.fields['total']+"#", - gradient: true, - radius: 90, - x: 280, - y: 150 - }); - pieChart.parse(res, "json"); - - /*static data for stackedbar chart*/ - var data = [{ - total: "2.0", - total1: "0.0", - stage: "Lost" - }, { - total: "1.0", - total1: "2.0", - stage: "Negotiation" - }, { - total: "4.0", - total1: "2.0", - stage: "New" - }, { - total: "3.0", - total1: "0.0", - stage: "Proposition" - }, { - total: "1.0", - total1: "1.0", - stage: "Qualification" - }, { - total: "1.0", - total1: "0.0", - stage: "Won" - }]; - - var stackedChart = new dhtmlXChart({ - view: "stackedBar", - container: "stackedchart", - value: "#total#", - label: "#total#", - width: 60, - tooltip: { - template: "#total#" - }, - xAxis: { - template: "#stage#" - }, - yAxis: { - title: "User" - }, - gradient: "3d", - color: "#66cc33", - legend: { - values: [{ - text: "Administrator", - color: "#66cc33" - }, { - text: "Demo User", - color: "#ff9933" - }], - valign: "top", - align: "right", - width: 120, - layout: "y", - marker: { - width: 15, - type: "round" - } - } - }); - stackedChart.addSeries({ - value: "#total1#", - color: "#ff9933", - label: "#total1#", - tooltip: { - template: "#total1#" - } - }); - stackedChart.parse(data, "json"); - }, + do_search: function(domains, contexts, groupbys) { + var self = this; + this.rpc('/base/session/eval_domain_and_context', { + domains: domains, + contexts: contexts, + group_by_seq: groupbys + }, function (results) { + // TODO: handle non-empty results.group_by with read_group + self.dataset.context = self.context = results.context; + self.dataset.domain = self.domain = results.domain; + self.dataset.read_slice(self.fields, 0, self.limit,function(result){ + self.schedule_chart(result) + }); + }); + }, }); -- cgit v1.2.3 From 6b56e10d11b518e4b036e93ddd89ede2e2325c42 Mon Sep 17 00:00:00 2001 From: "Kunal Chavda (OpenERP)" Date: Thu, 21 Apr 2011 14:35:52 +0530 Subject: [IMP]Improved code for search and group record. bzr revid: kch@tinyerp.com-20110421090552-ynzfrg2nvduseov3 --- addons/base_graph/static/src/js/graph.js | 76 ++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 29 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index 86ce064acbc..56bf784a02f 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -37,22 +37,23 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ this.group_field = ''; this.orientation = this.fields_view.arch.attrs.orientation || ''; for(fld in this.fields_view.arch.children) { - if (this.fields_view.arch.children[fld].attrs.operator) { + if (this.fields_view.arch.children[fld].attrs.operator) { this.operator_field = this.fields_view.arch.children[fld].attrs.name; } else if (this.fields_view.arch.children[fld].attrs.group) { - this.group_field = this.fields_view.arch.children[fld].attrs.name + this.group_field = this.fields_view.arch.children[fld].attrs.name; } else { - this.chart_info_fields.push(this.fields_view.arch.children[fld].attrs.name) + this.chart_info_fields.push(this.fields_view.arch.children[fld].attrs.name); } } - + this.load_chart(); }, - + load_chart: function() { var self = this; + this.dataset.read_ids( this.dataset.ids, this.fields, @@ -61,80 +62,96 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ } ) }, - + schedule_chart: function(result) { - this.$element.html(QWeb.render("GraphView", {"fields_view": this.fields_view, "chart": this.chart})); - + for(res in result) { for(fld in result[res]) { if (fld != 'state') { if (typeof result[res][fld] == 'object') { result[res][fld] = result[res][fld][result[res][fld].length - 1]; } - + } } } + if(this.chart == 'bar') { - return this.schedule_bar(result, "barchart") + return this.schedule_bar(result, "barchart") } else if(this.chart == "pie") { return this.schedule_pie(result, "piechart"); } - + }, - + schedule_bar: function(result, container) { var self = this; - this.chart = this.orientation == 'horizontal'? 'barH' : this.chart || 'bar'; - + var view_chart = this.orientation == 'horizontal'? 'barH' : this.chart || 'bar'; + var bar_chart = new dhtmlxchartChart({ - view: this.chart, + view: view_chart, container: container, gradient: "3d", border: false, - value: "#"+this.operator_field+"#", - label: self.orientation == 'horizontal' ? '#'+this.operator_field+'#' : "#"+this.chart_info_fields[0]+'#', width: 30, - tooltip: self.orientation == 'horizontal' ? "#"+this.chart_info_fields[0]+'#': "#"+this.operator_field+"#", origin:0, - legend: { + legend: { align:"right", valign:"top", marker:{ type:"round", width:12 }, - template: self.fields[this.operator_field]['string'] + template: self.fields[self.operator_field]['string'] + } }); - - if(this.chart == 'barH') { + + if(self.group_field) { + bar_chart.define("group",{ + by:"#"+self.chart_info_fields[0]+"#", + map:{ + map_fld:["#"+self.operator_field+"#", "sum"] + } + }); + bar_chart.define("value","#map_fld#"); + bar_chart.define("label","#map_fld#"); + } + else{ + bar_chart.define("value","#"+self.operator_field+"#"); + bar_chart.define("label","#"+self.chart_info_fields[0]+"#"); + } + + if(view_chart == 'barH') { bar_chart.define("xAxis",{ title: this.fields[this.operator_field]['string'], lines: true }); - + bar_chart.define("yAxis",{ - template: "#"+this.chart_info_fields[0]+'#', + template: "#id#", title: this.fields[this.chart_info_fields[0]]['string'], lines: true }); + } else { bar_chart.define("xAxis",{ template:"#"+this.chart_info_fields[0]+"#", title: this.fields[this.chart_info_fields[0]]['string'], lines: true }); - + bar_chart.define("yAxis",{ title: this.fields[this.operator_field]['string'], lines: true, }); + } - bar_chart.parse(result,"json"); + bar_chart.parse(result,"json"); + }, - + schedule_pie: function(result, container) { var chart = new dhtmlxchartChart({ view:"pie", @@ -157,9 +174,10 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ }); chart.parse(result,"json"); }, - + do_search: function(domains, contexts, groupbys) { var self = this; + this.rpc('/base/session/eval_domain_and_context', { domains: domains, contexts: contexts, @@ -172,8 +190,8 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ self.schedule_chart(result) }); }); - }, + }, }); -- cgit v1.2.3 From e5dc3d5d54ee2c86a0d893ece336e0a5f2320afb Mon Sep 17 00:00:00 2001 From: "Kunal Chavda (OpenERP)" Date: Fri, 6 May 2011 18:11:08 +0530 Subject: [IMP]show stackbarchart when there is group and improved code for legend and color. bzr revid: kch@tinyerp.com-20110506124108-ov131ru1os1acel6 --- addons/base_graph/static/src/js/graph.js | 269 ++++++++++++++++++++----------- 1 file changed, 178 insertions(+), 91 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index 56bf784a02f..22b777fc5bc 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -28,151 +28,232 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ on_loaded: function(data) { var self = this; this.fields_view = data.fields_view; - this.name = this.fields_view.name || this.fields_view.arch.attrs.string; - this.view_id = this.fields_view.view_id; + this.name = this.fields_view.name || this.fields_view.arch.attrs.string; + this.view_id = this.fields_view.view_id; this.chart = this.fields_view.arch.attrs.type || 'pie'; this.fields = this.fields_view.fields; this.chart_info_fields = []; this.operator_field = ''; this.group_field = ''; this.orientation = this.fields_view.arch.attrs.orientation || ''; + for(fld in this.fields_view.arch.children) { - if (this.fields_view.arch.children[fld].attrs.operator) { + if (this.fields_view.arch.children[fld].attrs.operator) { this.operator_field = this.fields_view.arch.children[fld].attrs.name; } else if (this.fields_view.arch.children[fld].attrs.group) { - this.group_field = this.fields_view.arch.children[fld].attrs.name; + this.group_field = this.fields_view.arch.children[fld].attrs.name; } else { this.chart_info_fields.push(this.fields_view.arch.children[fld].attrs.name); } } - + if(this.operator_field == ''){ + this.operator_field = this.chart_info_fields[1]; + } + this.chart_info = this.chart_info_fields[0]; this.load_chart(); - }, + }, - load_chart: function() { + load_chart: function(result) { var self = this; - - this.dataset.read_ids( - this.dataset.ids, - this.fields, - function(result) { - self.schedule_chart(result) - } - ) + if(result){ + self.schedule_chart(result); + }else{ + this.dataset.read_ids( + this.dataset.ids, + {}, + function(result) { + self.schedule_chart(result); + } + ) + } }, schedule_chart: function(result) { this.$element.html(QWeb.render("GraphView", {"fields_view": this.fields_view, "chart": this.chart})); - for(res in result) { - for(fld in result[res]) { - if (fld != 'state') { + if (result.length){ + for(res in result) { + for(fld in result[res]) { if (typeof result[res][fld] == 'object') { result[res][fld] = result[res][fld][result[res][fld].length - 1]; } + } + } + if(this.chart == 'bar') { + return this.schedule_bar(result); + } else if(this.chart == "pie") { + return this.schedule_pie(result); + } + } + }, + + schedule_bar: function(result) { + var self = this; + var view_chart = ''; + var xystr = {}; + var xyname = {}; + var res = []; + var group_list = []; + var opration_fld = {}; + + for (i in result){ + var gen_key = result[i][self.chart_info_fields]+"_"+result[i][self.group_field] + if (opration_fld[gen_key] == undefined){ + var map_val = {} + map_val[self.operator_field] = result[i][self.operator_field]; + map_val[self.chart_info_fields] = result[i][self.chart_info_fields]; + if (this.group_field){ + map_val[self.group_field] = result[i][self.group_field].replace(" ", "_"); + }else{ + map_val[self.group_field] = result[i][self.group_field]; } + opration_fld[gen_key] = map_val; + }else{ + map_val = opration_fld[gen_key]; + map_val[self.operator_field] = map_val[self.operator_field] + result[i][self.operator_field]; + opration_fld[gen_key] = map_val; } } - if(this.chart == 'bar') { - return this.schedule_bar(result, "barchart") - } else if(this.chart == "pie") { - return this.schedule_pie(result, "piechart"); + result = [] + for (i in opration_fld){ + result.push(opration_fld[i]); } - }, + var COLOR_PALETTE = ['#ff8e00', '#ff0000', '#b0008c', '#9000ff', '#0078ff', '#00ff00', '#e6ff00', '#ffff00', + '#905000', '#9b0000', '#840067', '#9abe00', '#ffc900', '#510090', '#0000c9', '#009b00', + '#75507b', '#3465a4', '#73d216', '#c17d11', '#edd400', '#fcaf3e', '#ef2929', '#ff00c9', + '#ad7fa8', '#729fcf', '#8ae234', '#e9b96e', '#fce94f', '#f57900', '#cc0000', '#d400a8']; - schedule_bar: function(result, container) { - var self = this; - var view_chart = this.orientation == 'horizontal'? 'barH' : this.chart || 'bar'; + if(this.group_field){ + view_chart = this.orientation == 'horizontal'? 'stackedBarH' : 'stackedBar'; + }else{ + view_chart = this.orientation == 'horizontal'? 'barH' : 'bar'; + } - var bar_chart = new dhtmlxchartChart({ - view: view_chart, - container: container, - gradient: "3d", - border: false, - width: 30, - origin:0, - legend: { - align:"right", - valign:"top", - marker:{ - type:"round", - width:12 - }, - template: self.fields[self.operator_field]['string'] + for (i in result){ + if (this.group_field){ + var newkey =result[i][this.group_field].replace(" ", "_"); + }else{ + var newkey =result[i][this.group_field]; + } + if (jQuery.inArray(newkey, group_list) == -1){ + group_list.push(newkey); + } + } + for (i in result){ + var xystring = result[i][this.chart_info_fields]; + if (this.group_field){ + var newkey =result[i][this.group_field].replace(" ", "_"); + }else{ + var newkey =result[i][this.group_field]; } - }); + if (xystr[xystring] == undefined){ + xyname = {}; + xyname['name'] = xystring; + for (j in group_list){ + xyname[group_list[j]] = 0.0001; + } + xyname[newkey] = result[i][this.operator_field]; + xystr[xystring] = xyname; + } + else{ + xyname = {}; + xyname = xystr[xystring]; + xyname[newkey] = result[i][this.operator_field]; + xystr[xystring] = xyname; + } + } - if(self.group_field) { - bar_chart.define("group",{ - by:"#"+self.chart_info_fields[0]+"#", - map:{ - map_fld:["#"+self.operator_field+"#", "sum"] - } - }); - bar_chart.define("value","#map_fld#"); - bar_chart.define("label","#map_fld#"); + for (i in xystr){ + res.push(xystr[i]); } - else{ - bar_chart.define("value","#"+self.operator_field+"#"); - bar_chart.define("label","#"+self.chart_info_fields[0]+"#"); + + //for legend color + var grp_color = []; + for (i in group_list){ + var legend = {}; + if (group_list[i] == undefined){ + legend['text'] = self.fields[self.operator_field]['string'] + }else{ + legend['text'] = group_list[i]; + } + legend['color'] = COLOR_PALETTE[i]; + grp_color.push(legend); } - if(view_chart == 'barH') { - bar_chart.define("xAxis",{ - title: this.fields[this.operator_field]['string'], - lines: true - }); + var temp_ax = {}; + var oth_ax = {}; - bar_chart.define("yAxis",{ - template: "#id#", - title: this.fields[this.chart_info_fields[0]]['string'], - lines: true - }); + temp_ax['template'] = "#name#"; + temp_ax['lines'] = true; - } else { - bar_chart.define("xAxis",{ - template:"#"+this.chart_info_fields[0]+"#", - title: this.fields[this.chart_info_fields[0]]['string'], - lines: true - }); + oth_ax['lines'] = true; - bar_chart.define("yAxis",{ - title: this.fields[this.operator_field]['string'], - lines: true, - }); + if (this.orientation == 'horizontal'){ + var x_ax = oth_ax; + var y_ax = temp_ax; + }else{ + var x_ax = temp_ax; + var y_ax = oth_ax; + } + var bar_chart = new dhtmlxchartChart({ + view: view_chart, + container: "barchart", + value:"#"+group_list[0]+"#", + gradient: "3d", + border: false, + width: 30, + color:grp_color[0]['color'], + origin:0, + xAxis: x_ax, + yAxis: y_ax, + legend: { + values: grp_color, + align:"right", + valign:"top", + marker:{ + type:"round", + width:12 + }, + } + }); + for (var i = 1; i#"+this.operator_field+"#", - gradient:"3d", + view:"pie", + container:"piechart", + value:"#"+this.operator_field+"#", + color:"#d2ed7e", + label:"#"+this.chart_info_fields[0]+"#", + pieInnerText:"#"+this.operator_field+"#", + gradient:"3d", legend: { width: 100, align:"right", - valign:"top", - marker:{ - type:"round", - width:12 - }, + valign:"top", + marker:{ + type:"round", + width:12 + }, template:"#"+this.chart_info_fields[0]+"#" } - }); - chart.parse(result,"json"); + }); + chart.parse(result,"json"); }, do_search: function(domains, contexts, groupbys) { @@ -184,10 +265,16 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ group_by_seq: groupbys }, function (results) { // TODO: handle non-empty results.group_by with read_group + if(contexts[0]['group_by']){ + self.chart_info_fields = contexts[0]['group_by']; + } + else{ + self.chart_info_fields = self.chart_info; + } self.dataset.context = self.context = results.context; self.dataset.domain = self.domain = results.domain; self.dataset.read_slice(self.fields, 0, self.limit,function(result){ - self.schedule_chart(result) + self.load_chart(result); }); }); -- cgit v1.2.3 From 963fd40ab25ca464f8fde48566dc87571113fc57 Mon Sep 17 00:00:00 2001 From: "Kunal Chavda (OpenERP)" Date: Tue, 17 May 2011 12:07:18 +0530 Subject: [IMP]code for piechart with default color and improved code for groupby. bzr revid: kch@tinyerp.com-20110517063718-bets5l1knkpwqhr5 --- addons/base_graph/static/src/js/graph.js | 127 ++++++++++++++++--------------- 1 file changed, 66 insertions(+), 61 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index 22b777fc5bc..1c697942df2 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -72,6 +72,8 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ schedule_chart: function(result) { this.$element.html(QWeb.render("GraphView", {"fields_view": this.fields_view, "chart": this.chart})); + this.opration_fld = {}; + this.group_list = []; if (result.length){ for(res in result) { @@ -82,9 +84,34 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ } } + for (i in result){ + var gen_key = result[i][this.chart_info_fields]+"_"+result[i][this.group_field] + if (this.opration_fld[gen_key] == undefined){ + var map_val = {} + map_val[this.operator_field] = result[i][this.operator_field]; + map_val[this.chart_info_fields] = result[i][this.chart_info_fields]; + if (this.group_field){ + map_val[this.group_field] = result[i][this.group_field].replace(" ", "_"); + }else{ + map_val[this.group_field] = result[i][this.group_field]; + } + this.opration_fld[gen_key] = map_val; + }else{ + map_val = this.opration_fld[gen_key]; + map_val[this.operator_field] = map_val[this.operator_field] + result[i][this.operator_field]; + this.opration_fld[gen_key] = map_val; + } + } + + result = [] + for (i in this.opration_fld){ + result.push(this.opration_fld[i]); + } + if(this.chart == 'bar') { return this.schedule_bar(result); } else if(this.chart == "pie") { + console.log("test"); return this.schedule_pie(result); } } @@ -96,75 +123,50 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ var xystr = {}; var xyname = {}; var res = []; - var group_list = []; - var opration_fld = {}; - - for (i in result){ - var gen_key = result[i][self.chart_info_fields]+"_"+result[i][self.group_field] - if (opration_fld[gen_key] == undefined){ - var map_val = {} - map_val[self.operator_field] = result[i][self.operator_field]; - map_val[self.chart_info_fields] = result[i][self.chart_info_fields]; - if (this.group_field){ - map_val[self.group_field] = result[i][self.group_field].replace(" ", "_"); - }else{ - map_val[self.group_field] = result[i][self.group_field]; - } - opration_fld[gen_key] = map_val; - }else{ - map_val = opration_fld[gen_key]; - map_val[self.operator_field] = map_val[self.operator_field] + result[i][self.operator_field]; - opration_fld[gen_key] = map_val; - } - } - result = [] - for (i in opration_fld){ - result.push(opration_fld[i]); - } var COLOR_PALETTE = ['#ff8e00', '#ff0000', '#b0008c', '#9000ff', '#0078ff', '#00ff00', '#e6ff00', '#ffff00', '#905000', '#9b0000', '#840067', '#9abe00', '#ffc900', '#510090', '#0000c9', '#009b00', '#75507b', '#3465a4', '#73d216', '#c17d11', '#edd400', '#fcaf3e', '#ef2929', '#ff00c9', '#ad7fa8', '#729fcf', '#8ae234', '#e9b96e', '#fce94f', '#f57900', '#cc0000', '#d400a8']; - if(this.group_field){ - view_chart = this.orientation == 'horizontal'? 'stackedBarH' : 'stackedBar'; + if(self.group_field){ + view_chart = self.orientation == 'horizontal'? 'stackedBarH' : 'stackedBar'; }else{ - view_chart = this.orientation == 'horizontal'? 'barH' : 'bar'; + view_chart = self.orientation == 'horizontal'? 'barH' : 'bar'; } for (i in result){ - if (this.group_field){ - var newkey =result[i][this.group_field].replace(" ", "_"); + if (self.group_field){ + var newkey =result[i][self.group_field].replace(" ", "_"); }else{ - var newkey =result[i][this.group_field]; + var newkey =result[i][self.group_field]; } - if (jQuery.inArray(newkey, group_list) == -1){ - group_list.push(newkey); + if (jQuery.inArray(newkey, self.group_list) == -1){ + self.group_list.push(newkey); } } for (i in result){ - var xystring = result[i][this.chart_info_fields]; - if (this.group_field){ - var newkey =result[i][this.group_field].replace(" ", "_"); + var xystring = result[i][self.chart_info_fields]; + if (self.group_field){ + var newkey =result[i][self.group_field].replace(" ", "_"); }else{ - var newkey =result[i][this.group_field]; + var newkey =result[i][self.group_field]; } if (xystr[xystring] == undefined){ xyname = {}; xyname['name'] = xystring; - for (j in group_list){ - xyname[group_list[j]] = 0.0001; + for (j in self.group_list){ + xyname[self.group_list[j]] = 0.0001; } - xyname[newkey] = result[i][this.operator_field]; + xyname[newkey] = result[i][self.operator_field]; xystr[xystring] = xyname; } else{ xyname = {}; xyname = xystr[xystring]; - xyname[newkey] = result[i][this.operator_field]; + xyname[newkey] = result[i][self.operator_field]; xystr[xystring] = xyname; } } @@ -175,12 +177,12 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ //for legend color var grp_color = []; - for (i in group_list){ + for (i in self.group_list){ var legend = {}; - if (group_list[i] == undefined){ + if (self.group_list[i] == undefined){ legend['text'] = self.fields[self.operator_field]['string'] }else{ - legend['text'] = group_list[i]; + legend['text'] = self.group_list[i]; } legend['color'] = COLOR_PALETTE[i]; grp_color.push(legend); @@ -190,11 +192,9 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ var oth_ax = {}; temp_ax['template'] = "#name#"; - temp_ax['lines'] = true; - oth_ax['lines'] = true; - if (this.orientation == 'horizontal'){ + if (self.orientation == 'horizontal'){ var x_ax = oth_ax; var y_ax = temp_ax; }else{ @@ -205,10 +205,10 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ var bar_chart = new dhtmlxchartChart({ view: view_chart, container: "barchart", - value:"#"+group_list[0]+"#", + value:"#"+self.group_list[0]+"#", gradient: "3d", border: false, - width: 30, + width: 50, color:grp_color[0]['color'], origin:0, xAxis: x_ax, @@ -223,7 +223,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ }, } }); - for (var i = 1; i#"+this.operator_field+"#", + value:"#"+self.operator_field+"#", + pieInnerText:function(obj) { + var sum = chart.sum("#"+self.operator_field+"#"); + var val = obj[self.operator_field] / sum * 100 ; + return Math.round(val * 10)/10 + "%"; + }, + label:"#"+self.chart_info_fields[0]+"#", gradient:"3d", legend: { - width: 100, + width: 300, align:"right", valign:"top", marker:{ type:"round", width:12 }, - template:"#"+this.chart_info_fields[0]+"#" + template:"#"+self.chart_info_fields[0]+"#" } }); chart.parse(result,"json"); @@ -265,15 +270,15 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ group_by_seq: groupbys }, function (results) { // TODO: handle non-empty results.group_by with read_group - if(contexts[0]['group_by']){ - self.chart_info_fields = contexts[0]['group_by']; + if(contexts[0]['group_by'] && contexts[0]['group_by'] != ''){ + self.chart_info_fields[0] = contexts[0]['group_by']; } else{ - self.chart_info_fields = self.chart_info; + self.chart_info_fields[0] = self.chart_info; } self.dataset.context = self.context = results.context; self.dataset.domain = self.domain = results.domain; - self.dataset.read_slice(self.fields, 0, self.limit,function(result){ + self.dataset.read_slice({}, 0, self.limit,function(result){ self.load_chart(result); }); }); -- cgit v1.2.3 From a3131539a6399d8694bc7d8055e0b27f9ff9c934 Mon Sep 17 00:00:00 2001 From: "Kunal Chavda (OpenERP)" Date: Thu, 19 May 2011 18:34:13 +0530 Subject: [IMP]Improved code for axis label. bzr revid: kch@tinyerp.com-20110519130413-5i4uz4fjd4o6tvlm --- addons/base_graph/static/src/js/graph.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index 869b26ac291..8f457c2a8d1 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -27,6 +27,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ }, on_loaded: function(data) { var self = this; + this.all_fields = data.all_fields; this.fields_view = data.fields_view; this.name = this.fields_view.name || this.fields_view.arch.attrs.string; this.view_id = this.fields_view.view_id; @@ -52,12 +53,16 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ this.operator_field = this.chart_info_fields[1]; } this.chart_info = this.chart_info_fields[0]; + this.x_title = this.fields[this.chart_info_fields[0]]['string']; + this.y_title = this.fields[this.operator_field]['string']; this.load_chart(); }, load_chart: function(result) { var self = this; if(result){ + this.x_title = this.all_fields[this.chart_info_fields[0]]['string']; + this.y_title = this.all_fields[this.operator_field]['string']; self.schedule_chart(result); }else{ this.dataset.read_ids( @@ -191,7 +196,9 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ var oth_ax = {}; temp_ax['template'] = "#name#"; + temp_ax['title'] = ""+self.x_title+"" ; oth_ax['lines'] = true; + oth_ax['title'] = ""+self.y_title+""; if (self.orientation == 'horizontal'){ var x_ax = oth_ax; @@ -212,10 +219,14 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ origin:0, xAxis: x_ax, yAxis: y_ax, + padding: { + left: 75 + }, legend: { values: grp_color, - align:"right", + align:"left", valign:"top", + layout: "x", marker:{ type:"round", width:12 @@ -246,10 +257,12 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ }, gradient:"3d", height: 20, + radius: 200, legend: { width: 300, - align:"right", + align:"left", valign:"top", + layout: "x", marker:{ type:"round", width:12 -- cgit v1.2.3 From 47b14bddc5e0443de68e66a7191f8824e8e4187d Mon Sep 17 00:00:00 2001 From: "Kunal Chavda (OpenERP)" Date: Wed, 25 May 2011 11:39:00 +0530 Subject: [IMP]Improved code for two operator fields are in view. bzr revid: kch@tinyerp.com-20110525060900-n85m7ezzjhww5bw3 --- addons/base_graph/static/src/js/graph.js | 85 ++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 32 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index 8f457c2a8d1..de7083e39ce 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -7,8 +7,7 @@ QWeb.add_template('/base_graph/static/src/xml/base_graph.xml'); openerp.base.views.add('graph', 'openerp.base_graph.GraphView'); openerp.base_graph.GraphView = openerp.base.Controller.extend({ - init: function(view_manager, session, element_id, dataset, view_id) { - + init: function(view_manager, session, element_id, dataset, view_id) { this._super(session, element_id); this.view_manager = view_manager; this.dataset = dataset; @@ -35,12 +34,14 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ this.fields = this.fields_view.fields; this.chart_info_fields = []; this.operator_field = ''; + this.operator_field_one = ''; + this.operator = []; this.group_field = ''; this.orientation = this.fields_view.arch.attrs.orientation || ''; for(fld in this.fields_view.arch.children) { if (this.fields_view.arch.children[fld].attrs.operator) { - this.operator_field = this.fields_view.arch.children[fld].attrs.name; + this.operator.push(this.fields_view.arch.children[fld].attrs.name); } else if (this.fields_view.arch.children[fld].attrs.group) { this.group_field = this.fields_view.arch.children[fld].attrs.name; @@ -49,36 +50,39 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ this.chart_info_fields.push(this.fields_view.arch.children[fld].attrs.name); } } - if(this.operator_field == ''){ + this.operator_field = this.operator[0]; + if(this.operator.length > 1){ + this.operator_field_one = this.operator[1]; + } + if(this.operator == ''){ this.operator_field = this.chart_info_fields[1]; } this.chart_info = this.chart_info_fields[0]; this.x_title = this.fields[this.chart_info_fields[0]]['string']; this.y_title = this.fields[this.operator_field]['string']; - this.load_chart(); + self.load_chart(); }, - load_chart: function(result) { + load_chart: function(data) { var self = this; - if(result){ + if(data){ this.x_title = this.all_fields[this.chart_info_fields[0]]['string']; this.y_title = this.all_fields[this.operator_field]['string']; - self.schedule_chart(result); + self.schedule_chart(data); }else{ this.dataset.read_ids( this.dataset.ids, {}, - function(result) { - self.schedule_chart(result); + function(res) { + self.schedule_chart(res); } - ) + ); } }, schedule_chart: function(result) { this.$element.html(QWeb.render("GraphView", {"fields_view": this.fields_view, "chart": this.chart})); this.opration_fld = {}; - this.group_list = []; if (result.length){ for(res in result) { @@ -88,26 +92,28 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ } } } - for (i in result){ var gen_key = result[i][this.chart_info_fields]+"_"+result[i][this.group_field] if (this.opration_fld[gen_key] == undefined){ var map_val = {} map_val[this.operator_field] = result[i][this.operator_field]; + if (this.operator.length > 1){ + map_val[this.operator_field_one] = result[i][this.operator_field_one]; + } map_val[this.chart_info_fields] = result[i][this.chart_info_fields]; if (this.group_field){ - map_val[this.group_field] = result[i][this.group_field].replace(" ", "_"); - }else{ - map_val[this.group_field] = result[i][this.group_field]; + map_val[this.group_field] = result[i][this.group_field].split(' ').join('_'); } this.opration_fld[gen_key] = map_val; }else{ map_val = this.opration_fld[gen_key]; map_val[this.operator_field] = map_val[this.operator_field] + result[i][this.operator_field]; + if (this.operator.length > 1){ + map_val[this.operator_field_one] = map_val[this.operator_field_one] + result[i][this.operator_field_one]; + } this.opration_fld[gen_key] = map_val; } } - result = [] for (i in this.opration_fld){ result.push(this.opration_fld[i]); @@ -127,9 +133,10 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ var xystr = {}; var xyname = {}; var res = []; + this.group_list = []; + var newkey = ''; - - var COLOR_PALETTE = ['#cc99ff', '#75507b', '#ccccff', '#b0008c', '#ff0000', '#ff8e00', '#9000ff', '#0078ff', '#00ff00', '#e6ff00', '#ffff00', + var COLOR_PALETTE = ['#cc99ff', '#ccccff', '#48D1CC', '#CFD784', '#8B7B8B', '#75507b', '#b0008c', '#ff0000', '#ff8e00', '#9000ff', '#0078ff', '#00ff00', '#e6ff00', '#ffff00', '#905000', '#9b0000', '#840067', '#9abe00', '#ffc900', '#510090', '#0000c9', '#009b00', '#75507b', '#3465a4', '#73d216', '#c17d11', '#edd400', '#fcaf3e', '#ef2929', '#ff00c9', '#ad7fa8', '#729fcf', '#8ae234', '#e9b96e', '#fce94f', '#f57900', '#cc0000', '#d400a8']; @@ -142,21 +149,25 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ for (i in result){ if (self.group_field){ - var newkey =result[i][self.group_field].replace(" ", "_"); + newkey =result[i][self.group_field].split(' ').join('_'); }else{ - var newkey =result[i][self.group_field]; + newkey = "val"; } if (jQuery.inArray(newkey, self.group_list) == -1){ self.group_list.push(newkey); + if(this.operator.length > 1){ + var newkey_one = "val1"; + self.group_list.push(newkey_one); + } } } for (i in result){ var xystring = result[i][self.chart_info_fields]; if (self.group_field){ - var newkey =result[i][self.group_field].replace(" ", "_"); + newkey =result[i][self.group_field].split(' ').join('_'); }else{ - var newkey =result[i][self.group_field]; + newkey = "val"; } if (xystr[xystring] == undefined){ xyname = {}; @@ -165,12 +176,18 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ xyname[self.group_list[j]] = 0.0001; } xyname[newkey] = result[i][self.operator_field]; + if (self.operator.length > 1){ + xyname[newkey_one] = result[i][self.operator_field_one]; + } xystr[xystring] = xyname; } else{ xyname = {}; xyname = xystr[xystring]; xyname[newkey] = result[i][self.operator_field]; + if (self.operator.length > 1){ + xyname[newkey_one] = result[i][self.operator_field_one]; + } xystr[xystring] = xyname; } } @@ -183,8 +200,10 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ var grp_color = []; for (i in self.group_list){ var legend = {}; - if (self.group_list[i] == undefined){ + if (self.group_list[i] == "val"){ legend['text'] = self.fields[self.operator_field]['string'] + }else if(self.group_list[i] == "val1"){ + legend['text'] = self.fields[self.operator_field_one]['string'] }else{ legend['text'] = self.group_list[i]; } @@ -214,7 +233,8 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ value:"#"+self.group_list[0]+"#", gradient: "3d", border: false, - width: 50, + width: 1024, + radius: 0, color:grp_color[0]['color'], origin:0, xAxis: x_ax, @@ -235,12 +255,11 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ }); for (var i = 1; i Date: Wed, 25 May 2011 17:09:49 +0530 Subject: [IMP]Improved code for groupby when domain is there. bzr revid: kch@tinyerp.com-20110525113949-3spob7ruoskuws33 --- addons/base_graph/static/src/js/graph.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index de7083e39ce..70a94a5c595 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -304,8 +304,8 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ group_by_seq: groupbys }, function (results) { // TODO: handle non-empty results.group_by with read_group - if(contexts[0]['group_by'] && contexts[0]['group_by'] != ''){ - self.chart_info_fields[0] = contexts[0]['group_by']; + if(results.context['group_by']){ + self.chart_info_fields[0] = results.context['group_by']; } else{ self.chart_info_fields[0] = self.chart_info; -- cgit v1.2.3 From a4e00cabc025a7045300b5b10e629295377dfed7 Mon Sep 17 00:00:00 2001 From: "Kunal Chavda (OpenERP)" Date: Mon, 6 Jun 2011 11:27:54 +0530 Subject: [IMP]Implement switch view when click on pie or bar column. bzr revid: kch@tinyerp.com-20110606055754-hfb41vvvxog6q69j --- addons/base_graph/static/src/js/graph.js | 101 ++++++++++++++++++++++++------- 1 file changed, 79 insertions(+), 22 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index 70a94a5c595..e38c213de73 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -66,7 +66,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ load_chart: function(data) { var self = this; if(data){ - this.x_title = this.all_fields[this.chart_info_fields[0]]['string']; + this.x_title = this.all_fields[this.chart_info_fields]['string']; this.y_title = this.all_fields[this.operator_field]['string']; self.schedule_chart(data); }else{ @@ -90,10 +90,20 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ if (typeof result[res][fld] == 'object') { result[res][fld] = result[res][fld][result[res][fld].length - 1]; } + if (typeof result[res][fld] == 'string'){ + if (this.all_fields[fld]['selection']){ + for (i in this.all_fields[fld]['selection']){ + if(result[res][fld] == this.all_fields[fld]['selection'][i][0]){ + result[res][fld] = this.all_fields[fld]['selection'][i]; + } + } + } + } } } + for (i in result){ - var gen_key = result[i][this.chart_info_fields]+"_"+result[i][this.group_field] + var gen_key = result[i][this.chart_info_fields]+"_"+result[i][this.group_field]; if (this.opration_fld[gen_key] == undefined){ var map_val = {} map_val[this.operator_field] = result[i][this.operator_field]; @@ -102,7 +112,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ } map_val[this.chart_info_fields] = result[i][this.chart_info_fields]; if (this.group_field){ - map_val[this.group_field] = result[i][this.group_field].split(' ').join('_'); + map_val[this.group_field] = (typeof result[i][this.group_field] == 'object')?result[i][this.group_field][1]:result[i][this.group_field]; } this.opration_fld[gen_key] = map_val; }else{ @@ -118,7 +128,6 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ for (i in this.opration_fld){ result.push(this.opration_fld[i]); } - if(this.chart == 'bar') { return this.schedule_bar(result); } else if(this.chart == "pie") { @@ -171,7 +180,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ } if (xystr[xystring] == undefined){ xyname = {}; - xyname['name'] = xystring; + xyname[self.chart_info_fields] = xystring; for (j in self.group_list){ xyname[self.group_list[j]] = 0.0001; } @@ -211,10 +220,10 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ grp_color.push(legend); } + //for axis's value and title var temp_ax = {}; var oth_ax = {}; - - temp_ax['template'] = "#name#"; + temp_ax['template'] = self.chart_info_fields; temp_ax['title'] = ""+self.x_title+"" ; oth_ax['lines'] = true; oth_ax['title'] = ""+self.y_title+""; @@ -237,8 +246,32 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ radius: 0, color:grp_color[0]['color'], origin:0, - xAxis: x_ax, - yAxis: y_ax, + xAxis:{ + template:function(obj){ + if(x_ax['template']){ + var val = obj[x_ax['template']]; + val = (typeof val == 'object')?val[1]:(val==false?'Undefined':val); + return val; + }else{ + return obj; + } + }, + title:x_ax['title'], + lines:x_ax['lines'] + }, + yAxis:{ + template:function(obj){ + if(y_ax['template']){ + var vals = obj[y_ax['template']]; + vals = (typeof vals == 'object')?vals[1]:(vals==false?'Undefined':vals); + return vals; + }else{ + return obj; + } + }, + title:y_ax['title'], + lines: y_ax['lines'] + }, padding: { left: 75 }, @@ -260,11 +293,13 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ }); } bar_chart.parse(res,"json"); + bar_chart.attachEvent("onItemClick", function(id) { + var id = bar_chart.get(id); + self.open(id); + }); }, - schedule_pie: function(result) { var self = this; - var chart = new dhtmlxchartChart({ view:"pie3D", container:"piechart", @@ -286,16 +321,39 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ type:"round", width:12 }, - template:"#"+self.chart_info_fields[0]+"#" + template:function(obj){ + var val = obj[self.chart_info_fields]; + val = (typeof val == 'object')?val[1]:val; + return val; + } } }); chart.parse(result,"json"); - /* chart.attachEvent("onItemClick", function(id) { - var event_list = new openerp.base.ListView(self.view_manager, self.session, self.element_id, self.dataset, false, false); - event_list.start(); - });*/ + chart.attachEvent("onItemClick", function(id) { + var id = chart.get(id); + self.open(id); + }); + }, + open : function (id){ + var self = this; + var id = id[self.chart_info_fields]; + if (typeof id == 'object'){ + id = id[0]; + }else{ + id = id; + } + if(this.view_manager.action.context){ + this.view_manager.action.context = {}; + } + if(!this.view_manager.action.domain) { + this.view_manager.action.domain = [[self.chart_info_fields, '=', id],['id','in',self.dataset.ids]]; + } else { + this.view_manager.action.domain.push([self.chart_info_fields, '=', id],['id','in',self.dataset.ids]); + } + var action_manager = new openerp.base.ActionManager(this.view_manager.session, this.view_manager.element_id); + action_manager.start(); + action_manager.do_action(this.view_manager.action); }, - do_search: function(domains, contexts, groupbys) { var self = this; this.rpc('/base/session/eval_domain_and_context', { @@ -304,11 +362,10 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ group_by_seq: groupbys }, function (results) { // TODO: handle non-empty results.group_by with read_group - if(results.context['group_by']){ - self.chart_info_fields[0] = results.context['group_by']; - } - else{ - self.chart_info_fields[0] = self.chart_info; + if(results.group_by && results.group_by != ''){ + self.chart_info_fields = results.group_by[0]; + }else{ + self.chart_info_fields = self.chart_info; } self.dataset.context = self.context = results.context; self.dataset.domain = self.domain = results.domain; -- cgit v1.2.3 From 8521bf46a3c33cef2b44a213f92895a9a98e7497 Mon Sep 17 00:00:00 2001 From: "Kunal Chavda (OpenERP)" Date: Mon, 13 Jun 2011 10:58:46 +0530 Subject: [FIX]fixed code for dashboard overriding graph and x-axis label. bzr revid: kch@tinyerp.com-20110613052846-zxzetxg6dk06qzw1 --- addons/base_graph/static/src/js/graph.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index e38c213de73..0c0f9deb629 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -81,9 +81,8 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ }, schedule_chart: function(result) { - this.$element.html(QWeb.render("GraphView", {"fields_view": this.fields_view, "chart": this.chart})); + this.$element.html(QWeb.render("GraphView", {"fields_view": this.fields_view, "chart": this.chart,'view_id': this.view_id})); this.opration_fld = {}; - if (result.length){ for(res in result) { for(fld in result[res]) { @@ -128,6 +127,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ for (i in this.opration_fld){ result.push(this.opration_fld[i]); } + if(this.chart == 'bar') { return this.schedule_bar(result); } else if(this.chart == "pie") { @@ -150,18 +150,19 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ '#75507b', '#3465a4', '#73d216', '#c17d11', '#edd400', '#fcaf3e', '#ef2929', '#ff00c9', '#ad7fa8', '#729fcf', '#8ae234', '#e9b96e', '#fce94f', '#f57900', '#cc0000', '#d400a8']; - if(self.group_field){ + if(self.group_field && (this.operator.length <= 1)){ view_chart = self.orientation == 'horizontal'? 'stackedBarH' : 'stackedBar'; }else{ view_chart = self.orientation == 'horizontal'? 'barH' : 'bar'; } for (i in result){ - if (self.group_field){ + if (self.group_field && (this.operator.length <= 1)){ newkey =result[i][self.group_field].split(' ').join('_'); }else{ newkey = "val"; } + if (jQuery.inArray(newkey, self.group_list) == -1){ self.group_list.push(newkey); if(this.operator.length > 1){ @@ -173,7 +174,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ for (i in result){ var xystring = result[i][self.chart_info_fields]; - if (self.group_field){ + if (self.group_field && (self.operator.length <= 1)){ newkey =result[i][self.group_field].split(' ').join('_'); }else{ newkey = "val"; @@ -200,7 +201,6 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ xystr[xystring] = xyname; } } - for (i in xystr){ res.push(xystr[i]); } @@ -238,7 +238,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ var bar_chart = new dhtmlxchartChart({ view: view_chart, - container: "barchart", + container: self.view_id+"-barchart", value:"#"+self.group_list[0]+"#", gradient: "3d", border: false, @@ -295,14 +295,14 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ bar_chart.parse(res,"json"); bar_chart.attachEvent("onItemClick", function(id) { var id = bar_chart.get(id); - self.open(id); + self.open_list_view(id); }); }, schedule_pie: function(result) { var self = this; var chart = new dhtmlxchartChart({ view:"pie3D", - container:"piechart", + container:self.view_id+"-piechart", value:"#"+self.operator_field+"#", pieInnerText:function(obj) { var sum = chart.sum("#"+self.operator_field+"#"); @@ -331,10 +331,10 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ chart.parse(result,"json"); chart.attachEvent("onItemClick", function(id) { var id = chart.get(id); - self.open(id); + self.open_list_view(id); }); }, - open : function (id){ + open_list_view : function (id){ var self = this; var id = id[self.chart_info_fields]; if (typeof id == 'object'){ -- cgit v1.2.3 From 3bbb11353a0bf03c12bc08a6f2832b386d852b15 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 17 Jun 2011 11:07:46 +0200 Subject: [FIX] non-instance should all be declared with 'var' See doc for rationale bzr revid: xmo@openerp.com-20110617090746-z35n4jsdqvicoa9h --- addons/base_graph/static/src/js/graph.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index 0c0f9deb629..e1805f2d07a 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -84,8 +84,8 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ this.$element.html(QWeb.render("GraphView", {"fields_view": this.fields_view, "chart": this.chart,'view_id': this.view_id})); this.opration_fld = {}; if (result.length){ - for(res in result) { - for(fld in result[res]) { + for(var res in result) { + for(var fld in result[res]) { if (typeof result[res][fld] == 'object') { result[res][fld] = result[res][fld][result[res][fld].length - 1]; } @@ -101,7 +101,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ } } - for (i in result){ + for (var i in result){ var gen_key = result[i][this.chart_info_fields]+"_"+result[i][this.group_field]; if (this.opration_fld[gen_key] == undefined){ var map_val = {} @@ -182,7 +182,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ if (xystr[xystring] == undefined){ xyname = {}; xyname[self.chart_info_fields] = xystring; - for (j in self.group_list){ + for (var j in self.group_list){ xyname[self.group_list[j]] = 0.0001; } xyname[newkey] = result[i][self.operator_field]; @@ -207,7 +207,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ //for legend color var grp_color = []; - for (i in self.group_list){ + for (var i in self.group_list){ var legend = {}; if (self.group_list[i] == "val"){ legend['text'] = self.fields[self.operator_field]['string'] @@ -381,4 +381,4 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ }; -// vim:et fdc=0 fdl=0: \ No newline at end of file +// vim:et fdc=0 fdl=0: -- cgit v1.2.3 From ceda49fbad9b86b140012011c4a07087aa31537d Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 17 Jun 2011 11:13:35 +0200 Subject: [FIX] terminate statements missing semicolons bzr revid: xmo@openerp.com-20110617091335-r9k07mr5m5lp9f0o --- addons/base_graph/static/src/js/graph.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index e1805f2d07a..719ef55df5d 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -104,7 +104,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ for (var i in result){ var gen_key = result[i][this.chart_info_fields]+"_"+result[i][this.group_field]; if (this.opration_fld[gen_key] == undefined){ - var map_val = {} + var map_val = {}; map_val[this.operator_field] = result[i][this.operator_field]; if (this.operator.length > 1){ map_val[this.operator_field_one] = result[i][this.operator_field_one]; @@ -123,7 +123,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ this.opration_fld[gen_key] = map_val; } } - result = [] + result = []; for (i in this.opration_fld){ result.push(this.opration_fld[i]); } -- cgit v1.2.3 From 7ed58deec796efcd4c3cd14bb85f789d081428c6 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 17 Jun 2011 11:13:44 +0200 Subject: [FIX] remove trailing commas in object literals bzr revid: xmo@openerp.com-20110617091344-mlal79a9poagjwm3 --- addons/base_graph/static/src/js/graph.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index 719ef55df5d..c67a4494594 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -283,7 +283,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ marker:{ type:"round", width:12 - }, + } } }); for (var i = 1; i Date: Fri, 17 Jun 2011 11:13:54 +0200 Subject: [IMP] simplify summing: use the += operator to avoid redundancies and excessively long lines bzr revid: xmo@openerp.com-20110617091354-nus2mw3r7g2bvbrr --- addons/base_graph/static/src/js/graph.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index c67a4494594..e0a3c1feeea 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -116,9 +116,9 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ this.opration_fld[gen_key] = map_val; }else{ map_val = this.opration_fld[gen_key]; - map_val[this.operator_field] = map_val[this.operator_field] + result[i][this.operator_field]; + map_val[this.operator_field] += result[i][this.operator_field]; if (this.operator.length > 1){ - map_val[this.operator_field_one] = map_val[this.operator_field_one] + result[i][this.operator_field_one]; + map_val[this.operator_field_one] += result[i][this.operator_field_one]; } this.opration_fld[gen_key] = map_val; } -- cgit v1.2.3 From c5e061fec9bc1594f7a99e26970ecf12211ed95f Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 17 Jun 2011 11:24:36 +0200 Subject: [FIX] don't make explicit boolean comparisons without identity In javascript, '0 == false', '1 == true' and even '"1" == true'. Either use variables directly in a boolean context, or use type-strict equality (===) to ensure the variable is an actual boolean, not some other type coerced to a boolean bzr revid: xmo@openerp.com-20110617092436-s8b5v4v5ytbonvi1 --- addons/base_graph/static/src/js/graph.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index e0a3c1feeea..7a9073996e9 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -250,7 +250,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ template:function(obj){ if(x_ax['template']){ var val = obj[x_ax['template']]; - val = (typeof val == 'object')?val[1]:(val==false?'Undefined':val); + val = (typeof val == 'object')?val[1]:(!val?'Undefined':val); return val; }else{ return obj; @@ -263,7 +263,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ template:function(obj){ if(y_ax['template']){ var vals = obj[y_ax['template']]; - vals = (typeof vals == 'object')?vals[1]:(vals==false?'Undefined':vals); + vals = (typeof vals == 'object')?vals[1]:(!vals?'Undefined':vals); return vals; }else{ return obj; -- cgit v1.2.3 From 485adfdef9db1ecac8cefc4b171fd940eadd5a91 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 17 Jun 2011 11:32:22 +0200 Subject: [FIX] avoid reusing variables in completely different contexts, especially function parameters. Also avoid declaring the same variables multiple times in the same function, either split the usage into different variables (if it's reuse) or declare only once (if it's alternate initialization) bzr revid: xmo@openerp.com-20110617093222-8mx8tkshkcave3g1 --- addons/base_graph/static/src/js/graph.js | 87 ++++++++++++++++---------------- 1 file changed, 43 insertions(+), 44 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index 7a9073996e9..73609175798 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -39,7 +39,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ this.group_field = ''; this.orientation = this.fields_view.arch.attrs.orientation || ''; - for(fld in this.fields_view.arch.children) { + for(var fld in this.fields_view.arch.children) { if (this.fields_view.arch.children[fld].attrs.operator) { this.operator.push(this.fields_view.arch.children[fld].attrs.name); } @@ -91,7 +91,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ } if (typeof result[res][fld] == 'string'){ if (this.all_fields[fld]['selection']){ - for (i in this.all_fields[fld]['selection']){ + for (var i in this.all_fields[fld]['selection']){ if(result[res][fld] == this.all_fields[fld]['selection'][i][0]){ result[res][fld] = this.all_fields[fld]['selection'][i]; } @@ -101,37 +101,37 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ } } - for (var i in result){ - var gen_key = result[i][this.chart_info_fields]+"_"+result[i][this.group_field]; + for (var j in result){ + var gen_key = result[j][this.chart_info_fields]+"_"+result[j][this.group_field]; if (this.opration_fld[gen_key] == undefined){ var map_val = {}; - map_val[this.operator_field] = result[i][this.operator_field]; + map_val[this.operator_field] = result[j][this.operator_field]; if (this.operator.length > 1){ - map_val[this.operator_field_one] = result[i][this.operator_field_one]; + map_val[this.operator_field_one] = result[j][this.operator_field_one]; } - map_val[this.chart_info_fields] = result[i][this.chart_info_fields]; + map_val[this.chart_info_fields] = result[j][this.chart_info_fields]; if (this.group_field){ - map_val[this.group_field] = (typeof result[i][this.group_field] == 'object')?result[i][this.group_field][1]:result[i][this.group_field]; + map_val[this.group_field] = (typeof result[j][this.group_field] == 'object')?result[j][this.group_field][1]:result[j][this.group_field]; } this.opration_fld[gen_key] = map_val; }else{ map_val = this.opration_fld[gen_key]; - map_val[this.operator_field] += result[i][this.operator_field]; + map_val[this.operator_field] += result[j][this.operator_field]; if (this.operator.length > 1){ - map_val[this.operator_field_one] += result[i][this.operator_field_one]; + map_val[this.operator_field_one] += result[j][this.operator_field_one]; } this.opration_fld[gen_key] = map_val; } } - result = []; - for (i in this.opration_fld){ - result.push(this.opration_fld[i]); + var graph_data = []; + for (var op in this.opration_fld){ + graph_data.push(this.opration_fld[op]); } if(this.chart == 'bar') { - return this.schedule_bar(result); + return this.schedule_bar(graph_data); } else if(this.chart == "pie") { - return this.schedule_pie(result); + return this.schedule_pie(graph_data); } } }, @@ -156,7 +156,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ view_chart = self.orientation == 'horizontal'? 'barH' : 'bar'; } - for (i in result){ + for (var i in result){ if (self.group_field && (this.operator.length <= 1)){ newkey =result[i][self.group_field].split(' ').join('_'); }else{ @@ -172,51 +172,51 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ } } - for (i in result){ - var xystring = result[i][self.chart_info_fields]; + for (var j in result){ + var xystring = result[j][self.chart_info_fields]; if (self.group_field && (self.operator.length <= 1)){ - newkey =result[i][self.group_field].split(' ').join('_'); + newkey =result[j][self.group_field].split(' ').join('_'); }else{ newkey = "val"; } if (xystr[xystring] == undefined){ xyname = {}; xyname[self.chart_info_fields] = xystring; - for (var j in self.group_list){ - xyname[self.group_list[j]] = 0.0001; + for (var k in self.group_list){ + xyname[self.group_list[k]] = 0.0001; } - xyname[newkey] = result[i][self.operator_field]; + xyname[newkey] = result[j][self.operator_field]; if (self.operator.length > 1){ - xyname[newkey_one] = result[i][self.operator_field_one]; + xyname[newkey_one] = result[j][self.operator_field_one]; } xystr[xystring] = xyname; } else{ xyname = {}; xyname = xystr[xystring]; - xyname[newkey] = result[i][self.operator_field]; + xyname[newkey] = result[j][self.operator_field]; if (self.operator.length > 1){ - xyname[newkey_one] = result[i][self.operator_field_one]; + xyname[newkey_one] = result[j][self.operator_field_one]; } xystr[xystring] = xyname; } } - for (i in xystr){ - res.push(xystr[i]); + for (var label in xystr){ + res.push(xystr[label]); } //for legend color var grp_color = []; - for (var i in self.group_list){ + for (var l in self.group_list){ var legend = {}; - if (self.group_list[i] == "val"){ + if (self.group_list[l] == "val"){ legend['text'] = self.fields[self.operator_field]['string'] - }else if(self.group_list[i] == "val1"){ + }else if(self.group_list[l] == "val1"){ legend['text'] = self.fields[self.operator_field_one]['string'] }else{ - legend['text'] = self.group_list[i]; + legend['text'] = self.group_list[l]; } - legend['color'] = COLOR_PALETTE[i]; + legend['color'] = COLOR_PALETTE[l]; grp_color.push(legend); } @@ -228,12 +228,13 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ oth_ax['lines'] = true; oth_ax['title'] = ""+self.y_title+""; + var x_ax, y_ax; if (self.orientation == 'horizontal'){ - var x_ax = oth_ax; - var y_ax = temp_ax; + x_ax = oth_ax; + y_ax = temp_ax; }else{ - var x_ax = temp_ax; - var y_ax = oth_ax; + x_ax = temp_ax; + y_ax = oth_ax; } var bar_chart = new dhtmlxchartChart({ @@ -286,16 +287,15 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ } } }); - for (var i = 1; i Date: Fri, 17 Jun 2011 11:32:59 +0200 Subject: [FIX] Assigning variables to themselves is a NOOP in Javascript, and just noise bzr revid: xmo@openerp.com-20110617093259-eltod1l1ytsyq82h --- addons/base_graph/static/src/js/graph.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index 73609175798..bd54a68a117 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -338,8 +338,6 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ id = id[self.chart_info_fields]; if (typeof id == 'object'){ id = id[0]; - }else{ - id = id; } if(this.view_manager.action.context){ this.view_manager.action.context = {}; -- cgit v1.2.3 From 8ad063965daef98cdd78c6c0efcfbc1fb76fed9d Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 17 Jun 2011 13:52:26 +0200 Subject: [FIX] do not use for...in to iterate on arrays, avoid using it to iterate on object as well. Use _.each in either cases. See doc for rationale bzr revid: xmo@openerp.com-20110617115226-21meg23d0tg43wgv --- addons/base_graph/static/src/js/graph.js | 126 ++++++++++++++++--------------- 1 file changed, 64 insertions(+), 62 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index bd54a68a117..2aa290e61f2 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -39,17 +39,18 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ this.group_field = ''; this.orientation = this.fields_view.arch.attrs.orientation || ''; - for(var fld in this.fields_view.arch.children) { - if (this.fields_view.arch.children[fld].attrs.operator) { - this.operator.push(this.fields_view.arch.children[fld].attrs.name); + _.each(this.fields_view.arch.children, function (field) { + if (field.attrs.operator) { + this.operator.push(field.attrs.name); } - else if (this.fields_view.arch.children[fld].attrs.group) { - this.group_field = this.fields_view.arch.children[fld].attrs.name; + else if (field.attrs.group) { + this.group_field = field.attrs.name; } else { - this.chart_info_fields.push(this.fields_view.arch.children[fld].attrs.name); + this.chart_info_fields.push(field.attrs.name); } - } + }, this); + this.operator_field = this.operator[0]; if(this.operator.length > 1){ this.operator_field_one = this.operator[1]; @@ -80,53 +81,53 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ } }, - schedule_chart: function(result) { + schedule_chart: function(results) { this.$element.html(QWeb.render("GraphView", {"fields_view": this.fields_view, "chart": this.chart,'view_id': this.view_id})); this.opration_fld = {}; - if (result.length){ - for(var res in result) { - for(var fld in result[res]) { - if (typeof result[res][fld] == 'object') { - result[res][fld] = result[res][fld][result[res][fld].length - 1]; + if (results.length){ + _.each(results, function (result) { + _.each(result, function (field_value, field_name) { + if (typeof field_value == 'object') { + result[field_name] = field_value[field_value.length - 1]; } - if (typeof result[res][fld] == 'string'){ - if (this.all_fields[fld]['selection']){ - for (var i in this.all_fields[fld]['selection']){ - if(result[res][fld] == this.all_fields[fld]['selection'][i][0]){ - result[res][fld] = this.all_fields[fld]['selection'][i]; - } + if (typeof field_value == 'string'){ + var choices = this.all_fields[field_name]['selection']; + _.each(choices, function (choice) { + if(field_value == choice[0]){ + result[field_name] = choice; } - } + }); } - } - } + }, this); + }, this); - for (var j in result){ - var gen_key = result[j][this.chart_info_fields]+"_"+result[j][this.group_field]; + _.each(results, function (result) { + var gen_key = result[this.chart_info_fields]+"_"+result[this.group_field]; if (this.opration_fld[gen_key] == undefined){ var map_val = {}; - map_val[this.operator_field] = result[j][this.operator_field]; + map_val[this.operator_field] = result[this.operator_field]; if (this.operator.length > 1){ - map_val[this.operator_field_one] = result[j][this.operator_field_one]; + map_val[this.operator_field_one] = result[this.operator_field_one]; } - map_val[this.chart_info_fields] = result[j][this.chart_info_fields]; + map_val[this.chart_info_fields] = result[this.chart_info_fields]; if (this.group_field){ - map_val[this.group_field] = (typeof result[j][this.group_field] == 'object')?result[j][this.group_field][1]:result[j][this.group_field]; + map_val[this.group_field] = (typeof result[this.group_field] == 'object')?result[this.group_field][1]:result[this.group_field]; } this.opration_fld[gen_key] = map_val; - }else{ + } else { map_val = this.opration_fld[gen_key]; - map_val[this.operator_field] += result[j][this.operator_field]; + map_val[this.operator_field] += result[this.operator_field]; if (this.operator.length > 1){ - map_val[this.operator_field_one] += result[j][this.operator_field_one]; + map_val[this.operator_field_one] += result[this.operator_field_one]; } this.opration_fld[gen_key] = map_val; } - } + }, this); + var graph_data = []; - for (var op in this.opration_fld){ - graph_data.push(this.opration_fld[op]); - } + _.each(this.opration_fld, function (column_data) { + graph_data.push(column_data); + }); if(this.chart == 'bar') { return this.schedule_bar(graph_data); @@ -136,14 +137,14 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ } }, - schedule_bar: function(result) { + schedule_bar: function(results) { var self = this; var view_chart = ''; var xystr = {}; var xyname = {}; var res = []; this.group_list = []; - var newkey = ''; + var newkey = '', newkey_one; var COLOR_PALETTE = ['#cc99ff', '#ccccff', '#48D1CC', '#CFD784', '#8B7B8B', '#75507b', '#b0008c', '#ff0000', '#ff8e00', '#9000ff', '#0078ff', '#00ff00', '#e6ff00', '#ffff00', '#905000', '#9b0000', '#840067', '#9abe00', '#ffc900', '#510090', '#0000c9', '#009b00', @@ -156,69 +157,70 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ view_chart = self.orientation == 'horizontal'? 'barH' : 'bar'; } - for (var i in result){ + _.each(results, function (result) { if (self.group_field && (this.operator.length <= 1)){ - newkey =result[i][self.group_field].split(' ').join('_'); - }else{ + newkey = result[self.group_field].split(' ').join('_'); + } else { newkey = "val"; } if (jQuery.inArray(newkey, self.group_list) == -1){ self.group_list.push(newkey); if(this.operator.length > 1){ - var newkey_one = "val1"; + newkey_one = "val1"; self.group_list.push(newkey_one); } } - } + }, this); - for (var j in result){ - var xystring = result[j][self.chart_info_fields]; + _.each(results, function (result) { + var xystring = result[self.chart_info_fields]; if (self.group_field && (self.operator.length <= 1)){ - newkey =result[j][self.group_field].split(' ').join('_'); + newkey = result[self.group_field].split(' ').join('_'); }else{ newkey = "val"; } if (xystr[xystring] == undefined){ xyname = {}; xyname[self.chart_info_fields] = xystring; - for (var k in self.group_list){ - xyname[self.group_list[k]] = 0.0001; - } - xyname[newkey] = result[j][self.operator_field]; + _.each(self.group_list, function (group) { + xyname[group] = 0.0001; + }); + xyname[newkey] = result[self.operator_field]; if (self.operator.length > 1){ - xyname[newkey_one] = result[j][self.operator_field_one]; + xyname[newkey_one] = result[self.operator_field_one]; } xystr[xystring] = xyname; } else{ xyname = {}; xyname = xystr[xystring]; - xyname[newkey] = result[j][self.operator_field]; + xyname[newkey] = result[self.operator_field]; if (self.operator.length > 1){ - xyname[newkey_one] = result[j][self.operator_field_one]; + xyname[newkey_one] = result[self.operator_field_one]; } xystr[xystring] = xyname; } - } - for (var label in xystr){ - res.push(xystr[label]); - } + }); + + _.each(xystr, function (column_data) { + res.push(column_data); + }); //for legend color var grp_color = []; - for (var l in self.group_list){ + _.each(self.group_list, function (group_legend, index) { var legend = {}; - if (self.group_list[l] == "val"){ + if (group_legend == "val"){ legend['text'] = self.fields[self.operator_field]['string'] - }else if(self.group_list[l] == "val1"){ + }else if(group_legend == "val1"){ legend['text'] = self.fields[self.operator_field_one]['string'] }else{ - legend['text'] = self.group_list[l]; + legend['text'] = group_legend; } - legend['color'] = COLOR_PALETTE[l]; + legend['color'] = COLOR_PALETTE[index]; grp_color.push(legend); - } + }); //for axis's value and title var temp_ax = {}; -- cgit v1.2.3 From 413054ce53d20ace6813e26db118399150761829 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 17 Jun 2011 13:55:59 +0200 Subject: [IMP] use object literals when possible: clearer lower amount of noise, and clearer relations between the object and its components bzr revid: xmo@openerp.com-20110617115559-n89evkkufc3f8k9t --- addons/base_graph/static/src/js/graph.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index 2aa290e61f2..81b99cbddbd 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -210,7 +210,8 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ //for legend color var grp_color = []; _.each(self.group_list, function (group_legend, index) { - var legend = {}; + var legend = {color: COLOR_PALETTE[index]}; + if (group_legend == "val"){ legend['text'] = self.fields[self.operator_field]['string'] }else if(group_legend == "val1"){ @@ -218,17 +219,18 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ }else{ legend['text'] = group_legend; } - legend['color'] = COLOR_PALETTE[index]; grp_color.push(legend); }); //for axis's value and title - var temp_ax = {}; - var oth_ax = {}; - temp_ax['template'] = self.chart_info_fields; - temp_ax['title'] = ""+self.x_title+"" ; - oth_ax['lines'] = true; - oth_ax['title'] = ""+self.y_title+""; + var temp_ax = { + template: self.chart_info_fields, + title: ""+self.x_title+"" + }; + var oth_ax = { + lines: true, + title: ""+self.y_title+"" + }; var x_ax, y_ax; if (self.orientation == 'horizontal'){ -- cgit v1.2.3 From 57bd9de5023b26ae1e965b2b8f237bb99cd9513d Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 17 Jun 2011 15:22:22 +0200 Subject: [IMP] reduce variable scopes: move instance variables to function scopes, remove unneeded temps, move variables to inner function scopes. Variable scopes should be as small as possible (but no smaller) in order to make their data flow easy to understand bzr revid: xmo@openerp.com-20110617132222-p0jabvioctjcn9o4 --- addons/base_graph/static/src/js/graph.js | 68 ++++++++++++-------------------- 1 file changed, 26 insertions(+), 42 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index 81b99cbddbd..7ebeffa78ab 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -25,7 +25,6 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ this.rpc("/base_graph/graphview/load", {"model": this.model, "view_id": this.view_id}, this.on_loaded); }, on_loaded: function(data) { - var self = this; this.all_fields = data.all_fields; this.fields_view = data.fields_view; this.name = this.fields_view.name || this.fields_view.arch.attrs.string; @@ -61,7 +60,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ this.chart_info = this.chart_info_fields[0]; this.x_title = this.fields[this.chart_info_fields[0]]['string']; this.y_title = this.fields[this.operator_field]['string']; - self.load_chart(); + this.load_chart(); }, load_chart: function(data) { @@ -83,7 +82,6 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ schedule_chart: function(results) { this.$element.html(QWeb.render("GraphView", {"fields_view": this.fields_view, "chart": this.chart,'view_id': this.view_id})); - this.opration_fld = {}; if (results.length){ _.each(results, function (result) { _.each(result, function (field_value, field_name) { @@ -101,10 +99,11 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ }, this); }, this); + var opration_fld = {}; _.each(results, function (result) { var gen_key = result[this.chart_info_fields]+"_"+result[this.group_field]; - if (this.opration_fld[gen_key] == undefined){ - var map_val = {}; + var map_val = {}; + if (opration_fld[gen_key] == undefined){ map_val[this.operator_field] = result[this.operator_field]; if (this.operator.length > 1){ map_val[this.operator_field_one] = result[this.operator_field_one]; @@ -113,19 +112,18 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ if (this.group_field){ map_val[this.group_field] = (typeof result[this.group_field] == 'object')?result[this.group_field][1]:result[this.group_field]; } - this.opration_fld[gen_key] = map_val; } else { - map_val = this.opration_fld[gen_key]; + map_val = opration_fld[gen_key]; map_val[this.operator_field] += result[this.operator_field]; if (this.operator.length > 1){ map_val[this.operator_field_one] += result[this.operator_field_one]; } - this.opration_fld[gen_key] = map_val; } + opration_fld[gen_key] = map_val; }, this); var graph_data = []; - _.each(this.opration_fld, function (column_data) { + _.each(opration_fld, function (column_data) { graph_data.push(column_data); }); @@ -141,9 +139,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ var self = this; var view_chart = ''; var xystr = {}; - var xyname = {}; - var res = []; - this.group_list = []; + var group_list = []; var newkey = '', newkey_one; var COLOR_PALETTE = ['#cc99ff', '#ccccff', '#48D1CC', '#CFD784', '#8B7B8B', '#75507b', '#b0008c', '#ff0000', '#ff8e00', '#9000ff', '#0078ff', '#00ff00', '#e6ff00', '#ffff00', @@ -164,52 +160,40 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ newkey = "val"; } - if (jQuery.inArray(newkey, self.group_list) == -1){ - self.group_list.push(newkey); + if (jQuery.inArray(newkey, group_list) == -1){ + group_list.push(newkey); if(this.operator.length > 1){ newkey_one = "val1"; - self.group_list.push(newkey_one); + group_list.push(newkey_one); } } }, this); _.each(results, function (result) { - var xystring = result[self.chart_info_fields]; + var xystring = result[self.chart_info_fields], + xyname = {}; if (self.group_field && (self.operator.length <= 1)){ newkey = result[self.group_field].split(' ').join('_'); }else{ newkey = "val"; } if (xystr[xystring] == undefined){ - xyname = {}; xyname[self.chart_info_fields] = xystring; - _.each(self.group_list, function (group) { + _.each(group_list, function (group) { xyname[group] = 0.0001; }); - xyname[newkey] = result[self.operator_field]; - if (self.operator.length > 1){ - xyname[newkey_one] = result[self.operator_field_one]; - } - xystr[xystring] = xyname; - } - else{ - xyname = {}; + } else { xyname = xystr[xystring]; - xyname[newkey] = result[self.operator_field]; - if (self.operator.length > 1){ - xyname[newkey_one] = result[self.operator_field_one]; - } - xystr[xystring] = xyname; } - }); - - _.each(xystr, function (column_data) { - res.push(column_data); + xyname[newkey] = result[self.operator_field]; + if (self.operator.length > 1){ + xyname[newkey_one] = result[self.operator_field_one]; + } + xystr[xystring] = xyname; }); //for legend color - var grp_color = []; - _.each(self.group_list, function (group_legend, index) { + var grp_color = _.map(group_list, function (group_legend, index) { var legend = {color: COLOR_PALETTE[index]}; if (group_legend == "val"){ @@ -219,7 +203,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ }else{ legend['text'] = group_legend; } - grp_color.push(legend); + return legend; }); //for axis's value and title @@ -244,7 +228,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ var bar_chart = new dhtmlxchartChart({ view: view_chart, container: self.view_id+"-barchart", - value:"#"+self.group_list[0]+"#", + value:"#"+group_list[0]+"#", gradient: "3d", border: false, width: 1024, @@ -291,13 +275,13 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ } } }); - for (var m = 1; m Date: Fri, 17 Jun 2011 15:25:50 +0200 Subject: [IMP] move COLOR_PALETTE to toplevel constant, so it does not have to be recreated every time we go through the corresponding function bzr revid: xmo@openerp.com-20110617132550-b5add9fv7xuxjilz --- addons/base_graph/static/src/js/graph.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index 7ebeffa78ab..c868807b30d 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -3,6 +3,15 @@ *---------------------------------------------------------*/ openerp.base_graph = function (openerp) { +var COLOR_PALETTE = [ + '#cc99ff', '#ccccff', '#48D1CC', '#CFD784', '#8B7B8B', '#75507b', + '#b0008c', '#ff0000', '#ff8e00', '#9000ff', '#0078ff', '#00ff00', + '#e6ff00', '#ffff00', '#905000', '#9b0000', '#840067', '#9abe00', + '#ffc900', '#510090', '#0000c9', '#009b00', '#75507b', '#3465a4', + '#73d216', '#c17d11', '#edd400', '#fcaf3e', '#ef2929', '#ff00c9', + '#ad7fa8', '#729fcf', '#8ae234', '#e9b96e', '#fce94f', '#f57900', + '#cc0000', '#d400a8']; + QWeb.add_template('/base_graph/static/src/xml/base_graph.xml'); openerp.base.views.add('graph', 'openerp.base_graph.GraphView'); openerp.base_graph.GraphView = openerp.base.Controller.extend({ @@ -142,11 +151,6 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ var group_list = []; var newkey = '', newkey_one; - var COLOR_PALETTE = ['#cc99ff', '#ccccff', '#48D1CC', '#CFD784', '#8B7B8B', '#75507b', '#b0008c', '#ff0000', '#ff8e00', '#9000ff', '#0078ff', '#00ff00', '#e6ff00', '#ffff00', - '#905000', '#9b0000', '#840067', '#9abe00', '#ffc900', '#510090', '#0000c9', '#009b00', - '#75507b', '#3465a4', '#73d216', '#c17d11', '#edd400', '#fcaf3e', '#ef2929', '#ff00c9', - '#ad7fa8', '#729fcf', '#8ae234', '#e9b96e', '#fce94f', '#f57900', '#cc0000', '#d400a8']; - if(self.group_field && (this.operator.length <= 1)){ view_chart = self.orientation == 'horizontal'? 'stackedBarH' : 'stackedBar'; }else{ -- cgit v1.2.3 From 872f7e163d0c1034ad2c62c75d071d0ba8215b37 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 17 Jun 2011 15:31:56 +0200 Subject: [IMP] invert tests and bail out early in order to reduce excessive nesting of functions bzr revid: xmo@openerp.com-20110617133156-g3fk9f386tdrdcje --- addons/base_graph/static/src/js/graph.js | 103 +++++++++++++++---------------- 1 file changed, 50 insertions(+), 53 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index c868807b30d..7670eca9c83 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -91,56 +91,52 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ schedule_chart: function(results) { this.$element.html(QWeb.render("GraphView", {"fields_view": this.fields_view, "chart": this.chart,'view_id': this.view_id})); - if (results.length){ - _.each(results, function (result) { - _.each(result, function (field_value, field_name) { - if (typeof field_value == 'object') { - result[field_name] = field_value[field_value.length - 1]; - } - if (typeof field_value == 'string'){ - var choices = this.all_fields[field_name]['selection']; - _.each(choices, function (choice) { - if(field_value == choice[0]){ - result[field_name] = choice; - } - }); - } - }, this); - }, this); - - var opration_fld = {}; - _.each(results, function (result) { - var gen_key = result[this.chart_info_fields]+"_"+result[this.group_field]; - var map_val = {}; - if (opration_fld[gen_key] == undefined){ - map_val[this.operator_field] = result[this.operator_field]; - if (this.operator.length > 1){ - map_val[this.operator_field_one] = result[this.operator_field_one]; - } - map_val[this.chart_info_fields] = result[this.chart_info_fields]; - if (this.group_field){ - map_val[this.group_field] = (typeof result[this.group_field] == 'object')?result[this.group_field][1]:result[this.group_field]; - } - } else { - map_val = opration_fld[gen_key]; - map_val[this.operator_field] += result[this.operator_field]; - if (this.operator.length > 1){ - map_val[this.operator_field_one] += result[this.operator_field_one]; - } + if (!results.length) { + return; + } + _.each(results, function (result) { + _.each(result, function (field_value, field_name) { + if (typeof field_value == 'object') { + result[field_name] = field_value[field_value.length - 1]; + } + if (typeof field_value == 'string') { + var choices = this.all_fields[field_name]['selection']; + _.each(choices, function (choice) { + if (field_value == choice[0]) { + result[field_name] = choice; + } + }); } - opration_fld[gen_key] = map_val; }, this); + }, this); - var graph_data = []; - _.each(opration_fld, function (column_data) { - graph_data.push(column_data); - }); - - if(this.chart == 'bar') { - return this.schedule_bar(graph_data); - } else if(this.chart == "pie") { - return this.schedule_pie(graph_data); + var opration_fld = {}; + _.each(results, function (result) { + var gen_key = result[this.chart_info_fields] + "_" + result[this.group_field]; + var map_val = {}; + if (opration_fld[gen_key] == undefined) { + map_val[this.operator_field] = result[this.operator_field]; + if (this.operator.length > 1) { + map_val[this.operator_field_one] = result[this.operator_field_one]; + } + map_val[this.chart_info_fields] = result[this.chart_info_fields]; + if (this.group_field) { + map_val[this.group_field] = (typeof result[this.group_field] == 'object') ? result[this.group_field][1] : result[this.group_field]; + } + } else { + map_val = opration_fld[gen_key]; + map_val[this.operator_field] += result[this.operator_field]; + if (this.operator.length > 1) { + map_val[this.operator_field_one] += result[this.operator_field_one]; + } } + opration_fld[gen_key] = map_val; + }, this); + + if (this.chart == 'bar') { + return this.schedule_bar(_.values(opration_fld)); + } else if (this.chart == "pie") { + return this.schedule_pie(_.values(opration_fld)); } }, @@ -158,18 +154,19 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ } _.each(results, function (result) { - if (self.group_field && (this.operator.length <= 1)){ + if (self.group_field && (this.operator.length <= 1)) { newkey = result[self.group_field].split(' ').join('_'); } else { newkey = "val"; } - if (jQuery.inArray(newkey, group_list) == -1){ - group_list.push(newkey); - if(this.operator.length > 1){ - newkey_one = "val1"; - group_list.push(newkey_one); - } + if (_.contains(group_list, newkey)) { + return; + } + group_list.push(newkey); + if (this.operator.length > 1) { + newkey_one = "val1"; + group_list.push(newkey_one); } }, this); -- cgit v1.2.3 From f9fad97b47a24a2f7ba719ab31d0759debe3be21 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 20 Jun 2011 08:38:48 +0200 Subject: [IMP] try to improve naming slightly bzr revid: xmo@openerp.com-20110620063848-qltrrdm88v1ww3cy --- addons/base_graph/static/src/js/graph.js | 80 ++++++++++++++++---------------- 1 file changed, 40 insertions(+), 40 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index 7670eca9c83..edf3809d6f1 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -110,40 +110,39 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ }, this); }, this); - var opration_fld = {}; + var graph_data = {}; _.each(results, function (result) { - var gen_key = result[this.chart_info_fields] + "_" + result[this.group_field]; - var map_val = {}; - if (opration_fld[gen_key] == undefined) { - map_val[this.operator_field] = result[this.operator_field]; + var column_key = result[this.chart_info_fields] + "_" + result[this.group_field]; + var column_descriptor = {}; + if (graph_data[column_key] == undefined) { + column_descriptor[this.operator_field] = result[this.operator_field]; if (this.operator.length > 1) { - map_val[this.operator_field_one] = result[this.operator_field_one]; + column_descriptor[this.operator_field_one] = result[this.operator_field_one]; } - map_val[this.chart_info_fields] = result[this.chart_info_fields]; + column_descriptor[this.chart_info_fields] = result[this.chart_info_fields]; if (this.group_field) { - map_val[this.group_field] = (typeof result[this.group_field] == 'object') ? result[this.group_field][1] : result[this.group_field]; + column_descriptor[this.group_field] = (typeof result[this.group_field] == 'object') ? result[this.group_field][1] : result[this.group_field]; } } else { - map_val = opration_fld[gen_key]; - map_val[this.operator_field] += result[this.operator_field]; + column_descriptor = graph_data[column_key]; + column_descriptor[this.operator_field] += result[this.operator_field]; if (this.operator.length > 1) { - map_val[this.operator_field_one] += result[this.operator_field_one]; + column_descriptor[this.operator_field_one] += result[this.operator_field_one]; } } - opration_fld[gen_key] = map_val; + graph_data[column_key] = column_descriptor; }, this); if (this.chart == 'bar') { - return this.schedule_bar(_.values(opration_fld)); + return this.schedule_bar(_.values(graph_data)); } else if (this.chart == "pie") { - return this.schedule_pie(_.values(opration_fld)); + return this.schedule_pie(_.values(graph_data)); } }, schedule_bar: function(results) { var self = this; var view_chart = ''; - var xystr = {}; var group_list = []; var newkey = '', newkey_one; @@ -170,27 +169,28 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ } }, this); + var abscissa_data = {}; _.each(results, function (result) { - var xystring = result[self.chart_info_fields], - xyname = {}; + var label = result[self.chart_info_fields], + section = {}; if (self.group_field && (self.operator.length <= 1)){ newkey = result[self.group_field].split(' ').join('_'); }else{ newkey = "val"; } - if (xystr[xystring] == undefined){ - xyname[self.chart_info_fields] = xystring; + if (abscissa_data[label] == undefined){ + section[self.chart_info_fields] = label; _.each(group_list, function (group) { - xyname[group] = 0.0001; + section[group] = 0.0001; }); } else { - xyname = xystr[xystring]; + section = abscissa_data[label]; } - xyname[newkey] = result[self.operator_field]; + section[newkey] = result[self.operator_field]; if (self.operator.length > 1){ - xyname[newkey_one] = result[self.operator_field_one]; + section[newkey_one] = result[self.operator_field_one]; } - xystr[xystring] = xyname; + abscissa_data[label] = section; }); //for legend color @@ -208,22 +208,22 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ }); //for axis's value and title - var temp_ax = { + var abscissa_description = { template: self.chart_info_fields, title: ""+self.x_title+"" }; - var oth_ax = { + var ordinate_description = { lines: true, title: ""+self.y_title+"" }; - var x_ax, y_ax; + var x_axis, y_axis; if (self.orientation == 'horizontal'){ - x_ax = oth_ax; - y_ax = temp_ax; + x_axis = ordinate_description; + y_axis = abscissa_description; }else{ - x_ax = temp_ax; - y_ax = oth_ax; + x_axis = abscissa_description; + y_axis = ordinate_description; } var bar_chart = new dhtmlxchartChart({ @@ -238,29 +238,29 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ origin:0, xAxis:{ template:function(obj){ - if(x_ax['template']){ - var val = obj[x_ax['template']]; + if(x_axis['template']){ + var val = obj[x_axis['template']]; val = (typeof val == 'object')?val[1]:(!val?'Undefined':val); return val; }else{ return obj; } }, - title:x_ax['title'], - lines:x_ax['lines'] + title:x_axis['title'], + lines:x_axis['lines'] }, yAxis:{ template:function(obj){ - if(y_ax['template']){ - var vals = obj[y_ax['template']]; + if(y_axis['template']){ + var vals = obj[y_axis['template']]; vals = (typeof vals == 'object')?vals[1]:(!vals?'Undefined':vals); return vals; }else{ return obj; } }, - title:y_ax['title'], - lines: y_ax['lines'] + title:y_axis['title'], + lines: y_axis['lines'] }, padding: { left: 75 @@ -282,7 +282,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ color: grp_color[m]['color'] }); } - bar_chart.parse(_.values(xystr), "json"); + bar_chart.parse(_.values(abscissa_data), "json"); bar_chart.attachEvent("onItemClick", function(id) { self.open_list_view(bar_chart.get(id)); }); -- cgit v1.2.3 From 0aedbd386ceb9123dc9ddea99f8e0e644d1d9ee3 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 20 Jun 2011 09:55:02 +0200 Subject: [FIX] use Number.toFixed instead of doing decimal rounding by hand bzr revid: xmo@openerp.com-20110620075502-3p1v1asit32ti9um --- addons/base_graph/static/src/js/graph.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index edf3809d6f1..fc3cea371cf 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -296,7 +296,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ pieInnerText:function(obj) { var sum = chart.sum("#"+self.operator_field+"#"); var val = obj[self.operator_field] / sum * 100 ; - return Math.round(val * 10)/10 + "%"; + return val.toFixed(1) + "%"; }, gradient:"3d", height: 20, -- cgit v1.2.3 From ca34076fbd5d24f2a77954bd07f77d227daf45bd Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 20 Jun 2011 12:05:57 +0200 Subject: [IMP] rollback namespace-alteration to dhtmlXChart, fix dhtmlxscheduler and dhtmlxgantt to not fuck up the root dhtmlx namespace (which is what breaks chart) bzr revid: xmo@openerp.com-20110620100557-zya9u6a3zuhhs0c3 --- addons/base_graph/static/src/js/graph.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index fc3cea371cf..d5c16f1cb90 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -226,7 +226,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ y_axis = ordinate_description; } - var bar_chart = new dhtmlxchartChart({ + var bar_chart = new dhtmlXChart({ view: view_chart, container: self.view_id+"-barchart", value:"#"+group_list[0]+"#", @@ -289,7 +289,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ }, schedule_pie: function(result) { var self = this; - var chart = new dhtmlxchartChart({ + var chart = new dhtmlXChart({ view:"pie3D", container:self.view_id+"-piechart", value:"#"+self.operator_field+"#", -- cgit v1.2.3 From d44a542efbcb603d147115e4e450d28484e3c4df Mon Sep 17 00:00:00 2001 From: "Kunal Chavda (OpenERP)" Date: Mon, 20 Jun 2011 17:45:25 +0530 Subject: [IMP]implement code for there is no data than show axis and pass element_id instead of view_id. bzr revid: kch@tinyerp.com-20110620121525-kq2rw54ouu3fo8da --- addons/base_graph/static/src/js/graph.js | 74 ++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 13 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index edf3809d6f1..3186a50495f 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -46,6 +46,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ this.operator = []; this.group_field = ''; this.orientation = this.fields_view.arch.attrs.orientation || ''; + this.elem_id = this.$element[0]['id']; _.each(this.fields_view.arch.children, function (field) { if (field.attrs.operator) { @@ -81,19 +82,17 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ }else{ this.dataset.read_ids( this.dataset.ids, - {}, - function(res) { + {}, function(res) { self.schedule_chart(res); - } - ); + }); } }, schedule_chart: function(results) { - this.$element.html(QWeb.render("GraphView", {"fields_view": this.fields_view, "chart": this.chart,'view_id': this.view_id})); - if (!results.length) { + this.$element.html(QWeb.render("GraphView", {"fields_view": this.fields_view, "chart": this.chart,'elem_id': this.elem_id})); + /*if (!results.length) { return; - } + }*/ _.each(results, function (result) { _.each(result, function (field_value, field_name) { if (typeof field_value == 'object') { @@ -169,11 +168,16 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ } }, this); + if (group_list.length <=1){ + group_list = []; + group_list.push(newkey = "val"); + } + var abscissa_data = {}; _.each(results, function (result) { var label = result[self.chart_info_fields], section = {}; - if (self.group_field && (self.operator.length <= 1)){ + if (self.group_field && (group_list.length > 1) && (self.operator.length <= 1)){ newkey = result[self.group_field].split(' ').join('_'); }else{ newkey = "val"; @@ -196,7 +200,6 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ //for legend color var grp_color = _.map(group_list, function (group_legend, index) { var legend = {color: COLOR_PALETTE[index]}; - if (group_legend == "val"){ legend['text'] = self.fields[self.operator_field]['string'] }else if(group_legend == "val1"){ @@ -208,13 +211,54 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ }); //for axis's value and title + var max_min = []; + var max = 0; + var min = 0; + var step = 0; + var stack_data = 0; + var minimum = 0; + + if(! _.isEmpty(abscissa_data)){ + _.each(abscissa_data, function (abscissa_datas) { + if (group_list.length <= 1){ + max_min.push(abscissa_datas[group_list]); + }else{ + stack_data = (abscissa_datas[group_list[0]]) + (abscissa_datas[group_list[1]]); + max_min.push(stack_data); + } + }); + max = Math.max.apply(Math,max_min); + minimum = Math.min.apply(Math,max_min); + if (minimum < 0){ + min = minimum; + } + if (max != 0){ + if (max < 0){ + max = max - (10 + max % 10) + }else{ + max = max + (10 - (max % 10)) + } + step = Math.round(max/10); + }else{ + max = 9; + step = 1; + } + }else{ + max = 9; + step=1; + } + var abscissa_description = { template: self.chart_info_fields, title: ""+self.x_title+"" }; + var ordinate_description = { lines: true, - title: ""+self.y_title+"" + title: ""+self.y_title+"", + start: min, + step: step, + end: max }; var x_axis, y_axis; @@ -228,7 +272,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ var bar_chart = new dhtmlxchartChart({ view: view_chart, - container: self.view_id+"-barchart", + container: self.elem_id+"-barchart", value:"#"+group_list[0]+"#", gradient: "3d", border: false, @@ -260,7 +304,10 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ } }, title:y_axis['title'], - lines: y_axis['lines'] + lines: y_axis['lines'], + start:y_axis['start'], + step:y_axis['step'], + end:y_axis['end'] }, padding: { left: 75 @@ -283,6 +330,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ }); } bar_chart.parse(_.values(abscissa_data), "json"); + jQuery("#"+self.elem_id+"-barchart").height(jQuery("#"+self.elem_id+"-barchart").height()+50); bar_chart.attachEvent("onItemClick", function(id) { self.open_list_view(bar_chart.get(id)); }); @@ -291,7 +339,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ var self = this; var chart = new dhtmlxchartChart({ view:"pie3D", - container:self.view_id+"-piechart", + container:self.elem_id+"-piechart", value:"#"+self.operator_field+"#", pieInnerText:function(obj) { var sum = chart.sum("#"+self.operator_field+"#"); -- cgit v1.2.3 From ec186dfb7d394a337744a70aab3b042feeddbbf8 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 20 Jun 2011 16:39:46 +0200 Subject: [FIX] race condition between graph view loading and search request: View.start() should return a promise if it makes an async call, so caller (ViewManager in this case) knows when the graph view is ready for action Also inherit from View bzr revid: xmo@openerp.com-20110620143946-tv0qx84e0y06zxu7 --- addons/base_graph/static/src/js/graph.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index d5c16f1cb90..4dec023b93f 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -14,7 +14,7 @@ var COLOR_PALETTE = [ QWeb.add_template('/base_graph/static/src/xml/base_graph.xml'); openerp.base.views.add('graph', 'openerp.base_graph.GraphView'); -openerp.base_graph.GraphView = openerp.base.Controller.extend({ +openerp.base_graph.GraphView = openerp.base.View.extend({ init: function(view_manager, session, element_id, dataset, view_id) { this._super(session, element_id); @@ -31,7 +31,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({ this.$element.hide(); }, start: function() { - this.rpc("/base_graph/graphview/load", {"model": this.model, "view_id": this.view_id}, this.on_loaded); + return this.rpc("/base_graph/graphview/load", {"model": this.model, "view_id": this.view_id}, this.on_loaded); }, on_loaded: function(data) { this.all_fields = data.all_fields; -- cgit v1.2.3 From f41b9ccfa0b50e2eb72355092e1f704f0394a472 Mon Sep 17 00:00:00 2001 From: "Kunal Chavda (OpenERP)" Date: Tue, 21 Jun 2011 10:56:43 +0530 Subject: [FIX]fixed code for stackbar chart. bzr revid: kch@tinyerp.com-20110621052643-q084w0yh1rky63ej --- addons/base_graph/static/src/js/graph.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index 07efe19e6f8..c3b9f97ed5a 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -185,7 +185,7 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ if (abscissa_data[label] == undefined){ section[self.chart_info_fields] = label; _.each(group_list, function (group) { - section[group] = 0.0001; + section[group] = 0; }); } else { section = abscissa_data[label]; -- cgit v1.2.3 From 543460f23a998e8b907a989da55a72b859fbb4bb Mon Sep 17 00:00:00 2001 From: "Kunal Chavda (OpenERP)" Date: Tue, 21 Jun 2011 16:20:31 +0530 Subject: [IMP]Improved code for x-axis label rotation upto sixty degree. bzr revid: kch@tinyerp.com-20110621105031-cqb165ocpgh3og6t --- addons/base_graph/static/src/js/graph.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index c3b9f97ed5a..c3c5e9f62b9 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -277,6 +277,9 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ gradient: "3d", border: false, width: 1024, + tooltip:{ + template:"#"+group_list[0]+"#" + }, radius: 0, color:grp_color[0]['color'], origin:0, @@ -326,6 +329,9 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ for (var m = 1; m Date: Fri, 1 Jul 2011 12:09:56 +0530 Subject: [IMP]Improved code for when more than one field has group, legend and tooltip. bzr revid: kch@tinyerp.com-20110701063956-40c62ommlbubzqmr --- addons/base_graph/static/src/js/graph.js | 138 +++++++++++++++++++------------ 1 file changed, 85 insertions(+), 53 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index c3c5e9f62b9..67abdfd890a 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -44,7 +44,7 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ this.operator_field = ''; this.operator_field_one = ''; this.operator = []; - this.group_field = ''; + this.group_field = []; this.orientation = this.fields_view.arch.attrs.orientation || ''; this.elem_id = this.$element[0]['id']; @@ -53,7 +53,7 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ this.operator.push(field.attrs.name); } else if (field.attrs.group) { - this.group_field = field.attrs.name; + this.group_field.push(field.attrs.name); } else { this.chart_info_fields.push(field.attrs.name); @@ -111,7 +111,16 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ var graph_data = {}; _.each(results, function (result) { - var column_key = result[this.chart_info_fields] + "_" + result[this.group_field]; + var group_key = []; + if(this.group_field.length){ + _.each(this.group_field, function (res) { + result[res] = (typeof result[res] == 'object') ? result[res][1] : result[res]; + group_key.push(result[res]); + }); + }else{ + group_key.push(result[this.group_field]); + } + var column_key = result[this.chart_info_fields] + "_" + group_key; var column_descriptor = {}; if (graph_data[column_key] == undefined) { column_descriptor[this.operator_field] = result[this.operator_field]; @@ -119,8 +128,10 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ column_descriptor[this.operator_field_one] = result[this.operator_field_one]; } column_descriptor[this.chart_info_fields] = result[this.chart_info_fields]; - if (this.group_field) { - column_descriptor[this.group_field] = (typeof result[this.group_field] == 'object') ? result[this.group_field][1] : result[this.group_field]; + if(this.group_field.length){ + _.each(this.group_field, function (res) { + column_descriptor[res] = (typeof result[res] == 'object') ? result[res][1] : result[res]; + }); } } else { column_descriptor = graph_data[column_key]; @@ -143,42 +154,61 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ var self = this; var view_chart = ''; var group_list = []; + var legend_list = []; var newkey = '', newkey_one; + var string_legend = ''; - if(self.group_field && (this.operator.length <= 1)){ + if((self.group_field.length) && (this.operator.length <= 1)){ view_chart = self.orientation == 'horizontal'? 'stackedBarH' : 'stackedBar'; }else{ view_chart = self.orientation == 'horizontal'? 'barH' : 'bar'; } _.each(results, function (result) { - if (self.group_field && (this.operator.length <= 1)) { - newkey = result[self.group_field].split(' ').join('_'); + if ((self.group_field.length) && (this.operator.length <= 1)) { + var legend_key = ''; + _.each(self.group_field, function (res) { + result[res] = (typeof result[res] == 'object') ? result[res][1] : result[res]; + legend_key = legend_key + result[res]; + }); + newkey = legend_key.replace(/\s+/g,'_').replace(/[^a-zA-Z 0-9]+/g,'_'); + string_legend = legend_key; } else { - newkey = "val"; + newkey = string_legend = "val"; } - if (_.contains(group_list, newkey)) { + if (_.contains(group_list, newkey) && _.contains(legend_list, string_legend)) { return; } group_list.push(newkey); + legend_list.push(string_legend); + if (this.operator.length > 1) { newkey_one = "val1"; group_list.push(newkey_one); + legend_list.push(newkey_one); } }, this); if (group_list.length <=1){ group_list = []; - group_list.push(newkey = "val"); + legend_list = []; + newkey = string_legend = "val"; + group_list.push(newkey); + legend_list.push(string_legend); } var abscissa_data = {}; _.each(results, function (result) { var label = result[self.chart_info_fields], section = {}; - if (self.group_field && (group_list.length > 1) && (self.operator.length <= 1)){ - newkey = result[self.group_field].split(' ').join('_'); + if ((self.group_field.length) && (group_list.length > 1) && (self.operator.length <= 1)){ + var legend_key_two = ''; + _.each(self.group_field, function (res) { + result[res] = (typeof result[res] == 'object') ? result[res][1] : result[res]; + legend_key_two = legend_key_two +result[res]; + }); + newkey = legend_key_two.replace(/\s+/g,'_').replace(/[^a-zA-Z 0-9]+/g,'_'); }else{ newkey = "val"; } @@ -198,7 +228,7 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ }); //for legend color - var grp_color = _.map(group_list, function (group_legend, index) { + var grp_color = _.map(legend_list, function (group_legend, index) { var legend = {color: COLOR_PALETTE[index]}; if (group_legend == "val"){ legend['text'] = self.fields[self.operator_field]['string'] @@ -211,43 +241,37 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ }); //for axis's value and title - var max_min = []; - var max = 0; - var min = 0; - var step = 0; - var stack_data = 0; - var minimum = 0; - - if(! _.isEmpty(abscissa_data)){ + var max,min,step; + var maximum,minimum; + if(_.isEmpty(abscissa_data)){ + max = 9; + min = 0; + step=1; + }else{ + var max_min = []; _.each(abscissa_data, function (abscissa_datas) { - if (group_list.length <= 1){ - max_min.push(abscissa_datas[group_list]); - }else{ - stack_data = (abscissa_datas[group_list[0]]) + (abscissa_datas[group_list[1]]); - max_min.push(stack_data); - } + _.each(group_list, function(res){ + max_min.push(abscissa_datas[res]); + }); }); - max = Math.max.apply(Math,max_min); + maximum = Math.max.apply(Math,max_min); minimum = Math.min.apply(Math,max_min); - if (minimum < 0){ - min = minimum; - } - if (max != 0){ - if (max < 0){ - max = max - (10 + max % 10) + if (maximum == minimum){ + if (maximum == 0){ + max = 9; + min = 0; + step=1; + }else if(maximum > 0){ + max = maximum + (10 - maximum % 10) + min = 0; + step = Math.round(max/10); }else{ - max = max + (10 - (max % 10)) + max = 0; + min = minimum - (10 + minimum % 10) + step = Math.round(Math.abs(min)/10); } - step = Math.round(max/10); - }else{ - max = 9; - step = 1; } - }else{ - max = 9; - step=1; } - var abscissa_description = { template: self.chart_info_fields, title: ""+self.x_title+"" @@ -261,7 +285,7 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ end: max }; - var x_axis, y_axis; + var x_axis, y_axis, tooltip; if (self.orientation == 'horizontal'){ x_axis = ordinate_description; y_axis = abscissa_description; @@ -269,7 +293,7 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ x_axis = abscissa_description; y_axis = ordinate_description; } - + tooltip = self.chart_info_fields; var bar_chart = new dhtmlXChart({ view: view_chart, container: self.elem_id+"-barchart", @@ -278,7 +302,7 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ border: false, width: 1024, tooltip:{ - template:"#"+group_list[0]+"#" + template:"#"+tooltip+"#"+","+grp_color[0]['text']+"="+"#"+group_list[0]+"#" }, radius: 0, color:grp_color[0]['color'], @@ -288,6 +312,9 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ if(x_axis['template']){ var val = obj[x_axis['template']]; val = (typeof val == 'object')?val[1]:(!val?'Undefined':val); + if(val.length > 12){ + val = val.substring(0,12); + } return val; }else{ return obj; @@ -301,6 +328,9 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ if(y_axis['template']){ var vals = obj[y_axis['template']]; vals = (typeof vals == 'object')?vals[1]:(!vals?'Undefined':vals); + if(vals.length > 12){ + vals = vals.substring(0,12); + } return vals; }else{ return obj; @@ -330,7 +360,7 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ bar_chart.addSeries({ value: "#"+group_list[m]+"#", tooltip:{ - template:"#"+group_list[m]+"#" + template:"#"+tooltip+"#"+","+grp_color[m]['text']+"="+"#"+group_list[m]+"#" }, color: grp_color[m]['color'] }); @@ -338,6 +368,9 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ bar_chart.parse(_.values(abscissa_data), "json"); jQuery("#"+self.elem_id+"-barchart").height(jQuery("#"+self.elem_id+"-barchart").height()+50); bar_chart.attachEvent("onItemClick", function(id) { + if(jQuery(".dhx_tooltip").is(":visible") == true) { + jQuery(".dhx_tooltip").css('display','none'); + } self.open_list_view(bar_chart.get(id)); }); }, @@ -352,6 +385,9 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ var val = obj[self.operator_field] / sum * 100 ; return val.toFixed(1) + "%"; }, + tooltip:{ + template:"#"+self.chart_info_fields+"#"+"="+"#"+self.operator_field+"#" + }, gradient:"3d", height: 20, radius: 200, @@ -414,11 +450,7 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ }); }); } - }); - // here you may tweak globals object, if any, and play with on_* or do_* callbacks on them - }; - -// vim:et fdc=0 fdl=0: +// vim:et fdc=0 fdl=0: \ No newline at end of file -- cgit v1.2.3 From 2213b2bd326a23943bbe1b8e25fb019ef006a486 Mon Sep 17 00:00:00 2001 From: "Kunal Chavda (OpenERP)" Date: Thu, 7 Jul 2011 16:58:22 +0530 Subject: [FIX]Fixed issue of automatically load graph when switch from list to graph and implement code for click on graph in dashboard will switch list view. bzr revid: kch@tinyerp.com-20110707112822-of7q11div3hy8jl2 --- addons/base_graph/static/src/js/graph.js | 65 +++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 23 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index 67abdfd890a..1a6cf0be427 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -20,6 +20,7 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ this._super(session, element_id); this.view_manager = view_manager; this.dataset = dataset; + this.dataset_index = 0; this.model = this.dataset.model; this.view_id = view_id; }, @@ -80,19 +81,15 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ this.y_title = this.all_fields[this.operator_field]['string']; self.schedule_chart(data); }else{ - this.dataset.read_ids( - this.dataset.ids, - {}, function(res) { - self.schedule_chart(res); - }); + this.dataset.read_slice(this.fields, 0, false, function(res) { + self.schedule_chart(res); + }); } }, schedule_chart: function(results) { this.$element.html(QWeb.render("GraphView", {"fields_view": this.fields_view, "chart": this.chart,'elem_id': this.elem_id})); - /*if (!results.length) { - return; - }*/ + _.each(results, function (result) { _.each(result, function (field_value, field_name) { if (typeof field_value == 'object') { @@ -294,6 +291,7 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ y_axis = ordinate_description; } tooltip = self.chart_info_fields; + var bar_chart = new dhtmlXChart({ view: view_chart, container: self.elem_id+"-barchart", @@ -368,9 +366,6 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ bar_chart.parse(_.values(abscissa_data), "json"); jQuery("#"+self.elem_id+"-barchart").height(jQuery("#"+self.elem_id+"-barchart").height()+50); bar_chart.attachEvent("onItemClick", function(id) { - if(jQuery(".dhx_tooltip").is(":visible") == true) { - jQuery(".dhx_tooltip").css('display','none'); - } self.open_list_view(bar_chart.get(id)); }); }, @@ -413,23 +408,47 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ }); }, open_list_view : function (id){ + if($(".dhx_tooltip").is(":visible") == true) { + $(".dhx_tooltip").remove('div'); + } var self = this; id = id[self.chart_info_fields]; if (typeof id == 'object'){ id = id[0]; } - if(this.view_manager.action.context){ - this.view_manager.action.context = {}; + + var self = this; + var record_id = ""; + self.dataset.model = self.model; + if (typeof self.chart_info_fields == 'object'){ + record_id = self.chart_info_fields[0]; + }else{ + record_id = self.chart_info_fields; } - if(!this.view_manager.action.domain) { - this.view_manager.action.domain = [[self.chart_info_fields, '=', id],['id','in',self.dataset.ids]]; - } else { - this.view_manager.action.domain.push([self.chart_info_fields, '=', id],['id','in',self.dataset.ids]); + self.dataset.domain = [[record_id, '=', id],['id','in',self.dataset.ids]]; + var modes = !!modes ? modes.split(",") : ["list", "form", "graph"]; + var views = []; + _.each(modes, function(mode) { + var view = [false, mode]; + if (self.fields.views && self.fields.views[mode]) { + view.push(self.fields.views[mode]); + } + views.push(view); + }); + var action = { + "res_model" : self.dataset.model, + "domain" : self.dataset.domain, + "views" : views, + "type" : "ir.actions.act_window", + "auto_search" : true, + "view_type" : "list", + "view_mode" : "list" } - var action_manager = new openerp.base.ActionManager(this.view_manager.session, this.view_manager.element_id); - action_manager.start(); - action_manager.do_action(this.view_manager.action); + this.actionmanager = new openerp.base.ActionManager(this.session, "oe_app"); + this.actionmanager.start(); + this.actionmanager.do_action(action); }, + do_search: function(domains, contexts, groupbys) { var self = this; this.rpc('/base/session/eval_domain_and_context', { @@ -443,9 +462,9 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ }else{ self.chart_info_fields = self.chart_info; } - self.dataset.context = self.context = results.context; - self.dataset.domain = self.domain = results.domain; - self.dataset.read_slice({}, 0, self.limit,function(response){ + self.dataset.context = results.context; + self.dataset.domain = results.domain; + self.dataset.read_slice([], 0, false,function(response){ self.load_chart(response); }); }); -- cgit v1.2.3 From df955d1dc8997c9bbef1648d8f34fde90c026584 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 11 Jul 2011 16:58:16 +0200 Subject: [IMP] remove some intermediate variables crud in graph bzr revid: xmo@openerp.com-20110711145816-lrk9y1iijcy6yptl --- addons/base_graph/static/src/js/graph.js | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index 1a6cf0be427..378e219d4c4 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -408,24 +408,23 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ }); }, open_list_view : function (id){ - if($(".dhx_tooltip").is(":visible") == true) { + var self = this; + if($(".dhx_tooltip").is(":visible")) { $(".dhx_tooltip").remove('div'); } - var self = this; - id = id[self.chart_info_fields]; + id = id[this.chart_info_fields]; if (typeof id == 'object'){ id = id[0]; } - var self = this; var record_id = ""; - self.dataset.model = self.model; - if (typeof self.chart_info_fields == 'object'){ - record_id = self.chart_info_fields[0]; + this.dataset.model = this.model; + if (typeof this.chart_info_fields == 'object'){ + record_id = this.chart_info_fields[0]; }else{ - record_id = self.chart_info_fields; + record_id = this.chart_info_fields; } - self.dataset.domain = [[record_id, '=', id],['id','in',self.dataset.ids]]; + this.dataset.domain = [[record_id, '=', id],['id','in',this.dataset.ids]]; var modes = !!modes ? modes.split(",") : ["list", "form", "graph"]; var views = []; _.each(modes, function(mode) { @@ -435,18 +434,17 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ } views.push(view); }); - var action = { - "res_model" : self.dataset.model, - "domain" : self.dataset.domain, + this.actionmanager = new openerp.base.ActionManager(this.session, "oe_app"); + this.actionmanager.start(); + this.actionmanager.do_action({ + "res_model" : this.dataset.model, + "domain" : this.dataset.domain, "views" : views, "type" : "ir.actions.act_window", "auto_search" : true, "view_type" : "list", "view_mode" : "list" - } - this.actionmanager = new openerp.base.ActionManager(this.session, "oe_app"); - this.actionmanager.start(); - this.actionmanager.do_action(action); + }); }, do_search: function(domains, contexts, groupbys) { @@ -472,4 +470,4 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ }); // here you may tweak globals object, if any, and play with on_* or do_* callbacks on them }; -// vim:et fdc=0 fdl=0: \ No newline at end of file +// vim:et fdc=0 fdl=0: -- cgit v1.2.3 From 94ed3f9e7504fc845388e45b6be31de561e63363 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 11 Jul 2011 16:59:07 +0200 Subject: [FIX] some warnings bzr revid: xmo@openerp.com-20110711145907-inumrb183i01a35n --- addons/base_graph/static/src/js/graph.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'addons/base_graph/static/src/js') diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index 378e219d4c4..6f1e3a89253 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -166,7 +166,7 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ var legend_key = ''; _.each(self.group_field, function (res) { result[res] = (typeof result[res] == 'object') ? result[res][1] : result[res]; - legend_key = legend_key + result[res]; + legend_key += result[res]; }); newkey = legend_key.replace(/\s+/g,'_').replace(/[^a-zA-Z 0-9]+/g,'_'); string_legend = legend_key; @@ -203,7 +203,7 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ var legend_key_two = ''; _.each(self.group_field, function (res) { result[res] = (typeof result[res] == 'object') ? result[res][1] : result[res]; - legend_key_two = legend_key_two +result[res]; + legend_key_two += result[res]; }); newkey = legend_key_two.replace(/\s+/g,'_').replace(/[^a-zA-Z 0-9]+/g,'_'); }else{ @@ -259,12 +259,12 @@ openerp.base_graph.GraphView = openerp.base.View.extend({ min = 0; step=1; }else if(maximum > 0){ - max = maximum + (10 - maximum % 10) + max = maximum + (10 - maximum % 10); min = 0; step = Math.round(max/10); }else{ max = 0; - min = minimum - (10 + minimum % 10) + min = minimum - (10 + minimum % 10); step = Math.round(Math.abs(min)/10); } } -- cgit v1.2.3