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

Add new chart component options #4318

Merged
merged 6 commits into from
Oct 22, 2024
Merged

Add new chart component options #4318

merged 6 commits into from
Oct 22, 2024

Conversation

andysellick
Copy link
Contributor

@andysellick andysellick commented Oct 18, 2024

What

Adds some options to the chart component:

  • minimal, for when the graph is in a small space and should display minimal information and link to more information
  • height, to set the height in situations like the above

I've started going down a bit of a rabbit hole with this one, so I've raised #4322 as an issue to record my concerns rather than try to address them here and spiral the scope out of control.

Why

Needed for a page where the graphs are going to be small and link to another page.

Visual Changes

Minimal version:

Screenshot 2024-10-21 at 09 19 18

Minimal version with a smaller height:

Screenshot 2024-10-21 at 09 19 26

Trello card: https://trello.com/c/DFT05NWN/97-implement-small-graphs-on-main-landing-page

@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4318 October 18, 2024 15:45 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4318 October 21, 2024 10:13 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4318 October 21, 2024 11:13 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4318 October 21, 2024 11:15 Inactive
@andysellick andysellick changed the title [WIP] Add new chart component options Add new chart component options Oct 21, 2024
@andysellick andysellick marked this pull request as ready for review October 21, 2024 11:30
Copy link
Contributor

@AshGDS AshGDS 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, just had some questions first 👍

enableInteractivity = false if minimal
textPosition = nil
textPosition = 'none' if minimal
valid_minimal = true
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be better to use rails validation here? E.g.

 if minimal && !minimal_link
    raise ArgumentError, "Minimal version must include a link"
  end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good shout, thanks, have updated.

@@ -75,77 +89,85 @@
<% end %>

<div class="gem-c-chart__chart" id="<%= chart_id %>">
Copy link
Contributor

Choose a reason for hiding this comment

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

If the purpose of the minimal version is just for presentation, and not for conveying information, should it be hidden from the accessibility tree? E.g. give it a tabindex so that it can't be focused on, and use aria-hidden="true"?

If not, I think the focus style for the minimal version should be improved - for example the yellow is not visible around the whole chart container. Otherwise, I think it will be flagged as an accessibility issue.

Also, how will users know that this is a link? Will it be next to some content that implies so?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good shout on the first point - have added aria-hidden as suggested so now the only thing a screenreader should encounter is the link. Have also improved the focus style for the link to make it look better.

How will users know this is a link? That's an excellent question and I'm not sure of the answer. In the designs we have they're directly underneath some headings, which themselves are also links, so this being a link as well is kind of a backup (although that itself introduces a duplicate link, which isn't great).

I'm left wondering if minimal should be a link at all, but the link is needed to allow users to go to the full graph and table of data - it might as well just be an image if it isn't a link, but we decided to generate a chart otherwise we have to keep updating images every time the chart they link to changes. A bit of a rabbit hole in general.

- 82
- 118
- 85
- 80
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: no empty line at the end of the file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

- currently hard coded as the chart isn't responsive
- quite difficult to write a test for this as it's applied as an inline style
- use an Openstruct to persist a value between multiple instances of the component to make the external script for Google charts only be called once
- perhaps unsurprisingly this doesn't make any difference to the page weight in Chrome, presumably because Chrome is smart enough to realise it's already loaded that script if there's more than one chart
- however it feels tidier to limit it this way, particularly for browsers that may not be so clever
Copy link
Contributor

@AshGDS AshGDS 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, minor comment but happy for you to sort that on your own, so will approve 👍

@@ -92,14 +92,15 @@
} %>
<% end %>

<div class="gem-c-chart__chart" id="<%= chart_id %>">
<% aria_attributes = { hidden: true } if minimal %>
Copy link
Contributor

Choose a reason for hiding this comment

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

I think if we have aria-hidden i don't think it can be keyboard focusable as well, as the component guide is flagging this as an issue. Happy for you to pick between either having focus or having aria-hidden.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Argh, good spot, thanks. Think I've fixed this now - since the chart is just a link, I've included some logic to simply not render the visually hidden text (it's the thing that contained a link).

@andysellick
Copy link
Contributor Author

@AshGDS are you happy to approve the visual changes?

- improve focus state around link to have a complete border and be more visible
- use aria hidden on the graph when in minimal mode
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4318 October 22, 2024 12:29 Inactive
@andysellick andysellick merged commit 64bc3fc into main Oct 22, 2024
12 checks passed
@andysellick andysellick deleted the add-small-chart branch October 22, 2024 12:34
@andysellick andysellick mentioned this pull request Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants