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

do not show prefix and suffix for minor log axes #4064

Merged
merged 3 commits into from
Jul 22, 2019
Merged
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
39 changes: 29 additions & 10 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,34 +571,44 @@ axes.calcTicks = function calcTicks(ax) {
if((ax._tmin < startTick) !== axrev) return [];

// return the full set of tick vals
var vals = [];
var tickVals = [];
if(ax.type === 'category' || ax.type === 'multicategory') {
endTick = (axrev) ? Math.max(-0.5, endTick) :
Math.min(ax._categories.length - 0.5, endTick);
}

var isLog = (ax.type === 'log');

var xPrevious = null;
var maxTicks = Math.max(1000, ax._length || 0);
for(var x = ax._tmin;
(axrev) ? (x >= endTick) : (x <= endTick);
x = axes.tickIncrement(x, ax.dtick, axrev, ax.calendar)) {
// prevent infinite loops - no more than one tick per pixel,
// and make sure each value is different from the previous
if(vals.length > maxTicks || x === xPrevious) break;
if(tickVals.length > maxTicks || x === xPrevious) break;
xPrevious = x;

vals.push(x);
var minor = false;
if(isLog && (x !== (x | 0))) {
etpinard marked this conversation as resolved.
Show resolved Hide resolved
minor = true;
}

tickVals.push({
minor: minor,
value: x
});
}

// If same angle over a full circle, the last tick vals is a duplicate.
// TODO must do something similar for angular date axes.
if(isAngular(ax) && Math.abs(rng[1] - rng[0]) === 360) {
vals.pop();
tickVals.pop();
}

// save the last tick as well as first, so we can
// show the exponent only on the last one
ax._tmax = vals[vals.length - 1];
ax._tmax = (tickVals[tickVals.length - 1] || {}).value;

// for showing the rest of a date when the main tick label is only the
// latter part: ax._prevDateHead holds what we showed most recently.
Expand All @@ -607,8 +617,15 @@ axes.calcTicks = function calcTicks(ax) {
ax._prevDateHead = '';
ax._inCalcTicks = true;

var ticksOut = new Array(vals.length);
for(var i = 0; i < vals.length; i++) ticksOut[i] = axes.tickText(ax, vals[i]);
var ticksOut = new Array(tickVals.length);
for(var i = 0; i < tickVals.length; i++) {
ticksOut[i] = axes.tickText(
ax,
tickVals[i].value,
false, // hover
tickVals[i].minor // noSuffixPrefix
);
}

ax._inCalcTicks = false;

Expand Down Expand Up @@ -937,7 +954,7 @@ axes.tickFirst = function(ax) {
// ax is the axis layout, x is the tick value
// hover is a (truthy) flag for whether to show numbers with a bit
// more precision for hovertext
axes.tickText = function(ax, x, hover) {
axes.tickText = function(ax, x, hover, noSuffixPrefix) {
var out = tickTextObj(ax, x);
var arrayMode = ax.tickmode === 'array';
var extraPrecision = hover || arrayMode;
Expand Down Expand Up @@ -983,8 +1000,10 @@ axes.tickText = function(ax, x, hover) {
else formatLinear(ax, out, hover, extraPrecision, hideexp);

// add prefix and suffix
if(ax.tickprefix && !isHidden(ax.showtickprefix)) out.text = ax.tickprefix + out.text;
if(ax.ticksuffix && !isHidden(ax.showticksuffix)) out.text += ax.ticksuffix;
if(!noSuffixPrefix) {
if(ax.tickprefix && !isHidden(ax.showtickprefix)) out.text = ax.tickprefix + out.text;
if(ax.ticksuffix && !isHidden(ax.showticksuffix)) out.text += ax.ticksuffix;
}

// Setup ticks and grid lines boundaries
// at 1/2 a 'category' to the left/bottom
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions test/image/mocks/log-axis_no-minor_suffix-prefix.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"data": [
{
"y": [
etpinard marked this conversation as resolved.
Show resolved Hide resolved
1e8,
1e6,
1e7
],
"type": "scatter"
}
],
"layout": {
"yaxis": {
"type": "log",
"tickprefix": "$",
"ticksuffix": "Hz"
},
"height": 600,
"width": 300,
"margin": {
"l": 150
}
}
}