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

feat: Upstream Doughnut Chart to RC #1128

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Kxiru
Copy link
Contributor

@Kxiru Kxiru commented Sep 4, 2024

Done

  • Added the Doughnut Chart Component

TODOs

  • Correct failing test that verifies whether a tooltip shows on hover.

QA

Storybook

To see rendered examples of all react-components, run:

yarn start

QA in your project

from react-components run:

yarn build
npm pack

Install the resulting tarball in your project with:

yarn add <path-to-tarball>

QA steps

  • Run Storybook
  • Navigate to Doughnut Chart component

Percy steps

  • List any expected visual change in Percy, or write something like "No visual changes expected" if none is expected.

Fixes

Fixes: N/A

@webteam-app
Copy link

@Kxiru Kxiru changed the title feat: [WD-13450] Upstream Doughnut Chart to RC feat: Upstream Doughnut Chart to RC Sep 4, 2024
Copy link
Contributor

@edlerd edlerd left a comment

Choose a reason for hiding this comment

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

This is a good start. Some ideas to improve:

  • The linter has found one issue
  • In storybook there is an error on the Docs and Template section for the component
  • For the test you can start easy i.e. by rendering a chart with two equal segments and checking the radius is calculated correctly as 180 degrees. Or be creative for other test cases.

@advl
Copy link

advl commented Sep 5, 2024

It looks good to me. I second @edlerd 's comments.

You could maybe also add additional stories with edge cases (100%, 0%). What do you think ?

Also, in general, and outside the scope of this PR, how do you think @Kxiru we could approach integrating more charts into the library ? Do you have an idea what other use cases might be, and how we could implement a common API ?

@Kxiru Kxiru force-pushed the upstream-doughnut-chart branch 2 times, most recently from 4a2bc1f to 2f12684 Compare September 5, 2024 11:21
@Kxiru
Copy link
Contributor Author

Kxiru commented Sep 5, 2024

Apologies, it seems as though my existing test suite and much of my changes did not actually push 💀 . Here is the latest version, and I will address any outstanding suggestions on top of this.

Edit: @edlerd , as you can see, one of my tests is failing and this is the one regarding the Tooltips showing. I'd like to perfect it but Jest simply isn't having it, haha. Any ideas on what could be wrong with my current implementation? Alternatively, if you do not think that it is a necessary test to have, I can remove it.

@Kxiru
Copy link
Contributor Author

Kxiru commented Sep 5, 2024

@advl , could you give me some examples of the edge cases you are considering? :)
Also, I would be happy to implement some more graphs! I definitely think that some data visualisation components in React Components would go a long way for future projects. Two that we have perfected in the backlog include Multi-Bar (supporting Single bar) meters, and Horizontal bar charts.
image
image
image

We also have a legend for the doughnut chart which could be triggered and autogenerated by a prop?

image

Let me know your thoughts :).

@Kxiru Kxiru marked this pull request as ready for review September 9, 2024 12:22
@jmuzina
Copy link
Member

jmuzina commented Sep 13, 2024

Looks good as-is, but I wonder if there is a way for us to make the chart a bit more accessible - screen readers and keyboard users may have a hard time navigating and understanding this chart. I'll take a brief look and let you know if there's anything that can be done quickly in scope of just upstreaming this

@advl
Copy link

advl commented Sep 13, 2024

Agreed @jmuzina . I would suggest to timebox it and merge to unblock.
We can use these learnings for the new arch in case they would require too much work here.

@jmuzina
Copy link
Member

jmuzina commented Sep 13, 2024

Looks good as-is, but I wonder if there is a way for us to make the chart a bit more accessible - screen readers and keyboard users may have a hard time navigating and understanding this chart. I'll take a brief look and let you know if there's anything that can be done quickly in scope of just upstreaming this

A quick solution would be to give the chart a title and description, that way screen readers announce the contents. You can do this by creating <title> and <desc>.

 <svg
    className="doughnut-chart__chart"
    id={id.current}
    viewBox={`0 0 ${canvasSize} ${canvasSize}`}
    data-testid={TestIds.Section}
    aria-labelledby={`${id.current}-chart-title ${id.current}-chart-desc`}
  >
    {label && <title id={`${id.current}-chart-title`}>{label}</title>}
    <desc id={`${id.current}-chart-desc`}>
      {segments.map(
        (segment) => {
          let description = "";
          if (segment.tooltip) description += `${segment.tooltip}: `;
          description += segment.value;
          return description;
        })
        .join(",")}
    </desc>

This causes a screen reader to announce the chart contents:
Screenshot 2024-09-13 at 11 44 53 AM

cx={radius - segmentWidth / 2 - hoverIncrease}
cy={radius + segmentWidth / 2 + hoverIncrease}
data-testid={TestIds.Segment}
key={i}
Copy link
Member

@jmuzina jmuzina Sep 13, 2024

Choose a reason for hiding this comment

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

Suggested change
key={i}
key={i}
tabIndex={0}
aria-label={`${tooltip}: ${value}`}

If you do something like this, the segments will also be tab-selectable and announce their contents to screen readers.

Copy link
Member

@jmuzina jmuzina Sep 13, 2024

Choose a reason for hiding this comment

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

It would also be nice to make the tooltip of a focused segment visible and highlight the segment as you do with mouseover. Though that may be a bit more difficult and to be tackled as a separate issue.

viewBox={`0 0 ${canvasSize} ${canvasSize}`}
data-testid={TestIds.Section}
>
<mask id="myMask">

Choose a reason for hiding this comment

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

Nit: Can we use a more descriptive name here?

/**
* The width of the segments.
*/
segmentWidth: number;

Choose a reason for hiding this comment

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

I believe conventionally this is referred to as "thickness," rather than "width," which I think is a bit clearer.

display: block;
}

.doughnut-chart__tooltip > :only-child {

Choose a reason for hiding this comment

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

Why is this necessary, and why is the tooltip child inline-block by default?

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.

6 participants