Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: lazy load Highcharts #1087

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading