options for plottingยค
the default table representation should have an accompanying form to it. in this notebook, we design a common pattern form changes views of stylized tables. radio groups and checkbox groups are useful for these styling choicess.
from nbconvert_a11y.repr import get_table, new, TableOptions
from nbconvert_a11y.table import aria
bs4.Tag._repr_html_ = bs4.Tag.prettify
df = DataFrame(numpy.random.randn(30, 3), None, list("xyz"))
df.iloc[0] *= 0
df.iloc[-1] = df.iloc[:-1].mean()
section = df.T.pipe(get_table, id="xyz", options=TableOptions(figcaption=TableOptions.Position.last))
section.table.attrs.update(**{"class": "xyz"})
%%
options = {
"color everything red":
```css
#xyz {color: red;}
```
, "big text":
```css
#xyz{font-size: 300%;}
```
}
%%
update_view =\
```text/javascript
document.querySelectorAll(`[name=%s][aria-controls]`).forEach((object)=>{
var target = document.getElementById(object.getAttribute(`aria-controls`));
(target.tagName == `STYLE`) && target.setAttribute("media", object.checked ? "all" : "none");
});
```
def choices(options, name, id=None, kind="radio", default=0):
id = "xyz"
ul = new("ul")
for i, (label, css) in enumerate(options.items()):
id = F"{id}-{name}-style"
ul.append(new("li", new("label", new("input", type=kind, name=name, onchange=update_view%name, **aria(controls=id)), label), new("style", css, id=id, media="none")))
return ul
section.form.append(choices(options, "views"))
section.form.append(choices(options, "checks", kind="checkbox"))
section