|
2 | 2 | 'use strict'; |
3 | 3 | angular.module('zingchart-angularjs', [] ) |
4 | 4 | .directive('zingchart', [function(){ |
| 5 | + var currentAutoId = 1; |
| 6 | + |
5 | 7 | return { |
6 | 8 | restrict : 'EA', |
7 | 9 | scope : { |
|
10 | 12 | zcRender : '=' |
11 | 13 | }, |
12 | 14 | controller : ['$scope', '$element', '$attrs', function($scope, $element, $attrs){ |
| 15 | + var id; |
| 16 | + |
| 17 | + // Get or generate id |
| 18 | + if(!$element.attr('id')){ |
| 19 | + id = 'zingchart-auto-' + currentAutoId; |
| 20 | + currentAutoId++; |
| 21 | + $element.attr('id', id); |
| 22 | + } else { |
| 23 | + id = $element.attr('id'); |
| 24 | + } |
| 25 | + |
13 | 26 | var initializing = { |
14 | 27 | json : true, |
15 | 28 | values :true |
|
21 | 34 | } |
22 | 35 | if($scope.zcValues){ |
23 | 36 | if(isMultiArray($scope.zcValues)){ |
24 | | - zingchart.exec($attrs.id, 'setseriesvalues', { |
| 37 | + zingchart.exec(id, 'setseriesvalues', { |
25 | 38 | values : $scope.zcValues |
26 | 39 | }); |
27 | 40 | } |
28 | 41 | else{ |
29 | | - zingchart.exec($attrs.id, 'setseriesvalues', { |
| 42 | + zingchart.exec(id, 'setseriesvalues', { |
30 | 43 | values : [$scope.zcValues] |
31 | 44 | }); |
32 | 45 | } |
|
64 | 77 | else{ |
65 | 78 | _json.type = ($attrs.zcType) ? $attrs.zcType : _json.type |
66 | 79 | } |
67 | | - zingchart.exec($attrs.id, 'setdata', { |
| 80 | + zingchart.exec(id, 'setdata', { |
68 | 81 | data : _json |
69 | 82 | }); |
70 | 83 | } |
71 | 84 | },true); |
72 | 85 |
|
73 | 86 | }], |
74 | 87 | link : function($scope, $element, $attrs){ |
75 | | - //Setup json : |
76 | | - if(!$attrs.id){ |
77 | | - throw new Error('ZingChart-AngularJS : Attribute ID needed'); |
78 | | - } |
| 88 | + var id = $element.attr('id'); |
79 | 89 |
|
80 | 90 | //Defaults |
81 | 91 | var _json = { |
|
128 | 138 | _json.data.type = ($attrs.zcType) ? $attrs.zcType : _json.data.type; |
129 | 139 | _json.height = ($attrs.zcHeight) ? $attrs.zcHeight : _json.height; |
130 | 140 | _json.width = ($attrs.zcWidth) ? $attrs.zcWidth : _json.width; |
131 | | - _json.id = $attrs.id; |
| 141 | + _json.id = id; |
132 | 142 |
|
133 | 143 | //Set the box-model of the container element if the height or width are defined as 100%. |
134 | 144 | if(_json.width === "100%" && !$element.width){ |
|
0 commit comments