Add client side exporting functionality
Highcharts allows for client side exporting of charts without the need for an exporting server by loading the module offline-exporting.js. See https://www.highcharts.com/docs/export-module/client-side-export.
The current implementation of vaadin charts does not load this module. Could the client side exporting be added to this project? Because if I understand correctly at the moment our only options to export charts are the public highcharts export server or running our own export server.
The way Highcharts has implemented client side rendering still relies on access to their server. It is not sending your data there, but the exporting.js and offine-exporting.js will dynamically load additional JavaScript files depending on whether you decide to export PDF or PNG etc. So one question that needs to be resolved here is that ok, or is there need for a solution where those files are served locally, which seems to be an option based on this "By default, the module will load these file from our server on demand, but the URL can be changed using the exporting.libURL option."
According to https://github.com/vaadin/web-components/pull/10010#issuecomment-3232889750, when upgrading to Highcharts 12.3.0 it should be able to use the ability to export charts locally instead of using the online exporting provided by Highcharts. But that is blocked by https://github.com/vaadin/web-components/issues/10104.
The way Highcharts has implemented client side rendering still relies on access to their server. It is not sending your data there, but the exporting.js and offine-exporting.js will dynamically load additional JavaScript files depending on whether you decide to export PDF or PNG etc. So one question that needs to be resolved here is that ok, or is there need for a solution where those files are served locally, which seems to be an option based on this "By default, the module will load these file from our server on demand, but the URL can be changed using the exporting.libURL option."
I think the most sense is to have the required dependencies served locally. Use case is for applications that are deployed in environments without Internet access.
According to #10010 (comment), when upgrading to Highcharts 12.3.0 it should be able to use the ability to export charts locally instead of using the online exporting provided by Highcharts. But that is blocked by #10104.
As far as I'm aware, offline exporting was already supported by Highcharts for a long time through offline-exporting.js. Our company implemented a workaround in Vaadin Charts by additionally loading it:
@JsModule("highcharts/es-modules/masters/modules/offline-exporting.src.js")
The following changes were made:
Exporting exporting = configuration.getExporting();
exporting.setEnabled(true);
exporting.setFallbackToExportServer(false);
exporting.setLibURL("/static/js/charts/");
And then the following JavaScript libraries had to be made available on that path:
- canvg.js (According to https://www.highcharts.com/docs/export-module/client-side-export only required for exporting in Internet Explorer, no longer supported by Vaadin for a while now)
- jspdf.js
- svg2pdf.js This works, but the annoying part is keeping the required dependencies in sync with the Highcharts version used in Vaadin Charts, and they have to be explicitly served as resources.
If Vaadin can include this functionality by default without the additional required steps, that would be greatly appreciated.
@thomasdewaelheyns , thanks for the valuable insight, I was about to test whether the trick you did would work as it popped to my mind as well as potential workaround. And yes, that requires occasional manual update of those extra files.