apca-introduction

The missing introduction to APCA  https://p.ce9e.org/apca-introduction/
git clone https://git.ce9e.org/apca-introduction.git

commit
4ed86c8a70fc9bde482b2c2f701d07420cd3dd6f
parent
b39fb7a6e86960226fd89a9767e1a083fbdff02b
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2022-07-29 04:12
highlight diagonals in coverage tables

Diffstat

M analysis.md 59 +++++++++++++++++++++++++++++++----------------------------
M plots/coverage.py 8 +++++---

2 files changed, 36 insertions, 31 deletions


diff --git a/analysis.md b/analysis.md

@@ -389,30 +389,33 @@ and 75 loosely correspond to 3, 4.5, and 7 in WCAG 2.x.
  389   389 
  390   390 Again I generated random color pairs and used them to compare APCA to WCAG 2.x:
  391   391 
  392    -1 
  393    -1 |        |  < 15 | 15-30 | 30-45 | 45-60 | 60-75 | 75-90 |  > 90 | total |
  394    -1 | ------:| -----:| -----:| -----:| -----:| -----:| -----:| -----:| -----:|
  395    -1 |    < 3 |  35.3 |  25.0 |  11.3 |   1.7 |   0.0 |   0.0 |   0.0 |  73.3 |
  396    -1 |  3-4.5 |   0.0 |   0.8 |   6.2 |   6.5 |   0.8 |   0.0 |   0.0 |  14.3 |
  397    -1 |  4.5-7 |   0.0 |   0.0 |   0.8 |   3.8 |   3.7 |   0.2 |   0.0 |   8.6 |
  398    -1 |    > 7 |   0.0 |   0.0 |   0.0 |   0.2 |   1.8 |   1.6 |   0.1 |   3.8 |
  399    -1 |  total |  35.3 |  25.8 |  18.3 |  12.3 |   6.4 |   1.8 |   0.1 |       |
   -1   392 |        |    < 15 |   15-30 |  30-45 |  45-60 |  60-75 |  75-90 |   > 90 |   total |
   -1   393 | ------:| -------:| -------:| ------:| ------:| ------:| ------:| ------:| -------:|
   -1   394 |    < 3 |  35.3\* |  25.0\* | 11.3\* |    1.7 |    0.0 |    0.0 |    0.0 |    73.3 |
   -1   395 |  3-4.5 |     0.0 |     0.8 |    6.2 |  6.5\* |    0.8 |    0.0 |    0.0 |    14.3 |
   -1   396 |  4.5-7 |     0.0 |     0.0 |    0.8 |    3.8 |  3.7\* |    0.2 |    0.0 |     8.6 |
   -1   397 |    > 7 |     0.0 |     0.0 |    0.0 |    0.2 |    1.8 |  1.6\* |  0.1\* |     3.8 |
   -1   398 |  total |    35.3 |    25.8 |   18.3 |   12.3 |    6.4 |    1.8 |    0.1 |  83.5\* |
  400   399 
  401   400 The columns correspond to APCA thresholds, the rows correspond to WCAG 2.x
  402   401 thresholds. For example, 6.2 % of the generated color pairs pass WCAG 2.x with
  403   402 a contrast above 3, but fail APCA with a contrast below 45 (assuming a
  404   403 conventional spatial frequency).
  405   404 
  406    -1 |          |  < 15 | 15-30 | 30-45 | 45-60 | 60-75 | 75-90 |  > 90 | total |
  407    -1 | --------:| -----:| -----:| -----:| -----:| -----:| -----:| -----:| -----:|
  408    -1 |    < 1.6 |  33.7 |   0.7 |   0.0 |   0.0 |   0.0 |   0.0 |   0.0 |  34.5 |
  409    -1 |  1.6-2.5 |   1.5 |  23.5 |   0.8 |   0.0 |   0.0 |   0.0 |   0.0 |  25.9 |
  410    -1 |  2.5-3.8 |   0.0 |   1.5 |  15.8 |   0.2 |   0.0 |   0.0 |   0.0 |  17.5 |
  411    -1 |  3.8-5.7 |   0.0 |   0.0 |   1.7 |  10.4 |   0.0 |   0.0 |   0.0 |  12.2 |
  412    -1 |  5.7-8.7 |   0.0 |   0.0 |   0.0 |   1.7 |   5.7 |   0.0 |   0.0 |   7.4 |
  413    -1 | 8.7-13.2 |   0.0 |   0.0 |   0.0 |   0.0 |   0.6 |   1.8 |   0.0 |   2.4 |
  414    -1 |   > 13.2 |   0.0 |   0.0 |   0.0 |   0.0 |   0.0 |   0.0 |   0.1 |   0.2 |
  415    -1 |    total |  35.3 |  25.8 |  18.3 |  12.3 |   6.4 |   1.8 |   0.1 |       |
   -1   405 The \* indicate cases where both a algorithms agree on a threshold level. The
   -1   406 cell in the bottom right is the total number of cases where both algorithms
   -1   407 agree, so it can be seen as an indicator of how similar the algorithms are.
   -1   408 
   -1   409 |           |    < 15 |   15-30 |   30-45 |   45-60 |   60-75 |   75-90 |    > 90 |   total |
   -1   410 | ---------:| -------:| -------:| -------:| -------:| -------:| -------:| -------:| -------:|
   -1   411 |     < 1.6 |  33.7\* |     0.7 |     0.0 |     0.0 |     0.0 |     0.0 |     0.0 |    34.5 |
   -1   412 |   1.6-2.5 |     1.5 |  23.5\* |     0.8 |     0.0 |     0.0 |     0.0 |     0.0 |    25.9 |
   -1   413 |   2.5-3.8 |     0.0 |     1.5 |  15.8\* |     0.2 |     0.0 |     0.0 |     0.0 |    17.5 |
   -1   414 |   3.8-5.7 |     0.0 |     0.0 |     1.7 |  10.4\* |     0.0 |     0.0 |     0.0 |    12.2 |
   -1   415 |   5.7-8.7 |     0.0 |     0.0 |     0.0 |     1.7 |   5.7\* |     0.0 |     0.0 |     7.4 |
   -1   416 |  8.7-13.2 |     0.0 |     0.0 |     0.0 |     0.0 |     0.6 |   1.8\* |     0.0 |     2.4 |
   -1   417 |    > 13.2 |     0.0 |     0.0 |     0.0 |     0.0 |     0.0 |     0.0 |   0.1\* |     0.2 |
   -1   418 |     total |    35.3 |    25.8 |    18.3 |    12.3 |     6.4 |     1.8 |     0.1 |  91.0\* |
  416   419 
  417   420 The second table compares APCA to the modified WCAG 2.x contrast. The
  418   421 thresholds were derived by applying the normalization steps described above to
@@ -420,16 +423,16 @@ the APCA thresholds. As expected, most color pairs fall into the same category
  420   423 with both formulas. For example, only 1.7 % pass the modified WCAG 2.x with a
  421   424 contrast above 3.8, but fail APCA with a contrast below 45.
  422   425 
  423    -1 |        |  < 15 | 15-30 | 30-45 | 45-60 | 60-75 | 75-90 |  > 90 | total |
  424    -1 | ------:| -----:| -----:| -----:| -----:| -----:| -----:| -----:| -----:|
  425    -1 |   < 15 |  33.6 |   1.3 |   0.0 |   0.0 |   0.0 |   0.0 |   0.0 |  34.9 |
  426    -1 |  15-30 |   1.3 |  23.1 |   1.3 |   0.0 |   0.0 |   0.0 |   0.0 |  25.7 |
  427    -1 |  30-45 |   0.0 |   1.4 |  16.5 |   1.1 |   0.0 |   0.0 |   0.0 |  18.9 |
  428    -1 |  45-60 |   0.0 |   0.0 |   1.2 |  10.4 |   0.7 |   0.0 |   0.0 |  12.3 |
  429    -1 |  60-75 |   0.0 |   0.0 |   0.0 |   0.8 |   5.2 |   0.3 |   0.0 |   6.2 |
  430    -1 |  75-90 |   0.0 |   0.0 |   0.0 |   0.0 |   0.3 |   1.5 |   0.0 |   1.8 |
  431    -1 |   > 90 |   0.0 |   0.0 |   0.0 |   0.0 |   0.0 |   0.0 |   0.1 |   0.1 |
  432    -1 |  total |  34.9 |  25.8 |  18.9 |  12.3 |   6.2 |   1.8 |   0.1 |       |
   -1   426 |         |    < 15 |   15-30 |   30-45 |   45-60 |   60-75 |   75-90 |    > 90 |   total |
   -1   427 | -------:| -------:| -------:| -------:| -------:| -------:| -------:| -------:| -------:|
   -1   428 |    < 15 |  33.6\* |     1.3 |     0.0 |     0.0 |     0.0 |     0.0 |     0.0 |    34.9 |
   -1   429 |   15-30 |     1.3 |  23.1\* |     1.3 |     0.0 |     0.0 |     0.0 |     0.0 |    25.7 |
   -1   430 |   30-45 |     0.0 |     1.4 |  16.5\* |     1.1 |     0.0 |     0.0 |     0.0 |    18.9 |
   -1   431 |   45-60 |     0.0 |     0.0 |     1.2 |  10.4\* |     0.7 |     0.0 |     0.0 |    12.3 |
   -1   432 |   60-75 |     0.0 |     0.0 |     0.0 |     0.8 |   5.2\* |     0.3 |     0.0 |     6.2 |
   -1   433 |   75-90 |     0.0 |     0.0 |     0.0 |     0.0 |     0.3 |   1.5\* |     0.0 |     1.8 |
   -1   434 |    > 90 |     0.0 |     0.0 |     0.0 |     0.0 |     0.0 |     0.0 |   0.1\* |     0.1 |
   -1   435 |   total |    34.9 |    25.8 |    18.9 |    12.3 |     6.2 |     1.8 |     0.1 |  90.4\* |
  433   436 
  434   437 The third table compares APCA to itself, but with foreground and background
  435   438 switched. WCAG 2.x does not make a difference between foreground and

diff --git a/plots/coverage.py b/plots/coverage.py

@@ -52,8 +52,8 @@ def iter_levels(levels):
   52    52 			yield levels[i - 1], levels[i]
   53    53 
   54    54 
   55    -1 def print_row(row, sep=' | ', end=['']):
   56    -1 	_row = [''] + [f'{x:.1f}' for x in row] + end
   -1    55 def print_row(row, sep=' | '):
   -1    56 	_row = [''] + [f'{x:.1f}' for x in row] + ['']
   57    57 	_row = [f'{s: >5}' for s in _row]
   58    58 	print(sep.join(_row).strip())
   59    59 
@@ -64,7 +64,9 @@ def print_table(rows):
   64    64 
   65    65 	r = np.array(rows)
   66    66 	totals = [sum(r[:, i]) for i in range(r.shape[1])]
   67    -1 	print_row(totals, end=['', ''])
   -1    67 	if len(rows) == len(rows[0]):
   -1    68 		totals.append(sum(rows[i][i] for i in range(len(rows))))
   -1    69 	print_row(totals)
   68    70 	print()
   69    71 
   70    72