drmrbrewer
Posts: 248
Joined: Sat Sep 06, 2014 6:39 pm

Advanced customisations when using the export server as a node module

I am trying to use the highcharts node export server as a module (see https://github.com/highcharts/node-expo ... ejs-module), not as a server, i.e. like the example code given in the above section of the docs.

But I also want to do some custom stuff, to generate the options for the chart, to override certain core functions of Highcharts, and also to manipulate the chart after it is first generated (e.g. to move stuff around or add other custom elements).

I think that I should be able to use callback, resources and customCode to achieve this, but I can't seem to get these to work... whatever I try I get errors. And yes I have set allowCodeExecution to 1 in the exportSettings object passed to exporter.export().

I note that it is also possible to pass a custom worker script to exporter.initPool()... in that case I guess we can start with copy/pasting the default worker (https://github.com/highcharts/node-expo ... /worker.js) and modify it for our needs?

Is there a very simple working example of using these customisations (callback, resources customCode and worker ) with the export server as a node module?
drmrbrewer
Posts: 248
Joined: Sat Sep 06, 2014 6:39 pm

Re: Advanced customisations when using the export server as a node module

Any ideas about this one? I can’t believe there isn’t a really simple working example out there, but I certainly haven’t been able to find one.
User avatar
dawid.d
Posts: 837
Joined: Thu Oct 06, 2022 11:31 am

Re: Advanced customisations when using the export server as a node module

Hi,

Thanks for contacting us with your question and I'm sorry for the late response.

In the export server's repository (see: https://github.com/highcharts/node-expo ... ster/tests), there is a tests folder, where you can find examples for modules. Unfortunately, I don't think there would be something more when it comes to available examples. Alternatively, you can share your code in the form of a demo, maybe I will be able to help you on a live example.

Best regards!
Dawid Draguła
Highcharts Developer
drmrbrewer
Posts: 248
Joined: Sat Sep 06, 2014 6:39 pm

Re: Advanced customisations when using the export server as a node module

Hi Dawid

Thanks for the reply.

That tests folder is useful but only to a limited extent. The sorts of issues I'm having are shown via the following code example (I'm only using jsfiddle as a way of properly formatting and displaying the code... I find it's difficult on this forum):

https://jsfiddle.net/o2pvx3ke/

The content of ./lib/ is explained at the top of the comments.

As can be seen in the comments, when I specify customCode directly as a function, and callback directly as a string (not a function), it works OK.

But this isn't practical, particularly for the callback... I thought that it was possible to define this in a separate file, as actual javascript (for development purposes)? But trying this ends in an error.

Same for customCode... can't seem to have this as a separate file?

Note that (as an example) I'm referring to the lodash library, and testing this using _.round(4.006, 2) in the customCode and callback functions.

Note that I am also passing a "custom" worker to exporter.initPool()... to offer further ability to customise operation (but at present just using the default worker.js for testing)... that much seems to work.

Thanks.
User avatar
dawid.d
Posts: 837
Joined: Thu Oct 06, 2022 11:31 am

Re: Advanced customisations when using the export server as a node module

Hi,

Thanks for sharing the code. I have contacted the export server development team about your problem and will let you know as soon as I get a response.

Regards!
Dawid Draguła
Highcharts Developer
drmrbrewer
Posts: 248
Joined: Sat Sep 06, 2014 6:39 pm

Re: Advanced customisations when using the export server as a node module

Actually this is more the sort of model I'm trying to use:

https://jsfiddle.net/kxmasnz0/

I have a MyChart function/class which I create an instance of, and use the myChart instance to get the chart options and also the callback, with the callback function referring to other functions and variables in the myChart instance. In reality, in my actual code, the MyChart utility class will of course be more sophisticated and handle more data processing (for the input options) and chart manipulation (via the callback).

Is this possible?
drmrbrewer
Posts: 248
Joined: Sat Sep 06, 2014 6:39 pm

Re: Advanced customisations when using the export server as a node module

And also... will this be possible with the puppeteer version (currently only available via the branch https://github.com/highcharts/node-expo ... /puppeteer)? I feel like it ought to be possible... if not now, then maybe it could be in future?
User avatar
dawid.d
Posts: 837
Joined: Thu Oct 06, 2022 11:31 am

Re: Advanced customisations when using the export server as a node module

Hi,

I've received the answer!

I recommend trying the new Puppetter version right away. There it should work as you need. Here is a new description of all options:
  • The --allowFileResources and --allowCodeExecution flags must be set to true for any custom code and file system-related properties to be considered. Since there is a danger of injections, such an environment should be a sandbox. That's why we have these options set to false by default.
  • You can use --callback from a separate file. But you have to remember that this is a callback to the constructor, where this is a chart.
  • As for the --customCode issue, the functionality of this option has been changed, which now works so that it is the code that is executed just before creating the chart. The description of the option says what it can be (code, path to a file with a function or normal code, which will later be wrapped in a self-invoke in the code).
  • There is also the --resources option. It can be an object or a path to a file that the object has. It may contain three sections:
    • js: Stringified JS code.
    • css: Raw CSS in the form of a string.
    • files: An array containing paths to JS files that will be executed after chart creation.
Since demos and examples are quite scarce in the old export server, a large number of option use cases have been created. You might be interested in the specific file ./tests/node/scenarios/allow_file_resources.json. It contains an example of using all options related to the use of custom code. This is one of the scenarios triggered by the file ./tests/node/scenarios/allow_file_resources.json, which is a node runner for the created scenarios.

Regarding the old version, --callback and --resources should work similarly, but sometimes had problems. The same is true of the highexp.done() function, which is supposed to wait for async code (unfortunately, PhantomJS doesn't wait by itself), but that might not have worked in all cases either.

If you have any questions or suggestions/issues/features, you can report them on our GitHub directly to the dev team here:
https://github.com/highcharts/node-export-server/issues

Best regards!
Dawid Draguła
Highcharts Developer
drmrbrewer
Posts: 248
Joined: Sat Sep 06, 2014 6:39 pm

Re: Advanced customisations when using the export server as a node module

OK thanks. I still can't get it working, particularly with the sort of model I referred to in my second example (viewtopic.php?f=9&t=50529#p184894).

I posted an issue directly over on GitHub as suggested, but it looks like there have been no replies on any issues for at least 6 months so I'm not sure how active this project really is :(
User avatar
dawid.d
Posts: 837
Joined: Thu Oct 06, 2022 11:31 am

Re: Advanced customisations when using the export server as a node module

You're welcome!

This project is still being developed; I've sent a link to your issue to the dev team, so I think you should get an answer soon.

​If you have any further inquiries, you may reach out to me at any time.
Kind regards!
Dawid Draguła
Highcharts Developer
drmrbrewer
Posts: 248
Joined: Sat Sep 06, 2014 6:39 pm

Re: Advanced customisations when using the export server as a node module

It seems like things move rather slowly over at highcharts/node-export-server because I'm still waiting for a response to my issue (https://github.com/highcharts/node-expo ... issues/391).
User avatar
dawid.d
Posts: 837
Joined: Thu Oct 06, 2022 11:31 am

Re: Advanced customisations when using the export server as a node module

Hi,

Thanks for the message. I let the dev team know again that you are still waiting for a reply.

Regards
Dawid Draguła
Highcharts Developer
User avatar
dawid.d
Posts: 837
Joined: Thu Oct 06, 2022 11:31 am

Re: Advanced customisations when using the export server as a node module

Hi,

Looks like you just got a pretty comprehensive answer. I put a link to it here: https://github.com/highcharts/node-expo ... 1503264541

Best regards!
Dawid Draguła
Highcharts Developer

Return to “Highcharts Usage”