Triangle =
({levels, wide, width, background, boxed, margin, rotate}) =>
({x = "col", y = "row", text = "value", caption = `Raw triangle coordinates for ${levels} levels`} = {}) =>
(data) =>
Plot.plot({
caption,
marks: [
Plot.cell(data, {
x,
y,
stroke: boxed ? "black" : "none",
fill: background ? "peachpuff" : "none",
}),
Plot.text(data, {
x,
y,
text,
fontSize: 27 - 2 * levels,
rotate,
}),
],
width,
height: width,
marginTop: margin,
marginLeft: margin,
marginBottom: margin,
marginRight: margin,
x: { tickSize: 0, padding: 0, tickRotate: -45, axis: null },
y: { tickSize: 0, padding: 0, tickRotate: -45, axis: null },
style: `transform: rotate(${-rotate}deg); background:transparent;`
})