Skip to content
Closed
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
17 changes: 16 additions & 1 deletion src/axis.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {axisTop, axisBottom, axisRight, axisLeft, create, format, utcFormat} from "d3";
import {axisTop, axisBottom, axisRight, axisLeft, create, format, select, utcFormat} from "d3";
import {formatIsoDate} from "./format.js";
import {boolean, take, number, string, keyword, maybeKeyword, constant, isTemporal} from "./mark.js";
import {impliedString} from "./style.js";
Expand Down Expand Up @@ -66,6 +66,7 @@ export class AxisX {
return create("svg:g")
.attr("transform", `translate(0,${ty})`)
.call(createAxis(axis === "top" ? axisTop : axisBottom, x, this))
.call(g => g.selectAll("text").each(splitText()))
.call(maybeTickRotate, tickRotate)
.attr("font-size", null)
.attr("font-family", null)
Expand All @@ -90,6 +91,20 @@ export class AxisX {
}
}

function splitText() {
const repeats = [];
return function() {
const cur = this.textContent;
const lines = cur.split("\n");
if (lines.length > 1) {
select(this).text(lines.shift())
.selectAll().data(lines).join("tspan")
.text((d, i) => d[0] === "?" ? d === repeats[i] ? " " : (repeats[i] = d).slice(1) : d)
.attr("x", 0)
.attr("dy", "1.2em");
}
};
}
export class AxisY {
constructor({
name = "y",
Expand Down
35 changes: 13 additions & 22 deletions test/output/availability.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: 2 additions & 0 deletions test/plots/availability.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export default async function() {
const sum = d => d.length ? d3.sum(d) : NaN; // force gaps
return Plot.plot({
height: 180,
marginBottom: 45,
x: {tickFormat: "%b\n?%Y"},
marks: [
Plot.areaY(
data,
Expand Down