Any way to get DOM in framework like Observable HQ? #1684
-
Hi there, I was recently working on a force collide framework page and the example I was following made its canvas using I ended up with making the canvas in html below and resizing it to be the width and height that I wanted, but it felt like there might be a more seamless way to translate from the observablehq example. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
See the note here: https://observablehq.com/framework/convert#standard-library
function context2d(width, height, dpi = devicePixelRatio) {
const canvas = document.createElement("canvas");
canvas.width = width * dpi;
canvas.height = height * dpi;
canvas.style = `width: ${width}px;`;
const context = canvas.getContext("2d");
context.scale(dpi, dpi);
return context;
} |
Beta Was this translation helpful? Give feedback.
See the note here: https://observablehq.com/framework/convert#standard-library