load echarts as JS modules if data-filename attr

This commit is contained in:
Mij 2022-09-01 20:37:15 +02:00
parent b81607c09e
commit 137e99df11

View file

@ -515,8 +515,20 @@ class Theme {
} }
this._echartsArr = []; this._echartsArr = [];
this.util.forEach(document.getElementsByClassName('echarts'), $echarts => { this.util.forEach(document.getElementsByClassName('echarts'), $echarts => {
const chart = echarts.init($echarts, this.isDark ? 'dark' : 'light', {renderer: 'svg'}); let filename = $echarts.dataset.filename;
const chart = echarts.init($echarts, this.isDark ? 'dark' : 'macarons', {renderer: 'svg'});
if (! filename) {
// has chart config stored in some element ID as JSON
chart.setOption(JSON.parse(this.data[$echarts.id])); chart.setOption(JSON.parse(this.data[$echarts.id]));
} else {
// has data-filename attribute => load chart config from external file
$echarts.innerHTML = '';
import(filename).then(module => {
chart.setOption(module.option);
}).catch((err) => {
console.error("While loading eChart for " + filename + ": " + err);
})
}
this._echartsArr.push(chart); this._echartsArr.push(chart);
}); });
}); });