-
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
Add stroke lines option around ticks to improve readability #6787
Conversation
src/core/core.scale.js
Outdated
return { | ||
minor: minor, | ||
major: major, | ||
strokeStyle: valueOrDefault(options.strokeStyle, defaults.scale.ticks.strokeStyle), |
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.
These options should probably be included in parseFontOptions
instead
We have a notion of major & minor ticks, which is best demonstrated here: https://www.chartjs.org/samples/latest/scales/time/financial.html. In that example we have the years as major ticks and have them formatted differently. Putting in parseFontOptions
will allow the users to have different strokeStyle and lineWidth for major and minor ticks. While I don't have a specific use case in mind for that it would be more consistent with how the other options work
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.
Hmm, I think I'm missing something.
It is already in parseFontOptions
, but if for example, I don't add it here or in _parseFont
, the arguments are not set, I mean strokeStyle
and lineWidth
are empty... where is the "setter"? I don't find it
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.
oki! I let the parseTickFontOptions
how it was and the new options are only in parseFontOptions
src/core/core.scale.js
Outdated
@@ -1255,16 +1264,20 @@ class Scale extends Element { | |||
ctx.fillStyle = tickFont.color; | |||
ctx.textBaseline = 'middle'; | |||
ctx.textAlign = item.textAlign; | |||
ctx.strokeStyle = optionTicks.strokeStyle; |
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 think this should be tickFont.strokeStyle
, I guess this is the missing link.
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.
Hi @kurkle, thanks for the suggestion, but unfortunately nop:
I need to explicitly add it to _parseFont
to have it available in tickFont
, but it seems that I'm adding this new options to everywhere that needs to parse fonts, so it's like a little dirty, doesn't it?
However, I can't find how to use the options directly inside _drawLabels
, the new arguments are empty if I don't add in _parseFont
or parseTickFontOptions
.. so there is some magic somewhere that I can't find
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 had those changes in parseFontOptions
when debugging?
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.
yep, it's there lineWidth
, strokeStyle
:
function parseFontOptions(options, nestedOpts) {
return helpers.extend(helpers.options._parseFont({
fontFamily: valueOrDefault(nestedOpts.fontFamily, options.fontFamily),
fontSize: valueOrDefault(nestedOpts.fontSize, options.fontSize),
fontStyle: valueOrDefault(nestedOpts.fontStyle, options.fontStyle),
lineHeight: valueOrDefault(nestedOpts.lineHeight, options.lineHeight),
lineWidth: valueOrDefault(nestedOpts.lineWidth, options.lineWidth),
strokeStyle: valueOrDefault(nestedOpts.strokeStyle, options.strokeStyle),
}), {
color: resolve([nestedOpts.fontColor, options.fontColor, defaults.global.defaultFontColor])
});
}
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.
Finally, the options are in optionTicks
and as I commented above, I let also the pareFontOptions
for the minor and major.
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'd be ok with enabling it in _parseFont
if we allow all the text to be stroked as well (likely outside the scope of this PR)
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 don't think specifying different lineWidth for major ticks works now.
Sorry for the delay! I think is ready now, could you take a look when you have some time, please? thanks! BTW, @benmccann, @etimberg and @kurkle, thanks for supporting the project... 491 issues and only 11 PR's... it's a pity that there are no more developers that try to collaborate a bit, so, thanks for your work guys. |
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 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.
Looks like there is still some minor adjustment to do to get this fully functional. I could be wrong on those points though :)
src/core/core.scale.js
Outdated
@@ -1255,16 +1259,20 @@ class Scale extends Element { | |||
ctx.fillStyle = tickFont.color; | |||
ctx.textBaseline = 'middle'; | |||
ctx.textAlign = item.textAlign; | |||
ctx.strokeStyle = optionTicks.strokeStyle; | |||
ctx.lineWidth = optionTicks.lineWidth; |
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.
If my memory serves, ctx
will not accept a lineWidth
of 0
and remains in the previous value.
So I think we should add a check for lineWidth
and not do the strokeText
if its not defined.
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 one, I did a small test and ctx
does not accept zeros in lineWidth
at all. I added a small conditional. thanks!
src/core/core.scale.js
Outdated
@@ -1255,16 +1264,20 @@ class Scale extends Element { | |||
ctx.fillStyle = tickFont.color; | |||
ctx.textBaseline = 'middle'; | |||
ctx.textAlign = item.textAlign; | |||
ctx.strokeStyle = optionTicks.strokeStyle; |
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 don't think specifying different lineWidth for major ticks works now.
You are right 😞 , |
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.
Can you debug again, if those options are now correctly resolved into the font?
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.
Lgtm
@benmccann did you want to review this as well? |
This looks good to me. I just had a couple nitpicks |
I come from here: #6784
Before: https://codepen.io/joseraul/pen/qBBwgpQ
After: