mistercrunch closed pull request #6282: [nvd3] refactor, thinner margins
URL: https://github.com/apache/incubator-superset/pull/6282
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/superset/assets/src/visualizations/nvd3/NVD3Vis.js 
b/superset/assets/src/visualizations/nvd3/NVD3Vis.js
index 1267b422b8..2b4168de43 100644
--- a/superset/assets/src/visualizations/nvd3/NVD3Vis.js
+++ b/superset/assets/src/visualizations/nvd3/NVD3Vis.js
@@ -295,11 +295,6 @@ function nvd3Vis(element, props) {
           .showControls(showControls)
           .groupSpacing(0.1);
 
-        if (showBarValue) {
-          setTimeout(function () {
-            drawBarValues(svg, data, isBarStacked, yAxisFormat);
-          }, ANIMATION_TIME);
-        }
         if (!reduceXTicks) {
           width = computeBarChartWidth(data, isBarStacked, maxWidth);
         }
@@ -322,14 +317,6 @@ function nvd3Vis(element, props) {
             d.values.sort((a, b) => tryNumify(a.x) < tryNumify(b.x) ? -1 : 1);
           });
         }
-        if (showBarValue) {
-          // Add more margin to avoid label colliding with legend.
-          const top = chart.margin().top;
-          chart.margin({ top: top + 24 });
-          setTimeout(function () {
-            drawBarValues(svg, data, isBarStacked, yAxisFormat);
-          }, ANIMATION_TIME);
-        }
         if (!reduceXTicks) {
           width = computeBarChartWidth(data, isBarStacked, maxWidth);
         }
@@ -362,7 +349,6 @@ function nvd3Vis(element, props) {
             chart.labelType(d => `${d.data.x}: ${((d.data.y / total) * 
100).toFixed()}%`);
           }
         }
-
         break;
 
       case 'column':
@@ -417,6 +403,14 @@ function nvd3Vis(element, props) {
       default:
         throw new Error('Unrecognized visualization for nvd3' + vizType);
     }
+    // Assuming the container has padding already
+    chart.margin({ top: 0, left: 0, right: 0, bottom: 0 });
+
+    if (showBarValue) {
+      setTimeout(function () {
+        drawBarValues(svg, data, isBarStacked, yAxisFormat);
+      }, ANIMATION_TIME);
+    }
 
     if (canShowBrush && onBrushEnd !== NOOP) {
       chart.focus.dispatch.on('brush', (event) => {
@@ -589,19 +583,26 @@ function nvd3Vis(element, props) {
       const marginPad = Math.ceil(
         Math.min(maxWidth * (isExplore ? 0.01 : 0.03), MAX_MARGIN_PAD),
       );
-      const maxYAxisLabelWidth = getMaxLabelSize(svg, chart.yAxis2 ? 'nv-y1' : 
'nv-y');
-      const maxXAxisLabelHeight = getMaxLabelSize(svg, 'nv-x');
-      chart.margin({ left: maxYAxisLabelWidth + marginPad });
-      if (yAxisLabel && yAxisLabel !== '') {
-        chart.margin({ left: maxYAxisLabelWidth + marginPad + 25 });
-      }
       // Hack to adjust margins to accommodate long axis tick labels.
       // - has to be done only after the chart has been rendered once
       // - measure the width or height of the labels
       // ---- (x axis labels are rotated 45 degrees so we use height),
       // - adjust margins based on these measures and render again
       const margins = chart.margin();
-      margins.bottom = 28;
+      if (chart.xAxis) {
+        margins.bottom = 28;
+      }
+      const maxYAxisLabelWidth = getMaxLabelSize(svg, chart.yAxis2 ? 'nv-y1' : 
'nv-y');
+      const maxXAxisLabelHeight = getMaxLabelSize(svg, 'nv-x');
+      margins.left = maxYAxisLabelWidth + marginPad;
+
+      if (yAxisLabel && yAxisLabel !== '') {
+        margins.left += 25;
+      }
+      if (showBarValue) {
+        // Add more margin to avoid label colliding with legend.
+        margins.top += 24;
+      }
       if (xAxisShowMinMax) {
         // If x bounds are shown, we need a right margin
         margins.right = Math.max(20, maxXAxisLabelHeight / 2) + marginPad;
@@ -642,7 +643,6 @@ function nvd3Vis(element, props) {
         }
         chart.yAxis.axisLabel(yAxisLabel).axisLabelDistance(distance);
       }
-
       if (isTimeSeries && annotationData && activeAnnotationLayers.length > 0) 
{
         // Time series annotations add additional data
         const timeSeriesAnnotations = activeAnnotationLayers


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to