Skip to content

Commit

Permalink
test all positions
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil committed Dec 17, 2021
1 parent 208d94e commit 9e78a97
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 0 deletions.
147 changes: 147 additions & 0 deletions test/output/labelPositioning.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/plots/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export {default as identityScale} from "./identity-scale.js";
export {default as industryUnemployment} from "./industry-unemployment.js";
export {default as industryUnemploymentShare} from "./industry-unemployment-share.js";
export {default as industryUnemploymentStream} from "./industry-unemployment-stream.js";
export {default as labelPositioning} from "./label-positioning.js";
export {default as learningPoverty} from "./learning-poverty.js";
export {default as letterFrequencyBar} from "./letter-frequency-bar.js";
export {default as letterFrequencyCloud} from "./letter-frequency-cloud.js";
Expand Down
30 changes: 30 additions & 0 deletions test/plots/label-positioning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as Plot from "@observablehq/plot";
import * as d3 from "d3";

export default async function() {
const data = d3.cross(["top", "", "bottom"], ["left", "", "right"]);
return Plot.plot({
facet: {
data,
x: "1",
y: "0",
marginLeft: 50
},
fx: { label: null, domain: ["left", "", "right"], padding: 0.2, inset: 20 },
fy: { label: null, domain: ["top", "", "bottom"], padding: 0.2, inset: 20 },
marks: [
Plot.frame({stroke: "#eee"}),
data.map(d => Plot.text(data, {
filter: p => p === d,
text: p => p.filter(x => x).join("-").toUpperCase() || "—",
anchor: d.filter(x => x).join("-"),
y: d[0] === "top" ? 10 : d[0] === "bottom" ? -10 : 0,
x: d[1] === "left" ? 5 : d[1] === "right" ? -5 : 0,
textAnchor: d[1] === "left" ? "start" : d[1] === "right" ? "end" : null
}))
],
height: 400,
marginLeft: 60

});
}

0 comments on commit 9e78a97

Please sign in to comment.