-
Notifications
You must be signed in to change notification settings - Fork 11.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
Improved formatting of numeric scale labels #7007
Conversation
fcedf3a
to
08effe7
Compare
If we think this will be useful to lots of users, perhaps we can offer it as an option, but not change the defaults? That would give a quick switch but keep the defaults simple (similar idea for #7004) |
e585af8
to
26b1d00
Compare
I'd probably rather keep it simpler by having fewer options and just always doing it. I think inserting a comma is a pretty minor change and I'm struggling to think of a usecase where it wouldn't be valuable. If we get feedback during the alpha/beta we can always come back to add an option. |
26b1d00
to
7e5a3ab
Compare
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.
Another thing I'm not quite sure about is the placement of the locale
configuration. Should it rather be in options
? One could want to have charts with different locales on the same page (for example in Chart.js docs).
8e63e8a
to
f8b0a69
Compare
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.
There is a mix of Chart.platform.locale
and chart.platform.locale
(global vs instance).
Is that intended?
No, it wasn't. I updated that. Thanks |
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.
Still unsure about the placement of locale
, but that can be changed later if needed.
5f24b97
to
0f9f1fa
Compare
Rebased |
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.
Agree, not hot on placing it on Chart.platform
since that was intended to be for switching between browser, basic platform, etc.
I think some documentation should also be written telling users how to use this new option (unless we are intending this only for testing)
src/core/core.ticks.js
Outdated
tickString = '0'; // never show decimal places for 0 | ||
const maxTick = Math.max(Math.abs(ticks[0].value), Math.abs(ticks[ticks.length - 1].value)); | ||
const locale = Chart.platform.locale; | ||
if (maxTick < 1e-4) { // all ticks are small numbers; use scientific notation |
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.
I know the old code didn't do this, but would it be good to do this if all ticks are large as well?
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.
Ok, I've added that
My thinking for putting it on |
Personally, I would put under |
Ok, I've moved it to being an option. Unfortunately there's no really good page to document it on, so I've punted on that for now since it at least solves the testing issue |
9875651
to
989bd01
Compare
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.
While at it, can we change the calling of the callback to be consistent. Either way is fine by me.
src/scales/scale.time.js
Outdated
@@ -652,7 +652,7 @@ class TimeScale extends Scale { | |||
tickOpts.callback | |||
]); | |||
|
|||
return formatter ? formatter(label, index, ticks) : label; | |||
return formatter ? formatter(label, index, ticks, me) : label; |
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.
Oh, looks like we are calling the callback inconsistently. Should probably make it consistent.
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.
Yeah, there's multiple things I don't like about this. One of the biggest is that the first parameter is different here. I'd noticed while working on this. It's not that easy to change though and a bit outside the scope of this PR, so probably better handled separately
const maxTick = Math.max(Math.abs(ticks[0].value), Math.abs(ticks[ticks.length - 1].value)); | ||
const minTick = Math.min(Math.abs(ticks[0].value), Math.abs(ticks[ticks.length - 1].value)); | ||
const locale = scale.chart.options.locale; | ||
if (maxTick < 1e-4 || minTick > 1e+7) { // all ticks are small or big numbers; use scientific notation |
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.
Don't really like the use of constants here, but this is something that can be altered if it becomes an issue later.
This makes three main changes:
ticks.callback
to be a context object similar to scriptable optionsscale.logarithmic.tests.js
the numbers range from 1 to 80. It's much easier to read these just as normal numbers instead of scientific notation. We still use scientific notation when all the numbers are small.There's also just some minor changes like using
const
/let
and improving the structure of theif
/else
checks to bring cognitive complexity down from 9 to 5 to make codeclimate happy