From 69257d5d6f9c757cfba4447f63336fd14fb4be49 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 8 Nov 2013 12:32:10 +0100 Subject: [REF] work in progress. reset graph view to minimal state in addon web_graph bzr revid: ged@openerp.com-20131108113210-aptz2pne05iwca82 --- addons/web_graph/static/src/js/graph.js | 412 +------------------------------- 1 file changed, 4 insertions(+), 408 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index a84bb53fc85..f0bef5d5749 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -7,15 +7,6 @@ openerp.web_graph = function (instance) { var _lt = instance.web._lt; var _t = instance.web._t; -// removed ``undefined`` values -var filter_values = function (o) { - var out = {}; - for (var k in o) { - if (!o.hasOwnProperty(k) || o[k] === undefined) { continue; } - out[k] = o[k]; - } - return out; -}; instance.web.views.add('graph', 'instance.web_graph.GraphView'); instance.web_graph.GraphView = instance.web.View.extend({ @@ -24,411 +15,16 @@ instance.web_graph.GraphView = instance.web.View.extend({ view_type: "graph", init: function(parent, dataset, view_id, options) { - var self = this; - this._super(parent); + this._super(parent, dataset, view_id, options); this.set_default_options(options); - this.dataset = dataset; - this.view_id = view_id; - - this.mode = "bar"; // line, bar, area, pie, radar - this.orientation = false; // true: horizontal, false: vertical - this.stacked = true; - - this.spreadsheet = false; // Display data grid, allows copy to CSV - this.forcehtml = false; - this.legend = "top"; // top, inside, no - - this.domain = []; - this.context = {}; - this.group_by = []; - - this.graph = null; - }, - view_loading: function(r) { - return this.load_graph(r); - }, - destroy: function () { - if (this.graph) { - this.graph.destroy(); - } - this._super(); - }, - - load_graph: function(fields_view_get) { - // TODO: move to load_view and document - var self = this; - this.fields_view = fields_view_get; - this.$el.addClass(this.fields_view.arch.attrs['class']); - - this.mode = this.fields_view.arch.attrs.type || 'bar'; - this.orientation = this.fields_view.arch.attrs.orientation == 'horizontal'; - - var width = this.$el.parent().width(); - this.$el.css("width", width); - this.container = this.$el.find("#editor-render-body").css({ - width: width, - height: Math.min(500, width * 0.8) - })[0]; - - var graph_render = this.proxy('graph_render'); - this.$el.on('click', '.oe_graph_options a', function (evt) { - var $el = $(evt.target); - - self.graph_render({data: filter_values({ - mode: $el.data('mode'), - legend: $el.data('legend'), - orientation: $el.data('orientation'), - stacked: $el.data('stacked') - })}); - }); - - this.$el.find("#graph_show_data").click(function () { - self.spreadsheet = ! self.spreadsheet; - self.graph_render(); - }); - this.$el.find("#graph_switch").click(function () { - if (self.mode != 'radar') { - self.orientation = ! self.orientation; - } - self.graph_render(); - }); - - this.$el.find("#graph_download").click(function () { - if (self.legend == "top") { self.legend = "inside"; } - self.forcehtml = true; - - self.graph_get_data().done(function (result) { - self.graph_render_all(result).download.saveImage('png'); - }).always(function () { - self.forcehtml = false; - }); - }); - this.trigger('graph_view_loaded', fields_view_get); - }, - - get_format: function (options) { - options = options || {}; - var legend = { - show: this.legend != 'no', - }; - - switch (this.legend) { - case 'top': - legend.noColumns = 4; - legend.container = this.$el.find("div.graph_header_legend")[0]; - break; - case 'inside': - legend.position = 'nw'; - legend.backgroundColor = '#D2E8FF'; - break; - } - - return _.extend({ - legend: legend, - mouse: { - track: true, - relative: true - }, - spreadsheet : { - show: this.spreadsheet, - initialTab: "data" - }, - HtmlText : (options.xaxis && options.xaxis.labelsAngle) ? false : !this.forcehtml, - }, options); - }, - - make_graph: function (mode, container, data) { - if (mode === 'area') { mode = 'line'; } - var format = this.get_format(this['options_' + mode](data)); - return Flotr.draw(container, data.data, format); - }, - - options_bar: function (data) { - var min = _(data.data).chain() - .map(function (record) { - if (record.data.length > 0){ - return _.min(record.data, function (item) { - return item[1]; - })[1]; - } - }).min().value(); - return { - bars : { - show : true, - stacked : this.stacked, - horizontal : this.orientation, - barWidth : 0.7, - lineWidth : 1 - }, - grid : { - verticalLines : this.orientation, - horizontalLines : !this.orientation, - outline : "sw", - }, - yaxis : { - ticks: this.orientation ? data.ticks : false, - min: !this.orientation ? (min < 0 ? min : 0) : null - }, - xaxis : { - labelsAngle: 45, - ticks: this.orientation ? false : data.ticks, - min: this.orientation ? (min < 0 ? min : 0) : null - } - }; - }, - - options_pie: function (data) { - return { - pie : { - show: true - }, - grid : { - verticalLines : false, - horizontalLines : false, - outline : "", - }, - xaxis : {showLabels: false}, - yaxis : {showLabels: false}, - }; - }, - - options_radar: function (data) { - return { - radar : { - show : true, - stacked : this.stacked - }, - grid : { - circular : true, - minorHorizontalLines : true - }, - xaxis : { - ticks: data.ticks - }, - }; - }, - - options_line: function (data) { - return { - lines : { - show : true, - }, - points: { - show: true, - }, - grid : { - verticalLines : this.orientation, - horizontalLines : !this.orientation, - outline : "sw", - }, - yaxis : { - ticks: this.orientation ? data.ticks : false - }, - xaxis : { - labelsAngle: 45, - ticks: this.orientation ? false : data.ticks - } - }; - }, - - graph_get_data: function () { - var model = this.dataset.model, - domain = new instance.web.CompoundDomain(this.domain || []), - context = new instance.web.CompoundContext(this.context || {}), - group_by = this.group_by || [], - view_id = this.view_id || false, - mode = this.mode || 'bar', - orientation = this.orientation || false, - stacked = this.stacked || false; - - var obj = new instance.web.Model(model); - var view_get; - var fields; - var result = []; - var ticks = {}; - - return this.alive(obj.call("fields_view_get", [view_id, 'graph', context]).then(function(tmp) { - view_get = tmp; - fields = view_get['fields']; - var toload = _.select(group_by, function(x) { return fields[x] === undefined }); - if (toload.length >= 1) - return obj.call("fields_get", [toload, context]); - else - return $.when([]); - }).then(function (fields_to_add) { - _.extend(fields, fields_to_add); - - var tree = $($.parseXML(view_get['arch'])); - - var pos = 0; - var xaxis = _.clone(group_by || []); - var yaxis = []; - tree.find("field").each(function() { - var field = $(this); - if (! field.attr("name")) - return; - if ((group_by.length == 0) && ((! pos) || instance.web.py_eval(field.attr('group') || "false"))) { - xaxis.push(field.attr('name')); - } - if (pos && ! instance.web.py_eval(field.attr('group') || "false")) { - yaxis.push(field.attr('name')); - } - pos += 1; - }); - - if (xaxis.length === 0) - throw new Error("No field for the X axis!"); - if (yaxis.length === 0) - throw new Error("No field for the Y axis!"); - - // Convert a field's data into a displayable string - - function _convert_key(field, data) { - if (fields[field]['type'] === 'many2one') - data = data && data[0]; - return data; - } - - function _convert(field, data, tick) { - tick = tick === undefined ? true : false; - try { - data = instance.web.format_value(data, fields[field]); - } catch(e) { - data = "" + data; - } - if (tick) { - if (ticks[data] === undefined) - ticks[data] = _.size(ticks); - return ticks[data]; - } - return data || 0; - } - - function _orientation(x, y) { - if (! orientation) - return [x, y] - return [y, x] - } - - if (mode === "pie") { - return obj.call("read_group", [domain, yaxis.concat([xaxis[0]]), [xaxis[0]]], {context: context}).then(function(res) { - _.each(res, function(record) { - result.push({ - 'data': [[_convert(xaxis[0], record[xaxis[0]]), record[yaxis[0]]]], - 'label': _convert(xaxis[0], record[xaxis[0]], false) - }); - }); - }); - } else if ((! stacked) || (xaxis.length < 2)) { - var defs = []; - _.each(xaxis, function(x) { - defs.push(obj.call("read_group", [domain, yaxis.concat([x]), [x]], {context: context}).then(function(res) { - return [x, res]; - })); - }); - return $.when.apply($, defs).then(function() { - _.each(_.toArray(arguments), function(res) { - var x = res[0]; - res = res[1]; - result.push({ - 'data': _.map(res, function(record) { - return _orientation(_convert(x, record[x]), record[yaxis[0]] || 0); - }), - 'label': fields[x]['string'] - }); - }); - }); - } else { - xaxis.reverse(); - return obj.call("read_group", [domain, yaxis.concat(xaxis.slice(0, 1)), xaxis.slice(0, 1)], {context: context}).then(function(axis) { - var defs = []; - _.each(axis, function(x) { - var key = x[xaxis[0]] - defs.push(obj.call("read_group", [x['__domain'], yaxis.concat(xaxis.slice(1, 2)), xaxis.slice(1, 2)], {context: context}).then(function(res) { - return [x, key, res]; - })); - }); - return $.when.apply($, defs).then(function() { - _.each(_.toArray(arguments), function(res) { - var x = res[0]; - var key = res[1]; - res = res[2]; - result.push({ - 'data': _.map(res, function(record) { - return _orientation(_convert(xaxis[1], record[xaxis[1]]), record[yaxis[0]] || 0); - }), - 'label': _convert(xaxis[0], key, false) - }) - }); - }); - }); - } - }).then(function() { - var res = { - 'data': result, - 'ticks': _.map(ticks, function(el, key) { return [el, key || _t("Undefined")] }) - }; - return res; - })); - }, - // Render the graph and update menu styles - graph_render: function (options) { - options = options || {}; - _.extend(this, options.data); - - return this.graph_get_data() - .done(this.proxy('graph_render_all')); - }, - - graph_render_all: function (data) { - var i; - if (this.mode=='area') { - for (i=0; i 1) { - $active = $active.filter('[data-stacked=' + this.stacked + ']'); - } - $active = $active.add( - this.$el.find('a:not([data-mode])[data-legend=' + this.legend + ']')); - - $active.addClass('active'); - - if (this.spreadsheet) { - this.$el.find("#graph_show_data").addClass("active"); - } - return this.graph; }, - // render the graph using the domain, context and group_by - // calls the 'graph_data_get' python controller to process all data - // TODO: check is group_by should better be in the context - do_search: function(domain, context, group_by) { - this.domain = domain; - this.context = context; - this.group_by = group_by; - - this.graph_render(); - }, - - do_show: function() { + do_show: function () { this.do_push_state({}); return this._super(); }, + + }); }; -- cgit v1.2.3 From 23b9f226c782e1b8290171df530dfb0465933204 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 8 Nov 2013 12:50:30 +0100 Subject: [ADD] add (custom version of) bootstrap library to graph view (addon web_graph) bzr revid: ged@openerp.com-20131108115030-0r4e4vk379mqtkzf --- addons/web_graph/static/src/js/graph.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index f0bef5d5749..af63c78cff1 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -16,8 +16,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ init: function(parent, dataset, view_id, options) { this._super(parent, dataset, view_id, options); - this.set_default_options(options); - }, do_show: function () { -- cgit v1.2.3 From 7ad9aecc13e23ce40a4b22e31ed5f7f9435adf4c Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 8 Nov 2013 14:08:06 +0100 Subject: [IMP] add widgets (chart view and pivot view) in addon web_graph bzr revid: ged@openerp.com-20131108130806-ez2a6sxdsy0bzg62 --- addons/web_graph/static/src/js/graph.js | 57 +++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index af63c78cff1..173f2e8973a 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -1,28 +1,79 @@ /*--------------------------------------------------------- * OpenERP web_graph *---------------------------------------------------------*/ +/*global openerp:true*/ +/*global $:true*/ +'use strict'; openerp.web_graph = function (instance) { var _lt = instance.web._lt; var _t = instance.web._t; - instance.web.views.add('graph', 'instance.web_graph.GraphView'); + instance.web_graph.GraphView = instance.web.View.extend({ - template: "GraphView", + template: 'GraphView', display_name: _lt('Graph'), - view_type: "graph", + view_type: 'graph', + events: { + 'click .graph_mode_selection li' : function (event) { + event.preventDefault(); + var mode = event.target.attributes['data-mode'].nodeValue; + if (mode == 'data') { + this.chart_view.hide(); + this.pivot_table.show(); + } else { + this.pivot_table.hide(); + this.chart_view.show(mode); + } + }, + }, init: function(parent, dataset, view_id, options) { this._super(parent, dataset, view_id, options); + this.pivot_table = new PivotTable(this); + this.chart_view = new ChartView(this); + }, + + view_loading: function (fields_view_get) { + this.pivot_table.appendTo('.graph_pivot'); + this.chart_view.appendTo('.graph_chart'); + this.chart_view.hide(); }, do_show: function () { this.do_push_state({}); return this._super(); }, +}); + +var PivotTable = instance.web.Widget.extend({ + template: 'pivot_table', + + show: function () { + this.$el.css('display', 'block'); + }, + + hide: function () { + this.$el.css('display', 'none'); + }, + +}); + +var ChartView = instance.web.Widget.extend({ + template: 'chart_view', + + show: function () { + this.$el.css('display', 'block'); + }, + hide: function () { + this.$el.css('display', 'none'); + }, }); + + + }; -- cgit v1.2.3 From eab6a192e9413c09b67b28fbf856d3314051bc4a Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 8 Nov 2013 16:20:48 +0100 Subject: [IMP] add pie, line and bar chart to the chartview widget (addon web_graph) bzr revid: ged@openerp.com-20131108152048-0akyhf0c7lcdsqjh --- addons/web_graph/static/src/js/graph.js | 190 +++++++++++++++++++++++++++++++- 1 file changed, 188 insertions(+), 2 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 173f2e8973a..aa4275493b6 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -12,6 +12,10 @@ var _t = instance.web._t; instance.web.views.add('graph', 'instance.web_graph.GraphView'); + /** + * GraphView view. It mostly contains two widgets (PivotTable and ChartView) + * and some data. + */ instance.web_graph.GraphView = instance.web.View.extend({ template: 'GraphView', display_name: _lt('Graph'), @@ -19,13 +23,17 @@ instance.web_graph.GraphView = instance.web.View.extend({ events: { 'click .graph_mode_selection li' : function (event) { event.preventDefault(); - var mode = event.target.attributes['data-mode'].nodeValue; + var self = this, + mode = event.target.attributes['data-mode'].nodeValue; if (mode == 'data') { this.chart_view.hide(); this.pivot_table.show(); } else { this.pivot_table.hide(); - this.chart_view.show(mode); + this.get_data().done(function (data) { + self.chart_view.draw(data, mode); + self.chart_view.show(mode); + }); } }, }, @@ -34,20 +42,56 @@ instance.web_graph.GraphView = instance.web.View.extend({ this._super(parent, dataset, view_id, options); this.pivot_table = new PivotTable(this); this.chart_view = new ChartView(this); + this.x_groups = []; + this.measure = null; + this.domain = []; + this.model = null; + }, view_loading: function (fields_view_get) { + var self = this; + this.model = new instance.web.Model(fields_view_get.model, {group_by_no_leaf: true}); + + // get the default groupbys and measure defined in the field view + _.each(fields_view_get.arch.children, function (field) { + if ('name' in field.attrs) { + if ('operator' in field.attrs) { + self.measure = field.attrs.name; + } else { + self.x_groups.push(field.attrs.name); + } + } + }); + + this.chart_view.set_measure(this.measure); this.pivot_table.appendTo('.graph_pivot'); this.chart_view.appendTo('.graph_chart'); this.chart_view.hide(); + this.get_data().done(this.pivot_table.draw); + }, + + get_data: function () { + var view_fields = this.x_groups.concat(this.measure); + + return query_groups(this.model, view_fields, this.domain, this.x_groups); + }, + + do_search: function (domain, context, group_by) { + this.domain = new instance.web.CompoundDomain(domain); }, do_show: function () { this.do_push_state({}); return this._super(); }, + }); + /** + * PivotTable widget. It displays the data in tabular data and allows the + * user to drill down and up in the table + */ var PivotTable = instance.web.Widget.extend({ template: 'pivot_table', @@ -59,10 +103,18 @@ var PivotTable = instance.web.Widget.extend({ this.$el.css('display', 'none'); }, + draw: function (data) { + console.log("data",data); + }, }); + /** + * ChartView widget. It displays the data in chart form, using the nvd3 + * library. Various modes include bar charts, pie charts or line charts. + */ var ChartView = instance.web.Widget.extend({ template: 'chart_view', + measure: null, show: function () { this.$el.css('display', 'block'); @@ -72,8 +124,142 @@ var ChartView = instance.web.Widget.extend({ this.$el.css('display', 'none'); }, + set_measure: function (measure) { + this.measure = measure; + }, + + draw: function (data, mode) { + // d3.select('.graph_chart_svg').remove(); + + $('.graph_chart_svg').empty(); + $('.graph_chart_svg').append(''); + + switch (mode) { + case 'bar_chart': + this.render_bar_chart(data); + break; + case 'pie_chart': + this.render_pie_chart(data); + break; + case 'line_chart': + this.render_line_chart(data); + break; + } + }, + + format_data: function (datapt) { + var val = datapt.attributes; + return { + x: datapt.attributes.value[1], + y: this.measure ? val.aggregates[this.measure] : val.length, + }; + }, + + render_bar_chart: function (data) { + var formatted_data = [{ + key: 'Bar chart', + values: _.map(data, this.format_data.bind(this)), + }]; + + nv.addGraph(function () { + var chart = nv.models.discreteBarChart() + .tooltips(false) + .showValues(true) + .staggerLabels(true) + .width(650) + .height(400); + + d3.select('.graph_chart_svg svg') + .datum(formatted_data) + .attr('width', 650) + .attr('height', 400) + .call(chart); + + nv.utils.windowResize(chart.update); + return chart; + }); + }, + + render_pie_chart: function (data) { + var formatted_data = _.map(data, this.format_data.bind(this)); + + nv.addGraph(function () { + var chart = nv.models.pieChart() + .color(d3.scale.category10().range()) + .width(650) + .height(400); + + d3.select('.graph_chart_svg svg') + .datum(formatted_data) + .transition().duration(1200) + .attr('width', 650) + .attr('height', 400) + .call(chart); + + nv.utils.windowResize(chart.update); + return chart; + }); + }, + + render_line_chart: function (data) { + var measure_label = (this.measure) ? this.measure : 'Quantity'; + + var formatted_data = [{ + key: measure_label, + values: _.map(data, this.format_data.bind(this)) + }]; + + nv.addGraph(function () { + var width = 600, + height = 300; + + var chart = nv.models.lineChart() + .x(function (d,u) { return u; }) + .width(width) + .height(height) + .margin({top: 30, right: 20, bottom: 20, left: 60}); + + d3.select('.graph_chart_svg svg') + .attr('width', width) + .attr('height', height) + .datum(formatted_data) + .call(chart); + + return chart; + }); + }, + }); +/** + * Query the server and return a deferred which will return the data + * with all the groupbys applied (this is done for now, but the goal + * is to modify read_group in order to allow eager and lazy groupbys + */ +function query_groups (model, fields, domain, groupbys) { + return model.query(fields) + .filter(domain) + .group_by(groupbys) + .then(function (results) { + var non_empty_results = _.filter(results, function (group) { + return group.attributes.length > 0; + }); + if (groupbys.length <= 1) { + return non_empty_results; + } else { + var get_subgroups = $.when.apply(null, _.map(non_empty_results, function (result) { + var new_domain = result.model._domain; + var new_groupings = groupbys.slice(1); + return query_groups(model, fields,new_domain, new_groupings).then(function (subgroups) { + result.subgroups_data = subgroups; + }); + })); + return get_subgroups.then(function () { + return non_empty_results; + }); + } + }); +} }; -- cgit v1.2.3 From 906d5168cc29f3258dfa2899de1e8c45f88098b7 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 8 Nov 2013 16:27:17 +0100 Subject: [IMP] small cleanups to chartview widget (addon web_graph) bzr revid: ged@openerp.com-20131108152717-stbx0us8ipom67iq --- addons/web_graph/static/src/js/graph.js | 69 +++++++++++++++------------------ 1 file changed, 32 insertions(+), 37 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index aa4275493b6..ca704e31527 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -129,21 +129,19 @@ var ChartView = instance.web.Widget.extend({ }, draw: function (data, mode) { - // d3.select('.graph_chart_svg').remove(); - - $('.graph_chart_svg').empty(); - $('.graph_chart_svg').append(''); + $('.graph_chart').empty(); + $('.graph_chart').append(''); switch (mode) { case 'bar_chart': this.render_bar_chart(data); break; - case 'pie_chart': - this.render_pie_chart(data); - break; case 'line_chart': this.render_line_chart(data); break; + case 'pie_chart': + this.render_pie_chart(data); + break; } }, @@ -169,29 +167,8 @@ var ChartView = instance.web.Widget.extend({ .width(650) .height(400); - d3.select('.graph_chart_svg svg') - .datum(formatted_data) - .attr('width', 650) - .attr('height', 400) - .call(chart); - - nv.utils.windowResize(chart.update); - return chart; - }); - }, - - render_pie_chart: function (data) { - var formatted_data = _.map(data, this.format_data.bind(this)); - - nv.addGraph(function () { - var chart = nv.models.pieChart() - .color(d3.scale.category10().range()) - .width(650) - .height(400); - - d3.select('.graph_chart_svg svg') + d3.select('.graph_chart svg') .datum(formatted_data) - .transition().duration(1200) .attr('width', 650) .attr('height', 400) .call(chart); @@ -210,18 +187,15 @@ var ChartView = instance.web.Widget.extend({ }]; nv.addGraph(function () { - var width = 600, - height = 300; - var chart = nv.models.lineChart() .x(function (d,u) { return u; }) - .width(width) - .height(height) + .width(600) + .height(300) .margin({top: 30, right: 20, bottom: 20, left: 60}); - d3.select('.graph_chart_svg svg') - .attr('width', width) - .attr('height', height) + d3.select('.graph_chart svg') + .attr('width', 600) + .attr('height', 300) .datum(formatted_data) .call(chart); @@ -229,6 +203,27 @@ var ChartView = instance.web.Widget.extend({ }); }, + render_pie_chart: function (data) { + var formatted_data = _.map(data, this.format_data.bind(this)); + + nv.addGraph(function () { + var chart = nv.models.pieChart() + .color(d3.scale.category10().range()) + .width(650) + .height(400); + + d3.select('.graph_chart svg') + .datum(formatted_data) + .transition().duration(1200) + .attr('width', 650) + .attr('height', 400) + .call(chart); + + nv.utils.windowResize(chart.update); + return chart; + }); + }, + }); /** -- cgit v1.2.3 From 4dd5ac99249c3addd3806b31476a536c721b4fb6 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 8 Nov 2013 16:41:14 +0100 Subject: [FIX] fix a bug preventing hide and show method of chartview widget to function properly (addon web_graph) bzr revid: ged@openerp.com-20131108154114-25zqn3jq5u6iuibt --- addons/web_graph/static/src/js/graph.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index ca704e31527..30318a923a7 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -1,8 +1,10 @@ /*--------------------------------------------------------- * OpenERP web_graph *---------------------------------------------------------*/ -/*global openerp:true*/ +/*global openerp:true $:true*/ /*global $:true*/ +/*global _:true*/ + 'use strict'; openerp.web_graph = function (instance) { @@ -117,11 +119,11 @@ var ChartView = instance.web.Widget.extend({ measure: null, show: function () { - this.$el.css('display', 'block'); + $('.graph_chart').css('display', 'block'); }, hide: function () { - this.$el.css('display', 'none'); + $('.graph_chart').css('display', 'none'); }, set_measure: function (measure) { -- cgit v1.2.3 From 6ecbf2ef80552656b1ea065ba0fb5ae92967ab1d Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 12 Nov 2013 09:38:27 +0100 Subject: [IMP] add access to model fields description in addon web_graph bzr revid: ged@openerp.com-20131112083827-fy9i054l9mq3vynz --- addons/web_graph/static/src/js/graph.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 30318a923a7..e5e297dc2a8 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -1,11 +1,10 @@ /*--------------------------------------------------------- * OpenERP web_graph *---------------------------------------------------------*/ -/*global openerp:true $:true*/ -/*global $:true*/ -/*global _:true*/ 'use strict'; +/* jshint undef: false */ + openerp.web_graph = function (instance) { @@ -48,6 +47,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.measure = null; this.domain = []; this.model = null; + this.model_fields = []; }, @@ -71,6 +71,10 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.chart_view.appendTo('.graph_chart'); this.chart_view.hide(); this.get_data().done(this.pivot_table.draw); + + return this.model.call('fields_get', []).then(function (fields) { + self.model_fields = fields; + }); }, get_data: function () { @@ -79,6 +83,10 @@ instance.web_graph.GraphView = instance.web.View.extend({ return query_groups(this.model, view_fields, this.domain, this.x_groups); }, + get_desc: function(field_id) { + return this.model_fields[field_id].string; + }, + do_search: function (domain, context, group_by) { this.domain = new instance.web.CompoundDomain(domain); }, @@ -106,7 +114,7 @@ var PivotTable = instance.web.Widget.extend({ }, draw: function (data) { - console.log("data",data); + console.log('data',data); }, }); @@ -260,3 +268,4 @@ function query_groups (model, fields, domain, groupbys) { }; + -- cgit v1.2.3 From d947299a740b9b7f6d40097b69235d6aa004aa38 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 12 Nov 2013 09:49:55 +0100 Subject: [FIX] fix pivottable and chartview widget to use their template instead of hardcoded divs (addon web_graph) bzr revid: ged@openerp.com-20131112084955-2x8o57ndln0xx0nx --- addons/web_graph/static/src/js/graph.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index e5e297dc2a8..5cfd437d666 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -67,8 +67,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ }); this.chart_view.set_measure(this.measure); - this.pivot_table.appendTo('.graph_pivot'); - this.chart_view.appendTo('.graph_chart'); + this.pivot_table.appendTo('.graph_main_content'); + this.chart_view.appendTo('.graph_main_content'); this.chart_view.hide(); this.get_data().done(this.pivot_table.draw); @@ -127,11 +127,11 @@ var ChartView = instance.web.Widget.extend({ measure: null, show: function () { - $('.graph_chart').css('display', 'block'); + this.$el.css('display', 'block'); }, hide: function () { - $('.graph_chart').css('display', 'none'); + this.$el.css('display', 'none'); }, set_measure: function (measure) { @@ -139,8 +139,8 @@ var ChartView = instance.web.Widget.extend({ }, draw: function (data, mode) { - $('.graph_chart').empty(); - $('.graph_chart').append(''); + this.$el.empty(); + this.$el.append(''); switch (mode) { case 'bar_chart': -- cgit v1.2.3 From 4d7150fc5895e518e313398715170020c3287eca Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 12 Nov 2013 12:31:34 +0100 Subject: [REF] large refactoring of addon web_graph (mainly add widget BasicDataView and many cleanups) bzr revid: ged@openerp.com-20131112113134-w2298fsh1va4jpm7 --- addons/web_graph/static/src/js/graph.js | 124 +++++++++++++++----------------- 1 file changed, 58 insertions(+), 66 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 5cfd437d666..a36f8f68db0 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -21,6 +21,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ template: 'GraphView', display_name: _lt('Graph'), view_type: 'graph', + events: { 'click .graph_mode_selection li' : function (event) { event.preventDefault(); @@ -31,62 +32,46 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.pivot_table.show(); } else { this.pivot_table.hide(); - this.get_data().done(function (data) { - self.chart_view.draw(data, mode); - self.chart_view.show(mode); - }); + this.chart_view.set_mode(mode); + this.chart_view.show(); } }, }, - init: function(parent, dataset, view_id, options) { - this._super(parent, dataset, view_id, options); - this.pivot_table = new PivotTable(this); - this.chart_view = new ChartView(this); - this.x_groups = []; - this.measure = null; - this.domain = []; - this.model = null; - this.model_fields = []; - - }, - view_loading: function (fields_view_get) { var self = this; - this.model = new instance.web.Model(fields_view_get.model, {group_by_no_leaf: true}); + var model = new instance.web.Model(fields_view_get.model, {group_by_no_leaf: true}); + var measure = null; + var groupbys = [] // get the default groupbys and measure defined in the field view _.each(fields_view_get.arch.children, function (field) { if ('name' in field.attrs) { if ('operator' in field.attrs) { - self.measure = field.attrs.name; + measure = field.attrs.name; } else { - self.x_groups.push(field.attrs.name); + groupbys.push(field.attrs.name); } } }); - this.chart_view.set_measure(this.measure); - this.pivot_table.appendTo('.graph_main_content'); - this.chart_view.appendTo('.graph_main_content'); - this.chart_view.hide(); - this.get_data().done(this.pivot_table.draw); - - return this.model.call('fields_get', []).then(function (fields) { - self.model_fields = fields; + return model.call('fields_get', []).then(function (fields) { + var view_fields = groupbys.concat(measure); + query_groups(model, view_fields, self.domain, groupbys).done(function (data) { + self.pivot_table = new PivotTable(data, fields, groupbys, measure); + self.chart_view = new ChartView(data, fields, groupbys, measure); + self.pivot_table.appendTo('.graph_main_content') + .done(function () { + self.pivot_table.draw(); + }); + self.chart_view.appendTo('.graph_main_content') + .done(function () { + self.chart_view.hide(); + }); + }); }); }, - get_data: function () { - var view_fields = this.x_groups.concat(this.measure); - - return query_groups(this.model, view_fields, this.domain, this.x_groups); - }, - - get_desc: function(field_id) { - return this.model_fields[field_id].string; - }, - do_search: function (domain, context, group_by) { this.domain = new instance.web.CompoundDomain(domain); }, @@ -99,11 +84,17 @@ instance.web_graph.GraphView = instance.web.View.extend({ }); /** - * PivotTable widget. It displays the data in tabular data and allows the - * user to drill down and up in the table + * BasicDataView widget. Basic widget to manage show/hide functionality + * and to initialize some attributes. It is inherited by PivotTable + * and ChartView widget. */ -var PivotTable = instance.web.Widget.extend({ - template: 'pivot_table', +var BasicDataView = instance.web.Widget.extend({ + init: function (data, fields, groupby, measure) { + this.data = data; + this.fields = fields; + this.groupby = groupby; + this.measure = measure; + }, show: function () { this.$el.css('display', 'block'); @@ -112,9 +103,17 @@ var PivotTable = instance.web.Widget.extend({ hide: function () { this.$el.css('display', 'none'); }, +}); - draw: function (data) { - console.log('data',data); + /** + * PivotTable widget. It displays the data in tabular data and allows the + * user to drill down and up in the table + */ +var PivotTable = BasicDataView.extend({ + template: 'pivot_table', + + draw: function () { + console.log('data',this.data); }, }); @@ -122,35 +121,28 @@ var PivotTable = instance.web.Widget.extend({ * ChartView widget. It displays the data in chart form, using the nvd3 * library. Various modes include bar charts, pie charts or line charts. */ -var ChartView = instance.web.Widget.extend({ +var ChartView = BasicDataView.extend({ template: 'chart_view', - measure: null, + mode: 'bar_chart', - show: function () { - this.$el.css('display', 'block'); - }, - - hide: function () { - this.$el.css('display', 'none'); - }, - - set_measure: function (measure) { - this.measure = measure; + set_mode: function (mode) { + this.mode = mode; + this.draw(); }, - draw: function (data, mode) { + draw: function () { this.$el.empty(); this.$el.append(''); - switch (mode) { + switch (this.mode) { case 'bar_chart': - this.render_bar_chart(data); + this.render_bar_chart(); break; case 'line_chart': - this.render_line_chart(data); + this.render_line_chart(); break; case 'pie_chart': - this.render_pie_chart(data); + this.render_pie_chart(); break; } }, @@ -163,10 +155,10 @@ var ChartView = instance.web.Widget.extend({ }; }, - render_bar_chart: function (data) { + render_bar_chart: function () { var formatted_data = [{ key: 'Bar chart', - values: _.map(data, this.format_data.bind(this)), + values: _.map(this.data, this.format_data.bind(this)), }]; nv.addGraph(function () { @@ -188,12 +180,12 @@ var ChartView = instance.web.Widget.extend({ }); }, - render_line_chart: function (data) { + render_line_chart: function () { var measure_label = (this.measure) ? this.measure : 'Quantity'; var formatted_data = [{ key: measure_label, - values: _.map(data, this.format_data.bind(this)) + values: _.map(this.data, this.format_data.bind(this)) }]; nv.addGraph(function () { @@ -213,8 +205,8 @@ var ChartView = instance.web.Widget.extend({ }); }, - render_pie_chart: function (data) { - var formatted_data = _.map(data, this.format_data.bind(this)); + render_pie_chart: function () { + var formatted_data = _.map(this.data, this.format_data.bind(this)); nv.addGraph(function () { var chart = nv.models.pieChart() -- cgit v1.2.3 From 298a7012bfb1ba3b66bee56d196aa52be7bb2789 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 12 Nov 2013 14:53:44 +0100 Subject: [IMP] add rendering of basic table in pivottable widget (addon web_graph) bzr revid: ged@openerp.com-20131112135344-fi7mwyd49bqnbg69 --- addons/web_graph/static/src/js/graph.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index a36f8f68db0..e8836604324 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -10,6 +10,7 @@ openerp.web_graph = function (instance) { var _lt = instance.web._lt; var _t = instance.web._t; +var QWeb = instance.web.qweb; instance.web.views.add('graph', 'instance.web_graph.GraphView'); @@ -94,6 +95,7 @@ var BasicDataView = instance.web.Widget.extend({ this.fields = fields; this.groupby = groupby; this.measure = measure; + this.measure_label = measure ? fields[measure].string : 'Quantity'; }, show: function () { @@ -113,7 +115,23 @@ var PivotTable = BasicDataView.extend({ template: 'pivot_table', draw: function () { - console.log('data',this.data); + var self = this; + console.log("data",this.data); + + var rows = '' + + this.fields[this.groupby[0]].string + + '' + + this.measure_label + + ''; + _.each(this.data, function (datapt) { + rows += '' + + datapt.attributes.value[1] + + '' + + datapt.attributes.aggregates[self.measure]+ + ''; + }); + + this.$el.append(rows); }, }); @@ -181,10 +199,9 @@ var ChartView = BasicDataView.extend({ }, render_line_chart: function () { - var measure_label = (this.measure) ? this.measure : 'Quantity'; var formatted_data = [{ - key: measure_label, + key: this.measure_label, values: _.map(this.data, this.format_data.bind(this)) }]; -- cgit v1.2.3 From 8eeaca216d796eca53b361dfad364028ef09882e Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 12 Nov 2013 17:10:34 +0100 Subject: [REF] refactoring of addon web_graph. goal is to handle properly the switch of chart view to table view bzr revid: ged@openerp.com-20131112161034-yy80ypm39j32sazv --- addons/web_graph/static/src/js/graph.js | 114 ++++++++++++++++++-------------- 1 file changed, 63 insertions(+), 51 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index e8836604324..44152e45372 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -22,59 +22,72 @@ instance.web_graph.GraphView = instance.web.View.extend({ template: 'GraphView', display_name: _lt('Graph'), view_type: 'graph', + mode: 'pivot', // pivot => display pivot table, chart => display chart events: { 'click .graph_mode_selection li' : function (event) { event.preventDefault(); - var self = this, - mode = event.target.attributes['data-mode'].nodeValue; - if (mode == 'data') { - this.chart_view.hide(); - this.pivot_table.show(); + var view_mode = event.target.attributes['data-mode'].nodeValue; + if (view_mode === 'data') { + this.mode = 'pivot'; } else { - this.pivot_table.hide(); - this.chart_view.set_mode(mode); - this.chart_view.show(); + this.mode = 'chart'; + this.chart_view.set_mode(view_mode); } + this.display_data(); }, }, + display_data : function () { + if (this.mode === 'pivot') { + this.chart_view.hide(); + this.pivot_table.show(); + } else { + this.pivot_table.hide(); + this.chart_view.draw(); + this.chart_view.show(); + } + }, + view_loading: function (fields_view_get) { var self = this; - var model = new instance.web.Model(fields_view_get.model, {group_by_no_leaf: true}); - var measure = null; - var groupbys = [] + this.model = new instance.web.Model(fields_view_get.model, {group_by_no_leaf: true}); + this.measure = null; + this.groupbys = []; // get the default groupbys and measure defined in the field view _.each(fields_view_get.arch.children, function (field) { if ('name' in field.attrs) { if ('operator' in field.attrs) { - measure = field.attrs.name; + self.measure = field.attrs.name; } else { - groupbys.push(field.attrs.name); + self.groupbys.push(field.attrs.name); } } }); - return model.call('fields_get', []).then(function (fields) { - var view_fields = groupbys.concat(measure); - query_groups(model, view_fields, self.domain, groupbys).done(function (data) { - self.pivot_table = new PivotTable(data, fields, groupbys, measure); - self.chart_view = new ChartView(data, fields, groupbys, measure); - self.pivot_table.appendTo('.graph_main_content') - .done(function () { - self.pivot_table.draw(); - }); - self.chart_view.appendTo('.graph_main_content') - .done(function () { - self.chart_view.hide(); - }); - }); + return this.model.call('fields_get', []).then(function (fields) { + self.pivot_table = new PivotTable(fields, self.groupbys, self.measure); + self.chart_view = new ChartView(fields, self.groupbys, self.measure); + self.pivot_table.appendTo('.graph_main_content'); + self.chart_view.appendTo('.graph_main_content'); }); }, + get_data: function () { + var view_fields = this.groupbys.concat(this.measure); + return query_groups(this.model, view_fields, this.domain, this.groupbys); + }, + do_search: function (domain, context, group_by) { + var self = this; this.domain = new instance.web.CompoundDomain(domain); + return this.get_data().done(function (data) { + self.pivot_table.set_data(data); + self.chart_view.set_data(data); + self.pivot_table.draw(); + self.display_data(); + }); }, do_show: function () { @@ -90,12 +103,16 @@ instance.web_graph.GraphView = instance.web.View.extend({ * and ChartView widget. */ var BasicDataView = instance.web.Widget.extend({ - init: function (data, fields, groupby, measure) { - this.data = data; + init: function (fields, groupby, measure) { this.fields = fields; this.groupby = groupby; this.measure = measure; this.measure_label = measure ? fields[measure].string : 'Quantity'; + this.data = []; + }, + + set_data : function (data) { + this.data = data; }, show: function () { @@ -105,6 +122,9 @@ var BasicDataView = instance.web.Widget.extend({ hide: function () { this.$el.css('display', 'none'); }, + + draw: function() { + }, }); /** @@ -115,19 +135,19 @@ var PivotTable = BasicDataView.extend({ template: 'pivot_table', draw: function () { + this.$el.empty(); var self = this; - console.log("data",this.data); - var rows = '' + + var rows = '' + this.fields[this.groupby[0]].string + - '' + + '' + this.measure_label + ''; _.each(this.data, function (datapt) { - rows += '' + + rows += '' + datapt.attributes.value[1] + - '' + - datapt.attributes.aggregates[self.measure]+ + '' + + datapt.attributes.aggregates[self.measure] + ''; }); @@ -141,28 +161,21 @@ var PivotTable = BasicDataView.extend({ */ var ChartView = BasicDataView.extend({ template: 'chart_view', - mode: 'bar_chart', set_mode: function (mode) { - this.mode = mode; - this.draw(); + var render_functions = { + 'bar_chart' : this.render_bar_chart, + 'line_chart' : this.render_line_chart, + 'pie_chart' : this.render_pie_chart, + }; + + this.render = render_functions[mode]; }, draw: function () { this.$el.empty(); this.$el.append(''); - - switch (this.mode) { - case 'bar_chart': - this.render_bar_chart(); - break; - case 'line_chart': - this.render_line_chart(); - break; - case 'pie_chart': - this.render_pie_chart(); - break; - } + this.render(); }, format_data: function (datapt) { @@ -199,7 +212,6 @@ var ChartView = BasicDataView.extend({ }, render_line_chart: function () { - var formatted_data = [{ key: this.measure_label, values: _.map(this.data, this.format_data.bind(this)) -- cgit v1.2.3 From 3c0445479bf5ceaab5bb2b6f201daa787c53bb82 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 13 Nov 2013 10:18:07 +0100 Subject: [REF] move the method displaydata to a better place in addon web_graph bzr revid: ged@openerp.com-20131113091807-cxmc4aaaswdmkfia --- addons/web_graph/static/src/js/graph.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 44152e45372..7ade3843bde 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -38,17 +38,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, }, - display_data : function () { - if (this.mode === 'pivot') { - this.chart_view.hide(); - this.pivot_table.show(); - } else { - this.pivot_table.hide(); - this.chart_view.draw(); - this.chart_view.show(); - } - }, - view_loading: function (fields_view_get) { var self = this; this.model = new instance.web.Model(fields_view_get.model, {group_by_no_leaf: true}); @@ -79,6 +68,17 @@ instance.web_graph.GraphView = instance.web.View.extend({ return query_groups(this.model, view_fields, this.domain, this.groupbys); }, + display_data : function () { + if (this.mode === 'pivot') { + this.chart_view.hide(); + this.pivot_table.show(); + } else { + this.pivot_table.hide(); + this.chart_view.draw(); + this.chart_view.show(); + } + }, + do_search: function (domain, context, group_by) { var self = this; this.domain = new instance.web.CompoundDomain(domain); @@ -138,7 +138,7 @@ var PivotTable = BasicDataView.extend({ this.$el.empty(); var self = this; - var rows = '' + + var rows = ' fa-sort-asc' + this.fields[this.groupby[0]].string + '' + this.measure_label + -- cgit v1.2.3 From 3be25d2c45b6869e30b7ad77413b50bd99f62822 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 13 Nov 2013 10:26:46 +0100 Subject: [IMP] add redraw flag to basicview widget in addon web_graph bzr revid: ged@openerp.com-20131113092646-182veoj027lkbdb6 --- addons/web_graph/static/src/js/graph.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 7ade3843bde..7f83d656059 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -74,7 +74,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.pivot_table.show(); } else { this.pivot_table.hide(); - this.chart_view.draw(); this.chart_view.show(); } }, @@ -85,7 +84,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ return this.get_data().done(function (data) { self.pivot_table.set_data(data); self.chart_view.set_data(data); - self.pivot_table.draw(); self.display_data(); }); }, @@ -103,6 +101,9 @@ instance.web_graph.GraphView = instance.web.View.extend({ * and ChartView widget. */ var BasicDataView = instance.web.Widget.extend({ + + need_redraw: false, + init: function (fields, groupby, measure) { this.fields = fields; this.groupby = groupby; @@ -113,9 +114,14 @@ var BasicDataView = instance.web.Widget.extend({ set_data : function (data) { this.data = data; + this.need_redraw = true; }, show: function () { + if (this.need_redraw) { + this.draw(); + this.need_redraw = false; + } this.$el.css('display', 'block'); }, @@ -170,6 +176,7 @@ var ChartView = BasicDataView.extend({ }; this.render = render_functions[mode]; + this.need_redraw = true; }, draw: function () { -- cgit v1.2.3 From b5af9d421e6aa98ea21b47416cd9dc7391a5e54b Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 13 Nov 2013 11:50:59 +0100 Subject: [IMP] add functionality to basicview widget and rearrange code in addon web_graph bzr revid: ged@openerp.com-20131113105059-1l6th5zcn5wrm3x7 --- addons/web_graph/static/src/js/graph.js | 106 +++++++++++++++++++++----------- 1 file changed, 71 insertions(+), 35 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 7f83d656059..0361cd12e0d 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -2,11 +2,11 @@ * OpenERP web_graph *---------------------------------------------------------*/ -'use strict'; /* jshint undef: false */ openerp.web_graph = function (instance) { +'use strict'; var _lt = instance.web._lt; var _t = instance.web._t; @@ -40,32 +40,30 @@ instance.web_graph.GraphView = instance.web.View.extend({ view_loading: function (fields_view_get) { var self = this; - this.model = new instance.web.Model(fields_view_get.model, {group_by_no_leaf: true}); - this.measure = null; + var model = new instance.web.Model(fields_view_get.model, {group_by_no_leaf: true}); + var measure = null; this.groupbys = []; // get the default groupbys and measure defined in the field view _.each(fields_view_get.arch.children, function (field) { if ('name' in field.attrs) { if ('operator' in field.attrs) { - self.measure = field.attrs.name; + measure = field.attrs.name; } else { self.groupbys.push(field.attrs.name); } } }); - return this.model.call('fields_get', []).then(function (fields) { - self.pivot_table = new PivotTable(fields, self.groupbys, self.measure); - self.chart_view = new ChartView(fields, self.groupbys, self.measure); - self.pivot_table.appendTo('.graph_main_content'); - self.chart_view.appendTo('.graph_main_content'); + return model.call('fields_get', []).then(function (fields) { + self.pivot_table = new PivotTable(model, fields, [], self.groupbys, [], measure); + self.chart_view = new ChartView(model, fields, [], self.groupbys, [], measure); + return self.pivot_table.appendTo('.graph_main_content'); + }).then(function() { + return self.chart_view.appendTo('.graph_main_content'); }); - }, - get_data: function () { - var view_fields = this.groupbys.concat(this.measure); - return query_groups(this.model, view_fields, this.domain, this.groupbys); + }, display_data : function () { @@ -79,13 +77,10 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, do_search: function (domain, context, group_by) { - var self = this; this.domain = new instance.web.CompoundDomain(domain); - return this.get_data().done(function (data) { - self.pivot_table.set_data(data); - self.chart_view.set_data(data); - self.display_data(); - }); + this.pivot_table.set_domain(domain); + this.chart_view.set_domain(domain); + this.display_data(); }, do_show: function () { @@ -104,16 +99,43 @@ var BasicDataView = instance.web.Widget.extend({ need_redraw: false, - init: function (fields, groupby, measure) { + // Input parameters: + // model: model to display + // fields: dictionary returned by field_get on model (desc of model) + // domain: constraints on model records + // row_groupby: groubys on rows (so, row headers in the pivot table) + // col_groupby: idem, but on col + // measure: quantity to display. either a field from the model, or + // null, in which case we use the "count" measure + init: function (model, fields, domain, row_groupby, col_groupby, measure) { + this.model = model; this.fields = fields; - this.groupby = groupby; + this.domain = domain; + this.row_groupby = row_groupby; + this.col_groupby = col_groupby; this.measure = measure; this.measure_label = measure ? fields[measure].string : 'Quantity'; this.data = []; + this.need_redraw = true; }, - set_data : function (data) { - this.data = data; + set_domain: function (domain) { + this.domain = domain; + this.need_redraw = true; + }, + + set_row_groupby: function (row_groupby) { + this.row_groupby = row_groupby; + this.need_redraw = true; + }, + + set_col_groupby: function (col_groupby) { + this.col_groupby = col_groupby; + this.need_redraw = true; + }, + + set_measure: function (measure) { + this.measure = measure; this.need_redraw = true; }, @@ -131,6 +153,12 @@ var BasicDataView = instance.web.Widget.extend({ draw: function() { }, + + get_data: function (groupby) { + var view_fields = this.row_groupby.concat(this.measure, this.col_groupby); + return query_groups(this.model, view_fields, this.domain, groupby); + }, + }); /** @@ -141,24 +169,29 @@ var PivotTable = BasicDataView.extend({ template: 'pivot_table', draw: function () { + this.get_data(this.row_groupby).done(this._draw.bind(this)); + }, + + _draw: function (data) { + console.log("data",data); this.$el.empty(); var self = this; - var rows = ' fa-sort-asc' + - this.fields[this.groupby[0]].string + + var rows = '' + + this.fields[this.row_groupby[0]].string + '' + this.measure_label + ''; - _.each(this.data, function (datapt) { + + _.each(data, function (datapt) { rows += '' + datapt.attributes.value[1] + '' + datapt.attributes.aggregates[self.measure] + ''; }); - this.$el.append(rows); - }, + } }); /** @@ -180,9 +213,12 @@ var ChartView = BasicDataView.extend({ }, draw: function () { + var self = this; this.$el.empty(); this.$el.append(''); - this.render(); + this.get_data(this.row_groupby).done(function (data) { + self.render(data); + }); }, format_data: function (datapt) { @@ -193,10 +229,10 @@ var ChartView = BasicDataView.extend({ }; }, - render_bar_chart: function () { + render_bar_chart: function (data) { var formatted_data = [{ key: 'Bar chart', - values: _.map(this.data, this.format_data.bind(this)), + values: _.map(data, this.format_data.bind(this)), }]; nv.addGraph(function () { @@ -218,10 +254,10 @@ var ChartView = BasicDataView.extend({ }); }, - render_line_chart: function () { + render_line_chart: function (data) { var formatted_data = [{ key: this.measure_label, - values: _.map(this.data, this.format_data.bind(this)) + values: _.map(data, this.format_data.bind(this)) }]; nv.addGraph(function () { @@ -241,8 +277,8 @@ var ChartView = BasicDataView.extend({ }); }, - render_pie_chart: function () { - var formatted_data = _.map(this.data, this.format_data.bind(this)); + render_pie_chart: function (data) { + var formatted_data = _.map(data, this.format_data.bind(this)); nv.addGraph(function () { var chart = nv.models.pieChart() -- cgit v1.2.3 From cecac9a32a786a4bdb5d0e0c8a4847738c7ffc00 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 13 Nov 2013 15:44:24 +0100 Subject: [IMP] improve the rendering of the table in pivottable widget (addon web_graph) bzr revid: ged@openerp.com-20131113144424-8i4ld0fjggw6nled --- addons/web_graph/static/src/js/graph.js | 73 +++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 21 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 0361cd12e0d..f400f76d459 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -167,30 +167,67 @@ var BasicDataView = instance.web.Widget.extend({ */ var PivotTable = BasicDataView.extend({ template: 'pivot_table', + rows: null, + cols: null, draw: function () { - this.get_data(this.row_groupby).done(this._draw.bind(this)); + this.get_data(this.row_groupby) + .then(this.proxy('build_table')) + .done(this.proxy('_draw')); }, - _draw: function (data) { - console.log("data",data); + build_table: function (data) { + var self = this; + function make_cell (content, is_border) { + return '' + content + ''; + } + + this.cols = [{ + path: [], + value: this.measure_label, + expanded: false, + parent: null, + children: [], + html_tds: [], + domain: this.domain, + header: $(make_cell(this.measure_label, true)), + }]; + + this.rows = _.map(data, function (datapt) { + var row = $(''); + row.html(make_cell(datapt.attributes.value[1], true)); + row.append(make_cell(datapt.attributes.aggregates[self.measure])); + + return { + path: [datapt.attributes.grouped_on], + value: datapt.attributes.value[1], + expanded: false, + parent: null, + children: [], + html_tr: row, + domain: datapt.model._domain + }; + }); + }, + + _draw: function () { + this.$el.empty(); var self = this; - var rows = '' + + var header = '' + this.fields[this.row_groupby[0]].string + '' + this.measure_label + ''; + this.$el.append(header); - _.each(data, function (datapt) { - rows += '' + - datapt.attributes.value[1] + - '' + - datapt.attributes.aggregates[self.measure] + - ''; + _.each(this.rows, function (row) { + self.$el.append(row.html_tr); }); - this.$el.append(rows); + } }); @@ -202,13 +239,7 @@ var ChartView = BasicDataView.extend({ template: 'chart_view', set_mode: function (mode) { - var render_functions = { - 'bar_chart' : this.render_bar_chart, - 'line_chart' : this.render_line_chart, - 'pie_chart' : this.render_pie_chart, - }; - - this.render = render_functions[mode]; + this.render = this['render_' + mode]; this.need_redraw = true; }, @@ -232,7 +263,7 @@ var ChartView = BasicDataView.extend({ render_bar_chart: function (data) { var formatted_data = [{ key: 'Bar chart', - values: _.map(data, this.format_data.bind(this)), + values: _.map(data, this.proxy('format_data')), }]; nv.addGraph(function () { @@ -257,7 +288,7 @@ var ChartView = BasicDataView.extend({ render_line_chart: function (data) { var formatted_data = [{ key: this.measure_label, - values: _.map(data, this.format_data.bind(this)) + values: _.map(data, this.proxy('format_data')) }]; nv.addGraph(function () { @@ -278,7 +309,7 @@ var ChartView = BasicDataView.extend({ }, render_pie_chart: function (data) { - var formatted_data = _.map(data, this.format_data.bind(this)); + var formatted_data = _.map(data, this.proxy('format_data')); nv.addGraph(function () { var chart = nv.models.pieChart() -- cgit v1.2.3 From 26e6a496bebb3200c58e37b5e5bb7f167e0f3618 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 13 Nov 2013 16:47:31 +0100 Subject: [IMP] work in progress. goal is to allow expansion of rows/cols in pivottable (addon web_graph) bzr revid: ged@openerp.com-20131113154731-lmhcyajqcf2k4bxt --- addons/web_graph/static/src/js/graph.js | 97 +++++++++++++++++++++++++-------- 1 file changed, 75 insertions(+), 22 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index f400f76d459..bc1040e9df9 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -41,29 +41,62 @@ instance.web_graph.GraphView = instance.web.View.extend({ view_loading: function (fields_view_get) { var self = this; var model = new instance.web.Model(fields_view_get.model, {group_by_no_leaf: true}); - var measure = null; - this.groupbys = []; + var options = {}; + options.domain = []; + options.col_groupby = []; // get the default groupbys and measure defined in the field view + options.measure = null; + options.row_groupby = []; _.each(fields_view_get.arch.children, function (field) { if ('name' in field.attrs) { if ('operator' in field.attrs) { - measure = field.attrs.name; + options.measure = field.attrs.name; } else { - self.groupbys.push(field.attrs.name); + options.row_groupby.push(field.attrs.name); } } }); - return model.call('fields_get', []).then(function (fields) { - self.pivot_table = new PivotTable(model, fields, [], self.groupbys, [], measure); - self.chart_view = new ChartView(model, fields, [], self.groupbys, [], measure); - return self.pivot_table.appendTo('.graph_main_content'); - }).then(function() { - return self.chart_view.appendTo('.graph_main_content'); + // get the most important fields (of the model) by looking at the + // groupby filters defined in the search view + options.important_fields = [] + var load_view = instance.web.fields_view_get({ + model: model, + view_type: 'search', }); + var important_fields_def = $.when(load_view).then(function (search_view) { + var groups = _.select(search_view.arch.children, function (c) { + return (c.tag == 'group') && (c.attrs.string != 'Display'); + }); + _.each(groups, function(g) { + _.each(g.children, function (g) { + if (g.attrs.context) { + var field_id = py.eval(g.attrs.context).group_by; + options.important_fields.push(field_id); + } + }); + }); + }).then + + // get the fields descriptions from the model + var field_descr_def = model.call('fields_get', []) + .then(function (fields) { options.fields = fields; }); + + + return $.when(important_fields_def, field_descr_def) + .then(function () { + self.pivot_table = new PivotTable(model, options); + self.chart_view = new ChartView(model, options); + }) + .then(function () { + return self.pivot_table.appendTo('.graph_main_content') + }) + .then(function() { + return self.chart_view.appendTo('.graph_main_content'); + }); }, display_data : function () { @@ -107,16 +140,17 @@ var BasicDataView = instance.web.Widget.extend({ // col_groupby: idem, but on col // measure: quantity to display. either a field from the model, or // null, in which case we use the "count" measure - init: function (model, fields, domain, row_groupby, col_groupby, measure) { + init: function (model, options) { this.model = model; - this.fields = fields; - this.domain = domain; - this.row_groupby = row_groupby; - this.col_groupby = col_groupby; - this.measure = measure; - this.measure_label = measure ? fields[measure].string : 'Quantity'; + this.fields = options.fields; + this.domain = options.domain; + this.row_groupby = options.row_groupby; + this.col_groupby = options.col_groupby; + this.measure = options.measure; + this.measure_label = options.measure ? options.fields[options.measure].string : 'Quantity'; this.data = []; this.need_redraw = true; + this.important_fields = options.important_fields; }, set_domain: function (domain) { @@ -169,6 +203,20 @@ var PivotTable = BasicDataView.extend({ template: 'pivot_table', rows: null, cols: null, + current_row_id : 0, + + events: { + 'click .graph_border a' : function (event) { + event.preventDefault(); + var row_id = event.target.attributes['data-row-id'].nodeValue; + console.log("clickclick on row ", row_id); + }, + }, + + generate_id: function () { + this.current_row_id += 1; + return this.current_row_id - 1; + }, draw: function () { this.get_data(this.row_groupby) @@ -196,19 +244,24 @@ var PivotTable = BasicDataView.extend({ }]; this.rows = _.map(data, function (datapt) { - var row = $(''); - row.html(make_cell(datapt.attributes.value[1], true)); - row.append(make_cell(datapt.attributes.aggregates[self.measure])); + var jquery_row = $(''); + var header = $(make_cell(datapt.attributes.value[1], true)); + var row_id = self.generate_id(); + + header.prepend('+ '); + jquery_row.html(header); + jquery_row.append(make_cell(datapt.attributes.aggregates[self.measure])); - return { + var row = { path: [datapt.attributes.grouped_on], value: datapt.attributes.value[1], expanded: false, parent: null, children: [], - html_tr: row, + html_tr: jquery_row, domain: datapt.model._domain }; + return row; }); }, -- cgit v1.2.3 From 4f448f36317eab36e332544a1463c85c3abaa740 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 14 Nov 2013 11:34:46 +0100 Subject: [IMP] work in progress. goal is to allow expansion of rows/cols in pivottable (addon web_graph) bzr revid: ged@openerp.com-20131114103446-qpqs3j0i8yhbvbg3 --- addons/web_graph/static/src/js/graph.js | 81 +++++++++++++++++++++++++++------ 1 file changed, 67 insertions(+), 14 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index bc1040e9df9..e1c20281bd0 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -60,7 +60,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ // get the most important fields (of the model) by looking at the // groupby filters defined in the search view - options.important_fields = [] + options.important_fields = []; var load_view = instance.web.fields_view_get({ model: model, view_type: 'search', @@ -79,7 +79,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ } }); }); - }).then + }); // get the fields descriptions from the model var field_descr_def = model.call('fields_get', []) @@ -92,7 +92,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ self.chart_view = new ChartView(model, options); }) .then(function () { - return self.pivot_table.appendTo('.graph_main_content') + return self.pivot_table.appendTo('.graph_main_content'); }) .then(function() { return self.chart_view.appendTo('.graph_main_content'); @@ -153,6 +153,10 @@ var BasicDataView = instance.web.Widget.extend({ this.important_fields = options.important_fields; }, + get_descr: function (field_id) { + return this.fields[field_id].string; + }, + set_domain: function (domain) { this.domain = domain; this.need_redraw = true; @@ -206,18 +210,70 @@ var PivotTable = BasicDataView.extend({ current_row_id : 0, events: { - 'click .graph_border a' : function (event) { + 'click .graph_border > a' : function (event) { + var self = this; event.preventDefault(); + + var dropdown_options = { + fields: _.map(this.important_fields, function (field) { + return {id: field, value: self.fields[field].string}; + }), + row_id: event.target.attributes['data-row-id'].nodeValue, + }; + + this.dropdown = $(QWeb.render('field_selection', dropdown_options)); + + $(event.target).after(this.dropdown); + $('.field-selection').next('.dropdown-menu').toggle(); + }, + 'click a.field-selection' : function (event) { + event.preventDefault(); + this.dropdown.remove(); var row_id = event.target.attributes['data-row-id'].nodeValue; - console.log("clickclick on row ", row_id); + var field_id = event.target.attributes['data-field-id'].nodeValue; + this.expand_row(row_id, field_id); }, }, + init: function (model, options) { + this._super(model, options); + }, + generate_id: function () { this.current_row_id += 1; return this.current_row_id - 1; }, + get_row: function (id) { + return _.find(this.rows, function(row) { + return (row.id == id); + }); + }, + + make_cell: function (content, is_border) { + return '' + content + ''; + }, + + expand_row: function (row_id, field_id) { + var row = this.get_row(row_id); + this.row_groupby.push(field_id); + var visible_fields = this.row_groupby.concat(this.col_groupby, this.measure); + + console.log("model",this.model); + console.log("vf",visible_fields); + console.log("domain",row.domain); + console.log("gb",this.row_groupby); + + query_groups(this.model, visible_fields, row.domain, [field_id]) + .then(function (data) { + console.log("datapt",data); + }); + + }, +// function query_groups (model, fields, domain, groupbys) { + draw: function () { this.get_data(this.row_groupby) .then(this.proxy('build_table')) @@ -226,11 +282,7 @@ var PivotTable = BasicDataView.extend({ build_table: function (data) { var self = this; - function make_cell (content, is_border) { - return '' + content + ''; - } + this.cols = [{ path: [], @@ -240,26 +292,27 @@ var PivotTable = BasicDataView.extend({ children: [], html_tds: [], domain: this.domain, - header: $(make_cell(this.measure_label, true)), + header: $(this.make_cell(this.measure_label, true)), }]; this.rows = _.map(data, function (datapt) { var jquery_row = $(''); - var header = $(make_cell(datapt.attributes.value[1], true)); + var header = $(self.make_cell(datapt.attributes.value[1], true)); var row_id = self.generate_id(); header.prepend('+ '); jquery_row.html(header); - jquery_row.append(make_cell(datapt.attributes.aggregates[self.measure])); + jquery_row.append(self.make_cell(datapt.attributes.aggregates[self.measure])); var row = { + id: row_id, path: [datapt.attributes.grouped_on], value: datapt.attributes.value[1], expanded: false, parent: null, children: [], html_tr: jquery_row, - domain: datapt.model._domain + domain: datapt.model._domain, }; return row; }); -- cgit v1.2.3 From a38ab9c56c7316dc8984fb80474339e3d7c81e89 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 14 Nov 2013 14:17:47 +0100 Subject: [IMP] work in progress. goal is to allow expansion of rows/cols in pivottable (addon web_graph) bzr revid: ged@openerp.com-20131114131747-mq8uh02iplc0xmer --- addons/web_graph/static/src/js/graph.js | 97 +++++++++++++++++++++------------ 1 file changed, 62 insertions(+), 35 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index e1c20281bd0..f7670ab7b60 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -205,8 +205,8 @@ var BasicDataView = instance.web.Widget.extend({ */ var PivotTable = BasicDataView.extend({ template: 'pivot_table', - rows: null, - cols: null, + rows: [], + cols: [], current_row_id : 0, events: { @@ -250,29 +250,74 @@ var PivotTable = BasicDataView.extend({ }); }, - make_cell: function (content, is_border) { - return '' + content + ''; + make_cell: function (content, options) { + var attrs = [''); + if (options && options.indent) { + _.each(_.range(options.indent), function () { + attrs.push(''); + }); + } + return attrs.join(' ') + content + ''; + }, + + make_row: function (data, parent_id) { + var has_parent = (parent_id !== undefined); + var parent = has_parent ? this.get_row(parent_id) : null; + var path = has_parent ? parent.path.concat(data.attributes.grouped_on) + : [data.attributes.grouped_on]; + + + var indent_level = has_parent ? parent.path.length : 0; + + + var jquery_row = $(''); + var header = $(this.make_cell(data.attributes.value[1], {is_border:true, indent: indent_level})); + var row_id = this.generate_id(); + + header.prepend('+ '); + jquery_row.html(header); + jquery_row.append(this.make_cell(data.attributes.aggregates[this.measure])); + + var row = { + id: row_id, + path: path, + value: data.attributes.value[1], + expanded: false, + parent: parent_id, + children: [], + html_tr: jquery_row, + domain: data.model._domain, + }; + this.rows.push(row); // to do, insert it properly + + if (has_parent) { + parent.children.push(row); + } + return row; }, expand_row: function (row_id, field_id) { + var self = this; var row = this.get_row(row_id); this.row_groupby.push(field_id); var visible_fields = this.row_groupby.concat(this.col_groupby, this.measure); - console.log("model",this.model); - console.log("vf",visible_fields); - console.log("domain",row.domain); - console.log("gb",this.row_groupby); - query_groups(this.model, visible_fields, row.domain, [field_id]) .then(function (data) { - console.log("datapt",data); + _.each(data, function (datapt) { + + var new_row = self.make_row(datapt, row_id); + row.html_tr.after(new_row.html_tr); + }); + row.expanded = true; }); }, -// function query_groups (model, fields, domain, groupbys) { draw: function () { this.get_data(this.row_groupby) @@ -292,31 +337,13 @@ var PivotTable = BasicDataView.extend({ children: [], html_tds: [], domain: this.domain, - header: $(this.make_cell(this.measure_label, true)), + header: $(this.make_cell(this.measure_label, {is_border:true})), }]; - this.rows = _.map(data, function (datapt) { - var jquery_row = $(''); - var header = $(self.make_cell(datapt.attributes.value[1], true)); - var row_id = self.generate_id(); - - header.prepend('+ '); - jquery_row.html(header); - jquery_row.append(self.make_cell(datapt.attributes.aggregates[self.measure])); - - var row = { - id: row_id, - path: [datapt.attributes.grouped_on], - value: datapt.attributes.value[1], - expanded: false, - parent: null, - children: [], - html_tr: jquery_row, - domain: datapt.model._domain, - }; - return row; + _.each(data, function (datapt) { + self.make_row(datapt); }); - }, + }, _draw: function () { -- cgit v1.2.3 From 3c16fd11320fbc381855474116f90cddb7fb44be Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 14 Nov 2013 15:00:15 +0100 Subject: [IMP] allows expansion of rows in pivottable (addon web_graph) bzr revid: ged@openerp.com-20131114140015-h1hqzl5a70921vkq --- addons/web_graph/static/src/js/graph.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index f7670ab7b60..1c3ebd74075 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -262,6 +262,9 @@ var PivotTable = BasicDataView.extend({ attrs.push(''); }); } + if (options && options.foldable) { + attrs.push(' '); + } return attrs.join(' ') + content + ''; }, @@ -276,10 +279,9 @@ var PivotTable = BasicDataView.extend({ var jquery_row = $(''); - var header = $(this.make_cell(data.attributes.value[1], {is_border:true, indent: indent_level})); var row_id = this.generate_id(); - header.prepend('+ '); + var header = $(this.make_cell(data.attributes.value[1], {is_border:true, indent: indent_level, foldable:true, row_id: row_id})); jquery_row.html(header); jquery_row.append(this.make_cell(data.attributes.aggregates[this.measure])); @@ -315,6 +317,12 @@ var PivotTable = BasicDataView.extend({ row.html_tr.after(new_row.html_tr); }); row.expanded = true; + console.log("tr",row.html_tr); + var icon = row.html_tr.find('.icon-caret-right'); + icon.removeClass('icon-caret-right') + .addClass('icon-caret-down'); + console.log("icon",icon); + // console.log("nrst",); }); }, -- cgit v1.2.3 From 3e607e8e3c9809a4279d96727a46887eebeeb69c Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 14 Nov 2013 15:07:33 +0100 Subject: [IMP] changes triangle icon into + and - signs icon in pivot table (addon web_graph) bzr revid: ged@openerp.com-20131114140733-9jyvttydbb2gm5jv --- addons/web_graph/static/src/js/graph.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 1c3ebd74075..46c739121f9 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -263,7 +263,7 @@ var PivotTable = BasicDataView.extend({ }); } if (options && options.foldable) { - attrs.push(' '); + attrs.push(' '); } return attrs.join(' ') + content + ''; }, @@ -312,17 +312,13 @@ var PivotTable = BasicDataView.extend({ query_groups(this.model, visible_fields, row.domain, [field_id]) .then(function (data) { _.each(data, function (datapt) { - var new_row = self.make_row(datapt, row_id); row.html_tr.after(new_row.html_tr); }); row.expanded = true; - console.log("tr",row.html_tr); - var icon = row.html_tr.find('.icon-caret-right'); - icon.removeClass('icon-caret-right') - .addClass('icon-caret-down'); - console.log("icon",icon); - // console.log("nrst",); + var icon = row.html_tr.find('.icon-plus-sign'); + icon.removeClass('icon-plus-sign') + .addClass('icon-minus-sign'); }); }, -- cgit v1.2.3 From ba5de8088bf0448a6c015ccf0292decbc03c760c Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 14 Nov 2013 16:33:48 +0100 Subject: [IMP] allows the user to clear the groupbys in pivottable (addon web_graph) bzr revid: ged@openerp.com-20131114153348-bux7ldhkhe1jl29e --- addons/web_graph/static/src/js/graph.js | 69 ++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 13 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 46c739121f9..ffc773f1c3e 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -36,6 +36,9 @@ instance.web_graph.GraphView = instance.web.View.extend({ } this.display_data(); }, + 'click .graph_clear_groups' : function (event) { + this.pivot_table.clear_groups(); + }, }, view_loading: function (fields_view_get) { @@ -216,7 +219,7 @@ var PivotTable = BasicDataView.extend({ var dropdown_options = { fields: _.map(this.important_fields, function (field) { - return {id: field, value: self.fields[field].string}; + return {id: field, value: self.get_descr(field)}; }), row_id: event.target.attributes['data-row-id'].nodeValue, }; @@ -235,6 +238,14 @@ var PivotTable = BasicDataView.extend({ }, }, + clear_groups: function () { + this.row_groupby = []; + this.col_groupby = []; + this.rows = []; + this.cols = []; + this.draw(); + }, + init: function (model, options) { this._super(model, options); }, @@ -271,24 +282,31 @@ var PivotTable = BasicDataView.extend({ make_row: function (data, parent_id) { var has_parent = (parent_id !== undefined); var parent = has_parent ? this.get_row(parent_id) : null; - var path = has_parent ? parent.path.concat(data.attributes.grouped_on) - : [data.attributes.grouped_on]; - + var path; + if (has_parent) { + console.log("parent",parent); + path = parent.path.concat(data.attributes.grouped_on); + } else if (data.attributes.grouped_on !== undefined) { + path = [data.attributes.grouped_on]; + } else { + path = []; + } var indent_level = has_parent ? parent.path.length : 0; + var value = (this.row_groupby.length > 0) ? data.attributes.value[1] : "Total"; var jquery_row = $(''); var row_id = this.generate_id(); - var header = $(this.make_cell(data.attributes.value[1], {is_border:true, indent: indent_level, foldable:true, row_id: row_id})); + var header = $(this.make_cell(value, {is_border:true, indent: indent_level, foldable:true, row_id: row_id})); jquery_row.html(header); jquery_row.append(this.make_cell(data.attributes.aggregates[this.measure])); var row = { id: row_id, path: path, - value: data.attributes.value[1], + value: value, expanded: false, parent: parent_id, children: [], @@ -297,6 +315,9 @@ var PivotTable = BasicDataView.extend({ }; this.rows.push(row); // to do, insert it properly + if (this.row_groupby.length === 0) { + row.remove_when_expanded = true; + } if (has_parent) { parent.children.push(row); } @@ -307,18 +328,31 @@ var PivotTable = BasicDataView.extend({ var self = this; var row = this.get_row(row_id); this.row_groupby.push(field_id); + var visible_fields = this.row_groupby.concat(this.col_groupby, this.measure); + if (row.remove_when_expanded) { + this.rows = []; + row.html_tr.remove(); + } else { + row.expanded = true; + row.html_tr.find('.icon-plus-sign') + .removeClass('icon-plus-sign') + .addClass('icon-minus-sign'); + } + query_groups(this.model, visible_fields, row.domain, [field_id]) .then(function (data) { _.each(data, function (datapt) { - var new_row = self.make_row(datapt, row_id); - row.html_tr.after(new_row.html_tr); + var new_row; + if (row.remove_when_expanded) { + new_row = self.make_row(datapt); + self.$('tr.graph_table_header').after(new_row.html_tr); + } else { + new_row = self.make_row(datapt, row_id); + row.html_tr.after(new_row.html_tr); + } }); - row.expanded = true; - var icon = row.html_tr.find('.icon-plus-sign'); - icon.removeClass('icon-plus-sign') - .addClass('icon-minus-sign'); }); }, @@ -332,6 +366,7 @@ var PivotTable = BasicDataView.extend({ build_table: function (data) { var self = this; + console.log("data",data); this.cols = [{ path: [], @@ -353,12 +388,20 @@ var PivotTable = BasicDataView.extend({ this.$el.empty(); var self = this; + var header; - var header = '' + + if (this.row_groupby.length > 0) { + header = '' + this.fields[this.row_groupby[0]].string + '' + this.measure_label + ''; + } else { + header = '' + + '' + + this.measure_label + + ''; + } this.$el.append(header); _.each(this.rows, function (row) { -- cgit v1.2.3 From 2216a699087c790182bd34227d3d1d4554131b9d Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 14 Nov 2013 17:31:07 +0100 Subject: [IMP] many usability fixes in pivottable drill down and up (addon web_graph) bzr revid: ged@openerp.com-20131114163107-pm3s3siwtzqn98jy --- addons/web_graph/static/src/js/graph.js | 43 +++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 16 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index ffc773f1c3e..3ab9b034ea1 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -216,18 +216,24 @@ var PivotTable = BasicDataView.extend({ 'click .graph_border > a' : function (event) { var self = this; event.preventDefault(); + var row_id = event.target.attributes['data-row-id'].nodeValue; - var dropdown_options = { - fields: _.map(this.important_fields, function (field) { - return {id: field, value: self.get_descr(field)}; - }), - row_id: event.target.attributes['data-row-id'].nodeValue, - }; - - this.dropdown = $(QWeb.render('field_selection', dropdown_options)); + var row = this.get_row(row_id); + if (row.expanded) { + this.fold_row(row_id) + } else { + var dropdown_options = { + fields: _.map(this.important_fields, function (field) { + return {id: field, value: self.get_descr(field)}; + }), + row_id: row_id, + }; + this.dropdown = $(QWeb.render('field_selection', dropdown_options)); + $(event.target).after(this.dropdown); + $('.field-selection').next('.dropdown-menu').toggle(); + } - $(event.target).after(this.dropdown); - $('.field-selection').next('.dropdown-menu').toggle(); + }, 'click a.field-selection' : function (event) { event.preventDefault(); @@ -284,7 +290,6 @@ var PivotTable = BasicDataView.extend({ var parent = has_parent ? this.get_row(parent_id) : null; var path; if (has_parent) { - console.log("parent",parent); path = parent.path.concat(data.attributes.grouped_on); } else if (data.attributes.grouped_on !== undefined) { path = [data.attributes.grouped_on]; @@ -293,7 +298,7 @@ var PivotTable = BasicDataView.extend({ } var indent_level = has_parent ? parent.path.length : 0; - var value = (this.row_groupby.length > 0) ? data.attributes.value[1] : "Total"; + var value = (this.row_groupby.length > 0) ? data.attributes.value[1] : 'Total'; var jquery_row = $(''); @@ -313,10 +318,12 @@ var PivotTable = BasicDataView.extend({ html_tr: jquery_row, domain: data.model._domain, }; + // rows.splice(index of parent if any,0,row); this.rows.push(row); // to do, insert it properly if (this.row_groupby.length === 0) { row.remove_when_expanded = true; + row.domain = this.domain; } if (has_parent) { parent.children.push(row); @@ -333,7 +340,6 @@ var PivotTable = BasicDataView.extend({ if (row.remove_when_expanded) { this.rows = []; - row.html_tr.remove(); } else { row.expanded = true; row.html_tr.find('.icon-plus-sign') @@ -343,7 +349,7 @@ var PivotTable = BasicDataView.extend({ query_groups(this.model, visible_fields, row.domain, [field_id]) .then(function (data) { - _.each(data, function (datapt) { + _.each(data.reverse(), function (datapt) { var new_row; if (row.remove_when_expanded) { new_row = self.make_row(datapt); @@ -353,10 +359,17 @@ var PivotTable = BasicDataView.extend({ row.html_tr.after(new_row.html_tr); } }); + if (row.remove_when_expanded) { + row.html_tr.remove(); + } }); }, + fold_row: function (row_id) { + + }, + draw: function () { this.get_data(this.row_groupby) .then(this.proxy('build_table')) @@ -366,8 +379,6 @@ var PivotTable = BasicDataView.extend({ build_table: function (data) { var self = this; - console.log("data",data); - this.cols = [{ path: [], value: this.measure_label, -- cgit v1.2.3 From 2609105d41cfd7ef798a87c161e84eaf0092e2f1 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 15 Nov 2013 09:50:37 +0100 Subject: [IMP] allow pivottable to fold rows (addon web_graph) bzr revid: ged@openerp.com-20131115085037-nhbi5x9ooa75drnk --- addons/web_graph/static/src/js/graph.js | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 3ab9b034ea1..efde4315b29 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -220,7 +220,7 @@ var PivotTable = BasicDataView.extend({ var row = this.get_row(row_id); if (row.expanded) { - this.fold_row(row_id) + this.fold_row(row_id); } else { var dropdown_options = { fields: _.map(this.important_fields, function (field) { @@ -326,7 +326,7 @@ var PivotTable = BasicDataView.extend({ row.domain = this.domain; } if (has_parent) { - parent.children.push(row); + parent.children.push(row.id); } return row; }, @@ -360,14 +360,37 @@ var PivotTable = BasicDataView.extend({ } }); if (row.remove_when_expanded) { - row.html_tr.remove(); + row.html_tr.remove(); } }); }, fold_row: function (row_id) { + var self = this; + var row = this.get_row(row_id); + + _.each(row.children, function (child_row) { + self.remove_row(child_row); + }); + row.children = []; + + row.expanded = false; + row.html_tr.find('.icon-minus-sign') + .removeClass('icon-minus-sign') + .addClass('icon-plus-sign');; + + }, + + remove_row: function (row_id) { + var self = this; + var row = this.get_row(row_id); + + _.each(row.children, function (child_row) { + self.remove_row(child_row); + }); + row.html_tr.remove(); }, draw: function () { -- cgit v1.2.3 From fecfa8e52cdaca9925c32945da0d5638a6802c1b Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 15 Nov 2013 10:24:11 +0100 Subject: [IMP] makes display smarter list of options in dropdown menu on pivottable widget (addon web_graph) bzr revid: ged@openerp.com-20131115092411-abnckphk4mn9ji3z --- addons/web_graph/static/src/js/graph.js | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index efde4315b29..875a34aa92f 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -222,15 +222,22 @@ var PivotTable = BasicDataView.extend({ if (row.expanded) { this.fold_row(row_id); } else { - var dropdown_options = { - fields: _.map(this.important_fields, function (field) { - return {id: field, value: self.get_descr(field)}; - }), - row_id: row_id, - }; - this.dropdown = $(QWeb.render('field_selection', dropdown_options)); - $(event.target).after(this.dropdown); - $('.field-selection').next('.dropdown-menu').toggle(); + if (row.path.length < this.row_groupby.length) { + var field_to_expand = this.row_groupby[row.path.length]; + this.expand_row(row_id, field_to_expand); + } else { + var already_grouped = self.row_groupby.concat(self.col_groupby); + var possible_groups = _.difference(self.important_fields, already_grouped); + var dropdown_options = { + fields: _.map(possible_groups, function (field) { + return {id: field, value: self.get_descr(field)}; + }), + row_id: row_id, + }; + this.dropdown = $(QWeb.render('field_selection', dropdown_options)); + $(event.target).after(this.dropdown); + $('.field-selection').next('.dropdown-menu').toggle(); + } } @@ -334,7 +341,10 @@ var PivotTable = BasicDataView.extend({ expand_row: function (row_id, field_id) { var self = this; var row = this.get_row(row_id); - this.row_groupby.push(field_id); + + if (row.path.length == this.row_groupby.length) { + this.row_groupby.push(field_id); + } var visible_fields = this.row_groupby.concat(this.col_groupby, this.measure); -- cgit v1.2.3 From 75caaeb1a39cea51b05e41c3f5db1fe904f64f43 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 15 Nov 2013 12:19:32 +0100 Subject: [IMP] smarter behavior when unfolding/refolding: check 'unfolding' level and do not ask what field to expand if it already knows (addon web_graph) bzr revid: ged@openerp.com-20131115111932-rdphi3w01nmein7t --- addons/web_graph/static/src/js/graph.js | 61 +++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 21 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 875a34aa92f..93e8d72cfe8 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -144,11 +144,15 @@ var BasicDataView = instance.web.Widget.extend({ // measure: quantity to display. either a field from the model, or // null, in which case we use the "count" measure init: function (model, options) { + var self = this; this.model = model; this.fields = options.fields; this.domain = options.domain; - this.row_groupby = options.row_groupby; - this.col_groupby = options.col_groupby; + this.groupby = { + row: options.row_groupby, + col: options.col_groupby, + }; + this.measure = options.measure; this.measure_label = options.measure ? options.fields[options.measure].string : 'Quantity'; this.data = []; @@ -166,12 +170,12 @@ var BasicDataView = instance.web.Widget.extend({ }, set_row_groupby: function (row_groupby) { - this.row_groupby = row_groupby; + this.groupby.row = row_groupby; this.need_redraw = true; }, set_col_groupby: function (col_groupby) { - this.col_groupby = col_groupby; + this.groupby.col = col_groupby; this.need_redraw = true; }, @@ -196,7 +200,7 @@ var BasicDataView = instance.web.Widget.extend({ }, get_data: function (groupby) { - var view_fields = this.row_groupby.concat(this.measure, this.col_groupby); + var view_fields = this.groupby.row.concat(this.measure, this.groupby.col); return query_groups(this.model, view_fields, this.domain, groupby); }, @@ -222,11 +226,11 @@ var PivotTable = BasicDataView.extend({ if (row.expanded) { this.fold_row(row_id); } else { - if (row.path.length < this.row_groupby.length) { - var field_to_expand = this.row_groupby[row.path.length]; + if (row.path.length < this.groupby.row.length) { + var field_to_expand = this.groupby.row[row.path.length]; this.expand_row(row_id, field_to_expand); } else { - var already_grouped = self.row_groupby.concat(self.col_groupby); + var already_grouped = self.groupby.row.concat(self.groupby.col); var possible_groups = _.difference(self.important_fields, already_grouped); var dropdown_options = { fields: _.map(possible_groups, function (field) { @@ -252,8 +256,8 @@ var PivotTable = BasicDataView.extend({ }, clear_groups: function () { - this.row_groupby = []; - this.col_groupby = []; + this.groupby.row = []; + this.groupby.col = []; this.rows = []; this.cols = []; this.draw(); @@ -305,7 +309,7 @@ var PivotTable = BasicDataView.extend({ } var indent_level = has_parent ? parent.path.length : 0; - var value = (this.row_groupby.length > 0) ? data.attributes.value[1] : 'Total'; + var value = (this.groupby.row.length > 0) ? data.attributes.value[1] : 'Total'; var jquery_row = $(''); @@ -328,7 +332,7 @@ var PivotTable = BasicDataView.extend({ // rows.splice(index of parent if any,0,row); this.rows.push(row); // to do, insert it properly - if (this.row_groupby.length === 0) { + if (this.groupby.row.length === 0) { row.remove_when_expanded = true; row.domain = this.domain; } @@ -342,11 +346,11 @@ var PivotTable = BasicDataView.extend({ var self = this; var row = this.get_row(row_id); - if (row.path.length == this.row_groupby.length) { - this.row_groupby.push(field_id); + if (row.path.length == this.groupby.row.length) { + this.groupby.row.push(field_id); } - var visible_fields = this.row_groupby.concat(this.col_groupby, this.measure); + var visible_fields = this.groupby.row.concat(this.groupby.col, this.measure); if (row.remove_when_expanded) { this.rows = []; @@ -381,15 +385,21 @@ var PivotTable = BasicDataView.extend({ var row = this.get_row(row_id); _.each(row.children, function (child_row) { - self.remove_row(child_row); + self.remove_row(child_row); }); row.children = []; row.expanded = false; row.html_tr.find('.icon-minus-sign') .removeClass('icon-minus-sign') - .addClass('icon-plus-sign');; + .addClass('icon-plus-sign'); + var fold_levels = _.map(self.rows, function(g) {return g.path.length;}); + var new_groupby_length = _.reduce(fold_levels, function (x, y) { + return Math.max(x,y); + }, 0); + + this.groupby.row.splice(new_groupby_length); }, remove_row: function (row_id) { @@ -401,10 +411,11 @@ var PivotTable = BasicDataView.extend({ }); row.html_tr.remove(); + removeFromArray(this.rows, row); }, draw: function () { - this.get_data(this.row_groupby) + this.get_data(this.groupby.row) .then(this.proxy('build_table')) .done(this.proxy('_draw')); }, @@ -434,9 +445,9 @@ var PivotTable = BasicDataView.extend({ var self = this; var header; - if (this.row_groupby.length > 0) { + if (this.groupby.row.length > 0) { header = '' + - this.fields[this.row_groupby[0]].string + + this.fields[this.groupby.row[0]].string + '' + this.measure_label + ''; @@ -471,7 +482,7 @@ var ChartView = BasicDataView.extend({ var self = this; this.$el.empty(); this.$el.append(''); - this.get_data(this.row_groupby).done(function (data) { + this.get_data(this.groupby.row).done(function (data) { self.render(data); }); }, @@ -555,6 +566,14 @@ var ChartView = BasicDataView.extend({ }); +// utility +function removeFromArray(array, element) { + var index = array.indexOf(element); + if (index > -1) { + array.splice(index, 1); + } +} + /** * Query the server and return a deferred which will return the data * with all the groupbys applied (this is done for now, but the goal -- cgit v1.2.3 From 776a57ef0cda65ce03f60d9f5bf3d466225dd4b2 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 15 Nov 2013 12:26:59 +0100 Subject: [FIX] fixes a bug where the view build a table without clearing the existing rows (addon web_graph) bzr revid: ged@openerp.com-20131115112659-mzb4smcr85dq60ww --- addons/web_graph/static/src/js/graph.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 93e8d72cfe8..5a4ff51f2d4 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -144,6 +144,7 @@ var BasicDataView = instance.web.Widget.extend({ // measure: quantity to display. either a field from the model, or // null, in which case we use the "count" measure init: function (model, options) { + console.log("initializing", model, options); var self = this; this.model = model; this.fields = options.fields; @@ -422,6 +423,7 @@ var PivotTable = BasicDataView.extend({ build_table: function (data) { var self = this; + this.rows = []; this.cols = [{ path: [], -- cgit v1.2.3 From ab1411aa9eaedc8ef569aaa660cf7a3584f3ef30 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 15 Nov 2013 13:13:15 +0100 Subject: [IMP] makes the text clickable in clickable cells in pivottable (addon web_graph) bzr revid: ged@openerp.com-20131115121315-2lb0mptvv44g8xjk --- addons/web_graph/static/src/js/graph.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 5a4ff51f2d4..9f94f5eb0ee 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -144,7 +144,6 @@ var BasicDataView = instance.web.Widget.extend({ // measure: quantity to display. either a field from the model, or // null, in which case we use the "count" measure init: function (model, options) { - console.log("initializing", model, options); var self = this; this.model = model; this.fields = options.fields; @@ -218,7 +217,7 @@ var PivotTable = BasicDataView.extend({ current_row_id : 0, events: { - 'click .graph_border > a' : function (event) { + 'click .web_graph_click' : function (event) { var self = this; event.preventDefault(); var row_id = event.target.attributes['data-row-id'].nodeValue; @@ -241,6 +240,9 @@ var PivotTable = BasicDataView.extend({ }; this.dropdown = $(QWeb.render('field_selection', dropdown_options)); $(event.target).after(this.dropdown); + this.dropdown.css({position:"absolute", + left:event.pageX, + top:event.pageY}); $('.field-selection').next('.dropdown-menu').toggle(); } } @@ -292,9 +294,18 @@ var PivotTable = BasicDataView.extend({ }); } if (options && options.foldable) { - attrs.push(' '); + attrs.push(''); } - return attrs.join(' ') + content + ''; + if (content) { + attrs.push(content); + } else { + attrs.push('Undefined'); + } + if (options && options.foldable) { + attrs.push(''); + } + attrs.push(''); + return attrs.join(' '); }, make_row: function (data, parent_id) { -- cgit v1.2.3 From b08a38c5286ddca7945ed73938e53b0d7e98dbd2 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 15 Nov 2013 16:16:59 +0100 Subject: [REF] refactoring in progress. moves charts to its own file in addon web_graph bzr revid: ged@openerp.com-20131115151659-g1lc0ypd9v3cxg1p --- addons/web_graph/static/src/js/graph.js | 131 ++++++++------------------------ 1 file changed, 32 insertions(+), 99 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 9f94f5eb0ee..ccec8f03ec3 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -126,6 +126,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ }); + + /** * BasicDataView widget. Basic widget to manage show/hide functionality * and to initialize some attributes. It is inherited by PivotTable @@ -206,6 +208,35 @@ var BasicDataView = instance.web.Widget.extend({ }); + + + /** + * ChartView widget. It displays the data in chart form, using the nvd3 + * library. Various modes include bar charts, pie charts or line charts. + */ +var ChartView = BasicDataView.extend({ + template: 'chart_view', + + set_mode: function (mode) { + this.mode = mode; + console.log("mode",mode); + this.render = this['render_' + mode]; + this.need_redraw = true; + }, + + draw: function () { + var self = this; + this.$el.empty(); + console.log("measrue",self.measure); + this.$el.append(''); + this.get_data(this.groupby.row).done(function (data) { + Charts[self.mode](data, self.measure, self.measure_label); + }); + }, + + + +}); /** * PivotTable widget. It displays the data in tabular data and allows the * user to drill down and up in the table @@ -479,106 +510,8 @@ var PivotTable = BasicDataView.extend({ } }); - /** - * ChartView widget. It displays the data in chart form, using the nvd3 - * library. Various modes include bar charts, pie charts or line charts. - */ -var ChartView = BasicDataView.extend({ - template: 'chart_view', - - set_mode: function (mode) { - this.render = this['render_' + mode]; - this.need_redraw = true; - }, - - draw: function () { - var self = this; - this.$el.empty(); - this.$el.append(''); - this.get_data(this.groupby.row).done(function (data) { - self.render(data); - }); - }, - - format_data: function (datapt) { - var val = datapt.attributes; - return { - x: datapt.attributes.value[1], - y: this.measure ? val.aggregates[this.measure] : val.length, - }; - }, - - render_bar_chart: function (data) { - var formatted_data = [{ - key: 'Bar chart', - values: _.map(data, this.proxy('format_data')), - }]; - - nv.addGraph(function () { - var chart = nv.models.discreteBarChart() - .tooltips(false) - .showValues(true) - .staggerLabels(true) - .width(650) - .height(400); - - d3.select('.graph_chart svg') - .datum(formatted_data) - .attr('width', 650) - .attr('height', 400) - .call(chart); - - nv.utils.windowResize(chart.update); - return chart; - }); - }, - - render_line_chart: function (data) { - var formatted_data = [{ - key: this.measure_label, - values: _.map(data, this.proxy('format_data')) - }]; - - nv.addGraph(function () { - var chart = nv.models.lineChart() - .x(function (d,u) { return u; }) - .width(600) - .height(300) - .margin({top: 30, right: 20, bottom: 20, left: 60}); - - d3.select('.graph_chart svg') - .attr('width', 600) - .attr('height', 300) - .datum(formatted_data) - .call(chart); - - return chart; - }); - }, - - render_pie_chart: function (data) { - var formatted_data = _.map(data, this.proxy('format_data')); - - nv.addGraph(function () { - var chart = nv.models.pieChart() - .color(d3.scale.category10().range()) - .width(650) - .height(400); - - d3.select('.graph_chart svg') - .datum(formatted_data) - .transition().duration(1200) - .attr('width', 650) - .attr('height', 400) - .call(chart); - - nv.utils.windowResize(chart.update); - return chart; - }); - }, - -}); +//////////////////////////////////////////////////////////////////////////////// // utility function removeFromArray(array, element) { var index = array.indexOf(element); -- cgit v1.2.3 From 08a26f9e95ab5a432385d803679eba030fcb6673 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 15 Nov 2013 16:37:01 +0100 Subject: [REF] refactoring in progress. moves some util functions to its own file in addon web_graph bzr revid: ged@openerp.com-20131115153701-rxh1voksnu0ule4t --- addons/web_graph/static/src/js/graph.js | 40 --------------------------------- 1 file changed, 40 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index ccec8f03ec3..48fa416ba75 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -511,45 +511,5 @@ var PivotTable = BasicDataView.extend({ }); -//////////////////////////////////////////////////////////////////////////////// -// utility -function removeFromArray(array, element) { - var index = array.indexOf(element); - if (index > -1) { - array.splice(index, 1); - } -} - -/** - * Query the server and return a deferred which will return the data - * with all the groupbys applied (this is done for now, but the goal - * is to modify read_group in order to allow eager and lazy groupbys - */ -function query_groups (model, fields, domain, groupbys) { - return model.query(fields) - .filter(domain) - .group_by(groupbys) - .then(function (results) { - var non_empty_results = _.filter(results, function (group) { - return group.attributes.length > 0; - }); - if (groupbys.length <= 1) { - return non_empty_results; - } else { - var get_subgroups = $.when.apply(null, _.map(non_empty_results, function (result) { - var new_domain = result.model._domain; - var new_groupings = groupbys.slice(1); - return query_groups(model, fields,new_domain, new_groupings).then(function (subgroups) { - result.subgroups_data = subgroups; - }); - })); - return get_subgroups.then(function () { - return non_empty_results; - }); - } - }); -} - - }; -- cgit v1.2.3 From 990deeebe465ae9ee992b1251b89c46683d84589 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 15 Nov 2013 17:32:09 +0100 Subject: [REF] refactoring in progress. removes widget chartview and merges basicdataview with pivottable widgets in addon web_graph bzr revid: ged@openerp.com-20131115163209-iebydq0jth2f8lee --- addons/web_graph/static/src/js/graph.js | 102 +++++++++++--------------------- 1 file changed, 34 insertions(+), 68 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 48fa416ba75..3b53744d9f3 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -22,18 +22,12 @@ instance.web_graph.GraphView = instance.web.View.extend({ template: 'GraphView', display_name: _lt('Graph'), view_type: 'graph', - mode: 'pivot', // pivot => display pivot table, chart => display chart + mode: 'pivot', // pivot, bar_chart, line_chart or pie_chart events: { 'click .graph_mode_selection li' : function (event) { event.preventDefault(); - var view_mode = event.target.attributes['data-mode'].nodeValue; - if (view_mode === 'data') { - this.mode = 'pivot'; - } else { - this.mode = 'chart'; - this.chart_view.set_mode(view_mode); - } + this.mode = event.target.attributes['data-mode'].nodeValue; this.display_data(); }, 'click .graph_clear_groups' : function (event) { @@ -91,31 +85,48 @@ instance.web_graph.GraphView = instance.web.View.extend({ return $.when(important_fields_def, field_descr_def) .then(function () { + + self.data = { + model: model, + domain: options.domain, + fields: options.fields, + important_fields: options.important_fields, + measure: options.measure, + measure_label: options.fields[options.measure].string, + col_groupby: [], + row_groupby: options.row_groupby, + groups: [], + total: null, + }; self.pivot_table = new PivotTable(model, options); - self.chart_view = new ChartView(model, options); }) .then(function () { return self.pivot_table.appendTo('.graph_main_content'); - }) - .then(function() { - return self.chart_view.appendTo('.graph_main_content'); }); + }, display_data : function () { + var content = this.$el.filter('.graph_main_content'); + content.find('svg').remove(); + var self = this; if (this.mode === 'pivot') { - this.chart_view.hide(); this.pivot_table.show(); + } else { this.pivot_table.hide(); - this.chart_view.show(); + content.append(''); + var view_fields = this.data.row_groupby.concat(this.data.measure, this.data.col_groupby); + query_groups(this.data.model, view_fields, this.data.domain, this.data.row_groupby).then(function (groups) { + Charts[self.mode](groups, self.data.measure, self.data.measure_label); + }); + } }, do_search: function (domain, context, group_by) { - this.domain = new instance.web.CompoundDomain(domain); + this.data.domain = new instance.web.CompoundDomain(domain); this.pivot_table.set_domain(domain); - this.chart_view.set_domain(domain); this.display_data(); }, @@ -127,14 +138,15 @@ instance.web_graph.GraphView = instance.web.View.extend({ }); - /** - * BasicDataView widget. Basic widget to manage show/hide functionality - * and to initialize some attributes. It is inherited by PivotTable - * and ChartView widget. + * PivotTable widget. It displays the data in tabular data and allows the + * user to drill down and up in the table */ -var BasicDataView = instance.web.Widget.extend({ - +var PivotTable = instance.web.Widget.extend({ + template: 'pivot_table', + rows: [], + cols: [], + current_row_id : 0, need_redraw: false, // Input parameters: @@ -198,54 +210,12 @@ var BasicDataView = instance.web.Widget.extend({ this.$el.css('display', 'none'); }, - draw: function() { - }, get_data: function (groupby) { var view_fields = this.groupby.row.concat(this.measure, this.groupby.col); return query_groups(this.model, view_fields, this.domain, groupby); }, -}); - - - - /** - * ChartView widget. It displays the data in chart form, using the nvd3 - * library. Various modes include bar charts, pie charts or line charts. - */ -var ChartView = BasicDataView.extend({ - template: 'chart_view', - - set_mode: function (mode) { - this.mode = mode; - console.log("mode",mode); - this.render = this['render_' + mode]; - this.need_redraw = true; - }, - - draw: function () { - var self = this; - this.$el.empty(); - console.log("measrue",self.measure); - this.$el.append(''); - this.get_data(this.groupby.row).done(function (data) { - Charts[self.mode](data, self.measure, self.measure_label); - }); - }, - - - -}); - /** - * PivotTable widget. It displays the data in tabular data and allows the - * user to drill down and up in the table - */ -var PivotTable = BasicDataView.extend({ - template: 'pivot_table', - rows: [], - cols: [], - current_row_id : 0, events: { 'click .web_graph_click' : function (event) { @@ -297,10 +267,6 @@ var PivotTable = BasicDataView.extend({ this.draw(); }, - init: function (model, options) { - this._super(model, options); - }, - generate_id: function () { this.current_row_id += 1; return this.current_row_id - 1; -- cgit v1.2.3 From 0b9150160c89f96388b50ad6eb39bfe9595a1c50 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Mon, 18 Nov 2013 10:07:15 +0100 Subject: [REF] refactoring in progress. removes widget chartview and merges basicdataview with pivottable widgets in addon web_graph bzr revid: ged@openerp.com-20131118090715-2e9vgt7y2ynm6nql --- addons/web_graph/static/src/js/graph.js | 34 +++++++-------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 3b53744d9f3..a0762dd5ae0 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -15,8 +15,8 @@ var QWeb = instance.web.qweb; instance.web.views.add('graph', 'instance.web_graph.GraphView'); /** - * GraphView view. It mostly contains two widgets (PivotTable and ChartView) - * and some data. + * GraphView view. It mostly contains a widget (PivotTable), some data, and + * calls to charts function. */ instance.web_graph.GraphView = instance.web.View.extend({ template: 'GraphView', @@ -111,6 +111,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ content.find('svg').remove(); var self = this; if (this.mode === 'pivot') { + this.pivot_table.draw(); this.pivot_table.show(); } else { @@ -126,7 +127,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ do_search: function (domain, context, group_by) { this.data.domain = new instance.web.CompoundDomain(domain); - this.pivot_table.set_domain(domain); + this.pivot_table.set_domain(this.data.domain); this.display_data(); }, @@ -147,7 +148,6 @@ var PivotTable = instance.web.Widget.extend({ rows: [], cols: [], current_row_id : 0, - need_redraw: false, // Input parameters: // model: model to display @@ -170,39 +170,16 @@ var PivotTable = instance.web.Widget.extend({ this.measure = options.measure; this.measure_label = options.measure ? options.fields[options.measure].string : 'Quantity'; this.data = []; - this.need_redraw = true; this.important_fields = options.important_fields; }, - get_descr: function (field_id) { - return this.fields[field_id].string; - }, set_domain: function (domain) { this.domain = domain; - this.need_redraw = true; - }, - - set_row_groupby: function (row_groupby) { - this.groupby.row = row_groupby; - this.need_redraw = true; - }, - - set_col_groupby: function (col_groupby) { - this.groupby.col = col_groupby; - this.need_redraw = true; }, - set_measure: function (measure) { - this.measure = measure; - this.need_redraw = true; - }, show: function () { - if (this.need_redraw) { - this.draw(); - this.need_redraw = false; - } this.$el.css('display', 'block'); }, @@ -210,6 +187,9 @@ var PivotTable = instance.web.Widget.extend({ this.$el.css('display', 'none'); }, + get_descr: function (field_id) { + return this.fields[field_id].string; + }, get_data: function (groupby) { var view_fields = this.groupby.row.concat(this.measure, this.groupby.col); -- cgit v1.2.3 From 06b125de40269076969232fa877ea8b8ec3c61ec Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Mon, 18 Nov 2013 13:53:20 +0100 Subject: [REF] large refactoring. removes widget chartview and merges basicdataview with pivottable widgets in addon web_graph bzr revid: ged@openerp.com-20131118125320-uhy58xmxlx4nkvbt --- addons/web_graph/static/src/js/graph.js | 385 +++++++++++++------------------- 1 file changed, 157 insertions(+), 228 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index a0762dd5ae0..558e101c921 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -23,6 +23,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ display_name: _lt('Graph'), view_type: 'graph', mode: 'pivot', // pivot, bar_chart, line_chart or pie_chart + pivot_table: null, events: { 'click .graph_mode_selection li' : function (event) { @@ -30,34 +31,31 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.mode = event.target.attributes['data-mode'].nodeValue; this.display_data(); }, - 'click .graph_clear_groups' : function (event) { - this.pivot_table.clear_groups(); - }, }, view_loading: function (fields_view_get) { var self = this; var model = new instance.web.Model(fields_view_get.model, {group_by_no_leaf: true}); - var options = {}; - options.domain = []; - options.col_groupby = []; + var domain = []; + var col_groupby = []; + var row_groupby = []; + var measure = null; + var fields; + var important_fields = []; // get the default groupbys and measure defined in the field view - options.measure = null; - options.row_groupby = []; _.each(fields_view_get.arch.children, function (field) { if ('name' in field.attrs) { if ('operator' in field.attrs) { - options.measure = field.attrs.name; + measure = field.attrs.name; } else { - options.row_groupby.push(field.attrs.name); + row_groupby.push(field.attrs.name); } } }); // get the most important fields (of the model) by looking at the // groupby filters defined in the search view - options.important_fields = []; var load_view = instance.web.fields_view_get({ model: model, view_type: 'search', @@ -67,12 +65,11 @@ instance.web_graph.GraphView = instance.web.View.extend({ var groups = _.select(search_view.arch.children, function (c) { return (c.tag == 'group') && (c.attrs.string != 'Display'); }); - _.each(groups, function(g) { _.each(g.children, function (g) { if (g.attrs.context) { var field_id = py.eval(g.attrs.context).group_by; - options.important_fields.push(field_id); + important_fields.push(field_id); } }); }); @@ -80,30 +77,23 @@ instance.web_graph.GraphView = instance.web.View.extend({ // get the fields descriptions from the model var field_descr_def = model.call('fields_get', []) - .then(function (fields) { options.fields = fields; }); - + .then(function (fs) { fields = fs; }); return $.when(important_fields_def, field_descr_def) .then(function () { - self.data = { model: model, - domain: options.domain, - fields: options.fields, - important_fields: options.important_fields, - measure: options.measure, - measure_label: options.fields[options.measure].string, + domain: domain, + fields: fields, + important_fields: important_fields, + measure: measure, + measure_label: fields[measure].string, col_groupby: [], - row_groupby: options.row_groupby, + row_groupby: row_groupby, groups: [], total: null, }; - self.pivot_table = new PivotTable(model, options); - }) - .then(function () { - return self.pivot_table.appendTo('.graph_main_content'); }); - }, display_data : function () { @@ -111,9 +101,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ content.find('svg').remove(); var self = this; if (this.mode === 'pivot') { - this.pivot_table.draw(); this.pivot_table.show(); - } else { this.pivot_table.hide(); content.append(''); @@ -127,7 +115,13 @@ instance.web_graph.GraphView = instance.web.View.extend({ do_search: function (domain, context, group_by) { this.data.domain = new instance.web.CompoundDomain(domain); - this.pivot_table.set_domain(this.data.domain); + + if (this.pivot_table) { + this.pivot_table.draw(); + } else { + this.pivot_table = new PivotTable(this.data); + this.pivot_table.appendTo('.graph_main_content'); + } this.display_data(); }, @@ -139,64 +133,19 @@ instance.web_graph.GraphView = instance.web.View.extend({ }); + /** * PivotTable widget. It displays the data in tabular data and allows the * user to drill down and up in the table */ var PivotTable = instance.web.Widget.extend({ template: 'pivot_table', + data: null, + headers: [], rows: [], cols: [], current_row_id : 0, - // Input parameters: - // model: model to display - // fields: dictionary returned by field_get on model (desc of model) - // domain: constraints on model records - // row_groupby: groubys on rows (so, row headers in the pivot table) - // col_groupby: idem, but on col - // measure: quantity to display. either a field from the model, or - // null, in which case we use the "count" measure - init: function (model, options) { - var self = this; - this.model = model; - this.fields = options.fields; - this.domain = options.domain; - this.groupby = { - row: options.row_groupby, - col: options.col_groupby, - }; - - this.measure = options.measure; - this.measure_label = options.measure ? options.fields[options.measure].string : 'Quantity'; - this.data = []; - this.important_fields = options.important_fields; - }, - - - set_domain: function (domain) { - this.domain = domain; - }, - - - show: function () { - this.$el.css('display', 'block'); - }, - - hide: function () { - this.$el.css('display', 'none'); - }, - - get_descr: function (field_id) { - return this.fields[field_id].string; - }, - - get_data: function (groupby) { - var view_fields = this.groupby.row.concat(this.measure, this.groupby.col); - return query_groups(this.model, view_fields, this.domain, groupby); - }, - - events: { 'click .web_graph_click' : function (event) { var self = this; @@ -207,12 +156,12 @@ var PivotTable = instance.web.Widget.extend({ if (row.expanded) { this.fold_row(row_id); } else { - if (row.path.length < this.groupby.row.length) { - var field_to_expand = this.groupby.row[row.path.length]; + if (row.path.length < this.data.row_groupby.length) { + var field_to_expand = this.data.row_groupby[row.path.length]; this.expand_row(row_id, field_to_expand); } else { - var already_grouped = self.groupby.row.concat(self.groupby.col); - var possible_groups = _.difference(self.important_fields, already_grouped); + var already_grouped = self.data.row_groupby.concat(self.data.col_groupby); + var possible_groups = _.difference(self.data.important_fields, already_grouped); var dropdown_options = { fields: _.map(possible_groups, function (field) { return {id: field, value: self.get_descr(field)}; @@ -221,14 +170,13 @@ var PivotTable = instance.web.Widget.extend({ }; this.dropdown = $(QWeb.render('field_selection', dropdown_options)); $(event.target).after(this.dropdown); - this.dropdown.css({position:"absolute", - left:event.pageX, + this.dropdown.css({position:'absolute', + left:event.pageX, top:event.pageY}); $('.field-selection').next('.dropdown-menu').toggle(); } } - }, 'click a.field-selection' : function (event) { event.preventDefault(); @@ -238,133 +186,167 @@ var PivotTable = instance.web.Widget.extend({ this.expand_row(row_id, field_id); }, }, + + init: function (data) { + this.data = data; + }, - clear_groups: function () { - this.groupby.row = []; - this.groupby.col = []; - this.rows = []; - this.cols = []; - this.draw(); + start: function () { + var self = this; + this.get_groups(this.data.row_groupby) + .then(function (groups) { + self.data.groups = groups; + return self.get_groups([]); + }).then(function (total) { + self.data.total = total; + self.build_table(); + self.draw(); + }); }, - generate_id: function () { - this.current_row_id += 1; - return this.current_row_id - 1; + draw: function () { + var self = this; + this.$el.empty(); + + _.each(this.headers, function (header) { + self.$el.append(header); + }); + + _.each(this.rows, function (row) { + self.$el.append(row.html); + }); }, - get_row: function (id) { - return _.find(this.rows, function(row) { - return (row.id == id); + show: function () { + this.$el.css('display', 'block'); + }, + + hide: function () { + this.$el.css('display', 'none'); + }, + + build_table: function () { + var self = this; + + this.headers.push('' + + '' + + this.data.measure_label + + ''); + + var main_row = this.make_row(this.data.total[0]); + + _.each(this.data.groups, function (group) { + self.make_row(group, main_row.id); }); }, - make_cell: function (content, options) { - var attrs = [''); - if (options && options.indent) { - _.each(_.range(options.indent), function () { - attrs.push(''); - }); - } - if (options && options.foldable) { - attrs.push(''); - } - if (content) { - attrs.push(content); - } else { - attrs.push('Undefined'); - } - if (options && options.foldable) { - attrs.push(''); - } - attrs.push(''); - return attrs.join(' '); + get_groups: function (groupby) { + var view_fields = this.data.row_groupby.concat(this.data.measure, this.data.col_groupby); + return query_groups(this.data.model, view_fields, this.data.domain, groupby); }, - make_row: function (data, parent_id) { - var has_parent = (parent_id !== undefined); - var parent = has_parent ? this.get_row(parent_id) : null; - var path; + make_row: function (group, parent_id) { + var path, + value, + expanded, + domain, + parent, + has_parent = (parent_id !== undefined), + row_id = this.generate_id(); + if (has_parent) { - path = parent.path.concat(data.attributes.grouped_on); - } else if (data.attributes.grouped_on !== undefined) { - path = [data.attributes.grouped_on]; + parent = this.get_row(parent_id); + path = parent.path.concat(group.attributes.grouped_on); + value = group.attributes.value[1]; + expanded = false; + parent.children.push(row_id); + domain = group.model._domain; } else { + parent = null; path = []; + value = 'Total'; + expanded = true; + domain = this.data.domain; } - var indent_level = has_parent ? parent.path.length : 0; - var value = (this.groupby.row.length > 0) ? data.attributes.value[1] : 'Total'; - - var jquery_row = $(''); - var row_id = this.generate_id(); - var header = $(this.make_cell(value, {is_border:true, indent: indent_level, foldable:true, row_id: row_id})); + var header = this.make_cell(value, {is_border:true, indent: path.length, foldable:true, row_id: row_id}); jquery_row.html(header); - jquery_row.append(this.make_cell(data.attributes.aggregates[this.measure])); + jquery_row.append(this.make_cell(group.attributes.aggregates[this.data.measure])); var row = { id: row_id, path: path, value: value, - expanded: false, + expanded: expanded, parent: parent_id, children: [], - html_tr: jquery_row, - domain: data.model._domain, + html: jquery_row, + domain: domain, }; - // rows.splice(index of parent if any,0,row); - this.rows.push(row); // to do, insert it properly + this.rows.push(row); // to do, insert it properly, after all childs of parent + return row; + }, - if (this.groupby.row.length === 0) { - row.remove_when_expanded = true; - row.domain = this.domain; - } - if (has_parent) { - parent.children.push(row.id); + generate_id: function () { + this.current_row_id += 1; + return this.current_row_id - 1; + }, + + get_row: function (id) { + return _.find(this.rows, function(row) { + return (row.id == id); + }); + }, + + make_cell: function (content, options) { + options = _.extend({is_border: false, indent:0, foldable:false}, options); + content = (content) ? content : 'Undefined'; + + var cell = $(''); + if (options.is_border) cell.addClass('graph_border'); + _.each(_.range(options.indent), function () { + cell.prepend($('', {class:'web_graph_indent'})); + }); + + if (options.foldable) { + var plus = $('', {'data-row-id':options.row_id, + class:'icon-plus-sign web_graph_click', + href:'#'}); + plus.append(' '); + plus.append(content); + cell.append(plus); + } else { + cell.append(content); } - return row; + return cell; }, expand_row: function (row_id, field_id) { var self = this; var row = this.get_row(row_id); - if (row.path.length == this.groupby.row.length) { - this.groupby.row.push(field_id); + if (row.path.length == this.data.row_groupby.length) { + this.data.row_groupby.push(field_id); } + row.expanded = true; + row.html.find('.icon-plus-sign') + .removeClass('icon-plus-sign') + .addClass('icon-minus-sign'); - var visible_fields = this.groupby.row.concat(this.groupby.col, this.measure); - - if (row.remove_when_expanded) { - this.rows = []; - } else { - row.expanded = true; - row.html_tr.find('.icon-plus-sign') - .removeClass('icon-plus-sign') - .addClass('icon-minus-sign'); - } - - query_groups(this.model, visible_fields, row.domain, [field_id]) + var visible_fields = this.data.row_groupby.concat(this.data.col_groupby, this.data.measure); + query_groups(this.data.model, visible_fields, row.domain, [field_id]) .then(function (data) { _.each(data.reverse(), function (datapt) { - var new_row; - if (row.remove_when_expanded) { - new_row = self.make_row(datapt); - self.$('tr.graph_table_header').after(new_row.html_tr); - } else { - new_row = self.make_row(datapt, row_id); - row.html_tr.after(new_row.html_tr); - } + var new_row = self.make_row(datapt, row_id); + row.html.after(new_row.html); + }); - if (row.remove_when_expanded) { - row.html_tr.remove(); - } }); }, @@ -379,7 +361,7 @@ var PivotTable = instance.web.Widget.extend({ row.children = []; row.expanded = false; - row.html_tr.find('.icon-minus-sign') + row.html.find('.icon-minus-sign') .removeClass('icon-minus-sign') .addClass('icon-plus-sign'); @@ -388,7 +370,7 @@ var PivotTable = instance.web.Widget.extend({ return Math.max(x,y); }, 0); - this.groupby.row.splice(new_groupby_length); + this.data.row_groupby.splice(new_groupby_length); }, remove_row: function (row_id) { @@ -399,63 +381,10 @@ var PivotTable = instance.web.Widget.extend({ self.remove_row(child_row); }); - row.html_tr.remove(); + row.html.remove(); removeFromArray(this.rows, row); }, - draw: function () { - this.get_data(this.groupby.row) - .then(this.proxy('build_table')) - .done(this.proxy('_draw')); - }, - - build_table: function (data) { - var self = this; - this.rows = []; - - this.cols = [{ - path: [], - value: this.measure_label, - expanded: false, - parent: null, - children: [], - html_tds: [], - domain: this.domain, - header: $(this.make_cell(this.measure_label, {is_border:true})), - }]; - - _.each(data, function (datapt) { - self.make_row(datapt); - }); - }, - - _draw: function () { - - this.$el.empty(); - var self = this; - var header; - - if (this.groupby.row.length > 0) { - header = '' + - this.fields[this.groupby.row[0]].string + - '' + - this.measure_label + - ''; - } else { - header = '' + - '' + - this.measure_label + - ''; - } - this.$el.append(header); - - _.each(this.rows, function (row) { - self.$el.append(row.html_tr); - }); - - } }); - }; - -- cgit v1.2.3 From b34a2307cd60d857d4bcbf8cec053cf6748a8dc0 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Mon, 18 Nov 2013 14:07:56 +0100 Subject: [REF] moves the loading data code from start to draw function, in widget pivottable (addon web_graph) bzr revid: ged@openerp.com-20131118130756-rx6wqcejn92j5sl4 --- addons/web_graph/static/src/js/graph.js | 45 ++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 21 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 558e101c921..a1a9ef68429 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -117,7 +117,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.data.domain = new instance.web.CompoundDomain(domain); if (this.pivot_table) { - this.pivot_table.draw(); + this.pivot_table.draw(true); } else { this.pivot_table = new PivotTable(this.data); this.pivot_table.appendTo('.graph_main_content'); @@ -133,7 +133,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ }); - /** * PivotTable widget. It displays the data in tabular data and allows the * user to drill down and up in the table @@ -186,35 +185,39 @@ var PivotTable = instance.web.Widget.extend({ this.expand_row(row_id, field_id); }, }, - + init: function (data) { this.data = data; }, start: function () { - var self = this; - this.get_groups(this.data.row_groupby) - .then(function (groups) { - self.data.groups = groups; - return self.get_groups([]); - }).then(function (total) { - self.data.total = total; - self.build_table(); - self.draw(); - }); + this.draw(true); }, - draw: function () { + draw: function (load_data) { var self = this; - this.$el.empty(); - _.each(this.headers, function (header) { - self.$el.append(header); - }); + if (load_data === true) { + this.get_groups(this.data.row_groupby) + .then(function (groups) { + self.data.groups = groups; + return self.get_groups([]); + }).then(function (total) { + self.data.total = total; + self.build_table(); + self.draw(false); + }); + } else { + this.$el.empty(); - _.each(this.rows, function (row) { - self.$el.append(row.html); - }); + _.each(this.headers, function (header) { + self.$el.append(header); + }); + + _.each(this.rows, function (row) { + self.$el.append(row.html); + }); + } }, show: function () { -- cgit v1.2.3 From a6848a195a60b9b0d2a6a65daa2716dbeece4708 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Mon, 18 Nov 2013 15:19:55 +0100 Subject: [IMP] small code cleanup in addon web_graph bzr revid: ged@openerp.com-20131118141955-00qcb19wm0gswvck --- addons/web_graph/static/src/js/graph.js | 49 +++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 21 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index a1a9ef68429..4f8c579cfc3 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -147,11 +147,11 @@ var PivotTable = instance.web.Widget.extend({ events: { 'click .web_graph_click' : function (event) { - var self = this; + var row_id = event.target.attributes['data-row-id'].nodeValue, + row = this.get_row(row_id); + event.preventDefault(); - var row_id = event.target.attributes['data-row-id'].nodeValue; - var row = this.get_row(row_id); if (row.expanded) { this.fold_row(row_id); } else { @@ -159,24 +159,12 @@ var PivotTable = instance.web.Widget.extend({ var field_to_expand = this.data.row_groupby[row.path.length]; this.expand_row(row_id, field_to_expand); } else { - var already_grouped = self.data.row_groupby.concat(self.data.col_groupby); - var possible_groups = _.difference(self.data.important_fields, already_grouped); - var dropdown_options = { - fields: _.map(possible_groups, function (field) { - return {id: field, value: self.get_descr(field)}; - }), - row_id: row_id, - }; - this.dropdown = $(QWeb.render('field_selection', dropdown_options)); - $(event.target).after(this.dropdown); - this.dropdown.css({position:'absolute', - left:event.pageX, - top:event.pageY}); - $('.field-selection').next('.dropdown-menu').toggle(); + this.display_dropdown(row_id, $(event.target), event.pageY, event.pageY); } } }, + 'click a.field-selection' : function (event) { event.preventDefault(); this.dropdown.remove(); @@ -228,13 +216,32 @@ var PivotTable = instance.web.Widget.extend({ this.$el.css('display', 'none'); }, + display_dropdown: function (row_id, target, x, y) { + var self = this, + already_grouped = self.data.row_groupby.concat(self.data.col_groupby), + possible_groups = _.difference(self.data.important_fields, already_grouped), + dropdown_options = { + fields: _.map(possible_groups, function (field) { + return {id: field, value: self.get_descr(field)}; + }), + row_id: row_id, + }; + this.dropdown = $(QWeb.render('field_selection', dropdown_options)); + target.after(this.dropdown); + this.dropdown.css({position:'absolute', + left:x, + top:y}); + $('.field-selection').next('.dropdown-menu').toggle(); + }, + build_table: function () { var self = this; - this.headers.push('' + - '' + - this.data.measure_label + - ''); + var header = $(''); + header.append(this.make_cell(' ', {is_border:true})); + header.append(this.make_cell(this.data.measure_label, + {is_border:true, foldable: true})); + this.headers = [header]; var main_row = this.make_row(this.data.total[0]); -- cgit v1.2.3 From 1901b38c16648267077a3a2f5671ba1f2ad04ba3 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Mon, 18 Nov 2013 16:26:20 +0100 Subject: [IMP] preliminary work on supporting col expansion in pivottable widget (addon web_graph) bzr revid: ged@openerp.com-20131118152620-srzpkuom8rmxlik1 --- addons/web_graph/static/src/js/graph.js | 101 ++++++++++++++++++++++++-------- 1 file changed, 78 insertions(+), 23 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 4f8c579cfc3..949739c7ae1 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -143,26 +143,18 @@ var PivotTable = instance.web.Widget.extend({ headers: [], rows: [], cols: [], - current_row_id : 0, + id_seed : 0, events: { 'click .web_graph_click' : function (event) { - var row_id = event.target.attributes['data-row-id'].nodeValue, - row = this.get_row(row_id); - event.preventDefault(); - if (row.expanded) { - this.fold_row(row_id); - } else { - if (row.path.length < this.data.row_groupby.length) { - var field_to_expand = this.data.row_groupby[row.path.length]; - this.expand_row(row_id, field_to_expand); - } else { - this.display_dropdown(row_id, $(event.target), event.pageY, event.pageY); - } + if (event.target.attributes['data-row-id'] !== undefined) { + this.handle_row_event(event); + } + if (event.target.attributes['data-col-id'] !== undefined) { + this.handle_col_event(event); } - }, 'click a.field-selection' : function (event) { @@ -174,6 +166,39 @@ var PivotTable = instance.web.Widget.extend({ }, }, + handle_row_event: function (event) { + var row_id = event.target.attributes['data-row-id'].nodeValue, + row = this.get_row(row_id); + + if (row.expanded) { + this.fold_row(row_id); + } else { + if (row.path.length < this.data.row_groupby.length) { + var field_to_expand = this.data.row_groupby[row.path.length]; + this.expand_row(row_id, field_to_expand); + } else { + this.display_dropdown(row_id, $(event.target), event.pageY, event.pageY); + } + } + }, + + handle_col_event: function (event) { + console.log("col expand", this.cols); + // var col_id = event.target.attributes['data-col-id'].nodeValue, + // col = this.get_row(col_id); + + // if (col.expanded) { + // this.fold_row(row_id); + // } else { + // if (col.path.length < this.data.col_groupby.length) { + // var field_to_expand = this.data.col_groupby[col.path.length]; + // this.expand_col(col_id, field_to_expand); + // } else { + // this.display_dropdown(col_id, $(event.target), event.pageY, event.pageY); + // } + // } + }, + init: function (data) { this.data = data; }, @@ -237,12 +262,24 @@ var PivotTable = instance.web.Widget.extend({ build_table: function () { var self = this; + var col_id = this.generate_id(); + var header = $(''); header.append(this.make_cell(' ', {is_border:true})); header.append(this.make_cell(this.data.measure_label, - {is_border:true, foldable: true})); + {is_border:true, foldable: true, col_id:col_id})); this.headers = [header]; + this.cols= [{ + path: [], + value: this.data.measure_label, + expanded: false, + parent: null, + children: [], + cells: [], // a cell is {td:, row_id:} + domain: this.data.domain, + }]; + var main_row = this.make_row(this.data.total[0]); _.each(this.data.groups, function (group) { @@ -286,8 +323,14 @@ var PivotTable = instance.web.Widget.extend({ var jquery_row = $(''); var header = this.make_cell(value, {is_border:true, indent: path.length, foldable:true, row_id: row_id}); + var cell = this.make_cell(group.attributes.aggregates[this.data.measure]); jquery_row.html(header); - jquery_row.append(this.make_cell(group.attributes.aggregates[this.data.measure])); + jquery_row.append(cell); + + _.each(this.cols, function (col) { + col.cells.push({row_id: row_id, td: cell }); + // insert cells into corresponding col + }); var row = { id: row_id, @@ -304,8 +347,8 @@ var PivotTable = instance.web.Widget.extend({ }, generate_id: function () { - this.current_row_id += 1; - return this.current_row_id - 1; + this.id_seed += 1; + return this.id_seed - 1; }, get_row: function (id) { @@ -314,9 +357,15 @@ var PivotTable = instance.web.Widget.extend({ }); }, + get_col: function (id) { + return _.find(this.cols, function(col) { + return (col.id == id); + }); + }, + make_cell: function (content, options) { options = _.extend({is_border: false, indent:0, foldable:false}, options); - content = (content) ? content : 'Undefined'; + content = (content !== undefined) ? content : 'Undefined'; var cell = $(''); if (options.is_border) cell.addClass('graph_border'); @@ -325,9 +374,10 @@ var PivotTable = instance.web.Widget.extend({ }); if (options.foldable) { - var plus = $('', {'data-row-id':options.row_id, - class:'icon-plus-sign web_graph_click', - href:'#'}); + var attrs = {class:'icon-plus-sign web_graph_click', href:'#'}; + if (options.row_id !== undefined) attrs['data-row-id'] = options.row_id; + if (options.col_id !== undefined) attrs['data-col-id'] = options.col_id; + var plus = $('', attrs); plus.append(' '); plus.append(content); cell.append(plus); @@ -355,7 +405,6 @@ var PivotTable = instance.web.Widget.extend({ _.each(data.reverse(), function (datapt) { var new_row = self.make_row(datapt, row_id); row.html.after(new_row.html); - }); }); @@ -393,6 +442,12 @@ var PivotTable = instance.web.Widget.extend({ row.html.remove(); removeFromArray(this.rows, row); + + _.each(this.cols, function (col) { + col.cells = _.filter(col.cells, function (cell) { + return cell.row_id !== row_id; + }); + }); }, }); -- cgit v1.2.3 From 40ededd5401624b65392c3936e739217e5f5e0a8 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 19 Nov 2013 10:20:53 +0100 Subject: [IMP] preliminary work on supporting col expansion in pivottable widget (addon web_graph) bzr revid: ged@openerp.com-20131119092053-hp1pdgckiplw8mgp --- addons/web_graph/static/src/js/graph.js | 71 +++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 25 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 949739c7ae1..83b99d63b36 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -158,11 +158,18 @@ var PivotTable = instance.web.Widget.extend({ }, 'click a.field-selection' : function (event) { + var id, + field_id = event.target.attributes['data-field-id'].nodeValue; event.preventDefault(); this.dropdown.remove(); - var row_id = event.target.attributes['data-row-id'].nodeValue; - var field_id = event.target.attributes['data-field-id'].nodeValue; - this.expand_row(row_id, field_id); + if (event.target.attributes['data-row-id'] !== undefined) { + var id = event.target.attributes['data-row-id'].nodeValue; + this.expand_row(id, field_id); + } + if (event.target.attributes['data-col-id'] !== undefined) { + var id = event.target.attributes['data-col-id'].nodeValue; + this.expand_col(id, field_id); + } }, }, @@ -177,26 +184,31 @@ var PivotTable = instance.web.Widget.extend({ var field_to_expand = this.data.row_groupby[row.path.length]; this.expand_row(row_id, field_to_expand); } else { - this.display_dropdown(row_id, $(event.target), event.pageY, event.pageY); + this.display_dropdown({row_id:row_id, + target: $(event.target), + x: event.pageY, + y: event.pageY}); } } }, handle_col_event: function (event) { - console.log("col expand", this.cols); - // var col_id = event.target.attributes['data-col-id'].nodeValue, - // col = this.get_row(col_id); - - // if (col.expanded) { - // this.fold_row(row_id); - // } else { - // if (col.path.length < this.data.col_groupby.length) { - // var field_to_expand = this.data.col_groupby[col.path.length]; - // this.expand_col(col_id, field_to_expand); - // } else { - // this.display_dropdown(col_id, $(event.target), event.pageY, event.pageY); - // } - // } + var col_id = event.target.attributes['data-col-id'].nodeValue, + col = this.get_col(col_id); + + if (col.expanded) { + this.fold_col(col_id); + } else { + if (col.path.length < this.data.col_groupby.length) { + var field_to_expand = this.data.col_groupby[col.path.length]; + this.expand_col(col_id, field_to_expand); + } else { + this.display_dropdown({col_id: col_id, + target: $(event.target), + x: event.pageX, + y: event.pageY}); + } + } }, init: function (data) { @@ -241,21 +253,25 @@ var PivotTable = instance.web.Widget.extend({ this.$el.css('display', 'none'); }, - display_dropdown: function (row_id, target, x, y) { + display_dropdown: function (options) { var self = this, already_grouped = self.data.row_groupby.concat(self.data.col_groupby), possible_groups = _.difference(self.data.important_fields, already_grouped), dropdown_options = { fields: _.map(possible_groups, function (field) { return {id: field, value: self.get_descr(field)}; - }), - row_id: row_id, - }; + })}; + if (options.row_id) { + dropdown_options.row_id= options.row_id; + } else { + dropdown_options.col_id = options.col_id; + } + this.dropdown = $(QWeb.render('field_selection', dropdown_options)); - target.after(this.dropdown); + options.target.after(this.dropdown); this.dropdown.css({position:'absolute', - left:x, - top:y}); + left:options.x, + top:options.y}); $('.field-selection').next('.dropdown-menu').toggle(); }, @@ -271,6 +287,7 @@ var PivotTable = instance.web.Widget.extend({ this.headers = [header]; this.cols= [{ + id: col_id, path: [], value: this.data.measure_label, expanded: false, @@ -410,6 +427,10 @@ var PivotTable = instance.web.Widget.extend({ }, + expand_col: function (col_id, field_id) { + console.log("expandidng col",col_id, field_id); + }, + fold_row: function (row_id) { var self = this; var row = this.get_row(row_id); -- cgit v1.2.3 From 3ce4ec44d92136a0b8e7ed01f31636aa5328373f Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 19 Nov 2013 14:20:24 +0100 Subject: [IMP] preliminary work on supporting col expansion in pivottable widget (addon web_graph) bzr revid: ged@openerp.com-20131119132024-k67wlje2h14p5ptu --- addons/web_graph/static/src/js/graph.js | 79 +++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 8 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 83b99d63b36..dfcc2759ffa 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -279,11 +279,11 @@ var PivotTable = instance.web.Widget.extend({ var self = this; var col_id = this.generate_id(); - + var col_header = this.make_cell(this.data.measure_label, + {is_border:true, foldable: true, col_id:col_id}); var header = $(''); header.append(this.make_cell(' ', {is_border:true})); - header.append(this.make_cell(this.data.measure_label, - {is_border:true, foldable: true, col_id:col_id})); + header.append(col_header); this.headers = [header]; this.cols= [{ @@ -295,6 +295,7 @@ var PivotTable = instance.web.Widget.extend({ children: [], cells: [], // a cell is {td:, row_id:} domain: this.data.domain, + header: col_header }]; var main_row = this.make_row(this.data.total[0]); @@ -324,7 +325,7 @@ var PivotTable = instance.web.Widget.extend({ if (has_parent) { parent = this.get_row(parent_id); - path = parent.path.concat(group.attributes.grouped_on); + path = parent.path.concat(group.attributes.value[1]); value = group.attributes.value[1]; expanded = false; parent.children.push(row_id); @@ -418,9 +419,9 @@ var PivotTable = instance.web.Widget.extend({ var visible_fields = this.data.row_groupby.concat(this.data.col_groupby, this.data.measure); query_groups(this.data.model, visible_fields, row.domain, [field_id]) - .then(function (data) { - _.each(data.reverse(), function (datapt) { - var new_row = self.make_row(datapt, row_id); + .then(function (groups) { + _.each(groups.reverse(), function (group) { + var new_row = self.make_row(group, row_id); row.html.after(new_row.html); }); }); @@ -428,7 +429,69 @@ var PivotTable = instance.web.Widget.extend({ }, expand_col: function (col_id, field_id) { - console.log("expandidng col",col_id, field_id); + var self = this; + var col = this.get_col(col_id); + + console.log("expanding col",col); + if (col.path.length == this.data.col_groupby.length) { + this.data.col_groupby.push(field_id); + } + col.expanded = true; + col.header.find('.icon-plus-sign') + .removeClass('icon-plus-sign') + .addClass('icon-minus-sign'); + + + var visible_fields = this.data.row_groupby.concat(this.data.col_groupby, this.data.measure); + query_groups_data(this.data.model, visible_fields, col.domain, this.data.row_groupby, field_id) + .then(function (groups) { + console.log("inserting groups",groups); + console.log("this.rows",self.rows); + console.log("this.cols",self.cols); + _.each(groups, function (group) { + var new_col = { + id: self.generate_id(), + path: col.path.concat(field_id), + value: group[0].attributes.value[1], + expanded: false, + parent: col_id, + children: [], + cells: [], // a cell is {td:, row_id:} + domain: group[0].model._domain, + // header: col_header + }; + col.header.css('display','none'); + col.children.push(new_col.id); + self.cols.push(new_col); + _.each(col.cells, function (cell) { + var col_path = self.get_row(cell.row_id).path; + + var datapt = _.find(group, function (g) { + return _.isEqual(g.path.slice(1), col_path); + }); + + var value; + if (datapt === undefined) { + value = ''; + } else { + value = datapt.attributes.aggregates[self.data.measure]; + } + console.log("value", value); + // make new cell + var new_cell = { + row_id: cell.row_id, + td: self.make_cell(value) + }; + // add cell to new_col cells ({row_id, td}) + new_col.cells.push(new_cell); + // insert new cell (td) after cell.td + cell.td.after(new_cell.td); + cell.td.css('display','none'); + }); + + }); + }); + }, fold_row: function (row_id) { -- cgit v1.2.3 From ad8bddd00eac5c97ab077d225a0714d08407f24b Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 19 Nov 2013 15:52:33 +0100 Subject: [IMP] col expansion support in pivottable widget, still many bugs left (addon web_graph) bzr revid: ged@openerp.com-20131119145233-n8gjast7q48foku9 --- addons/web_graph/static/src/js/graph.js | 64 +++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 26 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index dfcc2759ffa..ca852a36c5c 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -235,9 +235,7 @@ var PivotTable = instance.web.Widget.extend({ } else { this.$el.empty(); - _.each(this.headers, function (header) { - self.$el.append(header); - }); + this.draw_top_headers(); _.each(this.rows, function (row) { self.$el.append(row.html); @@ -279,12 +277,6 @@ var PivotTable = instance.web.Widget.extend({ var self = this; var col_id = this.generate_id(); - var col_header = this.make_cell(this.data.measure_label, - {is_border:true, foldable: true, col_id:col_id}); - var header = $(''); - header.append(this.make_cell(' ', {is_border:true})); - header.append(col_header); - this.headers = [header]; this.cols= [{ id: col_id, @@ -295,9 +287,11 @@ var PivotTable = instance.web.Widget.extend({ children: [], cells: [], // a cell is {td:, row_id:} domain: this.data.domain, - header: col_header + // header: col_header }]; + self.make_top_headers(); + var main_row = this.make_row(this.data.total[0]); _.each(this.data.groups, function (group) { @@ -314,6 +308,33 @@ var PivotTable = instance.web.Widget.extend({ return query_groups(this.data.model, view_fields, this.data.domain, groupby); }, + make_top_headers : function () { + var self = this; + + var height = maxInArray(_.map(self.rows, function(g) {return g.path.length;}),1); + + var header = $(''); + header.append(this.make_cell('', {is_border:true, }).attr('colspan', height)); + + _.each(this.cols, function (col) { + if (col.children.length === 0) { + var options = {is_border: true, foldable:true, col_id: col.id}; + header.append(self.make_cell(col.value, options)); + } + }); + header.addClass('graph_top'); + this.headers = [header]; + }, + + draw_top_headers: function () { + var self = this; + $("tr.graph_top").remove(); + _.each(this.headers, function (header) { + self.$el.prepend(header); + }); + + }, + make_row: function (group, parent_id) { var path, value, @@ -432,22 +453,18 @@ var PivotTable = instance.web.Widget.extend({ var self = this; var col = this.get_col(col_id); - console.log("expanding col",col); if (col.path.length == this.data.col_groupby.length) { this.data.col_groupby.push(field_id); } col.expanded = true; - col.header.find('.icon-plus-sign') - .removeClass('icon-plus-sign') - .addClass('icon-minus-sign'); + // col.header.find('.icon-plus-sign') + // .removeClass('icon-plus-sign') + // .addClass('icon-minus-sign'); var visible_fields = this.data.row_groupby.concat(this.data.col_groupby, this.data.measure); query_groups_data(this.data.model, visible_fields, col.domain, this.data.row_groupby, field_id) .then(function (groups) { - console.log("inserting groups",groups); - console.log("this.rows",self.rows); - console.log("this.cols",self.cols); _.each(groups, function (group) { var new_col = { id: self.generate_id(), @@ -460,7 +477,7 @@ var PivotTable = instance.web.Widget.extend({ domain: group[0].model._domain, // header: col_header }; - col.header.css('display','none'); + // col.header.css('display','none'); col.children.push(new_col.id); self.cols.push(new_col); _.each(col.cells, function (cell) { @@ -476,22 +493,19 @@ var PivotTable = instance.web.Widget.extend({ } else { value = datapt.attributes.aggregates[self.data.measure]; } - console.log("value", value); - // make new cell var new_cell = { row_id: cell.row_id, td: self.make_cell(value) }; - // add cell to new_col cells ({row_id, td}) new_col.cells.push(new_cell); - // insert new cell (td) after cell.td cell.td.after(new_cell.td); cell.td.css('display','none'); }); }); + self.make_top_headers(); + self.draw_top_headers(); }); - }, fold_row: function (row_id) { @@ -509,9 +523,7 @@ var PivotTable = instance.web.Widget.extend({ .addClass('icon-plus-sign'); var fold_levels = _.map(self.rows, function(g) {return g.path.length;}); - var new_groupby_length = _.reduce(fold_levels, function (x, y) { - return Math.max(x,y); - }, 0); + var new_groupby_length = maxInArray(fold_levels); this.data.row_groupby.splice(new_groupby_length); }, -- cgit v1.2.3 From 01a4fc36240711c535db253189a21edd9fd38fd7 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 20 Nov 2013 12:08:21 +0100 Subject: [IMP] col expansion support in pivottable widget, improve the column headers rendering (addon web_graph) bzr revid: ged@openerp.com-20131120110821-8r4q3dybhndm3gjz --- addons/web_graph/static/src/js/graph.js | 116 +++++++++++++++++++++++++++----- 1 file changed, 99 insertions(+), 17 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index ca852a36c5c..606de2ba2a9 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -163,11 +163,11 @@ var PivotTable = instance.web.Widget.extend({ event.preventDefault(); this.dropdown.remove(); if (event.target.attributes['data-row-id'] !== undefined) { - var id = event.target.attributes['data-row-id'].nodeValue; + id = event.target.attributes['data-row-id'].nodeValue; this.expand_row(id, field_id); } if (event.target.attributes['data-col-id'] !== undefined) { - var id = event.target.attributes['data-col-id'].nodeValue; + id = event.target.attributes['data-col-id'].nodeValue; this.expand_col(id, field_id); } }, @@ -309,27 +309,106 @@ var PivotTable = instance.web.Widget.extend({ }, make_top_headers : function () { - var self = this; + var self = this, + header; - var height = maxInArray(_.map(self.rows, function(g) {return g.path.length;}),1); + function partition (columns) { + return _.reduce(columns, function (partial, col) { + if (partial.length === 0) return [[col]]; + if (col.path.length > _.first(_.last(partial)).path.length) { + _.last(partial).push(col); + } else { + partial.push([col]); + } + return partial; + }, []); + } - var header = $(''); - header.append(this.make_cell('', {is_border:true, }).attr('colspan', height)); + function side_by_side(blocks) { + var result = _.zip.apply(_,blocks); + result = _.map(result, function(line) {return _.compact(_.flatten(line))}); + return result; + } - _.each(this.cols, function (col) { - if (col.children.length === 0) { - var options = {is_border: true, foldable:true, col_id: col.id}; - header.append(self.make_cell(col.value, options)); + function make_header_cell(col, span) { + var options = { + is_border:true, + foldable:true, + row_span: (span === undefined) ? 1 : span, + col_id: col.id, + }; + var result = self.make_cell(col.value, options); + return result; + } + + function calculate_width(cols) { + if (cols.length === 1) { + return 1; } - }); - header.addClass('graph_top'); - this.headers = [header]; + var p = partition(_.rest(cols)); + return _.reduce(p, function(x, y){ return x + calculate_width(y); }, 0); + } + + function make_header_cells(cols, height) { + var p = partition(cols); + if ((p.length === 1) && (p[0].length === 1)) { + var result = [[make_header_cell(cols[0], height)]]; + return result; + } + if ((p.length === 1) && (p[0].length > 1)) { + var cell = make_header_cell(p[0][0]); + cell.attr('colspan', calculate_width(cols)); + return [[cell]].concat(make_header_cells(_.rest(cols), height - 1)); + } + if (p.length > 1) { + return side_by_side(_.map(p, function (group) { + return make_header_cells(group, height); + })); + } + } + + if (this.cols.length === 1) { + header = $(''); + header.append(this.make_cell('', {is_border:true})); + header.append(this.make_cell(this.cols[0].value, + {is_border:true, foldable:true, col_id:this.cols[0].id})); + header.addClass('graph_top'); + this.headers = [header]; + } else { + console.log("cols",this.cols); + var height = _.max(_.map(self.cols, function(g) {return g.path.length;})); + console.log("height",height); + var header_rows = make_header_cells(_.rest(this.cols), height); + + header_rows[0].splice(0,0,self.make_cell('', {is_border:true, }).attr('rowspan', height)) + console.log("header rows",header_rows); + self.headers = []; + _.each(header_rows, function (cells) { + header = $(''); + console.log("cells",cells); + header.append(cells); + header.addClass('graph_top'); + self.headers.push(header); + }); + + // header = + // header.append(this.make_cell('', {is_border:true, }).attr('rowspan', height)); + + // _.each(this.cols, function (col) { + // if (col.children.length === 0) { + // var options = {is_border: true, foldable:true, col_id: col.id}; + // header.append(self.make_cell(col.value, options)); + // } + // }); + // header.addClass('graph_top'); + // this.headers = [header]; + } }, draw_top_headers: function () { var self = this; $("tr.graph_top").remove(); - _.each(this.headers, function (header) { + _.each(this.headers.reverse(), function (header) { self.$el.prepend(header); }); @@ -408,6 +487,8 @@ var PivotTable = instance.web.Widget.extend({ var cell = $(''); if (options.is_border) cell.addClass('graph_border'); + if (options.row_span) cell.attr('rowspan', options.row_span); + if (options.col_span) cell.attr('rowspan', options.col_span); _.each(_.range(options.indent), function () { cell.prepend($('', {class:'web_graph_indent'})); }); @@ -468,7 +549,7 @@ var PivotTable = instance.web.Widget.extend({ _.each(groups, function (group) { var new_col = { id: self.generate_id(), - path: col.path.concat(field_id), + path: col.path.concat(group[0].attributes.value[1]), value: group[0].attributes.value[1], expanded: false, parent: col_id, @@ -479,7 +560,8 @@ var PivotTable = instance.web.Widget.extend({ }; // col.header.css('display','none'); col.children.push(new_col.id); - self.cols.push(new_col); + insertAfter(self.cols, col, new_col) + // self.cols.push(new_col); _.each(col.cells, function (cell) { var col_path = self.get_row(cell.row_id).path; @@ -523,7 +605,7 @@ var PivotTable = instance.web.Widget.extend({ .addClass('icon-plus-sign'); var fold_levels = _.map(self.rows, function(g) {return g.path.length;}); - var new_groupby_length = maxInArray(fold_levels); + var new_groupby_length = _.max(fold_levels); this.data.row_groupby.splice(new_groupby_length); }, -- cgit v1.2.3 From fde3f47a2e21afbee6d7ec575590e97a05a3eb98 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 20 Nov 2013 12:17:28 +0100 Subject: [FIX] properly clears the current rows when building pivot table (addon web_graph) bzr revid: ged@openerp.com-20131120111728-3aqr9xxz8kdhkfg6 --- addons/web_graph/static/src/js/graph.js | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 606de2ba2a9..6e9e20d943a 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -275,6 +275,8 @@ var PivotTable = instance.web.Widget.extend({ build_table: function () { var self = this; + this.rows = []; + var col_id = this.generate_id(); @@ -287,7 +289,6 @@ var PivotTable = instance.web.Widget.extend({ children: [], cells: [], // a cell is {td:, row_id:} domain: this.data.domain, - // header: col_header }]; self.make_top_headers(); @@ -375,33 +376,17 @@ var PivotTable = instance.web.Widget.extend({ header.addClass('graph_top'); this.headers = [header]; } else { - console.log("cols",this.cols); var height = _.max(_.map(self.cols, function(g) {return g.path.length;})); - console.log("height",height); var header_rows = make_header_cells(_.rest(this.cols), height); header_rows[0].splice(0,0,self.make_cell('', {is_border:true, }).attr('rowspan', height)) - console.log("header rows",header_rows); self.headers = []; _.each(header_rows, function (cells) { header = $(''); - console.log("cells",cells); header.append(cells); header.addClass('graph_top'); self.headers.push(header); }); - - // header = - // header.append(this.make_cell('', {is_border:true, }).attr('rowspan', height)); - - // _.each(this.cols, function (col) { - // if (col.children.length === 0) { - // var options = {is_border: true, foldable:true, col_id: col.id}; - // header.append(self.make_cell(col.value, options)); - // } - // }); - // header.addClass('graph_top'); - // this.headers = [header]; } }, -- cgit v1.2.3 From 215f66550805e81c8fa53125734fb3ee0e8a1f63 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 20 Nov 2013 13:46:32 +0100 Subject: [IMP] supports columns folding in pivottable (addon web_graph) bzr revid: ged@openerp.com-20131120124632-ydjuvtcvou14qivo --- addons/web_graph/static/src/js/graph.js | 49 +++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 6e9e20d943a..d99bffbb2d6 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -613,6 +613,55 @@ var PivotTable = instance.web.Widget.extend({ }); }, + fold_col: function (col_id) { + var self = this; + var col = this.get_col(col_id); + + _.each(col.children, function (child_col) { + self.remove_col(child_col); + }); + col.children = []; + + _.each(col.cells, function (cell) { + cell.td.css('display','table-cell'); + }); + col.expanded = false; + // row.html.find('.icon-minus-sign') + // .removeClass('icon-minus-sign') + // .addClass('icon-plus-sign'); + + var fold_levels = _.map(self.cols, function(g) {return g.path.length;}); + var new_groupby_length = _.max(fold_levels); + + this.data.col_groupby.splice(new_groupby_length); + this.make_top_headers(); + this.draw_top_headers(); + + + }, + + remove_col: function (col_id) { + var self = this; + var col = this.get_col(col_id); + + _.each(col.children, function (child_col) { + self.remove_col(child_col); + }); + + _.each(col.cells, function (cell) { + cell.td.remove(); + }); + // row.html.remove(); + removeFromArray(this.cols, col); + + // _.each(this.cols, function (col) { + // col.cells = _.filter(col.cells, function (cell) { + // return cell.row_id !== row_id; + // }); + // }); + }, + + }); }; -- cgit v1.2.3 From 53a8f56f03b2097d58ccf8ba687df641680ae821 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 20 Nov 2013 14:07:48 +0100 Subject: [FIX] correctly handles + and - signs on rows/columns expansion/folding (addon web_graph) bzr revid: ged@openerp.com-20131120130748-mge1w8apby67miqm --- addons/web_graph/static/src/js/graph.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index d99bffbb2d6..5f7d70776a3 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -339,6 +339,11 @@ var PivotTable = instance.web.Widget.extend({ col_id: col.id, }; var result = self.make_cell(col.value, options); + if (col.expanded) { + result.find('.icon-plus-sign') + .removeClass('icon-plus-sign') + .addClass('icon-minus-sign'); + } return result; } @@ -432,9 +437,14 @@ var PivotTable = instance.web.Widget.extend({ _.each(this.cols, function (col) { col.cells.push({row_id: row_id, td: cell }); - // insert cells into corresponding col }); + if (!has_parent) { + header.find('.icon-plus-sign') + .removeClass('icon-plus-sign') + .addClass('icon-minus-sign'); + } + var row = { id: row_id, path: path, @@ -523,10 +533,6 @@ var PivotTable = instance.web.Widget.extend({ this.data.col_groupby.push(field_id); } col.expanded = true; - // col.header.find('.icon-plus-sign') - // .removeClass('icon-plus-sign') - // .addClass('icon-minus-sign'); - var visible_fields = this.data.row_groupby.concat(this.data.col_groupby, this.data.measure); query_groups_data(this.data.model, visible_fields, col.domain, this.data.row_groupby, field_id) -- cgit v1.2.3 From 9c76cb8a4c8366979e40bc86fc0b66e088c026c3 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 20 Nov 2013 14:15:43 +0100 Subject: [FIX] fixes a bug where dropdown menu used wrong coordinates when expanding rows (addon web_graph) bzr revid: ged@openerp.com-20131120131543-d119benx379oglry --- addons/web_graph/static/src/js/graph.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 5f7d70776a3..7e6f5b78ef7 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -186,7 +186,7 @@ var PivotTable = instance.web.Widget.extend({ } else { this.display_dropdown({row_id:row_id, target: $(event.target), - x: event.pageY, + x: event.pageX, y: event.pageY}); } } -- cgit v1.2.3 From a7953bbd850468cbf0abfb41da49f501e6e65a42 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 20 Nov 2013 15:19:14 +0100 Subject: [REF] preparation work to allows row expansion to query and display correct data when columns are already expanded (addon web_graph) bzr revid: ged@openerp.com-20131120141914-yf4o5sh4gzagh2ym --- addons/web_graph/static/src/js/graph.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 7e6f5b78ef7..357fc2b2a8a 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -223,12 +223,13 @@ var PivotTable = instance.web.Widget.extend({ var self = this; if (load_data === true) { - this.get_groups(this.data.row_groupby) + var view_fields = this.data.row_groupby.concat(this.data.measure, this.data.col_groupby); + query_groups_data(this.data.model, view_fields, this.data.domain, this.data.col_groupby, this.data.row_groupby[0]) .then(function (groups) { self.data.groups = groups; return self.get_groups([]); }).then(function (total) { - self.data.total = total; + self.data.total = [total]; self.build_table(); self.draw(false); }); @@ -405,6 +406,7 @@ var PivotTable = instance.web.Widget.extend({ }, make_row: function (group, parent_id) { + group = group[0]; var path, value, expanded, @@ -515,7 +517,7 @@ var PivotTable = instance.web.Widget.extend({ .addClass('icon-minus-sign'); var visible_fields = this.data.row_groupby.concat(this.data.col_groupby, this.data.measure); - query_groups(this.data.model, visible_fields, row.domain, [field_id]) + query_groups_data(this.data.model, visible_fields, row.domain, this.data.col_groupby, field_id) .then(function (groups) { _.each(groups.reverse(), function (group) { var new_row = self.make_row(group, row_id); @@ -547,12 +549,9 @@ var PivotTable = instance.web.Widget.extend({ children: [], cells: [], // a cell is {td:, row_id:} domain: group[0].model._domain, - // header: col_header }; - // col.header.css('display','none'); col.children.push(new_col.id); insertAfter(self.cols, col, new_col) - // self.cols.push(new_col); _.each(col.cells, function (cell) { var col_path = self.get_row(cell.row_id).path; -- cgit v1.2.3 From a309c97505dd01072225a1f45b39c19f1e6b32e6 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 21 Nov 2013 10:07:19 +0100 Subject: [IMP] allows row expansion to query and display correct data when columns are already expanded (addon web_graph) bzr revid: ged@openerp.com-20131121090719-lauwesqz7c189nba --- addons/web_graph/static/src/js/graph.js | 37 ++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 357fc2b2a8a..7d73f0df695 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -222,13 +222,14 @@ var PivotTable = instance.web.Widget.extend({ draw: function (load_data) { var self = this; - if (load_data === true) { + if (load_data) { var view_fields = this.data.row_groupby.concat(this.data.measure, this.data.col_groupby); query_groups_data(this.data.model, view_fields, this.data.domain, this.data.col_groupby, this.data.row_groupby[0]) .then(function (groups) { self.data.groups = groups; return self.get_groups([]); }).then(function (total) { + total[0].path = []; self.data.total = [total]; self.build_table(); self.draw(false); @@ -405,9 +406,9 @@ var PivotTable = instance.web.Widget.extend({ }, - make_row: function (group, parent_id) { - group = group[0]; - var path, + make_row: function (groups, parent_id) { + var self = this, + path, value, expanded, domain, @@ -417,11 +418,11 @@ var PivotTable = instance.web.Widget.extend({ if (has_parent) { parent = this.get_row(parent_id); - path = parent.path.concat(group.attributes.value[1]); - value = group.attributes.value[1]; + path = parent.path.concat(groups[0].attributes.value[1]); + value = groups[0].attributes.value[1]; expanded = false; parent.children.push(row_id); - domain = group.model._domain; + domain = groups[0].model._domain; } else { parent = null; path = []; @@ -432,13 +433,25 @@ var PivotTable = instance.web.Widget.extend({ var jquery_row = $(''); - var header = this.make_cell(value, {is_border:true, indent: path.length, foldable:true, row_id: row_id}); - var cell = this.make_cell(group.attributes.aggregates[this.data.measure]); - jquery_row.html(header); - jquery_row.append(cell); + var header = self.make_cell(value, {is_border:true, indent: path.length, foldable:true, row_id: row_id}); + jquery_row.append(header); + + var cell; _.each(this.cols, function (col) { - col.cells.push({row_id: row_id, td: cell }); + var element = _.find(groups, function (group) { + return _.isEqual(_.rest(group.path), col.path); + }); + if (element === undefined) { + cell = self.make_cell(''); + } else { + cell = self.make_cell(element.attributes.aggregates[self.data.measure]); + } + if (col.expanded) { + cell.css('display', 'none'); + } + col.cells.push({td:cell, row_id:row_id}); + jquery_row.append(cell); }); if (!has_parent) { -- cgit v1.2.3 From d0cb5149b4dc03f233fcce60d498b24ab8ac0259 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 22 Nov 2013 08:43:27 +0100 Subject: [REF] large refactoring in progress. goal is to separate the data handling code (pivot) from the ui code (drawing, buttons, events (addon web_graph) bzr revid: ged@openerp.com-20131122074327-bfnlw3ew1120um0k --- addons/web_graph/static/src/js/graph.js | 1326 ++++++++++++++++++------------- 1 file changed, 779 insertions(+), 547 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 7d73f0df695..3363f7cb3a8 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -22,26 +22,26 @@ instance.web_graph.GraphView = instance.web.View.extend({ template: 'GraphView', display_name: _lt('Graph'), view_type: 'graph', - mode: 'pivot', // pivot, bar_chart, line_chart or pie_chart - pivot_table: null, events: { 'click .graph_mode_selection li' : function (event) { event.preventDefault(); this.mode = event.target.attributes['data-mode'].nodeValue; - this.display_data(); + console.log("change mode",this.mode); }, }, view_loading: function (fields_view_get) { - var self = this; - var model = new instance.web.Model(fields_view_get.model, {group_by_no_leaf: true}); - var domain = []; - var col_groupby = []; - var row_groupby = []; - var measure = null; - var fields; - var important_fields = []; + var self = this, + model = new instance.web.Model(fields_view_get.model, {group_by_no_leaf: true}), + domain = [], + measure = null, + fields, + important_fields = [], + col_groupby = [], + row_groupby = []; + + this.pivot_table = null; // get the default groupbys and measure defined in the field view _.each(fields_view_get.arch.children, function (field) { @@ -96,33 +96,26 @@ instance.web_graph.GraphView = instance.web.View.extend({ }); }, - display_data : function () { - var content = this.$el.filter('.graph_main_content'); - content.find('svg').remove(); - var self = this; - if (this.mode === 'pivot') { - this.pivot_table.show(); - } else { - this.pivot_table.hide(); - content.append(''); - var view_fields = this.data.row_groupby.concat(this.data.measure, this.data.col_groupby); - query_groups(this.data.model, view_fields, this.data.domain, this.data.row_groupby).then(function (groups) { - Charts[self.mode](groups, self.data.measure, self.data.measure_label); - }); - - } + start: function () { + this.table = $('
'); + this.svg = $(''); + this.$el.filter('.graph_main_content').append(this.table); + this.$el.filter('.graph_main_content').append(this.svg); + return this.load_view(); }, do_search: function (domain, context, group_by) { + var self = this; this.data.domain = new instance.web.CompoundDomain(domain); - if (this.pivot_table) { - this.pivot_table.draw(true); + if (!this.pivot_table) { + self.pivot_table = new PivotTable(self.data); + self.pivot_table.start().then(self.proxy('draw_table')); } else { - this.pivot_table = new PivotTable(this.data); - this.pivot_table.appendTo('.graph_main_content'); + this.pivot_table.update_values.done(function () { + self.draw_table(); + }); } - this.display_data(); }, do_show: function () { @@ -130,556 +123,795 @@ instance.web_graph.GraphView = instance.web.View.extend({ return this._super(); }, -}); - - - /** - * PivotTable widget. It displays the data in tabular data and allows the - * user to drill down and up in the table - */ -var PivotTable = instance.web.Widget.extend({ - template: 'pivot_table', - data: null, - headers: [], - rows: [], - cols: [], - id_seed : 0, - - events: { - 'click .web_graph_click' : function (event) { - event.preventDefault(); - - if (event.target.attributes['data-row-id'] !== undefined) { - this.handle_row_event(event); - } - if (event.target.attributes['data-col-id'] !== undefined) { - this.handle_col_event(event); - } - }, - - 'click a.field-selection' : function (event) { - var id, - field_id = event.target.attributes['data-field-id'].nodeValue; - event.preventDefault(); - this.dropdown.remove(); - if (event.target.attributes['data-row-id'] !== undefined) { - id = event.target.attributes['data-row-id'].nodeValue; - this.expand_row(id, field_id); - } - if (event.target.attributes['data-col-id'] !== undefined) { - id = event.target.attributes['data-col-id'].nodeValue; - this.expand_col(id, field_id); - } - }, - }, - - handle_row_event: function (event) { - var row_id = event.target.attributes['data-row-id'].nodeValue, - row = this.get_row(row_id); - - if (row.expanded) { - this.fold_row(row_id); - } else { - if (row.path.length < this.data.row_groupby.length) { - var field_to_expand = this.data.row_groupby[row.path.length]; - this.expand_row(row_id, field_to_expand); - } else { - this.display_dropdown({row_id:row_id, - target: $(event.target), - x: event.pageX, - y: event.pageY}); - } - } - }, - - handle_col_event: function (event) { - var col_id = event.target.attributes['data-col-id'].nodeValue, - col = this.get_col(col_id); - - if (col.expanded) { - this.fold_col(col_id); - } else { - if (col.path.length < this.data.col_groupby.length) { - var field_to_expand = this.data.col_groupby[col.path.length]; - this.expand_col(col_id, field_to_expand); - } else { - this.display_dropdown({col_id: col_id, - target: $(event.target), - x: event.pageX, - y: event.pageY}); - } - } - }, - - init: function (data) { - this.data = data; - }, - - start: function () { - this.draw(true); - }, - - draw: function (load_data) { - var self = this; - - if (load_data) { - var view_fields = this.data.row_groupby.concat(this.data.measure, this.data.col_groupby); - query_groups_data(this.data.model, view_fields, this.data.domain, this.data.col_groupby, this.data.row_groupby[0]) - .then(function (groups) { - self.data.groups = groups; - return self.get_groups([]); - }).then(function (total) { - total[0].path = []; - self.data.total = [total]; - self.build_table(); - self.draw(false); - }); - } else { - this.$el.empty(); - - this.draw_top_headers(); - - _.each(this.rows, function (row) { - self.$el.append(row.html); - }); - } - }, - - show: function () { - this.$el.css('display', 'block'); - }, - - hide: function () { - this.$el.css('display', 'none'); - }, - - display_dropdown: function (options) { - var self = this, - already_grouped = self.data.row_groupby.concat(self.data.col_groupby), - possible_groups = _.difference(self.data.important_fields, already_grouped), - dropdown_options = { - fields: _.map(possible_groups, function (field) { - return {id: field, value: self.get_descr(field)}; - })}; - if (options.row_id) { - dropdown_options.row_id= options.row_id; - } else { - dropdown_options.col_id = options.col_id; - } - - this.dropdown = $(QWeb.render('field_selection', dropdown_options)); - options.target.after(this.dropdown); - this.dropdown.css({position:'absolute', - left:options.x, - top:options.y}); - $('.field-selection').next('.dropdown-menu').toggle(); - }, - - build_table: function () { - var self = this; - this.rows = []; - - - var col_id = this.generate_id(); - - this.cols= [{ - id: col_id, - path: [], - value: this.data.measure_label, - expanded: false, - parent: null, - children: [], - cells: [], // a cell is {td:, row_id:} - domain: this.data.domain, - }]; - - self.make_top_headers(); - - var main_row = this.make_row(this.data.total[0]); - - _.each(this.data.groups, function (group) { - self.make_row(group, main_row.id); - }); - }, - - get_descr: function (field_id) { - return this.data.fields[field_id].string; - }, - - get_groups: function (groupby) { - var view_fields = this.data.row_groupby.concat(this.data.measure, this.data.col_groupby); - return query_groups(this.data.model, view_fields, this.data.domain, groupby); + draw_table: function () { + this.draw_top_headers(); + _.each(this.pivot_table.rows, this.proxy('draw_row')); }, - make_top_headers : function () { + draw_top_headers: function () { var self = this, - header; - - function partition (columns) { - return _.reduce(columns, function (partial, col) { - if (partial.length === 0) return [[col]]; - if (col.path.length > _.first(_.last(partial)).path.length) { - _.last(partial).push(col); - } else { - partial.push([col]); - } - return partial; - }, []); - } + pivot = this.pivot_table; - function side_by_side(blocks) { - var result = _.zip.apply(_,blocks); - result = _.map(result, function(line) {return _.compact(_.flatten(line))}); - return result; - } - - function make_header_cell(col, span) { - var options = { - is_border:true, - foldable:true, - row_span: (span === undefined) ? 1 : span, - col_id: col.id, - }; - var result = self.make_cell(col.value, options); - if (col.expanded) { - result.find('.icon-plus-sign') - .removeClass('icon-plus-sign') - .addClass('icon-minus-sign'); - } - return result; - } - - function calculate_width(cols) { - if (cols.length === 1) { - return 1; - } - var p = partition(_.rest(cols)); - return _.reduce(p, function(x, y){ return x + calculate_width(y); }, 0); - } - - function make_header_cells(cols, height) { - var p = partition(cols); - if ((p.length === 1) && (p[0].length === 1)) { - var result = [[make_header_cell(cols[0], height)]]; - return result; - } - if ((p.length === 1) && (p[0].length > 1)) { - var cell = make_header_cell(p[0][0]); - cell.attr('colspan', calculate_width(cols)); - return [[cell]].concat(make_header_cells(_.rest(cols), height - 1)); - } - if (p.length > 1) { - return side_by_side(_.map(p, function (group) { - return make_header_cells(group, height); - })); + function get_column_tree(cols, level) { + var height, + width, + children = _.map(cols[0].children, function (child) { + get_column_tree(child, level - 1); + }); + if (children.length > 0) { + height = 1; + width = _.reduce(children, function (x,y) { return x + y;}, 0); + } else { + height = level; + width = 1; } + return {level: level, + width: width, + height: height, + col:cols[0], + children: children}; } - if (this.cols.length === 1) { - header = $(''); - header.append(this.make_cell('', {is_border:true})); - header.append(this.make_cell(this.cols[0].value, - {is_border:true, foldable:true, col_id:this.cols[0].id})); - header.addClass('graph_top'); - this.headers = [header]; - } else { - var height = _.max(_.map(self.cols, function(g) {return g.path.length;})); - var header_rows = make_header_cells(_.rest(this.cols), height); - - header_rows[0].splice(0,0,self.make_cell('', {is_border:true, }).attr('rowspan', height)) - self.headers = []; - _.each(header_rows, function (cells) { - header = $(''); - header.append(cells); - header.addClass('graph_top'); - self.headers.push(header); - }); - } - }, - - draw_top_headers: function () { - var self = this; - $("tr.graph_top").remove(); - _.each(this.headers.reverse(), function (header) { - self.$el.prepend(header); - }); - - }, - - make_row: function (groups, parent_id) { - var self = this, - path, - value, - expanded, - domain, - parent, - has_parent = (parent_id !== undefined), - row_id = this.generate_id(); - - if (has_parent) { - parent = this.get_row(parent_id); - path = parent.path.concat(groups[0].attributes.value[1]); - value = groups[0].attributes.value[1]; - expanded = false; - parent.children.push(row_id); - domain = groups[0].model._domain; - } else { - parent = null; - path = []; - value = 'Total'; - expanded = true; - domain = this.data.domain; + function make_cell(elem) { + var title = $(' ') + .addClass('web_graph_click') + .attr('href', '#') + .attr('data-col-id', elem.col.id) + .addClass((elem.col.is_expanded) ? 'icon-minus-sign' : 'icon-plus-sign') + .append(elem.col.name); + return $('').addClass('graph_border') + .append(title) + .attr('rowspan', elem.height) + .attr('colspan', elem.width); } - var jquery_row = $(''); + var height = _.max(_.map(pivot.cols, function(g) {return g.path.length;})); + height = (height === 0) ? 1 : height; - var header = self.make_cell(value, {is_border:true, indent: path.length, foldable:true, row_id: row_id}); - jquery_row.append(header); + var col_tree = get_column_tree(pivot.cols, height); - var cell; + var header_cells = [[$('') + .attr('rowspan', height) + .addClass('graph_border')]]; - _.each(this.cols, function (col) { - var element = _.find(groups, function (group) { - return _.isEqual(_.rest(group.path), col.path); - }); - if (element === undefined) { - cell = self.make_cell(''); + function make_cells (queue, level) { + var tree = queue.shift(); + queue = queue.concat(tree.children); + if (tree.level == level) { + _.last(header_cells).push(make_cell(tree)); } else { - cell = self.make_cell(element.attributes.aggregates[self.data.measure]); + level -=1; + header_cells.push([make_cell(tree)]); } - if (col.expanded) { - cell.css('display', 'none'); + if (queue.length !== 0) { + make_cells(queue, level); } - col.cells.push({td:cell, row_id:row_id}); - jquery_row.append(cell); - }); - - if (!has_parent) { - header.find('.icon-plus-sign') - .removeClass('icon-plus-sign') - .addClass('icon-minus-sign'); } - var row = { - id: row_id, - path: path, - value: value, - expanded: expanded, - parent: parent_id, - children: [], - html: jquery_row, - domain: domain, - }; - this.rows.push(row); // to do, insert it properly, after all childs of parent - return row; - }, - - generate_id: function () { - this.id_seed += 1; - return this.id_seed - 1; - }, - - get_row: function (id) { - return _.find(this.rows, function(row) { - return (row.id == id); - }); - }, - - get_col: function (id) { - return _.find(this.cols, function(col) { - return (col.id == id); + make_cells([col_tree], height); + _.each(header_cells, function (cells) { + var row = $("").append(cells); + self.table.append(row); }); }, - make_cell: function (content, options) { - options = _.extend({is_border: false, indent:0, foldable:false}, options); - content = (content !== undefined) ? content : 'Undefined'; - - var cell = $(''); - if (options.is_border) cell.addClass('graph_border'); - if (options.row_span) cell.attr('rowspan', options.row_span); - if (options.col_span) cell.attr('rowspan', options.col_span); - _.each(_.range(options.indent), function () { - cell.prepend($('', {class:'web_graph_indent'})); - }); - - if (options.foldable) { - var attrs = {class:'icon-plus-sign web_graph_click', href:'#'}; - if (options.row_id !== undefined) attrs['data-row-id'] = options.row_id; - if (options.col_id !== undefined) attrs['data-col-id'] = options.col_id; - var plus = $('', attrs); - plus.append(' '); - plus.append(content); - cell.append(plus); - } else { - cell.append(content); + draw_row: function (row) { + var pivot = this.pivot_table, + html_row = $(''), + name = $(' ') + .addClass('web_graph_click') + .attr('href', '#') + .attr('data-row-id', row.id) + .addClass((row.is_expanded) ? 'icon-minus-sign' : 'icon-plus-sign') + .append(row.name), + row_header = $('') + .append(name) + .addClass('graph_border'); + + for (var i in _.range(row.path.length)) { + row_header.prepend($('', {class:'web_graph_indent'})); } - return cell; - }, - expand_row: function (row_id, field_id) { - var self = this; - var row = this.get_row(row_id); + html_row.append(row_header); - if (row.path.length == this.data.row_groupby.length) { - this.data.row_groupby.push(field_id); - } - row.expanded = true; - row.html.find('.icon-plus-sign') - .removeClass('icon-plus-sign') - .addClass('icon-minus-sign'); - - var visible_fields = this.data.row_groupby.concat(this.data.col_groupby, this.data.measure); - query_groups_data(this.data.model, visible_fields, row.domain, this.data.col_groupby, field_id) - .then(function (groups) { - _.each(groups.reverse(), function (group) { - var new_row = self.make_row(group, row_id); - row.html.after(new_row.html); - }); + _.each(pivot.cols, function (col) { + var cell = $('').append(pivot.get_value(row.id, col.id)); + html_row.append(cell) }); + this.table.append(html_row); + } +}); - }, - - expand_col: function (col_id, field_id) { - var self = this; - var col = this.get_col(col_id); - - if (col.path.length == this.data.col_groupby.length) { - this.data.col_groupby.push(field_id); - } - col.expanded = true; - - var visible_fields = this.data.row_groupby.concat(this.data.col_groupby, this.data.measure); - query_groups_data(this.data.model, visible_fields, col.domain, this.data.row_groupby, field_id) - .then(function (groups) { - _.each(groups, function (group) { - var new_col = { - id: self.generate_id(), - path: col.path.concat(group[0].attributes.value[1]), - value: group[0].attributes.value[1], - expanded: false, - parent: col_id, - children: [], - cells: [], // a cell is {td:, row_id:} - domain: group[0].model._domain, - }; - col.children.push(new_col.id); - insertAfter(self.cols, col, new_col) - _.each(col.cells, function (cell) { - var col_path = self.get_row(cell.row_id).path; - - var datapt = _.find(group, function (g) { - return _.isEqual(g.path.slice(1), col_path); - }); - - var value; - if (datapt === undefined) { - value = ''; - } else { - value = datapt.attributes.aggregates[self.data.measure]; - } - var new_cell = { - row_id: cell.row_id, - td: self.make_cell(value) - }; - new_col.cells.push(new_cell); - cell.td.after(new_cell.td); - cell.td.css('display','none'); - }); - - }); - self.make_top_headers(); - self.draw_top_headers(); - }); - }, - - fold_row: function (row_id) { - var self = this; - var row = this.get_row(row_id); - - _.each(row.children, function (child_row) { - self.remove_row(child_row); - }); - row.children = []; - - row.expanded = false; - row.html.find('.icon-minus-sign') - .removeClass('icon-minus-sign') - .addClass('icon-plus-sign'); - - var fold_levels = _.map(self.rows, function(g) {return g.path.length;}); - var new_groupby_length = _.max(fold_levels); - - this.data.row_groupby.splice(new_groupby_length); - }, - - remove_row: function (row_id) { - var self = this; - var row = this.get_row(row_id); - - _.each(row.children, function (child_row) { - self.remove_row(child_row); - }); - - row.html.remove(); - removeFromArray(this.rows, row); - - _.each(this.cols, function (col) { - col.cells = _.filter(col.cells, function (cell) { - return cell.row_id !== row_id; - }); - }); - }, - - fold_col: function (col_id) { - var self = this; - var col = this.get_col(col_id); - - _.each(col.children, function (child_col) { - self.remove_col(child_col); - }); - col.children = []; - _.each(col.cells, function (cell) { - cell.td.css('display','table-cell'); - }); - col.expanded = false; - // row.html.find('.icon-minus-sign') - // .removeClass('icon-minus-sign') - // .addClass('icon-plus-sign'); - var fold_levels = _.map(self.cols, function(g) {return g.path.length;}); - var new_groupby_length = _.max(fold_levels); +// make_top_headers : function () { +// var self = this, +// header; + +// function partition (columns) { +// return _.reduce(columns, function (partial, col) { +// if (partial.length === 0) return [[col]]; +// if (col.path.length > _.first(_.last(partial)).path.length) { +// _.last(partial).push(col); +// } else { +// partial.push([col]); +// } +// return partial; +// }, []); +// } + +// function side_by_side(blocks) { +// var result = _.zip.apply(_,blocks); +// result = _.map(result, function(line) {return _.compact(_.flatten(line))}); +// return result; +// } + +// function make_header_cell(col, span) { +// var options = { +// is_border:true, +// foldable:true, +// row_span: (span === undefined) ? 1 : span, +// col_id: col.id, +// }; +// var result = self.make_cell(col.value, options); +// if (col.expanded) { +// result.find('.icon-plus-sign') +// .removeClass('icon-plus-sign') +// .addClass('icon-minus-sign'); +// } +// return result; +// } + +// function calculate_width(cols) { +// if (cols.length === 1) { +// return 1; +// } +// var p = partition(_.rest(cols)); +// return _.reduce(p, function(x, y){ return x + calculate_width(y); }, 0); +// } + +// function make_header_cells(cols, height) { +// var p = partition(cols); +// if ((p.length === 1) && (p[0].length === 1)) { +// var result = [[make_header_cell(cols[0], height)]]; +// return result; +// } +// if ((p.length === 1) && (p[0].length > 1)) { +// var cell = make_header_cell(p[0][0]); +// cell.attr('colspan', calculate_width(cols)); +// return [[cell]].concat(make_header_cells(_.rest(cols), height - 1)); +// } +// if (p.length > 1) { +// return side_by_side(_.map(p, function (group) { +// return make_header_cells(group, height); +// })); +// } +// } + +// if (this.cols.length === 1) { +// header = $(''); +// header.append(this.make_cell('', {is_border:true})); +// header.append(this.make_cell(this.cols[0].value, +// {is_border:true, foldable:true, col_id:this.cols[0].id})); +// header.addClass('graph_top'); +// this.headers = [header]; +// } else { +// var height = _.max(_.map(self.cols, function(g) {return g.path.length;})); +// var header_rows = make_header_cells(_.rest(this.cols), height); + +// header_rows[0].splice(0,0,self.make_cell('', {is_border:true, }).attr('rowspan', height)) +// self.headers = []; +// _.each(header_rows, function (cells) { +// header = $(''); +// header.append(cells); +// header.addClass('graph_top'); +// self.headers.push(header); +// }); +// } +// }, + + + // mode: 'pivot', // pivot, bar_chart, line_chart or pie_chart + // pivot_table: null, + + // events: { + // 'click .graph_mode_selection li' : function (event) { + // event.preventDefault(); + // this.mode = event.target.attributes['data-mode'].nodeValue; + // this.display_data(); + // }, + // }, + + // display_data : function () { + // var content = this.$el.filter('.graph_main_content'); + // content.find('svg').remove(); + // var self = this; + // if (this.mode === 'pivot') { + // this.pivot_table.show(); + // } else { + // this.pivot_table.hide(); + // content.append(''); + // var view_fields = this.data.row_groupby.concat(this.data.measure, this.data.col_groupby); + // query_groups(this.data.model, view_fields, this.data.domain, this.data.row_groupby).then(function (groups) { + // Charts[self.mode](groups, self.data.measure, self.data.measure_label); + // }); + + // } + // }, + + + // if (this.pivot_table) { + // this.pivot_table.draw(true); + // } else { + + // this.pivot_table = new PivotTable(this.data); + // this.pivot_table.appendTo('.graph_main_content'); + // } + // this.display_data(); - this.data.col_groupby.splice(new_groupby_length); - this.make_top_headers(); - this.draw_top_headers(); + /** + * PivotTable widget. It displays the data in tabular data and allows the + * user to drill down and up in the table + */ +// var PivotTable = instance.web.Widget.extend({ +// template: 'pivot_table', + +// init: function (data) { +// var self = this; +// makePivotTable(this.data).done(function (table) { +// self.pivottable = table; +// }); +// }, + +// }); + +// var PivotTable = instance.web.Widget.extend({ +// template: 'pivot_table', +// data: null, +// headers: [], +// rows: [], +// cols: [], +// id_seed : 0, + +// events: { +// 'click .web_graph_click' : function (event) { +// event.preventDefault(); + +// if (event.target.attributes['data-row-id'] !== undefined) { +// this.handle_row_event(event); +// } +// if (event.target.attributes['data-col-id'] !== undefined) { +// this.handle_col_event(event); +// } +// }, + +// 'click a.field-selection' : function (event) { +// var id, +// field_id = event.target.attributes['data-field-id'].nodeValue; +// event.preventDefault(); +// this.dropdown.remove(); +// if (event.target.attributes['data-row-id'] !== undefined) { +// id = event.target.attributes['data-row-id'].nodeValue; +// this.expand_row(id, field_id); +// } +// if (event.target.attributes['data-col-id'] !== undefined) { +// id = event.target.attributes['data-col-id'].nodeValue; +// this.expand_col(id, field_id); +// } +// }, +// }, + +// handle_row_event: function (event) { +// var row_id = event.target.attributes['data-row-id'].nodeValue, +// row = this.get_row(row_id); + +// if (row.expanded) { +// this.fold_row(row_id); +// } else { +// if (row.path.length < this.data.row_groupby.length) { +// var field_to_expand = this.data.row_groupby[row.path.length]; +// this.expand_row(row_id, field_to_expand); +// } else { +// this.display_dropdown({row_id:row_id, +// target: $(event.target), +// x: event.pageX, +// y: event.pageY}); +// } +// } +// }, + +// handle_col_event: function (event) { +// var col_id = event.target.attributes['data-col-id'].nodeValue, +// col = this.get_col(col_id); + +// if (col.expanded) { +// this.fold_col(col_id); +// } else { +// if (col.path.length < this.data.col_groupby.length) { +// var field_to_expand = this.data.col_groupby[col.path.length]; +// this.expand_col(col_id, field_to_expand); +// } else { +// this.display_dropdown({col_id: col_id, +// target: $(event.target), +// x: event.pageX, +// y: event.pageY}); +// } +// } +// }, + +// init: function (data) { +// this.data = data; +// makePivotTable(this.data).done(function (table) { +// self.pivottable = table; +// }); + +// }, + +// start: function () { +// this.draw(true); +// }, + +// draw: function (load_data) { +// var self = this; + +// if (load_data) { +// var view_fields = this.data.row_groupby.concat(this.data.measure, this.data.col_groupby); +// query_groups_data(this.data.model, view_fields, this.data.domain, this.data.col_groupby, this.data.row_groupby[0]) +// .then(function (groups) { +// self.data.groups = groups; +// return self.get_groups([]); +// }).then(function (total) { +// total[0].path = []; +// self.data.total = [total]; +// self.build_table(); +// self.draw(false); +// }); +// } else { +// this.$el.empty(); + +// this.draw_top_headers(); + +// _.each(this.rows, function (row) { +// self.$el.append(row.html); +// }); +// } +// }, + +// show: function () { +// this.$el.css('display', 'block'); +// }, + +// hide: function () { +// this.$el.css('display', 'none'); +// }, + +// display_dropdown: function (options) { +// var self = this, +// already_grouped = self.data.row_groupby.concat(self.data.col_groupby), +// possible_groups = _.difference(self.data.important_fields, already_grouped), +// dropdown_options = { +// fields: _.map(possible_groups, function (field) { +// return {id: field, value: self.get_descr(field)}; +// })}; +// if (options.row_id) { +// dropdown_options.row_id= options.row_id; +// } else { +// dropdown_options.col_id = options.col_id; +// } + +// this.dropdown = $(QWeb.render('field_selection', dropdown_options)); +// options.target.after(this.dropdown); +// this.dropdown.css({position:'absolute', +// left:options.x, +// top:options.y}); +// $('.field-selection').next('.dropdown-menu').toggle(); +// }, + +// build_table: function () { +// var self = this; +// this.rows = []; + + +// var col_id = this.generate_id(); + +// this.cols= [{ +// id: col_id, +// path: [], +// value: this.data.measure_label, +// expanded: false, +// parent: null, +// children: [], +// cells: [], // a cell is {td:, row_id:} +// domain: this.data.domain, +// }]; + +// self.make_top_headers(); + +// var main_row = this.make_row(this.data.total[0]); + +// _.each(this.data.groups, function (group) { +// self.make_row(group, main_row.id); +// }); +// }, + +// get_descr: function (field_id) { +// return this.data.fields[field_id].string; +// }, + +// get_groups: function (groupby) { +// var view_fields = this.data.row_groupby.concat(this.data.measure, this.data.col_groupby); +// return query_groups(this.data.model, view_fields, this.data.domain, groupby); +// }, + +// make_top_headers : function () { +// var self = this, +// header; + +// function partition (columns) { +// return _.reduce(columns, function (partial, col) { +// if (partial.length === 0) return [[col]]; +// if (col.path.length > _.first(_.last(partial)).path.length) { +// _.last(partial).push(col); +// } else { +// partial.push([col]); +// } +// return partial; +// }, []); +// } + +// function side_by_side(blocks) { +// var result = _.zip.apply(_,blocks); +// result = _.map(result, function(line) {return _.compact(_.flatten(line))}); +// return result; +// } + +// function make_header_cell(col, span) { +// var options = { +// is_border:true, +// foldable:true, +// row_span: (span === undefined) ? 1 : span, +// col_id: col.id, +// }; +// var result = self.make_cell(col.value, options); +// if (col.expanded) { +// result.find('.icon-plus-sign') +// .removeClass('icon-plus-sign') +// .addClass('icon-minus-sign'); +// } +// return result; +// } + +// function calculate_width(cols) { +// if (cols.length === 1) { +// return 1; +// } +// var p = partition(_.rest(cols)); +// return _.reduce(p, function(x, y){ return x + calculate_width(y); }, 0); +// } + +// function make_header_cells(cols, height) { +// var p = partition(cols); +// if ((p.length === 1) && (p[0].length === 1)) { +// var result = [[make_header_cell(cols[0], height)]]; +// return result; +// } +// if ((p.length === 1) && (p[0].length > 1)) { +// var cell = make_header_cell(p[0][0]); +// cell.attr('colspan', calculate_width(cols)); +// return [[cell]].concat(make_header_cells(_.rest(cols), height - 1)); +// } +// if (p.length > 1) { +// return side_by_side(_.map(p, function (group) { +// return make_header_cells(group, height); +// })); +// } +// } + +// if (this.cols.length === 1) { +// header = $(''); +// header.append(this.make_cell('', {is_border:true})); +// header.append(this.make_cell(this.cols[0].value, +// {is_border:true, foldable:true, col_id:this.cols[0].id})); +// header.addClass('graph_top'); +// this.headers = [header]; +// } else { +// var height = _.max(_.map(self.cols, function(g) {return g.path.length;})); +// var header_rows = make_header_cells(_.rest(this.cols), height); + +// header_rows[0].splice(0,0,self.make_cell('', {is_border:true, }).attr('rowspan', height)) +// self.headers = []; +// _.each(header_rows, function (cells) { +// header = $(''); +// header.append(cells); +// header.addClass('graph_top'); +// self.headers.push(header); +// }); +// } +// }, + +// draw_top_headers: function () { +// var self = this; +// $("tr.graph_top").remove(); +// _.each(this.headers.reverse(), function (header) { +// self.$el.prepend(header); +// }); + +// }, + +// make_row: function (groups, parent_id) { +// var self = this, +// path, +// value, +// expanded, +// domain, +// parent, +// has_parent = (parent_id !== undefined), +// row_id = this.generate_id(); + +// if (has_parent) { +// parent = this.get_row(parent_id); +// path = parent.path.concat(groups[0].attributes.value[1]); +// value = groups[0].attributes.value[1]; +// expanded = false; +// parent.children.push(row_id); +// domain = groups[0].model._domain; +// } else { +// parent = null; +// path = []; +// value = 'Total'; +// expanded = true; +// domain = this.data.domain; +// } + +// var jquery_row = $(''); + +// var header = self.make_cell(value, {is_border:true, indent: path.length, foldable:true, row_id: row_id}); +// jquery_row.append(header); + +// var cell; + +// _.each(this.cols, function (col) { +// var element = _.find(groups, function (group) { +// return _.isEqual(_.rest(group.path), col.path); +// }); +// if (element === undefined) { +// cell = self.make_cell(''); +// } else { +// cell = self.make_cell(element.attributes.aggregates[self.data.measure]); +// } +// if (col.expanded) { +// cell.css('display', 'none'); +// } +// col.cells.push({td:cell, row_id:row_id}); +// jquery_row.append(cell); +// }); + +// if (!has_parent) { +// header.find('.icon-plus-sign') +// .removeClass('icon-plus-sign') +// .addClass('icon-minus-sign'); +// } + +// var row = { +// id: row_id, +// path: path, +// value: value, +// expanded: expanded, +// parent: parent_id, +// children: [], +// html: jquery_row, +// domain: domain, +// }; +// this.rows.push(row); // to do, insert it properly, after all childs of parent +// return row; +// }, + +// generate_id: function () { +// this.id_seed += 1; +// return this.id_seed - 1; +// }, + +// get_row: function (id) { +// return _.find(this.rows, function(row) { +// return (row.id == id); +// }); +// }, + +// get_col: function (id) { +// return _.find(this.cols, function(col) { +// return (col.id == id); +// }); +// }, + +// make_cell: function (content, options) { +// options = _.extend({is_border: false, indent:0, foldable:false}, options); +// content = (content !== undefined) ? content : 'Undefined'; + +// var cell = $(''); +// if (options.is_border) cell.addClass('graph_border'); +// if (options.row_span) cell.attr('rowspan', options.row_span); +// if (options.col_span) cell.attr('rowspan', options.col_span); +// _.each(_.range(options.indent), function () { +// cell.prepend($('', {class:'web_graph_indent'})); +// }); + +// if (options.foldable) { +// var attrs = {class:'icon-plus-sign web_graph_click', href:'#'}; +// if (options.row_id !== undefined) attrs['data-row-id'] = options.row_id; +// if (options.col_id !== undefined) attrs['data-col-id'] = options.col_id; +// var plus = $('', attrs); +// plus.append(' '); +// plus.append(content); +// cell.append(plus); +// } else { +// cell.append(content); +// } +// return cell; +// }, + +// expand_row: function (row_id, field_id) { +// var self = this; +// var row = this.get_row(row_id); + +// if (row.path.length == this.data.row_groupby.length) { +// this.data.row_groupby.push(field_id); +// } +// row.expanded = true; +// row.html.find('.icon-plus-sign') +// .removeClass('icon-plus-sign') +// .addClass('icon-minus-sign'); + +// var visible_fields = this.data.row_groupby.concat(this.data.col_groupby, this.data.measure); +// query_groups_data(this.data.model, visible_fields, row.domain, this.data.col_groupby, field_id) +// .then(function (groups) { +// _.each(groups.reverse(), function (group) { +// var new_row = self.make_row(group, row_id); +// row.html.after(new_row.html); +// }); +// }); + +// }, + +// expand_col: function (col_id, field_id) { +// var self = this; +// var col = this.get_col(col_id); + +// if (col.path.length == this.data.col_groupby.length) { +// this.data.col_groupby.push(field_id); +// } +// col.expanded = true; + +// var visible_fields = this.data.row_groupby.concat(this.data.col_groupby, this.data.measure); +// query_groups_data(this.data.model, visible_fields, col.domain, this.data.row_groupby, field_id) +// .then(function (groups) { +// _.each(groups, function (group) { +// var new_col = { +// id: self.generate_id(), +// path: col.path.concat(group[0].attributes.value[1]), +// value: group[0].attributes.value[1], +// expanded: false, +// parent: col_id, +// children: [], +// cells: [], // a cell is {td:, row_id:} +// domain: group[0].model._domain, +// }; +// col.children.push(new_col.id); +// insertAfter(self.cols, col, new_col) +// _.each(col.cells, function (cell) { +// var col_path = self.get_row(cell.row_id).path; + +// var datapt = _.find(group, function (g) { +// return _.isEqual(g.path.slice(1), col_path); +// }); + +// var value; +// if (datapt === undefined) { +// value = ''; +// } else { +// value = datapt.attributes.aggregates[self.data.measure]; +// } +// var new_cell = { +// row_id: cell.row_id, +// td: self.make_cell(value) +// }; +// new_col.cells.push(new_cell); +// cell.td.after(new_cell.td); +// cell.td.css('display','none'); +// }); + +// }); +// self.make_top_headers(); +// self.draw_top_headers(); +// }); +// }, + +// fold_row: function (row_id) { +// var self = this; +// var row = this.get_row(row_id); + +// _.each(row.children, function (child_row) { +// self.remove_row(child_row); +// }); +// row.children = []; + +// row.expanded = false; +// row.html.find('.icon-minus-sign') +// .removeClass('icon-minus-sign') +// .addClass('icon-plus-sign'); + +// var fold_levels = _.map(self.rows, function(g) {return g.path.length;}); +// var new_groupby_length = _.max(fold_levels); + +// this.data.row_groupby.splice(new_groupby_length); +// }, + +// remove_row: function (row_id) { +// var self = this; +// var row = this.get_row(row_id); + +// _.each(row.children, function (child_row) { +// self.remove_row(child_row); +// }); + +// row.html.remove(); +// removeFromArray(this.rows, row); + +// _.each(this.cols, function (col) { +// col.cells = _.filter(col.cells, function (cell) { +// return cell.row_id !== row_id; +// }); +// }); +// }, + +// fold_col: function (col_id) { +// var self = this; +// var col = this.get_col(col_id); + +// _.each(col.children, function (child_col) { +// self.remove_col(child_col); +// }); +// col.children = []; + +// _.each(col.cells, function (cell) { +// cell.td.css('display','table-cell'); +// }); +// col.expanded = false; +// // row.html.find('.icon-minus-sign') +// // .removeClass('icon-minus-sign') +// // .addClass('icon-plus-sign'); + +// var fold_levels = _.map(self.cols, function(g) {return g.path.length;}); +// var new_groupby_length = _.max(fold_levels); + +// this.data.col_groupby.splice(new_groupby_length); +// this.make_top_headers(); +// this.draw_top_headers(); - }, +// }, - remove_col: function (col_id) { - var self = this; - var col = this.get_col(col_id); +// remove_col: function (col_id) { +// var self = this; +// var col = this.get_col(col_id); - _.each(col.children, function (child_col) { - self.remove_col(child_col); - }); +// _.each(col.children, function (child_col) { +// self.remove_col(child_col); +// }); - _.each(col.cells, function (cell) { - cell.td.remove(); - }); - // row.html.remove(); - removeFromArray(this.cols, col); - - // _.each(this.cols, function (col) { - // col.cells = _.filter(col.cells, function (cell) { - // return cell.row_id !== row_id; - // }); - // }); - }, +// _.each(col.cells, function (cell) { +// cell.td.remove(); +// }); +// // row.html.remove(); +// removeFromArray(this.cols, col); +// // _.each(this.cols, function (col) { +// // col.cells = _.filter(col.cells, function (cell) { +// // return cell.row_id !== row_id; +// // }); +// // }); +// }, -}); + +// }); }; -- cgit v1.2.3 From a32018f96237b72ee2ad021987d97539ff433129 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 22 Nov 2013 10:43:22 +0100 Subject: [REF] large refactoring in progress. goal is to separate the data handling code (pivot) from the ui code (drawing, buttons, events (addon web_graph) bzr revid: ged@openerp.com-20131122094322-wn36gtmtv9pgn5su --- addons/web_graph/static/src/js/graph.js | 99 +++++++++++++-------------------- 1 file changed, 39 insertions(+), 60 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 3363f7cb3a8..7ad283c6810 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -125,87 +125,66 @@ instance.web_graph.GraphView = instance.web.View.extend({ draw_table: function () { this.draw_top_headers(); - _.each(this.pivot_table.rows, this.proxy('draw_row')); + this.pivot_table.iterate(this.pivot_table.rows, this.proxy('draw_row')); }, - draw_top_headers: function () { - var self = this, - pivot = this.pivot_table; + make_border_cell: function (colspan, rowspan) { + return $('').addClass('graph_border') + .attr('colspan', colspan) + .attr('rowspan', rowspan); + }, - function get_column_tree(cols, level) { - var height, - width, - children = _.map(cols[0].children, function (child) { - get_column_tree(child, level - 1); - }); - if (children.length > 0) { - height = 1; - width = _.reduce(children, function (x,y) { return x + y;}, 0); - } else { - height = level; - width = 1; - } - return {level: level, - width: width, - height: height, - col:cols[0], - children: children}; - } + make_header_title: function (header) { + return $(' ') + .addClass('web_graph_click') + .attr('href', '#') + .addClass((header.is_expanded) ? 'icon-minus-sign' : 'icon-plus-sign') + .append(header.name); + }, - function make_cell(elem) { - var title = $(' ') - .addClass('web_graph_click') - .attr('href', '#') - .attr('data-col-id', elem.col.id) - .addClass((elem.col.is_expanded) ? 'icon-minus-sign' : 'icon-plus-sign') - .append(elem.col.name); - return $('').addClass('graph_border') - .append(title) - .attr('rowspan', elem.height) - .attr('colspan', elem.width); + draw_top_headers: function () { + var self = this, + pivot = this.pivot_table, + height = pivot.get_max_path_length(pivot.cols), + header_cells = [[this.make_border_cell(1, height)]]; + + function make_col_header (col) { + var cell = self.make_border_cell(col.width, col.height); + return cell.append(self.make_header_title(col)) + .attr('data-col-id', col.id); } - var height = _.max(_.map(pivot.cols, function(g) {return g.path.length;})); - height = (height === 0) ? 1 : height; - - var col_tree = get_column_tree(pivot.cols, height); - - var header_cells = [[$('') - .attr('rowspan', height) - .addClass('graph_border')]]; - function make_cells (queue, level) { - var tree = queue.shift(); - queue = queue.concat(tree.children); - if (tree.level == level) { - _.last(header_cells).push(make_cell(tree)); + var col = queue.shift(); + queue = queue.concat(col.children); + console.log("col",col, level); + if (col.path.length == level) { + _.last(header_cells).push(make_col_header(col)); } else { - level -=1; - header_cells.push([make_cell(tree)]); + level +=1; + header_cells.push([make_col_header(col)]); } if (queue.length !== 0) { make_cells(queue, level); } } - make_cells([col_tree], height); + if (pivot.cols.children.length === 0) { + make_cells([pivot.cols], 0); + } else { + make_cells(pivot.cols.children, 1); + } + _.each(header_cells, function (cells) { - var row = $("").append(cells); - self.table.append(row); + self.table.append($("").append(cells)); }); }, draw_row: function (row) { var pivot = this.pivot_table, html_row = $(''), - name = $(' ') - .addClass('web_graph_click') - .attr('href', '#') - .attr('data-row-id', row.id) - .addClass((row.is_expanded) ? 'icon-minus-sign' : 'icon-plus-sign') - .append(row.name), row_header = $('') - .append(name) + .append(this.make_header_title(row)) .addClass('graph_border'); for (var i in _.range(row.path.length)) { @@ -214,7 +193,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ html_row.append(row_header); - _.each(pivot.cols, function (col) { + pivot.iterate(pivot.cols, function (col) { var cell = $('').append(pivot.get_value(row.id, col.id)); html_row.append(cell) }); -- cgit v1.2.3 From 2c5fb3b2a29aae9a27b957f4db456643c35db746 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 22 Nov 2013 14:59:27 +0100 Subject: [REF] large refactoring in progress. goal is to separate the data handling code (pivot) from the ui code (drawing, buttons, events (addon web_graph) bzr revid: ged@openerp.com-20131122135927-mfaa44juzjhp4kas --- addons/web_graph/static/src/js/graph.js | 101 +++++++++++++++++++++++++++++--- 1 file changed, 93 insertions(+), 8 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 7ad283c6810..91c794ea2ae 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -27,7 +27,34 @@ instance.web_graph.GraphView = instance.web.View.extend({ 'click .graph_mode_selection li' : function (event) { event.preventDefault(); this.mode = event.target.attributes['data-mode'].nodeValue; - console.log("change mode",this.mode); + }, + + 'click .web_graph_click' : function (event) { + event.preventDefault(); + if (event.target.attributes['data-row-id'] !== undefined) { + this.handle_header_event({type:'row', event:event}); + + } + if (event.target.attributes['data-col-id'] !== undefined) { + this.handle_header_event({type:'col', event:event}); + } + }, + + 'click a.field-selection' : function (event) { + var id, + field_id = event.target.attributes['data-field-id'].nodeValue; + event.preventDefault(); + this.dropdown.remove(); + if (event.target.attributes['data-row-id'] !== undefined) { + id = event.target.attributes['data-row-id'].nodeValue; + this.pivot_table.expand_row(id, field_id) + .then(this.proxy('draw_table')); + } + if (event.target.attributes['data-col-id'] !== undefined) { + id = event.target.attributes['data-col-id'].nodeValue; + this.pivot_table.expand_col(id, field_id) + .then(this.proxy('draw_table')); + } }, }, @@ -123,9 +150,56 @@ instance.web_graph.GraphView = instance.web.View.extend({ return this._super(); }, + + handle_header_event: function (options) { + var pivot = this.pivot_table, + id = options.event.target.attributes['data-' + options.type + '-id'].nodeValue, + header = pivot['get_' + options.type](id); + + if (header.is_expanded) { + pivot['fold_' + options.type](header); + this.draw_table(); + } else { + if (header.path.length < pivot[options.type + '_groupby'].length) { + // expand the corresponding header + var field = pivot[options.type + '_groupby'][header.path.length]; + pivot['expand_' + options.type](id, field) + .then(this.proxy('draw_table')); + } else { + // display dropdown to query field to expand + this.display_dropdown({id:header.id, + type: options.type, + target: $(event.target), + x: event.pageX, + y: event.pageY}); + } + } + + }, + + display_dropdown: function (options) { + var self = this, + pivot = this.pivot_table, + already_grouped = pivot.row_groupby.concat(pivot.col_groupby), + possible_groups = _.difference(self.data.important_fields, already_grouped), + dropdown_options = { + fields: _.map(possible_groups, function (field) { + return {id: field, value: self.data.fields[field].string}; + })}; + dropdown_options[options.type + '_id'] = options.id; + + this.dropdown = $(QWeb.render('field_selection', dropdown_options)); + options.target.after(this.dropdown); + this.dropdown.css({position:'absolute', + left:options.x, + top:options.y}); + $('.field-selection').next('.dropdown-menu').toggle(); + }, + draw_table: function () { + this.table.empty(); this.draw_top_headers(); - this.pivot_table.iterate(this.pivot_table.rows, this.proxy('draw_row')); + _.each(this.pivot_table.rows_array(), this.proxy('draw_row')); }, make_border_cell: function (colspan, rowspan) { @@ -148,16 +222,25 @@ instance.web_graph.GraphView = instance.web.View.extend({ height = pivot.get_max_path_length(pivot.cols), header_cells = [[this.make_border_cell(1, height)]]; + function set_dim (cols) { + _.each(cols.children, set_dim); + if (cols.children.length === 0) { + cols.height = height - cols.path.length + 1; + cols.width = 1; + } else { + cols.height = 1; + cols.width = _.reduce(cols.children, function (sum,c) { return sum + c.width;}, 0); + } + } + function make_col_header (col) { var cell = self.make_border_cell(col.width, col.height); - return cell.append(self.make_header_title(col)) - .attr('data-col-id', col.id); + return cell.append(self.make_header_title(col).attr('data-col-id', col.id)); } function make_cells (queue, level) { var col = queue.shift(); queue = queue.concat(col.children); - console.log("col",col, level); if (col.path.length == level) { _.last(header_cells).push(make_col_header(col)); } else { @@ -169,6 +252,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ } } + set_dim(pivot.cols); // add width and height info to columns headers + if (pivot.cols.children.length === 0) { make_cells([pivot.cols], 0); } else { @@ -183,8 +268,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ draw_row: function (row) { var pivot = this.pivot_table, html_row = $(''), - row_header = $('') - .append(this.make_header_title(row)) + row_header = this.make_border_cell(1,1) + .append(this.make_header_title(row).attr('data-row-id', row.id)) .addClass('graph_border'); for (var i in _.range(row.path.length)) { @@ -193,7 +278,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ html_row.append(row_header); - pivot.iterate(pivot.cols, function (col) { + _.each(pivot.cols_array(), function (col) { var cell = $('').append(pivot.get_value(row.id, col.id)); html_row.append(cell) }); -- cgit v1.2.3 From 200762944abc00e5cb748af96583302237c9a669 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 22 Nov 2013 16:10:25 +0100 Subject: [REF] large refactoring in progress. goal is to separate the data handling code (pivot) from the ui code (drawing, buttons, events (addon web_graph) bzr revid: ged@openerp.com-20131122151025-8npxh5g5y2ema4tq --- addons/web_graph/static/src/js/graph.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 91c794ea2ae..7d7d575756c 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -197,9 +197,10 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, draw_table: function () { + console.log("cols",this.pivot_table.cols); this.table.empty(); this.draw_top_headers(); - _.each(this.pivot_table.rows_array(), this.proxy('draw_row')); + _.each(this.pivot_table.rows, this.proxy('draw_row')); }, make_border_cell: function (colspan, rowspan) { @@ -219,7 +220,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ draw_top_headers: function () { var self = this, pivot = this.pivot_table, - height = pivot.get_max_path_length(pivot.cols), + height = _.max(_.map(pivot.cols, function(g) {return g.path.length;})), header_cells = [[this.make_border_cell(1, height)]]; function set_dim (cols) { @@ -239,8 +240,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ } function make_cells (queue, level) { - var col = queue.shift(); - queue = queue.concat(col.children); + var col = queue[0]; + queue = _.rest(queue).concat(col.children); if (col.path.length == level) { _.last(header_cells).push(make_col_header(col)); } else { @@ -252,12 +253,11 @@ instance.web_graph.GraphView = instance.web.View.extend({ } } - set_dim(pivot.cols); // add width and height info to columns headers - - if (pivot.cols.children.length === 0) { - make_cells([pivot.cols], 0); + set_dim(pivot.cols[0]); // add width and height info to columns headers + if (pivot.cols[0].children.length === 0) { + make_cells(pivot.cols, 0); } else { - make_cells(pivot.cols.children, 1); + make_cells(pivot.cols[0].children, 1); } _.each(header_cells, function (cells) { @@ -278,9 +278,11 @@ instance.web_graph.GraphView = instance.web.View.extend({ html_row.append(row_header); - _.each(pivot.cols_array(), function (col) { - var cell = $('').append(pivot.get_value(row.id, col.id)); - html_row.append(cell) + _.each(pivot.cols, function (col) { + if (col.children.length === 0) { + var cell = $('').append(pivot.get_value(row.id, col.id)); + html_row.append(cell); + } }); this.table.append(html_row); } -- cgit v1.2.3 From 7299cde4cf2063dbccc797b6612c2b41c3564a8e Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 22 Nov 2013 17:04:49 +0100 Subject: [REF] large refactoring. it separates the data handling code (pivot) from the ui code (drawing, buttons, events (addon web_graph) bzr revid: ged@openerp.com-20131122160449-lv2t09bs67ux42m5 --- addons/web_graph/static/src/js/graph.js | 713 +------------------------------- 1 file changed, 18 insertions(+), 695 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 7d7d575756c..cfabdead833 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -26,7 +26,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ events: { 'click .graph_mode_selection li' : function (event) { event.preventDefault(); - this.mode = event.target.attributes['data-mode'].nodeValue; + var mode = event.target.attributes['data-mode'].nodeValue; + this.switch_mode(mode); }, 'click .web_graph_click' : function (event) { @@ -125,7 +126,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ start: function () { this.table = $('
'); - this.svg = $(''); + this.svg = $('
'); this.$el.filter('.graph_main_content').append(this.table); this.$el.filter('.graph_main_content').append(this.svg); return this.load_view(); @@ -150,6 +151,21 @@ instance.web_graph.GraphView = instance.web.View.extend({ return this._super(); }, + switch_mode: function (mode) { + var self = this; + this.mode = mode; + if (mode === 'pivot') { + this.table.css('display', 'block'); + this.svg.css('display','none'); + } else { + this.table.css('display', 'none'); + this.svg.remove(); + this.svg = $('
'); + this.$el.filter('.graph_main_content').append(this.svg); + Charts[mode](this.pivot_table.get_chart_data()); + + } + }, handle_header_event: function (options) { var pivot = this.pivot_table, @@ -174,7 +190,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ y: event.pageY}); } } - }, display_dropdown: function (options) { @@ -288,696 +303,4 @@ instance.web_graph.GraphView = instance.web.View.extend({ } }); - - -// make_top_headers : function () { -// var self = this, -// header; - -// function partition (columns) { -// return _.reduce(columns, function (partial, col) { -// if (partial.length === 0) return [[col]]; -// if (col.path.length > _.first(_.last(partial)).path.length) { -// _.last(partial).push(col); -// } else { -// partial.push([col]); -// } -// return partial; -// }, []); -// } - -// function side_by_side(blocks) { -// var result = _.zip.apply(_,blocks); -// result = _.map(result, function(line) {return _.compact(_.flatten(line))}); -// return result; -// } - -// function make_header_cell(col, span) { -// var options = { -// is_border:true, -// foldable:true, -// row_span: (span === undefined) ? 1 : span, -// col_id: col.id, -// }; -// var result = self.make_cell(col.value, options); -// if (col.expanded) { -// result.find('.icon-plus-sign') -// .removeClass('icon-plus-sign') -// .addClass('icon-minus-sign'); -// } -// return result; -// } - -// function calculate_width(cols) { -// if (cols.length === 1) { -// return 1; -// } -// var p = partition(_.rest(cols)); -// return _.reduce(p, function(x, y){ return x + calculate_width(y); }, 0); -// } - -// function make_header_cells(cols, height) { -// var p = partition(cols); -// if ((p.length === 1) && (p[0].length === 1)) { -// var result = [[make_header_cell(cols[0], height)]]; -// return result; -// } -// if ((p.length === 1) && (p[0].length > 1)) { -// var cell = make_header_cell(p[0][0]); -// cell.attr('colspan', calculate_width(cols)); -// return [[cell]].concat(make_header_cells(_.rest(cols), height - 1)); -// } -// if (p.length > 1) { -// return side_by_side(_.map(p, function (group) { -// return make_header_cells(group, height); -// })); -// } -// } - -// if (this.cols.length === 1) { -// header = $(''); -// header.append(this.make_cell('', {is_border:true})); -// header.append(this.make_cell(this.cols[0].value, -// {is_border:true, foldable:true, col_id:this.cols[0].id})); -// header.addClass('graph_top'); -// this.headers = [header]; -// } else { -// var height = _.max(_.map(self.cols, function(g) {return g.path.length;})); -// var header_rows = make_header_cells(_.rest(this.cols), height); - -// header_rows[0].splice(0,0,self.make_cell('', {is_border:true, }).attr('rowspan', height)) -// self.headers = []; -// _.each(header_rows, function (cells) { -// header = $(''); -// header.append(cells); -// header.addClass('graph_top'); -// self.headers.push(header); -// }); -// } -// }, - - - // mode: 'pivot', // pivot, bar_chart, line_chart or pie_chart - // pivot_table: null, - - // events: { - // 'click .graph_mode_selection li' : function (event) { - // event.preventDefault(); - // this.mode = event.target.attributes['data-mode'].nodeValue; - // this.display_data(); - // }, - // }, - - // display_data : function () { - // var content = this.$el.filter('.graph_main_content'); - // content.find('svg').remove(); - // var self = this; - // if (this.mode === 'pivot') { - // this.pivot_table.show(); - // } else { - // this.pivot_table.hide(); - // content.append(''); - // var view_fields = this.data.row_groupby.concat(this.data.measure, this.data.col_groupby); - // query_groups(this.data.model, view_fields, this.data.domain, this.data.row_groupby).then(function (groups) { - // Charts[self.mode](groups, self.data.measure, self.data.measure_label); - // }); - - // } - // }, - - - // if (this.pivot_table) { - // this.pivot_table.draw(true); - // } else { - - // this.pivot_table = new PivotTable(this.data); - // this.pivot_table.appendTo('.graph_main_content'); - // } - // this.display_data(); - - /** - * PivotTable widget. It displays the data in tabular data and allows the - * user to drill down and up in the table - */ -// var PivotTable = instance.web.Widget.extend({ -// template: 'pivot_table', - -// init: function (data) { -// var self = this; -// makePivotTable(this.data).done(function (table) { -// self.pivottable = table; -// }); -// }, - -// }); - -// var PivotTable = instance.web.Widget.extend({ -// template: 'pivot_table', -// data: null, -// headers: [], -// rows: [], -// cols: [], -// id_seed : 0, - -// events: { -// 'click .web_graph_click' : function (event) { -// event.preventDefault(); - -// if (event.target.attributes['data-row-id'] !== undefined) { -// this.handle_row_event(event); -// } -// if (event.target.attributes['data-col-id'] !== undefined) { -// this.handle_col_event(event); -// } -// }, - -// 'click a.field-selection' : function (event) { -// var id, -// field_id = event.target.attributes['data-field-id'].nodeValue; -// event.preventDefault(); -// this.dropdown.remove(); -// if (event.target.attributes['data-row-id'] !== undefined) { -// id = event.target.attributes['data-row-id'].nodeValue; -// this.expand_row(id, field_id); -// } -// if (event.target.attributes['data-col-id'] !== undefined) { -// id = event.target.attributes['data-col-id'].nodeValue; -// this.expand_col(id, field_id); -// } -// }, -// }, - -// handle_row_event: function (event) { -// var row_id = event.target.attributes['data-row-id'].nodeValue, -// row = this.get_row(row_id); - -// if (row.expanded) { -// this.fold_row(row_id); -// } else { -// if (row.path.length < this.data.row_groupby.length) { -// var field_to_expand = this.data.row_groupby[row.path.length]; -// this.expand_row(row_id, field_to_expand); -// } else { -// this.display_dropdown({row_id:row_id, -// target: $(event.target), -// x: event.pageX, -// y: event.pageY}); -// } -// } -// }, - -// handle_col_event: function (event) { -// var col_id = event.target.attributes['data-col-id'].nodeValue, -// col = this.get_col(col_id); - -// if (col.expanded) { -// this.fold_col(col_id); -// } else { -// if (col.path.length < this.data.col_groupby.length) { -// var field_to_expand = this.data.col_groupby[col.path.length]; -// this.expand_col(col_id, field_to_expand); -// } else { -// this.display_dropdown({col_id: col_id, -// target: $(event.target), -// x: event.pageX, -// y: event.pageY}); -// } -// } -// }, - -// init: function (data) { -// this.data = data; -// makePivotTable(this.data).done(function (table) { -// self.pivottable = table; -// }); - -// }, - -// start: function () { -// this.draw(true); -// }, - -// draw: function (load_data) { -// var self = this; - -// if (load_data) { -// var view_fields = this.data.row_groupby.concat(this.data.measure, this.data.col_groupby); -// query_groups_data(this.data.model, view_fields, this.data.domain, this.data.col_groupby, this.data.row_groupby[0]) -// .then(function (groups) { -// self.data.groups = groups; -// return self.get_groups([]); -// }).then(function (total) { -// total[0].path = []; -// self.data.total = [total]; -// self.build_table(); -// self.draw(false); -// }); -// } else { -// this.$el.empty(); - -// this.draw_top_headers(); - -// _.each(this.rows, function (row) { -// self.$el.append(row.html); -// }); -// } -// }, - -// show: function () { -// this.$el.css('display', 'block'); -// }, - -// hide: function () { -// this.$el.css('display', 'none'); -// }, - -// display_dropdown: function (options) { -// var self = this, -// already_grouped = self.data.row_groupby.concat(self.data.col_groupby), -// possible_groups = _.difference(self.data.important_fields, already_grouped), -// dropdown_options = { -// fields: _.map(possible_groups, function (field) { -// return {id: field, value: self.get_descr(field)}; -// })}; -// if (options.row_id) { -// dropdown_options.row_id= options.row_id; -// } else { -// dropdown_options.col_id = options.col_id; -// } - -// this.dropdown = $(QWeb.render('field_selection', dropdown_options)); -// options.target.after(this.dropdown); -// this.dropdown.css({position:'absolute', -// left:options.x, -// top:options.y}); -// $('.field-selection').next('.dropdown-menu').toggle(); -// }, - -// build_table: function () { -// var self = this; -// this.rows = []; - - -// var col_id = this.generate_id(); - -// this.cols= [{ -// id: col_id, -// path: [], -// value: this.data.measure_label, -// expanded: false, -// parent: null, -// children: [], -// cells: [], // a cell is {td:, row_id:} -// domain: this.data.domain, -// }]; - -// self.make_top_headers(); - -// var main_row = this.make_row(this.data.total[0]); - -// _.each(this.data.groups, function (group) { -// self.make_row(group, main_row.id); -// }); -// }, - -// get_descr: function (field_id) { -// return this.data.fields[field_id].string; -// }, - -// get_groups: function (groupby) { -// var view_fields = this.data.row_groupby.concat(this.data.measure, this.data.col_groupby); -// return query_groups(this.data.model, view_fields, this.data.domain, groupby); -// }, - -// make_top_headers : function () { -// var self = this, -// header; - -// function partition (columns) { -// return _.reduce(columns, function (partial, col) { -// if (partial.length === 0) return [[col]]; -// if (col.path.length > _.first(_.last(partial)).path.length) { -// _.last(partial).push(col); -// } else { -// partial.push([col]); -// } -// return partial; -// }, []); -// } - -// function side_by_side(blocks) { -// var result = _.zip.apply(_,blocks); -// result = _.map(result, function(line) {return _.compact(_.flatten(line))}); -// return result; -// } - -// function make_header_cell(col, span) { -// var options = { -// is_border:true, -// foldable:true, -// row_span: (span === undefined) ? 1 : span, -// col_id: col.id, -// }; -// var result = self.make_cell(col.value, options); -// if (col.expanded) { -// result.find('.icon-plus-sign') -// .removeClass('icon-plus-sign') -// .addClass('icon-minus-sign'); -// } -// return result; -// } - -// function calculate_width(cols) { -// if (cols.length === 1) { -// return 1; -// } -// var p = partition(_.rest(cols)); -// return _.reduce(p, function(x, y){ return x + calculate_width(y); }, 0); -// } - -// function make_header_cells(cols, height) { -// var p = partition(cols); -// if ((p.length === 1) && (p[0].length === 1)) { -// var result = [[make_header_cell(cols[0], height)]]; -// return result; -// } -// if ((p.length === 1) && (p[0].length > 1)) { -// var cell = make_header_cell(p[0][0]); -// cell.attr('colspan', calculate_width(cols)); -// return [[cell]].concat(make_header_cells(_.rest(cols), height - 1)); -// } -// if (p.length > 1) { -// return side_by_side(_.map(p, function (group) { -// return make_header_cells(group, height); -// })); -// } -// } - -// if (this.cols.length === 1) { -// header = $(''); -// header.append(this.make_cell('', {is_border:true})); -// header.append(this.make_cell(this.cols[0].value, -// {is_border:true, foldable:true, col_id:this.cols[0].id})); -// header.addClass('graph_top'); -// this.headers = [header]; -// } else { -// var height = _.max(_.map(self.cols, function(g) {return g.path.length;})); -// var header_rows = make_header_cells(_.rest(this.cols), height); - -// header_rows[0].splice(0,0,self.make_cell('', {is_border:true, }).attr('rowspan', height)) -// self.headers = []; -// _.each(header_rows, function (cells) { -// header = $(''); -// header.append(cells); -// header.addClass('graph_top'); -// self.headers.push(header); -// }); -// } -// }, - -// draw_top_headers: function () { -// var self = this; -// $("tr.graph_top").remove(); -// _.each(this.headers.reverse(), function (header) { -// self.$el.prepend(header); -// }); - -// }, - -// make_row: function (groups, parent_id) { -// var self = this, -// path, -// value, -// expanded, -// domain, -// parent, -// has_parent = (parent_id !== undefined), -// row_id = this.generate_id(); - -// if (has_parent) { -// parent = this.get_row(parent_id); -// path = parent.path.concat(groups[0].attributes.value[1]); -// value = groups[0].attributes.value[1]; -// expanded = false; -// parent.children.push(row_id); -// domain = groups[0].model._domain; -// } else { -// parent = null; -// path = []; -// value = 'Total'; -// expanded = true; -// domain = this.data.domain; -// } - -// var jquery_row = $(''); - -// var header = self.make_cell(value, {is_border:true, indent: path.length, foldable:true, row_id: row_id}); -// jquery_row.append(header); - -// var cell; - -// _.each(this.cols, function (col) { -// var element = _.find(groups, function (group) { -// return _.isEqual(_.rest(group.path), col.path); -// }); -// if (element === undefined) { -// cell = self.make_cell(''); -// } else { -// cell = self.make_cell(element.attributes.aggregates[self.data.measure]); -// } -// if (col.expanded) { -// cell.css('display', 'none'); -// } -// col.cells.push({td:cell, row_id:row_id}); -// jquery_row.append(cell); -// }); - -// if (!has_parent) { -// header.find('.icon-plus-sign') -// .removeClass('icon-plus-sign') -// .addClass('icon-minus-sign'); -// } - -// var row = { -// id: row_id, -// path: path, -// value: value, -// expanded: expanded, -// parent: parent_id, -// children: [], -// html: jquery_row, -// domain: domain, -// }; -// this.rows.push(row); // to do, insert it properly, after all childs of parent -// return row; -// }, - -// generate_id: function () { -// this.id_seed += 1; -// return this.id_seed - 1; -// }, - -// get_row: function (id) { -// return _.find(this.rows, function(row) { -// return (row.id == id); -// }); -// }, - -// get_col: function (id) { -// return _.find(this.cols, function(col) { -// return (col.id == id); -// }); -// }, - -// make_cell: function (content, options) { -// options = _.extend({is_border: false, indent:0, foldable:false}, options); -// content = (content !== undefined) ? content : 'Undefined'; - -// var cell = $(''); -// if (options.is_border) cell.addClass('graph_border'); -// if (options.row_span) cell.attr('rowspan', options.row_span); -// if (options.col_span) cell.attr('rowspan', options.col_span); -// _.each(_.range(options.indent), function () { -// cell.prepend($('', {class:'web_graph_indent'})); -// }); - -// if (options.foldable) { -// var attrs = {class:'icon-plus-sign web_graph_click', href:'#'}; -// if (options.row_id !== undefined) attrs['data-row-id'] = options.row_id; -// if (options.col_id !== undefined) attrs['data-col-id'] = options.col_id; -// var plus = $('', attrs); -// plus.append(' '); -// plus.append(content); -// cell.append(plus); -// } else { -// cell.append(content); -// } -// return cell; -// }, - -// expand_row: function (row_id, field_id) { -// var self = this; -// var row = this.get_row(row_id); - -// if (row.path.length == this.data.row_groupby.length) { -// this.data.row_groupby.push(field_id); -// } -// row.expanded = true; -// row.html.find('.icon-plus-sign') -// .removeClass('icon-plus-sign') -// .addClass('icon-minus-sign'); - -// var visible_fields = this.data.row_groupby.concat(this.data.col_groupby, this.data.measure); -// query_groups_data(this.data.model, visible_fields, row.domain, this.data.col_groupby, field_id) -// .then(function (groups) { -// _.each(groups.reverse(), function (group) { -// var new_row = self.make_row(group, row_id); -// row.html.after(new_row.html); -// }); -// }); - -// }, - -// expand_col: function (col_id, field_id) { -// var self = this; -// var col = this.get_col(col_id); - -// if (col.path.length == this.data.col_groupby.length) { -// this.data.col_groupby.push(field_id); -// } -// col.expanded = true; - -// var visible_fields = this.data.row_groupby.concat(this.data.col_groupby, this.data.measure); -// query_groups_data(this.data.model, visible_fields, col.domain, this.data.row_groupby, field_id) -// .then(function (groups) { -// _.each(groups, function (group) { -// var new_col = { -// id: self.generate_id(), -// path: col.path.concat(group[0].attributes.value[1]), -// value: group[0].attributes.value[1], -// expanded: false, -// parent: col_id, -// children: [], -// cells: [], // a cell is {td:, row_id:} -// domain: group[0].model._domain, -// }; -// col.children.push(new_col.id); -// insertAfter(self.cols, col, new_col) -// _.each(col.cells, function (cell) { -// var col_path = self.get_row(cell.row_id).path; - -// var datapt = _.find(group, function (g) { -// return _.isEqual(g.path.slice(1), col_path); -// }); - -// var value; -// if (datapt === undefined) { -// value = ''; -// } else { -// value = datapt.attributes.aggregates[self.data.measure]; -// } -// var new_cell = { -// row_id: cell.row_id, -// td: self.make_cell(value) -// }; -// new_col.cells.push(new_cell); -// cell.td.after(new_cell.td); -// cell.td.css('display','none'); -// }); - -// }); -// self.make_top_headers(); -// self.draw_top_headers(); -// }); -// }, - -// fold_row: function (row_id) { -// var self = this; -// var row = this.get_row(row_id); - -// _.each(row.children, function (child_row) { -// self.remove_row(child_row); -// }); -// row.children = []; - -// row.expanded = false; -// row.html.find('.icon-minus-sign') -// .removeClass('icon-minus-sign') -// .addClass('icon-plus-sign'); - -// var fold_levels = _.map(self.rows, function(g) {return g.path.length;}); -// var new_groupby_length = _.max(fold_levels); - -// this.data.row_groupby.splice(new_groupby_length); -// }, - -// remove_row: function (row_id) { -// var self = this; -// var row = this.get_row(row_id); - -// _.each(row.children, function (child_row) { -// self.remove_row(child_row); -// }); - -// row.html.remove(); -// removeFromArray(this.rows, row); - -// _.each(this.cols, function (col) { -// col.cells = _.filter(col.cells, function (cell) { -// return cell.row_id !== row_id; -// }); -// }); -// }, - -// fold_col: function (col_id) { -// var self = this; -// var col = this.get_col(col_id); - -// _.each(col.children, function (child_col) { -// self.remove_col(child_col); -// }); -// col.children = []; - -// _.each(col.cells, function (cell) { -// cell.td.css('display','table-cell'); -// }); -// col.expanded = false; -// // row.html.find('.icon-minus-sign') -// // .removeClass('icon-minus-sign') -// // .addClass('icon-plus-sign'); - -// var fold_levels = _.map(self.cols, function(g) {return g.path.length;}); -// var new_groupby_length = _.max(fold_levels); - -// this.data.col_groupby.splice(new_groupby_length); -// this.make_top_headers(); -// this.draw_top_headers(); - - -// }, - -// remove_col: function (col_id) { -// var self = this; -// var col = this.get_col(col_id); - -// _.each(col.children, function (child_col) { -// self.remove_col(child_col); -// }); - -// _.each(col.cells, function (cell) { -// cell.td.remove(); -// }); -// // row.html.remove(); -// removeFromArray(this.cols, col); - -// // _.each(this.cols, function (col) { -// // col.cells = _.filter(col.cells, function (cell) { -// // return cell.row_id !== row_id; -// // }); -// // }); -// }, - - -// }); - }; -- cgit v1.2.3 From 1e32b763f0e1da669d835b02fbf680f2deea0f65 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Sat, 23 Nov 2013 11:11:35 +0100 Subject: [IMP] add 'clear all groups' and 'swap axis' functionality to pivot table in addon web_graph bzr revid: ged@openerp.com-20131123101135-m0cx5eg0o41k7x2m --- addons/web_graph/static/src/js/graph.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index cfabdead833..da3f4257b33 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -57,6 +57,16 @@ instance.web_graph.GraphView = instance.web.View.extend({ .then(this.proxy('draw_table')); } }, + + 'click label.graph_swap_axis' : function (event) { + this.pivot_table.swap_axis(); + this.draw_table(); + }, + + 'click label.graph_clear_all' : function (event) { + this.pivot_table.clear_all(); + this.draw_table(); + }, }, view_loading: function (fields_view_get) { @@ -212,7 +222,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, draw_table: function () { - console.log("cols",this.pivot_table.cols); this.table.empty(); this.draw_top_headers(); _.each(this.pivot_table.rows, this.proxy('draw_row')); -- cgit v1.2.3 From ebf46e668d6f0ae9695eb693b8ffb6b1498ba6c4 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Sat, 23 Nov 2013 11:19:22 +0100 Subject: [REF] moves the data formatting for charts to the charts file (instead of pivot) in addon web_graph bzr revid: ged@openerp.com-20131123101922-xi429dmnwpqlfsiq --- addons/web_graph/static/src/js/graph.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index da3f4257b33..4d74ad71121 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -172,7 +172,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.svg.remove(); this.svg = $('
'); this.$el.filter('.graph_main_content').append(this.svg); - Charts[mode](this.pivot_table.get_chart_data()); + Charts[mode](this.pivot_table); } }, -- cgit v1.2.3 From 42e38292b8ba13f54349203a16e9b61e33ebfe7b Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Sat, 23 Nov 2013 12:42:01 +0100 Subject: [REF] slight modifications to the underlying data structure of pivot table in addon web_graph bzr revid: ged@openerp.com-20131123114201-g6v6q9r15n9gdzg2 --- addons/web_graph/static/src/js/graph.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 4d74ad71121..cd6cb44f93c 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -186,9 +186,9 @@ instance.web_graph.GraphView = instance.web.View.extend({ pivot['fold_' + options.type](header); this.draw_table(); } else { - if (header.path.length < pivot[options.type + '_groupby'].length) { + if (header.path.length < pivot[options.type + 's'].groupby.length) { // expand the corresponding header - var field = pivot[options.type + '_groupby'][header.path.length]; + var field = pivot[options.type + 's'].groupby[header.path.length]; pivot['expand_' + options.type](id, field) .then(this.proxy('draw_table')); } else { @@ -205,7 +205,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ display_dropdown: function (options) { var self = this, pivot = this.pivot_table, - already_grouped = pivot.row_groupby.concat(pivot.col_groupby), + already_grouped = pivot.rows.groupby.concat(pivot.cols.groupby), possible_groups = _.difference(self.data.important_fields, already_grouped), dropdown_options = { fields: _.map(possible_groups, function (field) { @@ -224,7 +224,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ draw_table: function () { this.table.empty(); this.draw_top_headers(); - _.each(this.pivot_table.rows, this.proxy('draw_row')); + _.each(this.pivot_table.rows.headers, this.proxy('draw_row')); }, make_border_cell: function (colspan, rowspan) { @@ -244,7 +244,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ draw_top_headers: function () { var self = this, pivot = this.pivot_table, - height = _.max(_.map(pivot.cols, function(g) {return g.path.length;})), + height = _.max(_.map(pivot.cols.headers, function(g) {return g.path.length;})), header_cells = [[this.make_border_cell(1, height)]]; function set_dim (cols) { @@ -277,11 +277,11 @@ instance.web_graph.GraphView = instance.web.View.extend({ } } - set_dim(pivot.cols[0]); // add width and height info to columns headers - if (pivot.cols[0].children.length === 0) { - make_cells(pivot.cols, 0); + set_dim(pivot.cols.main); // add width and height info to columns headers + if (pivot.cols.main.children.length === 0) { + make_cells(pivot.cols.headers, 0); } else { - make_cells(pivot.cols[0].children, 1); + make_cells(pivot.cols.main.children, 1); } _.each(header_cells, function (cells) { @@ -302,7 +302,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ html_row.append(row_header); - _.each(pivot.cols, function (col) { + _.each(pivot.cols.headers, function (col) { if (col.children.length === 0) { var cell = $('').append(pivot.get_value(row.id, col.id)); html_row.append(cell); -- cgit v1.2.3 From aa5958eaf5bab2bc193eea7e1a1e76644967b9ce Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Sun, 24 Nov 2013 15:29:27 +0100 Subject: [IMP] many very small tweaks to pivot view (addon web_graph) bzr revid: ged@openerp.com-20131124142927-jnuqykwfp351337v --- addons/web_graph/static/src/js/graph.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index cd6cb44f93c..c0ccb80285a 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -63,8 +63,18 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.draw_table(); }, - 'click label.graph_clear_all' : function (event) { - this.pivot_table.clear_all(); + 'click label.graph_fold_all' : function (event) { + this.pivot_table.fold_all(); + this.draw_table(); + }, + + 'click label.graph_fold_rows' : function (event) { + this.pivot_table.fold_rows(); + this.draw_table(); + }, + + 'click label.graph_fold_cols' : function (event) { + this.pivot_table.fold_cols(); this.draw_table(); }, }, @@ -172,7 +182,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.svg.remove(); this.svg = $('
'); this.$el.filter('.graph_main_content').append(this.svg); - Charts[mode](this.pivot_table); + draw_chart(this.svg, mode, this.pivot_table); } }, -- cgit v1.2.3 From 5173a56db659f91eb71255bcecb0cfe072f54cdb Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Sun, 24 Nov 2013 15:52:40 +0100 Subject: [IMP] add heat map functionality to pivot table (addon web_graph) bzr revid: ged@openerp.com-20131124145240-dn5vq5ecb598gf4e --- addons/web_graph/static/src/js/graph.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index c0ccb80285a..037a07c60ec 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -77,6 +77,11 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.pivot_table.fold_cols(); this.draw_table(); }, + + 'click label.graph_heat_map' : function (event) { + this.heat_map_mode = !this.heat_map_mode; + this.draw_table(); + }, }, view_loading: function (fields_view_get) { @@ -90,6 +95,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ row_groupby = []; this.pivot_table = null; + this.heat_map_mode = false; // get the default groupbys and measure defined in the field view _.each(fields_view_get.arch.children, function (field) { @@ -300,7 +306,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, draw_row: function (row) { - var pivot = this.pivot_table, + var self = this, + pivot = this.pivot_table, html_row = $(''), row_header = this.make_border_cell(1,1) .append(this.make_header_title(row).attr('data-row-id', row.id)) @@ -314,7 +321,17 @@ instance.web_graph.GraphView = instance.web.View.extend({ _.each(pivot.cols.headers, function (col) { if (col.children.length === 0) { - var cell = $('').append(pivot.get_value(row.id, col.id)); + var value = pivot.get_value(row.id, col.id), + cell = $(''); + + cell.append((value === undefined) ? '' : value); + if ((self.heat_map_mode) && (value !== undefined)) { + // heat map + console.log("heat map", self.heat_map_mode, pivot.total); + var ratio = Math.floor(70 + 185*(pivot.total - value)/pivot.total); + console.log("ratio",ratio); + cell.css("background-color", "rgb(255," + ratio + "," + ratio + ")"); + } html_row.append(cell); } }); -- cgit v1.2.3 From 40889788d3bb6cfac6a0dab0bf2d48e59409fe5a Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Sun, 24 Nov 2013 16:00:34 +0100 Subject: [REF] merge fold_row and fold_col methods into the fold method (addon web_graph) bzr revid: ged@openerp.com-20131124150034-0133mgww0nm3dfta --- addons/web_graph/static/src/js/graph.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 037a07c60ec..5dbe4b780cb 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -199,7 +199,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ header = pivot['get_' + options.type](id); if (header.is_expanded) { - pivot['fold_' + options.type](header); + pivot.fold(header); this.draw_table(); } else { if (header.path.length < pivot[options.type + 's'].groupby.length) { @@ -327,9 +327,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ cell.append((value === undefined) ? '' : value); if ((self.heat_map_mode) && (value !== undefined)) { // heat map - console.log("heat map", self.heat_map_mode, pivot.total); var ratio = Math.floor(70 + 185*(pivot.total - value)/pivot.total); - console.log("ratio",ratio); cell.css("background-color", "rgb(255," + ratio + "," + ratio + ")"); } html_row.append(cell); -- cgit v1.2.3 From 46ea9d29feb8d46eb5ee4d1900c955a219fca907 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Sun, 24 Nov 2013 21:10:49 +0100 Subject: [REF] better code organization for chart drawing in addon web_graph bzr revid: ged@openerp.com-20131124201049-p7cealv5p11hofr2 --- addons/web_graph/static/src/js/graph.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 5dbe4b780cb..0a1dcdd001b 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -178,7 +178,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, switch_mode: function (mode) { - var self = this; this.mode = mode; if (mode === 'pivot') { this.table.css('display', 'block'); @@ -188,7 +187,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.svg.remove(); this.svg = $('
'); this.$el.filter('.graph_main_content').append(this.svg); - draw_chart(this.svg, mode, this.pivot_table); + draw_chart(mode, this.pivot_table); } }, @@ -326,9 +325,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ cell.append((value === undefined) ? '' : value); if ((self.heat_map_mode) && (value !== undefined)) { - // heat map - var ratio = Math.floor(70 + 185*(pivot.total - value)/pivot.total); - cell.css("background-color", "rgb(255," + ratio + "," + ratio + ")"); + var color = Math.floor(50 + 205*(pivot.total - value)/pivot.total); + cell.css("background-color", "rgb(255," + color + "," + color + ")"); } html_row.append(cell); } -- cgit v1.2.3 From 5227f89396de7527906e7708d3559cc6576cabfe Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Sun, 24 Nov 2013 21:58:55 +0100 Subject: [REF] merge expand_row and expand_col methods into the fold method, also some small code tweaks (addon web_graph) bzr revid: ged@openerp.com-20131124205855-eekx2gwhgl4ye9uj --- addons/web_graph/static/src/js/graph.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 0a1dcdd001b..0ab02ccb51b 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -48,12 +48,12 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.dropdown.remove(); if (event.target.attributes['data-row-id'] !== undefined) { id = event.target.attributes['data-row-id'].nodeValue; - this.pivot_table.expand_row(id, field_id) + this.pivot_table.expand(id, field_id) .then(this.proxy('draw_table')); } if (event.target.attributes['data-col-id'] !== undefined) { id = event.target.attributes['data-col-id'].nodeValue; - this.pivot_table.expand_col(id, field_id) + this.pivot_table.expand(id, field_id) .then(this.proxy('draw_table')); } }, @@ -195,19 +195,16 @@ instance.web_graph.GraphView = instance.web.View.extend({ handle_header_event: function (options) { var pivot = this.pivot_table, id = options.event.target.attributes['data-' + options.type + '-id'].nodeValue, - header = pivot['get_' + options.type](id); + header = pivot.get_header(id); if (header.is_expanded) { pivot.fold(header); this.draw_table(); } else { - if (header.path.length < pivot[options.type + 's'].groupby.length) { - // expand the corresponding header - var field = pivot[options.type + 's'].groupby[header.path.length]; - pivot['expand_' + options.type](id, field) - .then(this.proxy('draw_table')); + if (header.path.length < header.root.groupby.length) { + var field = header.root.groupby[header.path.length]; + pivot.expand(id, field).then(this.proxy('draw_table')); } else { - // display dropdown to query field to expand this.display_dropdown({id:header.id, type: options.type, target: $(event.target), -- cgit v1.2.3 From 2ff7dd16fe8446493efcb5aad6df06ce858de229 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Sun, 24 Nov 2013 22:48:09 +0100 Subject: [REF] some more simplifications, using the symetry between cols and rows in addon web_graph bzr revid: ged@openerp.com-20131124214809-k08p4x4h0wm4owmq --- addons/web_graph/static/src/js/graph.js | 38 +++++++++++---------------------- 1 file changed, 12 insertions(+), 26 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 0ab02ccb51b..146a9d3e865 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -32,30 +32,17 @@ instance.web_graph.GraphView = instance.web.View.extend({ 'click .web_graph_click' : function (event) { event.preventDefault(); - if (event.target.attributes['data-row-id'] !== undefined) { - this.handle_header_event({type:'row', event:event}); - - } - if (event.target.attributes['data-col-id'] !== undefined) { - this.handle_header_event({type:'col', event:event}); - } + var id = event.target.attributes['data-id'].nodeValue; + this.handle_header_event({id:id, event:event}); }, 'click a.field-selection' : function (event) { - var id, + var id = event.target.attributes['data-id'].nodeValue, field_id = event.target.attributes['data-field-id'].nodeValue; event.preventDefault(); this.dropdown.remove(); - if (event.target.attributes['data-row-id'] !== undefined) { - id = event.target.attributes['data-row-id'].nodeValue; - this.pivot_table.expand(id, field_id) - .then(this.proxy('draw_table')); - } - if (event.target.attributes['data-col-id'] !== undefined) { - id = event.target.attributes['data-col-id'].nodeValue; - this.pivot_table.expand(id, field_id) - .then(this.proxy('draw_table')); - } + this.pivot_table.expand(id, field_id) + .then(this.proxy('draw_table')); }, 'click label.graph_swap_axis' : function (event) { @@ -194,7 +181,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ handle_header_event: function (options) { var pivot = this.pivot_table, - id = options.event.target.attributes['data-' + options.type + '-id'].nodeValue, + id = options.id, header = pivot.get_header(id); if (header.is_expanded) { @@ -206,10 +193,9 @@ instance.web_graph.GraphView = instance.web.View.extend({ pivot.expand(id, field).then(this.proxy('draw_table')); } else { this.display_dropdown({id:header.id, - type: options.type, - target: $(event.target), - x: event.pageX, - y: event.pageY}); + target: $(options.event.target), + x: options.event.pageX, + y: options.event.pageY}); } } }, @@ -220,10 +206,10 @@ instance.web_graph.GraphView = instance.web.View.extend({ already_grouped = pivot.rows.groupby.concat(pivot.cols.groupby), possible_groups = _.difference(self.data.important_fields, already_grouped), dropdown_options = { + header_id: options.id, fields: _.map(possible_groups, function (field) { return {id: field, value: self.data.fields[field].string}; })}; - dropdown_options[options.type + '_id'] = options.id; this.dropdown = $(QWeb.render('field_selection', dropdown_options)); options.target.after(this.dropdown); @@ -272,7 +258,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ function make_col_header (col) { var cell = self.make_border_cell(col.width, col.height); - return cell.append(self.make_header_title(col).attr('data-col-id', col.id)); + return cell.append(self.make_header_title(col).attr('data-id', col.id)); } function make_cells (queue, level) { @@ -306,7 +292,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ pivot = this.pivot_table, html_row = $(''), row_header = this.make_border_cell(1,1) - .append(this.make_header_title(row).attr('data-row-id', row.id)) + .append(this.make_header_title(row).attr('data-id', row.id)) .addClass('graph_border'); for (var i in _.range(row.path.length)) { -- cgit v1.2.3 From 2944752844ee3a98b4a5e0a2c35634a034b88acb Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Mon, 25 Nov 2013 08:42:00 +0100 Subject: [IMP] adds slight color to expanded rows to make it easier to see the subrows (addon web_graph) bzr revid: ged@openerp.com-20131125074200-6d3migzpl4x7c44s --- addons/web_graph/static/src/js/graph.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 146a9d3e865..e1234e6f489 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -310,7 +310,11 @@ instance.web_graph.GraphView = instance.web.View.extend({ if ((self.heat_map_mode) && (value !== undefined)) { var color = Math.floor(50 + 205*(pivot.total - value)/pivot.total); cell.css("background-color", "rgb(255," + color + "," + color + ")"); - } + } + if (row.is_expanded && (row.path.length <= 2)) { + var color = row.path.length * 5 + 240; + cell.css("background-color", "rgb(" + [color, color, color].join() + ")"); + } html_row.append(cell); } }); -- cgit v1.2.3 From 86a2d41d24045e1ba020199c998d315a5c8d9b10 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Mon, 25 Nov 2013 09:06:53 +0100 Subject: [IMP] adds expand_all button and method to graph view. beware, the code is not efficient (it does lots of db queries) (addon web_graph) bzr revid: ged@openerp.com-20131125080653-n3lgq7lb3kb3ygg7 --- addons/web_graph/static/src/js/graph.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index e1234e6f489..0a6a2fd15db 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -69,6 +69,10 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.heat_map_mode = !this.heat_map_mode; this.draw_table(); }, + + 'click label.graph_expand_all' : function (event) { + this.pivot_table.expand_all().then(this.proxy('draw_table')); + }, }, view_loading: function (fields_view_get) { -- cgit v1.2.3 From 7940ec40c65214a2bdcd800a1dd2291980abc25b Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Mon, 25 Nov 2013 10:04:43 +0100 Subject: [IMP] add total to each rows in pivot table view (addon web_graph) bzr revid: ged@openerp.com-20131125090443-r5dbre9wn2jymu37 --- addons/web_graph/static/src/js/graph.js | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 0a6a2fd15db..69155e7b255 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -284,6 +284,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ make_cells(pivot.cols.headers, 0); } else { make_cells(pivot.cols.main.children, 1); + header_cells[0].push(self.make_border_cell(1, height).append('Total')); } _.each(header_cells, function (cells) { @@ -322,6 +323,16 @@ instance.web_graph.GraphView = instance.web.View.extend({ html_row.append(cell); } }); + var cell = $('').append(pivot.get_value(row.id,pivot.cols.main.id)); + if (row.is_expanded && (row.path.length <= 2)) { + var color = row.path.length * 5 + 240; + cell.css("background-color", "rgb(" + [color, color, color].join() + ")"); + } + + if (pivot.cols.main.children.length > 0) { + html_row.append(cell); + } + this.table.append(html_row); } }); -- cgit v1.2.3 From d8aa7a6551ddb0b540cd14c35d4482d79f746fb5 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Mon, 25 Nov 2013 10:15:05 +0100 Subject: [IMP] improves the look of the total in each rows in pivot table view (addon web_graph) bzr revid: ged@openerp.com-20131125091505-wts1llbdexhnl8fe --- addons/web_graph/static/src/js/graph.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 69155e7b255..2c3645341d8 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -284,7 +284,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ make_cells(pivot.cols.headers, 0); } else { make_cells(pivot.cols.main.children, 1); - header_cells[0].push(self.make_border_cell(1, height).append('Total')); + header_cells[0].push(self.make_border_cell(1, height).append('Total').css('font-weight', 'bold')); } _.each(header_cells, function (cells) { @@ -323,10 +323,16 @@ instance.web_graph.GraphView = instance.web.View.extend({ html_row.append(cell); } }); - var cell = $('').append(pivot.get_value(row.id,pivot.cols.main.id)); + var total = pivot.get_value(row.id, pivot.cols.main.id); + var cell = $('') + .append(total) + .css('font-weight', 'bold'); if (row.is_expanded && (row.path.length <= 2)) { var color = row.path.length * 5 + 240; cell.css("background-color", "rgb(" + [color, color, color].join() + ")"); + } else if (self.heat_map_mode) { + var color = Math.floor(50 + 205*(pivot.total - total)/pivot.total); + cell.css("background-color", "rgb(255," + color + "," + color + ")"); } if (pivot.cols.main.children.length > 0) { -- cgit v1.2.3 From 4eef57206502a1d3201f256027d370f3cf386c5f Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 26 Nov 2013 16:19:06 +0100 Subject: [IMP] big commit: add query_all_values() method to pivot table, and uses it to add expand_all and update_values functionality to graph view (addon web_graph) bzr revid: ged@openerp.com-20131126151906-luj8ri6e4hj444h6 --- addons/web_graph/static/src/js/graph.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 2c3645341d8..2aeb68b9869 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -73,6 +73,10 @@ instance.web_graph.GraphView = instance.web.View.extend({ 'click label.graph_expand_all' : function (event) { this.pivot_table.expand_all().then(this.proxy('draw_table')); }, + + 'click label.graph_update_values' : function (event) { + this.pivot_table.update_values().then(this.proxy('draw_table')); + }, }, view_loading: function (fields_view_get) { @@ -157,7 +161,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ self.pivot_table = new PivotTable(self.data); self.pivot_table.start().then(self.proxy('draw_table')); } else { - this.pivot_table.update_values.done(function () { + this.pivot_table.update_values().done(function () { self.draw_table(); }); } @@ -240,7 +244,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ .addClass('web_graph_click') .attr('href', '#') .addClass((header.is_expanded) ? 'icon-minus-sign' : 'icon-plus-sign') - .append(header.name); + .append((header.title !== undefined) ? header.title : 'Undefined'); }, draw_top_headers: function () { -- cgit v1.2.3 From 857b48749b79bca158ddf1b5b4096dd6cf061d22 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 26 Nov 2013 16:57:06 +0100 Subject: [IMP] updates the pivot table domain when search view is activated bzr revid: ged@openerp.com-20131126155706-nqc6hgjbyty8jju2 --- addons/web_graph/static/src/js/graph.js | 1 + 1 file changed, 1 insertion(+) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 2aeb68b9869..3d218e38eba 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -161,6 +161,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ self.pivot_table = new PivotTable(self.data); self.pivot_table.start().then(self.proxy('draw_table')); } else { + this.pivot_table.domain = domain; this.pivot_table.update_values().done(function () { self.draw_table(); }); -- cgit v1.2.3 From 0b5ff7efff63c791cf0e5d8abe66653973391a16 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 27 Nov 2013 10:10:53 +0100 Subject: [IMP] reorganizes all options in graph views (puts them in 4 dropdown menus) (addon web_graph) bzr revid: ged@openerp.com-20131127091053-ydbo89dj027ndm3o --- addons/web_graph/static/src/js/graph.js | 73 ++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 29 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 3d218e38eba..9cd2147d9fb 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -30,6 +30,43 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.switch_mode(mode); }, + 'click .graph_expand_selection li' : function (event) { + event.preventDefault(); + switch (event.target.attributes['data-choice'].nodeValue) { + case 'fold_columns': + this.pivot_table.fold_cols(); + this.draw_table(); + break; + case 'fold_rows': + this.pivot_table.fold_rows(); + this.draw_table(); + break; + case 'fold_all': + this.pivot_table.fold_all(); + this.draw_table(); + break; + case 'expand_all': + this.pivot_table.expand_all().then(this.proxy('draw_table')); + break; + } + }, + + 'click .graph_options_selection li' : function (event) { + event.preventDefault(); + switch (event.target.attributes['data-choice'].nodeValue) { + case 'swap_axis': + this.pivot_table.swap_axis(); + this.draw_table(); + break; + case 'update_values': + this.pivot_table.update_values().then(this.proxy('draw_table')); + break; + case 'export_data': + // Export code... To do... + break; + } + }, + 'click .web_graph_click' : function (event) { event.preventDefault(); var id = event.target.attributes['data-id'].nodeValue; @@ -45,38 +82,11 @@ instance.web_graph.GraphView = instance.web.View.extend({ .then(this.proxy('draw_table')); }, - 'click label.graph_swap_axis' : function (event) { - this.pivot_table.swap_axis(); - this.draw_table(); - }, - - 'click label.graph_fold_all' : function (event) { - this.pivot_table.fold_all(); - this.draw_table(); - }, - - 'click label.graph_fold_rows' : function (event) { - this.pivot_table.fold_rows(); - this.draw_table(); - }, - - 'click label.graph_fold_cols' : function (event) { - this.pivot_table.fold_cols(); - this.draw_table(); - }, 'click label.graph_heat_map' : function (event) { this.heat_map_mode = !this.heat_map_mode; this.draw_table(); }, - - 'click label.graph_expand_all' : function (event) { - this.pivot_table.expand_all().then(this.proxy('draw_table')); - }, - - 'click label.graph_update_values' : function (event) { - this.pivot_table.update_values().then(this.proxy('draw_table')); - }, }, view_loading: function (fields_view_get) { @@ -91,6 +101,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.pivot_table = null; this.heat_map_mode = false; + this.mode = 'pivot'; // get the default groupbys and measure defined in the field view _.each(fields_view_get.arch.children, function (field) { @@ -175,7 +186,9 @@ instance.web_graph.GraphView = instance.web.View.extend({ switch_mode: function (mode) { this.mode = mode; - if (mode === 'pivot') { + var table_modes = ['pivot', 'heatmap', 'row_heatmap', 'col_heatmap']; + if (_.contains(table_modes, mode)) { + this.draw_table(); this.table.css('display', 'block'); this.svg.css('display','none'); } else { @@ -317,7 +330,9 @@ instance.web_graph.GraphView = instance.web.View.extend({ cell = $(''); cell.append((value === undefined) ? '' : value); - if ((self.heat_map_mode) && (value !== undefined)) { + console.log("self.mode",self.mode); + if ((self.mode == 'heatmap') && (value !== undefined)) { + console.log("yop"); var color = Math.floor(50 + 205*(pivot.total - value)/pivot.total); cell.css("background-color", "rgb(255," + color + "," + color + ")"); } -- cgit v1.2.3 From 1f8b8165e8f563108eef32c30576b298fc26404f Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 27 Nov 2013 10:20:52 +0100 Subject: [REF] small code cleanups... removing old commented code, and small tweaks (addon web_graph) bzr revid: ged@openerp.com-20131127092052-n2ub66oczqrtmr33 --- addons/web_graph/static/src/js/graph.js | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 9cd2147d9fb..13a0d93c888 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -33,7 +33,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ 'click .graph_expand_selection li' : function (event) { event.preventDefault(); switch (event.target.attributes['data-choice'].nodeValue) { - case 'fold_columns': + case 'fold_columns': this.pivot_table.fold_cols(); this.draw_table(); break; @@ -54,7 +54,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ 'click .graph_options_selection li' : function (event) { event.preventDefault(); switch (event.target.attributes['data-choice'].nodeValue) { - case 'swap_axis': + case 'swap_axis': this.pivot_table.swap_axis(); this.draw_table(); break; @@ -81,12 +81,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.pivot_table.expand(id, field_id) .then(this.proxy('draw_table')); }, - - - 'click label.graph_heat_map' : function (event) { - this.heat_map_mode = !this.heat_map_mode; - this.draw_table(); - }, }, view_loading: function (fields_view_get) { @@ -96,7 +90,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ measure = null, fields, important_fields = [], - col_groupby = [], row_groupby = []; this.pivot_table = null; @@ -214,9 +207,9 @@ instance.web_graph.GraphView = instance.web.View.extend({ var field = header.root.groupby[header.path.length]; pivot.expand(id, field).then(this.proxy('draw_table')); } else { - this.display_dropdown({id:header.id, - target: $(options.event.target), - x: options.event.pageX, + this.display_dropdown({id:header.id, + target: $(options.event.target), + x: options.event.pageX, y: options.event.pageY}); } } @@ -306,7 +299,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ } _.each(header_cells, function (cells) { - self.table.append($("").append(cells)); + self.table.append($('').append(cells)); }); }, @@ -330,15 +323,13 @@ instance.web_graph.GraphView = instance.web.View.extend({ cell = $(''); cell.append((value === undefined) ? '' : value); - console.log("self.mode",self.mode); if ((self.mode == 'heatmap') && (value !== undefined)) { - console.log("yop"); var color = Math.floor(50 + 205*(pivot.total - value)/pivot.total); - cell.css("background-color", "rgb(255," + color + "," + color + ")"); + cell.css('background-color', 'rgb(255,' + color + ',' + color + ')'); } if (row.is_expanded && (row.path.length <= 2)) { var color = row.path.length * 5 + 240; - cell.css("background-color", "rgb(" + [color, color, color].join() + ")"); + cell.css('background-color', 'rgb(' + [color, color, color].join() + ')'); } html_row.append(cell); } @@ -349,10 +340,10 @@ instance.web_graph.GraphView = instance.web.View.extend({ .css('font-weight', 'bold'); if (row.is_expanded && (row.path.length <= 2)) { var color = row.path.length * 5 + 240; - cell.css("background-color", "rgb(" + [color, color, color].join() + ")"); + cell.css('background-color', 'rgb(' + [color, color, color].join() + ')'); } else if (self.heat_map_mode) { var color = Math.floor(50 + 205*(pivot.total - total)/pivot.total); - cell.css("background-color", "rgb(255," + color + "," + color + ")"); + cell.css('background-color', 'rgb(255,' + color + ',' + color + ')'); } if (pivot.cols.main.children.length > 0) { -- cgit v1.2.3 From 22162b5a10f9daefa81cd61a75ae12d2a508499c Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 27 Nov 2013 10:47:18 +0100 Subject: [IMP] puts everything into openerp.web_graph namespace, to avoid polluting global namespace (addon web_graph) bzr revid: ged@openerp.com-20131127094718-boii5ncxfq8agfv9 --- addons/web_graph/static/src/js/graph.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 13a0d93c888..69e0fc19d15 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -162,7 +162,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.data.domain = new instance.web.CompoundDomain(domain); if (!this.pivot_table) { - self.pivot_table = new PivotTable(self.data); + self.pivot_table = new openerp.web_graph.PivotTable(self.data); self.pivot_table.start().then(self.proxy('draw_table')); } else { this.pivot_table.domain = domain; @@ -189,7 +189,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.svg.remove(); this.svg = $('
'); this.$el.filter('.graph_main_content').append(this.svg); - draw_chart(mode, this.pivot_table); + openerp.web_graph.draw_chart(mode, this.pivot_table); } }, -- cgit v1.2.3 From e0744a7427be939c1c9ac4a1629d67c40817795e Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 27 Nov 2013 12:05:38 +0100 Subject: [FIX] fixes an issue where the chart code didn't select the correct DOM node to display the chart (addon web_graph) bzr revid: ged@openerp.com-20131127110538-rsm6hl4lgdkxya3p --- addons/web_graph/static/src/js/graph.js | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 69e0fc19d15..33a7e8db83c 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -27,7 +27,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ 'click .graph_mode_selection li' : function (event) { event.preventDefault(); var mode = event.target.attributes['data-mode'].nodeValue; - this.switch_mode(mode); + this.mode = mode; + this.display_data(); }, 'click .graph_expand_selection li' : function (event) { @@ -151,9 +152,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ start: function () { this.table = $('
'); - this.svg = $('
'); - this.$el.filter('.graph_main_content').append(this.table); - this.$el.filter('.graph_main_content').append(this.svg); + this.$('.graph_main_content').append(this.table); return this.load_view(); }, @@ -177,20 +176,17 @@ instance.web_graph.GraphView = instance.web.View.extend({ return this._super(); }, - switch_mode: function (mode) { - this.mode = mode; + display_data: function () { + this.$('.graph_main_content svg').remove(); + this.table.empty(); + var table_modes = ['pivot', 'heatmap', 'row_heatmap', 'col_heatmap']; - if (_.contains(table_modes, mode)) { + if (_.contains(table_modes, this.mode)) { this.draw_table(); - this.table.css('display', 'block'); - this.svg.css('display','none'); } else { - this.table.css('display', 'none'); - this.svg.remove(); - this.svg = $('
'); - this.$el.filter('.graph_main_content').append(this.svg); - openerp.web_graph.draw_chart(mode, this.pivot_table); - + this.$('.graph_main_content').append($('
')); + var svg = this.$('.graph_main_content svg')[0]; + openerp.web_graph.draw_chart(this.mode, this.pivot_table, svg); } }, -- cgit v1.2.3 From 0dd3f715358391895a554238d386346e49bc54d4 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 27 Nov 2013 12:25:13 +0100 Subject: [FIX] corrects issue where calling some functions such as swap axis when in chart view would display the table and the chart at the same time (addon web_graph) bzr revid: ged@openerp.com-20131127112513-6s342zmarkglt52s --- addons/web_graph/static/src/js/graph.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 33a7e8db83c..61b86036cfa 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -36,18 +36,18 @@ instance.web_graph.GraphView = instance.web.View.extend({ switch (event.target.attributes['data-choice'].nodeValue) { case 'fold_columns': this.pivot_table.fold_cols(); - this.draw_table(); + this.display_data(); break; case 'fold_rows': this.pivot_table.fold_rows(); - this.draw_table(); + this.display_data(); break; case 'fold_all': this.pivot_table.fold_all(); - this.draw_table(); + this.display_data(); break; case 'expand_all': - this.pivot_table.expand_all().then(this.proxy('draw_table')); + this.pivot_table.expand_all().then(this.proxy('display_data')); break; } }, @@ -57,10 +57,10 @@ instance.web_graph.GraphView = instance.web.View.extend({ switch (event.target.attributes['data-choice'].nodeValue) { case 'swap_axis': this.pivot_table.swap_axis(); - this.draw_table(); + this.display_data(); break; case 'update_values': - this.pivot_table.update_values().then(this.proxy('draw_table')); + this.pivot_table.update_values().then(this.proxy('display_data')); break; case 'export_data': // Export code... To do... @@ -80,7 +80,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ event.preventDefault(); this.dropdown.remove(); this.pivot_table.expand(id, field_id) - .then(this.proxy('draw_table')); + .then(this.proxy('display_data')); }, }, @@ -162,11 +162,11 @@ instance.web_graph.GraphView = instance.web.View.extend({ if (!this.pivot_table) { self.pivot_table = new openerp.web_graph.PivotTable(self.data); - self.pivot_table.start().then(self.proxy('draw_table')); + self.pivot_table.start().then(self.proxy('display_data')); } else { this.pivot_table.domain = domain; this.pivot_table.update_values().done(function () { - self.draw_table(); + self.display_data(); }); } }, @@ -197,11 +197,11 @@ instance.web_graph.GraphView = instance.web.View.extend({ if (header.is_expanded) { pivot.fold(header); - this.draw_table(); + this.display_data(); } else { if (header.path.length < header.root.groupby.length) { var field = header.root.groupby[header.path.length]; - pivot.expand(id, field).then(this.proxy('draw_table')); + pivot.expand(id, field).then(this.proxy('display_data')); } else { this.display_dropdown({id:header.id, target: $(options.event.target), @@ -231,7 +231,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, draw_table: function () { - this.table.empty(); this.draw_top_headers(); _.each(this.pivot_table.rows.headers, this.proxy('draw_row')); }, -- cgit v1.2.3 From 761ff102265b69f0d0a4402480797c1b1f93e904 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 27 Nov 2013 14:04:06 +0100 Subject: [FIX] properly closes the dropdown menu (field selection when expanding row/col) when the user clicks somewhere else (addon web_graph) bzr revid: ged@openerp.com-20131127130406-slj3rvp02y3utevm --- addons/web_graph/static/src/js/graph.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 61b86036cfa..6c1f5ae3f32 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -70,6 +70,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ 'click .web_graph_click' : function (event) { event.preventDefault(); + event.stopPropagation(); var id = event.target.attributes['data-id'].nodeValue; this.handle_header_event({id:id, event:event}); }, @@ -78,12 +79,21 @@ instance.web_graph.GraphView = instance.web.View.extend({ var id = event.target.attributes['data-id'].nodeValue, field_id = event.target.attributes['data-field-id'].nodeValue; event.preventDefault(); - this.dropdown.remove(); this.pivot_table.expand(id, field_id) .then(this.proxy('display_data')); }, }, + init: function(parent, dataset, view_id, options) { + this._super(parent); + this.dataset = dataset; + this.set_default_options(options); + this.dropdown = null; + this.pivot_table = null; + this.heat_map_mode = false; + this.mode = 'pivot'; + }, + view_loading: function (fields_view_get) { var self = this, model = new instance.web.Model(fields_view_get.model, {group_by_no_leaf: true}), @@ -93,9 +103,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ important_fields = [], row_groupby = []; - this.pivot_table = null; - this.heat_map_mode = false; - this.mode = 'pivot'; // get the default groupbys and measure defined in the field view _.each(fields_view_get.arch.children, function (field) { @@ -153,6 +160,12 @@ instance.web_graph.GraphView = instance.web.View.extend({ start: function () { this.table = $('
'); this.$('.graph_main_content').append(this.table); + instance.web.bus.on('click', this, function (ev) { + if (this.dropdown) { + this.dropdown.remove(); + this.dropdown = null; + } + }); return this.load_view(); }, @@ -227,7 +240,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.dropdown.css({position:'absolute', left:options.x, top:options.y}); - $('.field-selection').next('.dropdown-menu').toggle(); + this.$('.field-selection').next('.dropdown-menu').toggle(); }, draw_table: function () { -- cgit v1.2.3 From 6e88cce3fb48c9ee780bb043f7ba548eb6e98d77 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 27 Nov 2013 15:07:01 +0100 Subject: [FIX] display message insteal of crashing when there are no records to display (addon web_graph) bzr revid: ged@openerp.com-20131127140701-9gej0qik7l4nzgni --- addons/web_graph/static/src/js/graph.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 6c1f5ae3f32..78fb16582a9 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -193,13 +193,18 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.$('.graph_main_content svg').remove(); this.table.empty(); - var table_modes = ['pivot', 'heatmap', 'row_heatmap', 'col_heatmap']; - if (_.contains(table_modes, this.mode)) { - this.draw_table(); + if (this.pivot_table.no_data) { + var msg = 'No data available. Try to remove any filter or add some data.'; + this.table.append($('' + msg + '')); } else { - this.$('.graph_main_content').append($('
')); - var svg = this.$('.graph_main_content svg')[0]; - openerp.web_graph.draw_chart(this.mode, this.pivot_table, svg); + var table_modes = ['pivot', 'heatmap', 'row_heatmap', 'col_heatmap']; + if (_.contains(table_modes, this.mode)) { + this.draw_table(); + } else { + this.$('.graph_main_content').append($('
')); + var svg = this.$('.graph_main_content svg')[0]; + openerp.web_graph.draw_chart(this.mode, this.pivot_table, svg); + } } }, -- cgit v1.2.3 From 574253bb63dc3d9a630033336c2d2dad9adf9e12 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 27 Nov 2013 15:45:05 +0100 Subject: [REF] improves the draw_row method which will allow to support row_heat_map and col_heatmap in table view (addon web_graph) bzr revid: ged@openerp.com-20131127144505-fq1bb3xv97a2ek38 --- addons/web_graph/static/src/js/graph.js | 44 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 23 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 78fb16582a9..1b18e9cd181 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -333,38 +333,36 @@ instance.web_graph.GraphView = instance.web.View.extend({ _.each(pivot.cols.headers, function (col) { if (col.children.length === 0) { var value = pivot.get_value(row.id, col.id), - cell = $(''); - - cell.append((value === undefined) ? '' : value); - if ((self.mode == 'heatmap') && (value !== undefined)) { - var color = Math.floor(50 + 205*(pivot.total - value)/pivot.total); - cell.css('background-color', 'rgb(255,' + color + ',' + color + ')'); - } - if (row.is_expanded && (row.path.length <= 2)) { - var color = row.path.length * 5 + 240; - cell.css('background-color', 'rgb(' + [color, color, color].join() + ')'); - } + cell = make_cell(value); html_row.append(cell); } }); - var total = pivot.get_value(row.id, pivot.cols.main.id); - var cell = $('') - .append(total) - .css('font-weight', 'bold'); - if (row.is_expanded && (row.path.length <= 2)) { - var color = row.path.length * 5 + 240; - cell.css('background-color', 'rgb(' + [color, color, color].join() + ')'); - } else if (self.heat_map_mode) { - var color = Math.floor(50 + 205*(pivot.total - total)/pivot.total); - cell.css('background-color', 'rgb(255,' + color + ',' + color + ')'); - } if (pivot.cols.main.children.length > 0) { + var row_total = pivot.get_value(row.id, pivot.cols.main.id), + cell = make_cell(row_total).css('font-weight', 'bold'); html_row.append(cell); } this.table.append(html_row); - } + + function make_cell (value) { + var color, + cell = $(''); + if (value !== undefined) { + cell.append(value); + } + if ((self.mode === 'pivot') && (row.is_expanded) && (row.path.length <=2)) { + color = row.path.length * 5 + 240; + cell.css('background-color', $.Color(color, color, color)); + } + if (self.mode === 'heatmap') { + color = Math.floor(50 + 205*(pivot.total - value)/pivot.total); + cell.css('background-color', $.Color(255, color, color)); + } + return cell; + } + }, }); }; -- cgit v1.2.3 From c17791dd8274d8cd98fba8773fad50676e801b34 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 27 Nov 2013 15:47:06 +0100 Subject: [FIX] corrects stupid bug with previous commit, where empty cells were colored in heatmap mode (addon web_graph) bzr revid: ged@openerp.com-20131127144706-w7amtjnnku214yih --- addons/web_graph/static/src/js/graph.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 1b18e9cd181..e9f0c8795ab 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -349,9 +349,10 @@ instance.web_graph.GraphView = instance.web.View.extend({ function make_cell (value) { var color, cell = $(''); - if (value !== undefined) { - cell.append(value); + if (value === undefined) { + return cell; } + cell.append(value); if ((self.mode === 'pivot') && (row.is_expanded) && (row.path.length <=2)) { color = row.path.length * 5 + 240; cell.css('background-color', $.Color(color, color, color)); -- cgit v1.2.3 From f5514c70ab0d5980d139409e97d7947497f11902 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 27 Nov 2013 16:06:28 +0100 Subject: [IMP] adds support for row_heatmap and col_heatmap mode to table view (addon web_graph) bzr revid: ged@openerp.com-20131127150628-lval018q5gc1d5ok --- addons/web_graph/static/src/js/graph.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index e9f0c8795ab..67c6a1dc26b 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -333,34 +333,46 @@ instance.web_graph.GraphView = instance.web.View.extend({ _.each(pivot.cols.headers, function (col) { if (col.children.length === 0) { var value = pivot.get_value(row.id, col.id), - cell = make_cell(value); + cell = make_cell(value, col); html_row.append(cell); } }); if (pivot.cols.main.children.length > 0) { var row_total = pivot.get_value(row.id, pivot.cols.main.id), - cell = make_cell(row_total).css('font-weight', 'bold'); + cell = make_cell(row_total, pivot.cols.main) + .css('font-weight', 'bold'); html_row.append(cell); } this.table.append(html_row); - function make_cell (value) { + function make_cell (value, col) { var color, + total, cell = $(''); - if (value === undefined) { - return cell; - } - cell.append(value); if ((self.mode === 'pivot') && (row.is_expanded) && (row.path.length <=2)) { color = row.path.length * 5 + 240; cell.css('background-color', $.Color(color, color, color)); } + if (value === undefined) { + return cell; + } + cell.append(value); if (self.mode === 'heatmap') { color = Math.floor(50 + 205*(pivot.total - value)/pivot.total); cell.css('background-color', $.Color(255, color, color)); } + if (self.mode === 'row_heatmap') { + total = pivot.get_value(row.id, pivot.cols.main.id); + color = Math.floor(50 + 205*(total - value)/total); + cell.css('background-color', $.Color(255, color, color)); + } + if (self.mode === 'col_heatmap') { + total = pivot.get_value(col.id, pivot.rows.main.id); + color = Math.floor(50 + 205*(total - value)/total); + cell.css('background-color', $.Color(255, color, color)); + } return cell; } }, -- cgit v1.2.3 From 51e4b240f841a76f562832cc84fcd0c6cd553721 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 28 Nov 2013 09:27:54 +0100 Subject: [IMP] adds support for multiple measures in graph view (addon web_graph) bzr revid: ged@openerp.com-20131128082754-4l7nx8ooye1pmc53 --- addons/web_graph/static/src/js/graph.js | 57 ++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 22 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 67c6a1dc26b..1bcb0fd98d3 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -31,6 +31,13 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.display_data(); }, + 'click .graph_measure_selection li' : function (event) { + event.preventDefault(); + var measure = event.target.attributes['data-choice'].nodeValue; + this.pivot_table.set_measure(measure) + .then(this.proxy('display_data')); + }, + 'click .graph_expand_selection li' : function (event) { event.preventDefault(); switch (event.target.attributes['data-choice'].nodeValue) { @@ -92,23 +99,35 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.pivot_table = null; this.heat_map_mode = false; this.mode = 'pivot'; + this.measure_list = []; + this.important_fields = []; + }, + + start: function () { + this.table = $('
'); + this.$('.graph_main_content').append(this.table); + instance.web.bus.on('click', this, function (ev) { + if (this.dropdown) { + this.dropdown.remove(); + this.dropdown = null; + } + }); + + return this.load_view(); }, view_loading: function (fields_view_get) { var self = this, model = new instance.web.Model(fields_view_get.model, {group_by_no_leaf: true}), domain = [], - measure = null, fields, - important_fields = [], row_groupby = []; - // get the default groupbys and measure defined in the field view _.each(fields_view_get.arch.children, function (field) { if ('name' in field.attrs) { if ('operator' in field.attrs) { - measure = field.attrs.name; + self.measure_list.push(field.attrs.name); } else { row_groupby.push(field.attrs.name); } @@ -130,7 +149,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ _.each(g.children, function (g) { if (g.attrs.context) { var field_id = py.eval(g.attrs.context).group_by; - important_fields.push(field_id); + self.important_fields.push(field_id); } }); }); @@ -146,27 +165,21 @@ instance.web_graph.GraphView = instance.web.View.extend({ model: model, domain: domain, fields: fields, - important_fields: important_fields, - measure: measure, - measure_label: fields[measure].string, + measure: self.measure_list[0], + measure_label: fields[self.measure_list[0]].string, col_groupby: [], row_groupby: row_groupby, groups: [], - total: null, }; - }); - }, + var measure_selection = self.$('.graph_measure_selection'); + _.each(self.measure_list, function (measure) { + var choice = $('').attr('data-choice', measure) + .attr('href', '#') + .append(fields[measure].string); + measure_selection.append($('
  • ').append(choice)); - start: function () { - this.table = $('
    '); - this.$('.graph_main_content').append(this.table); - instance.web.bus.on('click', this, function (ev) { - if (this.dropdown) { - this.dropdown.remove(); - this.dropdown = null; - } - }); - return this.load_view(); + }); + }); }, do_search: function (domain, context, group_by) { @@ -233,7 +246,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ var self = this, pivot = this.pivot_table, already_grouped = pivot.rows.groupby.concat(pivot.cols.groupby), - possible_groups = _.difference(self.data.important_fields, already_grouped), + possible_groups = _.difference(self.important_fields, already_grouped), dropdown_options = { header_id: options.id, fields: _.map(possible_groups, function (field) { -- cgit v1.2.3 From be00aca052de10bbcfcf82ab00bac7802059e331 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 28 Nov 2013 09:45:51 +0100 Subject: [REF] removes all references to measure label in pivot table (addon web_graph) bzr revid: ged@openerp.com-20131128084551-19hc23fmw3gvtoc9 --- addons/web_graph/static/src/js/graph.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 1bcb0fd98d3..119d0b12e16 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -34,7 +34,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ 'click .graph_measure_selection li' : function (event) { event.preventDefault(); var measure = event.target.attributes['data-choice'].nodeValue; - this.pivot_table.set_measure(measure) + this.measure = (measure === '__count') ? null : measure; + this.pivot_table.set_measure(this.measure) .then(this.proxy('display_data')); }, @@ -99,6 +100,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.pivot_table = null; this.heat_map_mode = false; this.mode = 'pivot'; + this.measure = null; this.measure_list = []; this.important_fields = []; }, @@ -133,6 +135,9 @@ instance.web_graph.GraphView = instance.web.View.extend({ } } }); + if (this.measure_list.length > 0) { + this.measure = this.measure_list[0]; + } // get the most important fields (of the model) by looking at the // groupby filters defined in the search view @@ -161,12 +166,12 @@ instance.web_graph.GraphView = instance.web.View.extend({ return $.when(important_fields_def, field_descr_def) .then(function () { + self.fields = fields; self.data = { model: model, domain: domain, fields: fields, - measure: self.measure_list[0], - measure_label: fields[self.measure_list[0]].string, + measure: self.measure, col_groupby: [], row_groupby: row_groupby, groups: [], @@ -261,7 +266,13 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.$('.field-selection').next('.dropdown-menu').toggle(); }, + measure_label: function () { + return (this.measure) ? this.fields[this.measure].string : 'Quantity'; + }, + draw_table: function () { + this.pivot_table.rows.main.title = 'Total'; + this.pivot_table.cols.main.title = this.measure_label(); this.draw_top_headers(); _.each(this.pivot_table.rows.headers, this.proxy('draw_row')); }, -- cgit v1.2.3 From 4aa70638ef8418f18e05bd8ff7dba88724b886a6 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 28 Nov 2013 10:47:46 +0100 Subject: [REF] adds a 'get_total' method and simplify a few parts of the code using totals (addon web_graph) bzr revid: ged@openerp.com-20131128094746-mthch89zqx66flq7 --- addons/web_graph/static/src/js/graph.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 119d0b12e16..c1c2b52f4b8 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -363,8 +363,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ }); if (pivot.cols.main.children.length > 0) { - var row_total = pivot.get_value(row.id, pivot.cols.main.id), - cell = make_cell(row_total, pivot.cols.main) + var cell = make_cell(pivot.get_total(row), pivot.cols.main) .css('font-weight', 'bold'); html_row.append(cell); } @@ -384,16 +383,17 @@ instance.web_graph.GraphView = instance.web.View.extend({ } cell.append(value); if (self.mode === 'heatmap') { - color = Math.floor(50 + 205*(pivot.total - value)/pivot.total); + total = pivot.get_total(); + color = Math.floor(50 + 205*(total - value)/total); cell.css('background-color', $.Color(255, color, color)); } if (self.mode === 'row_heatmap') { - total = pivot.get_value(row.id, pivot.cols.main.id); + total = pivot.get_total(row); color = Math.floor(50 + 205*(total - value)/total); cell.css('background-color', $.Color(255, color, color)); } if (self.mode === 'col_heatmap') { - total = pivot.get_value(col.id, pivot.rows.main.id); + total = pivot.get_total(col); color = Math.floor(50 + 205*(total - value)/total); cell.css('background-color', $.Color(255, color, color)); } -- cgit v1.2.3 From e0920173a32f7889ce2b9bc49a7a83ad035ca60a Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 28 Nov 2013 11:16:25 +0100 Subject: [REF] improves the initialization process of pivot table (addon web_graph) bzr revid: ged@openerp.com-20131128101625-7ig5lftk8wv8w6tj --- addons/web_graph/static/src/js/graph.js | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index c1c2b52f4b8..5d4eade76fb 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -114,7 +114,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.dropdown = null; } }); - return this.load_view(); }, @@ -167,7 +166,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ return $.when(important_fields_def, field_descr_def) .then(function () { self.fields = fields; - self.data = { + var data = { model: model, domain: domain, fields: fields, @@ -176,6 +175,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ row_groupby: row_groupby, groups: [], }; + self.pivot_table = new openerp.web_graph.PivotTable(data); + var measure_selection = self.$('.graph_measure_selection'); _.each(self.measure_list, function (measure) { var choice = $('').attr('data-choice', measure) @@ -188,18 +189,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, do_search: function (domain, context, group_by) { - var self = this; - this.data.domain = new instance.web.CompoundDomain(domain); - - if (!this.pivot_table) { - self.pivot_table = new openerp.web_graph.PivotTable(self.data); - self.pivot_table.start().then(self.proxy('display_data')); - } else { - this.pivot_table.domain = domain; - this.pivot_table.update_values().done(function () { - self.display_data(); - }); - } + this.pivot_table.domain = domain; + this.pivot_table.update_values().done(this.proxy('display_data')); }, do_show: function () { @@ -255,7 +246,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ dropdown_options = { header_id: options.id, fields: _.map(possible_groups, function (field) { - return {id: field, value: self.data.fields[field].string}; + return {id: field, value: self.fields[field].string}; })}; this.dropdown = $(QWeb.render('field_selection', dropdown_options)); -- cgit v1.2.3 From 6afd98516c4d18a146570184d3b667a3438ffdfc Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 28 Nov 2013 11:49:29 +0100 Subject: [REF] removes a few useless lines in view_loading method (addon web_graph) bzr revid: ged@openerp.com-20131128104929-4ou50xebjub3bijh --- addons/web_graph/static/src/js/graph.js | 45 ++++++++++++++------------------- 1 file changed, 19 insertions(+), 26 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 5d4eade76fb..de4d40a923a 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -120,8 +120,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ view_loading: function (fields_view_get) { var self = this, model = new instance.web.Model(fields_view_get.model, {group_by_no_leaf: true}), - domain = [], - fields, row_groupby = []; // get the default groupbys and measure defined in the field view @@ -140,40 +138,35 @@ instance.web_graph.GraphView = instance.web.View.extend({ // get the most important fields (of the model) by looking at the // groupby filters defined in the search view - var load_view = instance.web.fields_view_get({ - model: model, - view_type: 'search', - }); - - var important_fields_def = $.when(load_view).then(function (search_view) { - var groups = _.select(search_view.arch.children, function (c) { - return (c.tag == 'group') && (c.attrs.string != 'Display'); - }); - _.each(groups, function(g) { - _.each(g.children, function (g) { - if (g.attrs.context) { - var field_id = py.eval(g.attrs.context).group_by; - self.important_fields.push(field_id); - } + var options = {model:model, view_type: 'search'}, + deferred1 = instance.web.fields_view_get(options).then(function (search_view) { + var groups = _.select(search_view.arch.children, function (c) { + return (c.tag == 'group') && (c.attrs.string != 'Display'); + }); + _.each(groups, function(g) { + _.each(g.children, function (g) { + if (g.attrs.context) { + var field_id = py.eval(g.attrs.context).group_by; + self.important_fields.push(field_id); + } + }); }); }); - }); // get the fields descriptions from the model - var field_descr_def = model.call('fields_get', []) - .then(function (fs) { fields = fs; }); + var deferred2 = model.call('fields_get', []).then(function (fs) { + self.fields = fs; + console.log("fiels",self.fields); + }); - return $.when(important_fields_def, field_descr_def) + return $.when(deferred1, deferred2) .then(function () { - self.fields = fields; var data = { model: model, - domain: domain, - fields: fields, + domain: [], measure: self.measure, col_groupby: [], row_groupby: row_groupby, - groups: [], }; self.pivot_table = new openerp.web_graph.PivotTable(data); @@ -181,7 +174,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ _.each(self.measure_list, function (measure) { var choice = $('').attr('data-choice', measure) .attr('href', '#') - .append(fields[measure].string); + .append(self.fields[measure].string); measure_selection.append($('
  • ').append(choice)); }); -- cgit v1.2.3 From 7b2109dcae11ac37afce0918390f61b348290c02 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 28 Nov 2013 11:54:02 +0100 Subject: [REF] removes a few useless lines in view_loading method (addon web_graph) bzr revid: ged@openerp.com-20131128105402-eb3pqksd5v9ixaxn --- addons/web_graph/static/src/js/graph.js | 39 +++++++++++++++------------------ 1 file changed, 18 insertions(+), 21 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index de4d40a923a..689cccaab14 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -156,29 +156,26 @@ instance.web_graph.GraphView = instance.web.View.extend({ // get the fields descriptions from the model var deferred2 = model.call('fields_get', []).then(function (fs) { self.fields = fs; - console.log("fiels",self.fields); - }); - - return $.when(deferred1, deferred2) - .then(function () { - var data = { - model: model, - domain: [], - measure: self.measure, - col_groupby: [], - row_groupby: row_groupby, - }; - self.pivot_table = new openerp.web_graph.PivotTable(data); - - var measure_selection = self.$('.graph_measure_selection'); - _.each(self.measure_list, function (measure) { - var choice = $('').attr('data-choice', measure) - .attr('href', '#') - .append(self.fields[measure].string); - measure_selection.append($('
  • ').append(choice)); + var measure_selection = self.$('.graph_measure_selection'); + _.each(self.measure_list, function (measure) { + var choice = $('').attr('data-choice', measure) + .attr('href', '#') + .append(self.fields[measure].string); + measure_selection.append($('
  • ').append(choice)); - }); }); + }); + + return $.when(deferred1, deferred2).then(function () { + var data = { + model: model, + domain: [], + measure: self.measure, + col_groupby: [], + row_groupby: row_groupby, + }; + self.pivot_table = new openerp.web_graph.PivotTable(data); + }); }, do_search: function (domain, context, group_by) { -- cgit v1.2.3 From d41ca29475074bfccf79d9206019913e0c16f5ff Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 28 Nov 2013 14:01:46 +0100 Subject: [IMP] adds some rudimentary support to the integration of search bar groupby into the graph view (addon web_graph) bzr revid: ged@openerp.com-20131128130146-33i0ydw9gbjqgc0v --- addons/web_graph/static/src/js/graph.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 689cccaab14..94c5a4011f9 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -180,7 +180,11 @@ instance.web_graph.GraphView = instance.web.View.extend({ do_search: function (domain, context, group_by) { this.pivot_table.domain = domain; - this.pivot_table.update_values().done(this.proxy('display_data')); + if (group_by.length > 0) { + this.pivot_table.set_row_groupby(group_by).done(this.proxy('display_data')); + } else { + this.pivot_table.update_values().done(this.proxy('display_data')); + } }, do_show: function () { -- cgit v1.2.3 From 55bbabaf46cbc50e959192fdb8310a07afe77aef Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 28 Nov 2013 14:49:04 +0100 Subject: [IMP] changes the set_row_groupby method into set_groupby (more generic, works for rows and cols) (addon web_graph) bzr revid: ged@openerp.com-20131128134904-ubkxdowr29is2o86 --- addons/web_graph/static/src/js/graph.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 94c5a4011f9..450a86a470a 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -181,7 +181,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ do_search: function (domain, context, group_by) { this.pivot_table.domain = domain; if (group_by.length > 0) { - this.pivot_table.set_row_groupby(group_by).done(this.proxy('display_data')); + this.pivot_table.set_groupby(this.pivot_table.rows, group_by) + .done(this.proxy('display_data')); } else { this.pivot_table.update_values().done(this.proxy('display_data')); } -- cgit v1.2.3 From e2d2d51b7a7e9a77cb8b89e4adee35763e61201a Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 28 Nov 2013 15:51:55 +0100 Subject: [IMP] supports the attribute 'type' in the xml definition of the graph view, at least for bar_charts (addon web_graph) bzr revid: ged@openerp.com-20131128145155-b5w4fhw9vrp9txuc --- addons/web_graph/static/src/js/graph.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 450a86a470a..77f444948b5 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -122,6 +122,10 @@ instance.web_graph.GraphView = instance.web.View.extend({ model = new instance.web.Model(fields_view_get.model, {group_by_no_leaf: true}), row_groupby = []; + if (fields_view_get.arch.attrs.type === 'bar') { + this.mode = 'bar_chart'; + } + // get the default groupbys and measure defined in the field view _.each(fields_view_get.arch.children, function (field) { if ('name' in field.attrs) { -- cgit v1.2.3 From 15547d9267178493a22074b20b68099eb5948abb Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 5 Dec 2013 11:07:10 +0100 Subject: [REF] refactors the event handling code and prepare the way for supporting col_groupby and groupby in the searchbar (addon web_graph) bzr revid: ged@openerp.com-20131205100710-5owdxv0m971ymwbs --- addons/web_graph/static/src/js/graph.js | 248 ++++++++++++++++++++++---------- 1 file changed, 176 insertions(+), 72 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 77f444948b5..f1c9b62e137 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -15,8 +15,7 @@ var QWeb = instance.web.qweb; instance.web.views.add('graph', 'instance.web_graph.GraphView'); /** - * GraphView view. It mostly contains a widget (PivotTable), some data, and - * calls to charts function. + * GraphView */ instance.web_graph.GraphView = instance.web.View.extend({ template: 'GraphView', @@ -24,72 +23,12 @@ instance.web_graph.GraphView = instance.web.View.extend({ view_type: 'graph', events: { - 'click .graph_mode_selection li' : function (event) { - event.preventDefault(); - var mode = event.target.attributes['data-mode'].nodeValue; - this.mode = mode; - this.display_data(); - }, - - 'click .graph_measure_selection li' : function (event) { - event.preventDefault(); - var measure = event.target.attributes['data-choice'].nodeValue; - this.measure = (measure === '__count') ? null : measure; - this.pivot_table.set_measure(this.measure) - .then(this.proxy('display_data')); - }, - - 'click .graph_expand_selection li' : function (event) { - event.preventDefault(); - switch (event.target.attributes['data-choice'].nodeValue) { - case 'fold_columns': - this.pivot_table.fold_cols(); - this.display_data(); - break; - case 'fold_rows': - this.pivot_table.fold_rows(); - this.display_data(); - break; - case 'fold_all': - this.pivot_table.fold_all(); - this.display_data(); - break; - case 'expand_all': - this.pivot_table.expand_all().then(this.proxy('display_data')); - break; - } - }, - - 'click .graph_options_selection li' : function (event) { - event.preventDefault(); - switch (event.target.attributes['data-choice'].nodeValue) { - case 'swap_axis': - this.pivot_table.swap_axis(); - this.display_data(); - break; - case 'update_values': - this.pivot_table.update_values().then(this.proxy('display_data')); - break; - case 'export_data': - // Export code... To do... - break; - } - }, - - 'click .web_graph_click' : function (event) { - event.preventDefault(); - event.stopPropagation(); - var id = event.target.attributes['data-id'].nodeValue; - this.handle_header_event({id:id, event:event}); - }, - - 'click a.field-selection' : function (event) { - var id = event.target.attributes['data-id'].nodeValue, - field_id = event.target.attributes['data-field-id'].nodeValue; - event.preventDefault(); - this.pivot_table.expand(id, field_id) - .then(this.proxy('display_data')); - }, + 'click .graph_mode_selection li' : 'mode_selection', + 'click .graph_measure_selection li' : 'measure_selection', + 'click .graph_expand_selection li' : 'expand_selection', + 'click .graph_options_selection li' : 'option_selection', + 'click .web_graph_click' : 'cell_click_callback', + 'click a.field-selection' : 'field_selection', }, init: function(parent, dataset, view_id, options) { @@ -103,6 +42,12 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.measure = null; this.measure_list = []; this.important_fields = []; + this.search_view = parent.searchview; + this.search_field = { + get_context: function () { }, + get_domain: function () { }, + get_groupby: function () { }, + }; }, start: function () { @@ -183,12 +128,38 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, do_search: function (domain, context, group_by) { + console.log("START DO SEARCH",group_by); + var self = this; + this.pivot_table.domain = domain; if (group_by.length > 0) { this.pivot_table.set_groupby(this.pivot_table.rows, group_by) .done(this.proxy('display_data')); } else { - this.pivot_table.update_values().done(this.proxy('display_data')); + this.pivot_table.update_values().done(this.proxy('display_data')); + } + + var colgroupby = get_search_col_groupby(); + console.log ("colgroupby", colgroupby); + console.log("pivot cbh",this.pivot_table.cols.groupby); + + if (!_.isEqual(colgroupby, this.pivot_table.cols.groupby)) { + // console.log ('yop'); + // this.pivot_table.set_groupby(this.pivot_table.cols, colgroupby) + // .done(this.proxy('display_data')); + } + // console.log("query",this.search_view.query.models); + function get_search_col_groupby() { + var colgroupby = [], + search = _.find(self.search_view.query.models, function (model) { + return model.attributes.category == 'ColGroupBy'; + }); + if (search) { + colgroupby = _.map(search.values.models, function (val) { + return val.attributes.value; + }); + } + return colgroupby; } }, @@ -198,6 +169,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, display_data: function () { + console.log('displaying data'); this.$('.graph_main_content svg').remove(); this.table.empty(); @@ -216,6 +188,11 @@ instance.web_graph.GraphView = instance.web.View.extend({ } }, + +/****************************************************************************** + * Event handling methods... + ******************************************************************************/ + handle_header_event: function (options) { var pivot = this.pivot_table, id = options.id, @@ -237,6 +214,127 @@ instance.web_graph.GraphView = instance.web.View.extend({ } }, + + mode_selection: function (event) { + event.preventDefault(); + var mode = event.target.attributes['data-mode'].nodeValue; + this.mode = mode; + this.display_data(); + // console.log('yop'); + // var self = this; + // var attr = [{label: self.fields['user_id'].string, value: 'user_id'}]; + // var attr2 = [{label: self.fields['user_id'].string, value: { + // attrs: {domain: [], context: {'group_by':'user_id'}} + // }}]; + // var groupbytest = { + // category: 'GroupBy', + // values: attr2, + // icon: 'u', + // field: self.search_view._s_groupby, + // }; + + // // console.log("rnst",self.search_view); + // var test = { + // values: attr, + // icon: 'u', + // field: self.search_field, + // category: _t("ColGroupBy"), + // }; + // self.search_view.query.add(test); + // self.search_view.query.add(groupbytest, {}); + + }, + + + measure_selection: function (event) { + event.preventDefault(); + var measure = event.target.attributes['data-choice'].nodeValue; + this.measure = (measure === '__count') ? null : measure; + this.pivot_table.set_measure(this.measure) + .then(this.proxy('display_data')); + }, + + expand_selection: function (event) { + event.preventDefault(); + switch (event.target.attributes['data-choice'].nodeValue) { + case 'fold_columns': + this.pivot_table.fold_cols(); + this.display_data(); + break; + case 'fold_rows': + this.pivot_table.fold_rows(); + this.display_data(); + break; + case 'fold_all': + this.pivot_table.fold_all(); + this.display_data(); + break; + case 'expand_all': + this.pivot_table.expand_all().then(this.proxy('display_data')); + break; + } + }, + + option_selection: function (event) { + event.preventDefault(); + switch (event.target.attributes['data-choice'].nodeValue) { + case 'swap_axis': + this.pivot_table.swap_axis(); + this.display_data(); + break; + case 'update_values': + this.pivot_table.update_values().then(this.proxy('display_data')); + break; + case 'export_data': + // Export code... To do... + break; + } + }, + + + cell_click_callback: function (event) { + event.preventDefault(); + event.stopPropagation(); + var id = event.target.attributes['data-id'].nodeValue; + this.handle_header_event({id:id, event:event}); + }, + + field_selection: function (event) { + var self = this, + id = event.target.attributes['data-id'].nodeValue, + field_id = event.target.attributes['data-field-id'].nodeValue; + event.preventDefault(); + this.pivot_table.expand(id, field_id).then(function () { + + var attr = [{label: self.fields[field_id].string, value: field_id}]; + var attr2 = [{label: self.fields[field_id].string, value: { + attrs: {domain: [], context: {'group_by':'stage_id'}} + }}]; + + var test = { + values: attr, + icon: 'u', + field: self.search_field, + category: _t("ColGroupBy"), + }; + + var groupbytest = { + category: 'GroupBy', + values: attr2, + icon: 'u', + field: self.search_view._s_groupby, + }; + + // console.log("rnst",self.search_view); + console.log('BEF ADD CGB'); + // self.search_view.query.add(test); + console.log('BEF ADD RGB'); + // self.search_view.query.add(groupbytest, {}); + console.log('AFTER ADD GB'); + self.display_data(); + }); + }, + display_dropdown: function (options) { var self = this, pivot = this.pivot_table, @@ -256,9 +354,9 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.$('.field-selection').next('.dropdown-menu').toggle(); }, - measure_label: function () { - return (this.measure) ? this.fields[this.measure].string : 'Quantity'; - }, +/****************************************************************************** + * Drawing pivot table methods... + ******************************************************************************/ draw_table: function () { this.pivot_table.rows.main.title = 'Total'; @@ -267,6 +365,10 @@ instance.web_graph.GraphView = instance.web.View.extend({ _.each(this.pivot_table.rows.headers, this.proxy('draw_row')); }, + measure_label: function () { + return (this.measure) ? this.fields[this.measure].string : 'Quantity'; + }, + make_border_cell: function (colspan, rowspan) { return $('').addClass('graph_border') .attr('colspan', colspan) @@ -392,4 +494,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, }); + + }; -- cgit v1.2.3 From d3fffbff509f171fe658181891d90f0476f5145b Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 5 Dec 2013 16:19:45 +0100 Subject: [IMP] beginning of searchbar integration in graph view (addon web_graph) bzr revid: ged@openerp.com-20131205151945-8yo2vkykztvlru3g --- addons/web_graph/static/src/js/graph.js | 202 ++++++++++++++++++-------------- 1 file changed, 115 insertions(+), 87 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index f1c9b62e137..83f9ee4e33c 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -33,12 +33,14 @@ instance.web_graph.GraphView = instance.web.View.extend({ init: function(parent, dataset, view_id, options) { this._super(parent); + + this.model = new instance.web.Model(dataset.model, {group_by_no_leaf: true}); this.dataset = dataset; + + this.pivot_table = new openerp.web_graph.PivotTable(this.model, dataset.domain); this.set_default_options(options); this.dropdown = null; - this.pivot_table = null; - this.heat_map_mode = false; - this.mode = 'pivot'; + this.mode = 'pivot'; // pivot, bar_chart, line_chart, pie_chart, heatmap, row_heatmap, col_heatmap this.measure = null; this.measure_list = []; this.important_fields = []; @@ -48,6 +50,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ get_domain: function () { }, get_groupby: function () { }, }; + this.groupby_mode = 'default'; // 'default' or 'manual' + this.default_row_groupby = []; }, start: function () { @@ -64,8 +68,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ view_loading: function (fields_view_get) { var self = this, - model = new instance.web.Model(fields_view_get.model, {group_by_no_leaf: true}), - row_groupby = []; + measure = null; if (fields_view_get.arch.attrs.type === 'bar') { this.mode = 'bar_chart'; @@ -77,17 +80,18 @@ instance.web_graph.GraphView = instance.web.View.extend({ if ('operator' in field.attrs) { self.measure_list.push(field.attrs.name); } else { - row_groupby.push(field.attrs.name); + self.default_row_groupby.push(field.attrs.name); } } }); if (this.measure_list.length > 0) { - this.measure = this.measure_list[0]; + measure = this.measure_list[0]; + this.pivot_table.set_measure(measure); } // get the most important fields (of the model) by looking at the // groupby filters defined in the search view - var options = {model:model, view_type: 'search'}, + var options = {model:this.model, view_type: 'search'}, deferred1 = instance.web.fields_view_get(options).then(function (search_view) { var groups = _.select(search_view.arch.children, function (c) { return (c.tag == 'group') && (c.attrs.string != 'Display'); @@ -103,8 +107,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ }); // get the fields descriptions from the model - var deferred2 = model.call('fields_get', []).then(function (fs) { - self.fields = fs; + var deferred2 = this.model.call('fields_get', []).then(function (fs) { + self.fields = fs; var measure_selection = self.$('.graph_measure_selection'); _.each(self.measure_list, function (measure) { var choice = $('').attr('data-choice', measure) @@ -115,51 +119,41 @@ instance.web_graph.GraphView = instance.web.View.extend({ }); }); - return $.when(deferred1, deferred2).then(function () { - var data = { - model: model, - domain: [], - measure: self.measure, - col_groupby: [], - row_groupby: row_groupby, - }; - self.pivot_table = new openerp.web_graph.PivotTable(data); - }); + return $.when(deferred1, deferred2); }, do_search: function (domain, context, group_by) { - console.log("START DO SEARCH",group_by); - var self = this; + var self = this, + col_groupby = get_col_groupby('ColGroupBy'); - this.pivot_table.domain = domain; - if (group_by.length > 0) { - this.pivot_table.set_groupby(this.pivot_table.rows, group_by) - .done(this.proxy('display_data')); - } else { - this.pivot_table.update_values().done(this.proxy('display_data')); + if (group_by.length || col_groupby.length) { + this.groupby_mode = 'manual'; + if (!group_by.length) { + group_by = this.default_row_groupby; + } } - var colgroupby = get_search_col_groupby(); - console.log ("colgroupby", colgroupby); - console.log("pivot cbh",this.pivot_table.cols.groupby); - - if (!_.isEqual(colgroupby, this.pivot_table.cols.groupby)) { - // console.log ('yop'); - // this.pivot_table.set_groupby(this.pivot_table.cols, colgroupby) - // .done(this.proxy('display_data')); + this.pivot_table.set_domain(domain); + if (this.groupby_mode === 'manual') { + this.pivot_table.set_row_groupby(group_by); + this.pivot_table.set_col_groupby(col_groupby); + } else { + this.pivot_table.set_row_groupby(this.default_row_groupby); + this.pivot_table.set_col_groupby([]); } - // console.log("query",this.search_view.query.models); - function get_search_col_groupby() { - var colgroupby = [], + this.display_data(); + + function get_col_groupby() { + var groupby = [], search = _.find(self.search_view.query.models, function (model) { return model.attributes.category == 'ColGroupBy'; }); if (search) { - colgroupby = _.map(search.values.models, function (val) { + groupby = _.map(search.values.models, function (val) { return val.attributes.value; }); } - return colgroupby; + return groupby; } }, @@ -169,21 +163,25 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, display_data: function () { - console.log('displaying data'); - this.$('.graph_main_content svg').remove(); - this.table.empty(); - - if (this.pivot_table.no_data) { - var msg = 'No data available. Try to remove any filter or add some data.'; - this.table.append($('' + msg + '')); + var pivot = this.pivot_table; + if (pivot.stale_data) { + pivot.update_data().done(this.proxy('display_data')); } else { - var table_modes = ['pivot', 'heatmap', 'row_heatmap', 'col_heatmap']; - if (_.contains(table_modes, this.mode)) { - this.draw_table(); + this.$('.graph_main_content svg').remove(); + this.table.empty(); + + if (pivot.no_data) { + var msg = 'No data available. Try to remove any filter or add some data.'; + this.table.append($('' + msg + '')); } else { - this.$('.graph_main_content').append($('
    ')); - var svg = this.$('.graph_main_content svg')[0]; - openerp.web_graph.draw_chart(this.mode, this.pivot_table, svg); + var table_modes = ['pivot', 'heatmap', 'row_heatmap', 'col_heatmap']; + if (_.contains(table_modes, this.mode)) { + this.draw_table(); + } else { + this.$('.graph_main_content').append($('
    ')); + var svg = this.$('.graph_main_content svg')[0]; + openerp.web_graph.draw_chart(this.mode, this.pivot_table, svg); + } } } }, @@ -221,8 +219,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.mode = mode; this.display_data(); // console.log('yop'); - // var self = this; - // var attr = [{label: self.fields['user_id'].string, value: 'user_id'}]; // var attr2 = [{label: self.fields['user_id'].string, value: { // attrs: {domain: [], context: {'group_by':'user_id'}} // }}]; @@ -234,24 +230,48 @@ instance.web_graph.GraphView = instance.web.View.extend({ // }; // // console.log("rnst",self.search_view); + // var self = this; + // var attr = [{label: self.fields['user_id'].string, value: 'user_id'}]; // var test = { // values: attr, // icon: 'u', // field: self.search_field, // category: _t("ColGroupBy"), // }; - // self.search_view.query.add(test); + // self.search_view.query.add(test); // self.search_view.query.add(groupbytest, {}); }, + register_groupby: function (category, field) { + var groupby; + if (category === 'ColGroupBy') { + groupby = { + category: 'ColGroupBy', + values: [{label: this.fields[field].string, value: field}], + icon: 'u', + field: this.search_field, + }; + this.search_view.query.add(groupby); + } + if (category === 'GroupBy') { + var value = {attrs: {domain: [], context: {'group_by':field}}}; + groupby = { + category: 'GroupBy', + values: [{label: this.fields[field].string, value: value}], + icon: 'u', + field: this.search_view._s_groupby, + }; + this.search_view.query.add(groupby); + } + }, measure_selection: function (event) { event.preventDefault(); var measure = event.target.attributes['data-choice'].nodeValue; this.measure = (measure === '__count') ? null : measure; - this.pivot_table.set_measure(this.measure) - .then(this.proxy('display_data')); + this.pivot_table.set_measure(this.measure); + this.display_data(); }, expand_selection: function (event) { @@ -270,7 +290,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.display_data(); break; case 'expand_all': - this.pivot_table.expand_all().then(this.proxy('display_data')); + this.pivot_table.invalidate_data(); + this.display_data(); break; } }, @@ -283,7 +304,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.display_data(); break; case 'update_values': - this.pivot_table.update_values().then(this.proxy('display_data')); + this.pivot_table.stale_data = true; + this.display_data(); break; case 'export_data': // Export code... To do... @@ -306,32 +328,38 @@ instance.web_graph.GraphView = instance.web.View.extend({ event.preventDefault(); this.pivot_table.expand(id, field_id).then(function () { - var attr = [{label: self.fields[field_id].string, value: field_id}]; - var attr2 = [{label: self.fields[field_id].string, value: { - attrs: {domain: [], context: {'group_by':'stage_id'}} - }}]; - - var test = { - values: attr, - icon: 'u', - field: self.search_field, - category: _t("ColGroupBy"), - }; - - var groupbytest = { - category: 'GroupBy', - values: attr2, - icon: 'u', - field: self.search_view._s_groupby, - }; - - // console.log("rnst",self.search_view); - console.log('BEF ADD CGB'); - // self.search_view.query.add(test); - console.log('BEF ADD RGB'); - // self.search_view.query.add(groupbytest, {}); - console.log('AFTER ADD GB'); - self.display_data(); + if (self.pivot_table.is_col(id)) { + self.register_groupby('ColGroupBy', field_id); + } else { + self.register_groupby('GroupBy', field_id); + // self.display_data(); + } + // var attr = [{label: self.fields[field_id].string, value: field_id}]; + // var attr2 = [{label: self.fields[field_id].string, value: { + // attrs: {domain: [], context: {'group_by':'stage_id'}} + // }}]; + + // var test = { + // values: attr, + // icon: 'u', + // field: self.search_field, + // category: _t("ColGroupBy"), + // }; + + // var groupbytest = { + // category: 'GroupBy', + // values: attr2, + // icon: 'u', + // field: self.search_view._s_groupby, + // }; + + // // console.log("rnst",self.search_view); + // console.log('BEF ADD CGB'); + // // self.search_view.query.add(test); + // console.log('BEF ADD RGB'); + // // self.search_view.query.add(groupbytest, {}); + // console.log('AFTER ADD GB'); + // self.display_data(); }); }, -- cgit v1.2.3 From d1caee2a5f04ff5919e5a6f1240a867832a480f6 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 6 Dec 2013 13:44:37 +0100 Subject: [IMP] supports search bar integration in graph view (but not everything works yet) (addon web_graph) bzr revid: ged@openerp.com-20131206124437-8m1gnhz3ill6w1eo --- addons/web_graph/static/src/js/graph.js | 164 ++++++++++++++++++-------------- 1 file changed, 94 insertions(+), 70 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 83f9ee4e33c..bd4842eac41 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -123,14 +123,20 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, do_search: function (domain, context, group_by) { + console.log('dgb', this.default_row_groupby); + if (this.groupby_mode === 'getting_ready') { + this.groupby_mode = 'manual'; + return; + } + var self = this, col_groupby = get_col_groupby('ColGroupBy'); if (group_by.length || col_groupby.length) { this.groupby_mode = 'manual'; - if (!group_by.length) { - group_by = this.default_row_groupby; - } + // if (!group_by.length) { + // group_by = this.default_row_groupby; + // } } this.pivot_table.set_domain(domain); @@ -138,7 +144,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.pivot_table.set_row_groupby(group_by); this.pivot_table.set_col_groupby(col_groupby); } else { - this.pivot_table.set_row_groupby(this.default_row_groupby); + this.pivot_table.set_row_groupby(_.toArray(this.default_row_groupby)); this.pivot_table.set_col_groupby([]); } this.display_data(); @@ -190,15 +196,37 @@ instance.web_graph.GraphView = instance.web.View.extend({ /****************************************************************************** * Event handling methods... ******************************************************************************/ - handle_header_event: function (options) { var pivot = this.pivot_table, id = options.id, - header = pivot.get_header(id); + header = pivot.get_header(id), + dim = header.root.groupby.length; + console.log('test'); + // debugger; if (header.is_expanded) { + this.groupby_mode = 'manual'; pivot.fold(header); - this.display_data(); + if (header.root.groupby.length < dim) { + if (pivot.is_row(header.id)) { + this.clear_groupby('GroupBy'); + if (header.root.groupby.length) { + this.register_groupby('GroupBy', header.root.groupby); + } else { + + this.display_data(); + } + } else { + this.clear_groupby('ColGroupBy'); + if (header.root.groupby.length) { + this.register_groupby('ColGroupBy', header.root.groupby); + } else { + this.display_data(); + } + } + } else { + this.display_data(); + } } else { if (header.path.length < header.root.groupby.length) { var field = header.root.groupby[header.path.length]; @@ -212,60 +240,60 @@ instance.web_graph.GraphView = instance.web.View.extend({ } }, - mode_selection: function (event) { event.preventDefault(); var mode = event.target.attributes['data-mode'].nodeValue; this.mode = mode; this.display_data(); - // console.log('yop'); - // var attr2 = [{label: self.fields['user_id'].string, value: { - // attrs: {domain: [], context: {'group_by':'user_id'}} - // }}]; - // var groupbytest = { - // category: 'GroupBy', - // values: attr2, - // icon: 'u', - // field: self.search_view._s_groupby, - // }; - - // // console.log("rnst",self.search_view); - // var self = this; - // var attr = [{label: self.fields['user_id'].string, value: 'user_id'}]; - // var test = { - // values: attr, - // icon: 'u', - // field: self.search_field, - // category: _t("ColGroupBy"), - // }; - // self.search_view.query.add(test); - // self.search_view.query.add(groupbytest, {}); }, register_groupby: function (category, field) { - var groupby; + var self = this, + values, + groupby; if (category === 'ColGroupBy') { + if (!(field instanceof Array)) { + field = [field]; + } + values = _.map(field, function (f) { + return {label: self.fields[f].string, value: f}; + }); + // values = [{label: this.fields[field].string, value: field}]; groupby = { category: 'ColGroupBy', - values: [{label: this.fields[field].string, value: field}], - icon: 'u', + values: values, + icon: 'f', field: this.search_field, }; this.search_view.query.add(groupby); } if (category === 'GroupBy') { - var value = {attrs: {domain: [], context: {'group_by':field}}}; + if (!(field instanceof Array)) { + field = [field]; + } + values = _.map(field, function (f) { + return {label: self.fields[f].string, value: {attrs:{domain: [], context: {'group_by':f}}}}; + }); + // var value = {attrs: {domain: [], context: {'group_by':field}}}; + // var value2 = {attrs: {domain: [], context: {'group_by':'user_id'}}}; [{label: this.fields[field].string, value: value}, {label: 'test', value:value2}] groupby = { category: 'GroupBy', - values: [{label: this.fields[field].string, value: value}], - icon: 'u', + values: values, + icon: 'w', field: this.search_view._s_groupby, }; this.search_view.query.add(groupby); } }, + clear_groupby: function (category) { + // debugger; + this.search_view.query.models = _.filter(this.search_view.query.models, function (model) { + return model.attributes.category !== category; + }); + }, + measure_selection: function (event) { event.preventDefault(); var measure = event.target.attributes['data-choice'].nodeValue; @@ -297,11 +325,27 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, option_selection: function (event) { + var pivot = this.pivot_table; event.preventDefault(); switch (event.target.attributes['data-choice'].nodeValue) { case 'swap_axis': this.pivot_table.swap_axis(); - this.display_data(); + this.clear_groupby('GroupBy'); + this.clear_groupby('ColGroupBy'); + if (pivot.rows.groupby.length && pivot.cols.groupby.length) { + this.groupby_mode = 'getting_ready'; + this.register_groupby('GroupBy', pivot.rows.groupby); + this.register_groupby('ColGroupBy', pivot.cols.groupby); + } else { + this.groupby_mode = 'manual'; + if (pivot.rows.groupby.length) { + this.register_groupby('GroupBy', pivot.rows.groupby); + } else { + this.register_groupby('ColGroupBy', pivot.cols.groupby); + } + } + + // this.display_data(); break; case 'update_values': this.pivot_table.stale_data = true; @@ -328,38 +372,21 @@ instance.web_graph.GraphView = instance.web.View.extend({ event.preventDefault(); this.pivot_table.expand(id, field_id).then(function () { - if (self.pivot_table.is_col(id)) { - self.register_groupby('ColGroupBy', field_id); + + if (self.pivot_table.is_row(id)) { + if (self.groupby_mode === 'default') { + self.groupby_mode = 'manual'; + self.register_groupby('GroupBy', self.default_row_groupby.concat([field_id])); + } else { + self.register_groupby('GroupBy', field_id); + } } else { - self.register_groupby('GroupBy', field_id); - // self.display_data(); + if (self.groupby_mode === 'default') { + self.groupby_mode = 'getting_ready'; + self.register_groupby('GroupBy', self.default_row_groupby); + } + self.register_groupby('ColGroupBy', field_id); } - // var attr = [{label: self.fields[field_id].string, value: field_id}]; - // var attr2 = [{label: self.fields[field_id].string, value: { - // attrs: {domain: [], context: {'group_by':'stage_id'}} - // }}]; - - // var test = { - // values: attr, - // icon: 'u', - // field: self.search_field, - // category: _t("ColGroupBy"), - // }; - - // var groupbytest = { - // category: 'GroupBy', - // values: attr2, - // icon: 'u', - // field: self.search_view._s_groupby, - // }; - - // // console.log("rnst",self.search_view); - // console.log('BEF ADD CGB'); - // // self.search_view.query.add(test); - // console.log('BEF ADD RGB'); - // // self.search_view.query.add(groupbytest, {}); - // console.log('AFTER ADD GB'); - // self.display_data(); }); }, @@ -385,7 +412,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ /****************************************************************************** * Drawing pivot table methods... ******************************************************************************/ - draw_table: function () { this.pivot_table.rows.main.title = 'Total'; this.pivot_table.cols.main.title = this.measure_label(); @@ -522,6 +548,4 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, }); - - }; -- cgit v1.2.3 From 6a06f0d0eeee1efe7417d3a73eb2e4b8661d73d6 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 6 Dec 2013 16:43:19 +0100 Subject: [IMP] properly supports searchbar integration in graph view (addon web_graph) bzr revid: ged@openerp.com-20131206154319-6ci7ljmp2hd9q072 --- addons/web_graph/static/src/js/graph.js | 161 ++++++++++---------------------- 1 file changed, 47 insertions(+), 114 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index bd4842eac41..344899032d6 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -4,7 +4,6 @@ /* jshint undef: false */ - openerp.web_graph = function (instance) { 'use strict'; @@ -33,10 +32,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ init: function(parent, dataset, view_id, options) { this._super(parent); - this.model = new instance.web.Model(dataset.model, {group_by_no_leaf: true}); this.dataset = dataset; - this.pivot_table = new openerp.web_graph.PivotTable(this.model, dataset.domain); this.set_default_options(options); this.dropdown = null; @@ -45,13 +42,13 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.measure_list = []; this.important_fields = []; this.search_view = parent.searchview; - this.search_field = { - get_context: function () { }, - get_domain: function () { }, - get_groupby: function () { }, - }; this.groupby_mode = 'default'; // 'default' or 'manual' this.default_row_groupby = []; + this.search_field = { + get_context: function () { }, + get_domain: function () { }, + get_groupby: function () { }, + }; }, start: function () { @@ -123,12 +120,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, do_search: function (domain, context, group_by) { - console.log('dgb', this.default_row_groupby); - if (this.groupby_mode === 'getting_ready') { - this.groupby_mode = 'manual'; - return; - } - var self = this, col_groupby = get_col_groupby('ColGroupBy'); @@ -156,7 +147,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ }); if (search) { groupby = _.map(search.values.models, function (val) { - return val.attributes.value; + return val.attributes.value.attrs.context.col_group_by; }); } return groupby; @@ -202,35 +193,13 @@ instance.web_graph.GraphView = instance.web.View.extend({ header = pivot.get_header(id), dim = header.root.groupby.length; - console.log('test'); - // debugger; if (header.is_expanded) { - this.groupby_mode = 'manual'; pivot.fold(header); - if (header.root.groupby.length < dim) { - if (pivot.is_row(header.id)) { - this.clear_groupby('GroupBy'); - if (header.root.groupby.length) { - this.register_groupby('GroupBy', header.root.groupby); - } else { - - this.display_data(); - } - } else { - this.clear_groupby('ColGroupBy'); - if (header.root.groupby.length) { - this.register_groupby('ColGroupBy', header.root.groupby); - } else { - this.display_data(); - } - } - } else { - this.display_data(); - } + this.register_groupby(); } else { if (header.path.length < header.root.groupby.length) { var field = header.root.groupby[header.path.length]; - pivot.expand(id, field).then(this.proxy('display_data')); + pivot.expand(id, field).then(this.proxy('register_groupby')); } else { this.display_dropdown({id:header.id, target: $(options.event.target), @@ -248,52 +217,45 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, - register_groupby: function (category, field) { + register_groupby: function() { var self = this, - values, - groupby; - if (category === 'ColGroupBy') { - if (!(field instanceof Array)) { - field = [field]; - } - values = _.map(field, function (f) { - return {label: self.fields[f].string, value: f}; - }); - // values = [{label: this.fields[field].string, value: field}]; - groupby = { - category: 'ColGroupBy', - values: values, - icon: 'f', - field: this.search_field, - }; - this.search_view.query.add(groupby); - } - if (category === 'GroupBy') { - if (!(field instanceof Array)) { - field = [field]; + query = this.search_view.query; + this.groupby_mode = 'manual'; + + + var rows = _.map(this.pivot_table.rows.groupby, function (group) { + return make_facet('GroupBy', group); + }); + var cols = _.map(this.pivot_table.cols.groupby, function (group) { + return make_facet('ColGroupBy', group); + }); + + query.reset(rows.concat(cols)); + + function make_facet (category, fields) { + var values, + icon, + backbone_field, + cat_name; + if (!(fields instanceof Array)) { fields = [fields]; } + if (category === 'GroupBy') { + cat_name = 'group_by'; + icon = 'w'; + backbone_field = self.search_view._s_groupby; + } else { + cat_name = 'col_group_by'; + icon = 'f'; + backbone_field = self.search_field; } - values = _.map(field, function (f) { - return {label: self.fields[f].string, value: {attrs:{domain: [], context: {'group_by':f}}}}; + values = _.map(fields, function (field) { + var context = {}; + context[cat_name] = field; + return {label: self.fields[field].string, value: {attrs:{domain: [], context: context}}}; }); - // var value = {attrs: {domain: [], context: {'group_by':field}}}; - // var value2 = {attrs: {domain: [], context: {'group_by':'user_id'}}}; [{label: this.fields[field].string, value: value}, {label: 'test', value:value2}] - groupby = { - category: 'GroupBy', - values: values, - icon: 'w', - field: this.search_view._s_groupby, - }; - this.search_view.query.add(groupby); + return {category:category, values: values, icon:icon, field: backbone_field}; } }, - clear_groupby: function (category) { - // debugger; - this.search_view.query.models = _.filter(this.search_view.query.models, function (model) { - return model.attributes.category !== category; - }); - }, - measure_selection: function (event) { event.preventDefault(); var measure = event.target.attributes['data-choice'].nodeValue; @@ -307,15 +269,15 @@ instance.web_graph.GraphView = instance.web.View.extend({ switch (event.target.attributes['data-choice'].nodeValue) { case 'fold_columns': this.pivot_table.fold_cols(); - this.display_data(); + this.register_groupby(); break; case 'fold_rows': this.pivot_table.fold_rows(); - this.display_data(); + this.register_groupby(); break; case 'fold_all': this.pivot_table.fold_all(); - this.display_data(); + this.register_groupby(); break; case 'expand_all': this.pivot_table.invalidate_data(); @@ -330,28 +292,14 @@ instance.web_graph.GraphView = instance.web.View.extend({ switch (event.target.attributes['data-choice'].nodeValue) { case 'swap_axis': this.pivot_table.swap_axis(); - this.clear_groupby('GroupBy'); - this.clear_groupby('ColGroupBy'); - if (pivot.rows.groupby.length && pivot.cols.groupby.length) { - this.groupby_mode = 'getting_ready'; - this.register_groupby('GroupBy', pivot.rows.groupby); - this.register_groupby('ColGroupBy', pivot.cols.groupby); - } else { - this.groupby_mode = 'manual'; - if (pivot.rows.groupby.length) { - this.register_groupby('GroupBy', pivot.rows.groupby); - } else { - this.register_groupby('ColGroupBy', pivot.cols.groupby); - } - } - - // this.display_data(); + this.register_groupby(); break; case 'update_values': this.pivot_table.stale_data = true; this.display_data(); break; case 'export_data': + this.register_groupby(); // Export code... To do... break; } @@ -371,22 +319,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ field_id = event.target.attributes['data-field-id'].nodeValue; event.preventDefault(); this.pivot_table.expand(id, field_id).then(function () { - - - if (self.pivot_table.is_row(id)) { - if (self.groupby_mode === 'default') { - self.groupby_mode = 'manual'; - self.register_groupby('GroupBy', self.default_row_groupby.concat([field_id])); - } else { - self.register_groupby('GroupBy', field_id); - } - } else { - if (self.groupby_mode === 'default') { - self.groupby_mode = 'getting_ready'; - self.register_groupby('GroupBy', self.default_row_groupby); - } - self.register_groupby('ColGroupBy', field_id); - } + self.register_groupby(); }); }, -- cgit v1.2.3 From 5c04caf2ee2050bb0607f3ebf066e744b398d21f Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 6 Dec 2013 17:04:11 +0100 Subject: [REF] many small code cleanups in addon web_graph bzr revid: ged@openerp.com-20131206160411-9ajcschidssftb49 --- addons/web_graph/static/src/js/graph.js | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 344899032d6..8cf0ffd4877 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -38,7 +38,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.set_default_options(options); this.dropdown = null; this.mode = 'pivot'; // pivot, bar_chart, line_chart, pie_chart, heatmap, row_heatmap, col_heatmap - this.measure = null; this.measure_list = []; this.important_fields = []; this.search_view = parent.searchview; @@ -125,9 +124,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ if (group_by.length || col_groupby.length) { this.groupby_mode = 'manual'; - // if (!group_by.length) { - // group_by = this.default_row_groupby; - // } } this.pivot_table.set_domain(domain); @@ -214,7 +210,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ var mode = event.target.attributes['data-mode'].nodeValue; this.mode = mode; this.display_data(); - }, register_groupby: function() { @@ -222,7 +217,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ query = this.search_view.query; this.groupby_mode = 'manual'; - var rows = _.map(this.pivot_table.rows.groupby, function (group) { return make_facet('GroupBy', group); }); @@ -259,8 +253,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ measure_selection: function (event) { event.preventDefault(); var measure = event.target.attributes['data-choice'].nodeValue; - this.measure = (measure === '__count') ? null : measure; - this.pivot_table.set_measure(this.measure); + this.pivot_table.set_measure((measure === '__count') ? null : measure); this.display_data(); }, @@ -276,7 +269,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.register_groupby(); break; case 'fold_all': - this.pivot_table.fold_all(); + this.pivot_table.fold_cols(); + this.pivot_table.fold_rows(); this.register_groupby(); break; case 'expand_all': @@ -287,7 +281,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, option_selection: function (event) { - var pivot = this.pivot_table; event.preventDefault(); switch (event.target.attributes['data-choice'].nodeValue) { case 'swap_axis': @@ -299,7 +292,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.display_data(); break; case 'export_data': - this.register_groupby(); // Export code... To do... break; } @@ -353,7 +345,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, measure_label: function () { - return (this.measure) ? this.fields[this.measure].string : 'Quantity'; + var pivot = this.pivot_table; + return (pivot.measure) ? this.fields[pivot.measure].string : 'Quantity'; }, make_border_cell: function (colspan, rowspan) { -- cgit v1.2.3 From 65a0a97d67e02b5a659838bf54cd2accb892bc89 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 6 Dec 2013 17:25:49 +0100 Subject: [IMP] usability fix, makes sure that the dropdown menu displayed when expanding a field in graph view has always the same choices (addon web_graph) bzr revid: ged@openerp.com-20131206162549-08aw50z4zdelzxgc --- addons/web_graph/static/src/js/graph.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 8cf0ffd4877..7efc482f2dd 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -179,7 +179,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ } }, - /****************************************************************************** * Event handling methods... ******************************************************************************/ @@ -318,11 +317,11 @@ instance.web_graph.GraphView = instance.web.View.extend({ display_dropdown: function (options) { var self = this, pivot = this.pivot_table, - already_grouped = pivot.rows.groupby.concat(pivot.cols.groupby), - possible_groups = _.difference(self.important_fields, already_grouped), + // already_grouped = pivot.rows.groupby.concat(pivot.cols.groupby), + // possible_groups = _.difference(self.important_fields, already_grouped), dropdown_options = { header_id: options.id, - fields: _.map(possible_groups, function (field) { + fields: _.map(self.important_fields, function (field) { return {id: field, value: self.fields[field].string}; })}; -- cgit v1.2.3 From 66c8114768376670408a856a3c10bb342b40de5e Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 6 Dec 2013 17:26:41 +0100 Subject: [REF] removes two useless lines (addon web_graph) bzr revid: ged@openerp.com-20131206162641-27rerhfa56y6nf4e --- addons/web_graph/static/src/js/graph.js | 3 --- 1 file changed, 3 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 7efc482f2dd..a5de9f2dde7 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -317,14 +317,11 @@ instance.web_graph.GraphView = instance.web.View.extend({ display_dropdown: function (options) { var self = this, pivot = this.pivot_table, - // already_grouped = pivot.rows.groupby.concat(pivot.cols.groupby), - // possible_groups = _.difference(self.important_fields, already_grouped), dropdown_options = { header_id: options.id, fields: _.map(self.important_fields, function (field) { return {id: field, value: self.fields[field].string}; })}; - this.dropdown = $(QWeb.render('field_selection', dropdown_options)); options.target.after(this.dropdown); this.dropdown.css({position:'absolute', -- cgit v1.2.3 From 9f99fbdae7483ae8e73c4f6525ab8f3d23137126 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Mon, 9 Dec 2013 14:08:58 +0100 Subject: [FIX] properly writes the col group_by in the context (with the facets) which allows the filter to work correctly, in graph view (addon web_graph) bzr revid: ged@openerp.com-20131209130858-o8pqocw7otpqr8l0 --- addons/web_graph/static/src/js/graph.js | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index a5de9f2dde7..d64918aee56 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -44,12 +44,19 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.groupby_mode = 'default'; // 'default' or 'manual' this.default_row_groupby = []; this.search_field = { - get_context: function () { }, - get_domain: function () { }, + get_context: this.proxy('get_context'), + get_domain: function () {}, get_groupby: function () { }, }; }, + get_context: function (facet) { + var col_group_by = _.map(facet.values.models, function (model) { + return model.attributes.value.attrs.context.col_group_by; + }); + return {col_group_by : col_group_by}; + }, + start: function () { this.table = $('
    '); this.$('.graph_main_content').append(this.table); @@ -120,7 +127,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ do_search: function (domain, context, group_by) { var self = this, - col_groupby = get_col_groupby('ColGroupBy'); + col_groupby = context.col_group_by || []; // get_col_groupby('ColGroupBy'); if (group_by.length || col_groupby.length) { this.groupby_mode = 'manual'; @@ -135,19 +142,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.pivot_table.set_col_groupby([]); } this.display_data(); - - function get_col_groupby() { - var groupby = [], - search = _.find(self.search_view.query.models, function (model) { - return model.attributes.category == 'ColGroupBy'; - }); - if (search) { - groupby = _.map(search.values.models, function (val) { - return val.attributes.value.attrs.context.col_group_by; - }); - } - return groupby; - } }, do_show: function () { -- cgit v1.2.3 From 1419b0793939de96bf67fc2e48d05a4fc55773d7 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 10 Dec 2013 12:16:46 +0100 Subject: [IMP] improves the way the chart view understands the xml descr of the view, so that nows fields after the operator = + are considered col groupbys (addon web_graph) bzr revid: ged@openerp.com-20131210111646-9d8l78npv72pqfp8 --- addons/web_graph/static/src/js/graph.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index d64918aee56..e35b8516dd4 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -43,6 +43,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.search_view = parent.searchview; this.groupby_mode = 'default'; // 'default' or 'manual' this.default_row_groupby = []; + this.default_col_groupby = []; this.search_field = { get_context: this.proxy('get_context'), get_domain: function () {}, @@ -83,7 +84,11 @@ instance.web_graph.GraphView = instance.web.View.extend({ if ('operator' in field.attrs) { self.measure_list.push(field.attrs.name); } else { - self.default_row_groupby.push(field.attrs.name); + if (self.measure_list.length) { + self.default_col_groupby.push(field.attrs.name); + } else { + self.default_row_groupby.push(field.attrs.name); + } } } }); @@ -139,7 +144,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.pivot_table.set_col_groupby(col_groupby); } else { this.pivot_table.set_row_groupby(_.toArray(this.default_row_groupby)); - this.pivot_table.set_col_groupby([]); + this.pivot_table.set_col_groupby(_.toArray(this.default_col_groupby)); } this.display_data(); }, -- cgit v1.2.3 From 4416acaa5391860a010a03a05d82fa7c5f6b9b57 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 11 Dec 2013 11:12:24 +0100 Subject: [IMP] makes line charts smarter when multiple columns exists, in graph view (addon web_graph) bzr revid: ged@openerp.com-20131211101224-eul3hvm0dt7kdz41 --- addons/web_graph/static/src/js/graph.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index e35b8516dd4..07c0e578b83 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -172,7 +172,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ } else { this.$('.graph_main_content').append($('
    ')); var svg = this.$('.graph_main_content svg')[0]; - openerp.web_graph.draw_chart(this.mode, this.pivot_table, svg); + openerp.web_graph.draw_chart(this.mode, this.pivot_table, svg, this.measure_label()); } } } -- cgit v1.2.3 From 14d0a6e74c0cceb1af75377a314369122bd152c9 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 11 Dec 2013 13:43:07 +0100 Subject: [IMP] makes sure that the values displayed in the pivot table are properly formatted according to their types (addon web_graph) bzr revid: ged@openerp.com-20131211124307-z9lxbn39spahlxpw --- addons/web_graph/static/src/js/graph.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 07c0e578b83..53f0308f24c 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -407,9 +407,15 @@ instance.web_graph.GraphView = instance.web.View.extend({ }); }, + get_measure_type: function () { + var measure = this.pivot_table.measure; + return (measure) ? this.fields[measure].type : 'integer'; + }, + draw_row: function (row) { var self = this, pivot = this.pivot_table, + measure_type = this.get_measure_type(), html_row = $(''), row_header = this.make_border_cell(1,1) .append(this.make_header_title(row).attr('data-id', row.id)) @@ -448,7 +454,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ if (value === undefined) { return cell; } - cell.append(value); + cell.append(instance.web.format_value(value, {type: measure_type})); if (self.mode === 'heatmap') { total = pivot.get_total(); color = Math.floor(50 + 205*(total - value)/total); -- cgit v1.2.3 From b8a5b2d2b509bd19ef580f6c137327dbbae924f5 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 11 Dec 2013 14:11:48 +0100 Subject: [IMP] takes all integer and float field from model as possible measure (addon web_graph) bzr revid: ged@openerp.com-20131211131148-vdfhmf96fn2txvcj --- addons/web_graph/static/src/js/graph.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 53f0308f24c..8070bb152ce 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -82,9 +82,9 @@ instance.web_graph.GraphView = instance.web.View.extend({ _.each(fields_view_get.arch.children, function (field) { if ('name' in field.attrs) { if ('operator' in field.attrs) { - self.measure_list.push(field.attrs.name); + measure = field.attrs.name; } else { - if (self.measure_list.length) { + if (measure) { self.default_col_groupby.push(field.attrs.name); } else { self.default_row_groupby.push(field.attrs.name); @@ -92,10 +92,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ } } }); - if (this.measure_list.length > 0) { - measure = this.measure_list[0]; - this.pivot_table.set_measure(measure); - } + this.pivot_table.set_measure(measure); // get the most important fields (of the model) by looking at the // groupby filters defined in the search view @@ -117,6 +114,16 @@ instance.web_graph.GraphView = instance.web.View.extend({ // get the fields descriptions from the model var deferred2 = this.model.call('fields_get', []).then(function (fs) { self.fields = fs; + var temp = _.map(fs, function (field, name) { + return {name:name, type: field.type}; + }); + temp = _.filter(temp, function (field) { + return (((field.type === 'integer') || (field.type === 'float')) && (field.name !== 'id')); + }); + self.measure_list = _.map(temp, function (field) { + return field.name; + }); + var measure_selection = self.$('.graph_measure_selection'); _.each(self.measure_list, function (measure) { var choice = $('').attr('data-choice', measure) -- cgit v1.2.3 From b04f21ea12406fc28e7a74494af0397f6ce9e6d1 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 11 Dec 2013 15:01:40 +0100 Subject: [IMP] finally uses the full width and height to draw charts, instead of hardcoded numbers (in graph view) (addon web_graph) bzr revid: ged@openerp.com-20131211140140-shlpos1jt3z8wj41 --- addons/web_graph/static/src/js/graph.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 8070bb152ce..f1d08968626 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -61,6 +61,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ start: function () { this.table = $('
    '); this.$('.graph_main_content').append(this.table); + this.width = this.$el.width(); + this.height = this.$el.parent().parent().height(); // to get view manager body instance.web.bus.on('click', this, function (ev) { if (this.dropdown) { this.dropdown.remove(); @@ -178,8 +180,15 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.draw_table(); } else { this.$('.graph_main_content').append($('
    ')); - var svg = this.$('.graph_main_content svg')[0]; - openerp.web_graph.draw_chart(this.mode, this.pivot_table, svg, this.measure_label()); + var options = { + svg: this.$('.graph_main_content svg')[0], + mode: this.mode, + pivot: this.pivot_table, + width: this.width, + height: this.height - 30, + measure_label: this.measure_label() + }; + openerp.web_graph.draw_chart(options); } } } -- cgit v1.2.3 From 8da86807b6d459a7c6d010e447ea006c61790923 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 11 Dec 2013 15:50:56 +0100 Subject: [FIX] quick fix to make sure charts have a minimal height that is not too small (addon web_graph) bzr revid: ged@openerp.com-20131211145056-nzpnir06xx3q0n9y --- addons/web_graph/static/src/js/graph.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index f1d08968626..0b0078e7ff1 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -185,7 +185,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ mode: this.mode, pivot: this.pivot_table, width: this.width, - height: this.height - 30, + height: Math.max(this.height - 45, 250), measure_label: this.measure_label() }; openerp.web_graph.draw_chart(options); -- cgit v1.2.3 From 945719fb7dc9c63933dfbd0a27d557b4e0d2c3c6 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 11 Dec 2013 17:00:11 +0100 Subject: [FIX] correctly computes the height and the width of the graph view (addon web_graph) bzr revid: ged@openerp.com-20131211160011-fhv7ah63hlnyg7l0 --- addons/web_graph/static/src/js/graph.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 0b0078e7ff1..364014288c1 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -61,8 +61,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ start: function () { this.table = $('
    '); this.$('.graph_main_content').append(this.table); - this.width = this.$el.width(); - this.height = this.$el.parent().parent().height(); // to get view manager body instance.web.bus.on('click', this, function (ev) { if (this.dropdown) { this.dropdown.remove(); @@ -180,12 +178,17 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.draw_table(); } else { this.$('.graph_main_content').append($('
    ')); + // console.log('this.perentaui', this.getParent().$el); + // this.width = this.$el.width(); + // this.height = this.$el.parent().parent().height(); // to get view manager body + + // debugger; var options = { svg: this.$('.graph_main_content svg')[0], mode: this.mode, pivot: this.pivot_table, - width: this.width, - height: Math.max(this.height - 45, 250), + width: this.$el.width(), + height: Math.max(this.$el.parent().parent().height() - 45, 250), measure_label: this.measure_label() }; openerp.web_graph.draw_chart(options); -- cgit v1.2.3 From 7a672064c02d56f7c833c727e596b098caa5bf08 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 11 Dec 2013 17:28:50 +0100 Subject: [FIX] improves the handling of headers titles when the db query returns false or undefined (addon web_graph) bzr revid: ged@openerp.com-20131211162850-mgqs5csnw8wca974 --- addons/web_graph/static/src/js/graph.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 364014288c1..808f944c5f7 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -178,17 +178,12 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.draw_table(); } else { this.$('.graph_main_content').append($('
    ')); - // console.log('this.perentaui', this.getParent().$el); - // this.width = this.$el.width(); - // this.height = this.$el.parent().parent().height(); // to get view manager body - - // debugger; var options = { svg: this.$('.graph_main_content svg')[0], mode: this.mode, pivot: this.pivot_table, width: this.$el.width(), - height: Math.max(this.$el.parent().parent().height() - 45, 250), + height: Math.max(document.documentElement.clientHeight - 116 - 60, 250), measure_label: this.measure_label() }; openerp.web_graph.draw_chart(options); -- cgit v1.2.3 From f24f38ca880754ea6d514abe4d692b263c95605b Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 12 Dec 2013 09:39:36 +0100 Subject: [FIX] removes a debugger statement (addon web_graph) bzr revid: ged@openerp.com-20131212083936-5s8xi6ays4xq9jul --- addons/web_graph/static/src/js/graph.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 808f944c5f7..918a698e7b7 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -183,7 +183,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ mode: this.mode, pivot: this.pivot_table, width: this.$el.width(), - height: Math.max(document.documentElement.clientHeight - 116 - 60, 250), + height: Math.min(Math.max(document.documentElement.clientHeight - 116 - 60, 250), Math.round(0.8*this.$el.width())), measure_label: this.measure_label() }; openerp.web_graph.draw_chart(options); -- cgit v1.2.3 From e0ee9a58c547cd06d2d33018e43b02e549c10e9e Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 12 Dec 2013 11:55:33 +0100 Subject: [IMP] removes the expand/fold menu, because the search view covers the same functionality (addon web_graph) bzr revid: ged@openerp.com-20131212105533-uawad2hgqopfkygo --- addons/web_graph/static/src/js/graph.js | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 918a698e7b7..912f56e79fc 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -24,7 +24,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ events: { 'click .graph_mode_selection li' : 'mode_selection', 'click .graph_measure_selection li' : 'measure_selection', - 'click .graph_expand_selection li' : 'expand_selection', 'click .graph_options_selection li' : 'option_selection', 'click .web_graph_click' : 'cell_click_callback', 'click a.field-selection' : 'field_selection', @@ -269,36 +268,17 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.display_data(); }, - expand_selection: function (event) { + option_selection: function (event) { event.preventDefault(); switch (event.target.attributes['data-choice'].nodeValue) { - case 'fold_columns': - this.pivot_table.fold_cols(); - this.register_groupby(); - break; - case 'fold_rows': - this.pivot_table.fold_rows(); - this.register_groupby(); - break; - case 'fold_all': - this.pivot_table.fold_cols(); - this.pivot_table.fold_rows(); + case 'swap_axis': + this.pivot_table.swap_axis(); this.register_groupby(); break; case 'expand_all': this.pivot_table.invalidate_data(); this.display_data(); break; - } - }, - - option_selection: function (event) { - event.preventDefault(); - switch (event.target.attributes['data-choice'].nodeValue) { - case 'swap_axis': - this.pivot_table.swap_axis(); - this.register_groupby(); - break; case 'update_values': this.pivot_table.stale_data = true; this.display_data(); @@ -368,7 +348,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ return $(' ') .addClass('web_graph_click') .attr('href', '#') - .addClass((header.is_expanded) ? 'icon-minus-sign' : 'icon-plus-sign') + .addClass((header.is_expanded) ? 'fa fa-minus-square' : 'fa fa-plus-square') .append((header.title !== undefined) ? header.title : 'Undefined'); }, -- cgit v1.2.3 From c256cd4f14d1f1cde45f5eecdd705fe758295b4d Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Mon, 16 Dec 2013 15:49:35 +0100 Subject: [REF] merges update_data and query_all_values method into load_data, to simplify code (addon web_graph) bzr revid: ged@openerp.com-20131216144935-2ur7pgk7ml2064j0 --- addons/web_graph/static/src/js/graph.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 912f56e79fc..8433e560cfd 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -163,7 +163,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ display_data: function () { var pivot = this.pivot_table; if (pivot.stale_data) { - pivot.update_data().done(this.proxy('display_data')); + pivot.load_data().done(this.proxy('display_data')); } else { this.$('.graph_main_content svg').remove(); this.table.empty(); -- cgit v1.2.3 From de51e3c35a4ada3bc29c3de2abd371e43569f814 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 17 Dec 2013 12:15:01 +0100 Subject: [REF] moves more code to dataLoader class to simplify pivot class (clean separation between pivot code and loading code) (addon web_graph) bzr revid: ged@openerp.com-20131217111501-wu0nbid36bncy4wz --- addons/web_graph/static/src/js/graph.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 8433e560cfd..912f56e79fc 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -163,7 +163,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ display_data: function () { var pivot = this.pivot_table; if (pivot.stale_data) { - pivot.load_data().done(this.proxy('display_data')); + pivot.update_data().done(this.proxy('display_data')); } else { this.$('.graph_main_content svg').remove(); this.table.empty(); -- cgit v1.2.3 From 79250f0c077e3c463fd2d644b5fe398f82048a3f Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 17 Dec 2013 16:32:04 +0100 Subject: [REF] adds event handling to pivot table class (triggers 'redraw_required' and 'groupby_changed' event when necessary (addon web_graph) bzr revid: ged@openerp.com-20131217153204-43la1m8eqw632j05 --- addons/web_graph/static/src/js/graph.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 912f56e79fc..6805bce1793 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -138,20 +138,24 @@ instance.web_graph.GraphView = instance.web.View.extend({ do_search: function (domain, context, group_by) { var self = this, - col_groupby = context.col_group_by || []; // get_col_groupby('ColGroupBy'); + col_groupby = context.col_group_by || []; if (group_by.length || col_groupby.length) { this.groupby_mode = 'manual'; } this.pivot_table.set_domain(domain); + + var options; if (this.groupby_mode === 'manual') { - this.pivot_table.set_row_groupby(group_by); - this.pivot_table.set_col_groupby(col_groupby); + options = {row: group_by, col: col_groupby}; } else { - this.pivot_table.set_row_groupby(_.toArray(this.default_row_groupby)); - this.pivot_table.set_col_groupby(_.toArray(this.default_col_groupby)); + options = { + row: _.toArray(this.default_row_groupby), + col: _.toArray(this.default_col_groupby), + }; } + this.pivot_table.set_groupby(options); this.display_data(); }, -- cgit v1.2.3 From 7bb84af05f978f02dc9a8a01d9f73bbea7784d67 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 18 Dec 2013 14:40:40 +0100 Subject: [REF] large refactoring of graphview: it separates the drawing code into a widget that can be used independently of the view (addon web_graph) bzr revid: ged@openerp.com-20131218134040-63fcm5a68gsk3hry --- addons/web_graph/static/src/js/graph.js | 373 ++++++++++++++++---------------- 1 file changed, 190 insertions(+), 183 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 6805bce1793..f4d93305f41 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -13,32 +13,14 @@ var QWeb = instance.web.qweb; instance.web.views.add('graph', 'instance.web_graph.GraphView'); - /** - * GraphView - */ instance.web_graph.GraphView = instance.web.View.extend({ - template: 'GraphView', display_name: _lt('Graph'), view_type: 'graph', - events: { - 'click .graph_mode_selection li' : 'mode_selection', - 'click .graph_measure_selection li' : 'measure_selection', - 'click .graph_options_selection li' : 'option_selection', - 'click .web_graph_click' : 'cell_click_callback', - 'click a.field-selection' : 'field_selection', - }, - init: function(parent, dataset, view_id, options) { this._super(parent); - this.model = new instance.web.Model(dataset.model, {group_by_no_leaf: true}); this.dataset = dataset; - this.pivot_table = new openerp.web_graph.PivotTable(this.model, dataset.domain); - this.set_default_options(options); - this.dropdown = null; - this.mode = 'pivot'; // pivot, bar_chart, line_chart, pie_chart, heatmap, row_heatmap, col_heatmap - this.measure_list = []; - this.important_fields = []; + this.model = new instance.web.Model(dataset.model, {group_by_no_leaf: true}); this.search_view = parent.searchview; this.groupby_mode = 'default'; // 'default' or 'manual' this.default_row_groupby = []; @@ -58,14 +40,10 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, start: function () { - this.table = $('
    '); - this.$('.graph_main_content').append(this.table); - instance.web.bus.on('click', this, function (ev) { - if (this.dropdown) { - this.dropdown.remove(); - this.dropdown = null; - } - }); + var options = {enabled:false}; + this.graph_widget = new openerp.web_graph.Graph(this, this.model, options); + this.graph_widget.appendTo(this.$el); + this.graph_widget.pivot.on('groupby_changed', this, this.proxy('register_groupby')); return this.load_view(); }, @@ -77,7 +55,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.mode = 'bar_chart'; } - // get the default groupbys and measure defined in the field view _.each(fields_view_get.arch.children, function (field) { if ('name' in field.attrs) { if ('operator' in field.attrs) { @@ -91,8 +68,116 @@ instance.web_graph.GraphView = instance.web.View.extend({ } } }); - this.pivot_table.set_measure(measure); + this.graph_widget.pivot.config({measure:measure, update:false}); + }, + + do_search: function (domain, context, group_by) { + var self = this, + col_groupby = context.col_group_by || [], + options = {domain:domain}; + + if (group_by.length || col_groupby.length) { + this.groupby_mode = 'manual'; + } + if (!this.graph_widget.enabled) { + options.update = false; + options.silent = true; + } + + if (this.groupby_mode === 'manual') { + options.row_groupby = group_by; + options.col_groupby = col_groupby; + } else { + options.row_groupby = _.toArray(this.default_row_groupby); + options.col_groupby = _.toArray(this.default_col_groupby); + } + this.graph_widget.pivot.config(options); + + if (!this.graph_widget.enabled) { + this.graph_widget.activate_display(); + } + }, + + do_show: function () { + this.do_push_state({}); + return this._super(); + }, + + register_groupby: function() { + var self = this, + query = this.search_view.query; + this.groupby_mode = 'manual'; + + var rows = _.map(this.graph_widget.pivot.rows.groupby, function (group) { + return make_facet('GroupBy', group); + }); + var cols = _.map(this.graph_widget.pivot.cols.groupby, function (group) { + return make_facet('ColGroupBy', group); + }); + + query.reset(rows.concat(cols)); + + function make_facet (category, fields) { + var values, + icon, + backbone_field, + cat_name; + if (!(fields instanceof Array)) { fields = [fields]; } + if (category === 'GroupBy') { + cat_name = 'group_by'; + icon = 'w'; + backbone_field = self.search_view._s_groupby; + } else { + cat_name = 'col_group_by'; + icon = 'f'; + backbone_field = self.search_field; + } + values = _.map(fields, function (field) { + var context = {}; + context[cat_name] = field; + return {label: self.graph_widget.fields[field].string, value: {attrs:{domain: [], context: context}}}; + }); + return {category:category, values: values, icon:icon, field: backbone_field}; + } + }, +}); + +instance.web_graph.Graph = instance.web.Widget.extend({ + template: "GraphWidget", + + events: { + 'click .graph_mode_selection li' : 'mode_selection', + 'click .graph_measure_selection li' : 'measure_selection', + 'click .graph_options_selection li' : 'option_selection', + 'click .web_graph_click' : 'header_cell_clicked', + 'click a.field-selection' : 'field_selection', + }, + + init: function(parent, model, options) { + this._super(parent); + this.model = model; + this.mode = 'pivot'; + this.important_fields = []; + this.measure_list = []; + this.fields = []; + this.enabled = true; + this.dropdown = null; + + this.pivot = new openerp.web_graph.PivotTable(model, []); + + options = options || {}; + + // show_ui, hide ui ?, default stacked/grouped? + if (_.has(options, 'mode')) { this.mode = mode; } + if (_.has(options, 'measure')) { this.pivot.set_measure(options.measure); } + if (_.has(options, 'enabled')) { this.enabled = options.enabled; } + }, + + start: function() { + var self = this; + this.table = $('
    '); + this.$('.graph_main_content').append(this.table); // get the most important fields (of the model) by looking at the // groupby filters defined in the search view var options = {model:this.model, view_type: 'search'}, @@ -110,7 +195,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ }); }); - // get the fields descriptions from the model + // get the fields descriptions and measure list from the model var deferred2 = this.model.call('fields_get', []).then(function (fs) { self.fields = fs; var temp = _.map(fs, function (field, name) { @@ -133,89 +218,48 @@ instance.web_graph.GraphView = instance.web.View.extend({ }); }); - return $.when(deferred1, deferred2); - }, - - do_search: function (domain, context, group_by) { - var self = this, - col_groupby = context.col_group_by || []; - - if (group_by.length || col_groupby.length) { - this.groupby_mode = 'manual'; - } - - this.pivot_table.set_domain(domain); - - var options; - if (this.groupby_mode === 'manual') { - options = {row: group_by, col: col_groupby}; - } else { - options = { - row: _.toArray(this.default_row_groupby), - col: _.toArray(this.default_col_groupby), - }; - } - this.pivot_table.set_groupby(options); - this.display_data(); - }, - - do_show: function () { - this.do_push_state({}); - return this._super(); + return $.when(deferred1, deferred2).then(function () { + if (this.enabled) { + this.activate_display(); + } + }); }, - display_data: function () { - var pivot = this.pivot_table; - if (pivot.stale_data) { - pivot.update_data().done(this.proxy('display_data')); - } else { - this.$('.graph_main_content svg').remove(); - this.table.empty(); - - if (pivot.no_data) { - var msg = 'No data available. Try to remove any filter or add some data.'; - this.table.append($('' + msg + '')); - } else { - var table_modes = ['pivot', 'heatmap', 'row_heatmap', 'col_heatmap']; - if (_.contains(table_modes, this.mode)) { - this.draw_table(); - } else { - this.$('.graph_main_content').append($('
    ')); - var options = { - svg: this.$('.graph_main_content svg')[0], - mode: this.mode, - pivot: this.pivot_table, - width: this.$el.width(), - height: Math.min(Math.max(document.documentElement.clientHeight - 116 - 60, 250), Math.round(0.8*this.$el.width())), - measure_label: this.measure_label() - }; - openerp.web_graph.draw_chart(options); - } + activate_display: function () { + this.pivot.on('redraw_required', this, this.proxy('display_data')); + this.pivot.update_data(); + this.enabled = true; + instance.web.bus.on('click', this, function (ev) { + if (this.dropdown) { + this.dropdown.remove(); + this.dropdown = null; } - } + }); }, -/****************************************************************************** - * Event handling methods... - ******************************************************************************/ - handle_header_event: function (options) { - var pivot = this.pivot_table, - id = options.id, - header = pivot.get_header(id), - dim = header.root.groupby.length; + display_data: function () { + var pivot = this.pivot; + this.$('.graph_main_content svg').remove(); + this.table.empty(); - if (header.is_expanded) { - pivot.fold(header); - this.register_groupby(); + if (pivot.no_data) { + var msg = 'No data available. Try to remove any filter or add some data.'; + this.table.append($('' + msg + '')); } else { - if (header.path.length < header.root.groupby.length) { - var field = header.root.groupby[header.path.length]; - pivot.expand(id, field).then(this.proxy('register_groupby')); + var table_modes = ['pivot', 'heatmap', 'row_heatmap', 'col_heatmap']; + if (_.contains(table_modes, this.mode)) { + this.draw_table(); } else { - this.display_dropdown({id:header.id, - target: $(options.event.target), - x: options.event.pageX, - y: options.event.pageY}); + this.$('.graph_main_content').append($('
    ')); + var options = { + svg: this.$('.graph_main_content svg')[0], + mode: this.mode, + pivot: this.pivot, + width: this.$el.width(), + height: Math.min(Math.max(document.documentElement.clientHeight - 116 - 60, 250), Math.round(0.8*this.$el.width())), + measure_label: this.measure_label() + }; + openerp.web_graph.draw_chart(options); } } }, @@ -227,65 +271,26 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.display_data(); }, - register_groupby: function() { - var self = this, - query = this.search_view.query; - this.groupby_mode = 'manual'; - - var rows = _.map(this.pivot_table.rows.groupby, function (group) { - return make_facet('GroupBy', group); - }); - var cols = _.map(this.pivot_table.cols.groupby, function (group) { - return make_facet('ColGroupBy', group); - }); - - query.reset(rows.concat(cols)); - - function make_facet (category, fields) { - var values, - icon, - backbone_field, - cat_name; - if (!(fields instanceof Array)) { fields = [fields]; } - if (category === 'GroupBy') { - cat_name = 'group_by'; - icon = 'w'; - backbone_field = self.search_view._s_groupby; - } else { - cat_name = 'col_group_by'; - icon = 'f'; - backbone_field = self.search_field; - } - values = _.map(fields, function (field) { - var context = {}; - context[cat_name] = field; - return {label: self.fields[field].string, value: {attrs:{domain: [], context: context}}}; - }); - return {category:category, values: values, icon:icon, field: backbone_field}; - } - }, - measure_selection: function (event) { event.preventDefault(); var measure = event.target.attributes['data-choice'].nodeValue; - this.pivot_table.set_measure((measure === '__count') ? null : measure); - this.display_data(); + var actual_measure = (measure === '__count') ? null : measure + this.pivot.config({measure:actual_measure}); }, option_selection: function (event) { event.preventDefault(); switch (event.target.attributes['data-choice'].nodeValue) { case 'swap_axis': - this.pivot_table.swap_axis(); - this.register_groupby(); + this.pivot.swap_axis(); break; case 'expand_all': - this.pivot_table.invalidate_data(); - this.display_data(); + this.pivot.rows.headers = null; + this.pivot.cols.headers = null; + this.pivot.update_data(); break; case 'update_values': - this.pivot_table.stale_data = true; - this.display_data(); + this.pivot.update_data(); break; case 'export_data': // Export code... To do... @@ -293,12 +298,32 @@ instance.web_graph.GraphView = instance.web.View.extend({ } }, - - cell_click_callback: function (event) { + header_cell_clicked: function (event) { event.preventDefault(); event.stopPropagation(); - var id = event.target.attributes['data-id'].nodeValue; - this.handle_header_event({id:id, event:event}); + var id = event.target.attributes['data-id'].nodeValue, + header = this.pivot.get_header(id), + self = this, + dim = header.root.groupby.length; + + if (header.is_expanded) { + this.pivot.fold(header); + } else { + if (header.path.length < header.root.groupby.length) { + var field = header.root.groupby[header.path.length]; + this.pivot.expand(id, field); + } else { + var fields = _.map(this.important_fields, function (field) { + return {id: field, value: self.fields[field].string}; + }); + this.dropdown = $(QWeb.render('field_selection', {fields:fields, header_id:id})); + $(event.target).after(this.dropdown); + this.dropdown.css({position:'absolute', + left:event.pageX, + top:event.pageY}); + this.$('.field-selection').next('.dropdown-menu').toggle(); + } + } }, field_selection: function (event) { @@ -306,40 +331,21 @@ instance.web_graph.GraphView = instance.web.View.extend({ id = event.target.attributes['data-id'].nodeValue, field_id = event.target.attributes['data-field-id'].nodeValue; event.preventDefault(); - this.pivot_table.expand(id, field_id).then(function () { - self.register_groupby(); - }); - }, - - display_dropdown: function (options) { - var self = this, - pivot = this.pivot_table, - dropdown_options = { - header_id: options.id, - fields: _.map(self.important_fields, function (field) { - return {id: field, value: self.fields[field].string}; - })}; - this.dropdown = $(QWeb.render('field_selection', dropdown_options)); - options.target.after(this.dropdown); - this.dropdown.css({position:'absolute', - left:options.x, - top:options.y}); - this.$('.field-selection').next('.dropdown-menu').toggle(); + this.pivot.expand(id, field_id); }, /****************************************************************************** * Drawing pivot table methods... ******************************************************************************/ draw_table: function () { - this.pivot_table.rows.main.title = 'Total'; - this.pivot_table.cols.main.title = this.measure_label(); + this.pivot.rows.main.title = 'Total'; + this.pivot.cols.main.title = this.measure_label(); this.draw_top_headers(); - _.each(this.pivot_table.rows.headers, this.proxy('draw_row')); + _.each(this.pivot.rows.headers, this.proxy('draw_row')); }, measure_label: function () { - var pivot = this.pivot_table; - return (pivot.measure) ? this.fields[pivot.measure].string : 'Quantity'; + return (this.pivot.measure) ? this.fields[this.pivot.measure].string : 'Quantity'; }, make_border_cell: function (colspan, rowspan) { @@ -358,7 +364,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ draw_top_headers: function () { var self = this, - pivot = this.pivot_table, + pivot = this.pivot, height = _.max(_.map(pivot.cols.headers, function(g) {return g.path.length;})), header_cells = [[this.make_border_cell(1, height)]]; @@ -406,13 +412,13 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, get_measure_type: function () { - var measure = this.pivot_table.measure; + var measure = this.pivot.measure; return (measure) ? this.fields[measure].type : 'integer'; }, draw_row: function (row) { var self = this, - pivot = this.pivot_table, + pivot = this.pivot, measure_type = this.get_measure_type(), html_row = $(''), row_header = this.make_border_cell(1,1) @@ -471,6 +477,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ return cell; } }, + }); -}; +}; \ No newline at end of file -- cgit v1.2.3 From 0e8a8517f8ec74690c8819b00194efb667e04429 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 18 Dec 2013 16:07:56 +0100 Subject: [REF] moves all the charts code from chart.js into the graph widget (in file graph.js) (addon web_graph) bzr revid: ged@openerp.com-20131218150756-ol0or9m6pg61ye2c --- addons/web_graph/static/src/js/graph.js | 282 +++++++++++++++++++++++++++++--- 1 file changed, 262 insertions(+), 20 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index f4d93305f41..3c0fe1a8be5 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -156,23 +156,25 @@ instance.web_graph.Graph = instance.web.Widget.extend({ init: function(parent, model, options) { this._super(parent); this.model = model; - this.mode = 'pivot'; this.important_fields = []; this.measure_list = []; this.fields = []; - this.enabled = true; - this.dropdown = null; - this.pivot = new openerp.web_graph.PivotTable(model, []); - - options = options || {}; - - // show_ui, hide ui ?, default stacked/grouped? + this.mode = 'pivot'; if (_.has(options, 'mode')) { this.mode = mode; } - if (_.has(options, 'measure')) { this.pivot.set_measure(options.measure); } + this.enabled = true; if (_.has(options, 'enabled')) { this.enabled = options.enabled; } + this.visible_ui = true; + this.config(options || {}); }, + // hide ui/show, stacked/grouped + config: function (options) { + if (_.has(options, 'visible_ui')) { + this.visible_ui = options.visible_ui; + } + this.pivot.config(options); + }, start: function() { var self = this; @@ -242,6 +244,11 @@ instance.web_graph.Graph = instance.web.Widget.extend({ this.$('.graph_main_content svg').remove(); this.table.empty(); + if (this.visible_ui) { + this.$('.graph_header').css('display', 'block'); + } else { + this.$('.graph_header').css('display', 'none'); + } if (pivot.no_data) { var msg = 'No data available. Try to remove any filter or add some data.'; this.table.append($('' + msg + '')); @@ -251,15 +258,18 @@ instance.web_graph.Graph = instance.web.Widget.extend({ this.draw_table(); } else { this.$('.graph_main_content').append($('
    ')); - var options = { - svg: this.$('.graph_main_content svg')[0], - mode: this.mode, - pivot: this.pivot, - width: this.$el.width(), - height: Math.min(Math.max(document.documentElement.clientHeight - 116 - 60, 250), Math.round(0.8*this.$el.width())), - measure_label: this.measure_label() - }; - openerp.web_graph.draw_chart(options); + this.svg = this.$('.graph_main_content svg')[0]; + this.width = this.$el.width(); + this.height = Math.min(Math.max(document.documentElement.clientHeight - 116 - 60, 250), Math.round(0.8*this.$el.width())); + // var options = { + // svg: + // mode: this.mode, + // width: this.$el.width(), + // height: Math.min(Math.max(document.documentElement.clientHeight - 116 - 60, 250), Math.round(0.8*this.$el.width())), + // measure_label: this.measure_label() + // }; + this[this.mode](); + // openerp.web_graph.draw_chart(options); } } }, @@ -274,7 +284,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ measure_selection: function (event) { event.preventDefault(); var measure = event.target.attributes['data-choice'].nodeValue; - var actual_measure = (measure === '__count') ? null : measure + var actual_measure = (measure === '__count') ? null : measure; this.pivot.config({measure:actual_measure}); }, @@ -478,6 +488,238 @@ instance.web_graph.Graph = instance.web.Widget.extend({ } }, +/****************************************************************************** + * Drawing charts methods... + ******************************************************************************/ + bar_chart: function () { + var self = this, + dim_x = this.pivot.rows.groupby.length, + dim_y = this.pivot.cols.groupby.length, + data = []; + + // No groupby ************************************************************** + if ((dim_x === 0) && (dim_y === 0)) { + data = [{key: 'Total', values:[{ + title: 'Total', + value: this.pivot.get_value(this.pivot.rows.main.id, this.pivot.cols.main.id), + }]}]; + nv.addGraph(function () { + var chart = nv.models.discreteBarChart() + .x(function(d) { return d.title;}) + .y(function(d) { return d.value;}) + .tooltips(false) + .showValues(true) + .width(self.width) + .height(self.height) + .staggerLabels(true); + + d3.select(self.svg) + .datum(data) + .attr('width', self.width) + .attr('height', self.height) + .call(chart); + + nv.utils.windowResize(chart.update); + return chart; + }); + // Only column groupbys **************************************************** + } else if ((dim_x === 0) && (dim_y >= 1)){ + data = _.map(this.pivot.get_columns_depth(1), function (header) { + return { + key: header.title, + values: [{x:header.root.main.title, y: self.pivot.get_total(header)}] + }; + }); + nv.addGraph(function() { + var chart = nv.models.multiBarChart() + .stacked(true) + .tooltips(false) + .width(self.width) + .height(self.height) + .showControls(false); + + d3.select(self.svg) + .datum(data) + .attr('width', self.width) + .attr('height', self.height) + .transition() + .duration(500) + .call(chart); + + nv.utils.windowResize(chart.update); + + return chart; + }); + // Just 1 row groupby ****************************************************** + } else if ((dim_x === 1) && (dim_y === 0)) { + data = _.map(this.pivot.rows.main.children, function (pt) { + var value = self.pivot.get_value(pt.id, self.pivot.cols.main.id), + title = (pt.title !== undefined) ? pt.title : 'Undefined'; + return {title: title, value: value}; + }); + data = [{key: this.measure_label(), values:data}]; + nv.addGraph(function () { + var chart = nv.models.discreteBarChart() + .x(function(d) { return d.title;}) + .y(function(d) { return d.value;}) + .tooltips(false) + .showValues(true) + .width(self.width) + .height(self.height) + .staggerLabels(true); + + d3.select(self.svg) + .datum(data) + .attr('width', self.width) + .attr('height', self.height) + .call(chart); + + nv.utils.windowResize(chart.update); + return chart; + }); + // 1 row groupby and some col groupbys************************************** + } else if ((dim_x === 1) && (dim_y >= 1)) { + data = _.map(this.pivot.get_columns_depth(1), function (colhdr) { + var values = _.map(self.pivot.get_rows_depth(1), function (header) { + return { + x: header.title || 'Undefined', + y: self.pivot.get_value(header.id, colhdr.id, 0) + }; + }); + return {key: colhdr.title || 'Undefined', values: values}; + }); + + nv.addGraph(function () { + var chart = nv.models.multiBarChart() + .stacked(true) + .staggerLabels(true) + .width(self.width) + .height(self.height) + .tooltips(false); + + d3.select(self.svg) + .datum(data) + .attr('width', self.width) + .attr('height', self.height) + .call(chart); + + nv.utils.windowResize(chart.update); + return chart; + }); + // At least two row groupby************************************************* + } else { + var keys = _.uniq(_.map(this.pivot.get_rows_depth(2), function (hdr) { + return hdr.title || 'Undefined'; + })); + data = _.map(keys, function (key) { + var values = _.map(self.pivot.get_rows_depth(1), function (hdr) { + var subhdr = _.find(hdr.children, function (child) { + return ((child.title === key) || ((child.title === undefined) && (key === 'Undefined'))); + }); + return { + x: hdr.title || 'Undefined', + y: (subhdr) ? self.pivot.get_total(subhdr) : 0 + }; + }); + return {key:key, values: values}; + }); + + nv.addGraph(function () { + var chart = nv.models.multiBarChart() + .stacked(true) + .staggerLabels(true) + .width(self.width) + .height(self.height) + .tooltips(false); + + d3.select(self.svg) + .datum(data) + .attr('width', self.width) + .attr('height', self.height) + .call(chart); + + nv.utils.windowResize(chart.update); + return chart; + }); + } + }, + + line_chart: function () { + var self = this, + dim_x = this.pivot.rows.groupby.length, + dim_y = this.pivot.cols.groupby.length; + + var data = _.map(this.pivot.get_cols_leaves(), function (col) { + var values = _.map(self.pivot.get_rows_depth(dim_x), function (row) { + return {x: row.title, y: self.pivot.get_value(row.id,col.id, 0)}; + }); + var title = _.map(col.path, function (p) { + return p || 'Undefined'; + }).join('/'); + if (dim_y === 0) { + title = self.measure_label(); + } + return {values: values, key: title}; + }); + + nv.addGraph(function () { + var chart = nv.models.lineChart() + .x(function (d,u) { return u; }) + .width(self.width) + .height(self.height) + .margin({top: 30, right: 20, bottom: 20, left: 60}); + + d3.select(self.svg) + .attr('width', self.width) + .attr('height', self.height) + .datum(data) + .call(chart); + + return chart; + }); + }, + + pie_chart: function () { + var self = this, + dim_x = this.pivot.rows.groupby.length, + dim_y = this.pivot.cols.groupby.length; + + var data = _.map(this.pivot.get_rows_leaves(), function (row) { + var title = _.map(row.path, function (p) { + return p || 'Undefined'; + }).join('/'); + if (dim_x === 0) { + title = self.measure_label; + } + return {x: title, y: self.pivot.get_total(row)}; + }); + + nv.addGraph(function () { + var chart = nv.models.pieChart() + .color(d3.scale.category10().range()) + .width(self.width) + .height(self.height); + + d3.select(self.svg) + .datum(data) + .transition().duration(1200) + .attr('width', self.width) + .attr('height', self.height) + .call(chart); + + nv.utils.windowResize(chart.update); + return chart; + }); + }, + }); -}; \ No newline at end of file +}; + + + + + + + + -- cgit v1.2.3 From 1323c2c25b01d894f731fd1c2f76d5fabd610223 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 18 Dec 2013 16:20:48 +0100 Subject: [IMP] adds stacked/grouped setting to chart widget (addon web_graph) bzr revid: ged@openerp.com-20131218152048-36no38nud6a5ft10 --- addons/web_graph/static/src/js/graph.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 3c0fe1a8be5..145ee079c07 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -165,6 +165,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ this.enabled = true; if (_.has(options, 'enabled')) { this.enabled = options.enabled; } this.visible_ui = true; + this.bar_ui = 'group'; // group or stack this.config(options || {}); }, @@ -173,6 +174,9 @@ instance.web_graph.Graph = instance.web.Widget.extend({ if (_.has(options, 'visible_ui')) { this.visible_ui = options.visible_ui; } + if (_.has(options, 'bar_ui')) { + this.bar_ui = options.bar_ui; + } this.pivot.config(options); }, @@ -532,7 +536,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ }); nv.addGraph(function() { var chart = nv.models.multiBarChart() - .stacked(true) + .stacked(self.bar_ui === 'stacked') .tooltips(false) .width(self.width) .height(self.height) @@ -591,7 +595,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ nv.addGraph(function () { var chart = nv.models.multiBarChart() - .stacked(true) + .stacked(self.bar_ui === 'stacked') .staggerLabels(true) .width(self.width) .height(self.height) @@ -626,7 +630,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ nv.addGraph(function () { var chart = nv.models.multiBarChart() - .stacked(true) + .stacked(self.bar_ui === 'stacked') .staggerLabels(true) .width(self.width) .height(self.height) -- cgit v1.2.3 From d7fdeec72fca399dfc28687d78e28bf5793d501e Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 18 Dec 2013 16:49:49 +0100 Subject: [REF] refactors bar_chart method in graph widget. basically, it removes 80 duplicated lines (addon web_graph) bzr revid: ged@openerp.com-20131218154949-9jno1wb4s549jyl7 --- addons/web_graph/static/src/js/graph.js | 121 ++++++-------------------------- 1 file changed, 23 insertions(+), 98 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 145ee079c07..336be536346 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -499,33 +499,14 @@ instance.web_graph.Graph = instance.web.Widget.extend({ var self = this, dim_x = this.pivot.rows.groupby.length, dim_y = this.pivot.cols.groupby.length, - data = []; + data; // No groupby ************************************************************** if ((dim_x === 0) && (dim_y === 0)) { data = [{key: 'Total', values:[{ - title: 'Total', - value: this.pivot.get_value(this.pivot.rows.main.id, this.pivot.cols.main.id), + x: 'Total', + y: this.pivot.get_value(this.pivot.rows.main.id, this.pivot.cols.main.id), }]}]; - nv.addGraph(function () { - var chart = nv.models.discreteBarChart() - .x(function(d) { return d.title;}) - .y(function(d) { return d.value;}) - .tooltips(false) - .showValues(true) - .width(self.width) - .height(self.height) - .staggerLabels(true); - - d3.select(self.svg) - .datum(data) - .attr('width', self.width) - .attr('height', self.height) - .call(chart); - - nv.utils.windowResize(chart.update); - return chart; - }); // Only column groupbys **************************************************** } else if ((dim_x === 0) && (dim_y >= 1)){ data = _.map(this.pivot.get_columns_depth(1), function (header) { @@ -534,53 +515,14 @@ instance.web_graph.Graph = instance.web.Widget.extend({ values: [{x:header.root.main.title, y: self.pivot.get_total(header)}] }; }); - nv.addGraph(function() { - var chart = nv.models.multiBarChart() - .stacked(self.bar_ui === 'stacked') - .tooltips(false) - .width(self.width) - .height(self.height) - .showControls(false); - - d3.select(self.svg) - .datum(data) - .attr('width', self.width) - .attr('height', self.height) - .transition() - .duration(500) - .call(chart); - - nv.utils.windowResize(chart.update); - - return chart; - }); // Just 1 row groupby ****************************************************** } else if ((dim_x === 1) && (dim_y === 0)) { data = _.map(this.pivot.rows.main.children, function (pt) { var value = self.pivot.get_value(pt.id, self.pivot.cols.main.id), title = (pt.title !== undefined) ? pt.title : 'Undefined'; - return {title: title, value: value}; + return {x: title, y: value}; }); data = [{key: this.measure_label(), values:data}]; - nv.addGraph(function () { - var chart = nv.models.discreteBarChart() - .x(function(d) { return d.title;}) - .y(function(d) { return d.value;}) - .tooltips(false) - .showValues(true) - .width(self.width) - .height(self.height) - .staggerLabels(true); - - d3.select(self.svg) - .datum(data) - .attr('width', self.width) - .attr('height', self.height) - .call(chart); - - nv.utils.windowResize(chart.update); - return chart; - }); // 1 row groupby and some col groupbys************************************** } else if ((dim_x === 1) && (dim_y >= 1)) { data = _.map(this.pivot.get_columns_depth(1), function (colhdr) { @@ -592,24 +534,6 @@ instance.web_graph.Graph = instance.web.Widget.extend({ }); return {key: colhdr.title || 'Undefined', values: values}; }); - - nv.addGraph(function () { - var chart = nv.models.multiBarChart() - .stacked(self.bar_ui === 'stacked') - .staggerLabels(true) - .width(self.width) - .height(self.height) - .tooltips(false); - - d3.select(self.svg) - .datum(data) - .attr('width', self.width) - .attr('height', self.height) - .call(chart); - - nv.utils.windowResize(chart.update); - return chart; - }); // At least two row groupby************************************************* } else { var keys = _.uniq(_.map(this.pivot.get_rows_depth(2), function (hdr) { @@ -627,25 +551,26 @@ instance.web_graph.Graph = instance.web.Widget.extend({ }); return {key:key, values: values}; }); - - nv.addGraph(function () { - var chart = nv.models.multiBarChart() - .stacked(self.bar_ui === 'stacked') - .staggerLabels(true) - .width(self.width) - .height(self.height) - .tooltips(false); - - d3.select(self.svg) - .datum(data) - .attr('width', self.width) - .attr('height', self.height) - .call(chart); - - nv.utils.windowResize(chart.update); - return chart; - }); } + + nv.addGraph(function () { + var chart = nv.models.multiBarChart() + .tooltips(false) + .width(self.width) + .height(self.height) + .stacked(self.bar_ui === 'stacked') + .staggerLabels(true); + + d3.select(self.svg) + .datum(data) + .attr('width', self.width) + .attr('height', self.height) + .call(chart); + + nv.utils.windowResize(chart.update); + return chart; + }); + }, line_chart: function () { -- cgit v1.2.3 From 7fc2afc5162124e213af84327b87cdc97ec9dec0 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 19 Dec 2013 13:54:22 +0100 Subject: [FIX] properly handles the situation where a user selected twice the same field in the search view groupbys (it simply added the field twice to groupbys instead of removing it (addon web_graph) bzr revid: ged@openerp.com-20131219125422-n2rpzbekyg7e0eyh --- addons/web_graph/static/src/js/graph.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 336be536346..a473e4df042 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -22,6 +22,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.dataset = dataset; this.model = new instance.web.Model(dataset.model, {group_by_no_leaf: true}); this.search_view = parent.searchview; + this.search_view_groupby = []; this.groupby_mode = 'default'; // 'default' or 'manual' this.default_row_groupby = []; this.default_col_groupby = []; @@ -76,6 +77,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ col_groupby = context.col_group_by || [], options = {domain:domain}; + this.search_view_groupby = group_by; if (group_by.length || col_groupby.length) { this.groupby_mode = 'manual'; } @@ -106,8 +108,11 @@ instance.web_graph.GraphView = instance.web.View.extend({ register_groupby: function() { var self = this, query = this.search_view.query; - this.groupby_mode = 'manual'; + this.groupby_mode = 'manual'; + if (_.isEqual(this.search_view_groupby, this.graph_widget.pivot.rows.groupby)) { + return; + } var rows = _.map(this.graph_widget.pivot.rows.groupby, function (group) { return make_facet('GroupBy', group); }); -- cgit v1.2.3 From 1d92fc0353c7faad27d0e3a11c1591ce5b71d46e Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 19 Dec 2013 14:10:58 +0100 Subject: [FIX] correctly honors the 'bar' setting in graph views descriptions (addon web_graph) bzr revid: ged@openerp.com-20131219131058-ng9fix57v5hqu8pq --- addons/web_graph/static/src/js/graph.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index a473e4df042..234fffc5449 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -53,7 +53,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ measure = null; if (fields_view_get.arch.attrs.type === 'bar') { - this.mode = 'bar_chart'; + this.graph_widget.mode = 'bar_chart'; } _.each(fields_view_get.arch.children, function (field) { -- cgit v1.2.3 From 261b17d7b86702bdfb77403daf93ca8f3537b64c Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 19 Dec 2013 14:49:58 +0100 Subject: [REF] removes old useless comments (addon web_graph) bzr revid: ged@openerp.com-20131219134958-tdgcu3ytbsqszczw --- addons/web_graph/static/src/js/graph.js | 8 -------- 1 file changed, 8 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 234fffc5449..189ce801732 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -270,15 +270,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ this.svg = this.$('.graph_main_content svg')[0]; this.width = this.$el.width(); this.height = Math.min(Math.max(document.documentElement.clientHeight - 116 - 60, 250), Math.round(0.8*this.$el.width())); - // var options = { - // svg: - // mode: this.mode, - // width: this.$el.width(), - // height: Math.min(Math.max(document.documentElement.clientHeight - 116 - 60, 250), Math.round(0.8*this.$el.width())), - // measure_label: this.measure_label() - // }; this[this.mode](); - // openerp.web_graph.draw_chart(options); } } }, -- cgit v1.2.3 From 828d06f174b6892cfbe11fe454eb659589b17720 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 20 Dec 2013 12:02:43 +0100 Subject: [IMP] makes the graph view accept a new way to define graphs (supports type='col', type='row' and type='measure' attributes to fields, also supports 'stacked' attribute in (addon web_graph) bzr revid: ged@openerp.com-20131220110243-sccxichm0mgm21uz --- addons/web_graph/static/src/js/graph.js | 42 +++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 13 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 189ce801732..4eeaec194eb 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -50,26 +50,43 @@ instance.web_graph.GraphView = instance.web.View.extend({ view_loading: function (fields_view_get) { var self = this, - measure = null; + arch = fields_view_get.arch, + measure = null, + stacked = false; - if (fields_view_get.arch.attrs.type === 'bar') { + if (arch.attrs.type === 'bar' || !_.has(arch.attrs, 'type')) { this.graph_widget.mode = 'bar_chart'; } + if (arch.attrs.stacked === "True") { + stacked = true; + } - _.each(fields_view_get.arch.children, function (field) { - if ('name' in field.attrs) { + _.each(arch.children, function (field) { + if (_.has(field.attrs, 'type')) { + switch (field.attrs.type) { + case "row": + self.default_row_groupby.push(field.attrs.name); + break; + case "col": + self.default_col_groupby.push(field.attrs.name); + break; + case "measure": + measure = field.attrs.name; + break; + } + } else { // old style, kept for backward compatibility if ('operator' in field.attrs) { measure = field.attrs.name; } else { - if (measure) { - self.default_col_groupby.push(field.attrs.name); - } else { - self.default_row_groupby.push(field.attrs.name); - } + self.default_row_groupby.push(field.attrs.name); } } }); - this.graph_widget.pivot.config({measure:measure, update:false}); + this.graph_widget.config({ + measure:measure, + update:false, + bar_ui: (stacked) ? 'stack' : 'group' + }); }, do_search: function (domain, context, group_by) { @@ -249,7 +266,6 @@ instance.web_graph.Graph = instance.web.Widget.extend({ }, display_data: function () { - var pivot = this.pivot; this.$('.graph_main_content svg').remove(); this.table.empty(); @@ -258,7 +274,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ } else { this.$('.graph_header').css('display', 'none'); } - if (pivot.no_data) { + if (this.pivot.no_data) { var msg = 'No data available. Try to remove any filter or add some data.'; this.table.append($('' + msg + '')); } else { @@ -555,7 +571,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ .tooltips(false) .width(self.width) .height(self.height) - .stacked(self.bar_ui === 'stacked') + .stacked(self.bar_ui === 'stack') .staggerLabels(true); d3.select(self.svg) -- cgit v1.2.3 From e844ba1040aa3ea52792324272e3a39a9df2ea6e Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 20 Dec 2013 13:39:25 +0100 Subject: [FIX] prevents a crash happening in some cases when the searchview does not initialize a groupbygroup instance before the method register_groupby in graph view used it (addon web_graph) bzr revid: ged@openerp.com-20131220123925-qycdvanm51nkc4uo --- addons/web_graph/static/src/js/graph.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 4eeaec194eb..b966a38e898 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -127,7 +127,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ query = this.search_view.query; this.groupby_mode = 'manual'; - if (_.isEqual(this.search_view_groupby, this.graph_widget.pivot.rows.groupby)) { + if (_.isEqual(this.search_view_groupby, this.graph_widget.pivot.rows.groupby) || + (!_.has(this.search_view, '_s_groupby'))) { return; } var rows = _.map(this.graph_widget.pivot.rows.groupby, function (group) { @@ -340,6 +341,9 @@ instance.web_graph.Graph = instance.web.Widget.extend({ var field = header.root.groupby[header.path.length]; this.pivot.expand(id, field); } else { + if (!this.important_fields.length) { + return; + } var fields = _.map(this.important_fields, function (field) { return {id: field, value: self.fields[field].string}; }); -- cgit v1.2.3 From db9cdb7eb0c7c6e8a26c89fd314dd016d8f8ab03 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 24 Dec 2013 11:09:42 +0100 Subject: [IMP] makes some small changes to improves backward compatibility in some edge cases (takes the first 'operator' as a measure instead of the last, ...) in graph view (addon web_graph) bzr revid: ged@openerp.com-20131224100942-jnrdjeb9lg7rx8d2 --- addons/web_graph/static/src/js/graph.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index b966a38e898..991b21980e6 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -76,7 +76,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ } } else { // old style, kept for backward compatibility if ('operator' in field.attrs) { - measure = field.attrs.name; + measure = (measure) ? measure : field.attrs.name; } else { self.default_row_groupby.push(field.attrs.name); } @@ -95,6 +95,12 @@ instance.web_graph.GraphView = instance.web.View.extend({ options = {domain:domain}; this.search_view_groupby = group_by; + + if (group_by.length && this.groupby_mode !== 'manual') { + if (_.isEqual(col_groupby, [])) { + col_groupby = this.default_col_groupby; + } + } if (group_by.length || col_groupby.length) { this.groupby_mode = 'manual'; } @@ -243,7 +249,6 @@ instance.web_graph.Graph = instance.web.Widget.extend({ .attr('href', '#') .append(self.fields[measure].string); measure_selection.append($('
  • ').append(choice)); - }); }); @@ -572,7 +577,6 @@ instance.web_graph.Graph = instance.web.Widget.extend({ nv.addGraph(function () { var chart = nv.models.multiBarChart() - .tooltips(false) .width(self.width) .height(self.height) .stacked(self.bar_ui === 'stack') -- cgit v1.2.3 From 457090c1a3bbf4931ef3579cc7ca6d4a6c5765b3 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 24 Dec 2013 12:22:24 +0100 Subject: [REF] removes some useless variables and some other cleaning to please jshint (addon web_graph) bzr revid: ged@openerp.com-20131224112224-q1o0hmp1s2ryi9bn --- addons/web_graph/static/src/js/graph.js | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 991b21980e6..8a7ac4811b6 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -57,20 +57,20 @@ instance.web_graph.GraphView = instance.web.View.extend({ if (arch.attrs.type === 'bar' || !_.has(arch.attrs, 'type')) { this.graph_widget.mode = 'bar_chart'; } - if (arch.attrs.stacked === "True") { + if (arch.attrs.stacked === 'True') { stacked = true; } _.each(arch.children, function (field) { if (_.has(field.attrs, 'type')) { switch (field.attrs.type) { - case "row": + case 'row': self.default_row_groupby.push(field.attrs.name); break; - case "col": + case 'col': self.default_col_groupby.push(field.attrs.name); break; - case "measure": + case 'measure': measure = field.attrs.name; break; } @@ -83,15 +83,14 @@ instance.web_graph.GraphView = instance.web.View.extend({ } }); this.graph_widget.config({ - measure:measure, + measure:measure, update:false, bar_ui: (stacked) ? 'stack' : 'group' }); }, do_search: function (domain, context, group_by) { - var self = this, - col_groupby = context.col_group_by || [], + var col_groupby = context.col_group_by || [], options = {domain:domain}; this.search_view_groupby = group_by; @@ -99,12 +98,12 @@ instance.web_graph.GraphView = instance.web.View.extend({ if (group_by.length && this.groupby_mode !== 'manual') { if (_.isEqual(col_groupby, [])) { col_groupby = this.default_col_groupby; - } + } } if (group_by.length || col_groupby.length) { this.groupby_mode = 'manual'; } - if (!this.graph_widget.enabled) { + if (!this.graph_widget.enabled) { options.update = false; options.silent = true; } @@ -172,7 +171,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ }); instance.web_graph.Graph = instance.web.Widget.extend({ - template: "GraphWidget", + template: 'GraphWidget', events: { 'click .graph_mode_selection li' : 'mode_selection', @@ -263,7 +262,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ this.pivot.on('redraw_required', this, this.proxy('display_data')); this.pivot.update_data(); this.enabled = true; - instance.web.bus.on('click', this, function (ev) { + instance.web.bus.on('click', this, function () { if (this.dropdown) { this.dropdown.remove(); this.dropdown = null; @@ -336,8 +335,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ event.stopPropagation(); var id = event.target.attributes['data-id'].nodeValue, header = this.pivot.get_header(id), - self = this, - dim = header.root.groupby.length; + self = this; if (header.is_expanded) { this.pivot.fold(header); @@ -363,8 +361,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ }, field_selection: function (event) { - var self = this, - id = event.target.attributes['data-id'].nodeValue, + var id = event.target.attributes['data-id'].nodeValue, field_id = event.target.attributes['data-field-id'].nodeValue; event.preventDefault(); this.pivot.expand(id, field_id); @@ -631,8 +628,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ pie_chart: function () { var self = this, - dim_x = this.pivot.rows.groupby.length, - dim_y = this.pivot.cols.groupby.length; + dim_x = this.pivot.rows.groupby.length; var data = _.map(this.pivot.get_rows_leaves(), function (row) { var title = _.map(row.path, function (p) { -- cgit v1.2.3 From 69f6efa000e5368462fa3a0c66577d0f405334f0 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 24 Dec 2013 15:09:42 +0100 Subject: [IMP] hides controls (stacked/grouped) in graph view when they are useless (i.e., when there's only one dimension which can't be stacked/grouped (addon web_graph) bzr revid: ged@openerp.com-20131224140942-w0dwy3ck6yslbhxy --- addons/web_graph/static/src/js/graph.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 8a7ac4811b6..c155337d90e 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -579,6 +579,8 @@ instance.web_graph.Graph = instance.web.Widget.extend({ .stacked(self.bar_ui === 'stack') .staggerLabels(true); + if (dim_x === 1 && dim_y === 0) { chart.showControls(false); } + d3.select(self.svg) .datum(data) .attr('width', self.width) -- cgit v1.2.3 From d145c7a8c4bd828d741fdd6fd9f3d8d0fee0fa84 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 24 Dec 2013 16:37:35 +0100 Subject: [IMP] displays a nice message when the graph view has no data to display (addon web_graph) bzr revid: ged@openerp.com-20131224153735-on6cx12v7x2r1ln0 --- addons/web_graph/static/src/js/graph.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index c155337d90e..17a0721fd82 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -272,6 +272,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ display_data: function () { this.$('.graph_main_content svg').remove(); + this.$('.graph_main_content div').remove(); this.table.empty(); if (this.visible_ui) { @@ -280,8 +281,9 @@ instance.web_graph.Graph = instance.web.Widget.extend({ this.$('.graph_header').css('display', 'none'); } if (this.pivot.no_data) { - var msg = 'No data available. Try to remove any filter or add some data.'; - this.table.append($('' + msg + '')); + this.$('.graph_main_content').append($(QWeb.render('graph_no_data'))); + // var msg = 'No data available. Try to remove any filter or add some data.'; + // this.table.append($('' + msg + '')); } else { var table_modes = ['pivot', 'heatmap', 'row_heatmap', 'col_heatmap']; if (_.contains(table_modes, this.mode)) { -- cgit v1.2.3 From 5a2ddfdf8053f2166ddcbcd04299e5788f64b786 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 26 Dec 2013 13:34:49 +0100 Subject: [FIX] forces an update when the user switches back to the graph view, to make sure the data displayed are up to date (graph view, addon web_graph) bzr revid: ged@openerp.com-20131226123449-qjm7hvkhfsdvi7pw --- addons/web_graph/static/src/js/graph.js | 1 + 1 file changed, 1 insertion(+) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 17a0721fd82..18432d9fa61 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -119,6 +119,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ if (!this.graph_widget.enabled) { this.graph_widget.activate_display(); + this.ViewManager.on('switch_mode', this, function () {this.graph_widget.pivot.update_data(); }); } }, -- cgit v1.2.3 From c44786804d289f768606c29f1dd48451370f0e32 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 26 Dec 2013 14:37:35 +0100 Subject: [IMP] adds an image when a graph view has no data to display (it uses the same image as an empty dashboard) (addon web_graph) bzr revid: ged@openerp.com-20131226133735-x2g7veg6d9p77y2d --- addons/web_graph/static/src/js/graph.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 18432d9fa61..b56a2cde7a3 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -283,8 +283,6 @@ instance.web_graph.Graph = instance.web.Widget.extend({ } if (this.pivot.no_data) { this.$('.graph_main_content').append($(QWeb.render('graph_no_data'))); - // var msg = 'No data available. Try to remove any filter or add some data.'; - // this.table.append($('' + msg + '')); } else { var table_modes = ['pivot', 'heatmap', 'row_heatmap', 'col_heatmap']; if (_.contains(table_modes, this.mode)) { -- cgit v1.2.3 From e1e676d737a2f682ed6a106e99b63a4dd377c5d5 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 26 Dec 2013 17:14:57 +0100 Subject: [FIX] correctly calls the parent of the graph view in the constructor (now, the view manager gets the correct view_id) (graph view, addon web_graph) bzr revid: ged@openerp.com-20131226161457-a4k3iflz61fiaqj4 --- addons/web_graph/static/src/js/graph.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index b56a2cde7a3..9806e7011a4 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -18,7 +18,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ view_type: 'graph', init: function(parent, dataset, view_id, options) { - this._super(parent); + this._super(parent, dataset, view_id, options); this.dataset = dataset; this.model = new instance.web.Model(dataset.model, {group_by_no_leaf: true}); this.search_view = parent.searchview; -- cgit v1.2.3 From 0650d9d7380ec1885e6f9bd6627b7d14fd2eeded Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 27 Dec 2013 11:22:40 +0100 Subject: [FIX] correctly displays fields of type 'selection' in graph view. Previously, the code only displayed the key and not the value (addon web_graph) bzr revid: ged@openerp.com-20131227102240-gmgik0p5lujssm3w --- addons/web_graph/static/src/js/graph.js | 1 + 1 file changed, 1 insertion(+) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 9806e7011a4..cfac0ea02f6 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -233,6 +233,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ // get the fields descriptions and measure list from the model var deferred2 = this.model.call('fields_get', []).then(function (fs) { self.fields = fs; + self.pivot.config({fields:fs}); var temp = _.map(fs, function (field, name) { return {name:name, type: field.type}; }); -- cgit v1.2.3 From ed4fdc51080c88c6cc289eedb86407c0587d1648 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 27 Dec 2013 11:25:10 +0100 Subject: [REF] simplifies a for loop to make the code simpler (addon web_graph) bzr revid: ged@openerp.com-20131227102510-dwpjth4fng4ze14e --- addons/web_graph/static/src/js/graph.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index cfac0ea02f6..3a6d5e8ffed 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -460,7 +460,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ .append(this.make_header_title(row).attr('data-id', row.id)) .addClass('graph_border'); - for (var i in _.range(row.path.length)) { + for (var i = 0; i < row.path.length; i++) { row_header.prepend($('', {class:'web_graph_indent'})); } -- cgit v1.2.3 From 868be53bae50a49d86658102baa092c81e048691 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 27 Dec 2013 15:28:14 +0100 Subject: [IMP] incline the x-axis text by 15 degree when there are too many bars to display in a bar chart. Also, reduces the number of 'ticks' displayed (addon web_graph) bzr revid: ged@openerp.com-20131227142814-8ktqqxlthfa5hxe8 --- addons/web_graph/static/src/js/graph.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 3a6d5e8ffed..33d17e2b059 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -578,9 +578,15 @@ instance.web_graph.Graph = instance.web.Widget.extend({ var chart = nv.models.multiBarChart() .width(self.width) .height(self.height) + .reduceXTicks(false) .stacked(self.bar_ui === 'stack') .staggerLabels(true); + if (self.width / data[0].values.length < 100) { + chart.rotateLabels(-15); + chart.reduceXTicks(true); + chart.margin({bottom:40}); + } if (dim_x === 1 && dim_y === 0) { chart.showControls(false); } d3.select(self.svg) -- cgit v1.2.3 From 66ee322d0ff749cbbc8ba382ebb89a755bed66d4 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 27 Dec 2013 15:35:08 +0100 Subject: [FIX] fixes a crash happening when the context of some attributes does not have a 'group_by' attribute (in the group fields of the search view) bzr revid: ged@openerp.com-20131227143508-3g04fn2s5u9vxams --- addons/web_graph/static/src/js/graph.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 33d17e2b059..7dc6d261b0d 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -224,7 +224,9 @@ instance.web_graph.Graph = instance.web.Widget.extend({ _.each(g.children, function (g) { if (g.attrs.context) { var field_id = py.eval(g.attrs.context).group_by; - self.important_fields.push(field_id); + if (field_id) { + self.important_fields.push(field_id); + } } }); }); -- cgit v1.2.3 From 650d792413ebb6fa0af8783a97f7de032dd47d42 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 27 Dec 2013 15:55:01 +0100 Subject: [IMP] removes the 'group/stack' buttons from the bar chart ui and adds 'group/stack' controls in the option menu of the graph widget. It makes small graphs much cleaner (addon web_graph) bzr revid: ged@openerp.com-20131227145501-0hf21nieyl8mgomm --- addons/web_graph/static/src/js/graph.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 7dc6d261b0d..6a70a9c4459 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -317,6 +317,18 @@ instance.web_graph.Graph = instance.web.Widget.extend({ option_selection: function (event) { event.preventDefault(); switch (event.target.attributes['data-choice'].nodeValue) { + case 'bar_grouped': + this.bar_ui = 'group'; + if (this.mode === 'bar_chart') { + this.display_data(); + } + break; + case 'bar_stacked': + this.bar_ui = 'stack'; + if (this.mode === 'bar_chart') { + this.display_data(); + } + break; case 'swap_axis': this.pivot.swap_axis(); break; @@ -582,6 +594,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ .height(self.height) .reduceXTicks(false) .stacked(self.bar_ui === 'stack') + .showControls(false) .staggerLabels(true); if (self.width / data[0].values.length < 100) { @@ -589,7 +602,6 @@ instance.web_graph.Graph = instance.web.Widget.extend({ chart.reduceXTicks(true); chart.margin({bottom:40}); } - if (dim_x === 1 && dim_y === 0) { chart.showControls(false); } d3.select(self.svg) .datum(data) -- cgit v1.2.3 From fb63eb63ededd5dd5c747728cd0d23a3b409f77b Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 27 Dec 2013 16:07:19 +0100 Subject: [IMP] removes the stagger labels in bar charts, only uses the inclined labels when necessary (addon web_graph) bzr revid: ged@openerp.com-20131227150719-olinm65mh515quc2 --- addons/web_graph/static/src/js/graph.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 6a70a9c4459..ffc94e6dd84 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -594,10 +594,9 @@ instance.web_graph.Graph = instance.web.Widget.extend({ .height(self.height) .reduceXTicks(false) .stacked(self.bar_ui === 'stack') - .showControls(false) - .staggerLabels(true); + .showControls(false); - if (self.width / data[0].values.length < 100) { + if (self.width / data[0].values.length < 80) { chart.rotateLabels(-15); chart.reduceXTicks(true); chart.margin({bottom:40}); -- cgit v1.2.3 From e69f4d1af6180f95d22f52e735f1f716b28de45f Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 27 Dec 2013 16:20:55 +0100 Subject: [FIX] fixes a rendering bug which happened when the rowspan (or colspan) attributes were set to 0. Now, it is always set to a value >= 1 (addon web_graph) bzr revid: ged@openerp.com-20131227152055-77fvsc27mzs0x5t9 --- addons/web_graph/static/src/js/graph.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index ffc94e6dd84..80b7eb07d6c 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -399,8 +399,8 @@ instance.web_graph.Graph = instance.web.Widget.extend({ make_border_cell: function (colspan, rowspan) { return $('').addClass('graph_border') - .attr('colspan', colspan) - .attr('rowspan', rowspan); + .attr('colspan', (colspan) ? colspan : 1) + .attr('rowspan', (rowspan) ? rowspan : 1); }, make_header_title: function (header) { -- cgit v1.2.3 From 3d5b03af08409caf78f3deef263ebebb894d9e61 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 31 Dec 2013 10:02:57 +0100 Subject: [IMP] changes the css of the pivot table to make it look decent (at least, not as awful as before), (addon web_graph) bzr revid: ged@openerp.com-20131231090257-y0os22omx0pgjaqb --- addons/web_graph/static/src/js/graph.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 80b7eb07d6c..9fcb7f3ea8e 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -397,8 +397,9 @@ instance.web_graph.Graph = instance.web.Widget.extend({ return (this.pivot.measure) ? this.fields[this.pivot.measure].string : 'Quantity'; }, - make_border_cell: function (colspan, rowspan) { - return $('').addClass('graph_border') + make_border_cell: function (colspan, rowspan, headercell) { + var tag = (headercell) ? $('') : $(''); + return tag.addClass('graph_border') .attr('colspan', (colspan) ? colspan : 1) .attr('rowspan', (rowspan) ? rowspan : 1); }, @@ -413,9 +414,10 @@ instance.web_graph.Graph = instance.web.Widget.extend({ draw_top_headers: function () { var self = this, + thead = $(''), pivot = this.pivot, height = _.max(_.map(pivot.cols.headers, function(g) {return g.path.length;})), - header_cells = [[this.make_border_cell(1, height)]]; + header_cells = [[this.make_border_cell(1, height, true)]]; function set_dim (cols) { _.each(cols.children, set_dim); @@ -429,7 +431,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ } function make_col_header (col) { - var cell = self.make_border_cell(col.width, col.height); + var cell = self.make_border_cell(col.width, col.height, true); return cell.append(self.make_header_title(col).attr('data-id', col.id)); } @@ -452,12 +454,13 @@ instance.web_graph.Graph = instance.web.Widget.extend({ make_cells(pivot.cols.headers, 0); } else { make_cells(pivot.cols.main.children, 1); - header_cells[0].push(self.make_border_cell(1, height).append('Total').css('font-weight', 'bold')); + header_cells[0].push(self.make_border_cell(1, height, true).append('Total').css('font-weight', 'bold')); } _.each(header_cells, function (cells) { - self.table.append($('').append(cells)); + thead.append($('').append(cells)); }); + self.table.append(thead); }, get_measure_type: function () { @@ -500,10 +503,6 @@ instance.web_graph.Graph = instance.web.Widget.extend({ var color, total, cell = $(''); - if ((self.mode === 'pivot') && (row.is_expanded) && (row.path.length <=2)) { - color = row.path.length * 5 + 240; - cell.css('background-color', $.Color(color, color, color)); - } if (value === undefined) { return cell; } -- cgit v1.2.3 From d63db7b67f817178a3698904cacdd655676ed673 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 31 Dec 2013 10:49:29 +0100 Subject: [IMP] makes sure that the graph view properly honors default mode request as described in the xml (addon web_graph) bzr revid: ged@openerp.com-20131231094929-giqkzmean1lralow --- addons/web_graph/static/src/js/graph.js | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 9fcb7f3ea8e..8c652239d2a 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -54,9 +54,28 @@ instance.web_graph.GraphView = instance.web.View.extend({ measure = null, stacked = false; - if (arch.attrs.type === 'bar' || !_.has(arch.attrs, 'type')) { + if (!_.has(arch.attrs, 'type')) { this.graph_widget.mode = 'bar_chart'; + } else { + switch (arch.attrs.type) { + case 'bar': + this.graph_widget.mode = 'bar_chart'; + break; + case 'pie': + this.graph_widget.mode = 'pie_chart'; + break; + case 'line': + this.graph_widget.mode = 'line_chart'; + break; + case 'pivot': + case 'heatmap': + case 'row_heatmap': + case 'col_heatmap': + this.graph_widget.mode = arch.attrs.type; + break; + } } + if (arch.attrs.stacked === 'True') { stacked = true; } @@ -190,7 +209,6 @@ instance.web_graph.Graph = instance.web.Widget.extend({ this.fields = []; this.pivot = new openerp.web_graph.PivotTable(model, []); this.mode = 'pivot'; - if (_.has(options, 'mode')) { this.mode = mode; } this.enabled = true; if (_.has(options, 'enabled')) { this.enabled = options.enabled; } this.visible_ui = true; @@ -200,6 +218,9 @@ instance.web_graph.Graph = instance.web.Widget.extend({ // hide ui/show, stacked/grouped config: function (options) { + // Possible modes: pivot, heatmap, row_heatmap, col_heatmap, + // bar_chart, pie_chart, line_chart + if (_.has(options, 'mode')) { this.mode = mode; } if (_.has(options, 'visible_ui')) { this.visible_ui = options.visible_ui; } @@ -509,17 +530,17 @@ instance.web_graph.Graph = instance.web.Widget.extend({ cell.append(instance.web.format_value(value, {type: measure_type})); if (self.mode === 'heatmap') { total = pivot.get_total(); - color = Math.floor(50 + 205*(total - value)/total); + color = Math.floor(90 + 165*(total - value)/total); cell.css('background-color', $.Color(255, color, color)); } if (self.mode === 'row_heatmap') { total = pivot.get_total(row); - color = Math.floor(50 + 205*(total - value)/total); + color = Math.floor(90 + 165*(total - value)/total); cell.css('background-color', $.Color(255, color, color)); } if (self.mode === 'col_heatmap') { total = pivot.get_total(col); - color = Math.floor(50 + 205*(total - value)/total); + color = Math.floor(90 + 165*(total - value)/total); cell.css('background-color', $.Color(255, color, color)); } return cell; -- cgit v1.2.3 From 8347c44966b3718a23fc1d7867a6db0de8d09731 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Thu, 2 Jan 2014 11:01:27 +0100 Subject: [FIX] fixes a crash when the graph view receives an array of values instead of a single value describing a field (addon web_graph) bzr revid: ged@openerp.com-20140102100127-7bmviyzujjmlfg02 --- addons/web_graph/static/src/js/graph.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 8c652239d2a..cba45302050 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -246,7 +246,11 @@ instance.web_graph.Graph = instance.web.Widget.extend({ if (g.attrs.context) { var field_id = py.eval(g.attrs.context).group_by; if (field_id) { - self.important_fields.push(field_id); + if (field_id instanceof Array) { + self.important_fields.concat(field_id); + } else { + self.important_fields.push(field_id); + } } } }); -- cgit v1.2.3 From 2514343b52ecf98adb72333edcb4b8434f07d82c Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 3 Jan 2014 15:22:15 +0100 Subject: [IMP] adds support for more than one measure in graph view. (addon web_graph) bzr revid: ged@openerp.com-20140103142215-z19pnxmnla8xugx0 --- addons/web_graph/static/src/js/graph.js | 109 +++++++++++++++++++++++--------- 1 file changed, 79 insertions(+), 30 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index cba45302050..978c893db19 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -51,7 +51,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ view_loading: function (fields_view_get) { var self = this, arch = fields_view_get.arch, - measure = null, + measures = [], + title = arch.attrs.string, stacked = false; if (!_.has(arch.attrs, 'type')) { @@ -90,20 +91,24 @@ instance.web_graph.GraphView = instance.web.View.extend({ self.default_col_groupby.push(field.attrs.name); break; case 'measure': - measure = field.attrs.name; + measures.push(field.attrs.name); break; } } else { // old style, kept for backward compatibility if ('operator' in field.attrs) { - measure = (measure) ? measure : field.attrs.name; + measures.push(field.attrs.name); } else { self.default_row_groupby.push(field.attrs.name); } } }); + if (measures.length === 0) { + measures.push('__count'); + } this.graph_widget.config({ - measure:measure, + measures:measures, update:false, + title: title, bar_ui: (stacked) ? 'stack' : 'group' }); }, @@ -214,6 +219,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ this.visible_ui = true; this.bar_ui = 'group'; // group or stack this.config(options || {}); + this.title = 'Graph'; }, // hide ui/show, stacked/grouped @@ -227,6 +233,9 @@ instance.web_graph.Graph = instance.web.Widget.extend({ if (_.has(options, 'bar_ui')) { this.bar_ui = options.bar_ui; } + if (_.has(options, 'title')) { + this.title = options.title; + } this.pivot.config(options); }, @@ -335,8 +344,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ measure_selection: function (event) { event.preventDefault(); var measure = event.target.attributes['data-choice'].nodeValue; - var actual_measure = (measure === '__count') ? null : measure; - this.pivot.config({measure:actual_measure}); + this.pivot.config({measures:[measure]}); }, option_selection: function (event) { @@ -413,13 +421,13 @@ instance.web_graph.Graph = instance.web.Widget.extend({ ******************************************************************************/ draw_table: function () { this.pivot.rows.main.title = 'Total'; - this.pivot.cols.main.title = this.measure_label(); + this.pivot.cols.main.title = this.title; this.draw_top_headers(); _.each(this.pivot.rows.headers, this.proxy('draw_row')); }, - measure_label: function () { - return (this.pivot.measure) ? this.fields[this.pivot.measure].string : 'Quantity'; + measure_label: function (measure) { + return (measure !== '__count') ? this.fields[measure].string : 'Quantity'; }, make_border_cell: function (colspan, rowspan, headercell) { @@ -456,7 +464,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ } function make_col_header (col) { - var cell = self.make_border_cell(col.width, col.height, true); + var cell = self.make_border_cell(col.width*pivot.measures.length, col.height, true); return cell.append(self.make_header_title(col).attr('data-id', col.id)); } @@ -479,24 +487,62 @@ instance.web_graph.Graph = instance.web.Widget.extend({ make_cells(pivot.cols.headers, 0); } else { make_cells(pivot.cols.main.children, 1); - header_cells[0].push(self.make_border_cell(1, height, true).append('Total').css('font-weight', 'bold')); + if (pivot.get_cols_leaves().length > 1) { + header_cells[0].push(self.make_border_cell(pivot.measures.length, height, true).append('Total').css('font-weight', 'bold')); + } } _.each(header_cells, function (cells) { thead.append($('').append(cells)); }); + + if (pivot.measures.length >= 2) { + thead.append(self.make_measure_row()); + } + self.table.append(thead); }, - get_measure_type: function () { - var measure = this.pivot.measure; - return (measure) ? this.fields[measure].type : 'integer'; + make_measure_row: function() { + var self = this, + measures = this.pivot.measures, + cols = this.pivot.cols.headers, + measure_cells, + measure_row = $(''); + + measure_row.append($('')); + + _.each(cols, function (col) { + if (!col.children.length) { + for (var i = 0; i < measures.length; i++) { + measure_cells = $('').addClass('measure_row'); + measure_cells.append(self.measure_label(measures[i])); + measure_row.append(measure_cells); + } + } + }); + + if (this.pivot.get_cols_leaves().length > 1) { + for (var i = 0; i < measures.length; i++) { + measure_cells = $('').addClass('measure_row'); + measure_cells.append(self.measure_label(measures[i])); + measure_row.append(measure_cells); + } + } + return measure_row; + }, + + get_measure_types: function () { + var self = this; + return _.map(this.pivot.measures, function (measure) { + return (measure !== '__count') ? self.fields[measure].type : 'integer'; + }); }, draw_row: function (row) { var self = this, pivot = this.pivot, - measure_type = this.get_measure_type(), + measure_types = this.get_measure_types(), html_row = $(''), row_header = this.make_border_cell(1,1) .append(this.make_header_title(row).attr('data-id', row.id)) @@ -510,21 +556,24 @@ instance.web_graph.Graph = instance.web.Widget.extend({ _.each(pivot.cols.headers, function (col) { if (col.children.length === 0) { - var value = pivot.get_value(row.id, col.id), - cell = make_cell(value, col); - html_row.append(cell); + var values = pivot.get_value(row.id, col.id, new Array(measure_types.length)); + for (var i = 0; i < values.length; i++) { + html_row.append(make_cell(values[i], measure_types[i], col)); + } } }); - if (pivot.cols.main.children.length > 0) { - var cell = make_cell(pivot.get_total(row), pivot.cols.main) - .css('font-weight', 'bold'); - html_row.append(cell); + if (pivot.get_cols_leaves().length > 1) { + var total_vals = pivot.get_total(row); + for (var j = 0; j < total_vals.length; j++) { + var cell = make_cell(total_vals[j], measure_types[j], pivot.cols.main).css('font-weight', 'bold'); + html_row.append(cell); + } } this.table.append(html_row); - function make_cell (value, col) { + function make_cell (value, measure_type, col) { var color, total, cell = $(''); @@ -564,31 +613,31 @@ instance.web_graph.Graph = instance.web.Widget.extend({ if ((dim_x === 0) && (dim_y === 0)) { data = [{key: 'Total', values:[{ x: 'Total', - y: this.pivot.get_value(this.pivot.rows.main.id, this.pivot.cols.main.id), + y: this.pivot.get_value(this.pivot.rows.main.id, this.pivot.cols.main.id)[0], }]}]; // Only column groupbys **************************************************** } else if ((dim_x === 0) && (dim_y >= 1)){ data = _.map(this.pivot.get_columns_depth(1), function (header) { return { key: header.title, - values: [{x:header.root.main.title, y: self.pivot.get_total(header)}] + values: [{x:header.root.main.title, y: self.pivot.get_total(header)[0]}] }; }); // Just 1 row groupby ****************************************************** } else if ((dim_x === 1) && (dim_y === 0)) { data = _.map(this.pivot.rows.main.children, function (pt) { - var value = self.pivot.get_value(pt.id, self.pivot.cols.main.id), + var value = self.pivot.get_value(pt.id, self.pivot.cols.main.id)[0], title = (pt.title !== undefined) ? pt.title : 'Undefined'; return {x: title, y: value}; }); - data = [{key: this.measure_label(), values:data}]; + data = [{key: self.measure_label(self.pivot.measures[0]), values:data}]; // 1 row groupby and some col groupbys************************************** } else if ((dim_x === 1) && (dim_y >= 1)) { data = _.map(this.pivot.get_columns_depth(1), function (colhdr) { var values = _.map(self.pivot.get_rows_depth(1), function (header) { return { x: header.title || 'Undefined', - y: self.pivot.get_value(header.id, colhdr.id, 0) + y: self.pivot.get_value(header.id, colhdr.id, 0)[0] }; }); return {key: colhdr.title || 'Undefined', values: values}; @@ -605,7 +654,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ }); return { x: hdr.title || 'Undefined', - y: (subhdr) ? self.pivot.get_total(subhdr) : 0 + y: (subhdr) ? self.pivot.get_total(subhdr)[0] : 0 }; }); return {key:key, values: values}; @@ -651,7 +700,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ return p || 'Undefined'; }).join('/'); if (dim_y === 0) { - title = self.measure_label(); + title = self.measure_label(self.pivot.measures[0]); } return {values: values, key: title}; }); -- cgit v1.2.3 From 64775d40988ebff185a01797ac502e2ca12167bf Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 3 Jan 2014 15:32:36 +0100 Subject: [IMP] improves the rendering of heatmap modes when multiple measures are displayed (addon web_graph) bzr revid: ged@openerp.com-20140103143236-80zmxauy75b0n205 --- addons/web_graph/static/src/js/graph.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 978c893db19..93cac5146ec 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -558,7 +558,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ if (col.children.length === 0) { var values = pivot.get_value(row.id, col.id, new Array(measure_types.length)); for (var i = 0; i < values.length; i++) { - html_row.append(make_cell(values[i], measure_types[i], col)); + html_row.append(make_cell(values[i], measure_types[i], i, col)); } } }); @@ -566,14 +566,14 @@ instance.web_graph.Graph = instance.web.Widget.extend({ if (pivot.get_cols_leaves().length > 1) { var total_vals = pivot.get_total(row); for (var j = 0; j < total_vals.length; j++) { - var cell = make_cell(total_vals[j], measure_types[j], pivot.cols.main).css('font-weight', 'bold'); + var cell = make_cell(total_vals[j], measure_types[j], i, pivot.cols.main).css('font-weight', 'bold'); html_row.append(cell); } } this.table.append(html_row); - function make_cell (value, measure_type, col) { + function make_cell (value, measure_type, index, col) { var color, total, cell = $(''); @@ -582,18 +582,18 @@ instance.web_graph.Graph = instance.web.Widget.extend({ } cell.append(instance.web.format_value(value, {type: measure_type})); if (self.mode === 'heatmap') { - total = pivot.get_total(); - color = Math.floor(90 + 165*(total - value)/total); + total = pivot.get_total()[i]; + color = Math.floor(90 + 165*(total - Math.abs(value))/total); cell.css('background-color', $.Color(255, color, color)); } if (self.mode === 'row_heatmap') { - total = pivot.get_total(row); - color = Math.floor(90 + 165*(total - value)/total); + total = pivot.get_total(row)[i]; + color = Math.floor(90 + 165*(total - Math.abs(value))/total); cell.css('background-color', $.Color(255, color, color)); } if (self.mode === 'col_heatmap') { - total = pivot.get_total(col); - color = Math.floor(90 + 165*(total - value)/total); + total = pivot.get_total(col)[i]; + color = Math.floor(90 + 165*(total - Math.abs(value))/total); cell.css('background-color', $.Color(255, color, color)); } return cell; -- cgit v1.2.3 From 47762dfca2c49a8da9f9fd1b57f966a27d96f602 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 3 Jan 2014 15:44:18 +0100 Subject: [IMP] allows the selection of multiple measures in graph view (addon web_graph) bzr revid: ged@openerp.com-20140103144418-7mstnfwah6v6jkkx --- addons/web_graph/static/src/js/graph.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 93cac5146ec..e8e4e561ef4 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -344,7 +344,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ measure_selection: function (event) { event.preventDefault(); var measure = event.target.attributes['data-choice'].nodeValue; - this.pivot.config({measures:[measure]}); + this.pivot.config({toggle_measure:measure}); }, option_selection: function (event) { @@ -421,7 +421,11 @@ instance.web_graph.Graph = instance.web.Widget.extend({ ******************************************************************************/ draw_table: function () { this.pivot.rows.main.title = 'Total'; - this.pivot.cols.main.title = this.title; + if (this.pivot.measures.length == 1) { + this.pivot.cols.main.title = this.measure_label(this.pivot.measures[0]); + } else { + this.pivot.cols.main.title = this.title; + } this.draw_top_headers(); _.each(this.pivot.rows.headers, this.proxy('draw_row')); }, -- cgit v1.2.3 From 6a422f27d7bffd8457f275e2cc3c41f58e37a66d Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Mon, 6 Jan 2014 09:37:34 +0100 Subject: [FIX] fixes the computation of the color displayed in heatmap modes in graph view. (addon web_graph) bzr revid: ged@openerp.com-20140106083734-qkrvuhe7398me2d2 --- addons/web_graph/static/src/js/graph.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index e8e4e561ef4..7973a5646bc 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -570,7 +570,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ if (pivot.get_cols_leaves().length > 1) { var total_vals = pivot.get_total(row); for (var j = 0; j < total_vals.length; j++) { - var cell = make_cell(total_vals[j], measure_types[j], i, pivot.cols.main).css('font-weight', 'bold'); + var cell = make_cell(total_vals[j], measure_types[j], j, pivot.cols.main).css('font-weight', 'bold'); html_row.append(cell); } } @@ -586,17 +586,17 @@ instance.web_graph.Graph = instance.web.Widget.extend({ } cell.append(instance.web.format_value(value, {type: measure_type})); if (self.mode === 'heatmap') { - total = pivot.get_total()[i]; + total = pivot.get_total()[index]; color = Math.floor(90 + 165*(total - Math.abs(value))/total); cell.css('background-color', $.Color(255, color, color)); } if (self.mode === 'row_heatmap') { - total = pivot.get_total(row)[i]; + total = pivot.get_total(row)[index]; color = Math.floor(90 + 165*(total - Math.abs(value))/total); cell.css('background-color', $.Color(255, color, color)); } if (self.mode === 'col_heatmap') { - total = pivot.get_total(col)[i]; + total = pivot.get_total(col)[index]; color = Math.floor(90 + 165*(total - Math.abs(value))/total); cell.css('background-color', $.Color(255, color, color)); } -- cgit v1.2.3 From f62567507929c64725e2baf28c6881d6eb657916 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 10 Jan 2014 12:35:57 +0100 Subject: [REF] large refactoring in graph view: changes the underlying data structure of Pivot class and simplifies a lot of code (addon web_graph) bzr revid: ged@openerp.com-20140110113557-6bs77dg7qcdofy40 --- addons/web_graph/static/src/js/graph.js | 448 ++++++++++++++++++-------------- 1 file changed, 258 insertions(+), 190 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 7973a5646bc..84a7d147ac2 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -33,52 +33,39 @@ instance.web_graph.GraphView = instance.web.View.extend({ }; }, - get_context: function (facet) { - var col_group_by = _.map(facet.values.models, function (model) { - return model.attributes.value.attrs.context.col_group_by; - }); - return {col_group_by : col_group_by}; - }, - - start: function () { - var options = {enabled:false}; - this.graph_widget = new openerp.web_graph.Graph(this, this.model, options); - this.graph_widget.appendTo(this.$el); - this.graph_widget.pivot.on('groupby_changed', this, this.proxy('register_groupby')); - return this.load_view(); - }, - view_loading: function (fields_view_get) { var self = this, arch = fields_view_get.arch, measures = [], - title = arch.attrs.string, stacked = false; + this.widget_config = { title: arch.attrs.string }; + + debugger; if (!_.has(arch.attrs, 'type')) { - this.graph_widget.mode = 'bar_chart'; + this.widget_config.mode = 'bar_chart'; } else { switch (arch.attrs.type) { case 'bar': - this.graph_widget.mode = 'bar_chart'; + this.widget_config.mode = 'bar_chart'; break; case 'pie': - this.graph_widget.mode = 'pie_chart'; + this.widget_config.mode = 'pie_chart'; break; case 'line': - this.graph_widget.mode = 'line_chart'; + this.widget_config.mode = 'line_chart'; break; case 'pivot': case 'heatmap': case 'row_heatmap': case 'col_heatmap': - this.graph_widget.mode = arch.attrs.type; + this.widget_config.mode = arch.attrs.type; break; } } if (arch.attrs.stacked === 'True') { - stacked = true; + this.widget_config.stacked = true; } _.each(arch.children, function (field) { @@ -105,18 +92,32 @@ instance.web_graph.GraphView = instance.web.View.extend({ if (measures.length === 0) { measures.push('__count'); } - this.graph_widget.config({ - measures:measures, - update:false, - title: title, - bar_ui: (stacked) ? 'stack' : 'group' + this.widget_config.row_groupby = self.default_row_groupby; + this.widget_config.col_groupby = self.default_col_groupby; + this.widget_config.measures = measures; + // measures:measures, + // update:false, + // title: title, + // bar_ui: (stacked) ? 'stack' : 'group' + // }); + }, + + get_context: function (facet) { + var col_group_by = _.map(facet.values.models, function (model) { + return model.attributes.value.attrs.context.col_group_by; }); + return {col_group_by : col_group_by}; }, do_search: function (domain, context, group_by) { var col_groupby = context.col_group_by || [], options = {domain:domain}; + if (!this.graph_widget) { + this.graph_widget = new openerp.web_graph.Graph(this, this.model, domain, this.widget_config); + this.graph_widget.appendTo(this.$el); + this.graph_widget.on('groupby_changed', this, this.proxy('register_groupby')); + } this.search_view_groupby = group_by; if (group_by.length && this.groupby_mode !== 'manual') { @@ -139,7 +140,11 @@ instance.web_graph.GraphView = instance.web.View.extend({ options.row_groupby = _.toArray(this.default_row_groupby); options.col_groupby = _.toArray(this.default_col_groupby); } - this.graph_widget.pivot.config(options); + this.graph_widget.set_domain(domain); + this.graph_widget.set_col_groupby(options.col_groupby); + this.graph_widget.set_row_groupby(options.row_groupby); + + // this.graph_widget.pivot.config(options); if (!this.graph_widget.enabled) { this.graph_widget.activate_display(); @@ -153,49 +158,50 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, register_groupby: function() { - var self = this, - query = this.search_view.query; - - this.groupby_mode = 'manual'; - if (_.isEqual(this.search_view_groupby, this.graph_widget.pivot.rows.groupby) || - (!_.has(this.search_view, '_s_groupby'))) { - return; - } - var rows = _.map(this.graph_widget.pivot.rows.groupby, function (group) { - return make_facet('GroupBy', group); - }); - var cols = _.map(this.graph_widget.pivot.cols.groupby, function (group) { - return make_facet('ColGroupBy', group); - }); - - query.reset(rows.concat(cols)); - - function make_facet (category, fields) { - var values, - icon, - backbone_field, - cat_name; - if (!(fields instanceof Array)) { fields = [fields]; } - if (category === 'GroupBy') { - cat_name = 'group_by'; - icon = 'w'; - backbone_field = self.search_view._s_groupby; - } else { - cat_name = 'col_group_by'; - icon = 'f'; - backbone_field = self.search_field; - } - values = _.map(fields, function (field) { - var context = {}; - context[cat_name] = field; - return {label: self.graph_widget.fields[field].string, value: {attrs:{domain: [], context: context}}}; - }); - return {category:category, values: values, icon:icon, field: backbone_field}; - } + // var self = this, + // query = this.search_view.query; + + // this.groupby_mode = 'manual'; + // if (_.isEqual(this.search_view_groupby, this.graph_widget.pivot.rows.groupby) || + // (!_.has(this.search_view, '_s_groupby'))) { + // return; + // } + // var rows = _.map(this.graph_widget.pivot.rows.groupby, function (group) { + // return make_facet('GroupBy', group); + // }); + // var cols = _.map(this.graph_widget.pivot.cols.groupby, function (group) { + // return make_facet('ColGroupBy', group); + // }); + + // query.reset(rows.concat(cols)); + + // function make_facet (category, fields) { + // var values, + // icon, + // backbone_field, + // cat_name; + // if (!(fields instanceof Array)) { fields = [fields]; } + // if (category === 'GroupBy') { + // cat_name = 'group_by'; + // icon = 'w'; + // backbone_field = self.search_view._s_groupby; + // } else { + // cat_name = 'col_group_by'; + // icon = 'f'; + // backbone_field = self.search_field; + // } + // values = _.map(fields, function (field) { + // var context = {}; + // context[cat_name] = field; + // return {label: self.graph_widget.fields[field].string, value: {attrs:{domain: [], context: context}}}; + // }); + // return {category:category, values: values, icon:icon, field: backbone_field}; + // } }, }); -instance.web_graph.Graph = instance.web.Widget.extend({ +// important_fields = [field], field = {field: _,type: _, string: _} +instance.web_graph.Graph = instance.web.Widget.extend(openerp.EventDispatcherMixin, { template: 'GraphWidget', events: { @@ -206,108 +212,181 @@ instance.web_graph.Graph = instance.web.Widget.extend({ 'click a.field-selection' : 'field_selection', }, - init: function(parent, model, options) { + init: function(parent, model, domain, options) { + var self = this; + this._super(parent); this.model = model; - this.important_fields = []; - this.measure_list = []; - this.fields = []; - this.pivot = new openerp.web_graph.PivotTable(model, []); - this.mode = 'pivot'; - this.enabled = true; - if (_.has(options, 'enabled')) { this.enabled = options.enabled; } - this.visible_ui = true; - this.bar_ui = 'group'; // group or stack - this.config(options || {}); - this.title = 'Graph'; - }, - - // hide ui/show, stacked/grouped - config: function (options) { - // Possible modes: pivot, heatmap, row_heatmap, col_heatmap, - // bar_chart, pie_chart, line_chart - if (_.has(options, 'mode')) { this.mode = mode; } - if (_.has(options, 'visible_ui')) { - this.visible_ui = options.visible_ui; - } - if (_.has(options, 'bar_ui')) { - this.bar_ui = options.bar_ui; - } - if (_.has(options, 'title')) { - this.title = options.title; - } - this.pivot.config(options); + this.domain = domain; + this.mode = options.mode || 'pivot'; + this.title = options.title || 'Graph'; + this.visible_ui = options.visible_ui || true; + this.pivot_options = options; }, start: function() { var self = this; this.table = $('
    '); this.$('.graph_main_content').append(this.table); - // get the most important fields (of the model) by looking at the - // groupby filters defined in the search view - var options = {model:this.model, view_type: 'search'}, - deferred1 = instance.web.fields_view_get(options).then(function (search_view) { - var groups = _.select(search_view.arch.children, function (c) { - return (c.tag == 'group') && (c.attrs.string != 'Display'); - }); - _.each(groups, function(g) { - _.each(g.children, function (g) { - if (g.attrs.context) { - var field_id = py.eval(g.attrs.context).group_by; - if (field_id) { - if (field_id instanceof Array) { - self.important_fields.concat(field_id); - } else { - self.important_fields.push(field_id); - } - } - } - }); - }); - }); + var def1 = this.get_search_fields().then(function (f) { + self.important_fields = f; + }); - // get the fields descriptions and measure list from the model - var deferred2 = this.model.call('fields_get', []).then(function (fs) { - self.fields = fs; - self.pivot.config({fields:fs}); - var temp = _.map(fs, function (field, name) { - return {name:name, type: field.type}; + var def2 = this.get_model_fields().then(function (f) { + self.fields = f; + self.measure_list = self.get_measures(); + self.add_measures_to_options(); + }); + + $.when(def1, def2).then(function () { + self.pivot = new openerp.web_graph.PivotTable(self.model, self.domain, self.fields, self.pivot_options); + self.pivot.on('redraw_required', self, self.proxy('display_data')); + self.pivot.on('groupby_changed', self, function () { self.trigger('groupby_changed'); }); + instance.web.bus.on('click', self, function () { + if (self.dropdown) { + self.dropdown.remove(); + self.dropdown = null; + } }); - temp = _.filter(temp, function (field) { - return (((field.type === 'integer') || (field.type === 'float')) && (field.name !== 'id')); + self.pivot.activate(); + }); + }, + + get_search_fields: function () { + var self = this, + options = {model:this.model, view_type: 'search'}, + result = []; + + return instance.web.fields_view_get(options).then(function (search_view) { + var groups = _.select(search_view.arch.children, function (c) { + return (c.tag === 'group') && (c.attrs.string != 'Display'); }); - self.measure_list = _.map(temp, function (field) { - return field.name; + _.each(groups, function(g) { + _.each(g.children, function (g) { + if (g.attrs.context) { + var field_id = py.eval(g.attrs.context).group_by; + if (field_id) { + if (field_id instanceof Array) { + result.concat(field_id); + } else { + result.push(field_id); + } + } + } + }); }); + return result; + }); + }, - var measure_selection = self.$('.graph_measure_selection'); - _.each(self.measure_list, function (measure) { - var choice = $('').attr('data-choice', measure) - .attr('href', '#') - .append(self.fields[measure].string); - measure_selection.append($('
  • ').append(choice)); - }); + get_model_fields: function () { + return this.model.call('fields_get', []).then(function (fs) { + return fs; }); + }, - return $.when(deferred1, deferred2).then(function () { - if (this.enabled) { - this.activate_display(); + get_measures: function(fields) { + var measures = []; + _.each(this.fields, function (f, id) { + if (((f.type === 'integer') || (f.type === 'float')) && (id !== 'id')) { + measures.push({field:id, type: f.type, string: f.string}); } }); + return measures; }, - activate_display: function () { - this.pivot.on('redraw_required', this, this.proxy('display_data')); - this.pivot.update_data(); - this.enabled = true; - instance.web.bus.on('click', this, function () { - if (this.dropdown) { - this.dropdown.remove(); - this.dropdown = null; - } + set_domain: function (domain) { + if (this.pivot) { + this.pivot.set_domain(domain); + } else { + this.pivot_options.domain = domain; + } + }, + + set_row_groupby: function (groupby) { + if (this.pivot) { + this.pivot.set_row_groupby(groupby); + } else { + this.pivot_options.row_groupby = groupby; + } + }, + + set_col_groupby: function (groupby) { + if (this.pivot) { + this.pivot.set_col_groupby(groupby); + } else { + this.pivot_options.col_groupby = groupby; + } + }, + + add_measures_to_options: function() { + var measure_selection = this.$('.graph_measure_selection'); + _.each(this.measure_list, function (measure) { + var choice = $('').attr('data-choice', measure.field) + .attr('href', '#') + .append(measure.string); + measure_selection.append($('
  • ').append(choice)); }); }, + // self.fields = fs; + // var temp = _.map(fs, function (field, name) { + // return {name:name, type: field.type}; + // }); + // temp = _.filter(temp, function (field) { + // return (((field.type === 'integer') || (field.type === 'float')) && (field.name !== 'id')); + // }); + // self.measure_list = _.map(temp, function (field) { + // return field.name; + // }); + + // var measure_selection = self.$('.graph_measure_selection'); + // _.each(self.measure_list, function (measure) { + // var choice = $('').attr('data-choice', measure) + // .attr('href', '#') + // .append(self.fields[measure].string); + // measure_selection.append($('
  • ').append(choice)); + // }); + // }); + // }, + + // hide ui/show, stacked/grouped + // config: function (options) { + // Possible modes: pivot, heatmap, row_heatmap, col_heatmap, + // bar_chart, pie_chart, line_chart + // if (_.has(options, 'mode')) { this.mode = mode; } + // if (_.has(options, 'visible_ui')) { + // this.visible_ui = options.visible_ui; + // } + // if (_.has(options, 'bar_ui')) { + // this.bar_ui = options.bar_ui; + // } + // if (_.has(options, 'title')) { + // this.title = options.title; + // } + // debugger; + // this.pivot.config(options); + // }, + + + // get the most important fields (of the model) by looking at the + // groupby filters defined in the search view + + // get the fields descriptions and measure list from the model + + // return $.when(deferred1, deferred2).then(function () { + // self.pivot = new openerp.web_graph.PivotTable(self.model, self.fields); + // self.activate_display(); + // }); + // }, + + set_mode: function (mode) { + + }, + + activate_display: function () { + }, + display_data: function () { this.$('.graph_main_content svg').remove(); this.$('.graph_main_content div').remove(); @@ -344,7 +423,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ measure_selection: function (event) { event.preventDefault(); var measure = event.target.attributes['data-choice'].nodeValue; - this.pivot.config({toggle_measure:measure}); + this.pivot.toggle_measure(measure); }, option_selection: function (event) { @@ -386,12 +465,11 @@ instance.web_graph.Graph = instance.web.Widget.extend({ header = this.pivot.get_header(id), self = this; - if (header.is_expanded) { + if (header.expanded) { this.pivot.fold(header); } else { if (header.path.length < header.root.groupby.length) { - var field = header.root.groupby[header.path.length]; - this.pivot.expand(id, field); + this.pivot.expand(id); } else { if (!this.important_fields.length) { return; @@ -420,20 +498,16 @@ instance.web_graph.Graph = instance.web.Widget.extend({ * Drawing pivot table methods... ******************************************************************************/ draw_table: function () { - this.pivot.rows.main.title = 'Total'; + this.pivot.main_row().title = 'Total'; if (this.pivot.measures.length == 1) { - this.pivot.cols.main.title = this.measure_label(this.pivot.measures[0]); + this.pivot.main_col().title = this.pivot.measures[0].string; } else { - this.pivot.cols.main.title = this.title; + this.pivot.main_col().title = this.title; } this.draw_top_headers(); _.each(this.pivot.rows.headers, this.proxy('draw_row')); }, - measure_label: function (measure) { - return (measure !== '__count') ? this.fields[measure].string : 'Quantity'; - }, - make_border_cell: function (colspan, rowspan, headercell) { var tag = (headercell) ? $('') : $(''); return tag.addClass('graph_border') @@ -445,7 +519,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ return $(' ') .addClass('web_graph_click') .attr('href', '#') - .addClass((header.is_expanded) ? 'fa fa-minus-square' : 'fa fa-plus-square') + .addClass((header.expanded) ? 'fa fa-minus-square' : 'fa fa-plus-square') .append((header.title !== undefined) ? header.title : 'Undefined'); }, @@ -486,11 +560,11 @@ instance.web_graph.Graph = instance.web.Widget.extend({ } } - set_dim(pivot.cols.main); // add width and height info to columns headers - if (pivot.cols.main.children.length === 0) { + set_dim(pivot.main_col()); // add width and height info to columns headers + if (pivot.main_col().children.length === 0) { make_cells(pivot.cols.headers, 0); } else { - make_cells(pivot.cols.main.children, 1); + make_cells(pivot.main_col().children, 1); if (pivot.get_cols_leaves().length > 1) { header_cells[0].push(self.make_border_cell(pivot.measures.length, height, true).append('Total').css('font-weight', 'bold')); } @@ -520,7 +594,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ if (!col.children.length) { for (var i = 0; i < measures.length; i++) { measure_cells = $('').addClass('measure_row'); - measure_cells.append(self.measure_label(measures[i])); + measure_cells.append(measures[i].string); measure_row.append(measure_cells); } } @@ -529,24 +603,17 @@ instance.web_graph.Graph = instance.web.Widget.extend({ if (this.pivot.get_cols_leaves().length > 1) { for (var i = 0; i < measures.length; i++) { measure_cells = $('').addClass('measure_row'); - measure_cells.append(self.measure_label(measures[i])); + measure_cells.append(measures[i].string); measure_row.append(measure_cells); } } return measure_row; }, - get_measure_types: function () { - var self = this; - return _.map(this.pivot.measures, function (measure) { - return (measure !== '__count') ? self.fields[measure].type : 'integer'; - }); - }, - draw_row: function (row) { var self = this, pivot = this.pivot, - measure_types = this.get_measure_types(), + measure_types = _.pluck(this.pivot.measures, 'type'), html_row = $(''), row_header = this.make_border_cell(1,1) .append(this.make_header_title(row).attr('data-id', row.id)) @@ -560,7 +627,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ _.each(pivot.cols.headers, function (col) { if (col.children.length === 0) { - var values = pivot.get_value(row.id, col.id, new Array(measure_types.length)); + var values = pivot.get_values(row.id, col.id); for (var i = 0; i < values.length; i++) { html_row.append(make_cell(values[i], measure_types[i], i, col)); } @@ -570,7 +637,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ if (pivot.get_cols_leaves().length > 1) { var total_vals = pivot.get_total(row); for (var j = 0; j < total_vals.length; j++) { - var cell = make_cell(total_vals[j], measure_types[j], j, pivot.cols.main).css('font-weight', 'bold'); + var cell = make_cell(total_vals[j], measure_types[j], j, pivot.cols[0]).css('font-weight', 'bold'); html_row.append(cell); } } @@ -596,6 +663,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ cell.css('background-color', $.Color(255, color, color)); } if (self.mode === 'col_heatmap') { + debugger; total = pivot.get_total(col)[index]; color = Math.floor(90 + 165*(total - Math.abs(value))/total); cell.css('background-color', $.Color(255, color, color)); @@ -617,42 +685,42 @@ instance.web_graph.Graph = instance.web.Widget.extend({ if ((dim_x === 0) && (dim_y === 0)) { data = [{key: 'Total', values:[{ x: 'Total', - y: this.pivot.get_value(this.pivot.rows.main.id, this.pivot.cols.main.id)[0], + y: this.pivot.get_total(), }]}]; // Only column groupbys **************************************************** } else if ((dim_x === 0) && (dim_y >= 1)){ - data = _.map(this.pivot.get_columns_depth(1), function (header) { + data = _.map(this.pivot.get_columns_with_depth(1), function (header) { return { key: header.title, - values: [{x:header.root.main.title, y: self.pivot.get_total(header)[0]}] + values: [{x:header.root[0].title, y: self.pivot.get_total(header)[0]}] }; }); // Just 1 row groupby ****************************************************** } else if ((dim_x === 1) && (dim_y === 0)) { - data = _.map(this.pivot.rows.main.children, function (pt) { - var value = self.pivot.get_value(pt.id, self.pivot.cols.main.id)[0], + data = _.map(this.pivot.main_row().children, function (pt) { + var value = self.pivot.get_total(pt), title = (pt.title !== undefined) ? pt.title : 'Undefined'; return {x: title, y: value}; }); - data = [{key: self.measure_label(self.pivot.measures[0]), values:data}]; + data = [{key: self.pivot.measures[0].string, values:data}]; // 1 row groupby and some col groupbys************************************** } else if ((dim_x === 1) && (dim_y >= 1)) { - data = _.map(this.pivot.get_columns_depth(1), function (colhdr) { - var values = _.map(self.pivot.get_rows_depth(1), function (header) { + data = _.map(this.pivot.get_cols_with_depth(1), function (colhdr) { + var values = _.map(self.pivot.get_rows_with_depth(1), function (header) { return { x: header.title || 'Undefined', - y: self.pivot.get_value(header.id, colhdr.id, 0)[0] + y: self.pivot.get_values(header.id, colhdr.id, 0)[0] }; }); return {key: colhdr.title || 'Undefined', values: values}; }); // At least two row groupby************************************************* } else { - var keys = _.uniq(_.map(this.pivot.get_rows_depth(2), function (hdr) { + var keys = _.uniq(_.map(this.pivot.get_rows_with_depth(2), function (hdr) { return hdr.title || 'Undefined'; })); data = _.map(keys, function (key) { - var values = _.map(self.pivot.get_rows_depth(1), function (hdr) { + var values = _.map(self.pivot.get_rows_with_depth(1), function (hdr) { var subhdr = _.find(hdr.children, function (child) { return ((child.title === key) || ((child.title === undefined) && (key === 'Undefined'))); }); @@ -697,14 +765,14 @@ instance.web_graph.Graph = instance.web.Widget.extend({ dim_y = this.pivot.cols.groupby.length; var data = _.map(this.pivot.get_cols_leaves(), function (col) { - var values = _.map(self.pivot.get_rows_depth(dim_x), function (row) { - return {x: row.title, y: self.pivot.get_value(row.id,col.id, 0)}; + var values = _.map(self.pivot.get_rows_with_depth(dim_x), function (row) { + return {x: row.title, y: self.pivot.get_values(row.id,col.id, 0)}; }); var title = _.map(col.path, function (p) { return p || 'Undefined'; }).join('/'); if (dim_y === 0) { - title = self.measure_label(self.pivot.measures[0]); + title = self.pivot.measures[0].string; } return {values: values, key: title}; }); @@ -729,7 +797,7 @@ instance.web_graph.Graph = instance.web.Widget.extend({ pie_chart: function () { var self = this, dim_x = this.pivot.rows.groupby.length; - + debugger; var data = _.map(this.pivot.get_rows_leaves(), function (row) { var title = _.map(row.path, function (p) { return p || 'Undefined'; -- cgit v1.2.3 From dbf064e817b3b37fa29c01ef362662ec134707d2 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 10 Jan 2014 13:01:49 +0100 Subject: [REF] removes useless comments (addon web_graph) bzr revid: ged@openerp.com-20140110120149-pi0h75eqlr2tl9n5 --- addons/web_graph/static/src/js/graph.js | 55 +-------------------------------- 1 file changed, 1 insertion(+), 54 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 84a7d147ac2..8cdc9a3eb0f 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -41,7 +41,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.widget_config = { title: arch.attrs.string }; - debugger; if (!_.has(arch.attrs, 'type')) { this.widget_config.mode = 'bar_chart'; } else { @@ -238,7 +237,7 @@ instance.web_graph.Graph = instance.web.Widget.extend(openerp.EventDispatcherMix self.add_measures_to_options(); }); - $.when(def1, def2).then(function () { + return $.when(def1, def2).then(function () { self.pivot = new openerp.web_graph.PivotTable(self.model, self.domain, self.fields, self.pivot_options); self.pivot.on('redraw_required', self, self.proxy('display_data')); self.pivot.on('groupby_changed', self, function () { self.trigger('groupby_changed'); }); @@ -329,57 +328,6 @@ instance.web_graph.Graph = instance.web.Widget.extend(openerp.EventDispatcherMix }); }, - // self.fields = fs; - // var temp = _.map(fs, function (field, name) { - // return {name:name, type: field.type}; - // }); - // temp = _.filter(temp, function (field) { - // return (((field.type === 'integer') || (field.type === 'float')) && (field.name !== 'id')); - // }); - // self.measure_list = _.map(temp, function (field) { - // return field.name; - // }); - - // var measure_selection = self.$('.graph_measure_selection'); - // _.each(self.measure_list, function (measure) { - // var choice = $('').attr('data-choice', measure) - // .attr('href', '#') - // .append(self.fields[measure].string); - // measure_selection.append($('
  • ').append(choice)); - // }); - // }); - // }, - - // hide ui/show, stacked/grouped - // config: function (options) { - // Possible modes: pivot, heatmap, row_heatmap, col_heatmap, - // bar_chart, pie_chart, line_chart - // if (_.has(options, 'mode')) { this.mode = mode; } - // if (_.has(options, 'visible_ui')) { - // this.visible_ui = options.visible_ui; - // } - // if (_.has(options, 'bar_ui')) { - // this.bar_ui = options.bar_ui; - // } - // if (_.has(options, 'title')) { - // this.title = options.title; - // } - // debugger; - // this.pivot.config(options); - // }, - - - // get the most important fields (of the model) by looking at the - // groupby filters defined in the search view - - // get the fields descriptions and measure list from the model - - // return $.when(deferred1, deferred2).then(function () { - // self.pivot = new openerp.web_graph.PivotTable(self.model, self.fields); - // self.activate_display(); - // }); - // }, - set_mode: function (mode) { }, @@ -797,7 +745,6 @@ instance.web_graph.Graph = instance.web.Widget.extend(openerp.EventDispatcherMix pie_chart: function () { var self = this, dim_x = this.pivot.rows.groupby.length; - debugger; var data = _.map(this.pivot.get_rows_leaves(), function (row) { var title = _.map(row.path, function (p) { return p || 'Undefined'; -- cgit v1.2.3 From 2b3b08160cd43f47f1ee11fa0fb6f400849f2fa1 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 10 Jan 2014 15:08:37 +0100 Subject: [REF] simplification of the way Pivot configuration is done in graph view (addon web_graph) bzr revid: ged@openerp.com-20140110140837-tl3ts6za0zr46id7 --- addons/web_graph/static/src/js/graph.js | 158 +++++++++++--------------------- 1 file changed, 52 insertions(+), 106 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 8cdc9a3eb0f..d92d09f3a8c 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -35,37 +35,14 @@ instance.web_graph.GraphView = instance.web.View.extend({ view_loading: function (fields_view_get) { var self = this, - arch = fields_view_get.arch, - measures = [], - stacked = false; + arch = fields_view_get.arch; - this.widget_config = { title: arch.attrs.string }; - - if (!_.has(arch.attrs, 'type')) { - this.widget_config.mode = 'bar_chart'; - } else { - switch (arch.attrs.type) { - case 'bar': - this.widget_config.mode = 'bar_chart'; - break; - case 'pie': - this.widget_config.mode = 'pie_chart'; - break; - case 'line': - this.widget_config.mode = 'line_chart'; - break; - case 'pivot': - case 'heatmap': - case 'row_heatmap': - case 'col_heatmap': - this.widget_config.mode = arch.attrs.type; - break; - } - } - - if (arch.attrs.stacked === 'True') { - this.widget_config.stacked = true; - } + this.widget_config = { + title: arch.attrs.string, + stacked : (arch.attrs.stacked === 'True'), + mode: (arch.attrs.type) ? arch.attrs.type : 'bar', + measures: [], + }; _.each(arch.children, function (field) { if (_.has(field.attrs, 'type')) { @@ -77,28 +54,22 @@ instance.web_graph.GraphView = instance.web.View.extend({ self.default_col_groupby.push(field.attrs.name); break; case 'measure': - measures.push(field.attrs.name); + self.widget_config.measures.push(field.attrs.name); break; } } else { // old style, kept for backward compatibility if ('operator' in field.attrs) { - measures.push(field.attrs.name); + self.widget_config.measures.push(field.attrs.name); } else { self.default_row_groupby.push(field.attrs.name); } } }); - if (measures.length === 0) { - measures.push('__count'); + if (self.widget_config.measures.length === 0) { + self.widget_config.measures.push('__count'); } this.widget_config.row_groupby = self.default_row_groupby; this.widget_config.col_groupby = self.default_col_groupby; - this.widget_config.measures = measures; - // measures:measures, - // update:false, - // title: title, - // bar_ui: (stacked) ? 'stack' : 'group' - // }); }, get_context: function (facet) { @@ -109,46 +80,42 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, do_search: function (domain, context, group_by) { - var col_groupby = context.col_group_by || [], - options = {domain:domain}; + // var col_groupby = context.col_group_by || [], + // options = {domain:domain}; if (!this.graph_widget) { this.graph_widget = new openerp.web_graph.Graph(this, this.model, domain, this.widget_config); this.graph_widget.appendTo(this.$el); this.graph_widget.on('groupby_changed', this, this.proxy('register_groupby')); + this.ViewManager.on('switch_mode', this, function (e) { if (e === 'graph') this.graph_widget.reload(); }); } - this.search_view_groupby = group_by; + // this.search_view_groupby = group_by; - if (group_by.length && this.groupby_mode !== 'manual') { - if (_.isEqual(col_groupby, [])) { - col_groupby = this.default_col_groupby; - } - } - if (group_by.length || col_groupby.length) { - this.groupby_mode = 'manual'; - } - if (!this.graph_widget.enabled) { - options.update = false; - options.silent = true; - } - - if (this.groupby_mode === 'manual') { - options.row_groupby = group_by; - options.col_groupby = col_groupby; - } else { - options.row_groupby = _.toArray(this.default_row_groupby); - options.col_groupby = _.toArray(this.default_col_groupby); - } - this.graph_widget.set_domain(domain); - this.graph_widget.set_col_groupby(options.col_groupby); - this.graph_widget.set_row_groupby(options.row_groupby); + // if (group_by.length && this.groupby_mode !== 'manual') { + // if (_.isEqual(col_groupby, [])) { + // col_groupby = this.default_col_groupby; + // } + // } + // if (group_by.length || col_groupby.length) { + // this.groupby_mode = 'manual'; + // } + // if (!this.graph_widget.enabled) { + // options.update = false; + // options.silent = true; + // } - // this.graph_widget.pivot.config(options); + // if (this.groupby_mode === 'manual') { + // options.row_groupby = group_by; + // options.col_groupby = col_groupby; + // } else { + // options.row_groupby = _.toArray(this.default_row_groupby); + // options.col_groupby = _.toArray(this.default_col_groupby); + // } + // this.graph_widget.set(domain, options.row_groupby, options.col_groupby); + // this.graph_widget.set_domain(domain); + // this.graph_widget.set_col_groupby(options.col_groupby); + // this.graph_widget.set_row_groupby(options.row_groupby); - if (!this.graph_widget.enabled) { - this.graph_widget.activate_display(); - this.ViewManager.on('switch_mode', this, function () {this.graph_widget.pivot.update_data(); }); - } }, do_show: function () { @@ -199,7 +166,6 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, }); -// important_fields = [field], field = {field: _,type: _, string: _} instance.web_graph.Graph = instance.web.Widget.extend(openerp.EventDispatcherMixin, { template: 'GraphWidget', @@ -212,8 +178,6 @@ instance.web_graph.Graph = instance.web.Widget.extend(openerp.EventDispatcherMix }, init: function(parent, model, domain, options) { - var self = this; - this._super(parent); this.model = model; this.domain = domain; @@ -231,7 +195,7 @@ instance.web_graph.Graph = instance.web.Widget.extend(openerp.EventDispatcherMix self.important_fields = f; }); - var def2 = this.get_model_fields().then(function (f) { + var def2 = this.model.call('fields_get', []).then(function (f) { self.fields = f; self.measure_list = self.get_measures(); self.add_measures_to_options(); @@ -278,12 +242,6 @@ instance.web_graph.Graph = instance.web.Widget.extend(openerp.EventDispatcherMix }); }, - get_model_fields: function () { - return this.model.call('fields_get', []).then(function (fs) { - return fs; - }); - }, - get_measures: function(fields) { var measures = []; _.each(this.fields, function (f, id) { @@ -294,27 +252,14 @@ instance.web_graph.Graph = instance.web.Widget.extend(openerp.EventDispatcherMix return measures; }, - set_domain: function (domain) { - if (this.pivot) { - this.pivot.set_domain(domain); - } else { - this.pivot_options.domain = domain; - } - }, - set_row_groupby: function (groupby) { + set: function (domain, row_groupby, col_groupby) { if (this.pivot) { - this.pivot.set_row_groupby(groupby); + this.pivot.set(domain, row_groupby, col_groupby); } else { - this.pivot_options.row_groupby = groupby; - } - }, - - set_col_groupby: function (groupby) { - if (this.pivot) { - this.pivot.set_col_groupby(groupby); - } else { - this.pivot_options.col_groupby = groupby; + this.pivot_options.domain = domain; + this.pivot_options.row_groupby = row_groupby; + this.pivot_options.col_groupby = col_groupby; } }, @@ -329,10 +274,12 @@ instance.web_graph.Graph = instance.web.Widget.extend(openerp.EventDispatcherMix }, set_mode: function (mode) { - + this.mode = mode; + this.display_data(); }, - activate_display: function () { + reload: function () { + this.pivot.update_data(); }, display_data: function () { @@ -364,8 +311,7 @@ instance.web_graph.Graph = instance.web.Widget.extend(openerp.EventDispatcherMix mode_selection: function (event) { event.preventDefault(); var mode = event.target.attributes['data-mode'].nodeValue; - this.mode = mode; - this.display_data(); + this.set_mode(mode); }, measure_selection: function (event) { @@ -623,7 +569,7 @@ instance.web_graph.Graph = instance.web.Widget.extend(openerp.EventDispatcherMix /****************************************************************************** * Drawing charts methods... ******************************************************************************/ - bar_chart: function () { + bar: function () { var self = this, dim_x = this.pivot.rows.groupby.length, dim_y = this.pivot.cols.groupby.length, @@ -707,7 +653,7 @@ instance.web_graph.Graph = instance.web.Widget.extend(openerp.EventDispatcherMix }, - line_chart: function () { + line: function () { var self = this, dim_x = this.pivot.rows.groupby.length, dim_y = this.pivot.cols.groupby.length; @@ -742,7 +688,7 @@ instance.web_graph.Graph = instance.web.Widget.extend(openerp.EventDispatcherMix }); }, - pie_chart: function () { + pie: function () { var self = this, dim_x = this.pivot.rows.groupby.length; var data = _.map(this.pivot.get_rows_leaves(), function (row) { -- cgit v1.2.3 From e2bb629c3c2528c26b216ff8fe21b4c4fb7634e0 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Mon, 13 Jan 2014 14:38:00 +0100 Subject: [IMP] adds support for various intervals when grouping by date in graph view (addon web_graph) bzr revid: ged@openerp.com-20140113133800-3n1hi5ajpioktr3d --- addons/web_graph/static/src/js/graph.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index d92d09f3a8c..abd1d41d629 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -369,7 +369,7 @@ instance.web_graph.Graph = instance.web.Widget.extend(openerp.EventDispatcherMix return; } var fields = _.map(this.important_fields, function (field) { - return {id: field, value: self.fields[field].string}; + return {id: field, value: self.fields[field].string, type:self.fields[field].type}; }); this.dropdown = $(QWeb.render('field_selection', {fields:fields, header_id:id})); $(event.target).after(this.dropdown); @@ -383,9 +383,15 @@ instance.web_graph.Graph = instance.web.Widget.extend(openerp.EventDispatcherMix field_selection: function (event) { var id = event.target.attributes['data-id'].nodeValue, - field_id = event.target.attributes['data-field-id'].nodeValue; + field_id = event.target.attributes['data-field-id'].nodeValue, + interval; event.preventDefault(); - this.pivot.expand(id, field_id); + if (this.fields[field_id].type === 'date' || this.fields[field_id].type === 'datetime') { + interval = event.target.attributes['data-interval'].nodeValue; + this.pivot.expand(id, {field: field_id, interval: interval}); + } else { + this.pivot.expand(id, field_id); + } }, /****************************************************************************** -- cgit v1.2.3 From 4d550e963ea07da045bcb8f68ec4fad5fc7b591d Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Mon, 13 Jan 2014 16:23:16 +0100 Subject: [FIX] fixes some issues with chart drawing in graph view (addon web_graph) bzr revid: ged@openerp.com-20140113152316-4i3endkgu10jmxgc --- addons/web_graph/static/src/js/graph.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index abd1d41d629..f39f0574e9b 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -184,6 +184,7 @@ instance.web_graph.Graph = instance.web.Widget.extend(openerp.EventDispatcherMix this.mode = options.mode || 'pivot'; this.title = options.title || 'Graph'; this.visible_ui = options.visible_ui || true; + this.bar_ui = options.bar_ui || 'group'; this.pivot_options = options; }, @@ -325,13 +326,13 @@ instance.web_graph.Graph = instance.web.Widget.extend(openerp.EventDispatcherMix switch (event.target.attributes['data-choice'].nodeValue) { case 'bar_grouped': this.bar_ui = 'group'; - if (this.mode === 'bar_chart') { + if (this.mode === 'bar') { this.display_data(); } break; case 'bar_stacked': this.bar_ui = 'stack'; - if (this.mode === 'bar_chart') { + if (this.mode === 'bar') { this.display_data(); } break; @@ -609,7 +610,7 @@ instance.web_graph.Graph = instance.web.Widget.extend(openerp.EventDispatcherMix var values = _.map(self.pivot.get_rows_with_depth(1), function (header) { return { x: header.title || 'Undefined', - y: self.pivot.get_values(header.id, colhdr.id, 0)[0] + y: self.pivot.get_values(header.id, colhdr.id)[0] || 0 }; }); return {key: colhdr.title || 'Undefined', values: values}; -- cgit v1.2.3 From de85a1cefb2d62aae5a4a29295dcf36b6c545ad6 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 14 Jan 2014 10:27:24 +0100 Subject: [REF] adds comments and reorganize the functions in PivotTable class (addon web_graph) bzr revid: ged@openerp.com-20140114092724-z534vyceksc4dnr2 --- addons/web_graph/static/src/js/graph.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index f39f0574e9b..0259b4bcf73 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -340,9 +340,7 @@ instance.web_graph.Graph = instance.web.Widget.extend(openerp.EventDispatcherMix this.pivot.swap_axis(); break; case 'expand_all': - this.pivot.rows.headers = null; - this.pivot.cols.headers = null; - this.pivot.update_data(); + this.pivot.expand_all(); break; case 'update_values': this.pivot.update_data(); -- cgit v1.2.3 From 11de0f36ed923f0222d8e1ecc603b53366eabf75 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 14 Jan 2014 13:51:42 +0100 Subject: [REF] separates graph view and graph widget into two files, and renames pivot into pivot_table.js (addon web_graph) bzr revid: ged@openerp.com-20140114125142-9qj3mvu0a1fp4sis --- addons/web_graph/static/src/js/graph.js | 737 -------------------------------- 1 file changed, 737 deletions(-) delete mode 100644 addons/web_graph/static/src/js/graph.js (limited to 'addons/web_graph/static/src/js/graph.js') diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js deleted file mode 100644 index 0259b4bcf73..00000000000 --- a/addons/web_graph/static/src/js/graph.js +++ /dev/null @@ -1,737 +0,0 @@ -/*--------------------------------------------------------- - * OpenERP web_graph - *---------------------------------------------------------*/ - -/* jshint undef: false */ - -openerp.web_graph = function (instance) { -'use strict'; - -var _lt = instance.web._lt; -var _t = instance.web._t; -var QWeb = instance.web.qweb; - -instance.web.views.add('graph', 'instance.web_graph.GraphView'); - -instance.web_graph.GraphView = instance.web.View.extend({ - display_name: _lt('Graph'), - view_type: 'graph', - - init: function(parent, dataset, view_id, options) { - this._super(parent, dataset, view_id, options); - this.dataset = dataset; - this.model = new instance.web.Model(dataset.model, {group_by_no_leaf: true}); - this.search_view = parent.searchview; - this.search_view_groupby = []; - this.groupby_mode = 'default'; // 'default' or 'manual' - this.default_row_groupby = []; - this.default_col_groupby = []; - this.search_field = { - get_context: this.proxy('get_context'), - get_domain: function () {}, - get_groupby: function () { }, - }; - }, - - view_loading: function (fields_view_get) { - var self = this, - arch = fields_view_get.arch; - - this.widget_config = { - title: arch.attrs.string, - stacked : (arch.attrs.stacked === 'True'), - mode: (arch.attrs.type) ? arch.attrs.type : 'bar', - measures: [], - }; - - _.each(arch.children, function (field) { - if (_.has(field.attrs, 'type')) { - switch (field.attrs.type) { - case 'row': - self.default_row_groupby.push(field.attrs.name); - break; - case 'col': - self.default_col_groupby.push(field.attrs.name); - break; - case 'measure': - self.widget_config.measures.push(field.attrs.name); - break; - } - } else { // old style, kept for backward compatibility - if ('operator' in field.attrs) { - self.widget_config.measures.push(field.attrs.name); - } else { - self.default_row_groupby.push(field.attrs.name); - } - } - }); - if (self.widget_config.measures.length === 0) { - self.widget_config.measures.push('__count'); - } - this.widget_config.row_groupby = self.default_row_groupby; - this.widget_config.col_groupby = self.default_col_groupby; - }, - - get_context: function (facet) { - var col_group_by = _.map(facet.values.models, function (model) { - return model.attributes.value.attrs.context.col_group_by; - }); - return {col_group_by : col_group_by}; - }, - - do_search: function (domain, context, group_by) { - // var col_groupby = context.col_group_by || [], - // options = {domain:domain}; - - if (!this.graph_widget) { - this.graph_widget = new openerp.web_graph.Graph(this, this.model, domain, this.widget_config); - this.graph_widget.appendTo(this.$el); - this.graph_widget.on('groupby_changed', this, this.proxy('register_groupby')); - this.ViewManager.on('switch_mode', this, function (e) { if (e === 'graph') this.graph_widget.reload(); }); - } - // this.search_view_groupby = group_by; - - // if (group_by.length && this.groupby_mode !== 'manual') { - // if (_.isEqual(col_groupby, [])) { - // col_groupby = this.default_col_groupby; - // } - // } - // if (group_by.length || col_groupby.length) { - // this.groupby_mode = 'manual'; - // } - // if (!this.graph_widget.enabled) { - // options.update = false; - // options.silent = true; - // } - - // if (this.groupby_mode === 'manual') { - // options.row_groupby = group_by; - // options.col_groupby = col_groupby; - // } else { - // options.row_groupby = _.toArray(this.default_row_groupby); - // options.col_groupby = _.toArray(this.default_col_groupby); - // } - // this.graph_widget.set(domain, options.row_groupby, options.col_groupby); - // this.graph_widget.set_domain(domain); - // this.graph_widget.set_col_groupby(options.col_groupby); - // this.graph_widget.set_row_groupby(options.row_groupby); - - }, - - do_show: function () { - this.do_push_state({}); - return this._super(); - }, - - register_groupby: function() { - // var self = this, - // query = this.search_view.query; - - // this.groupby_mode = 'manual'; - // if (_.isEqual(this.search_view_groupby, this.graph_widget.pivot.rows.groupby) || - // (!_.has(this.search_view, '_s_groupby'))) { - // return; - // } - // var rows = _.map(this.graph_widget.pivot.rows.groupby, function (group) { - // return make_facet('GroupBy', group); - // }); - // var cols = _.map(this.graph_widget.pivot.cols.groupby, function (group) { - // return make_facet('ColGroupBy', group); - // }); - - // query.reset(rows.concat(cols)); - - // function make_facet (category, fields) { - // var values, - // icon, - // backbone_field, - // cat_name; - // if (!(fields instanceof Array)) { fields = [fields]; } - // if (category === 'GroupBy') { - // cat_name = 'group_by'; - // icon = 'w'; - // backbone_field = self.search_view._s_groupby; - // } else { - // cat_name = 'col_group_by'; - // icon = 'f'; - // backbone_field = self.search_field; - // } - // values = _.map(fields, function (field) { - // var context = {}; - // context[cat_name] = field; - // return {label: self.graph_widget.fields[field].string, value: {attrs:{domain: [], context: context}}}; - // }); - // return {category:category, values: values, icon:icon, field: backbone_field}; - // } - }, -}); - -instance.web_graph.Graph = instance.web.Widget.extend(openerp.EventDispatcherMixin, { - template: 'GraphWidget', - - events: { - 'click .graph_mode_selection li' : 'mode_selection', - 'click .graph_measure_selection li' : 'measure_selection', - 'click .graph_options_selection li' : 'option_selection', - 'click .web_graph_click' : 'header_cell_clicked', - 'click a.field-selection' : 'field_selection', - }, - - init: function(parent, model, domain, options) { - this._super(parent); - this.model = model; - this.domain = domain; - this.mode = options.mode || 'pivot'; - this.title = options.title || 'Graph'; - this.visible_ui = options.visible_ui || true; - this.bar_ui = options.bar_ui || 'group'; - this.pivot_options = options; - }, - - start: function() { - var self = this; - this.table = $('
    '); - this.$('.graph_main_content').append(this.table); - var def1 = this.get_search_fields().then(function (f) { - self.important_fields = f; - }); - - var def2 = this.model.call('fields_get', []).then(function (f) { - self.fields = f; - self.measure_list = self.get_measures(); - self.add_measures_to_options(); - }); - - return $.when(def1, def2).then(function () { - self.pivot = new openerp.web_graph.PivotTable(self.model, self.domain, self.fields, self.pivot_options); - self.pivot.on('redraw_required', self, self.proxy('display_data')); - self.pivot.on('groupby_changed', self, function () { self.trigger('groupby_changed'); }); - instance.web.bus.on('click', self, function () { - if (self.dropdown) { - self.dropdown.remove(); - self.dropdown = null; - } - }); - self.pivot.activate(); - }); - }, - - get_search_fields: function () { - var self = this, - options = {model:this.model, view_type: 'search'}, - result = []; - - return instance.web.fields_view_get(options).then(function (search_view) { - var groups = _.select(search_view.arch.children, function (c) { - return (c.tag === 'group') && (c.attrs.string != 'Display'); - }); - _.each(groups, function(g) { - _.each(g.children, function (g) { - if (g.attrs.context) { - var field_id = py.eval(g.attrs.context).group_by; - if (field_id) { - if (field_id instanceof Array) { - result.concat(field_id); - } else { - result.push(field_id); - } - } - } - }); - }); - return result; - }); - }, - - get_measures: function(fields) { - var measures = []; - _.each(this.fields, function (f, id) { - if (((f.type === 'integer') || (f.type === 'float')) && (id !== 'id')) { - measures.push({field:id, type: f.type, string: f.string}); - } - }); - return measures; - }, - - - set: function (domain, row_groupby, col_groupby) { - if (this.pivot) { - this.pivot.set(domain, row_groupby, col_groupby); - } else { - this.pivot_options.domain = domain; - this.pivot_options.row_groupby = row_groupby; - this.pivot_options.col_groupby = col_groupby; - } - }, - - add_measures_to_options: function() { - var measure_selection = this.$('.graph_measure_selection'); - _.each(this.measure_list, function (measure) { - var choice = $('').attr('data-choice', measure.field) - .attr('href', '#') - .append(measure.string); - measure_selection.append($('
  • ').append(choice)); - }); - }, - - set_mode: function (mode) { - this.mode = mode; - this.display_data(); - }, - - reload: function () { - this.pivot.update_data(); - }, - - display_data: function () { - this.$('.graph_main_content svg').remove(); - this.$('.graph_main_content div').remove(); - this.table.empty(); - - if (this.visible_ui) { - this.$('.graph_header').css('display', 'block'); - } else { - this.$('.graph_header').css('display', 'none'); - } - if (this.pivot.no_data) { - this.$('.graph_main_content').append($(QWeb.render('graph_no_data'))); - } else { - var table_modes = ['pivot', 'heatmap', 'row_heatmap', 'col_heatmap']; - if (_.contains(table_modes, this.mode)) { - this.draw_table(); - } else { - this.$('.graph_main_content').append($('
    ')); - this.svg = this.$('.graph_main_content svg')[0]; - this.width = this.$el.width(); - this.height = Math.min(Math.max(document.documentElement.clientHeight - 116 - 60, 250), Math.round(0.8*this.$el.width())); - this[this.mode](); - } - } - }, - - mode_selection: function (event) { - event.preventDefault(); - var mode = event.target.attributes['data-mode'].nodeValue; - this.set_mode(mode); - }, - - measure_selection: function (event) { - event.preventDefault(); - var measure = event.target.attributes['data-choice'].nodeValue; - this.pivot.toggle_measure(measure); - }, - - option_selection: function (event) { - event.preventDefault(); - switch (event.target.attributes['data-choice'].nodeValue) { - case 'bar_grouped': - this.bar_ui = 'group'; - if (this.mode === 'bar') { - this.display_data(); - } - break; - case 'bar_stacked': - this.bar_ui = 'stack'; - if (this.mode === 'bar') { - this.display_data(); - } - break; - case 'swap_axis': - this.pivot.swap_axis(); - break; - case 'expand_all': - this.pivot.expand_all(); - break; - case 'update_values': - this.pivot.update_data(); - break; - case 'export_data': - // Export code... To do... - break; - } - }, - - header_cell_clicked: function (event) { - event.preventDefault(); - event.stopPropagation(); - var id = event.target.attributes['data-id'].nodeValue, - header = this.pivot.get_header(id), - self = this; - - if (header.expanded) { - this.pivot.fold(header); - } else { - if (header.path.length < header.root.groupby.length) { - this.pivot.expand(id); - } else { - if (!this.important_fields.length) { - return; - } - var fields = _.map(this.important_fields, function (field) { - return {id: field, value: self.fields[field].string, type:self.fields[field].type}; - }); - this.dropdown = $(QWeb.render('field_selection', {fields:fields, header_id:id})); - $(event.target).after(this.dropdown); - this.dropdown.css({position:'absolute', - left:event.pageX, - top:event.pageY}); - this.$('.field-selection').next('.dropdown-menu').toggle(); - } - } - }, - - field_selection: function (event) { - var id = event.target.attributes['data-id'].nodeValue, - field_id = event.target.attributes['data-field-id'].nodeValue, - interval; - event.preventDefault(); - if (this.fields[field_id].type === 'date' || this.fields[field_id].type === 'datetime') { - interval = event.target.attributes['data-interval'].nodeValue; - this.pivot.expand(id, {field: field_id, interval: interval}); - } else { - this.pivot.expand(id, field_id); - } - }, - -/****************************************************************************** - * Drawing pivot table methods... - ******************************************************************************/ - draw_table: function () { - this.pivot.main_row().title = 'Total'; - if (this.pivot.measures.length == 1) { - this.pivot.main_col().title = this.pivot.measures[0].string; - } else { - this.pivot.main_col().title = this.title; - } - this.draw_top_headers(); - _.each(this.pivot.rows.headers, this.proxy('draw_row')); - }, - - make_border_cell: function (colspan, rowspan, headercell) { - var tag = (headercell) ? $('') : $(''); - return tag.addClass('graph_border') - .attr('colspan', (colspan) ? colspan : 1) - .attr('rowspan', (rowspan) ? rowspan : 1); - }, - - make_header_title: function (header) { - return $(' ') - .addClass('web_graph_click') - .attr('href', '#') - .addClass((header.expanded) ? 'fa fa-minus-square' : 'fa fa-plus-square') - .append((header.title !== undefined) ? header.title : 'Undefined'); - }, - - draw_top_headers: function () { - var self = this, - thead = $(''), - pivot = this.pivot, - height = _.max(_.map(pivot.cols.headers, function(g) {return g.path.length;})), - header_cells = [[this.make_border_cell(1, height, true)]]; - - function set_dim (cols) { - _.each(cols.children, set_dim); - if (cols.children.length === 0) { - cols.height = height - cols.path.length + 1; - cols.width = 1; - } else { - cols.height = 1; - cols.width = _.reduce(cols.children, function (sum,c) { return sum + c.width;}, 0); - } - } - - function make_col_header (col) { - var cell = self.make_border_cell(col.width*pivot.measures.length, col.height, true); - return cell.append(self.make_header_title(col).attr('data-id', col.id)); - } - - function make_cells (queue, level) { - var col = queue[0]; - queue = _.rest(queue).concat(col.children); - if (col.path.length == level) { - _.last(header_cells).push(make_col_header(col)); - } else { - level +=1; - header_cells.push([make_col_header(col)]); - } - if (queue.length !== 0) { - make_cells(queue, level); - } - } - - set_dim(pivot.main_col()); // add width and height info to columns headers - if (pivot.main_col().children.length === 0) { - make_cells(pivot.cols.headers, 0); - } else { - make_cells(pivot.main_col().children, 1); - if (pivot.get_cols_leaves().length > 1) { - header_cells[0].push(self.make_border_cell(pivot.measures.length, height, true).append('Total').css('font-weight', 'bold')); - } - } - - _.each(header_cells, function (cells) { - thead.append($('').append(cells)); - }); - - if (pivot.measures.length >= 2) { - thead.append(self.make_measure_row()); - } - - self.table.append(thead); - }, - - make_measure_row: function() { - var self = this, - measures = this.pivot.measures, - cols = this.pivot.cols.headers, - measure_cells, - measure_row = $(''); - - measure_row.append($('')); - - _.each(cols, function (col) { - if (!col.children.length) { - for (var i = 0; i < measures.length; i++) { - measure_cells = $('').addClass('measure_row'); - measure_cells.append(measures[i].string); - measure_row.append(measure_cells); - } - } - }); - - if (this.pivot.get_cols_leaves().length > 1) { - for (var i = 0; i < measures.length; i++) { - measure_cells = $('').addClass('measure_row'); - measure_cells.append(measures[i].string); - measure_row.append(measure_cells); - } - } - return measure_row; - }, - - draw_row: function (row) { - var self = this, - pivot = this.pivot, - measure_types = _.pluck(this.pivot.measures, 'type'), - html_row = $(''), - row_header = this.make_border_cell(1,1) - .append(this.make_header_title(row).attr('data-id', row.id)) - .addClass('graph_border'); - - for (var i = 0; i < row.path.length; i++) { - row_header.prepend($('', {class:'web_graph_indent'})); - } - - html_row.append(row_header); - - _.each(pivot.cols.headers, function (col) { - if (col.children.length === 0) { - var values = pivot.get_values(row.id, col.id); - for (var i = 0; i < values.length; i++) { - html_row.append(make_cell(values[i], measure_types[i], i, col)); - } - } - }); - - if (pivot.get_cols_leaves().length > 1) { - var total_vals = pivot.get_total(row); - for (var j = 0; j < total_vals.length; j++) { - var cell = make_cell(total_vals[j], measure_types[j], j, pivot.cols[0]).css('font-weight', 'bold'); - html_row.append(cell); - } - } - - this.table.append(html_row); - - function make_cell (value, measure_type, index, col) { - var color, - total, - cell = $(''); - if (value === undefined) { - return cell; - } - cell.append(instance.web.format_value(value, {type: measure_type})); - if (self.mode === 'heatmap') { - total = pivot.get_total()[index]; - color = Math.floor(90 + 165*(total - Math.abs(value))/total); - cell.css('background-color', $.Color(255, color, color)); - } - if (self.mode === 'row_heatmap') { - total = pivot.get_total(row)[index]; - color = Math.floor(90 + 165*(total - Math.abs(value))/total); - cell.css('background-color', $.Color(255, color, color)); - } - if (self.mode === 'col_heatmap') { - debugger; - total = pivot.get_total(col)[index]; - color = Math.floor(90 + 165*(total - Math.abs(value))/total); - cell.css('background-color', $.Color(255, color, color)); - } - return cell; - } - }, - -/****************************************************************************** - * Drawing charts methods... - ******************************************************************************/ - bar: function () { - var self = this, - dim_x = this.pivot.rows.groupby.length, - dim_y = this.pivot.cols.groupby.length, - data; - - // No groupby ************************************************************** - if ((dim_x === 0) && (dim_y === 0)) { - data = [{key: 'Total', values:[{ - x: 'Total', - y: this.pivot.get_total(), - }]}]; - // Only column groupbys **************************************************** - } else if ((dim_x === 0) && (dim_y >= 1)){ - data = _.map(this.pivot.get_columns_with_depth(1), function (header) { - return { - key: header.title, - values: [{x:header.root[0].title, y: self.pivot.get_total(header)[0]}] - }; - }); - // Just 1 row groupby ****************************************************** - } else if ((dim_x === 1) && (dim_y === 0)) { - data = _.map(this.pivot.main_row().children, function (pt) { - var value = self.pivot.get_total(pt), - title = (pt.title !== undefined) ? pt.title : 'Undefined'; - return {x: title, y: value}; - }); - data = [{key: self.pivot.measures[0].string, values:data}]; - // 1 row groupby and some col groupbys************************************** - } else if ((dim_x === 1) && (dim_y >= 1)) { - data = _.map(this.pivot.get_cols_with_depth(1), function (colhdr) { - var values = _.map(self.pivot.get_rows_with_depth(1), function (header) { - return { - x: header.title || 'Undefined', - y: self.pivot.get_values(header.id, colhdr.id)[0] || 0 - }; - }); - return {key: colhdr.title || 'Undefined', values: values}; - }); - // At least two row groupby************************************************* - } else { - var keys = _.uniq(_.map(this.pivot.get_rows_with_depth(2), function (hdr) { - return hdr.title || 'Undefined'; - })); - data = _.map(keys, function (key) { - var values = _.map(self.pivot.get_rows_with_depth(1), function (hdr) { - var subhdr = _.find(hdr.children, function (child) { - return ((child.title === key) || ((child.title === undefined) && (key === 'Undefined'))); - }); - return { - x: hdr.title || 'Undefined', - y: (subhdr) ? self.pivot.get_total(subhdr)[0] : 0 - }; - }); - return {key:key, values: values}; - }); - } - - nv.addGraph(function () { - var chart = nv.models.multiBarChart() - .width(self.width) - .height(self.height) - .reduceXTicks(false) - .stacked(self.bar_ui === 'stack') - .showControls(false); - - if (self.width / data[0].values.length < 80) { - chart.rotateLabels(-15); - chart.reduceXTicks(true); - chart.margin({bottom:40}); - } - - d3.select(self.svg) - .datum(data) - .attr('width', self.width) - .attr('height', self.height) - .call(chart); - - nv.utils.windowResize(chart.update); - return chart; - }); - - }, - - line: function () { - var self = this, - dim_x = this.pivot.rows.groupby.length, - dim_y = this.pivot.cols.groupby.length; - - var data = _.map(this.pivot.get_cols_leaves(), function (col) { - var values = _.map(self.pivot.get_rows_with_depth(dim_x), function (row) { - return {x: row.title, y: self.pivot.get_values(row.id,col.id, 0)}; - }); - var title = _.map(col.path, function (p) { - return p || 'Undefined'; - }).join('/'); - if (dim_y === 0) { - title = self.pivot.measures[0].string; - } - return {values: values, key: title}; - }); - - nv.addGraph(function () { - var chart = nv.models.lineChart() - .x(function (d,u) { return u; }) - .width(self.width) - .height(self.height) - .margin({top: 30, right: 20, bottom: 20, left: 60}); - - d3.select(self.svg) - .attr('width', self.width) - .attr('height', self.height) - .datum(data) - .call(chart); - - return chart; - }); - }, - - pie: function () { - var self = this, - dim_x = this.pivot.rows.groupby.length; - var data = _.map(this.pivot.get_rows_leaves(), function (row) { - var title = _.map(row.path, function (p) { - return p || 'Undefined'; - }).join('/'); - if (dim_x === 0) { - title = self.measure_label; - } - return {x: title, y: self.pivot.get_total(row)}; - }); - - nv.addGraph(function () { - var chart = nv.models.pieChart() - .color(d3.scale.category10().range()) - .width(self.width) - .height(self.height); - - d3.select(self.svg) - .datum(data) - .transition().duration(1200) - .attr('width', self.width) - .attr('height', self.height) - .call(chart); - - nv.utils.windowResize(chart.update); - return chart; - }); - }, - -}); - -}; - - - - - - - - -- cgit v1.2.3