-
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
fix: same-looking tooltips on charts #10548
fix: same-looking tooltips on charts #10548
Conversation
@kurkle Hi. Scatter and Bubble charts don't use |
I think its better to always show the title with the label of the dataset, not only if there is more than 1 dataset, will give a more consistent and clear look. Same goes for scatter you could use the dataset label in that case |
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 good.
I'm on the same page with @LeeLenaleee that it would actually be better to just remove the overrides alltogether from these controllers. So it would always look the same unless customized.
@etimberg what do you think?
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 like the fallback, I'd vote to keep it. Though it should be documented.
Could also split it into a separate PR.
const {xScale, yScale} = meta; | ||
const parsed = this.getParsed(index); | ||
const x = xScale.getLabelForValue(parsed.x); | ||
const y = yScale.getLabelForValue(parsed.y); | ||
const r = parsed._custom; | ||
|
||
return { | ||
label: meta.label, | ||
label: labels[index] || '', |
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.
Could be that I'm missing something, but I'm not sure that is the correct label? meta.label
is the dataset label while labels[index]
would equal x
or y
in some cases and be empty in others.
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.
This feels like pretty buggy behaviour.
Maby its better to not disable all the default overrides but make them as simillar as possible.
Like the doughnut/pie tooltip is now a lot better since it tells which dataset its about but with the bubble chart atm you see a title that is not in the graph so it feels verry weird, same goes for scatter
Changes also need to be reflected in the migration guide: https://github.com/chartjs/Chart.js/blob/master/docs/migration/v4-migration.md |
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'm onboard with removing the overrides.
On an addition on the reaction I left on @kurkle comment, maby you can delete the labels array from the bubble and scatter samples so they dont show a wrong tooltip title. |
@LeeLenaleee done |
@kurkle @LeeLenaleee @etimberg Hi guys. Review please 🙏 |
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.
Some doc changes
docs/migration/v4-migration.md
Outdated
@@ -4,6 +4,10 @@ Chart.js 4.0 introduces a number of breaking changes. We tried keeping the amoun | |||
|
|||
## End user migration | |||
|
|||
### Charts | |||
|
|||
* Charts don't override default tooltip callbacks, so all chart types have the same-looking tooltips. |
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.
* Charts don't override default tooltip callbacks, so all chart types have the same-looking tooltips. | |
* Charts don't override the default tooltip callbacks, so all chart types have the same-looking tooltips. |
}); | ||
chart.update(); | ||
} | ||
}, | ||
{ | ||
name: 'Add Dataset', | ||
handler(chart) { | ||
const data = chart.data; |
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.
keep this data
, so its consistent with all the other sampels
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.
'data' is already declared in the upper scope on line 5 column 7 . eslint(no-shadow)
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.
They are both block scoped so it shouldn't matter and they are for the user also in different tabs.
CI way of running lint never fails on it but you run it in another way, idk why it fails but its weird.
Might be worth to see if we can not let the rule count for the docs then or disable it since how I see it, it does not seem to work correctly.
If it does not work it should be renamed in all the samples but my preference goes to having it like it was
@@ -30,11 +52,11 @@ const actions = [ | |||
{ | |||
name: 'Add Data', | |||
handler(chart) { | |||
const data = chart.data; |
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.
See above comment
}); | ||
chart.update(); | ||
} | ||
}, | ||
{ | ||
name: 'Add Dataset', | ||
handler(chart) { | ||
const data = chart.data; |
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.
Same as above
}); | ||
chart.update(); | ||
} | ||
}, | ||
{ | ||
name: 'Add Dataset', | ||
handler(chart) { | ||
const data = chart.data; |
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.
Also here
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
I believe @kurkle is on vacation so his reviews might be delayed
That was true, but I'm back! |
What if we want to customize the tooltip on the doughnut charts (for example) adding a % calculation but not on every other chart type? How can we achieve that now? @dangreen |
You can still override the callbacks by configuring it in the |
Thanks @LeeLenaleee , maybe we should add this info to the migration guide from 3.x |
But this did not change between v3 and v4 |
@LeeLenaleee It's related to this line in the migration guide... right? https://www.chartjs.org/docs/latest/migration/v4-migration.html
|
No, that line is about the overrides we did in the code, not about what the user specified. So in our controllers we overrode those functions but as user you could always override them again and you still can |
Could this be related? I'm having issues with labels on bubble charts |
fixes #9771
Now, if tooltip callback returnsundefined
, then will be used default callback.PolarArea and Doughnut charts with multiple series shows tooltips same as other charts.