@@ -33,40 +33,12 @@ export default class OrgChart extends HTMLElement {
3333 'pan' : false ,
3434 'zoom' : false
3535 } ,
36- opts = Object . assign ( defaultOptions , options ) ,
37- data = opts . data ,
38- chart = document . createElement ( 'div' ) ;
36+ opts = Object . assign ( defaultOptions , options ) ;
3937
4038 this . options = opts ;
41- delete this . options . data ;
42- this . dataset . options = JSON . stringify ( opts ) ;
43- this . setAttribute ( 'class' , 'orgchart' + ( opts . chartClass !== '' ? ' ' + opts . chartClass : '' ) +
44- ( opts . direction !== 't2b' ? ' ' + opts . direction : '' ) ) ;
45- if ( typeof data === 'object' ) { // local json datasource
46- this . buildHierarchy ( this , opts . ajaxURL ? data : this . _attachRel ( data , '00' ) , 0 ) ;
47- } else if ( typeof data === 'string' && data . startsWith ( '#' ) ) { // ul datasource
48- this . buildHierarchy ( this , this . _buildJsonDS ( document . querySelector ( data ) . children [ 0 ] ) , 0 ) ;
49- } else { // ajax datasource
50- let spinner = document . createElement ( 'i' ) ;
5139
52- spinner . setAttribute ( 'class' , 'fa fa-circle-o-notch fa-spin spinner' ) ;
53- this . appendChild ( spinner ) ;
54- this . _getJSON ( data )
55- . then ( function ( resp ) {
56- that . buildHierarchy ( that , opts . ajaxURL ? resp : that . _attachRel ( resp , '00' ) , 0 ) ;
57- } )
58- . catch ( function ( err ) {
59- console . error ( 'failed to fetch datasource for orgchart' , err ) ;
60- } )
61- . finally ( function ( ) {
62- let spinner = that . querySelector ( '.spinner' ) ;
63-
64- spinner . parentNode . removeChild ( spinner ) ;
65- } ) ;
66- }
6740 this . addEventListener ( 'click' , this . _clickChart . bind ( this ) ) ;
6841
69-
7042 if ( opts . pan && opts . chartContainer ) {
7143 let chartContainer = document . querySelector ( opts . chartContainer ) ;
7244
@@ -87,7 +59,34 @@ export default class OrgChart extends HTMLElement {
8759 }
8860 }
8961 connectedCallback ( ) {
62+ let that = this ,
63+ opts = this . options ,
64+ data = opts . data ;
9065
66+ this . setAttribute ( 'class' , 'orgchart' + ( opts . chartClass !== '' ? ' ' + opts . chartClass : '' ) +
67+ ( opts . direction !== 't2b' ? ' ' + opts . direction : '' ) ) ;
68+ if ( typeof data === 'object' ) { // local json datasource
69+ this . buildHierarchy ( this , opts . ajaxURL ? data : this . _attachRel ( data , '00' ) , 0 ) ;
70+ } else if ( typeof data === 'string' && data . startsWith ( '#' ) ) { // ul datasource
71+ this . buildHierarchy ( this , this . _buildJsonDS ( document . querySelector ( data ) . children [ 0 ] ) , 0 ) ;
72+ } else { // ajax datasource
73+ let spinner = document . createElement ( 'i' ) ;
74+
75+ spinner . setAttribute ( 'class' , 'fa fa-circle-o-notch fa-spin spinner' ) ;
76+ this . appendChild ( spinner ) ;
77+ this . _getJSON ( data )
78+ . then ( function ( resp ) {
79+ that . buildHierarchy ( that , opts . ajaxURL ? resp : that . _attachRel ( resp , '00' ) , 0 ) ;
80+ } )
81+ . catch ( function ( err ) {
82+ console . error ( 'failed to fetch datasource for orgchart' , err ) ;
83+ } )
84+ . finally ( function ( ) {
85+ let spinner = that . querySelector ( '.spinner' ) ;
86+
87+ spinner . parentNode . removeChild ( spinner ) ;
88+ } ) ;
89+ }
9190 }
9291 disconnectedCallback ( ) {
9392
0 commit comments