Skip to content

Commit

Permalink
measure all of the labels and take the max height
Browse files Browse the repository at this point in the history
  • Loading branch information
alanna scott committed Jan 27, 2017
1 parent 5417849 commit 818f0db
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions superset/assets/visualizations/nvd3_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,20 @@ function nvd3Vis(slice, payload) {

// Hack to adjust margins to accomodate long x axis tick labels,
// has to be done only after the chart has been rendered once,
// then we measure the height of the labels (they are rotated 90 degrees),
// then we adjust the bottom margin and render again.
if (isTimeSeries) {
// get height of formatted axis label
const xAxisHeight = $('.nv-x.nv-axis .tick text')[0].getBoundingClientRect().height;
//get height of formatted axis labels
const labelEls = $('.nv-x.nv-axis .tick text');
const labelHeights = labelEls.map((i) => {
return labelEls[i].getBoundingClientRect().height;
});
const xAxisHeight = Math.max.apply(Math, labelHeights);

// set new bottom margin to accomodate labels
chart.margin({ bottom: xAxisHeight + 40 });

//render chart
svg
.datum(payload.data)
.transition().duration(500)
Expand Down

0 comments on commit 818f0db

Please sign in to comment.