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

Side by Side Diff: runtime/observatory/lib/src/elements/metrics.dart

Issue 1310153002: Switch from Google charts to Charted (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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
OLDNEW
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 library metrics; 5 library metrics;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:html'; 8 import 'dart:html';
9 import 'observatory_element.dart'; 9 import 'observatory_element.dart';
10 import 'package:charted/charted.dart';
10 import 'package:observatory/app.dart'; 11 import 'package:observatory/app.dart';
11 import 'package:observatory/service.dart'; 12 import 'package:observatory/service.dart';
12 import 'package:polymer/polymer.dart'; 13 import 'package:polymer/polymer.dart';
13 14
14 @CustomTag('metrics-page') 15 @CustomTag('metrics-page')
15 class MetricsPageElement extends ObservatoryElement { 16 class MetricsPageElement extends ObservatoryElement {
16 MetricsPageElement.created() : super.created(); 17 MetricsPageElement.created() : super.created();
17 18
18 @observable MetricsPage page; 19 @observable MetricsPage page;
19 @observable Isolate isolate; 20 @observable Isolate isolate;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 return; 146 return;
146 } 147 }
147 metric.sampleBufferSize = value; 148 metric.sampleBufferSize = value;
148 } 149 }
149 } 150 }
150 151
151 @CustomTag('metrics-graph') 152 @CustomTag('metrics-graph')
152 class MetricsGraphElement extends ObservatoryElement { 153 class MetricsGraphElement extends ObservatoryElement {
153 MetricsGraphElement.created() : super.created(); 154 MetricsGraphElement.created() : super.created();
154 155
155 final DataTable _table = new DataTable(); 156 HtmlElement _wrapper;
156 Chart _chart; 157 HtmlElement _areaHost;
158 CartesianArea _area;
159 ChartData _data;
160 final _columns = [
161 new ChartColumnSpec(label: 'Time', type: ChartColumnSpec.TYPE_TIMESTAMP),
162 new ChartColumnSpec(label: 'Value', formatter: (v) => v.toString())
163 ];
164 final _rows = [[0, 1000000.0]];
157 165
158 @published ServiceMetric metric; 166 @published ServiceMetric metric;
159 @observable Isolate isolate; 167 @observable Isolate isolate;
160 168
161 void attached() { 169 void attached() {
170 super.attached();
162 // Redraw once a second. 171 // Redraw once a second.
163 pollPeriod = new Duration(seconds: 1); 172 pollPeriod = new Duration(seconds: 1);
164 super.attached(); 173 _reset();
165 } 174 }
166 175
167 void onPoll() { 176 void onPoll() {
168 draw();
169 }
170
171 void draw() {
172 if (_chart == null) {
173 // Construct chart.
174 var element = shadowRoot.querySelector('#graph');
175 if (element == null) {
176 // Bail.
177 return;
178 }
179 _chart = new Chart('LineChart', element);
180 }
181 if (metric == null) { 177 if (metric == null) {
182 return; 178 return;
183 } 179 }
184 _update(); 180 _update();
185 _chart.draw(_table); 181 _draw();
186 } 182 }
187 183
188 void _setupInitialDataTable() { 184 void _reset() {
189 _table.clearColumns(); 185 _rows.clear();
190 // Only one metric right now. 186 _wrapper = shadowRoot.querySelector('#metric-chart');
191 _table.addColumn('timeofday', 'time'); 187 assert(_wrapper != null);
192 _table.addColumn('number', metric.name); 188 _areaHost = _wrapper.querySelector('.chart-host');
189 assert(_areaHost != null);
190 _areaHost.children.clear();
191 var series = new ChartSeries("one", [1], new LineChartRenderer());
192 var config = new ChartConfig([series], [0]);
193 config.minimumSize = new Rect(800, 600);
194 _data = new ChartData(_columns, _rows);
195 _area = new CartesianArea(_areaHost,
196 _data,
197 config,
198 state: new ChartState());
193 } 199 }
194 200
195 void _update() { 201 void _update() {
196 _table.clearRows(); 202 _rows.clear();
197 for (var i = 0; i < metric.samples.length; i++) { 203 for (var i = 0; i < metric.samples.length; i++) {
198 var sample = metric.samples[i]; 204 var sample = metric.samples[i];
199 _table.addTimeOfDayValue(sample.time, sample.value); 205 _rows.add([sample.time.millisecondsSinceEpoch, sample.value]);
200 } 206 }
201 } 207 }
202 208
209 void _draw() {
210 if (_rows.length < 2) {
211 return;
212 }
213 _area.data = new ChartData(_columns, _rows);
214 _area.draw();
215 }
216
203 metricChanged(oldValue) { 217 metricChanged(oldValue) {
204 if (oldValue != metric) { 218 if (oldValue != metric) {
205 _setupInitialDataTable(); 219 _reset();
206 } 220 }
207 } 221 }
208 } 222 }
OLDNEW
« no previous file with comments | « runtime/observatory/lib/src/elements/isolate_summary.html ('k') | runtime/observatory/lib/src/elements/metrics.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698