{
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.font = "14px sans";
ctx.textAlign = "center";
const rc = rough.canvas(canvas);
const opts = { seed: 0 };
const anchors = {
width: 540,
height: 260
};
anchors.chartLeft = 100;
anchors.chartBottom = anchors.height - 20;
anchors.chartRight = anchors.width - 80;
anchors.chartWidth = anchors.chartRight - anchors.chartLeft;
anchors.chartHeight = anchors.chartBottom;
anchors.singleMachineX = anchors.chartLeft + anchors.chartWidth / 4;
anchors.multipleMachineX = anchors.chartLeft + (anchors.chartWidth * 3) / 4;
anchors.systemY = (anchors.chartHeight * 1) / 6;
anchors.languageY = (anchors.chartHeight * 3) / 6;
anchors.langSpecificY = (anchors.chartHeight * 5) / 6;
rc.line(
anchors.chartLeft,
anchors.chartBottom,
anchors.chartRight,
anchors.chartBottom
);
ctx.fillStyle = "black";
ctx.fillText("Single machine", anchors.singleMachineX, anchors.height);
ctx.fillText("Multiple machines", anchors.multipleMachineX, anchors.height);
rc.line(anchors.chartLeft, 0, anchors.chartLeft, anchors.chartBottom);
ctx.textAlign = "right";
ctx.fillText("System", anchors.chartLeft - 3, anchors.systemY);
ctx.fillText("Languages", anchors.chartLeft - 3, anchors.languageY);
ctx.fillText("Lang-specific", anchors.chartLeft - 3, anchors.langSpecificY);
const padding = 6;
rc.rectangle(
anchors.chartLeft + padding,
padding,
anchors.chartWidth - padding * 2,
anchors.chartHeight - padding * 2,
{ ...opts, fill: "rgba(222,222,255,1)", fillStyle: "cross-hatch" }
);
function circleWithLabel(x, y, radius, text, extra) {
rc.circle(x, y, radius, { ...opts, ...(extra || {}) });
ctx.fillStyle = "rgba(255,255,255,0.6)";
ctx.fillRect(x - radius * 0.5 + 2, y - 7, radius - 4, 14);
ctx.textAlign = "center";
ctx.fillStyle = "black";
ctx.fillText(text, x, y + 4);
}
const radius = ((anchors.languageY - anchors.systemY) * 2) / 3;
circleWithLabel(anchors.singleMachineX, anchors.systemY, radius, "brew", {
fill: "yellow",
fillStyle: "hatchet"
});
circleWithLabel(
anchors.multipleMachineX,
anchors.langSpecificY,
radius,
"npm",
{ fill: "orange", fillStyle: "hatchet" }
);
circleWithLabel(
anchors.multipleMachineX,
anchors.languageY,
radius,
"pyenv",
{ fill: "green", fillStyle: "hatchet" }
);
rc.line(
anchors.chartRight,
anchors.systemY + 30,
anchors.chartRight + 10,
anchors.systemY + 30 - 6
);
ctx.textAlign = "left";
ctx.fillText("nix", anchors.chartRight + 14, anchors.systemY + 30 - 6);
return "rendered";
}