11import { registerDestructor } from '@ember/destroyable' ;
22import merge from 'deepmerge' ;
33import Modifier from 'ember-modifier' ;
4- import Highcharts from 'highcharts' ;
5- import highchartsAccessibilty from 'highcharts/modules/accessibility' ;
64
75const optionsForAllCharts = {
86 credits : {
@@ -21,26 +19,33 @@ const optionsForAllCharts = {
2119} ;
2220
2321export default class DrawChartModifier extends Modifier {
24- constructor ( owner , args ) {
25- super ( owner , args ) ;
22+ highcharts ;
2623
27- this . initializeHighcharts ( ) ;
28- }
29-
30- modify ( element , [ chart ] ) {
24+ async modify ( element , [ chart ] ) {
3125 if ( ! chart ) {
3226 return ;
3327 }
3428
29+ await this . initializeHighcharts ( ) ;
30+
3531 this . drawChart ( { chart, element } ) ;
3632
3733 registerDestructor ( this , this . destroyChart . bind ( this ) ) ;
3834 }
3935
40- initializeHighcharts ( ) {
41- highchartsAccessibilty ( Highcharts ) ;
36+ async initializeHighcharts ( ) {
37+ if ( this . highcharts ) {
38+ return ;
39+ }
40+
41+ const { default : highcharts } = await import ( 'highcharts' ) ;
42+ const { default : highchartsAccessibilty } = await import (
43+ 'highcharts/modules/accessibility'
44+ ) ;
45+
46+ highchartsAccessibilty ( highcharts ) ;
4247
43- this . highcharts = Highcharts ;
48+ this . highcharts = highcharts ;
4449 this . highcharts . setOptions ( optionsForAllCharts ) ;
4550 }
4651
0 commit comments