lightweight-charts icon indicating copy to clipboard operation
lightweight-charts copied to clipboard

Export image before rendering

Open andrewkenreich opened this issue 2 years ago • 8 comments

Is your feature request related to a problem? Please describe.

Self hosting of library to get images more quickly.

Currently the only way on the public and private repo is to use a screenshot of a chart from electron or some other way to export an image after the chart is loaded.

Describe the solution you'd like

When self hosting it would be great if we could call a function to return the image or base64 of the image and not have to render it. This would allow for quicker sending to the end user if we have to use images and not the full blown html. (chat platforms)

Something like plotly does with chart.to_image() using kaliedo or similar

Additional context

This mostly applies to the advanced charting library but I think it does here as well.

andrewkenreich avatar Apr 15 '22 13:04 andrewkenreich

Hi @andrewkenreich !

Apologies for the late (very) answer; Im not quite sure I follow the requirement here. Upon taking a screenshot a url corresponding to the image is generated and returned so you won't have to load & display the image.

romfrancois avatar Jun 27 '22 20:06 romfrancois

Hey @romfrancois,

Idea here is we want a function we can call to return this screenshot on the Advanced chart lib when we self host, Currently there is no way to do that.

andrewkenreich avatar Jun 28 '22 15:06 andrewkenreich

We have 2 methods that deal with screenshots:

Both are returning a Promise. Only the second one will return a HTML canvas element and the first one a URL. From that moment you could use that url to fetch that image and convert it to whatever you want.

Still not quite sure we are aligned though.

romfrancois avatar Jun 30 '22 21:06 romfrancois

And can these methods run without actually loading the chart? That is where I think we aren't aligned.

We want to be able to return an image of a graph from a function like takeScreenshot. But we don't want to render the chart.

That's why I referenced something like plotly with - chart.to_image() - this uses kaleido in the bg and returns an image as a bytes object. This is much easier to use rather than using something like electron to render the image and then take a screenshot of the chart to use.

andrewkenreich avatar Jul 01 '22 02:07 andrewkenreich

@andrewkenreich

It is not currently possible to generate screenshot without rendering the chart first.

edew avatar Jul 01 '22 09:07 edew

@edew Ok that is the feature we are requesting then

andrewkenreich avatar Jul 01 '22 16:07 andrewkenreich

@andrewkenreich

OK understood.

It is possible, but it would be a big task because the libraries aren't designed to be able to swap the rendering backend, and generally they assume that they are running a browser context with a canvas.

For Lightweight Charts in particular I'm not sure if such a feature is in scope for this library in the first place.

edew avatar Jul 04 '22 09:07 edew

@edew sorry I know this is in lightweight but it was meant to be a function of the advanced lib package, I just couldn't post there.

andrewkenreich avatar Jul 04 '22 10:07 andrewkenreich