Skip to content
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

Better log axis tick labeling with less label overlap for scatter plots #6120

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions draftlogs/6120_change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This patch removes the single-digit small subtick labels for logarithmically scaled plots, and replaces them with normal sized multi-digit ticks (including SI extensions if enabled) at positions 2, 3, 5, and 7 - if space permits.

See https://stackoverflow.com/questions/70926979 for details.
17 changes: 15 additions & 2 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ axes.prepTicks = function(ax, opts) {
minPx = ax.tickfont ? Lib.bigFont(ax.tickfont.size || 12) : 15;
nt = ax._length / minPx;
} else {
minPx = ax._id.charAt(0) === 'y' ? 40 : 80;
minPx = ax._id.charAt(0) === 'y' ? 40 : 100;
nt = Lib.constrain(ax._length / minPx, 4, 9) + 1;
}

Expand Down Expand Up @@ -951,6 +951,8 @@ axes.calcTicks = function calcTicks(ax, opts) {
};

var ticksOut = [];
var skipText1 = /^[346789]/; // for x-axis and tick length >= 3
var skipText2 = /^[4689]/; // for tick length < 3
var t, p;
for(i = 0; i < tickVals.length; i++) {
var _minor = tickVals[i].minor;
Expand All @@ -976,6 +978,14 @@ axes.calcTicks = function calcTicks(ax, opts) {
}
}

if(ax.type == 'log' && ax.dtick == 'D1' && (
(ax._attr[0] == 'y' && t.text.match(skipText2))
|| (ax._attr[0] == 'x' && t.text.length < 3 && t.text.match(skipText2))
|| (ax._attr[0] == 'x' && t.text.length >=3 && t.text.match(skipText1))
)) {
hideLabel(t);
}

if(tickVals[i].skipLabel) {
hideLabel(t);
}
Expand Down Expand Up @@ -1129,11 +1139,14 @@ axes.autoTicks = function(ax, roughDTick) {
Math.pow(10, rng[0])) / nt;
base = getBase(10);
ax.dtick = 'L' + roundDTick(roughDTick, base, roundBase10);
ax.tickformat = '';
} else {
// include intermediates between powers of 10,
// labeled with small digits
// ax.dtick = "D2" (show 2 and 5) or "D1" (show all digits)
ax.dtick = (roughDTick > 0.3) ? 'D2' : 'D1';
ax.dtick = (roughDTick > 0.4) ? 'D2' : 'D1';
ax.tickformat = '0.1s';
ax.hoverformat = '0.2s'; // workaround to fix hoverinfo label formatting
}
} else if(ax.type === 'category' || ax.type === 'multicategory') {
ax.tick0 = 0;
Expand Down