Skip to content

Commit 37f81b8

Browse files
committed
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
1 parent 84e24aa commit 37f81b8

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

src/plots/cartesian/axes.js

+36-10
Original file line numberDiff line numberDiff line change
@@ -1940,27 +1940,53 @@ axes.drawOne = function(gd, ax, opts) {
19401940
var hasRangeSlider = Registry.getComponentMethod('rangeslider', 'isVisible')(ax);
19411941

19421942
function doAutoMargins() {
1943-
var push, rangeSliderPush;
1943+
var s = ax.side.charAt(0);
1944+
var push;
1945+
var rangeSliderPush;
19441946

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

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

1954-
if(axLetter === 'x') {
1955-
push.y = (ax.anchor === 'free' ? ax.position :
1956-
ax._anchorAxis.domain[s === 't' ? 1 : 0]);
1957-
push[s] += ax._boundingBox.height;
1958-
} else {
1959-
push.x = (ax.anchor === 'free' ? ax.position :
1960-
ax._anchorAxis.domain[s === 'r' ? 1 : 0]);
1961-
push[s] += ax._boundingBox.width;
1955+
var bbox = ax._boundingBox;
1956+
var counterAx = mainPlotinfo[counterLetter + 'axis'];
1957+
var anchorAxDomainIndex;
1958+
var offset;
1959+
1960+
switch(axLetter + s) {
1961+
case 'xb':
1962+
anchorAxDomainIndex = 0;
1963+
offset = bbox.top - counterAx._length - counterAx._offset;
1964+
push[s] = bbox.height;
1965+
break;
1966+
case 'xt':
1967+
anchorAxDomainIndex = 1;
1968+
offset = counterAx._offset - bbox.bottom;
1969+
push[s] = bbox.height;
1970+
break;
1971+
case 'yl':
1972+
anchorAxDomainIndex = 0;
1973+
offset = counterAx._offset - bbox.right;
1974+
push[s] = bbox.width;
1975+
break;
1976+
case 'yr':
1977+
anchorAxDomainIndex = 1;
1978+
offset = bbox.left - counterAx._length - counterAx._offset;
1979+
push[s] = bbox.width;
1980+
break;
19621981
}
19631982

1983+
push[counterLetter] = ax.anchor === 'free' ?
1984+
ax.position :
1985+
ax._anchorAxis.domain[anchorAxDomainIndex];
1986+
1987+
if(push[s] > 0) {
1988+
push[s] += offset;
1989+
}
19641990
if(ax.title.text !== fullLayout._dfltTitle[axLetter]) {
19651991
push[s] += ax.title.font.size;
19661992
}

0 commit comments

Comments
 (0)