Skip to content

Commit c7d833f

Browse files
committed
fix #2434 - handle ax.automargin + ax.mirror cases
... by registering a mirror-specific push-margin id. Note that to handle the 'all' and 'allticks', we use ax._counterDomain(Min|Max) added previously.
1 parent 0268055 commit c7d833f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/plots/cartesian/axes.js

+21
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var BADNUM = constants.BADNUM;
3434

3535
var MID_SHIFT = require('../../constants/alignment').MID_SHIFT;
3636
var LINE_SPACING = require('../../constants/alignment').LINE_SPACING;
37+
var OPPOSITE_SIDE = require('../../constants/alignment').OPPOSITE_SIDE;
3738

3839
var axes = module.exports = {};
3940

@@ -1863,11 +1864,13 @@ axes.drawOne = function(gd, ax, opts) {
18631864

18641865
seq.push(function() {
18651866
var s = ax.side.charAt(0);
1867+
var sMirror = OPPOSITE_SIDE[ax.side].charAt(0);
18661868
var pos = axes.getPxPosition(gd, ax);
18671869
var outsideTickLen = ax.ticks === 'outside' ? ax.ticklen : 0;
18681870
var llbbox;
18691871

18701872
var push;
1873+
var mirrorPush;
18711874
var rangeSliderPush;
18721875

18731876
if(ax.automargin || hasRangeSlider) {
@@ -1935,13 +1938,27 @@ axes.drawOne = function(gd, ax, opts) {
19351938
if(ax.title.text !== fullLayout._dfltTitle[axLetter]) {
19361939
push[s] += ax.title.font.size;
19371940
}
1941+
1942+
if(ax.mirror) {
1943+
mirrorPush = {x: 0, y: 0, r: 0, l: 0, t: 0, b: 0};
1944+
1945+
mirrorPush[sMirror] = ax.linewidth;
1946+
if(ax.mirror && ax.mirror !== true) mirrorPush[sMirror] += outsideTickLen;
1947+
1948+
if(ax.mirror === true || ax.mirror === 'ticks') {
1949+
mirrorPush[counterLetter] = ax._anchorAxis.domain[domainIndices[1]];
1950+
} else if(ax.mirror === 'all' || ax.mirror === 'allticks') {
1951+
mirrorPush[counterLetter] = [ax._counterDomainMin, ax._counterDomainMax][domainIndices[1]];
1952+
}
1953+
}
19381954
}
19391955

19401956
if(hasRangeSlider) {
19411957
rangeSliderPush = Registry.getComponentMethod('rangeslider', 'autoMarginOpts')(gd, ax);
19421958
}
19431959

19441960
Plots.autoMargin(gd, axAutoMarginID(ax), push);
1961+
Plots.autoMargin(gd, axMirrorAutoMarginID(ax), mirrorPush);
19451962
Plots.autoMargin(gd, rangeSliderAutoMarginID(ax), rangeSliderPush);
19461963
});
19471964

@@ -2839,6 +2856,9 @@ axes.allowAutoMargin = function(gd) {
28392856
var ax = axList[i];
28402857
if(ax.automargin) {
28412858
Plots.allowAutoMargin(gd, axAutoMarginID(ax));
2859+
if(ax.mirror) {
2860+
Plots.allowAutoMargin(gd, axMirrorAutoMarginID(ax));
2861+
}
28422862
}
28432863
if(Registry.getComponentMethod('rangeslider', 'isVisible')(ax)) {
28442864
Plots.allowAutoMargin(gd, rangeSliderAutoMarginID(ax));
@@ -2847,6 +2867,7 @@ axes.allowAutoMargin = function(gd) {
28472867
};
28482868

28492869
function axAutoMarginID(ax) { return ax._id + '.automargin'; }
2870+
function axMirrorAutoMarginID(ax) { return axAutoMarginID(ax) + '.mirror'; }
28502871
function rangeSliderAutoMarginID(ax) { return ax._id + '.rangeslider'; }
28512872

28522873
// swap all the presentation attributes of the axes showing these traces

0 commit comments

Comments
 (0)