How best to add HighCharts offline-exporting module to Vaadin Charts?

Interestingly, the Vaadin-Charts addon explicitly defines the Highcharts modules it loads in HighchartResources, but the offline-exporting module is not one of them. How can I most easily add this one as well in my environment, without a custom local build of Vaadin-Charts?

Of course asking a question means I solve it soon after. I just created a sublcass of HighchartsScriptLoader and used the Widgetset XML to replace the original with the subclass. The subclass adds the new dependency in injectResources() after calling super.injectResources().

public class MyHighchartsScriptLoader extends HighchartsScriptLoader {

    public static interface MyChartResources extends ClientBundle {
        public static final MyChartResources INSTANCE = GWT
            .create(MyChartResources.class);

        /**
        * @return resource for offline exporting HighCharts module
        */
        @Source("offline-exporting.js")
        TextResource offlineExport();
    }

    /**
    * add offline-export module
    * @see com.vaadin.addon.charts.client.HighchartsScriptLoader#injectResources()
    */
    @Override
    protected void injectResources() {
        super.injectResources();
        inject(MyChartResources.INSTANCE.offlineExport().getText());
    }
}

Hi Greg,
is it possible for you to give example of changed Widgetset XML?

I have changed the AppWidgetset.gwt.xml at my local and it looks like still going Highcharts server.
When offline export enabled, I assume It wouldn’t make a call to remote server anymore, right?

Thank you,
Turgos

Inside the module tag, at the end, I included this:

    <replace-with class="domain.for.class.MyHighchartsScriptLoader">
    	<when-type-is class="com.vaadin.addon.charts.client.HighchartsScriptLoader" />
	</replace-with>

To make sure it doesn’t talk to the external export server, you may also need to set this property when configuring a Chart instance:

chart.getConfiguration().getExporting.setFallbackToExportServer(Boolean.FALSE);

Thank you for the quick reply. I guess I managed to pass the widgetset.gwt.xml file but hitting another problem.

Resource offline-exporting.js not found. Is the name specified as ClassLoader.getResource() would expect?
Errors in 'com/prj/kdn/client/MyHighchartsScriptLoader.java'
Line 13: Failed to resolve 'com.prj.kdn.client.MyHighchartsScriptLoader.MyChartResources' via deferred binding
[WARN]
 For the following type(s), generated source was never committed (did you forget to call commit()?)
[WARN]
 com.prj.kdn.client.MyHighchartsScriptLoader_MyChartResources_default_InlineClientBundleGenerator

> Task :vaadinCompile FAILED

Looking at this error, I assume I need to add the offline-exporting.js to my project.
I have downloaded it from https://code.highcharts.com/modules/offline-exporting.js

In this case, everything compiles, application starts, but when it comes to chart display, I see lots of javascript errors on browser side. Charts doesn’t display anymore.
So, I am guessing that I am not including the correct version of the “offline-exporting.js” into my project.

Am I at the right path? Do we need to add the “offline-exporting.js” into project and how can I get the correct version for the
vaadin-charts:4.0.5 ?

In relation to this topic, I was testing out the same steps above to do an offline export. However, I am unable to remove the option of exporting the chart to SVG (defaults as “Download Chart to SVG”) in the context menu. I’ve already declared in the instantiated Lang class to have the method setDownloadSVG as a blank (“”), yet still couldn’t manage to hide that menu. I’ve even removed the text and the onClick methods in the js files.

In that case, where have I missed out in removing that export option? I am using Charts version 4.2.0.