Skip to content

Commit

Permalink
feat: lazy load highcharts
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnaceMaes committed Feb 21, 2024
1 parent 02d09b9 commit 10927a1
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions app/modifiers/draw-chart.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { registerDestructor } from '@ember/destroyable';
import merge from 'deepmerge';
import Modifier from 'ember-modifier';
import Highcharts from 'highcharts';
import highchartsAccessibilty from 'highcharts/modules/accessibility';

const optionsForAllCharts = {
credits: {
Expand All @@ -21,26 +19,33 @@ const optionsForAllCharts = {
};

export default class DrawChartModifier extends Modifier {
constructor(owner, args) {
super(owner, args);
highcharts;

this.initializeHighcharts();
}

modify(element, [chart]) {
async modify(element, [chart]) {
if (!chart) {
return;
}

await this.initializeHighcharts();

this.drawChart({ chart, element });

registerDestructor(this, this.destroyChart.bind(this));
}

initializeHighcharts() {
highchartsAccessibilty(Highcharts);
async initializeHighcharts() {
if (this.highcharts) {
return;
}

const { default: highcharts } = await import('highcharts');
const { default: highchartsAccessibilty } = await import(
'highcharts/modules/accessibility'
);

highchartsAccessibilty(highcharts);

this.highcharts = Highcharts;
this.highcharts = highcharts;
this.highcharts.setOptions(optionsForAllCharts);
}

Expand Down

0 comments on commit 10927a1

Please sign in to comment.