From f6a1c4986dc7bcbe2d6d2b0557de00b51ece44c6 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 23 Oct 2012 16:58:58 +0200 Subject: [PATCH 1/6] lot of modifs, still not functionning bzr revid: nicolas.vanhoren@openerp.com-20121023145858-dg34k7kqi3jkar6z --- addons/web_graph/controllers/graph.py | 82 +------------ addons/web_graph/static/src/js/graph.js | 154 ++++++++++++++++++++++-- 2 files changed, 146 insertions(+), 90 deletions(-) diff --git a/addons/web_graph/controllers/graph.py b/addons/web_graph/controllers/graph.py index 21ec7d6e973..bae535a9137 100644 --- a/addons/web_graph/controllers/graph.py +++ b/addons/web_graph/controllers/graph.py @@ -8,85 +8,5 @@ class GraphView(openerp.addons.web.controllers.main.View): @openerp.addons.web.http.jsonrequest def data_get(self, req, model=None, domain=[], context={}, group_by=[], view_id=False, orientation=False, stacked=False, mode="bar", **kwargs): - obj = req.session.model(model) - - res = obj.fields_view_get(view_id, 'graph') - fields = res['fields'] - toload = filter(lambda x: x not in fields, group_by) - if toload: - fields.update( obj.fields_get(toload, context) ) - - tree = etree.fromstring(res['arch']) - - pos = 0 - xaxis = group_by or [] - yaxis = [] - for field in tree.iter(tag='field'): - if (field.tag != 'field') or (not field.get('name')): - continue - assert field.get('name'), "This tag must have a 'name' attribute." - if (not group_by) and ((not pos) or field.get('group')): - xaxis.append(field.get('name')) - if pos and not field.get('group'): - yaxis.append(field.get('name')) - pos += 1 - - assert len(xaxis), "No field for the X axis!" - assert len(yaxis), "No field for the Y axis!" - - # Convert a field's data into a displayable string - - ticks = {} - def _convert_key(field, data): - if fields[field]['type']=='many2one': - data = data and data[0] - return data - - def _convert(field, data, tick=True): - if fields[field]['type']=='many2one': - data = data and data[1] - elif (fields[field]['type']=='selection') and (type(fields[field]['selection']) in (list, tuple)): - d = dict(fields[field]['selection']) - data = d[data] - if tick: - return ticks.setdefault(data, len(ticks)) - return data or 0 - - def _orientation(x, y): - if not orientation: - return (x,y) - return (y,x) - - result = [] - if mode=="pie": - res = obj.read_group(domain, yaxis+[xaxis[0]], [xaxis[0]], context=context) - for record in res: - result.append( { - 'data': [(_convert(xaxis[0], record[xaxis[0]]), record[yaxis[0]])], - 'label': _convert(xaxis[0], record[xaxis[0]], tick=False) - }) - - elif (not stacked) or (len(xaxis)<2): - for x in xaxis: - res = obj.read_group(domain, yaxis+[x], [x], context=context) - result.append( { - 'data': map(lambda record: _orientation(_convert(x, record[x]), record[yaxis[0]] or 0), res), - 'label': fields[x]['string'] - }) - else: - xaxis.reverse() - axis = obj.read_group(domain, yaxis+xaxis[0:1], xaxis[0:1], context=context) - for x in axis: - key = x[xaxis[0]] - res = obj.read_group(domain+[(xaxis[0],'=',_convert_key(xaxis[0], key))], yaxis+xaxis[1:2], xaxis[1:2], context=context) - result.append( { - 'data': map(lambda record: _orientation(_convert(xaxis[1], record[xaxis[1]]), record[yaxis[0]] or 0), res), - 'label': _convert(xaxis[0], key, tick=False) - }) - - res = { - 'data': result, - 'ticks': map(lambda x: (x[1], x[0]), ticks.items()) - } - return res + pass diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 788ec3bcb3f..0295020dd92 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -228,15 +228,151 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, graph_get_data: function () { - return this.rpc('/web_graph/graph/data_get', { - model: this.dataset.model, - domain: this.domain, - context: this.context, - group_by: this.group_by, - view_id: this.view_id, - mode: this.mode, - orientation: this.orientation, - stacked: this.stacked + 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, + mode = this.mode, + orientation = this.orientation, + stacked = this.stacked; + + var obj = new instance.web.Model(model); + var view_get; + var fields; + var result = []; + var ticks = {}; + + return obj.call("fields_view_get", [view_id, 'graph']).pipe(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([]); + }).pipe(function (fields_to_add) { + _.extend(fields, fields_to_add); + + var tree = $($.parseXML(view_get['arch'])); + + var pos = 0; + var xaxis = group_by || []; + var yaxis = []; + debugger; + tree.find("field").each(function() { + var field = $(this); + if (! field.attr("name")) + return; + if ((! group_by) && ((! pos) || field.attr('group'))) { + xaxis.push(field.attr('name')); + } + if (pos && ! field.attr('group')) { + 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; + if (fields[field]['type'] === 'many2one') { + data = data && data[1]; + } else if ((fields[field]['type'] === 'selection') && (fields[field]['selection'] instanceof Array)) { + var d = {}; + _.each(fields[field]['selection'], function(el) { + d[el[0]] = el[1]; + }); + data = d[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+[xaxis[0]], [xaxis[0]]], {context: context}).pipe(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+[x], [x]], {context: context}).pipe(function(res) { + return [x, res]; + })); + }); + return $.when.apply($, defs).pipe(function() { + _.each(_.toArray(arguments), function(res) { + // TODO: must convert res + debugger; + 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 + xaxis.slice(0, 1), xaxis.slice(0, 1)], {context: context}).pipe(function(axis) { + var defs = []; + _.each(axis, function(x) { + var key = x[xaxis[0]] + defs.push(obj.call("read_group", [domain+[(xaxis[0],'=',_convert_key(xaxis[0], key))], yaxis + xaxis.slice(1, 2), xaxis.slice(1, 2)], + {context: context}).pipe(function(res) { + return [x, key, res]; + })); + }); + return $.when.apply($, defs).pipe(function(res) { + // TODO: must convert res + debugger; + 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]] or 0); + }), + 'label': _convert(xaxis[0], key, false) + }) + }); + }); + } + }).pipe(function() { + var res = { + 'data': result, + 'ticks': _.map(ticks, function(el, key) { return [el, key] }) + }; + return res; }); }, From 796958fa7c214eaba2c8379cd79a5d86059530f5 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 23 Oct 2012 17:11:23 +0200 Subject: [PATCH 2/6] Currently working for bar charts bzr revid: nicolas.vanhoren@openerp.com-20121023151123-ebo1edkp65c3dk94 --- addons/web_graph/controllers/graph.py | 82 ++++++++++++++++++++++++- addons/web_graph/static/src/js/graph.js | 31 ++++------ 2 files changed, 94 insertions(+), 19 deletions(-) diff --git a/addons/web_graph/controllers/graph.py b/addons/web_graph/controllers/graph.py index bae535a9137..21ec7d6e973 100644 --- a/addons/web_graph/controllers/graph.py +++ b/addons/web_graph/controllers/graph.py @@ -8,5 +8,85 @@ class GraphView(openerp.addons.web.controllers.main.View): @openerp.addons.web.http.jsonrequest def data_get(self, req, model=None, domain=[], context={}, group_by=[], view_id=False, orientation=False, stacked=False, mode="bar", **kwargs): - pass + obj = req.session.model(model) + + res = obj.fields_view_get(view_id, 'graph') + fields = res['fields'] + toload = filter(lambda x: x not in fields, group_by) + if toload: + fields.update( obj.fields_get(toload, context) ) + + tree = etree.fromstring(res['arch']) + + pos = 0 + xaxis = group_by or [] + yaxis = [] + for field in tree.iter(tag='field'): + if (field.tag != 'field') or (not field.get('name')): + continue + assert field.get('name'), "This tag must have a 'name' attribute." + if (not group_by) and ((not pos) or field.get('group')): + xaxis.append(field.get('name')) + if pos and not field.get('group'): + yaxis.append(field.get('name')) + pos += 1 + + assert len(xaxis), "No field for the X axis!" + assert len(yaxis), "No field for the Y axis!" + + # Convert a field's data into a displayable string + + ticks = {} + def _convert_key(field, data): + if fields[field]['type']=='many2one': + data = data and data[0] + return data + + def _convert(field, data, tick=True): + if fields[field]['type']=='many2one': + data = data and data[1] + elif (fields[field]['type']=='selection') and (type(fields[field]['selection']) in (list, tuple)): + d = dict(fields[field]['selection']) + data = d[data] + if tick: + return ticks.setdefault(data, len(ticks)) + return data or 0 + + def _orientation(x, y): + if not orientation: + return (x,y) + return (y,x) + + result = [] + if mode=="pie": + res = obj.read_group(domain, yaxis+[xaxis[0]], [xaxis[0]], context=context) + for record in res: + result.append( { + 'data': [(_convert(xaxis[0], record[xaxis[0]]), record[yaxis[0]])], + 'label': _convert(xaxis[0], record[xaxis[0]], tick=False) + }) + + elif (not stacked) or (len(xaxis)<2): + for x in xaxis: + res = obj.read_group(domain, yaxis+[x], [x], context=context) + result.append( { + 'data': map(lambda record: _orientation(_convert(x, record[x]), record[yaxis[0]] or 0), res), + 'label': fields[x]['string'] + }) + else: + xaxis.reverse() + axis = obj.read_group(domain, yaxis+xaxis[0:1], xaxis[0:1], context=context) + for x in axis: + key = x[xaxis[0]] + res = obj.read_group(domain+[(xaxis[0],'=',_convert_key(xaxis[0], key))], yaxis+xaxis[1:2], xaxis[1:2], context=context) + result.append( { + 'data': map(lambda record: _orientation(_convert(xaxis[1], record[xaxis[1]]), record[yaxis[0]] or 0), res), + 'label': _convert(xaxis[0], key, tick=False) + }) + + res = { + 'data': result, + 'ticks': map(lambda x: (x[1], x[0]), ticks.items()) + } + return res diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 0295020dd92..3b4a29bc55a 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -229,13 +229,13 @@ instance.web_graph.GraphView = instance.web.View.extend({ 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, - mode = this.mode, - orientation = this.orientation, - stacked = this.stacked; + 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; @@ -259,12 +259,11 @@ instance.web_graph.GraphView = instance.web.View.extend({ var pos = 0; var xaxis = group_by || []; var yaxis = []; - debugger; tree.find("field").each(function() { var field = $(this); if (! field.attr("name")) return; - if ((! group_by) && ((! pos) || field.attr('group'))) { + if ((group_by.length == 0) && ((! pos) || field.attr('group'))) { xaxis.push(field.attr('name')); } if (pos && ! field.attr('group')) { @@ -312,7 +311,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ } if (mode === "pie") { - return obj.call("read_group", [domain, yaxis+[xaxis[0]], [xaxis[0]]], {context: context}).pipe(function(res) { + return obj.call("read_group", [domain, yaxis.concat([xaxis[0]]), [xaxis[0]]], {context: context}).pipe(function(res) { _.each(res, function(record) { result.push({ 'data': [[_convert(xaxis[0], record[xaxis[0]]), record[yaxis[0]]]], @@ -323,14 +322,12 @@ instance.web_graph.GraphView = instance.web.View.extend({ } else if ((! stacked) || (xaxis.length < 2)) { var defs = []; _.each(xaxis, function(x) { - defs.push(obj.call("read_group", [domain, yaxis+[x], [x]], {context: context}).pipe(function(res) { + defs.push(obj.call("read_group", [domain, yaxis.concat([x]), [x]], {context: context}).pipe(function(res) { return [x, res]; })); }); return $.when.apply($, defs).pipe(function() { _.each(_.toArray(arguments), function(res) { - // TODO: must convert res - debugger; var x = res[0]; res = res[1]; result.push({ @@ -343,24 +340,22 @@ instance.web_graph.GraphView = instance.web.View.extend({ }); } else { xaxis.reverse(); - return obj.call("read_group", [domain, yaxis + xaxis.slice(0, 1), xaxis.slice(0, 1)], {context: context}).pipe(function(axis) { + return obj.call("read_group", [domain, yaxis.concat(xaxis.slice(0, 1)), xaxis.slice(0, 1)], {context: context}).pipe(function(axis) { var defs = []; _.each(axis, function(x) { var key = x[xaxis[0]] - defs.push(obj.call("read_group", [domain+[(xaxis[0],'=',_convert_key(xaxis[0], key))], yaxis + xaxis.slice(1, 2), xaxis.slice(1, 2)], + defs.push(obj.call("read_group", [domain+[(xaxis[0],'=',_convert_key(xaxis[0], key))], yaxis.concat(xaxis.slice(1, 2)), xaxis.slice(1, 2)], {context: context}).pipe(function(res) { return [x, key, res]; })); }); return $.when.apply($, defs).pipe(function(res) { - // TODO: must convert res - debugger; 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]] or 0); + return _orientation(_convert(xaxis[1], record[xaxis[1]]), record[yaxis[0]] || 0); }), 'label': _convert(xaxis[0], key, false) }) From f1e8ad572e31d78376976aab1a9a48526715fec0 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 23 Oct 2012 17:16:15 +0200 Subject: [PATCH 3/6] fixed problem with some other bar chart bzr revid: nicolas.vanhoren@openerp.com-20121023151615-ptv4was339w13li6 --- addons/web_graph/static/src/js/graph.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 3b4a29bc55a..aceb02cdc61 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -344,8 +344,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ var defs = []; _.each(axis, function(x) { var key = x[xaxis[0]] - defs.push(obj.call("read_group", [domain+[(xaxis[0],'=',_convert_key(xaxis[0], key))], yaxis.concat(xaxis.slice(1, 2)), xaxis.slice(1, 2)], - {context: context}).pipe(function(res) { + defs.push(obj.call("read_group", [new instance.web.CompoundDomain(domain, [[xaxis[0], '=' ,_convert_key(xaxis[0], key)]]), + yaxis.concat(xaxis.slice(1, 2)), xaxis.slice(1, 2)], {context: context}).pipe(function(res) { return [x, key, res]; })); }); From 4014421326ddd6935a598c1e62505ff5c6708761 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 23 Oct 2012 17:17:40 +0200 Subject: [PATCH 4/6] Regression with bar charts bzr revid: nicolas.vanhoren@openerp.com-20121023151740-20xaros930r9806p --- addons/web_graph/static/src/js/graph.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index aceb02cdc61..4e4dd98be9b 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -349,16 +349,18 @@ instance.web_graph.GraphView = instance.web.View.extend({ return [x, key, res]; })); }); - return $.when.apply($, defs).pipe(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) - }) + return $.when.apply($, defs).pipe(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) + }) + }); }); }); } From fa11c31eaea1168dbbb79c2646eb75c7458846f4 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 23 Oct 2012 17:26:46 +0200 Subject: [PATCH 5/6] Removed server-side implementation bzr revid: nicolas.vanhoren@openerp.com-20121023152646-ju42b5dzmckfzi5a --- addons/web_graph/__init__.py | 1 - addons/web_graph/controllers/__init__.py | 1 - addons/web_graph/controllers/graph.py | 92 ------------------------ 3 files changed, 94 deletions(-) delete mode 100644 addons/web_graph/controllers/__init__.py delete mode 100644 addons/web_graph/controllers/graph.py diff --git a/addons/web_graph/__init__.py b/addons/web_graph/__init__.py index ee5959455ad..e69de29bb2d 100644 --- a/addons/web_graph/__init__.py +++ b/addons/web_graph/__init__.py @@ -1 +0,0 @@ -import controllers diff --git a/addons/web_graph/controllers/__init__.py b/addons/web_graph/controllers/__init__.py deleted file mode 100644 index 7f317cca530..00000000000 --- a/addons/web_graph/controllers/__init__.py +++ /dev/null @@ -1 +0,0 @@ -import graph diff --git a/addons/web_graph/controllers/graph.py b/addons/web_graph/controllers/graph.py deleted file mode 100644 index 21ec7d6e973..00000000000 --- a/addons/web_graph/controllers/graph.py +++ /dev/null @@ -1,92 +0,0 @@ -# -*- coding: utf-8 -*- -import openerp - -from lxml import etree - -class GraphView(openerp.addons.web.controllers.main.View): - _cp_path = '/web_graph/graph' - - @openerp.addons.web.http.jsonrequest - def data_get(self, req, model=None, domain=[], context={}, group_by=[], view_id=False, orientation=False, stacked=False, mode="bar", **kwargs): - obj = req.session.model(model) - - res = obj.fields_view_get(view_id, 'graph') - fields = res['fields'] - toload = filter(lambda x: x not in fields, group_by) - if toload: - fields.update( obj.fields_get(toload, context) ) - - tree = etree.fromstring(res['arch']) - - pos = 0 - xaxis = group_by or [] - yaxis = [] - for field in tree.iter(tag='field'): - if (field.tag != 'field') or (not field.get('name')): - continue - assert field.get('name'), "This tag must have a 'name' attribute." - if (not group_by) and ((not pos) or field.get('group')): - xaxis.append(field.get('name')) - if pos and not field.get('group'): - yaxis.append(field.get('name')) - pos += 1 - - assert len(xaxis), "No field for the X axis!" - assert len(yaxis), "No field for the Y axis!" - - # Convert a field's data into a displayable string - - ticks = {} - def _convert_key(field, data): - if fields[field]['type']=='many2one': - data = data and data[0] - return data - - def _convert(field, data, tick=True): - if fields[field]['type']=='many2one': - data = data and data[1] - elif (fields[field]['type']=='selection') and (type(fields[field]['selection']) in (list, tuple)): - d = dict(fields[field]['selection']) - data = d[data] - if tick: - return ticks.setdefault(data, len(ticks)) - return data or 0 - - def _orientation(x, y): - if not orientation: - return (x,y) - return (y,x) - - result = [] - if mode=="pie": - res = obj.read_group(domain, yaxis+[xaxis[0]], [xaxis[0]], context=context) - for record in res: - result.append( { - 'data': [(_convert(xaxis[0], record[xaxis[0]]), record[yaxis[0]])], - 'label': _convert(xaxis[0], record[xaxis[0]], tick=False) - }) - - elif (not stacked) or (len(xaxis)<2): - for x in xaxis: - res = obj.read_group(domain, yaxis+[x], [x], context=context) - result.append( { - 'data': map(lambda record: _orientation(_convert(x, record[x]), record[yaxis[0]] or 0), res), - 'label': fields[x]['string'] - }) - else: - xaxis.reverse() - axis = obj.read_group(domain, yaxis+xaxis[0:1], xaxis[0:1], context=context) - for x in axis: - key = x[xaxis[0]] - res = obj.read_group(domain+[(xaxis[0],'=',_convert_key(xaxis[0], key))], yaxis+xaxis[1:2], xaxis[1:2], context=context) - result.append( { - 'data': map(lambda record: _orientation(_convert(xaxis[1], record[xaxis[1]]), record[yaxis[0]] or 0), res), - 'label': _convert(xaxis[0], key, tick=False) - }) - - res = { - 'data': result, - 'ticks': map(lambda x: (x[1], x[0]), ticks.items()) - } - return res - From 1480c7508a9353c7f77b843c39f5a17efa8bf27f Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 23 Oct 2012 17:38:01 +0200 Subject: [PATCH 6/6] Now uses official formatting method bzr revid: nicolas.vanhoren@openerp.com-20121023153801-l98x0dtpyh6l8vjm --- addons/web_graph/static/src/js/graph.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 4e4dd98be9b..df26e6fc123 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -287,15 +287,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ function _convert(field, data, tick) { tick = tick === undefined ? true : false; - if (fields[field]['type'] === 'many2one') { - data = data && data[1]; - } else if ((fields[field]['type'] === 'selection') && (fields[field]['selection'] instanceof Array)) { - var d = {}; - _.each(fields[field]['selection'], function(el) { - d[el[0]] = el[1]; - }); - data = d[data]; - } + data = instance.web.format_value(data, fields[field]); if (tick) { if (ticks[data] === undefined) ticks[data] = _.size(ticks);