diff options
| author | Gery Debongnie <ged@openerp.com> | 2013-12-11 15:01:40 +0100 |
|---|---|---|
| committer | Gery Debongnie <ged@openerp.com> | 2013-12-11 15:01:40 +0100 |
| commit | b04f21ea12406fc28e7a74494af0397f6ce9e6d1 (patch) | |
| tree | 20f54e38032fe77dbba83dbd5b1ee8d23686a23f /addons/web_graph/static/src | |
| parent | b8a5b2d2b509bd19ef580f6c137327dbbae924f5 (diff) | |
[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
Diffstat (limited to 'addons/web_graph/static/src')
| -rw-r--r-- | addons/web_graph/static/src/css/graph.css | 1 | ||||
| -rw-r--r-- | addons/web_graph/static/src/js/charts.js | 107 | ||||
| -rw-r--r-- | addons/web_graph/static/src/js/graph.js | 13 |
3 files changed, 66 insertions, 55 deletions
diff --git a/addons/web_graph/static/src/css/graph.css b/addons/web_graph/static/src/css/graph.css index 8a92da76605..f054a553d4f 100644 --- a/addons/web_graph/static/src/css/graph.css +++ b/addons/web_graph/static/src/css/graph.css @@ -1,4 +1,3 @@ - .graph_main_content td { border: 1px solid black; padding: 0.5rem; diff --git a/addons/web_graph/static/src/js/charts.js b/addons/web_graph/static/src/js/charts.js index 42bb7599912..9e6c40eb866 100644 --- a/addons/web_graph/static/src/js/charts.js +++ b/addons/web_graph/static/src/js/charts.js @@ -1,11 +1,12 @@ -openerp.web_graph.draw_chart = function (mode, pivot, svg, measure_label) { - openerp.web_graph[mode](pivot, svg, measure_label); +openerp.web_graph.draw_chart = function (options) { + openerp.web_graph[options.mode](options); }; -openerp.web_graph.bar_chart = function (pivot, svg, measure_label) { - var dim_x = pivot.rows.groupby.length, +openerp.web_graph.bar_chart = function (options) { + var pivot = options.pivot, + dim_x = pivot.rows.groupby.length, dim_y = pivot.cols.groupby.length, data = []; @@ -13,7 +14,7 @@ openerp.web_graph.bar_chart = function (pivot, svg, measure_label) { if ((dim_x === 0) && (dim_y === 0)) { data = [{key: 'Total', values:[{ title: 'Total', - value: pivot.get_value(pivot.rows.main.id, pivot.cols.main.id), + value: options.pivot.get_value(pivot.rows.main.id, pivot.cols.main.id), }]}]; nv.addGraph(function () { var chart = nv.models.discreteBarChart() @@ -21,14 +22,14 @@ openerp.web_graph.bar_chart = function (pivot, svg, measure_label) { .y(function(d) { return d.value;}) .tooltips(false) .showValues(true) - .staggerLabels(true) - .width(650) - .height(400); + .width(options.width) + .height(options.height) + .staggerLabels(true); - d3.select(svg) + d3.select(options.svg) .datum(data) - .attr('width', 650) - .attr('height', 400) + .attr('width', options.width) + .attr('height', options.height) .call(chart); nv.utils.windowResize(chart.update); @@ -46,14 +47,14 @@ openerp.web_graph.bar_chart = function (pivot, svg, measure_label) { var chart = nv.models.multiBarChart() .stacked(true) .tooltips(false) - .showControls(false) - .width(400) - .height(500); + .width(options.width) + .height(options.height) + .showControls(false); - d3.select(svg) + d3.select(options.svg) .datum(data) - .attr('width', 400) - .attr('height', 500) + .attr('width', options.width) + .attr('height', options.height) .transition() .duration(500) .call(chart); @@ -69,21 +70,21 @@ openerp.web_graph.bar_chart = function (pivot, svg, measure_label) { title = (pt.title !== undefined) ? pt.title : 'Undefined'; return {title: title, value: value}; }); - data = [{key: 'Bar chart', values:data}]; + data = [{key: options.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) - .staggerLabels(true) - .width(650) - .height(400); + .width(options.width) + .height(options.height) + .staggerLabels(true); - d3.select(svg) + d3.select(options.svg) .datum(data) - .attr('width', 650) - .attr('height', 400) + .attr('width', options.width) + .attr('height', options.height) .call(chart); nv.utils.windowResize(chart.update); @@ -105,14 +106,14 @@ openerp.web_graph.bar_chart = function (pivot, svg, measure_label) { var chart = nv.models.multiBarChart() .stacked(true) .staggerLabels(true) - .tooltips(false) - .width(650) - .height(400); + .width(options.width) + .height(options.height) + .tooltips(false); - d3.select(svg) + d3.select(options.svg) .datum(data) - .attr('width', 650) - .attr('height', 400) + .attr('width', options.width) + .attr('height', options.height) .call(chart); nv.utils.windowResize(chart.update); @@ -140,14 +141,14 @@ openerp.web_graph.bar_chart = function (pivot, svg, measure_label) { var chart = nv.models.multiBarChart() .stacked(true) .staggerLabels(true) - .tooltips(false) - .width(650) - .height(400); + .width(options.width) + .height(options.height) + .tooltips(false); - d3.select(svg) + d3.select(options.svg) .datum(data) - .attr('width', 650) - .attr('height', 400) + .attr('width', options.width) + .attr('height', options.height) .call(chart); nv.utils.windowResize(chart.update); @@ -157,8 +158,9 @@ openerp.web_graph.bar_chart = function (pivot, svg, measure_label) { }; -openerp.web_graph.line_chart = function (pivot, svg, measure_label) { - var dim_x = pivot.rows.groupby.length, +openerp.web_graph.line_chart = function (options) { + var pivot = options.pivot, + dim_x = pivot.rows.groupby.length, dim_y = pivot.cols.groupby.length; var data = _.map(pivot.get_cols_leaves(), function (col) { @@ -169,7 +171,7 @@ openerp.web_graph.line_chart = function (pivot, svg, measure_label) { return p || 'Undefined'; }).join('/'); if (dim_y === 0) { - title = measure_label; + title = options.measure_label; } return {values: values, key: title}; }); @@ -177,13 +179,13 @@ openerp.web_graph.line_chart = function (pivot, svg, measure_label) { nv.addGraph(function () { var chart = nv.models.lineChart() .x(function (d,u) { return u; }) - .width(600) - .height(300) + .width(options.width) + .height(options.height) .margin({top: 30, right: 20, bottom: 20, left: 60}); - d3.select(svg) - .attr('width', 600) - .attr('height', 300) + d3.select(options.svg) + .attr('width', options.width) + .attr('height', options.height) .datum(data) .call(chart); @@ -191,8 +193,9 @@ openerp.web_graph.line_chart = function (pivot, svg, measure_label) { }); }; -openerp.web_graph.pie_chart = function (pivot, svg, measure_label) { - var dim_x = pivot.rows.groupby.length, +openerp.web_graph.pie_chart = function (options) { + var pivot = options.pivot, + dim_x = pivot.rows.groupby.length, dim_y = pivot.cols.groupby.length; var data = _.map(pivot.get_rows_leaves(), function (row) { @@ -200,7 +203,7 @@ openerp.web_graph.pie_chart = function (pivot, svg, measure_label) { return p || 'Undefined'; }).join('/'); if (dim_x === 0) { - title = measure_label; + title = options.measure_label; } return {x: title, y: pivot.get_total(row)}; }); @@ -208,14 +211,14 @@ openerp.web_graph.pie_chart = function (pivot, svg, measure_label) { nv.addGraph(function () { var chart = nv.models.pieChart() .color(d3.scale.category10().range()) - .width(650) - .height(400); + .width(options.width) + .height(options.height); - d3.select(svg) + d3.select(options.svg) .datum(data) .transition().duration(1200) - .attr('width', 650) - .attr('height', 400) + .attr('width', options.width) + .attr('height', options.height) .call(chart); nv.utils.windowResize(chart.update); 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 = $('<table></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($('<div><svg></svg></div>')); - 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); } } } |
