function displaySpectrumGraph(correction, {height=350, domain=[0, 100], scale=rgbScale, displaySpace=true, colorbar=false})
{
var rgbdata2 = rgbdata.map(row => {
var {r, g, b, wl} = row;
[r, g, b] = correction([r * scale, g * scale, b * scale]);
return {r:r, g:g, b:b, wl:wl};
});
var plotConfig = {
height: height,
insetBottom: colorbar ? 4 : 0,
x: {label: "Wavelength (nm) →"},
y: {
label: displaySpace ? "↑ sRGB (%)" : "↑ RGB",
grid: true,
domain: domain,
percent: displaySpace
},
marks: [
Plot.areaY(rgbdata2, {x: "wl", y: "r", fill: "#f00", opacity: .07}),
Plot.areaY(rgbdata2, {x: "wl", y: "g", fill: "#0f0", opacity: .07}),
Plot.areaY(rgbdata2, {x: "wl", y: "b", fill: "#00f", opacity: .07}),
Plot.line(rgbdata2, {x: "wl", y: "r", stroke: "#f00"}),
Plot.line(rgbdata2, {x: "wl", y: "g", stroke: "#0d0"}),
Plot.line(rgbdata2, {x: "wl", y: "b", stroke: "#00f"}),
Plot.ruleY([0]),
]
};
if (displaySpace)
{
plotConfig.marks.push(
Plot.ruleY([1])
);
}
if (colorbar)
{
function rgbBar(e)
{
var rgb = rgbCap(rgbGreyDesaturate([e.r, e.g, e.b], {overdrive: 1.8}));
return colorToCss(sRGB(rgb));
}
rgbCap
plotConfig.marks.push(
Plot.line(rgbdata, {x: "wl", y: -1,strokeWidth: 5, z: null, dy: 2, stroke: rgbBar})
);
}
return Plot.plot(plotConfig);
}