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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animints Don't Render Alt Text #106

Open
ampurr opened this issue Aug 24, 2023 · 9 comments
Open

Animints Don't Render Alt Text #106

ampurr opened this issue Aug 24, 2023 · 9 comments

Comments

@ampurr
Copy link
Collaborator

ampurr commented Aug 24, 2023

In R Markdown, it's possible to use the fig.alt knitr code chunk option to add alt text to static data visualizations. Like this:

{r, fig.alt = "A scatterplot of something really cool. 馃槑"}
cool <- ggplot(cool_dataset) + geom_point() + ...

But this option doesn't work for animints. So this doesn't work right:

{r, fig.alt = "A really cool interactive scatterplot. 馃惎"}
animint(cool)

Maybe a future GSOC contributor can fix this as part of a larger Accessibility for Animint2 project?

@ampurr
Copy link
Collaborator Author

ampurr commented Aug 24, 2023

@ampurr
Copy link
Collaborator Author

ampurr commented Aug 24, 2023

An alternative solution is to add a function that lets users add alt text to their animints. That's probably easier than figuring out how knitr adds alt text and then change it.

@tdhock
Copy link
Collaborator

tdhock commented Aug 24, 2023

I thought alt text was only for images? Animints are rendered as <svg> elements. Maybe we could add role="img" as mentioned on https://css-tricks.com/accessible-svgs/ ?

@ampurr
Copy link
Collaborator Author

ampurr commented Aug 24, 2023

You're right. However, I'd consider an SVG an image, even though it's not an <img>. But you're in charge鈥攊f you disagree, we can close the issue. :>

Yeah, I think role="img" would be part of the solution. But it seems like accessible SVGs rely on <title>. So we can't use something <svg alt="foobar">.

I've never looked into how knitr works. I think we'd need it to output the role and the <title>.

@ampurr
Copy link
Collaborator Author

ampurr commented Aug 24, 2023

Two asides:

  1. Unlike an <img>, animints have SVG <text> elements and other elements that can be accessed by a screenreader. That makes our job harder, since we'll have to take that into account when thinking about animint accessibility.
  2. Animints are <table>s. I've never thought about the semantics of data visualizations before, so I'm not sure this is right or not. Maybe there's research on this. 馃

@tdhock
Copy link
Collaborator

tdhock commented Aug 24, 2023

you are right, each animint is actually a table containing several svg elements.
I don't think you should hack the knit_print.animint function. That would only change animints inside of Rmds, but accessibility applies to all animints (even outside of rendered Rmds).
Instead I would suggest modifying the inst/htmljs/animint.js code, which creates the table and svg elements.

@ampurr
Copy link
Collaborator Author

ampurr commented Aug 24, 2023

That makes sense. So the person would be modifying the JS code and creating a make_alt_text function alongside it?

@tdhock
Copy link
Collaborator

tdhock commented Aug 24, 2023

You are right, according to that page, we just need to add a <title> element as the first sub-element of each svg.

Inside the <svg>, add: 
<title>A short title of the SVG</title>
    must be the first child of it鈥檚 parent element
    will be used as a tooltip as the pointing device moves over it

For existing code like

animint(timeSeries=ggplot..., scatter=ggplot...)

We could provide some reasonable default like "plot of timeSeries" and "plot of scatter"
We could also allow user to override per plot via

animint(timeSeries=ggplot()+theme_animint(title="some plot")

which we could render in JS as

<title id="title_timeSeries">some plot</title>

@ampurr
Copy link
Collaborator Author

ampurr commented Aug 25, 2023

That makes sense. I feel conflicted about the default alt txt idea, but I'll think about it and give my thoughts after I'm done with the reference website stuff. :>

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

No branches or pull requests

2 participants