-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Implement ticklabeloverflow to improve control over display of tick labels #5584
Changes from 10 commits
6f0b5d9
1d5560b
f86bc37
7580842
e478e0d
adaea01
e4a13b3
e49fc41
8d5da73
51642ad
cd256f2
71e24eb
c9eaff2
f833ce4
0deec98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3013,8 +3013,6 @@ axes.drawLabels = function(gd, ax, opts) { | |
} | ||
|
||
function positionLabels(s, angle) { | ||
var isInside = insideTicklabelposition(ax); | ||
|
||
s.each(function(d) { | ||
var thisLabel = d3.select(this); | ||
var mathjaxGroup = thisLabel.select('.text-math-group'); | ||
|
@@ -3042,12 +3040,10 @@ axes.drawLabels = function(gd, ax, opts) { | |
'text-anchor': anchor | ||
}); | ||
|
||
if(isInside) { | ||
thisText.style('opacity', 1); // visible | ||
thisText.style('opacity', 1); // visible | ||
|
||
if(ax._hideOutOfRangeInsideTickLabels) { | ||
ax._hideOutOfRangeInsideTickLabels(); | ||
} | ||
if(ax._adjustTickLabelsOverflow) { | ||
ax._adjustTickLabelsOverflow(); | ||
} | ||
} else { | ||
var mjWidth = Drawing.bBox(mathjaxGroup.node()).width; | ||
|
@@ -3057,63 +3053,81 @@ axes.drawLabels = function(gd, ax, opts) { | |
}); | ||
} | ||
|
||
ax._hideOutOfRangeInsideTickLabels = function() { | ||
if(insideTicklabelposition(ax)) { | ||
ax._adjustTickLabelsOverflow = function() { | ||
var ticklabeloverflow = ax.ticklabeloverflow; | ||
if(!ticklabeloverflow || ticklabeloverflow === 'allow') return; | ||
|
||
var hideOverflow = ticklabeloverflow.indexOf('hide') !== -1; | ||
// var pushOverflow = ticklabeloverflow.indexOf('push') !== -1; | ||
|
||
var isX = ax._id.charAt(0) === 'x'; | ||
// div positions | ||
var p0 = 0; | ||
var p1 = isX ? | ||
gd._fullLayout.width : | ||
gd._fullLayout.height; | ||
|
||
if(ticklabeloverflow.indexOf('domain') !== -1) { | ||
// domain positions | ||
var rl = Lib.simpleMap(ax.range, ax.r2l); | ||
p0 = ax.l2p(rl[0]) + ax._offset; | ||
p1 = ax.l2p(rl[1]) + ax._offset; | ||
} | ||
|
||
// hide inside tick labels that go outside axis end points | ||
var p0 = ax.l2p(rl[0]); | ||
var p1 = ax.l2p(rl[1]); | ||
var min = Math.min(p0, p1); | ||
var max = Math.max(p0, p1); | ||
|
||
var min = Math.min(p0, p1) + ax._offset; | ||
var max = Math.max(p0, p1) + ax._offset; | ||
var side = ax.side; | ||
|
||
var side = ax.side; | ||
var isX = ax._id.charAt(0) === 'x'; | ||
var visibleLabelMin = Infinity; | ||
var visibleLabelMax = -Infinity; | ||
|
||
var visibleLabelMin = Infinity; | ||
var visibleLabelMax = -Infinity; | ||
tickLabels.each(function(d) { | ||
var thisLabel = d3.select(this); | ||
var mathjaxGroup = thisLabel.select('.text-math-group'); | ||
|
||
tickLabels.each(function(d) { | ||
var thisLabel = d3.select(this); | ||
var mathjaxGroup = thisLabel.select('.text-math-group'); | ||
|
||
if(mathjaxGroup.empty()) { | ||
var bb = Drawing.bBox(thisLabel.node()); | ||
var hide = false; | ||
if(isX) { | ||
if(bb.right > max) hide = true; | ||
else if(bb.left < min) hide = true; | ||
} else { | ||
if(bb.bottom > max) hide = true; | ||
else if(bb.top + (ax.tickangle ? 0 : d.fontSize / 4) < min) hide = true; | ||
if(mathjaxGroup.empty()) { | ||
var bb = Drawing.bBox(thisLabel.node()); | ||
var adjust = ''; | ||
if(isX) { | ||
if(bb.right > max) adjust += 'right'; | ||
else if(bb.left < min) adjust += 'left'; | ||
} else { | ||
if(bb.bottom > max) adjust += 'top'; | ||
else if(bb.top + (ax.tickangle ? 0 : d.fontSize / 4) < min) adjust += 'bottom'; | ||
} | ||
|
||
var t = thisLabel.select('text'); | ||
if(adjust) { | ||
if(hideOverflow) t.style('opacity', 0); // hidden | ||
/* | ||
else if(pushOverflow) { | ||
if(adjust.indexOf('left') !== -1) t.attr('text-anchor', 'start'); | ||
if(adjust.indexOf('right') !== -1) t.attr('text-anchor', 'end'); | ||
// more TODO: https://github.com/plotly/plotly.js/issues/3292 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could leave another branch open with this WIP for "push to ..." but I'd rather not have it commented out in the main codebase. Anyway the eventual solution is going to need to be a bit more complex than this: we'll want to push these labels only as far as necessary, and then if doing so causes them to intersect the next labels we should still hide them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed by c9eaff2. |
||
} | ||
*/ | ||
} else { | ||
t.style('opacity', 1); // visible | ||
|
||
var t = thisLabel.select('text'); | ||
if(hide) { | ||
t.style('opacity', 0); // hidden | ||
if(side === 'bottom' || side === 'right') { | ||
visibleLabelMin = Math.min(visibleLabelMin, isX ? bb.top : bb.left); | ||
} else { | ||
t.style('opacity', 1); // visible | ||
|
||
if(side === 'bottom' || side === 'right') { | ||
visibleLabelMin = Math.min(visibleLabelMin, isX ? bb.top : bb.left); | ||
} else { | ||
visibleLabelMin = -Infinity; | ||
} | ||
visibleLabelMin = -Infinity; | ||
} | ||
|
||
if(side === 'top' || side === 'left') { | ||
visibleLabelMax = Math.max(visibleLabelMax, isX ? bb.bottom : bb.right); | ||
} else { | ||
visibleLabelMax = Infinity; | ||
} | ||
if(side === 'top' || side === 'left') { | ||
visibleLabelMax = Math.max(visibleLabelMax, isX ? bb.bottom : bb.right); | ||
} else { | ||
visibleLabelMax = Infinity; | ||
} | ||
} // TODO: hide mathjax? | ||
}); | ||
} | ||
} // TODO: hide mathjax? | ||
}); | ||
|
||
if(ax._anchorAxis) { | ||
ax._anchorAxis._visibleLabelMin = visibleLabelMin; | ||
ax._anchorAxis._visibleLabelMax = visibleLabelMax; | ||
} | ||
if(ax._anchorAxis) { | ||
ax._anchorAxis._visibleLabelMin = visibleLabelMin; | ||
ax._anchorAxis._visibleLabelMax = visibleLabelMax; | ||
} | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"data": [{ | ||
"x": [-100, 0, 100], | ||
"y": [-100, 0, 100] | ||
}], | ||
"layout": { | ||
"xaxis": { | ||
"range": [-115, 105], | ||
"tickformat": ".3f", | ||
"ticklabeloverflow": "allow" | ||
}, | ||
"yaxis": { | ||
"range": [-115, 105], | ||
"tickangle": 90, | ||
"tickformat": ".3f", | ||
"ticklabeloverflow": "allow" | ||
}, | ||
"plot_bgcolor": "lightblue", | ||
"showlegend": false, | ||
"width": 300, | ||
"height": 300, | ||
"margin": { | ||
"t": 15, | ||
"b": 15, | ||
"l": 15, | ||
"r": 15 | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"data": [{ | ||
"x": [-100, 0, 100], | ||
"y": [-100, 0, 100] | ||
}], | ||
"layout": { | ||
"xaxis": { | ||
"range": [-115, 105], | ||
"tickformat": ".3f", | ||
"ticklabeloverflow": "hide past div" | ||
}, | ||
"yaxis": { | ||
"range": [-115, 105], | ||
"tickangle": 90, | ||
"tickformat": ".3f", | ||
"ticklabeloverflow": "hide past div" | ||
}, | ||
"plot_bgcolor": "lightblue", | ||
"showlegend": false, | ||
"width": 300, | ||
"height": 300, | ||
"margin": { | ||
"t": 15, | ||
"b": 15, | ||
"l": 15, | ||
"r": 15 | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"data": [{ | ||
"x": [-100, 0, 100], | ||
"y": [-100, 0, 100] | ||
}], | ||
"layout": { | ||
"xaxis": { | ||
"range": [-115, 105], | ||
"tickformat": ".3f", | ||
"ticklabeloverflow": "hide past domain" | ||
}, | ||
"yaxis": { | ||
"range": [-115, 105], | ||
"tickangle": 90, | ||
"tickformat": ".3f", | ||
"ticklabeloverflow": "hide past domain" | ||
}, | ||
"plot_bgcolor": "lightblue", | ||
"showlegend": false, | ||
"width": 300, | ||
"height": 300, | ||
"margin": { | ||
"t": 30, | ||
"b": 30, | ||
"l": 30, | ||
"r": 30 | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"data": [{ | ||
"colorbar": { | ||
"dtick": 2, | ||
"ticklen": 4, | ||
"tickangle": 90, | ||
"tickformat": ".4f", | ||
"ticklabeloverflow": "allow" | ||
}, | ||
"type": "heatmap", | ||
"x": [-100, 0, 100], | ||
"y": [-100, 0, 100], | ||
"z": [ | ||
[0, 5, 10], | ||
[5, 10, 0], | ||
[10, 5, 0] | ||
] | ||
}], | ||
"layout": { | ||
"plot_bgcolor": "lightblue", | ||
"showlegend": false, | ||
"width": 200, | ||
"height": 300, | ||
"margin": { | ||
"t": 5, | ||
"b": 5, | ||
"l": 45, | ||
"r": 45 | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't want a
dflt
here, do you?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good eye. Addressed in f833ce4.