Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix axis line width, length, and positioning for coupled subplots #1854

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 13 commits into from
Jul 14, 2017
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
Diff view
Prev Previous commit
Next Next commit
un-nest new lsInner helper functions
  • Loading branch information
alexcjohnson committed Jul 13, 2017
commit b31e60d3380122ec01e01c1cd5ffb51ab89d0207
132 changes: 66 additions & 66 deletions src/plot_api/subroutines.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,6 @@ exports.lsInner = function(gd) {
.call(Drawing.setTranslate, xa._offset, ya._offset)
.call(Drawing.setClipUrl, plotinfo.clipId);

function shouldShowLine(ax, counterAx, side) {
return (ax.anchor === counterAx._id && (ax.mirror || ax.side === side)) ||
ax.mirror === 'all' || ax.mirror === 'allticks' ||
(ax.mirrors && ax.mirrors[counterAx._id + side]);
}

var xIsFree = xa.anchor === 'free';
var showFreeX = xIsFree && !freeFinished[xa._id];
var showBottom = shouldShowLine(xa, ya, 'bottom');
Expand All @@ -191,62 +185,6 @@ exports.lsInner = function(gd) {
var xlw = Drawing.crispRound(gd, xa.linewidth, 1);
var ylw = Drawing.crispRound(gd, ya.linewidth, 1);

function findMainAxis(ax) {
return ax.overlaying ? Plotly.Axes.getFromId(gd, ax.overlaying) : ax;
}

function findCounterAxes(ax) {
var counterAxes = [];
var anchorAx = Plotly.Axes.getFromId(gd, ax.anchor);
if(anchorAx) {
var counterMain = findMainAxis(anchorAx);
if(counterAxes.indexOf(counterMain) === -1) {
counterAxes.push(counterMain);
}
for(var i = 0; i < axList.length; i++) {
if(axList[i].overlaying === counterMain._id &&
counterAxes.indexOf(axList[i]) === -1
) {
counterAxes.push(axList[i]);
}
}
}
return counterAxes;
}

function findLineWidth(axes, side) {
for(var i = 0; i < axes.length; i++) {
var ax = axes[i];
if(ax.anchor !== 'free' && shouldShowLine(ax, {_id: ax.anchor}, side)) {
return Drawing.crispRound(gd, ax.linewidth);
}
}
}

function findCounterAxisLineWidth(ax, subplotCounterLineWidth,
subplotCounterIsShown, side) {
if(subplotCounterIsShown) return subplotCounterLineWidth;

var i;

// find all counteraxes for this one, then of these, find the
// first one that has a visible line on this side
var mainAxis = findMainAxis(ax);
var counterAxes = findCounterAxes(mainAxis);

var lineWidth = findLineWidth(counterAxes, side);
if(lineWidth) return lineWidth;

for(i = 0; i < axList.length; i++) {
if(axList[i].overlaying === mainAxis._id) {
counterAxes = findCounterAxes(axList[i]);
lineWidth = findLineWidth(counterAxes, side);
if(lineWidth) return lineWidth;
}
}
return 0;
}

/*
* x lines get longer where they meet y lines, to make a crisp corner
* free x lines are not excluded - they don't necessarily *meet* the
Expand All @@ -261,8 +199,8 @@ exports.lsInner = function(gd) {
* ------
* ^ x2
*/
var xLinesXLeft = -pad - findCounterAxisLineWidth(xa, ylw, showLeft, 'left');
var xLinesXRight = xa._length + pad + findCounterAxisLineWidth(xa, ylw, showRight, 'right');
var xLinesXLeft = -pad - findCounterAxisLineWidth(gd, xa, ylw, showLeft, 'left', axList);
var xLinesXRight = xa._length + pad + findCounterAxisLineWidth(gd, xa, ylw, showRight, 'right', axList);
var xLinesYFree = gs.h * (1 - (xa.position || 0)) + ((xlw / 2) % 1);
var xLinesYBottom = ya._length + pad + xlw / 2;
var xLinesYTop = -pad - xlw / 2;
Expand All @@ -283,10 +221,10 @@ exports.lsInner = function(gd) {
* seem worth adding a lot of complexity for.
*/
var yLinesYBottom = ya._length + pad + (yIsFree ?
findCounterAxisLineWidth(ya, xlw, showBottom, 'bottom') :
findCounterAxisLineWidth(gd, ya, xlw, showBottom, 'bottom', axList) :
0);
var yLinesYTop = -pad - (yIsFree ?
findCounterAxisLineWidth(ya, xlw, showTop, 'top') :
findCounterAxisLineWidth(gd, ya, xlw, showTop, 'top', axList) :
0);
var yLinesXFree = gs.w * (ya.position || 0) + ((ylw / 2) % 1);
var yLinesXLeft = -pad - ylw / 2;
Expand Down Expand Up @@ -390,6 +328,68 @@ exports.lsInner = function(gd) {
return gd._promises.length && Promise.all(gd._promises);
};

function shouldShowLine(ax, counterAx, side) {
return (ax.anchor === counterAx._id && (ax.mirror || ax.side === side)) ||
ax.mirror === 'all' || ax.mirror === 'allticks' ||
(ax.mirrors && ax.mirrors[counterAx._id + side]);
}

function findMainAxis(gd, ax) {
return ax.overlaying ? Plotly.Axes.getFromId(gd, ax.overlaying) : ax;
}

function findCounterAxes(gd, ax, axList) {
var counterAxes = [];
var anchorAx = Plotly.Axes.getFromId(gd, ax.anchor);
if(anchorAx) {
var counterMain = findMainAxis(gd, anchorAx);
if(counterAxes.indexOf(counterMain) === -1) {
counterAxes.push(counterMain);
}
for(var i = 0; i < axList.length; i++) {
if(axList[i].overlaying === counterMain._id &&
counterAxes.indexOf(axList[i]) === -1
) {
counterAxes.push(axList[i]);
}
}
}
return counterAxes;
}

function findLineWidth(gd, axes, side) {
for(var i = 0; i < axes.length; i++) {
var ax = axes[i];
if(ax.anchor !== 'free' && shouldShowLine(ax, {_id: ax.anchor}, side)) {
return Drawing.crispRound(gd, ax.linewidth);
}
}
}

function findCounterAxisLineWidth(gd, ax, subplotCounterLineWidth,
subplotCounterIsShown, side, axList) {
if(subplotCounterIsShown) return subplotCounterLineWidth;

var i;

// find all counteraxes for this one, then of these, find the
// first one that has a visible line on this side
var mainAxis = findMainAxis(gd, ax);
var counterAxes = findCounterAxes(gd, mainAxis, axList);

var lineWidth = findLineWidth(gd, counterAxes, side);
if(lineWidth) return lineWidth;

for(i = 0; i < axList.length; i++) {
if(axList[i].overlaying === mainAxis._id) {
counterAxes = findCounterAxes(gd, axList[i], axList);
lineWidth = findLineWidth(gd, counterAxes, side);
if(lineWidth) return lineWidth;
}
}
return 0;
}

exports.drawMainTitle = function(gd) {
var fullLayout = gd._fullLayout;

Expand Down