chartist-js / chartist

Simple responsive charts
https://chartist.dev
MIT License
13.33k stars 2.54k forks source link

NodeJS JSDOM support - ability to render on the backend #1424

Open Darker opened 5 months ago

Darker commented 5 months ago

Would you like to work on this feature?

What problem are you trying to solve?

I wanted to use this library to render a chart in an Express endpoint, or to a file.

Describe the solution you'd like

When I write code that manipulates DOM, I either have a optional argument for document or take document from element.ownerDocument if I am already taking an element as an argument. Similar solution would work here. This would require some changes to eliminate any global window and document references, but would help for two cases:

  1. Running this on the backend
  2. Trying to render chart in an iframe from the top level frame

Describe alternatives you've considered

I will try to mock window and document, but I don't think it is going to work.

Documentation, Adoption, Migration Strategy

Users should not notice a difference. The changes would only take an effect when the element is passed to chart constructor. In that case, that elements parent window and document would be used, instead of the globals.