disability-access-charts 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- disability_access_charts-0.0.1/.gitignore +46 -0
- disability_access_charts-0.0.1/LICENSE +21 -0
- disability_access_charts-0.0.1/PKG-INFO +31 -0
- disability_access_charts-0.0.1/README.md +15 -0
- disability_access_charts-0.0.1/pyproject.toml +27 -0
- disability_access_charts-0.0.1/src/disability_access_charts/__init__.py +16 -0
- disability_access_charts-0.0.1/src/disability_access_charts/contrast.py +54 -0
- disability_access_charts-0.0.1/src/disability_access_charts/py.typed +0 -0
- disability_access_charts-0.0.1/tests/test_contrast.py +46 -0
- disability_access_charts-0.0.1/tests/test_smoke.py +5 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# --- Restricted zone: licensed microdata must never be committed ---
|
|
2
|
+
data/restricted/
|
|
3
|
+
|
|
4
|
+
# Python
|
|
5
|
+
__pycache__/
|
|
6
|
+
*.py[cod]
|
|
7
|
+
.venv/
|
|
8
|
+
*.egg-info/
|
|
9
|
+
build/
|
|
10
|
+
dist/
|
|
11
|
+
.pytest_cache/
|
|
12
|
+
.ruff_cache/
|
|
13
|
+
.coverage
|
|
14
|
+
coverage.xml
|
|
15
|
+
htmlcov/
|
|
16
|
+
|
|
17
|
+
# Local databases (public data ships as Parquet, not DuckDB)
|
|
18
|
+
*.duckdb
|
|
19
|
+
*.duckdb.wal
|
|
20
|
+
|
|
21
|
+
# LLM alt-text cache is local; regenerate from data
|
|
22
|
+
.disability_access_charts_cache/
|
|
23
|
+
|
|
24
|
+
# dbt
|
|
25
|
+
target/
|
|
26
|
+
dbt_packages/
|
|
27
|
+
logs/
|
|
28
|
+
|
|
29
|
+
# Node / site
|
|
30
|
+
node_modules/
|
|
31
|
+
site/dist/
|
|
32
|
+
|
|
33
|
+
# R / renv
|
|
34
|
+
.Rhistory
|
|
35
|
+
.RData
|
|
36
|
+
.Rproj.user/
|
|
37
|
+
|
|
38
|
+
# Secrets
|
|
39
|
+
.env
|
|
40
|
+
.env.*
|
|
41
|
+
|
|
42
|
+
# OS / editors
|
|
43
|
+
.DS_Store
|
|
44
|
+
Thumbs.db
|
|
45
|
+
.vscode/
|
|
46
|
+
.idea/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 batestguy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: disability-access-charts
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Accessible Plotly charts: alt-text checked against the data, a CI-ready audit, and a data-table fallback for every chart
|
|
5
|
+
Project-URL: Homepage, https://github.com/batestguy/curb-cut
|
|
6
|
+
Project-URL: Issues, https://github.com/batestguy/curb-cut/issues
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: a11y,accessibility,charts,disability,plotly,screen-reader,wcag
|
|
10
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# disability-access-charts
|
|
18
|
+
|
|
19
|
+
Accessible charts for Python, built by and for disabled data users. The goal: every chart ships with alt-text that is checked against its data, an accessibility audit you can run in CI, and a data-table fallback.
|
|
20
|
+
|
|
21
|
+
**Status: early (0.0.x).** This release contains only the WCAG 2.2 contrast checks; the chart API follows. Part of the [Curb Cut](https://github.com/batestguy/curb-cut) project.
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from disability_access_charts import contrast_ratio, passes_text, passes_non_text
|
|
25
|
+
|
|
26
|
+
contrast_ratio("#0072b2", "#ffffff") # 5.19
|
|
27
|
+
passes_text("#767676", "#ffffff") # True (SC 1.4.3, 4.5:1)
|
|
28
|
+
passes_non_text("#f0e442", "#ffffff") # False (SC 1.4.11, 3:1)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
MIT licensed.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# disability-access-charts
|
|
2
|
+
|
|
3
|
+
Accessible charts for Python, built by and for disabled data users. The goal: every chart ships with alt-text that is checked against its data, an accessibility audit you can run in CI, and a data-table fallback.
|
|
4
|
+
|
|
5
|
+
**Status: early (0.0.x).** This release contains only the WCAG 2.2 contrast checks; the chart API follows. Part of the [Curb Cut](https://github.com/batestguy/curb-cut) project.
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from disability_access_charts import contrast_ratio, passes_text, passes_non_text
|
|
9
|
+
|
|
10
|
+
contrast_ratio("#0072b2", "#ffffff") # 5.19
|
|
11
|
+
passes_text("#767676", "#ffffff") # True (SC 1.4.3, 4.5:1)
|
|
12
|
+
passes_non_text("#f0e442", "#ffffff") # False (SC 1.4.11, 3:1)
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
MIT licensed.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "disability-access-charts"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "Accessible Plotly charts: alt-text checked against the data, a CI-ready audit, and a data-table fallback for every chart"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
keywords = ["accessibility", "a11y", "disability", "wcag", "charts", "plotly", "screen-reader"]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Development Status :: 2 - Pre-Alpha",
|
|
12
|
+
"Programming Language :: Python :: 3",
|
|
13
|
+
"Topic :: Scientific/Engineering :: Visualization",
|
|
14
|
+
"Intended Audience :: Science/Research",
|
|
15
|
+
]
|
|
16
|
+
dependencies = []
|
|
17
|
+
|
|
18
|
+
[project.urls]
|
|
19
|
+
Homepage = "https://github.com/batestguy/curb-cut"
|
|
20
|
+
Issues = "https://github.com/batestguy/curb-cut/issues"
|
|
21
|
+
|
|
22
|
+
[build-system]
|
|
23
|
+
requires = ["hatchling>=1.26"]
|
|
24
|
+
build-backend = "hatchling.build"
|
|
25
|
+
|
|
26
|
+
[tool.hatch.build.targets.wheel]
|
|
27
|
+
packages = ["src/disability_access_charts"]
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Accessible charts: alt-text checked against the data, a CI-ready audit,
|
|
2
|
+
and a data-table fallback for every chart.
|
|
3
|
+
|
|
4
|
+
Early release: only the WCAG contrast checks exist so far.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from disability_access_charts.contrast import (
|
|
8
|
+
contrast_ratio,
|
|
9
|
+
passes_non_text,
|
|
10
|
+
passes_text,
|
|
11
|
+
relative_luminance,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
__version__ = "0.0.1"
|
|
15
|
+
|
|
16
|
+
__all__ = ["contrast_ratio", "passes_non_text", "passes_text", "relative_luminance"]
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""WCAG 2.2 contrast checks for SC 1.4.3 (text) and SC 1.4.11 (non-text)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
|
|
7
|
+
_HEX = re.compile(r"^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$")
|
|
8
|
+
|
|
9
|
+
TEXT_MIN = 4.5
|
|
10
|
+
"""SC 1.4.3 minimum for normal-size text."""
|
|
11
|
+
LARGE_TEXT_MIN = 3.0
|
|
12
|
+
"""SC 1.4.3 minimum for large text (18pt, or 14pt bold)."""
|
|
13
|
+
NON_TEXT_MIN = 3.0
|
|
14
|
+
"""SC 1.4.11 minimum for graphical objects such as chart marks."""
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _channels(color: str) -> tuple[int, int, int]:
|
|
18
|
+
match = _HEX.match(color.strip())
|
|
19
|
+
if not match:
|
|
20
|
+
raise ValueError(f"Expected a hex colour like '#1a2b3c' or '#abc', got {color!r}")
|
|
21
|
+
digits = match.group(1)
|
|
22
|
+
if len(digits) == 3:
|
|
23
|
+
digits = "".join(d * 2 for d in digits)
|
|
24
|
+
return int(digits[0:2], 16), int(digits[2:4], 16), int(digits[4:6], 16)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def relative_luminance(color: str) -> float:
|
|
28
|
+
"""Relative luminance of an sRGB hex colour, as defined by WCAG 2.2."""
|
|
29
|
+
|
|
30
|
+
def linear(channel: int) -> float:
|
|
31
|
+
c = channel / 255
|
|
32
|
+
return c / 12.92 if c <= 0.04045 else ((c + 0.055) / 1.055) ** 2.4
|
|
33
|
+
|
|
34
|
+
r, g, b = (linear(c) for c in _channels(color))
|
|
35
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def contrast_ratio(foreground: str, background: str) -> float:
|
|
39
|
+
"""Contrast ratio between two hex colours, from 1.0 to 21.0."""
|
|
40
|
+
lighter, darker = sorted(
|
|
41
|
+
(relative_luminance(foreground), relative_luminance(background)), reverse=True
|
|
42
|
+
)
|
|
43
|
+
return (lighter + 0.05) / (darker + 0.05)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def passes_text(foreground: str, background: str, *, large: bool = False) -> bool:
|
|
47
|
+
"""Whether text in ``foreground`` on ``background`` meets SC 1.4.3 (AA)."""
|
|
48
|
+
minimum = LARGE_TEXT_MIN if large else TEXT_MIN
|
|
49
|
+
return contrast_ratio(foreground, background) >= minimum
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def passes_non_text(foreground: str, background: str) -> bool:
|
|
53
|
+
"""Whether a chart mark in ``foreground`` on ``background`` meets SC 1.4.11."""
|
|
54
|
+
return contrast_ratio(foreground, background) >= NON_TEXT_MIN
|
|
File without changes
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from disability_access_charts import (
|
|
3
|
+
contrast_ratio,
|
|
4
|
+
passes_non_text,
|
|
5
|
+
passes_text,
|
|
6
|
+
relative_luminance,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def test_black_on_white_is_maximum() -> None:
|
|
11
|
+
assert contrast_ratio("#000000", "#ffffff") == pytest.approx(21.0)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_identical_colours_are_minimum() -> None:
|
|
15
|
+
assert contrast_ratio("#777777", "#777777") == pytest.approx(1.0)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def test_order_does_not_matter() -> None:
|
|
19
|
+
assert contrast_ratio("#0072b2", "#ffffff") == contrast_ratio("#ffffff", "#0072b2")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_shorthand_hex_matches_full() -> None:
|
|
23
|
+
assert relative_luminance("#fff") == relative_luminance("#ffffff")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_text_threshold_boundary() -> None:
|
|
27
|
+
# #767676 on white is the well-known lightest grey that passes 4.5:1 (about 4.54).
|
|
28
|
+
assert passes_text("#767676", "#ffffff")
|
|
29
|
+
assert not passes_text("#777777", "#ffffff")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_large_text_uses_lower_threshold() -> None:
|
|
33
|
+
# #949494 on white is about 3.03:1: fails normal text, passes large text.
|
|
34
|
+
assert not passes_text("#949494", "#ffffff")
|
|
35
|
+
assert passes_text("#949494", "#ffffff", large=True)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_okabe_ito_yellow_fails_non_text_on_white() -> None:
|
|
39
|
+
assert not passes_non_text("#f0e442", "#ffffff")
|
|
40
|
+
assert passes_non_text("#0072b2", "#ffffff")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@pytest.mark.parametrize("bad", ["red", "#12345", "#ggg", ""])
|
|
44
|
+
def test_rejects_invalid_colours(bad: str) -> None:
|
|
45
|
+
with pytest.raises(ValueError):
|
|
46
|
+
contrast_ratio(bad, "#ffffff")
|