Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions src/axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {axisTop, axisBottom, axisRight, axisLeft, create, format, utcFormat} fro
import {boolean, take, number, string, keyword, maybeKeyword, constant, isTemporal} from "./options.js";
import {formatIsoDate} from "./format.js";
import {radians} from "./math.js";
import {impliedString} from "./style.js";
import {applyAttr, impliedString} from "./style.js";

export class AxisX {
constructor({
Expand All @@ -19,7 +19,8 @@ export class AxisX {
labelOffset,
line,
tickRotate,
ariaLabel
ariaLabel,
ariaDescription
} = {}) {
this.name = name;
this.axis = keyword(axis, "axis", ["top", "bottom"]);
Expand All @@ -35,6 +36,7 @@ export class AxisX {
this.line = boolean(line);
this.tickRotate = number(tickRotate);
this.ariaLabel = string(ariaLabel);
this.ariaDescription = string(ariaDescription);
}
render(
index,
Expand Down Expand Up @@ -62,14 +64,13 @@ export class AxisX {
labelOffset,
line,
name,
tickRotate,
ariaLabel
tickRotate
} = this;
const offset = name === "x" ? 0 : axis === "top" ? marginTop - facetMarginTop : marginBottom - facetMarginBottom;
const offsetSign = axis === "top" ? -1 : 1;
const ty = offsetSign * offset + (axis === "top" ? marginTop : height - marginBottom);
return create("svg:g")
.attr("aria-label", ariaLabel === undefined ? `${name}-axis${label != null ? ` ${label}` : ""}` : ariaLabel)
.call(applyAria, this)
.attr("transform", `translate(0,${ty})`)
.call(createAxis(axis === "top" ? axisTop : axisBottom, x, this))
.call(maybeTickRotate, tickRotate)
Expand All @@ -81,7 +82,6 @@ export class AxisX {
: fy ? gridFacetX(index, fy, -ty)
: gridX(offsetSign * (marginBottom + marginTop - height)))
.call(!label ? () => {} : g => g.append("text")
.attr("aria-hidden", true)
.attr("fill", "currentColor")
.attr("transform", `translate(${
labelAnchor === "center" ? (width + marginLeft - marginRight) / 2
Expand Down Expand Up @@ -112,7 +112,8 @@ export class AxisY {
labelOffset,
line,
tickRotate,
ariaLabel
ariaLabel,
ariaDescription
} = {}) {
this.name = name;
this.axis = keyword(axis, "axis", ["left", "right"]);
Expand All @@ -128,6 +129,7 @@ export class AxisY {
this.line = boolean(line);
this.tickRotate = number(tickRotate);
this.ariaLabel = string(ariaLabel);
this.ariaDescription = string(ariaDescription);
}
render(
index,
Expand All @@ -153,14 +155,13 @@ export class AxisY {
labelOffset,
line,
name,
tickRotate,
ariaLabel
tickRotate
} = this;
const offset = name === "y" ? 0 : axis === "left" ? marginLeft - facetMarginLeft : marginRight - facetMarginRight;
const offsetSign = axis === "left" ? -1 : 1;
const tx = offsetSign * offset + (axis === "right" ? width - marginRight : marginLeft);
return create("svg:g")
.attr("aria-label", ariaLabel === undefined ? `${name}-axis${label != null ? ` ${label}` : ""}` : ariaLabel)
.call(applyAria, this)
.attr("transform", `translate(${tx},0)`)
.call(createAxis(axis === "right" ? axisRight : axisLeft, y, this))
.call(maybeTickRotate, tickRotate)
Expand All @@ -172,7 +173,6 @@ export class AxisY {
: fx ? gridFacetY(index, fx, -tx)
: gridY(offsetSign * (marginLeft + marginRight - width)))
.call(!label ? () => {} : g => g.append("text")
.attr("aria-hidden", true)
.attr("fill", "currentColor")
.attr("transform", `translate(${labelOffset * offsetSign},${
labelAnchor === "center" ? (height + marginTop - marginBottom) / 2
Expand All @@ -190,6 +190,16 @@ export class AxisY {
}
}

function applyAria(selection, {
name,
label,
ariaLabel = `${name}-axis`,
ariaDescription = label
}) {
applyAttr(selection, "aria-label", ariaLabel);
applyAttr(selection, "aria-description", ariaDescription);
}

function gridX(y2) {
return g => g.selectAll(".tick line")
.clone(true)
Expand Down
2 changes: 1 addition & 1 deletion test/output/aaplBollinger.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/aaplCandlestick.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/output/aaplChangeVolume.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/aaplClose.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/aaplCloseUntyped.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/aaplMonthly.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/output/aaplVolume.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/aaplVolumeRect.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions test/output/anscombeQuartet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/output/athletesBinsColors.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/output/athletesHeightWeight.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/output/athletesHeightWeightBin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/output/athletesHeightWeightBinStroke.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/output/athletesHeightWeightSex.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/output/athletesHeightWeightSport.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading