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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ If **x2** is not specified, it defaults to **x1**. If **y2** is not specified, i

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.

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.
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.

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).

Expand Down
34 changes: 27 additions & 7 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 @@ -18,7 +18,9 @@ export class AxisX {
labelAnchor,
labelOffset,
line,
tickRotate
tickRotate,
ariaLabel,
ariaDescription
} = {}) {
this.name = name;
this.axis = keyword(axis, "axis", ["top", "bottom"]);
Expand All @@ -33,6 +35,8 @@ export class AxisX {
this.labelOffset = number(labelOffset);
this.line = boolean(line);
this.tickRotate = number(tickRotate);
this.ariaLabel = string(ariaLabel);
this.ariaDescription = string(ariaDescription);
}
render(
index,
Expand All @@ -59,13 +63,14 @@ export class AxisX {
labelAnchor,
labelOffset,
line,
name,
tickRotate
} = this;
const offset = this.name === "x" ? 0 : axis === "top" ? marginTop - facetMarginTop : marginBottom - facetMarginBottom;
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", `${this.name}-axis`)
.call(applyAria, this)
.attr("transform", `translate(0,${ty})`)
.call(createAxis(axis === "top" ? axisTop : axisBottom, x, this))
.call(maybeTickRotate, tickRotate)
Expand Down Expand Up @@ -106,7 +111,9 @@ export class AxisY {
labelAnchor,
labelOffset,
line,
tickRotate
tickRotate,
ariaLabel,
ariaDescription
} = {}) {
this.name = name;
this.axis = keyword(axis, "axis", ["left", "right"]);
Expand All @@ -121,6 +128,8 @@ export class AxisY {
this.labelOffset = number(labelOffset);
this.line = boolean(line);
this.tickRotate = number(tickRotate);
this.ariaLabel = string(ariaLabel);
this.ariaDescription = string(ariaDescription);
}
render(
index,
Expand All @@ -145,13 +154,14 @@ export class AxisY {
labelAnchor,
labelOffset,
line,
name,
tickRotate
} = this;
const offset = this.name === "y" ? 0 : axis === "left" ? marginLeft - facetMarginLeft : marginRight - facetMarginRight;
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", `${this.name}-axis`)
.call(applyAria, this)
.attr("transform", `translate(${tx},0)`)
.call(createAxis(axis === "right" ? axisRight : axisLeft, y, this))
.call(maybeTickRotate, tickRotate)
Expand Down Expand Up @@ -180,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.
Loading