8000 Fix axis automargin push offset by etpinard · Pull Request #3510 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Fix axis automargin push offset #3510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 5, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
Next Next commit
fix axis automargin push offset value
- previously, we consider the ticks + tick labels to start right
  on the edge of the axis line. This is incorrect, there's a slight
  pad between tick labels and ticks that must be taken into account
  to get the correct automargin push
  • Loading branch information
etpinard committed Feb 4, 2019
commit 37f81b8f299bf9bb20a78f14184fce7228e970b3
46 changes: 36 additions & 10 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1940,27 +1940,53 @@ axes.drawOne = function(gd, ax, opts) {
var hasRangeSlider = Registry.getComponentMethod('rangeslider', 'isVisible')(ax);

8000 function doAutoMargins() {
var push, rangeSliderPush;
var s = ax.side.charAt(0);
var push;
var rangeSliderPush;

if(hasRangeSlider) {
rangeSliderPush = Registry.getComponentMethod('rangeslider', 'autoMarginOpts')(gd, ax);
}
Plots.autoMargin(gd, rangeSliderAutoMarginID(ax), rangeSliderPush);

var s = ax.side.charAt(0);
if(ax.automargin && (!hasRangeSlider || s !== 'b')) {
push = {x: 0, y: 0, r: 0, l: 0, t: 0, b: 0};

if(axLetter === 'x') {
push.y = (ax.anchor === 'free' ? ax.position :
ax._anchorAxis.domain[s === 't' ? 1 : 0]);
push[s] += ax._boundingBox.height;
} else {
push.x = (ax.anchor === 'free' ? ax.position :
ax._anchorAxis.domain[s === 'r' ? 1 : 0]);
push[s] += ax._boundingBox.width;
var bbox = ax._boundingBox;
var counterAx = mainPlotinfo[counterLetter + 'axis'];
var anchorAxDomainIndex;
var offset;

switch(axLetter + s) {
case 'xb':
anchorAxDomainIndex = 0;
offset = bbox.top - counterAx._length - counterAx._offset;
push[s] = bbox.height;
break;
case 'xt':
anchorAxDomainIndex = 1;
offset = counterAx._offset - bbox.bottom;
push[s] = bbox.height;
break;
case 'yl':
anchorAxDomainIndex = 0;
offset = counterAx._offset - bbox.right;
push[s] = bbox.width;
break;
case 'yr':
anchorAxDomainIndex = 1;
offset = bbox.left - counterAx._length - counterAx._offset;
push[s] = bbox.width;
break;
}

push[counterLetter] = ax.anchor === 'free' ?
ax.position :
ax._anchorAxis.domain[anchorAxDomainIndex];

if(push[s] > 0) {
push[s] += offset;
}
if(ax.title.text !== fullLayout._dfltTitle[axLetter]) {
push[s] += ax.title.font.size;
}
Expand Down
0