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

Side by Side Diff: chrome/browser/resources/performance_monitor/chart.js

Issue 10820031: Modifications to performance monitor UI to address real webui. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Final touchups for style. Created 8 years, 5 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) 2012 The Chromium Authors. All rights reserved. 1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be 2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. */ 3 * found in the LICENSE file. */
4 4
5 'use strict'; 5 'use strict';
6 6
7 /* convert to cr.define('PerformanceMonitor', function() {... 7 cr.define('performance_monitor', function() {
8 * when integrating into webui */
9
10 var Installer = function() {
11 /** 8 /**
12 * Enum for time ranges, giving a descriptive name, time span prior to |now|, 9 * Enum for time ranges, giving a descriptive name, time span prior to |now|,
13 * data point resolution, and time-label frequency and format for each. 10 * data point resolution, and time-label frequency and format for each.
14 * @enum {{ 11 * @enum {{
15 * value: !number, 12 * value: !number,
16 * name: !string, 13 * name: !string,
17 * timeSpan: !number, 14 * timeSpan: !number,
18 * resolution: !number, 15 * resolution: !number,
19 * labelEvery: !number, 16 * labelEvery: !number,
20 * format: !string 17 * format: !string
(...skipping 15 matching lines...) Expand all
36 // Labels at 168 point (weekly) intervals. 33 // Labels at 168 point (weekly) intervals.
37 month: {value: 2, name: 'Last Month', timeSpan: 30 * 24 * 3600 * 1000, 34 month: {value: 2, name: 'Last Month', timeSpan: 30 * 24 * 3600 * 1000,
38 resolution: 1000 * 3600, labelEvery: 168, format: 'M/d'}, 35 resolution: 1000 * 3600, labelEvery: 168, format: 'M/d'},
39 36
40 // Prior quarter (90 days), resolution of 3 hr -- at most 720 data points. 37 // Prior quarter (90 days), resolution of 3 hr -- at most 720 data points.
41 // Labels at 112 point (fortnightly) intervals. 38 // Labels at 112 point (fortnightly) intervals.
42 quarter: {value: 3, name: 'Last Quarter', timeSpan: 90 * 24 * 3600 * 1000, 39 quarter: {value: 3, name: 'Last Quarter', timeSpan: 90 * 24 * 3600 * 1000,
43 resolution: 1000 * 3600 * 3, labelEvery: 112, format: 'M/yy'}, 40 resolution: 1000 * 3600 * 3, labelEvery: 112, format: 'M/yy'},
44 }; 41 };
45 42
43 /*
44 * Offset, in mS, by which to subtract to convert GMT to local time
45 * @type {!number}
46 */
47 var timezoneOffset = new Date().getTimezoneOffset() * 60000;
48
46 /** @constructor */ 49 /** @constructor */
47 function PerformanceMonitor() { 50 function PerformanceMonitor() {
48 this.__proto__ = PerformanceMonitor.prototype; 51 this.__proto__ = PerformanceMonitor.prototype;
49 /** 52 /**
50 * All metrics have entries, but those not displayed have an empty div list. 53 * All metrics have entries, but those not displayed have an empty div list.
51 * If a div list is not empty, the associated data will be non-null, or 54 * If a div list is not empty, the associated data will be non-null, or
52 * null but about to be filled by webui response. Thus, any metric with 55 * null but about to be filled by webui response. Thus, any metric with
53 * non-empty div list but null data is awaiting a data response from the 56 * non-empty div list but null data is awaiting a data response from the
54 * webui. 57 * webui. The webui uses numbers to uniquely identify metric and event
58 * types, so we use the same numbers (in string form) for the map key,
59 * repeating the id number in the |id| field, as a number.
55 * @type {Object.<string, { 60 * @type {Object.<string, {
61 * id: !number,
62 * description: !string,
63 * units: !string,
64 * yAxis: !{max: !number, color: !string},
56 * divs: !Array.<HTMLDivElement>, 65 * divs: !Array.<HTMLDivElement>,
57 * yAxis: !{max: !number, color: !string}, 66 * data: ?Array.<{time: !number, value: !number}>
58 * data: ?Array.<{time: !number, value: !number}>,
59 * description: !string,
60 * units: !string
61 * }>} 67 * }>}
62 * @private 68 * @private
63 */ 69 */
64 this.metricMap_ = { 70 this.metricMap_ = {};
65 jankiness: {
66 divs: [],
67 yAxis: {max: 100, color: 'rgb(255, 128, 128)'},
68 data: null,
69 description: 'Jankiness',
70 units: 'milliJanks'
71 },
72 oddness: {
73 divs: [],
74 yAxis: {max: 20, color: 'rgb(0, 192, 0)'},
75 data: null,
76 description: 'Oddness',
77 units: 'kOdds'
78 }
79 };
80 71
81 /* 72 /*
82 * Similar data for events, though no yAxis info is needed since events 73 * Similar data for events, though no yAxis info is needed since events
83 * are simply labelled markers at X locations. Rules regarding null data 74 * are simply labelled markers at X locations. Rules regarding null data
84 * with non-empty div list apply here as for metricMap_ above. 75 * with non-empty div list apply here as for metricMap_ above.
85 * @type {Object.<string, { 76 * @type {Object.<number, {
86 * divs: !Array.<HTMLDivElement>, 77 * id: !number,
87 * description: !string, 78 * description: !string,
88 * color: !string, 79 * color: !string,
80 * divs: !Array.<HTMLDivElement>,
89 * data: ?Array.<{time: !number, longDescription: !string}> 81 * data: ?Array.<{time: !number, longDescription: !string}>
90 * }>} 82 * }>}
91 * @private 83 * @private
92 */ 84 */
93 this.eventMap_ = { 85 this.eventMap_ = {};
94 wampusAttacks: {
95 divs: [],
96 description: 'Wampus Attack',
97 color: 'rgb(0, 0, 255)',
98 data: null
99 },
100 solarEclipses: {
101 divs: [],
102 description: 'Solar Eclipse',
103 color: 'rgb(255, 0, 255)',
104 data: null
105 }
106 };
107 86
108 /** 87 /**
109 * Time periods in which the browser was active and collecting metrics. 88 * Time periods in which the browser was active and collecting metrics
110 * and events. 89 * and events.
111 * @type {!Array.<{start: !number, end: !number}>} 90 * @type {!Array.<{start: !number, end: !number}>}
112 * @private 91 * @private
113 */ 92 */
114 this.intervals_ = []; 93 this.intervals_ = [];
115 94
116 this.setupCheckboxes_(
117 '#chooseMetrics', this.metricMap_, this.addMetric, this.dropMetric);
118 this.setupCheckboxes_(
119 '#chooseEvents', this.eventMap_, this.addEventType, this.dropEventType);
120 this.setupTimeRangeChooser_(); 95 this.setupTimeRangeChooser_();
96 chrome.send('getAllEventTypes');
97 chrome.send('getAllMetricTypes');
121 this.setupMainChart_(); 98 this.setupMainChart_();
122 TimeRange_.day.element.click().call(this); 99 TimeRange_.day.element.click();
123 } 100 }
124 101
125 PerformanceMonitor.prototype = { 102 PerformanceMonitor.prototype = {
126 /** 103 /**
104 * Receive a list of all metrics, and populate |this.metricMap_| to
105 * reflect said list. Reconfigure the checkbox set for metric selection.
106 * @param {Array.<{metricType: !String, shortDescription: !String}>}
107 * allMetrics All metrics from which to select.
108 */
109 getAllMetricTypesCallback: function(allMetrics) {
110 for (var i = 0; i < allMetrics.length; i++) {
111 var metric = allMetrics[i];
112
113 this.metricMap_[metric.metricType] = {
114 id: metric.metricType,
115 description: metric.shortDescription,
116 units: metric.units,
117 yAxis: {min: 0, max: metric.maxValue, color: 'rgb(0, 0, 255'},
118 divs: [],
119 data: null
120 };
121 }
122
123 this.setupCheckboxes_(
124 '#chooseMetrics', this.metricMap_, this.addMetric, this.dropMetric);
125 },
126
127 /**
128 * Receive a list of all event types, and populate |this.eventMap_| to
129 * reflect said list. Reconfigure the checkbox set for event selection.
130 * @param {Array.<{eventType: !String, shortDescription: !String}>}
131 * allEvents All events from which to select.
132 */
133 getAllEventTypesCallback: function(allEvents) {
134 for (var i = 0; i < allEvents.length; i++) {
135 var eventInfo = allEvents[i];
136
137 this.eventMap_[eventInfo.eventType] = {
138 id: eventInfo.eventType,
139 color: 'rgb(255, 0, 0)',
140 data: null,
141 description: eventInfo.shortDescription,
142 divs: []
143 };
144 }
145
146 this.setupCheckboxes_('#chooseEvents',
147 this.eventMap_, this.addEventType, this.dropEventType);
148 },
149
150 /**
127 * Set up the radio button set to choose time range. Use div#radioTemplate 151 * Set up the radio button set to choose time range. Use div#radioTemplate
128 * as a template. 152 * as a template.
129 * @private 153 * @private
130 */ 154 */
131 setupTimeRangeChooser_: function() { 155 setupTimeRangeChooser_: function() {
132 var timeDiv = $('#chooseTimeRange')[0]; 156 var timeDiv = $('#chooseTimeRange')[0];
133 var radioTemplate = $('#radioTemplate')[0]; 157 var radioTemplate = $('#radioTemplate')[0];
134 158
135 for (var time in TimeRange_) { 159 for (var time in TimeRange_) {
136 var timeRange = TimeRange_[time]; 160 var timeRange = TimeRange_[time];
(...skipping 16 matching lines...) Expand all
153 }, 177 },
154 178
155 /** 179 /**
156 * Generalized function for setting up checkbox blocks for either events 180 * Generalized function for setting up checkbox blocks for either events
157 * or metrics. Take a div ID |divId| into which to place the checkboxes, 181 * or metrics. Take a div ID |divId| into which to place the checkboxes,
158 * and a map |optionMap| with values that each include a property 182 * and a map |optionMap| with values that each include a property
159 * |description|. Set up one checkbox for each entry in |optionMap| 183 * |description|. Set up one checkbox for each entry in |optionMap|
160 * labelled with that description. Arrange callbacks to function |check| 184 * labelled with that description. Arrange callbacks to function |check|
161 * or |uncheck|, passing them the key of the checked or unchecked option, 185 * or |uncheck|, passing them the key of the checked or unchecked option,
162 * when the relevant checkbox state changes. 186 * when the relevant checkbox state changes.
163 * @param {!string} divId Id of division into which to put checkboxes 187 * @param {!string} divId Id of division into which to put checkboxes
Evan Stade 2012/07/28 01:01:16 you can make this a more flexible function if you
clintstaley 2012/08/01 00:25:45 Done.
164 * @param {!Object} optionMap map of metric/event entries 188 * @param {!Object} optionMap map of metric/event entries
165 * @param {!function(this:Controller, Object)} check 189 * @param {!function(this:Controller, Object)} check
166 * function to select an entry (metric or event) 190 * function to select an entry (metric or event)
167 * @param {!function(this:Controller, Object)} uncheck 191 * @param {!function(this:Controller, Object)} uncheck
168 * function to deselect an entry (metric or event) 192 * function to deselect an entry (metric or event)
169 * @private 193 * @private
170 */ 194 */
171 setupCheckboxes_: function(divId, optionMap, check, uncheck) { 195 setupCheckboxes_: function(divId, optionMap, check, uncheck) {
172 var checkboxTemplate = $('#checkboxTemplate')[0]; 196 var checkboxTemplate = $('#checkboxTemplate')[0];
Evan Stade 2012/07/28 01:01:16 you don't need the hashtag.
clintstaley 2012/08/01 00:25:45 Hmm. This doesn't work for me (I get an undefined
Evan Stade 2012/08/01 02:06:08 it's from our util.js. Note all the places in reso
Dan Beam 2012/08/01 18:20:20 estade: these pages use a jQuery plugin (which req
173 var chooseMetricsDiv = $(divId)[0]; 197 var chooseMetricsDiv = $(divId)[0];
174 198
175 for (var option in optionMap) { 199 for (var option in optionMap) {
176 var checkbox = checkboxTemplate.cloneNode(true); 200 var checkbox = checkboxTemplate.cloneNode(true);
177 checkbox.querySelector('span').innerText = 'Show ' + 201 checkbox.querySelector('span').innerText = 'Show ' +
178 optionMap[option].description; 202 optionMap[option].description;
179 chooseMetricsDiv.appendChild(checkbox); 203 chooseMetricsDiv.appendChild(checkbox);
180 204
181 var input = checkbox.querySelector('input'); 205 var input = checkbox.querySelector('input');
182 input.option = option; 206 input.option = optionMap[option].id;
183 input.addEventListener('change', function(e) { 207 input.addEventListener('change', function(e) {
184 if (e.target.checked) 208 if (e.target.checked)
Evan Stade 2012/07/28 01:01:16 ternary imo
clintstaley 2012/07/31 02:34:32 I was always of the opinion that using a ternary t
185 check.call(this, e.target.option); 209 check.call(this, e.target.option);
186 else 210 else
187 uncheck.call(this, e.target.option); 211 uncheck.call(this, e.target.option);
188 }.bind(this)); 212 }.bind(this));
189 } 213 }
190 }, 214 },
191 215
192 /** 216 /**
193 * Set up just one chart in which all metrics will be displayed 217 * Set up just one chart in which all metrics will be displayed
194 * initially. But, the design readily accommodates addition of 218 * initially. But, the design readily accommodates addition of
(...skipping 11 matching lines...) Expand all
206 * Set the time range for which to display metrics and events. For 230 * Set the time range for which to display metrics and events. For
207 * now, the time range always ends at "now", but future implementations 231 * now, the time range always ends at "now", but future implementations
208 * may allow time ranges not so anchored. 232 * may allow time ranges not so anchored.
209 * @param {!{start: !number, end: !number, resolution: !number}} range 233 * @param {!{start: !number, end: !number, resolution: !number}} range
210 */ 234 */
211 setTimeRange: function(range) { 235 setTimeRange: function(range) {
212 this.range = range; 236 this.range = range;
213 this.end = Math.floor(Date.now() / range.resolution) * 237 this.end = Math.floor(Date.now() / range.resolution) *
214 range.resolution; 238 range.resolution;
215 239
216 // Take the GMT value of this.end ("now") and subtract from it the
217 // number of minutes by which we lag GMT in the present timezone,
218 // X mS/minute. This will show time in the present timezone.
219 this.end -= new Date().getTimezoneOffset() * 60000;
220 this.start = this.end - range.timeSpan; 240 this.start = this.end - range.timeSpan;
221 this.requestIntervals(); 241 this.requestIntervals();
222 }, 242 },
223 243
224 /** 244 /**
225 * Return mock interval set for testing.
226 * @return {!Array.<{start: !number, end: !number}>} intervals
227 */
228 getMockIntervals: function() {
229 var interval = this.end - this.start;
230
231 return [
232 {start: this.start + interval * .1,
233 end: this.start + interval * .2},
234 {start: this.start + interval * .7,
235 end: this.start + interval}
236 ];
237 },
238
239 /**
240 * Request activity intervals in the current time range. 245 * Request activity intervals in the current time range.
241 */ 246 */
242 requestIntervals: function() { 247 requestIntervals: function() {
243 this.onReceiveIntervals(this.getMockIntervals()); 248 chrome.send('getActiveIntervals', [this.start, this.end]);
244 // Replace with: chrome.send('getIntervals', this.start, this.end,
245 // this.onReceiveIntervals);
246 }, 249 },
247 250
248 /** 251 /**
249 * Webui callback delivering response from requestIntervals call. Assumes 252 * Webui callback delivering response from requestIntervals call. Assumes
250 * this is a new time range choice, which results in complete refresh of 253 * this is a new time range choice, which results in complete refresh of
251 * all metrics and event types that are currently selected. 254 * all metrics and event types that are currently selected.
252 * @param {!Array.<{start: !number, end: !number}>} intervals new intervals 255 * @param {!Array.<{start: !number, end: !number}>} intervals new intervals
253 */ 256 */
254 onReceiveIntervals: function(intervals) { 257 getActiveIntervalsCallback: function(intervals) {
255 this.intervals_ = intervals; 258 this.intervals_ = intervals;
256 259
257 for (var metric in this.metricMap_) { 260 for (var metric in this.metricMap_) {
258 var metricValue = this.metricMap_[metric]; 261 var metricValue = this.metricMap_[metric];
259 if (metricValue.divs.length > 0) // if we're displaying this metric. 262 if (metricValue.divs.length > 0) // if we're displaying this metric.
260 this.refreshMetric(metric); 263 this.refreshMetric(metric);
261 } 264 }
262 265
263 for (var eventType in this.eventMap_) { 266 for (var eventType in this.eventMap_) {
264 var eventValue = this.eventMap_[eventType]; 267 var eventValue = this.eventMap_[eventType];
265 if (eventValue.divs.length > 0) 268 if (eventValue.divs.length > 0)
266 this.refreshEventType(eventType); 269 this.refreshEventType(eventValue.id);
267 } 270 }
268 }, 271 },
269 272
270 /** 273 /**
271 * Add a new metric to the main (currently only) chart. 274 * Add a new metric to the main (currently only) chart.
272 * @param {!string} metric Metric to start displaying 275 * @param {!string} metric Metric to start displaying
273 */ 276 */
274 addMetric: function(metric) { 277 addMetric: function(metric) {
275 this.metricMap_[metric].divs.push(this.charts[0]); 278 this.metricMap_[metric].divs.push(this.charts[0]);
276 this.refreshMetric(metric); 279 this.refreshMetric(metric);
277 }, 280 },
278 281
279 /** 282 /**
280 * Remove a metric from the chart(s). 283 * Remove a metric from the chart(s).
281 * @param {!string} metric Metric to stop displaying 284 * @param {!string} metric Metric to stop displaying.
282 */ 285 */
283 dropMetric: function(metric) { 286 dropMetric: function(metric) {
284 var metricValue = this.metricMap_[metric]; 287 var metricValue = this.metricMap_[metric];
285 var affectedCharts = metricValue.divs; 288 var affectedCharts = metricValue.divs;
286 metricValue.divs = []; 289 metricValue.divs = [];
287 290
288 affectedCharts.forEach(this.drawChart, this); 291 affectedCharts.forEach(this.drawChart, this);
289 }, 292 },
290 293
291 /** 294 /**
292 * Return mock metric data points for testing. Give values ranging from
293 * offset to max-offset. (This lets us avoid direct overlap of
294 * different mock data sets in an ugly way that will die in the next
295 * version anyway.)
296 * @param {!number} max Max data value to return, less offset
297 * @param {!number} offset Adjustment factor
298 * @return {!Array.<{time: !number, value: !number}>}
299 */
300 getMockDataPoints: function(max, offset) {
301 var dataPoints = [];
302
303 for (var i = 0; i < this.intervals_.length; i++) {
304 // Rise from low offset to high max-offset in 100 point steps.
305 for (var time = this.intervals_[i].start;
306 time <= this.intervals_[i].end; time += this.range.resolution) {
307 var numPoints = time / this.range.resolution;
308 dataPoints.push({time: time, value: offset + (numPoints % 100) *
309 (max - 2 * offset) / 100});
310 }
311 }
312 return dataPoints;
313 },
314
315 /**
316 * Request new metric data, assuming the metric table and chart already 295 * Request new metric data, assuming the metric table and chart already
317 * exist. 296 * exist.
318 * @param {!string} metric Metric for which to get data 297 * @param {!string} metric Metric for which to get data.
319 */ 298 */
320 refreshMetric: function(metric) { 299 refreshMetric: function(metric) {
321 var metricValue = this.metricMap_[metric]; 300 var metricValue = this.metricMap_[metric];
322 301
323 metricValue.data = null; // Mark metric as awaiting response. 302 metricValue.data = null; // Mark metric as awaiting response.
324 this.onReceiveMetric(metric, 303 chrome.send('getMetric', [metricValue.id,
325 this.getMockDataPoints(metricValue.yAxis.max, 5)); 304 this.start, this.end, this.range.resolution]);
326 // Replace with:
327 // chrome.send("getMetric", this.range.start, this.range.end,
328 // this.range.resolution, this.onReceiveMetric);
329 }, 305 },
330 306
331 /** 307 /**
332 * Receive new datapoints for |metric|, convert the data to Flot-usable 308 * Receive new datapoints for a metric, convert the data to Flot-usable
333 * form, and redraw all affected charts. 309 * form, and redraw all affected charts.
334 * @param {!string} metric Metric to which |points| applies 310 * @param {!{
335 * @param {!Array.<{time: !number, value: !number}>} points 311 * type: !number,
336 * new data points 312 * points: !Array.<{time: !number, value: !number}>
313 * }} result Object giving metric ID, and time/value point pairs for
Evan Stade 2012/07/28 01:01:16 an extra space between result and Object
clintstaley 2012/07/31 02:34:32 Done.
314 * that id.
Evan Stade 2012/07/28 01:01:16 4 more indent
clintstaley 2012/07/31 02:34:32 Done.
337 */ 315 */
338 onReceiveMetric: function(metric, points) { 316 getMetricCallback: function(result) {
339 var metricValue = this.metricMap_[metric]; 317 var metricValue = this.metricMap_[result.metricType];
340
341 // Might have been dropped while waiting for data. 318 // Might have been dropped while waiting for data.
342 if (metricValue.divs.length == 0) 319 if (metricValue.divs.length == 0)
343 return; 320 return;
344 321
345 var series = []; 322 var series = [];
346 metricValue.data = [series]; 323 metricValue.data = [series]; // Data ends with current open series.
347 324
348 // Traverse the points, and the intervals, in parallel. Both are in 325 // Traverse the points, and the intervals, in parallel. Both are in
349 // ascending time order. Create a sequence of data "series" (per Flot) 326 // ascending time order. Create a sequence of data "series" (per Flot)
350 // arrays, with each series comprising all points within a given interval. 327 // arrays, with each series comprising all points within a given interval.
351 var interval = this.intervals_[0]; 328 var interval = this.intervals_[0];
352 var intervalIndex = 0; 329 var intervalIndex = 0;
353 var pointIndex = 0; 330 var pointIndex = 0;
354 while (pointIndex < points.length && 331 while (pointIndex < result.points.length &&
355 intervalIndex < this.intervals_.length) { 332 intervalIndex < this.intervals_.length) {
356 var point = points[pointIndex++]; 333 var point = result.points[pointIndex++];
357 while (intervalIndex < this.intervals_.length && 334 while (intervalIndex < this.intervals_.length &&
358 point.time > interval.end) { 335 point.time > interval.end) {
359 interval = this.intervals_[++intervalIndex]; // Jump to new interval. 336 interval = this.intervals_[++intervalIndex]; // Jump to new interval.
360 if (series.length > 0) { 337 if (series.length > 0) {
361 series = []; // Start a new series. 338 series = []; // Start a new series.
362 metricValue.data.push(series); // Put it on the end of the data. 339 metricValue.data.push(series); // Put it on the end of the data.
363 } 340 }
364 } 341 }
365 if (intervalIndex < this.intervals_.length && 342 if (intervalIndex < this.intervals_.length &&
366 point.time > interval.start) 343 point.time > interval.start) {
367 series.push([point.time, point.value]); 344 series.push([point.time - timezoneOffset, point.value]);
345 }
368 } 346 }
369
370 metricValue.divs.forEach(this.drawChart, this); 347 metricValue.divs.forEach(this.drawChart, this);
371 }, 348 },
372 349
373 /** 350 /**
374 * Add a new event to the chart(s). 351 * Add a new event to the chart(s).
375 * @param {!string} eventType type of event to start displaying 352 * @param {!string} eventType type of event to start displaying.
376 */ 353 */
377 addEventType: function(eventType) { 354 addEventType: function(eventType) {
378 // Events show on all charts. 355 // Events show on all charts.
379 this.eventMap_[eventType].divs = this.charts; 356 this.eventMap_[eventType].divs = this.charts;
380 this.refreshEventType(eventType); 357 this.refreshEventType(eventType);
381 }, 358 },
382 359
383 /* 360 /*
384 * Remove an event from the chart(s). 361 * Remove an event from the chart(s).
385 * @param {!string} eventType type of event to stop displaying 362 * @param {!string} eventType type of event to stop displaying
386 */ 363 */
387 dropEventType: function(eventType) { 364 dropEventType: function(eventType) {
388 var eventValue = this.eventMap_[eventType]; 365 var eventValue = this.eventMap_[eventType];
389 var affectedCharts = eventValue.divs; 366 var affectedCharts = eventValue.divs;
390 eventValue.divs = []; 367 eventValue.divs = [];
391 368
392 affectedCharts.forEach(this.drawChart, this); 369 affectedCharts.forEach(this.drawChart, this);
393 }, 370 },
394 371
395 /** 372 /**
396 * Return mock event points for testing.
397 * @param {!string} eventType type of event to generate mock data for
398 * @return {!Array.<{time: !number, longDescription: !string}>}
399 */
400 getMockEventValues: function(eventType) {
401 var mockValues = [];
402 for (var i = 0; i < this.intervals_.length; i++) {
403 var interval = this.intervals_[i];
404
405 mockValues.push({
406 time: interval.start,
407 longDescription: eventType + ' at ' +
408 new Date(interval.start) + ' blah, blah blah'});
409 mockValues.push({
410 time: (interval.start + interval.end) / 2,
411 longDescription: eventType + ' at ' +
412 new Date((interval.start + interval.end) / 2) + ' blah, blah'});
413 mockValues.push({
414 time: interval.end,
415 longDescription: eventType + ' at ' + new Date(interval.end) +
416 ' blah, blah blah'});
417 }
418 return mockValues;
419 },
420
421 /**
422 * Request new data for |eventType|, for times in the current range. 373 * Request new data for |eventType|, for times in the current range.
423 * @param {!string} eventType type of event to get new data for 374 * @param {!string} eventType type of event to get new data for
424 */ 375 */
425 refreshEventType: function(eventType) { 376 refreshEventType: function(eventType) {
377
Evan Stade 2012/07/28 01:01:16 ?
clintstaley 2012/07/31 02:34:32 Not sure I understand the implied question -- sorr
Evan Stade 2012/07/31 22:57:02 why is there a blank line here
clintstaley 2012/08/01 00:25:45 Done.
426 // Mark eventType as awaiting response. 378 // Mark eventType as awaiting response.
427 this.eventMap_[eventType].data = null; 379 this.eventMap_[eventType].data = null;
428 this.onReceiveEventType(eventType, this.getMockEventValues(eventType)); 380
429 // Replace with: 381 chrome.send('getEvents', [eventType, this.start, this.end]);
430 // chrome.send("getEvents", eventType, this.range.start, this.range.end);
431 }, 382 },
432 383
433 /** 384 /**
434 * Receive new data for |eventType|. If the event has been deselected while 385 * Receive new events for |eventType|. If |eventType| has been deselected
435 * awaiting webui response, do nothing. Otherwise, save the data directly, 386 * while awaiting webui response, do nothing. Otherwise, save the data
436 * since events are handled differently than metrics when drawing 387 * directly, since events are handled differently than metrics when drawing
437 * (no "series"), and redraw all the affected charts. 388 * (no "series"), and redraw all the affected charts.
438 * @param {!string} eventType type of event the new data applies to 389 * @param {!{
439 * @param {!Array.<{time: !number, longDescription: !string}>} values 390 * type: !number,
440 * new event values 391 * points: !Array.<{time: !number, longDescription: string}>
392 * }} result Object giving eventType ID, and time/description pairs for
393 * each event of that type in the range requested.
Evan Stade 2012/07/28 01:01:16 ditto
clintstaley 2012/07/31 02:34:32 Done.
441 */ 394 */
442 onReceiveEventType: function(eventType, values) { 395 getEventsCallback: function(result) {
443 var eventValue = this.eventMap_[eventType]; 396 var eventValue = this.eventMap_[result.eventType];
444 397
445 if (eventValue.divs.length == 0) 398 if (eventValue.divs.length == 0)
446 return; 399 return;
447 400
448 eventValue.data = values; 401 for (var i = 0; i < result.points.length; i++) {
Evan Stade 2012/07/28 01:01:16 forEach
clintstaley 2012/07/31 02:34:32 Didn't see this in style rules (only the warning a
Evan Stade 2012/07/31 22:57:02 I personally prefer forEach. I don't think it's in
402 result.points[i].time -= timezoneOffset;
403 }
404
405 eventValue.data = result.points;
449 eventValue.divs.forEach(this.drawChart, this); 406 eventValue.divs.forEach(this.drawChart, this);
450 }, 407 },
451 408
452 /** 409 /**
453 * Return an object containing an array of metrics and another of events 410 * Return an object containing an array of metrics and another of events
454 * that include |chart| as one of the divs into which they display. 411 * that include |chart| as one of the divs into which they display.
455 * @param {HTMLDivElement} chart div for which to get relevant items 412 * @param {HTMLDivElement} chart div for which to get relevant items
456 * @return {!{metrics: !Array,<Object>, events: !Array.<Object>}} 413 * @return {!{metrics: !Array,<Object>, events: !Array.<Object>}}
457 * @private 414 * @private
458 */ 415 */
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 * }>} mark data structure for Flot to use 474 * }>} mark data structure for Flot to use
518 * @private 475 * @private
519 */ 476 */
520 getEventMarks_: function(eventValues) { 477 getEventMarks_: function(eventValues) {
521 var markings = []; 478 var markings = [];
522 479
523 for (var i = 0; i < eventValues.length; i++) { 480 for (var i = 0; i < eventValues.length; i++) {
524 var eventValue = eventValues[i]; 481 var eventValue = eventValues[i];
525 for (var d = 0; d < eventValue.data.length; d++) { 482 for (var d = 0; d < eventValue.data.length; d++) {
526 var point = eventValue.data[d]; 483 var point = eventValue.data[d];
527 markings.push({ 484 if (point.time >= this.start && point.time <= this.end) {
528 color: eventValue.color, 485 markings.push({
529 description: eventValue.description, 486 color: eventValue.color,
530 xaxis: {from: point.time, to: point.time} 487 description: eventValue.description,
531 }); 488 xaxis: {from: point.time, to: point.time}
Evan Stade 2012/07/28 01:01:16 xAxis
clintstaley 2012/07/31 02:34:32 Sadly, this object is for use by Flot, which does
Evan Stade 2012/07/31 22:57:02 ok
489 });
490 } else {
491 console.log('Event out of time range at: ' + point.time);
492 }
532 } 493 }
533 } 494 }
534 495
535 return markings; 496 return markings;
536 }, 497 },
537 498
538 /** 499 /**
539 * Redraw the chart in div |chart|, *if* all its dependent data is present. 500 * Redraw the chart in div |chart|, *if* all its dependent data is present.
540 * Otherwise simply return, and await another call when all data is 501 * Otherwise simply return, and await another call when all data is
541 * available. 502 * available.
(...skipping 12 matching lines...) Expand all
554 for (var i = 0; i < value.data.length; i++) { 515 for (var i = 0; i < value.data.length; i++) {
555 seriesSeq.push({ 516 seriesSeq.push({
556 color: value.yAxis.color, 517 color: value.yAxis.color,
557 data: value.data[i], 518 data: value.data[i],
558 label: i == 0 ? value.description + ' (' + value.units + ')' : null, 519 label: i == 0 ? value.description + ' (' + value.units + ')' : null,
559 yaxis: yAxes.length, // Use just-added Y axis. 520 yaxis: yAxes.length, // Use just-added Y axis.
560 }); 521 });
561 } 522 }
562 }); 523 });
563 524
525 // Ensure at least one y axis, as a reference for event placement.
526 if (yAxes.length == 0)
527 yAxes.push({max: 1.0});
528
564 var markings = this.getEventMarks_(chartData.events); 529 var markings = this.getEventMarks_(chartData.events);
565 var chart = this.charts[0]; 530 var chart = this.charts[0];
566 var plot = $.plot(chart, seriesSeq, { 531 var plot = $.plot(chart, seriesSeq, {
567 yaxes: yAxes, 532 yaxes: yAxes,
568 xaxis: {mode: 'time'}, 533 xaxis: {
534 mode: 'time',
535 min: this.start - timezoneOffset,
536 max: this.end - timezoneOffset
537 },
538 points: {show: true, radius: 1},
539 lines: {show: true},
569 grid: {markings: markings} 540 grid: {markings: markings}
570 }); 541 });
571 542
572 // For each event in |markings|, create also a label div, with left 543 // For each event in |markings|, create also a label div, with left
573 // edge colinear with the event vertical-line. Top of label is 544 // edge colinear with the event vertical line. Top of label is
574 // presently a hack-in, putting labels in three tiers of 25px height 545 // presently a hack-in, putting labels in three tiers of 25px height
575 // each to avoid overlap. Will need something better. 546 // each to avoid overlap. Will need something better.
576 var labelTemplate = $('#labelTemplate')[0]; 547 var labelTemplate = $('#labelTemplate')[0];
577 for (var i = 0; i < markings.length; i++) { 548 for (var i = 0; i < markings.length; i++) {
578 var mark = markings[i]; 549 var mark = markings[i];
579 var point = 550 var point =
580 plot.pointOffset({x: mark.xaxis.to, y: yAxes[0].max, yaxis: 1}); 551 plot.pointOffset({x: mark.xaxis.to, y: yAxes[0].max, yaxis: 1});
581 var labelDiv = labelTemplate.cloneNode(true); 552 var labelDiv = labelTemplate.cloneNode(true);
582 labelDiv.innerText = mark.description; 553 labelDiv.innerText = mark.description;
583 labelDiv.style.left = point.left + 'px'; 554 labelDiv.style.left = point.left + 'px';
584 labelDiv.style.top = (point.top + 25 * (i % 3)) + 'px'; 555 labelDiv.style.top = (point.top + 25 * (i % 3)) + 'px';
556
585 chart.appendChild(labelDiv); 557 chart.appendChild(labelDiv);
586 } 558 }
587 } 559 }
588 }; 560 };
589 return { 561 return {
590 PerformanceMonitor: PerformanceMonitor 562 PerformanceMonitor: PerformanceMonitor
591 }; 563 };
592 }(); 564 });
593 565
594 var performanceMonitor = new Installer.PerformanceMonitor(); 566 var PerformanceMonitor = new performance_monitor.PerformanceMonitor();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698