Skip to content

Commit 51f7dba

Browse files
author
Luis Morales-Navarro
committed
comments on colorNamer and describe
1 parent 291691a commit 51f7dba

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

contributor_docs/web_accessibility.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,12 @@ The `describe()` function creates a screen reader accessible description for the
8383

8484
`describe()` is supported by several functions in [src/accessibility/describe.js](https://github.com/processing/p5.js/blob/main/src/accessibility/describe.js):
8585
* `_descriptionText()`: Checks that text is not `LABEL` or `FALLBACK` and ensures text ends with a punctuation mark. If the text does not end with '.', ',', ';', '?', '!', this function adds a '.' at the end of the string. Returns text.
86-
* `_describeFallbackHTML()`: Creates fallback HTML structure for the canvas.
87-
* `_describeLabelHTML()`: This function is only called when the second parameter of `_describe()` is `LABEL`. It creates a div adjacent to the canvas element for the description text.
86+
* `_describeHTML()`: Creates fallback HTML structure for the canvas. If the second parameter of `_describe()` is `LABEL`, this function creates a div adjacent to the canvas element for the description text.
8887

8988
### describeElement()
9089
The `describeElement()` function creates a screen reader accessible description for sketch elements or groups of shapes that create meaning together. The first parameter should be a string with the name of the element, the second parameter should be a string with the description of the element. The third parameter is optional. If specified, it determines how the description is displayed. All element descriptions become part of the sub DOM of the canvas element. If a user passes `LABEL` as a third parameter, an additional div with the element description adjacent to the canvas is created.
9190

9291
`describeElement()` is supported by several functions in [src/accessibility/describe.js](https://github.com/processing/p5.js/blob/main/src/accessibility/describe.js):
9392
* `_elementName()`: Checks that element name is not `LABEL` or `FALLBACK` and ensures text ends with a colon. Returns element name.
9493
* `_descriptionText()`: Checks that text is not `LABEL` or `FALLBACK` and ensures text ends with a punctuation mark. If the text does not end with '.', ',', ';', '?', '!', this function adds a '.' at the end of the string. Returns text.
95-
* `_describeElementFallbackHTML()`: Creates fallback HTML structure for the canvas.
96-
* `_describeElementLabelHTML()`: This function is only called when the second parameter of `_describeElement()` is `LABEL`. It creates a div adjacent to the canvas element for the description text.
94+
* `_describeElementHTML()`: Creates fallback HTML structure for the canvas. When the second parameter of `_describeElement()` is `LABEL`, this function creates a div adjacent to the canvas element for the descriptions.

src/accessibility/color_namer.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,19 +622,25 @@ const colorLookUp = [
622622
//returns text with color name
623623
function _calculateColor(hsb) {
624624
let colortext;
625+
//round hue
625626
if (hsb[0] !== 0) {
626627
hsb[0] = Math.round(hsb[0] * 100);
627628
let hue = hsb[0].toString().split('');
628629
const last = hue.length - 1;
629630
hue[last] = parseInt(hue[last]);
631+
//if last digit of hue is < 2.5 make it 0
630632
if (hue[last] < 2.5) {
631633
hue[last] = 0;
634+
//if last digit of hue is >= 2.5 and less than 7.5 make it 5
632635
} else if (hue[last] >= 2.5 && hue[last] < 7.5) {
633636
hue[last] = 5;
634637
}
638+
//if hue only has two digits
635639
if (hue.length === 2) {
636640
hue[0] = parseInt(hue[0]);
641+
//if last is greater than 7.5
637642
if (hue[last] >= 7.5) {
643+
//add one to the tens
638644
hue[last] = 0;
639645
hue[0] = hue[0] + 1;
640646
}
@@ -647,6 +653,9 @@ function _calculateColor(hsb) {
647653
}
648654
}
649655
}
656+
//map brightness from 0 to 1
657+
hsb[2] = hsb[2] / 255;
658+
//round saturation and brightness
650659
for (let i = hsb.length - 1; i >= 1; i--) {
651660
if (hsb[i] <= 0.25) {
652661
hsb[i] = 0;
@@ -656,11 +665,14 @@ function _calculateColor(hsb) {
656665
hsb[i] = 1;
657666
}
658667
}
668+
//after rounding, if the values are hue 0, saturation 0 and brightness 1
669+
//look at color exceptions which includes several tones from white to gray
659670
if (hsb[0] === 0 && hsb[1] === 0 && hsb[2] === 1) {
671+
//round original hsb values
660672
for (let i = 2; i >= 0; i--) {
661-
//for (let i = originalHSB.length - 1; i >= 0; i--) {
662673
originalHSB[i] = Math.round(originalHSB[i] * 10000) / 10000;
663674
}
675+
//compare with the values in the colorExceptions array
664676
for (let e = 0; e < colorExceptions.length; e++) {
665677
if (
666678
colorExceptions[e].h === originalHSB[0] &&
@@ -670,10 +682,12 @@ function _calculateColor(hsb) {
670682
colortext = colorExceptions[e].name;
671683
break;
672684
} else {
685+
//if there is no match return white
673686
colortext = 'white';
674687
}
675688
}
676689
} else {
690+
//otherwise, compare with values in colorLookUp
677691
for (let i = 0; i < colorLookUp.length; i++) {
678692
if (
679693
colorLookUp[i].h === hsb[0] &&

src/accessibility/describe.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ function _descriptionText(text) {
239239
* Helper functions for describe()
240240
*/
241241

242-
//creates fallback HTML structure
242+
//creates HTML structure for canvas descriptions
243243
p5.prototype._describeHTML = function(type, text) {
244244
const cnvId = this.canvas.id;
245245
if (type === 'fallback') {
@@ -327,7 +327,7 @@ function _elementName(name) {
327327
return name;
328328
}
329329

330-
//creates fallback HTML structure for element descriptions
330+
//creates HTML structure for element descriptions
331331
p5.prototype._describeElementHTML = function(type, name, text) {
332332
const cnvId = this.canvas.id;
333333
if (type === 'fallback') {

test/unit/accessibility/outputs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ suite('outputs', function() {
260260
});
261261
test('should create text output for point()', function() {
262262
return new Promise(function(resolve, reject) {
263-
expected = 'fuchsia point, location = bottom right';
263+
expected = 'dark fuchsia point, location = bottom right';
264264
new p5(function(p) {
265265
p.setup = function() {
266266
let cnv = p.createCanvas(100, 100);

0 commit comments

Comments
 (0)