This repository was archived by the owner on Nov 25, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -53,14 +53,27 @@ function generateCode(labels) {
53
53
const HierarchicalPlugin = {
54
54
id : 'chartJsPluginHierarchical' ,
55
55
56
+ _isValidScaleType ( chart , scale ) {
57
+ if ( ! chart . config . options . scales . hasOwnProperty ( scale ) ) {
58
+ return false ;
59
+ }
60
+ if ( ! Array . isArray ( chart . config . options . scales [ scale ] ) ) {
61
+ return false ;
62
+ }
63
+ return chart . config . options . scales [ scale ] [ 0 ] . hasOwnProperty ( 'type' ) ;
64
+ } ,
65
+
56
66
/**
57
67
* checks whether this plugin needs ot be enabled based on wehther one is a hierarchical axis
58
68
*/
59
69
_enabled ( chart ) {
60
- if ( chart . config . options . scales . xAxes [ 0 ] . type === 'hierarchical' ) {
70
+ if ( ! chart . config . options . hasOwnProperty ( 'scales' ) ) {
71
+ return null ;
72
+ }
73
+ if ( this . _isValidScaleType ( chart , 'xAxes' ) && chart . config . options . scales . xAxes [ 0 ] . type === 'hierarchical' ) {
61
74
return 'x' ;
62
75
}
63
- if ( chart . config . options . scales . yAxes [ 0 ] . type === 'hierarchical' ) {
76
+ if ( this . _isValidScaleType ( chart , 'yAxes' ) && chart . config . options . scales . yAxes [ 0 ] . type === 'hierarchical' ) {
64
77
return 'y' ;
65
78
}
66
79
return null ;
You can’t perform that action at this time.
0 commit comments