From 59b7dec69c2c84f691f3a7ba362758c3e43ba889 Mon Sep 17 00:00:00 2001 From: Adrien Dieudonne Date: Fri, 12 Oct 2018 12:36:38 +0000 Subject: [FIX] web: line chart x ticks labels overlapp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, we tried to hide some labels depending of the available size of the graph. However, it doesn't worked when the graph is updated. A much simpler solution is to use the scale’s automatic tick generator implemented in D3. So, in this commit, we realized that 'tickValues' is unnecessary because data are passed correctly (see 'svg.datum(data);') and labels are defined in 'ticksLabels'. There is nothing else to do. We had to remove the skipped test because 'renderEnd' is not triggered for line chart. We need to update nv.d3. We already tried to fix this issue in the following commit: https://github.com/odoo-dev/odoo/commit/c4937132a38873761fa0ac0b41c983b917cb52f1 Documentation: https://github.com/d3/d3-axis#axis_tickValues closes odoo/odoo#27828 --- .../static/src/js/views/graph/graph_renderer.js | 28 ---------------------- 1 file changed, 28 deletions(-) (limited to 'addons/web/static/src/js/views/graph/graph_renderer.js') diff --git a/addons/web/static/src/js/views/graph/graph_renderer.js b/addons/web/static/src/js/views/graph/graph_renderer.js index f923ade149b..0517e14c876 100644 --- a/addons/web/static/src/js/views/graph/graph_renderer.js +++ b/addons/web/static/src/js/views/graph/graph_renderer.js @@ -341,7 +341,6 @@ return AbstractRenderer.extend({ var data = []; var ticksLabels = []; - var tickValues = []; var measure = this.state.fields[this.state.measure].string; var values; @@ -363,18 +362,6 @@ return AbstractRenderer.extend({ key: measure + ' (compare)', color: '#ff7f0e', }); - - if (this.state.comparisonData.length > graphData.length) { - tickValues = this.state.comparisonData.map(function (d, i) { - return i; - }); - } - } - - if (!tickValues.length) { - tickValues = graphData.map(function (d, i) { - return i; - }); } for (i = 0; i < graphData.length; i++) { @@ -403,7 +390,6 @@ return AbstractRenderer.extend({ for (var i = 0; i < this.state.data.length; i++) { if (graphData[i].labels[0] !== tickLabel) { tickLabel = this.state.data[i].labels[0]; - tickValues.push(tick); ticksLabels.push(tickLabel); tick++; } @@ -438,7 +424,6 @@ return AbstractRenderer.extend({ }); chart.forceY([0]); chart.xAxis - .tickValues(tickValues) .tickFormat(function (d) { return ticksLabels[d]; }); @@ -491,19 +476,6 @@ return AbstractRenderer.extend({ $('.nv-y .tick > line').attr('x2', function (i, value) { return Math.abs(value); }); - - // We don't need to show all labels - $('.o_graph_svg_container svg .nv-x g.tick > text').show(); - var $ticksText = $('svg .nv-x g.tick:not(.zero) > text'); - var ticksLength = $ticksText.length; - var tickTextMargin = 5; - if (ticksLength) { - var tickWidth = $ticksText[0].getBBox().width + tickTextMargin; - var svgWidth = $('.o_graph_svg_container').width(); - var keepOneOf = Math.ceil(ticksLength / (svgWidth / tickWidth)); - // FIXME: should work with two line charts - $('.o_graph_svg_container svg .nv-x g.tick:not(:nth-child(' + keepOneOf + 'n+1)) > text').hide(); - } }) chartResize(chart); -- cgit v1.2.3