1 | // Generated by CoffeeScript 1.8.0 |
||
2 | angular.module('angular-flot', []).directive('flot', function() { |
||
3 | return { |
||
4 | restrict: 'EA', |
||
5 | template: '<div></div>', |
||
6 | scope: { |
||
7 | dataset: '=', |
||
8 | options: '=', |
||
9 | callback: '=' |
||
10 | }, |
||
11 | link: function(scope, element, attributes) { |
||
12 | var height, init, onDatasetChanged, onOptionsChanged, plot, plotArea, width, _ref, _ref1; |
||
13 | plot = null; |
||
14 | width = attributes.width || '100%'; |
||
15 | height = attributes.height || '100%'; |
||
16 | if (((_ref = scope.options) != null ? (_ref1 = _ref.legend) != null ? _ref1.container : void 0 : void 0) instanceof jQuery) { |
||
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
17 | throw 'Please use a jQuery expression string with the "legend.container" option.'; |
||
18 | } |
||
19 | if (!scope.dataset) { |
||
20 | scope.dataset = []; |
||
21 | } |
||
22 | if (!scope.options) { |
||
23 | scope.options = { |
||
24 | legend: { |
||
25 | show: false |
||
26 | } |
||
27 | }; |
||
28 | } |
||
29 | plotArea = $(element.children()[0]); |
||
30 | plotArea.css({ |
||
31 | width: width, |
||
32 | height: height |
||
33 | }); |
||
34 | init = function() { |
||
35 | var plotObj; |
||
36 | plotObj = $.plot(plotArea, scope.dataset, scope.options); |
||
37 | if (scope.callback) { |
||
38 | scope.callback(plotObj); |
||
39 | } |
||
40 | return plotObj; |
||
41 | }; |
||
42 | onDatasetChanged = function(dataset) { |
||
43 | if (plot) { |
||
44 | plot.setData(dataset); |
||
45 | plot.setupGrid(); |
||
46 | return plot.draw(); |
||
47 | } else { |
||
48 | return plot = init(); |
||
49 | } |
||
50 | }; |
||
51 | scope.$watch('dataset', onDatasetChanged, true); |
||
52 | onOptionsChanged = function() { |
||
53 | return plot = init(); |
||
54 | }; |
||
55 | return scope.$watch('options', onOptionsChanged, true); |
||
56 | } |
||
57 | }; |
||
58 | }); |
||
59 |