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

[Bug]: full data point is not passed to the DonutChart tooltip customHTML callback, unlike the other chart types #1518

Closed
mthaak opened this issue Mar 7, 2023 · 0 comments · Fixed by #1879
Labels
type: bug 🐛 Something isn't working

Comments

@mthaak
Copy link

mthaak commented Mar 7, 2023

Contact Details

No response

What happened?

Currently, only the (truncated) label and value is passed into the customHTML callback of the donut chart options. This makes it hard to find the original data point that the tooltip belongs to. Especially because a label might be truncated if it's too long, and thus may have become non-unique. Confusingly, the donut chart has a default truncation set on the tooltip so as developer you might not even be aware that the label passed to the customHTML callback can be non-unique.

In order to disable the truncation you need to set this on the donut chart options:

  const options: DonutChartOptions = { 
    tooltip: {
      truncation: {
        type: TruncationTypes.NONE,
      },
    }
  }

It would be very helpful if this caveat was documented somewhere.

This is the information that's currently passed to DonutChartOption's customHTML:

  const options: DonutChartOptions = { 
    tooltip: {
      customHTML: (
        datum: {
          label: string;
          value: string;
        }[]
      ) => {
        // do stuff with (truncated) label and value
      },
    },
  };

(also the value becomes a number if truncation is turned off, that was also a bit unexpected)

It would be better if the full data point was passed just like with the other charts:

  const options: BarChartOptions = { 
    tooltip: {
      customHTML: (data: ChartData) => {
        // do stuff with the full data point (of type `ChartData`)
      },
    },
  };

because then you wouldn't need to worry about truncation.

See how in the sandbox screen the label printed to the console is truncated:
image

Version

@carbon/charts-react@0.57.0 but it also happens on the latest version

Data & options used

See above...

Relevant log output

No response

Codesandbox example

https://codesandbox.io/s/stupefied-fermi-0sj2nm?file=/src/index.js

@mthaak mthaak added the type: bug 🐛 Something isn't working label Mar 7, 2023
SMassola added a commit to SMassola/carbon-charts that referenced this issue Aug 23, 2024
- updated handler for tooltip show event to extract the datum
from the event details and pass it as an argument to the customHTML
callback function if one was specific within the chart options

Close carbon-design-system#1518

Signed-off-by: Steven Massola <steven.massola@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🐛 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant