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

Unified Diff: runtime/bin/vmservice/client/lib/src/observatory/chart.dart

Issue 148153007: Add Google Charts to Observatory and use it in allocation profiler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: runtime/bin/vmservice/client/lib/src/observatory/chart.dart
diff --git a/runtime/bin/vmservice/client/lib/src/observatory/chart.dart b/runtime/bin/vmservice/client/lib/src/observatory/chart.dart
new file mode 100644
index 0000000000000000000000000000000000000000..62045b3d976fd00490274b44c6d4e5e98d2ee1a0
--- /dev/null
+++ b/runtime/bin/vmservice/client/lib/src/observatory/chart.dart
@@ -0,0 +1,101 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+part of observatory;
+
+// Static utility methods hiding dart:js interop calls.
+class Chart extends Observable {
turnidge 2014/01/28 18:28:08 See my other comment. I am suggesting getting awa
+ static var _gviz;
+ static get gviz {
+ return _gviz;
+ }
+
+ static Future initOnce() {
+ Completer c = new Completer();
+ context['google'].callMethod('load',
+ ['visualization', '1', new JsObject.jsify({
+ 'packages': ['corechart', 'table'],
+ 'callback': new JsFunction.withThis(c.complete)
+ })]);
+ return c.future.then(_initOnceOnComplete);
+ }
+
+ static _initOnceOnComplete(_) {
+ Logger.root.info('Google Charts API loaded');
+ _gviz = context['google']['visualization'];
+ assert(_gviz != null);
+ return _gviz;
+ }
+
+ /// Create a Google Chart of [chartType]. e.g. 'Table', 'BarChart', the
+ /// chart is rendered inside [element].
+ static createChart(String chartType, Element element) {
+ return new JsObject(gviz[chartType], [element]);
+ }
+
+ /// Create a new DataTable.
+ static createDataTable() {
+ return new JsObject(gviz['DataTable']);
+ }
+
+ /// Add a column to [dataTable] with [type] and [label].
+ static addColumn(var dataTable, String type, String label) {
+ dataTable.callMethod('addColumn', [type, label]);
+ }
+
+ static addAnnotationColumn(var dataTable, String type, String label) {
+ dataTable.callMethod('addColumn', [new JsObject.jsify({
+ 'type': type,
+ 'label': label,
+ 'role': 'annotation',
+ })]);
+ }
+
+ static addIntervalColumn(var dataTable, String type, String label) {
+ dataTable.callMethod('addColumn', [new JsObject.jsify({
+ 'type': type,
+ 'label': label,
+ 'role': 'interval',
+ })]);
+ }
+
+ static clearRows(var dataTable) {
+ var rows = dataTable.callMethod('getNumberOfRows');
+ dataTable.callMethod('removeRows', [0, rows]);
+ }
+
+ static addRow(var dataTable, List row) {
+ dataTable.callMethod('addRow', [new JsArray.from(row)]);
+ }
+
+ static bool hasRows(var dataTable) {
+ var rows = dataTable.callMethod('getNumberOfRows');
+ return rows > 0;
+ }
+
+ static int numRows(var dataTable) {
+ return dataTable.callMethod('getNumberOfRows');
+ }
+
+ static bool hasColumns(var dataTable) {
+ var cols = dataTable.callMethod('getNumberOfColumns');
+ return cols > 0;
+ }
+
+ static int numColumns(var dataTable) {
+ return dataTable.callMethod('getNumberOfColumns');
+ }
+
+ static refreshTableChartDrawOptions(var chart, var options) {
+ var props = chart.callMethod('getSortInfo');
+ if (props != null) {
+ options['sortColumn'] = props['column'];
+ options['sortAscending'] = props['ascending'];
+ }
+ }
+
+ static draw(var chart, var table, var options) {
+ chart.callMethod('draw', [table, options]);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698