Skip to content

Commit 9f64f5a

Browse files
authored
ariaLabel, ariaDescription, ariaHidden (#710)
* ariaLabel, ariaDescription * aria-description, not desc * ariaHidden
1 parent 16dbbc9 commit 9f64f5a

File tree

166 files changed

+1215
-1174
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+1215
-1174
lines changed

src/axis.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export class AxisX {
6565
const offsetSign = axis === "top" ? -1 : 1;
6666
const ty = offsetSign * offset + (axis === "top" ? marginTop : height - marginBottom);
6767
return create("svg:g")
68+
.attr("aria-label", `${this.name}-axis`)
6869
.attr("transform", `translate(0,${ty})`)
6970
.call(createAxis(axis === "top" ? axisTop : axisBottom, x, this))
7071
.call(maybeTickRotate, tickRotate)
@@ -150,6 +151,7 @@ export class AxisY {
150151
const offsetSign = axis === "left" ? -1 : 1;
151152
const tx = offsetSign * offset + (axis === "right" ? width - marginRight : marginLeft);
152153
return create("svg:g")
154+
.attr("aria-label", `${this.name}-axis`)
153155
.attr("transform", `translate(${tx},0)`)
154156
.call(createAxis(axis === "right" ? axisRight : axisLeft, y, this))
155157
.call(maybeTickRotate, tickRotate)

src/marks/area.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {maybeIdentityX, maybeIdentityY} from "../transforms/identity.js";
88
import {maybeStackX, maybeStackY} from "../transforms/stack.js";
99

1010
const defaults = {
11+
ariaLabel: "area",
1112
strokeWidth: 1,
1213
strokeMiterlimit: 1
1314
};

src/marks/arrow.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {applyChannelStyles, applyDirectStyles, applyIndirectStyles, applyTransfo
55
import {maybeSameValue} from "./link.js";
66

77
const defaults = {
8+
ariaLabel: "arrow",
89
fill: "none",
910
stroke: "currentColor",
1011
strokeLinecap: "round",

src/marks/bar.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ import {maybeIdentityX, maybeIdentityY} from "../transforms/identity.js";
77
import {maybeIntervalX, maybeIntervalY} from "../transforms/interval.js";
88
import {maybeStackX, maybeStackY} from "../transforms/stack.js";
99

10-
const defaults = {};
11-
1210
export class AbstractBar extends Mark {
13-
constructor(data, channels, options = {}) {
11+
constructor(data, channels, options = {}, defaults) {
1412
super(data, channels, options, defaults);
1513
const {inset = 0, insetTop = inset, insetRight = inset, insetBottom = inset, insetLeft = inset, rx, ry} = options;
1614
this.insetTop = number(insetTop);
@@ -58,6 +56,10 @@ export class AbstractBar extends Mark {
5856
}
5957
}
6058

59+
const defaults = {
60+
ariaLabel: "bar"
61+
};
62+
6163
export class BarX extends AbstractBar {
6264
constructor(data, options = {}) {
6365
const {x1, x2, y} = options;
@@ -68,7 +70,8 @@ export class BarX extends AbstractBar {
6870
{name: "x2", value: x2, scale: "x"},
6971
{name: "y", value: y, scale: "y", type: "band", optional: true}
7072
],
71-
options
73+
options,
74+
defaults
7275
);
7376
}
7477
_transform(selection, {x}, dx, dy) {
@@ -94,7 +97,8 @@ export class BarY extends AbstractBar {
9497
{name: "y2", value: y2, scale: "y"},
9598
{name: "x", value: x, scale: "x", type: "band", optional: true}
9699
],
97-
options
100+
options,
101+
defaults
98102
);
99103
}
100104
_transform(selection, {y}, dx, dy) {

src/marks/cell.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import {identity, indexOf, maybeColorChannel, maybeTuple} from "../options.js";
22
import {AbstractBar} from "./bar.js";
33

4+
const defaults = {
5+
ariaLabel: "cell"
6+
};
7+
48
export class Cell extends AbstractBar {
59
constructor(data, {x, y, ...options} = {}) {
610
super(
@@ -9,7 +13,8 @@ export class Cell extends AbstractBar {
913
{name: "x", value: x, scale: "x", type: "band", optional: true},
1014
{name: "y", value: y, scale: "y", type: "band", optional: true}
1115
],
12-
options
16+
options,
17+
defaults
1318
);
1419
}
1520
_transform() {

src/marks/dot.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {Mark} from "../plot.js";
55
import {applyChannelStyles, applyDirectStyles, applyFrameAnchor, applyIndirectStyles, applyTransform, offset} from "../style.js";
66

77
const defaults = {
8+
ariaLabel: "dot",
89
fill: "none",
910
stroke: "currentColor",
1011
strokeWidth: 1.5

src/marks/frame.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {number} from "../options.js";
44
import {applyDirectStyles, applyIndirectStyles, applyTransform, offset} from "../style.js";
55

66
const defaults = {
7+
ariaLabel: "frame",
78
fill: "none",
89
stroke: "currentColor"
910
};

src/marks/image.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {Mark} from "../plot.js";
55
import {applyChannelStyles, applyDirectStyles, applyIndirectStyles, applyTransform, applyAttr, offset, impliedString, applyFrameAnchor} from "../style.js";
66

77
const defaults = {
8+
ariaLabel: "image",
89
fill: null,
910
stroke: null
1011
};

src/marks/line.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {indexOf, identity, maybeTuple, maybeZ} from "../options.js";
66
import {applyDirectStyles, applyIndirectStyles, applyTransform, applyGroupedChannelStyles, offset} from "../style.js";
77

88
const defaults = {
9+
ariaLabel: "line",
910
fill: "none",
1011
stroke: "currentColor",
1112
strokeWidth: 1.5,

src/marks/link.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {Mark} from "../plot.js";
44
import {applyChannelStyles, applyDirectStyles, applyIndirectStyles, applyTransform, offset} from "../style.js";
55

66
const defaults = {
7+
ariaLabel: "link",
78
fill: "none",
89
stroke: "currentColor",
910
strokeMiterlimit: 1

src/marks/rect.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import {maybeIdentityX, maybeIdentityY} from "../transforms/identity.js";
77
import {maybeIntervalX, maybeIntervalY} from "../transforms/interval.js";
88
import {maybeStackX, maybeStackY} from "../transforms/stack.js";
99

10-
const defaults = {};
10+
const defaults = {
11+
ariaLabel: "rect"
12+
};
1113

1214
export class Rect extends Mark {
1315
constructor(data, options = {}) {

src/marks/rule.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {applyDirectStyles, applyIndirectStyles, applyTransform, applyChannelStyl
66
import {maybeIntervalX, maybeIntervalY} from "../transforms/interval.js";
77

88
const defaults = {
9+
ariaLabel: "rule",
910
fill: null,
1011
stroke: "currentColor"
1112
};

src/marks/text.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {Mark} from "../plot.js";
66
import {applyChannelStyles, applyDirectStyles, applyIndirectStyles, applyAttr, applyTransform, offset, impliedString, applyFrameAnchor} from "../style.js";
77

88
const defaults = {
9+
ariaLabel: "text",
910
strokeLinejoin: "round",
1011
strokeWidth: 3,
1112
paintOrder: "stroke"

src/marks/tick.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {identity, number} from "../options.js";
44
import {applyDirectStyles, applyIndirectStyles, applyTransform, applyChannelStyles, offset} from "../style.js";
55

66
const defaults = {
7+
ariaLabel: "tick",
78
fill: null,
89
stroke: "currentColor"
910
};

src/marks/vector.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {Mark} from "../plot.js";
55
import {applyChannelStyles, applyDirectStyles, applyFrameAnchor, applyIndirectStyles, applyTransform, offset} from "../style.js";
66

77
const defaults = {
8+
ariaLabel: "vector",
89
fill: null,
910
stroke: "currentColor",
1011
strokeWidth: 1.5,

src/plot.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {applyInlineStyles, maybeClassName, styles} from "./style.js";
1010
import {basic} from "./transforms/basic.js";
1111

1212
export function plot(options = {}) {
13-
const {facet, style, caption} = options;
13+
const {facet, style, caption, ariaLabel, ariaDescription} = options;
1414

1515
// className for inline styles
1616
const className = maybeClassName(options.className);
@@ -77,6 +77,8 @@ export function plot(options = {}) {
7777
.attr("width", width)
7878
.attr("height", height)
7979
.attr("viewBox", `0 0 ${width} ${height}`)
80+
.attr("aria-label", ariaLabel)
81+
.attr("aria-description", ariaDescription)
8082
.call(svg => svg.append("style").text(`
8183
.${className} {
8284
display: block;

src/style.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export function styles(
1010
{
1111
title,
1212
href,
13+
ariaLabel: variaLabel,
14+
ariaDescription,
15+
ariaHidden,
1316
target,
1417
fill,
1518
fillOpacity,
@@ -27,6 +30,7 @@ export function styles(
2730
},
2831
channels,
2932
{
33+
ariaLabel: cariaLabel,
3034
fill: defaultFill = "currentColor",
3135
stroke: defaultStroke = "none",
3236
strokeWidth: defaultStrokeWidth,
@@ -102,6 +106,9 @@ export function styles(
102106
}
103107

104108
mark.target = string(target);
109+
mark.ariaLabel = string(cariaLabel);
110+
mark.ariaDescription = string(ariaDescription);
111+
mark.ariaHidden = string(ariaHidden);
105112
mark.opacity = impliedNumber(copacity, 1);
106113
mark.mixBlendMode = impliedString(mixBlendMode, "normal");
107114
mark.paintOrder = impliedString(paintOrder, "normal");
@@ -111,6 +118,7 @@ export function styles(
111118
...channels,
112119
{name: "title", value: title, optional: true},
113120
{name: "href", value: href, optional: true},
121+
{name: "ariaLabel", value: variaLabel, optional: true},
114122
{name: "fill", value: vfill, scale: "color", optional: true},
115123
{name: "fillOpacity", value: vfillOpacity, scale: "opacity", optional: true},
116124
{name: "stroke", value: vstroke, scale: "color", optional: true},
@@ -138,29 +146,34 @@ export function applyTextGroup(selection, T) {
138146
if (T) selection.text(isTemporal(T) ? ([i]) => isoFormat(T[i]) : isNumeric(T) ? (f => ([i]) => f(T[i]))(formatNumber()) : ([i]) => T[i]);
139147
}
140148

141-
export function applyChannelStyles(selection, {target}, {title: L, fill: F, fillOpacity: FO, stroke: S, strokeOpacity: SO, strokeWidth: SW, opacity: O, href: H}) {
149+
export function applyChannelStyles(selection, {target}, {ariaLabel: AL, title: T, fill: F, fillOpacity: FO, stroke: S, strokeOpacity: SO, strokeWidth: SW, opacity: O, href: H}) {
150+
if (AL) applyAttr(selection, "aria-label", i => AL[i]);
142151
if (F) applyAttr(selection, "fill", i => F[i]);
143152
if (FO) applyAttr(selection, "fill-opacity", i => FO[i]);
144153
if (S) applyAttr(selection, "stroke", i => S[i]);
145154
if (SO) applyAttr(selection, "stroke-opacity", i => SO[i]);
146155
if (SW) applyAttr(selection, "stroke-width", i => SW[i]);
147156
if (O) applyAttr(selection, "opacity", i => O[i]);
148157
if (H) applyHref(selection, i => H[i], target);
149-
applyTitle(selection, L);
158+
applyTitle(selection, T);
150159
}
151160

152-
export function applyGroupedChannelStyles(selection, {target}, {title: L, fill: F, fillOpacity: FO, stroke: S, strokeOpacity: SO, strokeWidth: SW, opacity: O, href: H}) {
161+
export function applyGroupedChannelStyles(selection, {target}, {ariaLabel: AL, title: T, fill: F, fillOpacity: FO, stroke: S, strokeOpacity: SO, strokeWidth: SW, opacity: O, href: H}) {
162+
if (AL) applyAttr(selection, "aria-label", ([i]) => AL[i]);
153163
if (F) applyAttr(selection, "fill", ([i]) => F[i]);
154164
if (FO) applyAttr(selection, "fill-opacity", ([i]) => FO[i]);
155165
if (S) applyAttr(selection, "stroke", ([i]) => S[i]);
156166
if (SO) applyAttr(selection, "stroke-opacity", ([i]) => SO[i]);
157167
if (SW) applyAttr(selection, "stroke-width", ([i]) => SW[i]);
158168
if (O) applyAttr(selection, "opacity", ([i]) => O[i]);
159169
if (H) applyHref(selection, ([i]) => H[i], target);
160-
applyTitleGroup(selection, L);
170+
applyTitleGroup(selection, T);
161171
}
162172

163173
export function applyIndirectStyles(selection, mark) {
174+
applyAttr(selection, "aria-label", mark.ariaLabel);
175+
applyAttr(selection, "aria-description", mark.ariaDescription);
176+
applyAttr(selection, "aria-hidden", mark.ariaHidden);
164177
applyAttr(selection, "fill", mark.fill);
165178
applyAttr(selection, "fill-opacity", mark.fillOpacity);
166179
applyAttr(selection, "stroke", mark.stroke);

test/output/aaplBollinger.svg

Lines changed: 5 additions & 5 deletions
Loading

test/output/aaplCandlestick.svg

Lines changed: 4 additions & 4 deletions
Loading

test/output/aaplChangeVolume.svg

Lines changed: 4 additions & 4 deletions
Loading

test/output/aaplClose.svg

Lines changed: 5 additions & 5 deletions
Loading

test/output/aaplCloseUntyped.svg

Lines changed: 4 additions & 4 deletions
Loading

test/output/aaplMonthly.svg

Lines changed: 6 additions & 6 deletions
Loading

0 commit comments

Comments
 (0)