Plot.plot({
title: "Depth of Field by Lens, Object Distance and fStop",
subtitle: "How much of an object will be in focus given a lens/fstop at a specific distance?",
color: { legend: true },
x: { grid: false, domain: [2.8, 4, 5.6, 8, 11, 16], label: "fStop" },
fx: { grid: false, label: "Lens", tickFormat: (t) => (t + " mm") },
y: { grid: true, domain: [0, 20], label: "Distance", tickFormat: (t) => (t + "'")},
fy: {label: "Object Distance", tickFormat: (t) => (t + " ft")},
width: 1200,
height: 2000,
marks: [
Plot.frame({ strokeOpacity: 0.1 }),
Plot.ruleX(dof_data, {
fy: yfacet,
y1: "nearPoint",
y2: (d) => (_.clamp(d["farPoint"], 0, 20)),
x: "fstop",
fx: xfacet,
sort: (d) => (d["fstop"] * -1),
stroke: function(d) {
if(d["dof"] < 1.5) {
return "#999999"
} else if(d["dof"] < 3) {
return "#F59E0B"
} else if(d["dof"] < 4) {
return "#22C55E"
} else if(d["dof"] < 5) {
return "#16A34A"
} else {
return "#166534"
}
},
fillOpacity: 0.3,
strokeWidth: 20,
tip: true,
}),
Plot.ruleY(dof_data, {
fy: yfacet,
x1: 2.8,
x2: 16,
y: "distance_ft",
fx: xfacet,
stroke: "red",
strokeWidth: 1,
dx: -10
}),
Plot.text(dof_data, {
fy: yfacet,
x: "fstop",
y: "nearPoint",
fx: xfacet,
text: (d) => ("f" + d["fstop"]),
fill: "black",
dy: 10,
}),
Plot.text(dof_data, {
fy: yfacet,
x: "fstop",
y: (d) => (d["nearPoint"] + (_.clamp(d["farPoint"], 0, 20) - d["nearPoint"]) / 2),
fx: xfacet,
text: (d) => (d["dof"] === 5 ? ">5" : _.round(d["dof"], 1)),
fill: "white",
}),
Plot.ruleY([0])
]
})