Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example of canvas to png data loader #1510

Closed
wants to merge 14 commits into from

Conversation

palewire
Copy link
Contributor

I propose adding this example, which shows how you can use Node.JS in a data loader to serve a canvas map as a PNG. I currently use this pattern to render large amounts of data in lightweight static files.

I used the official d3 example of how to make a canvas map to put together this demo.

Screenshot from 2024-07-10 10-49-05
Screenshot from 2024-07-10 10-49-16

Copy link
Contributor

@Fil Fil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this seems useful. A few remarks as I read the code.


</div>

The above data loader lives in `data/us-map.png.js`, so we can access the image using `data/us-map.png`:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be us-map.png.js instead? not really “data”, maybe, if it's already a baked-in visualization?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm agnostic on the approach. I put it there because I saw a similar path in the Python to PNG example. If you want me to change it here, I'm happy to do so.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I don't know… we can leave it like this for now :)

@palewire palewire requested a review from Fil July 10, 2024 20:40
@Fil
Copy link
Contributor

Fil commented Jul 10, 2024

I think we also want to use double resolution (for retina screens) — this is hidden in DOM.context2d in observable notebooks.

@palewire
Copy link
Contributor Author

I think we also want to use double resolution (for retina screens) — this is hidden in DOM.context2d in observable notebooks.

What method would you like to see used for this?

@Fil
Copy link
Contributor

Fil commented Jul 11, 2024

I've added upscaling in 04eb615
this PR looks good to me, continuing at #1514.

@Fil
Copy link
Contributor

Fil commented Jul 11, 2024

merged as 661e0ff

thanks!

@Fil Fil closed this Jul 11, 2024
@palewire
Copy link
Contributor Author

Great. Would you want a companion example that loaded a d3 SVG graphic into a PNG?

@Fil
Copy link
Contributor

Fil commented Jul 12, 2024

I'm not sure what's best. I've already prepared a resource (but not shared as an "example" yet) explaining how to do SSR in png and svg with Plot:
https://observablehq.observablehq.cloud/pangea/support/becker-barley-ssr

I wonder if it makes sense to create one "example" for each case, or if we shouldn't instead make an example that shows the different techniques (that means 8 combinations of D3 v Plot, png v svg, and dark v light).

@palewire
Copy link
Contributor Author

palewire commented Jul 12, 2024

I'd defer to you all on the right presentation. My thing: Being able to render out big data-heavy graphics made with d3 into PNG is a very useful use case for your loaders in news publishing. Show it off!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants