1+ ( function ( ) {
2+ var fc = angular . module ( 'ngFusionCharts' , [ ] ) ;
3+
4+
5+ fc . directive ( 'fcChart' , function ( $http ) {
6+ return {
7+ scope : {
8+ fcWidth : '@' ,
9+ fcHeight : '@' ,
10+ fcDataset : '@' ,
11+ fcCategories : '@' ,
12+ fcChartAttrs : '@' ,
13+ fcChartClick : '@'
14+ } ,
15+ link : function ( scope , element , attrs ) {
16+ var chart = null ,
17+ events = {
18+ chartClick : function ( ev , props ) {
19+ if ( attrs . fcChartClick ) {
20+ scope . $parent [ attrs . fcChartClick ] ( ev , props ) ;
21+ }
22+ }
23+ } ;
24+ if ( attrs . fcConfig ) {
25+ chart = new FusionCharts ( scope [ attrs . fcConfig ] ) ;
26+ scope [ attrs . fcChartObject ] = chart ;
27+ chart . render ( ) ;
28+ } else if ( attrs . fcJsonUrl ) {
29+ $http . get ( attrs . fcJsonUrl )
30+ . success ( function ( data ) {
31+ data . renderAt = element [ 0 ] ;
32+ chart = new FusionCharts ( data ) ;
33+ scope [ attrs . fcChartObject ] = chart ;
34+ chart . render ( ) ;
35+ } )
36+ . error ( function ( err ) {
37+ throw err ;
38+ } ) ;
39+ } else {
40+ var chartConfigObject = {
41+ type : attrs . fcType ,
42+ width : attrs . fcWidth ,
43+ height : attrs . fcHeight ,
44+ renderAt : element [ 0 ] ,
45+ dataFormat : attrs . fcDataFormat || 'json' ,
46+ dataSource : { } ,
47+ events : events
48+ } ;
49+ attrs . $observe ( 'fcWidth' , function ( newVal ) {
50+ chart . resizeTo ( scope . fcWidth , scope . fcHeight ) ;
51+ } ) ;
52+ attrs . $observe ( 'fcHeight' , function ( newVal ) {
53+ chart . resizeTo ( scope . fcWidth , scope . fcHeight ) ;
54+ } ) ;
55+
56+ if ( attrs . fcDatasource ) {
57+ chartConfigObject . dataSource = scope [ attrs . fcDatasource ] ;
58+ attrs . $observe ( 'fcDatasource' , function ( newVal ) {
59+ chart . setJSONData ( JSON . parse ( newVal ) ) ;
60+ } , true ) ;
61+ } else {
62+ // chartConfigObject.dataSource.chart = scope[attrs.fcChartAttrs];
63+ attrs . $observe ( 'fcChartAttrs' , function ( newVal ) {
64+ setTimeout ( function ( ) {
65+ chartConfigObject . dataSource . chart = JSON . parse ( newVal ) ;
66+ chart . setJSONData ( chartConfigObject . dataSource ) ;
67+ } , 0 ) ;
68+ } , true )
69+ if ( attrs . fcData ) {
70+ // chartConfigObject.data = scope[attrs.fcData];
71+ attrs . $observe ( 'fcData' , function ( newVal ) {
72+ setTimeout ( function ( ) {
73+ chartConfigObject . dataSource . data = JSON . parse ( newVal ) ;
74+ chart . setJSONData ( chartConfigObject . dataSource ) ;
75+ } , 0 ) ;
76+ } , true ) ;
77+ }
78+ if ( attrs . fcCategories ) {
79+ // chartConfigObject.dataSource.categories = scope[attrs.fcCategories];
80+ attrs . $observe ( 'fcCategories' , function ( newVal ) {
81+ setTimeout ( function ( ) {
82+ chartConfigObject . dataSource . categories = JSON . parse ( newVal ) ;
83+ chart . setJSONData ( chartConfigObject . dataSource ) ;
84+ } , 0 ) ;
85+ } , true ) ;
86+ }
87+ if ( attrs . fcDataset ) {
88+ // chartConfigObject.dataSource.dataset = scope[attrs.fcDataset];
89+ attrs . $observe ( 'fcDataset' , function ( newVal ) {
90+ setTimeout ( function ( ) {
91+ chartConfigObject . dataSource . dataset = JSON . parse ( newVal ) ;
92+ chart . setJSONData ( chartConfigObject . dataSource ) ;
93+ } ) ;
94+ } , true ) ;
95+ }
96+
97+ }
98+
99+ var chart = new FusionCharts ( chartConfigObject ) ;
100+ scope [ attrs . fcChartObject ] = chart ;
101+ chart . render ( ) ;
102+ }
103+ }
104+ }
105+ } ) ;
106+ } ( ) ) ;
0 commit comments