Skip to content

Any way to get DOM in framework like Observable HQ? #1684

Answered by mbostock
DevinBayly asked this question in Q&A
Discussion options

You must be logged in to vote

See the note here: https://observablehq.com/framework/convert#standard-library

For convenience, we’ve linked to the implementations above so that you can see how they work, and if desired, copy the code into your own Framework app as vanilla JavaScript. For example, for a 2D canvas, you can replace DOM.context2d with:

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;
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@DevinBayly
Comment options

Answer selected by mbostock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants