Skip to content

Commit e63e65a

Browse files
committed
separate hide function
1 parent 60fe3d2 commit e63e65a

File tree

3 files changed

+35
-28
lines changed

3 files changed

+35
-28
lines changed

src/plots/cartesian/axes.js

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,9 +2184,7 @@ axes.drawOne = function(gd, ax, opts) {
21842184
labelFns: axes.makeLabelFns(ax, mainLinePosition)
21852185
};
21862186

2187-
if(ax._anchorAxis) {
2188-
opts.grid = plotinfo.gridlayer.select('.' + ax._anchorAxis._id);
2189-
}
2187+
opts.grid = plotinfo.gridlayer.select('.' + ax._id);
21902188

21912189
return axes.drawLabels(gd, ax, opts);
21922190
});
@@ -3047,9 +3045,8 @@ axes.drawLabels = function(gd, ax, opts) {
30473045
});
30483046
}
30493047

3050-
ax._hideOutOfRangeInsideTickLabels = undefined;
3051-
if((ax.ticklabelposition || '').indexOf('inside') !== -1) {
3052-
ax._hideOutOfRangeInsideTickLabels = function() {
3048+
ax._hideOutOfRangeInsideTickLabels = function() {
3049+
if((ax.ticklabelposition || '').indexOf('inside') !== -1) {
30533050
var rl = Lib.simpleMap(ax.range, ax.r2l);
30543051

30553052
// hide inside tick labels that go outside axis end points
@@ -3087,24 +3084,30 @@ axes.drawLabels = function(gd, ax, opts) {
30873084
} // TODO: hide mathjax?
30883085
});
30893086

3090-
var anchorAx = ax._anchorAxis || {};
3091-
3092-
if((anchorAx.ticklabelposition || '').indexOf('inside') !== -1) {
3093-
var grid = opts.grid;
3094-
if(grid) {
3095-
grid.each(function() {
3096-
d3.select(this).selectAll('path').each(function(d) {
3097-
var q = anchorAx.l2p(d.x) + anchorAx._offset;
3087+
if(ax._anchorAxis) {
3088+
ax._anchorAxis._visibleLabelMin = visibleLabelMin;
3089+
ax._anchorAxis._visibleLabelMax = visibleLabelMax;
3090+
}
3091+
}
3092+
};
30983093

3099-
if(q < visibleLabelMax && q > visibleLabelMin) {
3100-
d3.select(this).style({ opacity: 0 });
3101-
}
3102-
});
3094+
ax._hideCounterAxisInsideTickLabels = function() {
3095+
var anchorAx = ax._anchorAxis || {};
3096+
if((anchorAx.ticklabelposition || '').indexOf('inside') !== -1) {
3097+
var grid = opts.grid;
3098+
if(grid) {
3099+
grid.each(function() {
3100+
d3.select(this).selectAll('path').each(function(d) {
3101+
var q = ax.l2p(d.x) + ax._offset;
3102+
3103+
if(q < ax._visibleLabelMax && q > ax._visibleLabelMin) {
3104+
d3.select(this).style({ opacity: 0 });
3105+
}
31033106
});
3104-
}
3107+
});
31053108
}
3106-
};
3107-
}
3109+
}
3110+
};
31083111

31093112
// make sure all labels are correctly positioned at their base angle
31103113
// the positionLabels call above is only for newly drawn labels.

src/plots/plots.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,17 +2076,21 @@ plots.doAutoMargin = function(gd) {
20762076
}
20772077
}
20782078

2079-
hideOutOfRangeInsideTickLabels(gd);
2079+
hideInsideTickLabels(gd);
20802080
};
20812081

2082-
function hideOutOfRangeInsideTickLabels(gd) {
2082+
function hideInsideTickLabels(gd) {
20832083
var axList = axisIDs.list(gd, '', true);
2084-
for(var i = 0; i < axList.length; i++) {
2085-
var ax = axList[i];
20862084

2087-
var hideFn = ax._hideOutOfRangeInsideTickLabels;
2088-
if(hideFn) hideFn();
2089-
}
2085+
[
2086+
'_hideOutOfRangeInsideTickLabels',
2087+
'_hideCounterAxisInsideTickLabels'
2088+
].forEach(function(k) {
2089+
for(var i = 0; i < axList.length; i++) {
2090+
var hideFn = axList[i][k];
2091+
if(hideFn) hideFn();
2092+
}
2093+
});
20902094
}
20912095

20922096
var marginKeys = ['l', 'r', 't', 'b', 'p', 'w', 'h'];
-2.72 KB
Loading

0 commit comments

Comments
 (0)