Skip to content

Commit

Permalink
fix #2434 - handle ax.automargin + ax.mirror cases
Browse files Browse the repository at this point in the history
... by registering a mirror-specific push-margin id.
    Note that to handle the 'all' and 'allticks', we use
    ax._counterDomain(Min|Max) added previously.
  • Loading branch information
etpinard committed Sep 4, 2019
1 parent 0268055 commit c7d833f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var BADNUM = constants.BADNUM;

var MID_SHIFT = require('../../constants/alignment').MID_SHIFT;
var LINE_SPACING = require('../../constants/alignment').LINE_SPACING;
var OPPOSITE_SIDE = require('../../constants/alignment').OPPOSITE_SIDE;

var axes = module.exports = {};

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

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

var push;
var mirrorPush;
var rangeSliderPush;

if(ax.automargin || hasRangeSlider) {
Expand Down Expand Up @@ -1935,13 +1938,27 @@ axes.drawOne = function(gd, ax, opts) {
if(ax.title.text !== fullLayout._dfltTitle[axLetter]) {
push[s] += ax.title.font.size;
}

if(ax.mirror) {
mirrorPush = {x: 0, y: 0, r: 0, l: 0, t: 0, b: 0};

mirrorPush[sMirror] = ax.linewidth;
if(ax.mirror && ax.mirror !== true) mirrorPush[sMirror] += outsideTickLen;

if(ax.mirror === true || ax.mirror === 'ticks') {
mirrorPush[counterLetter] = ax._anchorAxis.domain[domainIndices[1]];
} else if(ax.mirror === 'all' || ax.mirror === 'allticks') {
mirrorPush[counterLetter] = [ax._counterDomainMin, ax._counterDomainMax][domainIndices[1]];
}
}
}

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

Plots.autoMargin(gd, axAutoMarginID(ax), push);
Plots.autoMargin(gd, axMirrorAutoMarginID(ax), mirrorPush);
Plots.autoMargin(gd, rangeSliderAutoMarginID(ax), rangeSliderPush);
});

Expand Down Expand Up @@ -2839,6 +2856,9 @@ axes.allowAutoMargin = function(gd) {
var ax = axList[i];
if(ax.automargin) {
Plots.allowAutoMargin(gd, axAutoMarginID(ax));
if(ax.mirror) {
Plots.allowAutoMargin(gd, axMirrorAutoMarginID(ax));
}
}
if(Registry.getComponentMethod('rangeslider', 'isVisible')(ax)) {
Plots.allowAutoMargin(gd, rangeSliderAutoMarginID(ax));
Expand All @@ -2847,6 +2867,7 @@ axes.allowAutoMargin = function(gd) {
};

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

// swap all the presentation attributes of the axes showing these traces
Expand Down

0 comments on commit c7d833f

Please sign in to comment.