amelioro / ameliorate

A tool for analyzing debatable problems effectively, collaboratively, and with an open mind.
https://ameliorate.app
MIT License
26 stars 10 forks source link

feat: take screenshot of diagram #338

Closed keyserj closed 9 months ago

keyserj commented 9 months ago

Closes #332

Description of changes

-

Additional context

netlify[bot] commented 9 months ago

Deploy Preview for velvety-vacherin-4193fb ready!

Name Link
Latest commit f428af4786527de39637d3726ac27d9708849253
Latest deploy log https://app.netlify.com/sites/velvety-vacherin-4193fb/deploys/65d3e8c9ccbec10008cf1f1d
Deploy Preview https://deploy-preview-338--velvety-vacherin-4193fb.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

Lighthouse
1 paths audited
Performance: 65
Accessibility: 86
Best Practices: 92
SEO: 85
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

keyserj commented 9 months ago

I initially went the path of screenshotting the diagram as-seen, rather than centering and sizing to a width x height, but sizing by width x height seems ideal for scenarios where you want to print the diagram for something like a picture frame. (right now you can't specify width x height but will add that in the future).

Here's the code for capturing the diagram as seen, and enhancing the pixel quality:

const element = document.querySelector(".react-flow__viewport");
    console.log(element.clientWidth, element.clientHeight);
    const widthRatio = Math.ceil(2500.0 / element.clientWidth);
    const heightRatio = Math.ceil(2500.0 / element.clientHeight);

    toPng(element, {
      backgroundColor: "#fff",
      pixelRatio: Math.min(widthRatio, heightRatio),
    }).then(downloadImage);
  };