Repository navigation
Give the Plots pane image alt text and announce plot changes - #19342
Merged
Merged
Conversation
Collect the alt text authors attach to drawn grobs (e.g. ggplot2's labs(alt = ...)) from the RStudio device's engine display list, which is reset on every new page, and send it with the plots state. Also flag when a different plot is shown, as opposed to the same plot redrawn after a resize, so the client can announce new plots. Addresses #19337
The image gets alt text with its position in the plot history, followed by the author's alt text when there is one. The same text is announced through a new, user-configurable plot_changed live announcement when a new plot is drawn or the history moves to another plot. Addresses #19337
Addresses #19337
The Plots presenter is loaded lazily. Until it loads, PlotsTab keeps only the latest plots state for it, so a state flagging a new plot could be replaced by one without the flag before the presenter saw it, and the plot went unannounced. PlotsTab sees every state, so announce there. Addresses #19337
A display list entry's arguments can be any object, and one whose own [[ method fails dropped the page's alt text and logged an error on every render. Addresses #19337
Alt text was read from the device's display on every render, including renders that reuse a plot's cached image. That repeated an R loop over the whole display list on each resize, and showed another plot's alt text when restoring a plot from history failed. Each plot now reads it when its image is taken, or on first display after a session restore, inside the scope that holds off polled events. Addresses #19337
ggplot2 starts a new page before building the plot, so a slow build can be shown, and its plot change announced, while the page is still blank. Announce the alt text again when it changes for the plot on show. Addresses #19337
A failed read was stored as empty alt text, so the plot kept no alt text until it was next redrawn. It is now left unread, and the next render reads it again. Addresses #19337
Whitespace-only alt text gave a description with nothing after the colon, e.g. "Plot 1 of 1: ". Addresses #19337
Info bars and other widgets have status regions too, and watching one of those would let the tests that expect no announcement pass without checking anything. Addresses #19337
RStudio E2E - all platformsAll tests passed!
View / download the full reportView report online -- opens in the browser, no download needed. Available for 14 days. Download playwright-report.zip -- extract and open
All platforms - commit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #19337.
The plot image in the Plots pane now has alt text with its position in the plot history, followed by the alt text the plot's author supplied, if any:
Plot 2 of 5Plot 3 of 5: Weight falls as fuel economy rises(from ggplot2'slabs(alt = ...))Screen readers also announce this text through the polite status live region when a new plot is drawn or the history moves to another plot. Redraws of the same plot (resize, refresh, client reconnect) are not announced. The announcement is a new
plot_changedentry in AriaLiveService, so it can be turned off in Global Options > Accessibility ("New or selected plot").How the author's alt text is found
ggplot2 (and any other grid code) attaches it as an
alt-labelattribute on the grob it draws. Grid records each top-level grob it draws in the device's engine display list, so.rs.graphicsAltText()reads the attribute from there. The engine display list is reset on every new page. Grid's own display list is not: a base-graphics plot drawn after a ggplot would otherwise inherit the ggplot's alt text.Each
Plotreads its alt text when its image is rendered from the display, and keeps it for cached redraws. A plot restored from a previous session reads it on first display. A failed read is logged and retried on the next render.How plot changes are detected
PlotManagersetsactivePlotChangedwhen a new page starts or the active plot changes, and clears it when the state is sent to the client.PlotsTabannounces when that flag is set, or when the alt text of the plot on show changes. The second case covers a ggplot shown while still blank, because ggplot2 starts the page before its build finishes. The announcement lives inPlotsTabrather than the lazily loaded presenter, which only sees the last state sent before it loads.Cost
The alt text read is an R loop over the page's display list. It runs only when a plot's snapshot is taken, which is already a much heavier step. With 100,000
points()calls on one page, the read took 68 ms against 1,080 ms for the snapshot save. A ggplot is a single display-list entry regardless of its size.Tests
src/cpp/tests/testthat/test-graphics.R: alt text is found, combined across grobs, trimmed, not carried to a later page, kept through snapshot save and restore, and read from ggplot2; display-list entries with a failing[[method are skipped.e2e/rstudio/tests/panes/plots/plot_alt_text.test.ts: alt text and announcements for a ggplot, a later base plot, history navigation, alt text drawn after the plot is shown, no announcement on refresh, and no announcement when the preference turns it off.Follow-ups: #19339 (combined plots), #19340 (Zoom window, export previews, notebook plots), #19341 (unused
PlotsPane.refresh()).