Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(572)

Side by Side Diff: runtime/bin/vmservice/client/lib/src/app/chart.dart

Issue 443713004: Rename vmservice/client to vmservice/observatory to match package name. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 part of app;
6
7 class GoogleChart {
8 static var _api;
9
10 /// Get access to the JsObject containing the Google Chart API:
11 /// https://developers.google.com/chart/interactive/docs/reference
12 static get api {
13 return _api;
14 }
15
16 static Completer _completer = new Completer();
17
18 static Future get onReady => _completer.future;
19
20 static bool get ready => _completer.isCompleted;
21
22 /// Load the Google Chart API. Returns a [Future] which completes
23 /// when the API is loaded.
24 static Future initOnce() {
25 Logger.root.info('Loading Google Charts API');
26 context['google'].callMethod('load',
27 ['visualization', '1', new JsObject.jsify({
28 'packages': ['corechart', 'table'],
29 'callback': new JsFunction.withThis(_completer.complete)
30 })]);
31 return _completer.future.then(_initOnceOnComplete);
32 }
33
34 static _initOnceOnComplete(_) {
35 Logger.root.info('Google Charts API loaded');
36 _api = context['google']['visualization'];
37 assert(_api != null);
38 return _api;
39 }
40 }
41
42 class DataTable {
43 final _table = new JsObject(GoogleChart.api['DataTable']);
44 /// Construct a Google Chart DataTable.
45 DataTable();
46
47 /// Number of columns.
48 int get columns => _table.callMethod('getNumberOfColumns');
49 /// Number of rows.
50 int get rows => _table.callMethod('getNumberOfRows');
51
52 /// Add a new column with [type] and [label].
53 /// type must be: 'string', 'number', or 'boolean'.
54 void addColumn(String type, String label) {
55 _table.callMethod('addColumn', [type, label]);
56 }
57
58 /// Add a new column with [type], [label] and [role].
59 /// Roles are used for metadata such as 'interval' or 'annotation'.
60 /// type must be: 'string', 'number', or 'boolean'.
61 void addRoleColumn(String type, String label, String role) {
62 _table.callMethod('addColumn', [new JsObject.jsify({
63 'type': type,
64 'label': label,
65 'role': role,
66 })]);
67 }
68
69 /// Remove rows [start, end).
70 void removeRows(int start, int end) {
71 _table.callMethod('removeRows', [start, end]);
72 }
73
74 /// Remove all rows in the table.
75 void clearRows() {
76 removeRows(0, rows);
77 }
78
79 /// Adds a new row to the table. [row] must have an entry for each
80 /// column in the table.
81 void addRow(List row) {
82 _table.callMethod('addRow', [new JsArray.from(row)]);
83 }
84 }
85
86 class Chart {
87 var _chart;
88 final Map options = new Map();
89
90 /// Create a Google Chart of [chartType]. e.g. 'Table', 'AreaChart',
91 /// 'BarChart', the chart is rendered inside [element].
92 Chart(String chartType, Element element) {
93 _chart = new JsObject(GoogleChart.api[chartType], [element]);
94 }
95
96 /// When the user interacts with the table by clicking on columns,
97 /// you must call this function before [draw] so that we draw
98 /// with the current sort settings.
99 void refreshOptionsSortInfo() {
100 var props = _chart.callMethod('getSortInfo');
101 if ((props != null) && (props['column'] != -1)) {
102 // Preserve current sort settings.
103 options['sortColumn'] = props['column'];
104 options['sortAscending'] = props['ascending'];
105 }
106 }
107
108 /// Draw this chart using [table] and the current [options].
109 void draw(DataTable table) {
110 var jsOptions = new JsObject.jsify(options);
111 _chart.callMethod('draw', [table._table, jsOptions]);
112 }
113 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698