Skip to content

Commit 63415aa

Browse files
authored
fix axis label being clipped with the clip plot option (#1804)
closes #1803
1 parent 315d52a commit 63415aa

File tree

3 files changed

+147
-19
lines changed

3 files changed

+147
-19
lines changed

src/marks/axis.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,18 @@ function gridDefaults({
482482
}
483483

484484
function labelOptions(
485-
{fill, fillOpacity, fontFamily, fontSize, fontStyle, fontWeight, monospace, pointerEvents, shapeRendering},
485+
{
486+
fill,
487+
fillOpacity,
488+
fontFamily,
489+
fontSize,
490+
fontStyle,
491+
fontWeight,
492+
monospace,
493+
pointerEvents,
494+
shapeRendering,
495+
clip = false
496+
},
486497
initializer
487498
) {
488499
// Only propagate these options if constant.
@@ -501,6 +512,7 @@ function labelOptions(
501512
monospace,
502513
pointerEvents,
503514
shapeRendering,
515+
clip,
504516
initializer
505517
};
506518
}

test/output/aaplCloseClip.svg

+104
Loading

test/plots/aapl-close.ts

+30-18
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,64 @@ import * as Plot from "@observablehq/plot";
22
import * as d3 from "d3";
33

44
export async function aaplClose() {
5-
const AAPL = await d3.csv<any>("data/aapl.csv", d3.autoType);
5+
const aapl = await d3.csv<any>("data/aapl.csv", d3.autoType);
66
return Plot.plot({
7-
y: {
8-
grid: true
9-
},
7+
y: {grid: true},
108
marks: [
11-
Plot.areaY(AAPL, {x: "Date", y: "Close", fillOpacity: 0.1}),
12-
Plot.lineY(AAPL, {x: "Date", y: "Close"}),
9+
Plot.areaY(aapl, {x: "Date", y: "Close", fillOpacity: 0.1}),
10+
Plot.lineY(aapl, {x: "Date", y: "Close"}),
1311
Plot.ruleY([0])
1412
]
1513
});
1614
}
1715

16+
export async function aaplCloseClip() {
17+
const aapl = await d3.csv<any>("data/aapl.csv", d3.autoType);
18+
return Plot.plot({
19+
clip: true,
20+
x: {domain: [new Date(Date.UTC(2015, 0, 1)), new Date(Date.UTC(2015, 3, 1))]},
21+
y: {grid: true},
22+
marks: [
23+
Plot.areaY(aapl, {x: "Date", y: "Close", fillOpacity: 0.1}),
24+
Plot.lineY(aapl, {x: "Date", y: "Close"}),
25+
Plot.ruleY([0], {clip: false})
26+
]
27+
});
28+
}
29+
1830
export async function aaplCloseDataTicks() {
19-
const AAPL = await d3.csv<any>("data/aapl.csv", d3.autoType);
31+
const aapl = await d3.csv<any>("data/aapl.csv", d3.autoType);
2032
return Plot.plot({
21-
marks: [Plot.axisY(d3.ticks(0, 200, 10), {anchor: "left"}), Plot.lineY(AAPL, {x: "Date", y: "Close"})]
33+
marks: [Plot.axisY(d3.ticks(0, 200, 10), {anchor: "left"}), Plot.lineY(aapl, {x: "Date", y: "Close"})]
2234
});
2335
}
2436

2537
export async function aaplCloseImplicitGrid() {
26-
const AAPL = await d3.csv<any>("data/aapl.csv", d3.autoType);
38+
const aapl = await d3.csv<any>("data/aapl.csv", d3.autoType);
2739
return Plot.plot({
2840
y: {grid: true}, // appears even though there’s an explicit axis
29-
marks: [Plot.axisY({anchor: "left"}), Plot.lineY(AAPL, {x: "Date", y: "Close"})]
41+
marks: [Plot.axisY({anchor: "left"}), Plot.lineY(aapl, {x: "Date", y: "Close"})]
3042
});
3143
}
3244

3345
export async function aaplCloseGridColor() {
34-
const AAPL = await d3.csv<any>("data/aapl.csv", d3.autoType);
35-
return Plot.lineY(AAPL, {x: "Date", y: "Close"}).plot({y: {grid: "red"}});
46+
const aapl = await d3.csv<any>("data/aapl.csv", d3.autoType);
47+
return Plot.lineY(aapl, {x: "Date", y: "Close"}).plot({y: {grid: "red"}});
3648
}
3749

3850
export async function aaplCloseGridInterval() {
39-
const AAPL = await d3.csv<any>("data/aapl.csv", d3.autoType);
40-
return Plot.lineY(AAPL, {x: "Date", y: "Close"}).plot({x: {grid: "3 months"}});
51+
const aapl = await d3.csv<any>("data/aapl.csv", d3.autoType);
52+
return Plot.lineY(aapl, {x: "Date", y: "Close"}).plot({x: {grid: "3 months"}});
4153
}
4254

4355
export async function aaplCloseGridIntervalName() {
44-
const AAPL = await d3.csv<any>("data/aapl.csv", d3.autoType);
45-
return Plot.lineY(AAPL, {x: "Date", y: "Close"}).plot({x: {grid: "month"}});
56+
const aapl = await d3.csv<any>("data/aapl.csv", d3.autoType);
57+
return Plot.lineY(aapl, {x: "Date", y: "Close"}).plot({x: {grid: "month"}});
4658
}
4759

4860
export async function aaplCloseGridIterable() {
49-
const AAPL = await d3.csv<any>("data/aapl.csv", d3.autoType);
50-
return Plot.lineY(AAPL, {x: "Date", y: "Close"}).plot({y: {grid: [100, 120, 140]}});
61+
const aapl = await d3.csv<any>("data/aapl.csv", d3.autoType);
62+
return Plot.lineY(aapl, {x: "Date", y: "Close"}).plot({y: {grid: [100, 120, 140]}});
5163
}
5264

5365
export async function aaplCloseNormalize() {

0 commit comments

Comments
 (0)