chartist-js / chartist

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

[Bug]: Using responsive options fails on some browsers #1390

Open s-szabo opened 1 year ago

s-szabo commented 1 year ago

Would you like to work on a fix?

Current and expected behavior

For specified media types the responsiveOptions (4th option of a chart function e.g. LineChart(..., ..., ..., responsiveOptions)) can be set. In case of some browsers (e.g. Safari 13.1.2 on macOS High Sierra 10.13.6) when you use the responsive Options chartist stops with error. The root cause of the error is the matchMedia function, because in case of some browsers the result object of the matchMedia has only an addListener function instead of the addEventListener function.

Reproduction

Use responsiveOption with e.g. a LineChart in Safari 13.1.2 with macOS High Sierra 10.13.6

Chartist version

v1.3.0

Possible solution

Change the mql.addEventListener("change", updateCurrentOptions); row in the } else if (responsiveOptions) {...} block of chartist to

if (mql.addEventListener) {
    mql.addEventListener("change", updateCurrentOptions);
} else {
    mql.addListener(updateCurrentOptions);
}

This can be found in the row # 1440 of the index.js of npm package of chartist.