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

[Feature] saveAsImage.formatter #20200

Open
jdgme opened this issue Jul 25, 2024 · 0 comments
Open

[Feature] saveAsImage.formatter #20200

jdgme opened this issue Jul 25, 2024 · 0 comments
Labels
en This issue is in English new-feature pending We are not sure about whether this is a bug/new feature.

Comments

@jdgme
Copy link

jdgme commented Jul 25, 2024

What problem does this feature solve?

I have a use case where I need to add elements (text, banners, etc.) to charts when they are downloaded, but these additional elements should not be included in the display of the charts in the browser. I prefer to still have the ability to utilize toolbox's saveAsImage to trigger this enhanced chart downloading since the only alternative is to put an event listener on the DOM element and use event.stopPropagation() if the click is in the area of the Download icon in the toolbox on the chart, which I have to calculate dynamically based on browser conditions. Towards this end, I recommend creating a saveAsImage function parameter (similar to tooltip.formatter) which the developer can set to further manipulate the saveAsImage prior to it being sent to the browser for download.

"formatter" may not be the best name for this parameter as it might be misleading for those who think only of formatting text, but I leave that to the developers/community.

Implementation should be rather straight forward as it just requires passing the current saveAsImage result to saveAsImage.formatter and exporting the result of that formatter instead of the current saveAsImage if the formatter is defined.

Additionally, I recommend/request implementation of #18121 so saveAsImage can be triggered outside of the echart itself.

What does the proposed API look like?

Setting in Options

option = {
    toolbox: {
        feature: {
            saveAsImage: {
                formatter: function (params) {
                    return this.myChartFormatFunction(params);
                },
            },
        }
    }
};

Documentation

saveAsImage.formatter

Function
The optional formatter of the saveAsImage output which supports a callback function.

Callback function

(params: any) => HTMLCanvasElement

The first parameter params is the data that the formatter needs. Its format is shown as follows:

{
    // Canvas image generated by saveAsImage
    canvas: HTMLCanvasElement,
}
@echarts-bot echarts-bot bot added en This issue is in English pending We are not sure about whether this is a bug/new feature. labels Jul 25, 2024
@jdgme jdgme changed the title saveAsImage.formatter [feature] saveAsImage.formatter Jul 26, 2024
@jdgme jdgme changed the title [feature] saveAsImage.formatter [Feature] saveAsImage.formatter Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
en This issue is in English new-feature pending We are not sure about whether this is a bug/new feature.
Projects
None yet
Development

No branches or pull requests

1 participant