From c1534d5b3bae1f028d56968c6941b85c10cbbf8c Mon Sep 17 00:00:00 2001 From: Beto Dealmeida Date: Wed, 9 Jan 2019 15:43:57 -0800 Subject: [PATCH] Improve padding in NVD3Vis (#6626) * WIP, fixing padding * Remove testing code (cherry picked from commit f6ac0daf7e2a0f46542a5d6d5015de71e1f19ede) --- .../assets/src/visualizations/nvd3/NVD3Vis.js | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/superset/assets/src/visualizations/nvd3/NVD3Vis.js b/superset/assets/src/visualizations/nvd3/NVD3Vis.js index cdd938f8936e3..6aef5a3dae3a1 100644 --- a/superset/assets/src/visualizations/nvd3/NVD3Vis.js +++ b/superset/assets/src/visualizations/nvd3/NVD3Vis.js @@ -546,6 +546,14 @@ function nvd3Vis(element, props) { .attr('width', width) .call(chart); + if (xLabelRotation > 0) { + // shift labels to the left so they look better + const xTicks = svg.select('.nv-x.nv-axis > g').selectAll('g'); + xTicks + .selectAll('text') + .attr('dx', -6.5); + } + // align yAxis1 and yAxis2 ticks if (isVizTypes(['dual_line', 'line_multi'])) { const count = chart.yAxis1.ticks(); @@ -612,11 +620,15 @@ function nvd3Vis(element, props) { // If x bounds are shown, we need a right margin margins.right = Math.max(20, maxXAxisLabelHeight / 2) + marginPad; } - if (xLabelRotation === 45) { - margins.bottom = maxXAxisLabelHeight + marginPad; - margins.right = maxXAxisLabelHeight + marginPad; - } else if (staggerLabels) { + if (staggerLabels) { margins.bottom = 40; + } else { + margins.bottom = ( + maxXAxisLabelHeight * Math.sin(Math.PI * xLabelRotation / 180) + ) + marginPad; + margins.right = ( + maxXAxisLabelHeight * Math.cos(Math.PI * xLabelRotation / 180) + ) + marginPad; } if (isVizTypes(['dual_line', 'line_multi'])) {