-
-
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
Fixup texttemplate on log axes #5622
Conversation
src/traces/bar/plot.js
Outdated
return tickText(pAxis, u, true).text; | ||
} | ||
|
||
function formatNumber(v) { | ||
if(vAxis.type === 'log') v = vAxis.c2r(v); |
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.
Nonblocking, but formatLabel
and formatNumber
are nearly the same function - just pAxis
vs vAxis
and the +
in the tickText
call (any reason that's in one but not the other?) - so should be able to be collapsed.
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.
Actually, we may be able to simplify all of this, and get rid of the type === 'log'
checks entirely, by using c2l
plotly.js/src/plots/cartesian/set_convert.js
Line 243 in 8cccacc
ax.c2l = (ax.type === 'log') ? toLog : ensureNumber; |
And while I'm here, this is ensureNumber
:
Lines 166 to 171 in 8cccacc
lib.ensureNumber = function ensureNumber(v) { | |
if(!isNumeric(v)) return BADNUM; | |
v = Number(v); | |
if(v < -FP_SAFE || v > FP_SAFE) return BADNUM; | |
return isNumeric(v) ? Number(v) : BADNUM; | |
}; |
Any reason the last line isn't just return v;
? This is a pretty hot function. After already filtering out non-numeric values and converting others to Number
explicitly, why would we have to check isNumeric
again?
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.
Actually, we may be able to simplify all of this, and get rid of the
type === 'log'
checks entirely, by usingc2l
plotly.js/src/plots/cartesian/set_convert.js
Line 243 in 8cccacc
ax.c2l = (ax.type === 'log') ? toLog : ensureNumber;
Good call. Applied in ca962bc.
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.
The ensureNumber
comment is tracked in #5634.
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.
💃 Consider my comment re: simplifying, but functionally this looks great. Excellent tests.
Fixes #5585 for
scatter
andbar
.@plotly/plotly_js