| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of app; | 5 part of app; |
| 6 | 6 |
| 7 class GoogleChart { | 7 class GoogleChart { |
| 8 static var _api; | 8 static var _api; |
| 9 | 9 |
| 10 /// Get access to the JsObject containing the Google Chart API: | 10 /// Get access to the JsObject containing the Google Chart API: |
| 11 /// https://developers.google.com/chart/interactive/docs/reference | 11 /// https://developers.google.com/chart/interactive/docs/reference |
| 12 static get api { | 12 static get api { |
| 13 return _api; | 13 return _api; |
| 14 } | 14 } |
| 15 | 15 |
| 16 static Completer _completer = new Completer(); |
| 17 |
| 18 static Future get onReady => _completer.future; |
| 19 |
| 20 static bool get ready => _completer.isCompleted; |
| 21 |
| 16 /// Load the Google Chart API. Returns a [Future] which completes | 22 /// Load the Google Chart API. Returns a [Future] which completes |
| 17 /// when the API is loaded. | 23 /// when the API is loaded. |
| 18 static Future initOnce() { | 24 static Future initOnce() { |
| 19 Completer c = new Completer(); | |
| 20 Logger.root.info('Loading Google Charts API'); | 25 Logger.root.info('Loading Google Charts API'); |
| 21 context['google'].callMethod('load', | 26 context['google'].callMethod('load', |
| 22 ['visualization', '1', new JsObject.jsify({ | 27 ['visualization', '1', new JsObject.jsify({ |
| 23 'packages': ['corechart', 'table'], | 28 'packages': ['corechart', 'table'], |
| 24 'callback': new JsFunction.withThis(c.complete) | 29 'callback': new JsFunction.withThis(_completer.complete) |
| 25 })]); | 30 })]); |
| 26 return c.future.then(_initOnceOnComplete); | 31 return _completer.future.then(_initOnceOnComplete); |
| 27 } | 32 } |
| 28 | 33 |
| 29 static _initOnceOnComplete(_) { | 34 static _initOnceOnComplete(_) { |
| 30 Logger.root.info('Google Charts API loaded'); | 35 Logger.root.info('Google Charts API loaded'); |
| 31 _api = context['google']['visualization']; | 36 _api = context['google']['visualization']; |
| 32 assert(_api != null); | 37 assert(_api != null); |
| 33 return _api; | 38 return _api; |
| 34 } | 39 } |
| 35 } | 40 } |
| 36 | 41 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 options['sortAscending'] = props['ascending']; | 104 options['sortAscending'] = props['ascending']; |
| 100 } | 105 } |
| 101 } | 106 } |
| 102 | 107 |
| 103 /// Draw this chart using [table] and the current [options]. | 108 /// Draw this chart using [table] and the current [options]. |
| 104 void draw(DataTable table) { | 109 void draw(DataTable table) { |
| 105 var jsOptions = new JsObject.jsify(options); | 110 var jsOptions = new JsObject.jsify(options); |
| 106 _chart.callMethod('draw', [table._table, jsOptions]); | 111 _chart.callMethod('draw', [table._table, jsOptions]); |
| 107 } | 112 } |
| 108 } | 113 } |
| OLD | NEW |