Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix axis label being clipped with the clip plot option #1804

Merged
merged 4 commits into from
Aug 14, 2023
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
14 changes: 13 additions & 1 deletion src/marks/axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,18 @@ function gridDefaults({
}

function labelOptions(
{fill, fillOpacity, fontFamily, fontSize, fontStyle, fontWeight, monospace, pointerEvents, shapeRendering},
{
fill,
fillOpacity,
fontFamily,
fontSize,
fontStyle,
fontWeight,
monospace,
pointerEvents,
shapeRendering,
clip = false
},
initializer
) {
// Only propagate these options if constant.
Expand All @@ -501,6 +512,7 @@ function labelOptions(
monospace,
pointerEvents,
shapeRendering,
clip,
initializer
};
}
Expand Down
104 changes: 104 additions & 0 deletions test/output/aaplCloseClip.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 30 additions & 18 deletions test/plots/aapl-close.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,64 @@ import * as Plot from "@observablehq/plot";
import * as d3 from "d3";

export async function aaplClose() {
const AAPL = await d3.csv<any>("data/aapl.csv", d3.autoType);
const aapl = await d3.csv<any>("data/aapl.csv", d3.autoType);
return Plot.plot({
y: {
grid: true
},
y: {grid: true},
marks: [
Plot.areaY(AAPL, {x: "Date", y: "Close", fillOpacity: 0.1}),
Plot.lineY(AAPL, {x: "Date", y: "Close"}),
Plot.areaY(aapl, {x: "Date", y: "Close", fillOpacity: 0.1}),
Plot.lineY(aapl, {x: "Date", y: "Close"}),
Plot.ruleY([0])
]
});
}

export async function aaplCloseClip() {
const aapl = await d3.csv<any>("data/aapl.csv", d3.autoType);
return Plot.plot({
clip: true,
x: {domain: [new Date(Date.UTC(2015, 0, 1)), new Date(Date.UTC(2015, 3, 1))]},
y: {grid: true},
marks: [
Plot.areaY(aapl, {x: "Date", y: "Close", fillOpacity: 0.1}),
Plot.lineY(aapl, {x: "Date", y: "Close"}),
Plot.ruleY([0], {clip: false})
]
});
}

export async function aaplCloseDataTicks() {
const AAPL = await d3.csv<any>("data/aapl.csv", d3.autoType);
const aapl = await d3.csv<any>("data/aapl.csv", d3.autoType);
return Plot.plot({
marks: [Plot.axisY(d3.ticks(0, 200, 10), {anchor: "left"}), Plot.lineY(AAPL, {x: "Date", y: "Close"})]
marks: [Plot.axisY(d3.ticks(0, 200, 10), {anchor: "left"}), Plot.lineY(aapl, {x: "Date", y: "Close"})]
});
}

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

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

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

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

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

export async function aaplCloseNormalize() {
Expand Down