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

fix: same-looking tooltips on charts #10548

Merged
merged 6 commits into from
Aug 18, 2022
Merged

fix: same-looking tooltips on charts #10548

merged 6 commits into from
Aug 18, 2022

Conversation

dangreen
Copy link
Collaborator

@dangreen dangreen commented Aug 2, 2022

fixes #9771

  • Now, if tooltip callback returns undefined, then will be used default callback.
  • PolarArea and Doughnut charts with multiple series shows tooltips same as other charts.

@dangreen dangreen marked this pull request as ready for review August 2, 2022 20:37
@dangreen
Copy link
Collaborator Author

dangreen commented Aug 2, 2022

@kurkle Hi. Scatter and Bubble charts don't use data.labels, so should their tooltips also look like on rest multiseries charts?

@LeeLenaleee
Copy link
Collaborator

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

Copy link
Member

@kurkle kurkle left a 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?

src/plugins/plugin.tooltip.js Outdated Show resolved Hide resolved
@dangreen dangreen changed the title fix: same-looking tooltips on multiseries charts fix: same-looking tooltips on charts Aug 4, 2022
@dangreen dangreen requested a review from kurkle August 4, 2022 22:05
Copy link
Member

@kurkle kurkle left a 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] || '',
Copy link
Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meta.label

Снимок экрана 2022-08-05 в 12 12 55

labels[index]

Снимок экрана 2022-08-05 в 12 12 33

Copy link
Collaborator

@LeeLenaleee LeeLenaleee Aug 5, 2022

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
image

@LeeLenaleee
Copy link
Collaborator

Changes also need to be reflected in the migration guide: https://github.com/chartjs/Chart.js/blob/master/docs/migration/v4-migration.md

etimberg
etimberg previously approved these changes Aug 5, 2022
Copy link
Member

@etimberg etimberg left a 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.

@LeeLenaleee
Copy link
Collaborator

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.

image

@dangreen
Copy link
Collaborator Author

dangreen commented Aug 7, 2022

@LeeLenaleee done

@dangreen
Copy link
Collaborator Author

@kurkle @LeeLenaleee @etimberg Hi guys. Review please 🙏

Copy link
Collaborator

@LeeLenaleee LeeLenaleee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some doc changes

@@ -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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 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;
Copy link
Collaborator

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

Copy link
Collaborator Author

@dangreen dangreen Aug 15, 2022

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)

@LeeLenaleee

Copy link
Collaborator

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;
Copy link
Collaborator

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;
Copy link
Collaborator

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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here

Copy link
Member

@etimberg etimberg left a 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

@kurkle
Copy link
Member

kurkle commented Aug 18, 2022

LGTM

I believe @kurkle is on vacation so his reviews might be delayed

That was true, but I'm back!

@etimberg etimberg merged commit e7372ad into chartjs:master Aug 18, 2022
@dangreen dangreen deleted the fix-tooltip-callbacks branch August 18, 2022 11:48
@Sergiobop
Copy link

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

@LeeLenaleee
Copy link
Collaborator

You can still override the callbacks by configuring it in the options for those charts or in the defaults for that controller

@Sergiobop
Copy link

Thanks @LeeLenaleee , maybe we should add this info to the migration guide from 3.x

@LeeLenaleee
Copy link
Collaborator

But this did not change between v3 and v4

@Sergiobop
Copy link

@LeeLenaleee It's related to this line in the migration guide... right?

https://www.chartjs.org/docs/latest/migration/v4-migration.html

Charts don't override the default tooltip callbacks, so all chart types have the same-looking tooltips.

@LeeLenaleee
Copy link
Collaborator

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

@shanecranor
Copy link

Could this be related? I'm having issues with labels on bubble charts
#11023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tooltip of multiseries pie chart has no dataset label
6 participants