Skip to content

Commit b72ec2a

Browse files
NalinDalalksen0perminder-17
authored
Improve Accessibility Guidance for describe() Usage (#8101)
* Add fontWidth() and clarify textWidth vs fontWidth docs in attributes.js * updated as per maintainers comment, only documentation is updated * Add fontWidth() and clarify textWidth vs fontWidth docs in attributes.js; simple docs are updated, not code * aded docs for difference between textWidth and fontWidth with respect to whitespace * unnecesaary file introduced, removed it, cleanedup the thing i was supposed to do * docs updated as asked * removed things from previous pr * i think done, if not will ask maintainer * check, merge conflicts * updated the docs as per suggesstion from perminder * fixes as per review * updated the bad code and good code examples, so actually now can diffrentiated b/w them * fix:inverted comma typos * invert typos * invert typos * invert typos * invert typos * invert typos * invert typos * invert typos * invert typos * invert typos * invert typos * invert typos * invert typos * invert typos * invert typos * invert typos * invert typos * invert typos * invert typos * invert typos to do fix * invert typos to do fix * invert typos to do fix * invert typos to do fix * invert typos to do fix * invert typos to do fix * invert typos to do fix * invert typos to do fix * invert typos to do fix * invert typos to do fix * invert typos to do fix * invert typos to do fix * invert typos to do fix * had docs style section repeated, removed to resolve redundancy * Tidy web accessibility updates * Tidy updates to documentation style guide * Tidy documentation style guide table of contents * Tidy web accessibility references in contributor docs * Tidy contributing documentation for describe() * Tidy unintended change in textCore.js * Update contributor_docs/documentation_style_guide.md --------- Co-authored-by: kit <1304340+ksen0@users.noreply.github.com> Co-authored-by: Perminder Singh <127239756+perminder-17@users.noreply.github.com>
1 parent 8125961 commit b72ec2a

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed

contributor_docs/contributing_to_the_p5js_reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ Finally, for every example you add, you are required to use the p5.js function `
308308
* </div>
309309
```
310310

311-
For more on `describe()` visit the [web accessibility contributor documentation](./web_accessibility/#describe).
311+
For more on `describe()` visit the [web accessibility contributor documentation](./web_accessibility/#describe), and the [Writing Accessible Canvas Descriptions](https://p5js.org/tutorials/writing-accessible-canvas-descriptions/) tutorial.
312312

313313
With all the above you should have most of the tools needed to write and edit p5.js reference comments. However, there are a few more specialized usage of JSDoc style reference comments that you may come across in p5.js. These are situationally useful and not something that you need often.
314314

contributor_docs/documentation_style_guide.md

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Our community is large and diverse. Many people learn to code using p5.js, and a
2525
### Code
2626
- [Code Samples](#code-samples)
2727
- [Comments](#comments)
28+
- [Accessible Canvas Labels](#accessible-canvas-labels)
2829
- [Whitespace](#whitespace)
2930
- [Semicolons](#semicolons)
3031
- [Naming Conventions](#naming-conventions)
@@ -116,7 +117,7 @@ Always use `let` to declare variables.
116117

117118
**Pronouns**
118119

119-
| Recommended | Not Recommended |
120+
| Recommended | Not Recommended |
120121
| -- | -- |
121122
| they | he or she |
122123
| them | him or her |
@@ -142,7 +143,7 @@ Always use `let` to declare variables.
142143

143144
The following terminology is adapted from the WordPress documentation guidelines for [Writing inclusive documentation](https://make.wordpress.org/docs/style-guide/general-guidelines/inclusivity/#accessibility-terminology). For more background on people-first language, see the CDC's guide on [Communicating With and About People with Disabilities](https://www.cdc.gov/ncbddd/disabilityandhealth/materials/factsheets/fs-communicating-with-people.html).
144145

145-
| Recommended | Not Recommended |
146+
| Recommended | Not Recommended |
146147
| -- | -- |
147148
| person with disability | the disabled, handicapped, differently abled, challenged, abnormal |
148149
| person without disability | normal person, healthy person, able-bodied |
@@ -230,6 +231,50 @@ let magicWord = 'Please';
230231

231232
```
232233

234+
235+
**[⬆ back to top](#table-of-contents)**
236+
237+
## Accessible Canvas Labels
238+
239+
- Use `describe()` to in p5.js example code, to add labels to your canvas so that it’s readable for screen readers.
240+
241+
> Why? It makes examples accessible to screen readers, and models how to write good canvas labels.
242+
243+
244+
```javascript
245+
// Good.
246+
function setup() {
247+
createCanvas(100, 100);
248+
describe('A red heart in the bottom right corner of a pink background.');
249+
}
250+
251+
// Bad.
252+
function setup() {
253+
createCanvas(100, 100);
254+
describe('heart shape');
255+
}
256+
257+
// Good.
258+
function draw() {
259+
background(220);
260+
fill(0, 255, 0);
261+
ellipse(mouseX, 50, 40, 40);
262+
// Label updates with shape's translation.
263+
describe(`A green circle at x pos ${round(mouseX)} moving with the mouse pointer.`, LABEL);
264+
}
265+
```
266+
267+
- Don’t use screen reader labels as a way of commenting your code. Labels should only summarize the resulting visual elements within a canvas.
268+
269+
- Don’t overuse screen reader labels, as you may end up complicating the screen reader’s interpretation of the canvas rather than helping it.
270+
271+
- Do make your label descriptions short and accurate. The recommended length for label descriptions is one to two sentences. Use full sentences for your labels, and write in the present tense when describing elements.
272+
273+
The above examples and suggestions are based on the [Writing Accessible Canvas Descriptions tutorial](https://p5js.org/tutorials/writing-accessible-canvas-descriptions/). This tutorial gives more detailed guidance, and includes other ways to label your canvas, in addition to `describe()`: `describeElement()`, `textOutput()`, and `gridOutput()`.
274+
275+
To understand the structure of p5.js’ web accessibility features for contributors, see the [Web Accessibility Contributor Doc](./web_accessibility.md#user-generated-accessible-canvas-descriptions).
276+
277+
233278
**[⬆ back to top](#table-of-contents)**
234279

235280
## Whitespace

contributor_docs/web_accessibility.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ This description is followed by a list of shapes where the color, position, and
5151
> orange circle at top left covering 1% of the canvas.\
5252
> fuchsia square, at bottom right, covering 2% of the canvas.
5353
54-
Each element can be selected to get more details. A table of elements is also provided. In this table, each element’s shape, color, location, coordinates, and area are described:
54+
Each element can be selected to get more details. A table of elements is also provided. In this table, each element’s shape, color, location, coordinates, and area are described:
5555

5656
> orange circle location=top left area=1%\
57-
> fuchsia square location = bottom right area = 2%
57+
> fuchsia square location = bottom right area = 2%
5858
5959
<details>
6060
<summary>This generates the following HTML:</summary>
@@ -100,7 +100,7 @@ Each element can be selected to get more details. A table of elements is also pr
100100

101101
`gridOutput()` lays out the content of the canvas in the form of a grid using an HTML table element. Each shape’s location in the grid is based on its spatial location on the canvas. A brief description of the canvas is available before the table output. This description includes the color of the background, size of the canvas, number of objects, and object types:
102102

103-
> lavender blue canvas, 400 by 400 pixels, contains 2 shapes: 1 circle 1 square
103+
> lavender blue canvas, 400 by 400 pixels, contains 2 shapes: 1 circle 1 square
104104
105105
Each shape’s description is placed in a cell of the table depending on its location on the canvas. Each description includes the color and type of shape:
106106

@@ -123,8 +123,8 @@ The generated HTML is as follows:
123123
<div id="defaultCanvas0gridOutput">
124124
Grid Output
125125
<p id="defaultCanvas0gridOutput_summary" aria-label="grid output summary">
126-
white canvas, 400 by 400 pixels, contains 2 shapes: 1 circle 1 square
127-
</p>
126+
white canvas, 400 by 400 pixels, contains 2 shapes: 1 circle 1 square
127+
</p>
128128
<table id="defaultCanvas0gridOutput_map" summary="grid output content">
129129
<tbody>
130130
<tr></tr>
@@ -272,7 +272,7 @@ The page will output:
272272

273273
### describeElement()
274274

275-
The `describeElement()` function creates a screen reader-accessible description for groups of shapes that create meaning together. For example, a custom-drawn “heart” shape made out of multiple lines of code. The first parameter should be a string with the name of the element, for example, “Heart”. The second parameter should be a string with the description of the element, for example, “A red heart in the bottom-right corner.” The third parameter is optional. If a user passes `LABEL` as a third parameter, an additional `<div>` element is inserted next to the `<canvas>` element. The new \<div> will contain a visible version of the same description embedded in the `<canvas>` element.
275+
The `describeElement()` function creates a screen reader-accessible description for groups of shapes that create meaning together. For example, a custom-drawn “heart” shape made out of multiple lines of code. The first parameter should be a string with the name of the element, for example, “Heart”. The second parameter should be a string with the description of the element, for example, “A red heart in the bottom-right corner.” The third parameter is optional. If a user passes `LABEL` as a third parameter, an additional `<div>` element is inserted next to the `<canvas>` element. The new \<div> will contain a visible version of the same description embedded in the `<canvas>` element.
276276

277277
`describeElement()` is supported by several functions in [src/accessibility/describe.js](https://github.com/processing/p5.js/blob/main/src/accessibility/describe.js):
278278

@@ -300,4 +300,3 @@ function setup() {
300300
The page will output:
301301

302302
![A p5.js canvas, followed by two lines of description: "A red heart and yellow circle over a pink background," and "Heart: A red heart in the bottom-right corner."](images/sketch-text-output3.png)
303-

0 commit comments

Comments
 (0)