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

a11y-checker not reporting images without alt-text #12

Open
balajialg opened this issue May 16, 2024 · 10 comments
Open

a11y-checker not reporting images without alt-text #12

balajialg opened this issue May 16, 2024 · 10 comments
Assignees

Comments

@balajialg
Copy link
Contributor

balajialg commented May 16, 2024

I launched a notebook that generates a sample matplotlib plot. I have copy pasted the code that generated the plot for your reference. By default, Matplotlib generated images are not accessible as they don't have alt attribute explicitly specified.

import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]
fig, ax = plt.subplots()
ax.plot(x, y, marker='o')
ax.set_title("Sample Line Plot")
ax.set_xlabel("X-axis")
ax.set_ylabel("Y-axis")
plt.show()

The presence of an issue related to alt-text gets reported in Axe Deque tool as seen in snapshot below,

Screenshot 2024-05-16 at 4 06 13 PM

However, "a11y checker" tool reports that there are no issues in the notebook,

image

@ranashreyas
Copy link
Collaborator

Fixed in latest commit.

@balajialg
Copy link
Contributor Author

Thanks @ranashreyas!

@balajialg
Copy link
Contributor Author

balajialg commented May 17, 2024

@ranashreyas After pulling the latest code, rebuilding the extension -> I am stilling seeing the same issue. Let me know if I am missing any steps that you are doing,

git pull origin main
yarn build:labextension:dev
jupyter labextension install .
jupyter lab build
jupyter lab

@balajialg balajialg reopened this May 17, 2024
@balajialg
Copy link
Contributor Author

I found another example
Screenshot 2024-05-17 at 12 30 53 PM

a11y-checker reports no issues below even when the images don't have alt attribute

image

@balajialg
Copy link
Contributor Author

balajialg commented May 21, 2024

Here is another case where it doesn't identify issues related to alt-text and transparency ratio in a notebook. Here is the code block,

import matplotlib.pyplot as plt
import numpy as np

# Data
x = np.linspace(0, 10, 100)
y1 = np.sin(x)
y2 = np.cos(x)

# Create plot
plt.figure(figsize=(8, 6))

# Sine curve with poor color contrast and poor transparency
plt.plot(x, y1, label='Sine', color='lightgrey', alpha=0.2)

# Cosine curve with poor color contrast
plt.plot(x, y2, label='Cosine', color='yellow')

# Unstructured header (just a plain text, no structure)
plt.text(2, 1, 'A Graph', fontsize=20, color='red')

# X-axis label
plt.xlabel('X-axis')

# Y-axis label
plt.ylabel('Y-axis')

# No title

# No legend added
# plt.legend()

# Display the plot
plt.show()

Here is the snapshot where the tool failed to identify the issue

Screenshot 2024-05-20 at 6 12 10 PM

@balajialg
Copy link
Contributor Author

Another scenario where code block is listed below,

import matplotlib.pyplot as plt
import numpy as np

# Generate some data
x = np.linspace(0, 2*np.pi, 100)
y = np.sin(x)

# Create a plot without alt text
plt.figure()
plt.plot(x, y)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Plot without Alt Text')
plt.show()

Output is listed below
Screenshot 2024-05-20 at 6 17 22 PM

@balajialg
Copy link
Contributor Author

Code block generating image with poor color contrast ratio,


import matplotlib.pyplot as plt
import numpy as np

# Generate some data
x = np.linspace(0, 10, 100)
y1 = np.sin(x)
y2 = np.cos(x)

# Create a plot with poor color contrast ratio
plt.figure()
plt.plot(x, y1, label='Sine', color='lightgrey')  # Low contrast color
plt.plot(x, y2, label='Cosine', color='lightblue')  # Low contrast color
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Plot with Poor Color Contrast Ratio')
plt.legend()
plt.show()
Screenshot 2024-05-20 at 6 19 30 PM

@ranashreyas
Copy link
Collaborator

ranashreyas commented May 22, 2024

> import matplotlib.pyplot as plt
> import numpy as np
> 
> # Data
> x = np.linspace(0, 10, 100)
> y1 = np.sin(x)
> y2 = np.cos(x)
> 
> # Create plot
> plt.figure(figsize=(8, 6))
> 
> # Sine curve with poor color contrast and poor transparency
> plt.plot(x, y1, label='Sine', color='lightgrey', alpha=0.2)
> 
> # Cosine curve with poor color contrast
> plt.plot(x, y2, label='Cosine', color='yellow')
> 
> # Unstructured header (just a plain text, no structure)
> plt.text(2, 1, 'A Graph', fontsize=20, color='red')
> 
> # X-axis label
> plt.xlabel('X-axis')
> 
> # Y-axis label
> plt.ylabel('Y-axis')
> 
> # No title
> 
> # No legend added
> # plt.legend()
> 
> # Display the plot
> plt.show()
Screenshot 2024-05-21 at 9 59 23 PM

In this instance, the color palette is showing a the dominance of these 3 colors: (light yellow, black, and red) respectively. The algorithm determines the black color to be the color with most contrast with the white background, thus being chosen as representative of the image's color. Obviously this is an issue in a special case, as the axes don't matter as much as the actual lines which don't contrast with the background well.

Using this color palette strategy, do you have any other suggestions to tackle this specific issue?

@ranashreyas
Copy link
Collaborator

Main is now able to detect alt tags in code generated images

@ranashreyas
Copy link
Collaborator

It should also no longer show buttons to cells that do not exist in the current visible notebook.

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