1
1
import { registerDestructor } from '@ember/destroyable' ;
2
2
import merge from 'deepmerge' ;
3
3
import Modifier from 'ember-modifier' ;
4
- import Highcharts from 'highcharts' ;
5
- import highchartsAccessibilty from 'highcharts/modules/accessibility' ;
6
4
7
5
const optionsForAllCharts = {
8
6
credits : {
@@ -21,26 +19,33 @@ const optionsForAllCharts = {
21
19
} ;
22
20
23
21
export default class DrawChartModifier extends Modifier {
24
- constructor ( owner , args ) {
25
- super ( owner , args ) ;
22
+ highcharts ;
26
23
27
- this . initializeHighcharts ( ) ;
28
- }
29
-
30
- modify ( element , [ chart ] ) {
24
+ async modify ( element , [ chart ] ) {
31
25
if ( ! chart ) {
32
26
return ;
33
27
}
34
28
29
+ await this . initializeHighcharts ( ) ;
30
+
35
31
this . drawChart ( { chart, element } ) ;
36
32
37
33
registerDestructor ( this , this . destroyChart . bind ( this ) ) ;
38
34
}
39
35
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 ) ;
42
47
43
- this . highcharts = Highcharts ;
48
+ this . highcharts = highcharts ;
44
49
this . highcharts . setOptions ( optionsForAllCharts ) ;
45
50
}
46
51
0 commit comments