Skip to content

Commit

Permalink
[Bug fix] Plotly legend overlaps plot on small screens (when legend c…
Browse files Browse the repository at this point in the history
…licked) (#3976)
  • Loading branch information
kravets-levko authored Jul 13, 2019
1 parent 15a8eec commit 4e9da3f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions client/app/visualizations/chart/plotly/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,14 @@ export function updateLayout(plotlyElement, layout, updatePlot) {
layout.width = Math.floor(plotlyElement.offsetWidth);
layout.height = Math.floor(plotlyElement.offsetHeight);

const transformName = find([
'transform',
'WebkitTransform',
'MozTransform',
'MsTransform',
'OTransform',
], prop => prop in plotlyElement.style);

if (layout.width <= 600) {
// change legend orientation to horizontal; plotly has a bug with this
// legend alignment - it does not preserve enough space under the plot;
Expand Down Expand Up @@ -794,9 +802,9 @@ export function updateLayout(plotlyElement, layout, updatePlot) {
layout.height / 2,
layout.height - (bounds.bottom - bounds.top),
));
updatePlot(plotlyElement, pick(layout, ['height']));
// offset the legend
legend.setAttribute('transform', 'translate(0, ' + layout.height + ')');
legend.style[transformName] = 'translate(0, ' + layout.height + 'px)';
updatePlot(plotlyElement, pick(layout, ['height']));
}
});
} else {
Expand All @@ -809,6 +817,12 @@ export function updateLayout(plotlyElement, layout, updatePlot) {
xanchor: 'left',
yanchor: 'top',
};

const legend = plotlyElement.querySelector('.legend');
if (legend) {
legend.style[transformName] = null;
}

updatePlot(plotlyElement, pick(layout, ['width', 'height', 'legend']));
}
}

0 comments on commit 4e9da3f

Please sign in to comment.