Skip to content

Commit

Permalink
axis marks’ ariaLabel option (#2162)
Browse files Browse the repository at this point in the history
* refactor the axis marks’ ariaLabel option
* concrete use case: a continuous horizontal crosshair
  • Loading branch information
Fil authored Sep 5, 2024
1 parent 0032c11 commit 09edfec
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/marks/axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ function axisKy(
labelAnchor,
labelArrow,
labelOffset,
ariaLabel = `${k}-axis`,
...options
}
) {
Expand All @@ -107,6 +108,7 @@ function axisKy(
tickPadding,
tickRotate,
x,
ariaLabel,
...options
})
: null,
Expand All @@ -126,6 +128,7 @@ function axisKy(
marginRight,
marginBottom,
marginLeft,
ariaLabel,
...options
})
: null,
Expand All @@ -150,7 +153,7 @@ function axisKy(
}
this.dy = cla === "top" ? 3 - marginTop : cla === "bottom" ? marginBottom - 3 : 0;
this.dx = anchor === "right" ? clo : -clo;
this.ariaLabel = `${k}-axis label`;
this.ariaLabel = `${ariaLabel} label`;
return {
facets: [[0]],
channels: {text: {value: [formatAxisLabel(k, scale, {anchor, label, labelAnchor: cla, labelArrow})]}}
Expand Down Expand Up @@ -190,6 +193,7 @@ function axisKx(
labelAnchor,
labelArrow,
labelOffset,
ariaLabel = `${k}-axis`,
...options
}
) {
Expand All @@ -208,6 +212,7 @@ function axisKx(
tickPadding,
tickRotate,
y,
ariaLabel,
...options
})
: null,
Expand All @@ -227,6 +232,7 @@ function axisKx(
marginRight,
marginBottom,
marginLeft,
ariaLabel,
...options
})
: null,
Expand All @@ -248,7 +254,7 @@ function axisKx(
this.lineAnchor = anchor;
this.dy = anchor === "top" ? -clo : clo;
this.dx = cla === "right" ? marginRight - 3 : cla === "left" ? 3 - marginLeft : 0;
this.ariaLabel = `${k}-axis label`;
this.ariaLabel = `${ariaLabel} label`;
return {
facets: [[0]],
channels: {text: {value: [formatAxisLabel(k, scale, {anchor, label, labelAnchor: cla, labelArrow})]}}
Expand All @@ -275,6 +281,7 @@ function axisTickKy(
insetRight = inset,
dx = 0,
y = k === "y" ? undefined : null,
ariaLabel,
...options
}
) {
Expand All @@ -283,7 +290,7 @@ function axisTickKy(
k,
data,
{
ariaLabel: `${k}-axis tick`,
ariaLabel: `${ariaLabel} tick`,
ariaHidden: true
},
{
Expand Down Expand Up @@ -318,6 +325,7 @@ function axisTickKx(
insetBottom = inset,
dy = 0,
x = k === "x" ? undefined : null,
ariaLabel,
...options
}
) {
Expand All @@ -326,7 +334,7 @@ function axisTickKx(
k,
data,
{
ariaLabel: `${k}-axis tick`,
ariaLabel: `${ariaLabel} tick`,
ariaHidden: true
},
{
Expand Down Expand Up @@ -363,6 +371,7 @@ function axisTextKy(
insetLeft = inset,
insetRight = inset,
dx = 0,
ariaLabel,
y = k === "y" ? undefined : null,
...options
}
Expand All @@ -371,7 +380,7 @@ function axisTextKy(
textY,
k,
data,
{ariaLabel: `${k}-axis tick label`},
{ariaLabel: `${ariaLabel} tick label`},
{
facetAnchor,
frameAnchor,
Expand Down Expand Up @@ -410,14 +419,15 @@ function axisTextKx(
insetBottom = inset,
dy = 0,
x = k === "x" ? undefined : null,
ariaLabel,
...options
}
) {
return axisMark(
textX,
k,
data,
{ariaLabel: `${k}-axis tick label`},
{ariaLabel: `${ariaLabel} tick label`},
{
facetAnchor,
frameAnchor,
Expand Down Expand Up @@ -466,10 +476,12 @@ function gridKy(
x = null,
x1 = anchor === "left" ? x : null,
x2 = anchor === "right" ? x : null,
ariaLabel = `${k}-grid`,
ariaHidden = true,
...options
}
) {
return axisMark(ruleY, k, data, {ariaLabel: `${k}-grid`, ariaHidden: true}, {y, x1, x2, ...gridDefaults(options)});
return axisMark(ruleY, k, data, {ariaLabel, ariaHidden}, {y, x1, x2, ...gridDefaults(options)});
}

function gridKx(
Expand All @@ -481,10 +493,12 @@ function gridKx(
y = null,
y1 = anchor === "top" ? y : null,
y2 = anchor === "bottom" ? y : null,
ariaLabel = `${k}-grid`,
ariaHidden = true,
...options
}
) {
return axisMark(ruleX, k, data, {ariaLabel: `${k}-grid`, ariaHidden: true}, {x, y1, y2, ...gridDefaults(options)});
return axisMark(ruleX, k, data, {ariaLabel, ariaHidden}, {x, y1, y2, ...gridDefaults(options)});
}

function gridDefaults({
Expand Down
Loading

0 comments on commit 09edfec

Please sign in to comment.