Skip to content

WIP: Multiple y-axis formatting #6320

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

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
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
Diff view
1 change: 1 addition & 0 deletions src/plot_api/subroutines.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function lsInner(gd) {
function getLinePosition(ax, counterAx, side) {
var lwHalf = ax._lw / 2;
var xshift = ax.position > 0 ? 0 : ax._xshift;
xshift = (xshift == undefined) ? 0 : xshift;

if(ax._id.charAt(0) === 'x') {
if(!counterAx) return gs.t + gs.h * (1 - (ax.position || 0)) + (lwHalf % 1);
Expand Down
31 changes: 28 additions & 3 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2318,7 +2318,6 @@ axes.drawOne = function(gd, ax, opts, allDepths) {
if(!mainPlotinfo) return;

var mainAxLayer = mainPlotinfo[axLetter + 'axislayer'];
var mainLinePosition = ax._mainLinePosition;
var mainMirrorPosition = ax._mainMirrorPosition;

var vals = ax._vals = axes.calcTicks(ax);
Expand All @@ -2345,12 +2344,20 @@ axes.drawOne = function(gd, ax, opts, allDepths) {
// to determine how much to shift this one out by
// TODO: Also need to account for the expected depth of the current axis
// (if drawing from the left inwards)
if(axLetter === 'y') {
if(axLetter === 'y' & !ax.position > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if understand the statement here.
!ax.position would be true or false and we are comparing it to be greater than zero?
Let's rewrite this statement.

ax._xshift = allDepths[ax.side];
} else {
ax._xshift = null;
ax._xshift = 0;
}

var mainLinePosition;
if (ax._xshift > 0){
// Calculate main line position from function
mainLinePosition = getLinePosition(ax, ax._anchorAxis, ax.side)
} else {
mainLinePosition = ax._mainLinePosition;
}

// calcLabelLevelBbox can be expensive,
// so make sure to not call it twice during the same Axes.drawOne call
// by stashing label-level bounding boxes per tick-label class
Expand Down Expand Up @@ -4240,3 +4247,21 @@ function hideCounterAxisInsideTickLabels(ax, opts) {
}
}
}

// Copied over from subroutines.js since I want to calculate the line position when
// drawing each y-axis if there is an xshift to be applied
// TODO: Possible to reference this from subroutines.js directly or put the function in some general utils file?
function getLinePosition(ax, counterAx, side) {
var lwHalf = ax._lw / 2;
var xshift = ax.position > 0 ? 0 : ax._xshift;
xshift = (xshift == undefined) ? 0 : xshift;

if(ax._id.charAt(0) === 'x') {
if(!counterAx) return gs.t + gs.h * (1 - (ax.position || 0)) + (lwHalf % 1);
else if(side === 'top') return counterAx._offset - lwHalf;
return counterAx._offset + counterAx._length + lwHalf;
}
if(!counterAx) return gs.l + gs.w * (ax.position || 0) + (lwHalf % 1) + xshift;
else if(side === 'right') return counterAx._offset + counterAx._length + lwHalf + xshift;
return counterAx._offset - lwHalf - xshift;
}
14 changes: 9 additions & 5 deletions test/image/mocks/z-multiple-yaxes-simple.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,34 +91,38 @@
"text": "yaxis title"

},
"automargin": true
"showline": true
},
"yaxis2": {
"title": {"text": "yaxis2 title"},
"overlaying": "y"
"overlaying": "y",
"showline": true
},
"yaxis3": {
"title": {
"text": "yaxis3 title"

},
"overlaying": "y"
"overlaying": "y",
"showline": true
},
"yaxis4": {
"title": {
"text": "yaxis4 title"

},
"overlaying": "y",
"side": "right"
"side": "right",
"showline": true
},
"yaxis5": {
"title": {
"text": "yaxis5 title"

},
"overlaying": "y",
"side": "right"
"side": "right",
"showline": true
}
}
}