Skip to content

Commit ef85327

Browse files
Filmbostock
andauthored
aria fast follow (#722)
* personalize ariaLabel and ariaDescription on axes * documentation: ariaLabel for lines is reduced to first value Co-authored-by: Mike Bostock <[email protected]>
1 parent 5ce6cc0 commit ef85327

File tree

119 files changed

+214
-194
lines changed

Some content is hidden

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

119 files changed

+214
-194
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ If **x2** is not specified, it defaults to **x1**. If **y2** is not specified, i
680680

681681
By default, the data is assumed to represent a single series (a single value that varies over time, *e.g.*). If the **z** channel is specified, data is grouped by *z* to form separate series. Typically *z* is a categorical value such as a series name. If **z** is not specified, it defaults to **fill** if a channel, or **stroke** if a channel.
682682

683-
The **stroke** defaults to none. The **fill** defaults to currentColor if the stroke is none, and to none otherwise. If both the stroke and fill are defined as channels, or if the *z* channel is also specified, it is possible for the stroke or fill to vary within a series; varying color within a series is not supported, however, so only the first channel value for each series is considered. This limitation also applies to the **fillOpacity**, **strokeOpacity**, **strokeWidth**, and **title** channels.
683+
The **stroke** defaults to none. The **fill** defaults to currentColor if the stroke is none, and to none otherwise. If both the stroke and fill are defined as channels, or if the *z* channel is also specified, it is possible for the stroke or fill to vary within a series; varying color within a series is not supported, however, so only the first channel value for each series is considered. This limitation also applies to the **fillOpacity**, **strokeOpacity**, **strokeWidth**, **title**, and **ariaLabel** channels.
684684

685685
Points along the baseline and topline are connected in input order. Likewise, if there are multiple series via the *z*, *fill*, or *stroke* channel, the series are drawn in input order such that the last series is drawn on top. Typically, the data is already in sorted order, such as chronological for time series; if sorting is needed, consider a [sort transform](#transforms).
686686

src/axis.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {axisTop, axisBottom, axisRight, axisLeft, create, format, utcFormat} fro
22
import {boolean, take, number, string, keyword, maybeKeyword, constant, isTemporal} from "./options.js";
33
import {formatIsoDate} from "./format.js";
44
import {radians} from "./math.js";
5-
import {impliedString} from "./style.js";
5+
import {applyAttr, impliedString} from "./style.js";
66

77
export class AxisX {
88
constructor({
@@ -18,7 +18,9 @@ export class AxisX {
1818
labelAnchor,
1919
labelOffset,
2020
line,
21-
tickRotate
21+
tickRotate,
22+
ariaLabel,
23+
ariaDescription
2224
} = {}) {
2325
this.name = name;
2426
this.axis = keyword(axis, "axis", ["top", "bottom"]);
@@ -33,6 +35,8 @@ export class AxisX {
3335
this.labelOffset = number(labelOffset);
3436
this.line = boolean(line);
3537
this.tickRotate = number(tickRotate);
38+
this.ariaLabel = string(ariaLabel);
39+
this.ariaDescription = string(ariaDescription);
3640
}
3741
render(
3842
index,
@@ -59,13 +63,14 @@ export class AxisX {
5963
labelAnchor,
6064
labelOffset,
6165
line,
66+
name,
6267
tickRotate
6368
} = this;
64-
const offset = this.name === "x" ? 0 : axis === "top" ? marginTop - facetMarginTop : marginBottom - facetMarginBottom;
69+
const offset = name === "x" ? 0 : axis === "top" ? marginTop - facetMarginTop : marginBottom - facetMarginBottom;
6570
const offsetSign = axis === "top" ? -1 : 1;
6671
const ty = offsetSign * offset + (axis === "top" ? marginTop : height - marginBottom);
6772
return create("svg:g")
68-
.attr("aria-label", `${this.name}-axis`)
73+
.call(applyAria, this)
6974
.attr("transform", `translate(0,${ty})`)
7075
.call(createAxis(axis === "top" ? axisTop : axisBottom, x, this))
7176
.call(maybeTickRotate, tickRotate)
@@ -106,7 +111,9 @@ export class AxisY {
106111
labelAnchor,
107112
labelOffset,
108113
line,
109-
tickRotate
114+
tickRotate,
115+
ariaLabel,
116+
ariaDescription
110117
} = {}) {
111118
this.name = name;
112119
this.axis = keyword(axis, "axis", ["left", "right"]);
@@ -121,6 +128,8 @@ export class AxisY {
121128
this.labelOffset = number(labelOffset);
122129
this.line = boolean(line);
123130
this.tickRotate = number(tickRotate);
131+
this.ariaLabel = string(ariaLabel);
132+
this.ariaDescription = string(ariaDescription);
124133
}
125134
render(
126135
index,
@@ -145,13 +154,14 @@ export class AxisY {
145154
labelAnchor,
146155
labelOffset,
147156
line,
157+
name,
148158
tickRotate
149159
} = this;
150-
const offset = this.name === "y" ? 0 : axis === "left" ? marginLeft - facetMarginLeft : marginRight - facetMarginRight;
160+
const offset = name === "y" ? 0 : axis === "left" ? marginLeft - facetMarginLeft : marginRight - facetMarginRight;
151161
const offsetSign = axis === "left" ? -1 : 1;
152162
const tx = offsetSign * offset + (axis === "right" ? width - marginRight : marginLeft);
153163
return create("svg:g")
154-
.attr("aria-label", `${this.name}-axis`)
164+
.call(applyAria, this)
155165
.attr("transform", `translate(${tx},0)`)
156166
.call(createAxis(axis === "right" ? axisRight : axisLeft, y, this))
157167
.call(maybeTickRotate, tickRotate)
@@ -180,6 +190,16 @@ export class AxisY {
180190
}
181191
}
182192

193+
function applyAria(selection, {
194+
name,
195+
label,
196+
ariaLabel = `${name}-axis`,
197+
ariaDescription = label
198+
}) {
199+
applyAttr(selection, "aria-label", ariaLabel);
200+
applyAttr(selection, "aria-description", ariaDescription);
201+
}
202+
183203
function gridX(y2) {
184204
return g => g.selectAll(".tick line")
185205
.clone(true)

test/output/aaplBollinger.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/aaplCandlestick.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/aaplChangeVolume.svg

Lines changed: 2 additions & 2 deletions
Loading

test/output/aaplClose.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/aaplCloseUntyped.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/aaplMonthly.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/aaplVolume.svg

Lines changed: 2 additions & 2 deletions
Loading

test/output/aaplVolumeRect.svg

Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)