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

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

Issue 10900035: Version 2 of CPM UI, with rearranged controls, multiple graphs, event rollovers, etc. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 3 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
6 cr.define('performance_monitor', function() { 5 cr.define('performance_monitor', function() {
7 'use strict'; 6 'use strict';
8 7
9 /** 8 /**
10 * 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|,
Jeffrey Yasskin 2012/08/30 00:15:10 Mention that time span and resolution are in milli
clintstaley 2012/08/30 21:40:18 Done.
11 * data point resolution, and time-label frequency and format for each. 10 * data point resolution, and time-label frequency and format for each.
Jeffrey Yasskin 2012/08/30 00:15:10 Where's the definition for symbols in the format s
clintstaley 2012/08/30 21:40:18 Done.
12 * @enum {{ 11 * @enum {{
Jeffrey Yasskin 2012/08/30 00:15:10 It looks like these objects also grow an 'element'
clintstaley 2012/08/30 21:40:18 Done.
13 * value: number, 12 * value: number,
14 * name: string, 13 * name: string,
15 * timeSpan: number, 14 * timeSpan: number,
16 * resolution: number, 15 * resolution: number,
17 * labelEvery: number, 16 * labelEvery: number,
18 * format: string 17 * format: string
19 * }} 18 * }}
20 * @private 19 * @private
21 */ 20 */
22 var TimeRange_ = { 21 var TimeRange_ = {
23 // Prior 12 min, resolution of 1s, at most 720 points. 22 // Prior 15 min, resolution of 5s, at most 180 points.
24 // Labels at 60 point (1 min) intervals. 23 // Labels at 12 point (1 min) intervals.
25 minutes: {value: 0, name: 'Last 12 min', timeSpan: 720 * 1000, 24 minutes: {value: 0, name: 'Last 15 min', timeSpan: 900 * 1000,
26 resolution: 1000, labelEvery: 60, format: 'MM-dd'}, 25 resolution: 1000 * 5, labelEvery: 12, format: 'MM-dd'},
27 26
28 // Prior hour, resolution of 5s, at most 720 points. 27 // Prior hour, resolution of 20s, at most 180 points.
29 // Labels at 60 point (5 min) intervals. 28 // Labels at 15 point (5 min) intervals.
30 hour: {value: 1, name: 'Last Hour', timeSpan: 3600 * 1000, 29 hour: {value: 1, name: 'Last Hour', timeSpan: 3600 * 1000,
31 resolution: 1000 * 5, labelEvery: 60, format: 'MM-dd'}, 30 resolution: 1000 * 20, labelEvery: 15, format: 'MM-dd'},
32 31
33 // Prior day, resolution of 2 min, at most 720 points. 32 // Prior day, resolution of 5 min, at most 288 points.
34 // Labels at 90 point (3 hour) intervals. 33 // Labels at 36 point (3 hour) intervals.
35 day: {value: 2, name: 'Last Day', timeSpan: 24 * 3600 * 1000, 34 day: {value: 2, name: 'Last Day', timeSpan: 24 * 3600 * 1000,
36 resolution: 1000 * 60 * 2, labelEvery: 90, format: 'MM-dd'}, 35 resolution: 1000 * 60 * 5, labelEvery: 36, format: 'MM-dd'},
37 36
38 // Prior week, resolution of 15 min -- at most 672 data points. 37 // Prior week, resolution of 1 hr -- at most 168 data points.
39 // Labels at 96 point (daily) intervals. 38 // Labels at 24 point (daily) intervals.
40 week: {value: 3, name: 'Last Week', timeSpan: 7 * 24 * 3600 * 1000, 39 week: {value: 3, name: 'Last Week', timeSpan: 7 * 24 * 3600 * 1000,
41 resolution: 1000 * 60 * 15, labelEvery: 96, format: 'M/d'}, 40 resolution: 1000 * 3600, labelEvery: 24, format: 'M/d'},
42 41
43 // Prior month (30 days), resolution of 1 hr -- at most 720 data points. 42 // Prior month (30 days), resolution of 4 hr -- at most 180 data points.
44 // Labels at 168 point (weekly) intervals. 43 // Labels at 42 point (weekly) intervals.
45 month: {value: 4, name: 'Last Month', timeSpan: 30 * 24 * 3600 * 1000, 44 month: {value: 4, name: 'Last Month', timeSpan: 30 * 24 * 3600 * 1000,
46 resolution: 1000 * 3600, labelEvery: 168, format: 'M/d'}, 45 resolution: 1000 * 3600 * 4, labelEvery: 42, format: 'M/d'},
47 46
48 // Prior quarter (90 days), resolution of 3 hr -- at most 720 data points. 47 // Prior quarter (90 days), resolution of 12 hr -- at most 180 data points.
49 // Labels at 112 point (fortnightly) intervals. 48 // Labels at 28 point (fortnightly) intervals.
50 quarter: {value: 5, name: 'Last Quarter', timeSpan: 90 * 24 * 3600 * 1000, 49 quarter: {value: 5, name: 'Last Quarter', timeSpan: 90 * 24 * 3600 * 1000,
51 resolution: 1000 * 3600 * 3, labelEvery: 112, format: 'M/yy'}, 50 resolution: 1000 * 3600 * 12, labelEvery: 28, format: 'M/yy'},
52 }; 51 };
53 52
54 /* 53 /*
55 * Offset, in ms, by which to subtract to convert GMT to local time 54 * Table of colors to use for metrics and events. Basically boxing the
55 * colorwheel, but leaving out yellows and fully saturated colors.
56 * @type {Array.<string>}
57 * @private
58 */
59 var ColorTable_ = [
60 'rgb(255, 128, 128)', 'rgb(128, 255, 128)', 'rgb(128, 128, 255)',
61 'rgb(128, 255, 255)', 'rgb(255, 128, 255)', // No bright yellow
62 'rgb(255, 64, 64)', 'rgb( 64, 255, 64)', 'rgb( 64, 64, 255)',
63 'rgb( 64, 255, 255)', 'rgb(255, 64, 255)', // No medium yellow either
64 'rgb(128, 64, 64)', 'rgb( 64, 128, 64)', 'rgb( 64, 64, 128)',
65 'rgb( 64, 128, 128)', 'rgb(128, 64, 128)', 'rgb(128, 128, 64)'
66 ];
67
68 /*
69 * Offset, in ms, by which to subtract to convert GMT to local time.
56 * @type {number} 70 * @type {number}
71 * @private
57 */ 72 */
58 var timezoneOffset = new Date().getTimezoneOffset() * 60000; 73 var timezoneOffset_ = new Date().getTimezoneOffset() * 60000;
74
75 /*
76 * Additional range multiplier to ensure that points don't hit the top of
77 * the graph.
78 * @type {number}
79 * @private
80 */
81 var yAxisMargin_ = 1.05;
82
83 /*
84 * Number of time resolution periods to wait between automated update of
85 * graphs.
86 * @type {number}
87 * @private
88 */
89 var intervalMultiple_ = 2;
90
91 /*
92 * Number of milliseconds to wait before deciding that the most recent
93 * resize event is not going to be followed immediately by another, and
94 * thus needs handling.
95 * @type {number}
96 * @private
97 */
98 var resizeDelay_ = 500;
Jeffrey Yasskin 2012/08/30 00:15:10 500ms is well inside human perception. Did you mea
clintstaley 2012/08/30 21:40:18 No, I meant it to *not* feel like a delay. If the
59 99
60 /** @constructor */ 100 /** @constructor */
61 function PerformanceMonitor() { 101 function PerformanceMonitor() {
62 this.__proto__ = PerformanceMonitor.prototype; 102 this.__proto__ = PerformanceMonitor.prototype;
103
104 /**
105 * Metrics fall into categories that have common units and thus may
106 * share a common graph, or share y-axes within a multi-y-axis graph.
107 * Each category has one home chart in which metrics of that category
108 * are displayed. Currently this is also the only chart in which such
109 * metrics are displayed, but the design permits a metric to show in
110 * several charts if this is useful later on.
111 * @type {Object.<string, {
112 * metricCategoryId: number,
Jeffrey Yasskin 2012/08/30 00:15:10 What sort of number? Is there a list of possible v
clintstaley 2012/08/30 21:40:18 Made up on the C++ side, as values of an enum. Di
113 * name: string,
114 * description: string,
115 * unit: string,
116 * details: !Array.<!Object>,
Jeffrey Yasskin 2012/08/30 00:15:10 Please describe the details objects. You might wan
clintstaley 2012/08/30 21:40:18 Not quite, actually. The result of getMetricTypes
117 * homeChart: !HTMLDivElement
118 * }>}
119 * @private
120 */
121 this.metricCategoryMap_ = {};
122
63 /** 123 /**
64 * All metrics have entries, but those not displayed have an empty div list. 124 * All metrics have entries, but those not displayed have an empty div list.
65 * If a div list is not empty, the associated data will be non-null, or 125 * If a div list is not empty, the associated data will be non-null, or
66 * null but about to be filled by webui handler response. Thus, any metric 126 * null but about to be filled by webui handler response. Thus, any metric
67 * with non-empty div list but null data is awaiting a data response 127 * with non-empty div list but null data is awaiting a data response
68 * from the webui handler. The webui handler uses numbers to uniquely 128 * from the webui handler. The webui handler uses numbers to uniquely
69 * identify metric and event types, so we use the same numbers (in 129 * identify metric and event types, so we use the same numbers (in
70 * string form) for the map key, repeating the id number in the |id| 130 * string form) for the map key, repeating the id number in the |id|
71 * field, as a number. 131 * field, as a number. All metrics also have an associated category,
132 * giving their unit information and home chart. Design note: Although
133 * in the present UI each metric appears only in the home chart of
134 * its metric category, we keep the divs property here to allow future
135 * modifications in which the same metric might appear in several charts
136 * for side-by-side comparisons.
72 * @type {Object.<string, { 137 * @type {Object.<string, {
73 * id: number, 138 * metricId: number,
74 * description: string, 139 * description: string,
75 * units: string, 140 * category: !Object,
76 * yAxis: !{max: number, color: string}, 141 * color: string,
77 * divs: !Array.<HTMLDivElement>, 142 * maxValue: number,
78 * data: ?Array.<{time: number, value: number}> 143 * divs: !Array.<HTMLDivElement>,
79 * }>} 144 * data: ?Array.<{time: number, value: number}>
145 * }>}
80 * @private 146 * @private
81 */ 147 */
82 this.metricMap_ = {}; 148 this.metricDetailsMap_ = {};
83 149
84 /* 150 /**
85 * Similar data for events, though no yAxis info is needed since events 151 * Events fall into categories just like metrics, above. This category
86 * are simply labelled markers at X locations. Rules regarding null data 152 * grouping is not as important as that for metrics, since events
87 * with non-empty div list apply here as for metricMap_ above. 153 * needn't share maxima, y-axes, nor units, and since events appear on
154 * all charts. But grouping of event categories in the event-selection
155 * UI is still useful.
156 * @type {Object.<string, {
157 * eventCategoryId: number,
158 * name: string,
159 * description: string,
160 * details: !Array.<!Object>,
161 * }>}
162 * @private
163 */
164 this.eventCategoryMap_ = {};
165
166 /**
167 * Similar data for events as for metrics, though no yAxis info is needed
168 * since events are simply labelled markers at X locations. Rules regarding
169 * null data with non-empty div list apply here as for metricDetailsMap_
170 * above. The |data| field follows a special rule not describable in
171 * JSDoc: Each array element may include arbitrary other properties with
172 * value {label: 'some label', value: 'some value'} for display in the
173 * event mouseover. These will vary per event type.
Jeffrey Yasskin 2012/08/30 00:15:10 Are the event types described somewhere?
clintstaley 2012/08/30 21:40:18 They're built on the C++ side. The UI is meant to
88 * @type {Object.<number, { 174 * @type {Object.<number, {
89 * id: number, 175 * eventId: number,
176 * name: string,
177 * popupTitle: string,
90 * description: string, 178 * description: string,
91 * color: string, 179 * color: string,
92 * divs: !Array.<HTMLDivElement>, 180 * divs: !Array.<HTMLDivElement>,
93 * data: ?Array.<{time: number, longDescription: string}> 181 * data: ?Array.<{time: number}>
94 * }>} 182 * }>}
95 * @private 183 * @private
96 */ 184 */
97 this.eventMap_ = {}; 185 this.eventDetailsMap_ = {};
98 186
99 /** 187 /**
100 * Time periods in which the browser was active and collecting metrics 188 * Time periods in which the browser was active and collecting metrics
101 * and events. 189 * and events.
102 * @type {!Array.<{start: number, end: number}>} 190 * @type {!Array.<{start: number, end: number}>}
103 * @private 191 * @private
104 */ 192 */
105 this.intervals_ = []; 193 this.intervals_ = [];
106 194
107 this.setupTimeRangeChooser_(); 195 /**
108 chrome.send('getAllEventTypes'); 196 * Handle of timer interval function used to update charts
109 chrome.send('getAllMetricTypes'); 197 * @type {Object}
110 this.setupMainChart_(); 198 * @private
199 */
200 this.updateTimer_ = null;
201
202 /**
203 * Handle of timer interval function used to check for resizes
204 * @type {!Object}
205 * @private
206 */
207 this.resizeTimer_ = setInterval(this.checkResize_.bind(this), 100);
Jeffrey Yasskin 2012/08/30 00:15:10 I would probably schedule a call to checkResize fr
clintstaley 2012/08/30 21:40:18 Thought of this, but it doesn't quite work. We ne
208
209 /**
210 * Time of last UNHANDLED resize event, or null if no resizes or if
211 * last one has been handled.
212 * @type {number}
213 * @private
214 */
215 this.lastResizeTime_ = null;
216
217 /**
218 * All chart divs in the display, whether hidden or not. Presently
219 * this has one entry for each metric category in |this.metricCategoryMap|.
220 * @type {Array.<HTMLDivElement>}
221 * @private
222 */
223 this.charts_ = [];
224
225 this.setupTimeRangeTab_();
226 chrome.send('getEventTypes');
227 chrome.send('getMetricTypes');
111 TimeRange_.day.element.click(); 228 TimeRange_.day.element.click();
112 } 229 }
113 230
114 PerformanceMonitor.prototype = { 231 PerformanceMonitor.prototype = {
115 /** 232 /**
116 * Receive a list of all metrics, and populate |this.metricMap_| to 233 * Receive a list of all metric categories, each with its correspoinding
117 * reflect said list. Reconfigure the checkbox set for metric selection. 234 * list of metric details. Populate |this.metricCategoryMap_| and
118 * @param {Array.<{metricType: string, shortDescription: string}>} 235 * |this.metrictDetailsMap_| to reflect said list. Reconfigure the
119 * allMetrics All metrics from which to select. 236 * checkbox set for metric selection.
237 * @param {Array.<{
238 * metricCategoryId: number,
239 * name: string,
240 * unit: string,
241 * description: string,
242 * details: Array.<{
243 * metricId: number,
244 * name: string,
245 * description: string
246 * }>
247 * }>} categories All metric categories needing charts and checkboxes.
120 */ 248 */
121 getAllMetricTypesCallback: function(allMetrics) { 249 getMetricTypesCallback: function(categories) {
122 for (var i = 0; i < allMetrics.length; i++) { 250 for (var c = 0; c < categories.length; c++) {
Jeffrey Yasskin 2012/08/30 00:15:10 Use categories.forEach(function(category) { ... },
clintstaley 2012/08/30 21:40:18 I always forget whether it's the forEach or the fo
Jeffrey Yasskin 2012/08/31 22:28:16 Thanks!
123 var metric = allMetrics[i]; 251 var category = categories[c];
124 252
125 this.metricMap_[metric.metricType] = { 253 this.addCategoryChart_(category);
126 id: metric.metricType, 254 this.metricCategoryMap_[category.metricCategoryId] = category;
127 description: metric.shortDescription, 255
128 units: metric.units, 256 for (var m = 0; m < category.details.length; m++) {
Jeffrey Yasskin 2012/08/30 00:15:10 Use category.details.forEach(function(metric) { ..
clintstaley 2012/08/30 21:40:18 Done.
129 yAxis: {min: 0, max: metric.maxValue, 257 var metric = category.details[m];
130 color: jQuery.color.parse('blue')}, 258
131 divs: [], 259 metric.color = ColorTable_[metric.metricId % ColorTable_.length];
Jeffrey Yasskin 2012/08/30 00:15:10 Where's it documented that metricId is densely all
clintstaley 2012/08/30 21:40:18 Good point. Added to the docs. (Webui currently
132 data: null 260 metric.maxValue = 1;
133 }; 261 metric.divs = [];
262 metric.data = null;
263 metric.category = category;
264 this.metricDetailsMap_[metric.metricId] = metric;
265 }
134 } 266 }
135 267
136 this.setupCheckboxes_($('#choose-metrics')[0], 268 this.setupCheckboxes_($('#choose-metrics')[0],
137 this.metricMap_, this.addMetric, this.dropMetric); 269 this.metricCategoryMap_, 'metricId', this.addMetric, this.dropMetric);
138 }, 270 },
139 271
140 /** 272 /**
141 * Receive a list of all event types, and populate |this.eventMap_| to 273 * Receive a list of all event categories, each with its correspoinding
142 * reflect said list. Reconfigure the checkbox set for event selection. 274 * list of event details. Populate |this.eventCategoryMap_| and
143 * @param {Array.<{eventType: string, shortDescription: string}>} 275 * |this.eventDetailsMap| to reflect said list. Reconfigure the
144 * allEvents All events from which to select. 276 * checkbox set for event selection.
277 * @param {Array.<{
278 * eventCategoryId: number,
279 * name: string,
280 * description: string,
281 * details: Array.<{
282 * eventId: number,
283 * name: string,
284 * description: string
285 * }>
286 * }>} categories All event categories needing charts checkboxes.
145 */ 287 */
146 getAllEventTypesCallback: function(allEvents) { 288 getEventTypesCallback: function(categories) {
147 for (var i = 0; i < allEvents.length; i++) { 289 for (var c = 0; c < categories.length; c++) {
148 var eventInfo = allEvents[i]; 290 var category = categories[c];
149 291
150 this.eventMap_[eventInfo.eventType] = { 292 this.eventCategoryMap_[category.eventCategoryId] = category;
151 id: eventInfo.eventType, 293
152 color: jQuery.color.parse('red'), 294 for (var e = 0; e < category.details.length; e++) {
153 data: null, 295 var event = category.details[e];
154 description: eventInfo.shortDescription, 296
155 divs: [] 297 event.color = ColorTable_[event.eventId % ColorTable_.length];
156 }; 298 event.divs = [];
299 event.data = null;
300 this.eventDetailsMap_[event.eventId] = event;
301 }
157 } 302 }
158 303
159 this.setupCheckboxes_($('#choose-events')[0], 304 this.setupCheckboxes_($('#choose-events')[0], this.eventCategoryMap_,
160 this.eventMap_, this.addEventType, this.dropEventType); 305 'eventId', this.addEventType, this.dropEventType);
161 }, 306 },
162 307
163 /** 308 /**
164 * Set up the radio button set to choose time range. Use div#radio-template 309 * Set up the radio button set to choose time range. Use div#radio-template
165 * as a template. 310 * as a template.
166 * @private 311 * @private
167 */ 312 */
168 setupTimeRangeChooser_: function() { 313 setupTimeRangeTab_: function() {
169 var timeDiv = $('#choose-time-range')[0]; 314 var timeDiv = $('#choose-time-range')[0];
315 var backButton = $('#back-time')[0];
316 var forwardButton = $('#forward-time')[0];
170 var radioTemplate = $('#radio-template')[0]; 317 var radioTemplate = $('#radio-template')[0];
171 318
172 for (var time in TimeRange_) { 319 for (var time in TimeRange_) {
173 var timeRange = TimeRange_[time]; 320 var timeRange = TimeRange_[time];
174 var radio = radioTemplate.cloneNode(true); 321 var radio = radioTemplate.cloneNode(true);
175 var input = radio.querySelector('input'); 322 var input = radio.querySelector('input');
176 323
177 input.value = timeRange.value; 324 input.value = timeRange.value;
178 input.timeRange = timeRange; 325 input.timeRange = timeRange;
179 radio.querySelector('span').innerText = timeRange.name; 326 radio.querySelector('span').innerText = timeRange.name;
180 timeDiv.appendChild(radio); 327 timeDiv.appendChild(radio);
181 timeRange.element = input; 328 timeRange.element = input;
182 } 329 }
183 330
184 timeDiv.addEventListener('click', function(e) { 331 timeDiv.addEventListener('click', function(e) {
185 if (!e.target.webkitMatchesSelector('input[type="radio"]')) 332 if (!e.target.webkitMatchesSelector('input[type="radio"]'))
186 return; 333 return;
187 334
188 this.setTimeRange(e.target.timeRange); 335 this.setTimeRange(e.target.timeRange, Date.now(), true);
189 }.bind(this)); 336 }.bind(this));
337
338 forwardButton.addEventListener('click', this.forwardTime.bind(this));
339 backButton.addEventListener('click', this.backTime.bind(this));
190 }, 340 },
191 341
192 /** 342 /**
193 * Generalized function for setting up checkbox blocks for either events 343 * Generalized function for setting up checkbox blocks for either events
194 * or metrics. Take a div |div| into which to place the checkboxes, 344 * or metrics. Take a div |div| into which to place the checkboxes,
195 * and a map |optionMap| with values that each include a property 345 * and a map |optionCategoryMap| with values that each include a property
Jeffrey Yasskin 2012/08/30 00:15:10 This might be more clear if you write down an exam
clintstaley 2012/08/30 21:40:18 Added two paragraphs of concrete example for metri
196 * |description|. Set up one checkbox for each entry in |optionMap| 346 * |description|, and a property |details|, which gives an array of
Jeffrey Yasskin 2012/08/30 00:15:10 grammar: "gives an array of that in turn"
clintstaley 2012/08/30 21:40:18 Done.
197 * labelled with that description. Arrange callbacks to function |check| 347 * that in turn each have a properties |id| and |name|.
198 * or |uncheck|, passing them the key of the checked or unchecked option, 348 *
199 * when the relevant checkbox state changes. 349 * Set up a checkbox group for each entry in |optionCategoryMap|, which
Jeffrey Yasskin 2012/08/30 00:15:10 Similarly, it might work better to write some samp
clintstaley 2012/08/30 21:40:18 Hoping the new concrete example might be sufficien
350 * group has one checkbox for each entry in the |details| array.
351 * Arrange callbacks to function |check| or |uncheck|, passing them
352 * the id of the checked or unchecked option, when the relevant checkbox
353 * state changes.
200 * @param {!HTMLDivElement} div A <div> into which to put checkboxes. 354 * @param {!HTMLDivElement} div A <div> into which to put checkboxes.
201 * @param {!Object} optionMap A map of metric/event entries. 355 * @param {!Object} optionCategory Map A map of metric/event categories.
356 * @param {string} idName The tagname of the id property.
202 * @param {!function(this:Controller, Object)} check 357 * @param {!function(this:Controller, Object)} check
203 * The function to select an entry (metric or event). 358 * The function to select an entry (metric or event).
204 * @param {!function(this:Controller, Object)} uncheck 359 * @param {!function(this:Controller, Object)} uncheck
205 * The function to deselect an entry (metric or event). 360 * The function to deselect an entry (metric or event).
206 * @private 361 * @private
207 */ 362 */
208 setupCheckboxes_: function(div, optionMap, check, uncheck) { 363 setupCheckboxes_: function(div, optionCategoryMap, idName, check, uncheck) {
209 var checkboxTemplate = $('#checkbox-template')[0]; 364 var checkboxTemplate = $('#detail-checkbox-template')[0];
365 var labelTemplate = $('#category-label-template')[0];
210 366
211 for (var option in optionMap) { 367 for (var c in optionCategoryMap) {
212 var checkbox = checkboxTemplate.cloneNode(true); 368 var category = optionCategoryMap[c];
213 checkbox.querySelector('span').innerText = 'Show ' + 369 var label = labelTemplate.cloneNode(true);
214 optionMap[option].description;
215 div.appendChild(checkbox);
216 370
217 var input = checkbox.querySelector('input'); 371 label.innerText = category.name;
218 input.option = optionMap[option].id; 372 div.appendChild(label);
219 input.addEventListener('change', function(e) { 373
220 (e.target.checked ? check : uncheck).call(this, e.target.option); 374 for (var d = 0; d < category.details.length; d++) {
221 }.bind(this)); 375 var details = category.details[d];
376 var checkbox = checkboxTemplate.cloneNode(true);
377 var input = checkbox.querySelector('input');
378 var label = checkbox.querySelector('.detail-label');
379 var icon = checkbox.querySelector('.color-icon');
380
381 input.option = details[idName];
382 input.icon = icon;
383 input.addEventListener('change', function(e) {
384 (e.target.checked ? check : uncheck).call(this, e.target.option);
385 e.target.icon.style.visibility =
386 e.target.checked ? 'visible' : 'hidden';
387 }.bind(this));
Jeffrey Yasskin 2012/08/30 00:15:10 Another option to replace this bind() call, and th
clintstaley 2012/08/30 21:40:18 Right. Closure-based "this". I've used it, but b
388
389 label.innerText = details.name;
390
391 icon.style.backgroundColor = details.color;
392
393 div.appendChild(checkbox);
394 }
222 } 395 }
223 }, 396 },
224 397
225 /** 398 /**
226 * Set up just one chart in which all metrics will be displayed 399 * Add a new chart for |category|, making it initially hidden,
227 * initially. But, the design readily accommodates addition of 400 * with no metrics displayed in it.
228 * new charts, and movement of metrics into those other charts. 401 * @param {!Object} category The metric category for which to create
Jeffrey Yasskin 2012/08/30 00:15:10 Name the type |category| is supposed to have.
clintstaley 2012/08/30 21:40:18 Clarified that it's a value from metricCategoryMap
Jeffrey Yasskin 2012/08/31 22:28:16 This should be ok. There's 1 indirection either wa
402 * the chart.
229 * @private 403 * @private
230 */ 404 */
231 setupMainChart_: function() { 405 addCategoryChart_: function(category) {
232 this.chartParent = $('#charts')[0]; 406 var chartParent = $('#charts')[0];
233 this.charts = [document.createElement('div')]; 407 var chart = document.createElement('div');
234 this.charts[0].className = 'chart'; 408
235 this.chartParent.appendChild(this.charts[0]); 409 chart.className = 'chart';
410 chart.hidden = true;
411 chartParent.appendChild(chart);
412 this.charts_.push(chart);
413 category.homeChart = chart;
414 chart.refs = 0;
415 chart.hovers = [];
416
417 // Receive hover events from Flot.
418 // Attached to chart will be properties 'hovers', a list of {x, div}
419 // pairs. As pos events arrive, check each hover to see if it should
420 // be hidden or made visible.
421 $(chart).bind('plothover', function(event, pos, item) {
422 var tolerance = this.range.resolution;
423
424 chart.hovers.forEach(function(hover) {
425 hover.div.hidden = hover.x < pos.x - tolerance ||
426 hover.x > pos.x + tolerance;
427 });
428
429 }.bind(this));
430
431 $(window).resize(function() {this.lastResizeTime_ = Date.now();}
432 .bind(this));
433 },
434
435 /**
436 * Check to see if resize events have recently occured, and if a long
437 * enough time has passed since the last one to justify actually redrawing
438 * all the charts. If so, redraw them all, and clear the resize state.
439 * @private
440 */
441 checkResize_: function() {
442 if (this.lastResizeTime_ != null && Date.now() - this.lastResizeTime_ >
443 resizeDelay_) {
444 this.lastResizeTime_ = null;
445 this.charts_.forEach(function(chart) {this.drawChart(chart);}, this);
446 }
236 }, 447 },
237 448
238 /** 449 /**
239 * Set the time range for which to display metrics and events. For 450 * Set the time range for which to display metrics and events. For
240 * now, the time range always ends at "now", but future implementations 451 * now, the time range always ends at 'now', but future implementations
241 * may allow time ranges not so anchored. 452 * may allow time ranges not so anchored.
242 * @param {!{start: number, end: number, resolution: number}} range 453 * @param {!{start: number, end: number, resolution: number}} range
243 * The time range for which to get display data. 454 * The time range for which to get display data.
455 * @param {number} end Ending time, in ms since epoch, to which to
456 * set the new time range.
457 * @param {boolean} startTimer Indicates whether we should restart the
458 * range-update timer.
244 */ 459 */
245 setTimeRange: function(range) { 460 setTimeRange: function(range, end, startTimer) {
246 this.range = range; 461 this.range = range;
247 this.end = Math.floor(Date.now() / range.resolution) * 462 if (this.updateTimer_ != null)
463 clearInterval(this.updateTimer_);
464 if (startTimer)
465 this.updateTimer_ = setInterval(this.forwardTime.bind(this),
466 intervalMultiple_ * range.resolution);
467 this.end = Math.floor(end / range.resolution) *
248 range.resolution; 468 range.resolution;
249 469
250 this.start = this.end - range.timeSpan; 470 this.start = this.end - range.timeSpan;
251 this.requestIntervals(); 471 this.requestIntervals();
252 }, 472 },
253 473
254 /** 474 /**
475 * Back up the time range by 1/2 of its current span, and cause chart
476 * redraws.
477 */
478 backTime: function() {
479 this.setTimeRange(this.range, this.end - this.range.timeSpan / 2, false);
480 },
481
482 /**
483 * Advance the time range by 1/2 of its current span, or up to the point
484 * where it ends at the present time, whichever is less.
485 */
486 forwardTime: function() {
487 var now = Date.now();
488 var newEnd = Math.min(now, this.end + this.range.timeSpan / 2);
489
490 this.setTimeRange(this.range, newEnd, newEnd == now);
491 },
492
493 /**
255 * Request activity intervals in the current time range. 494 * Request activity intervals in the current time range.
256 */ 495 */
257 requestIntervals: function() { 496 requestIntervals: function() {
258 chrome.send('getActiveIntervals', [this.start, this.end]); 497 chrome.send('getActiveIntervals', [this.start, this.end]);
259 }, 498 },
260 499
261 /** 500 /**
262 * Webui callback delivering response from requestIntervals call. Assumes 501 * Webui callback delivering response from requestIntervals call. Assumes
263 * this is a new time range choice, which results in complete refresh of 502 * this is a new time range choice, which results in complete refresh of
264 * all metrics and event types that are currently selected. 503 * all metrics and event types that are currently selected.
265 * @param {!Array.<{start: number, end: number}>} intervals 504 * @param {!Array.<{start: number, end: number}>} intervals
266 * The new intervals. 505 * The new intervals.
267 */ 506 */
268 getActiveIntervalsCallback: function(intervals) { 507 getActiveIntervalsCallback: function(intervals) {
269 this.intervals_ = intervals; 508 this.intervals_ = intervals;
270 509
271 for (var metric in this.metricMap_) { 510 for (var metric in this.metricDetailsMap_) {
272 var metricValue = this.metricMap_[metric]; 511 var metricDetails = this.metricDetailsMap_[metric];
273 if (metricValue.divs.length > 0) // if we're displaying this metric. 512 if (metricDetails.divs.length > 0) // if we're displaying this metric.
274 this.refreshMetric(metric); 513 this.refreshMetric(metricDetails);
275 } 514 }
276 515
277 for (var eventType in this.eventMap_) { 516 for (var eventType in this.eventDetailsMap_) {
278 var eventValue = this.eventMap_[eventType]; 517 var eventValue = this.eventDetailsMap_[eventType];
279 if (eventValue.divs.length > 0) 518 if (eventValue.divs.length > 0)
280 this.refreshEventType(eventValue.id); 519 this.refreshEventType(eventValue.eventId);
281 } 520 }
282 }, 521 },
283 522
284 /** 523 /**
285 * Add a new metric to the main (currently only) chart. 524 * Add a new metric to the display, showing it on its category's home
286 * @param {string} metric The metric to start displaying. 525 * chart. Un-hide the home chart if needed.
526 * @param {string} metricId The id of the metric to start displaying.
287 */ 527 */
288 addMetric: function(metric) { 528 addMetric: function(metricId) {
289 this.metricMap_[metric].divs.push(this.charts[0]); 529 var details = this.metricDetailsMap_[metricId];
290 this.refreshMetric(metric); 530 var homeChart = details.category.homeChart;
531
532 details.divs.push(homeChart);
533 if (homeChart.refs == 0)
534 homeChart.hidden = false;
535 homeChart.refs++;
536
537 this.refreshMetric(details);
291 }, 538 },
292 539
293 /** 540 /**
294 * Remove a metric from the chart(s). 541 * Remove a metric from the chart(s).
295 * @param {string} metric The metric to stop displaying. 542 * @param {string} metric The metric to stop displaying.
296 */ 543 */
297 dropMetric: function(metric) { 544 dropMetric: function(metric) {
298 var metricValue = this.metricMap_[metric]; 545 var details = this.metricDetailsMap_[metric];
299 var affectedCharts = metricValue.divs; 546 var affectedCharts = details.divs;
300 metricValue.divs = [];
301 547
302 affectedCharts.forEach(this.drawChart, this); 548 details.divs = []; // Gotta do this now to get correct drawChart result.
549 affectedCharts.forEach(function(chart)
550 {
551 chart.refs--;
552 if (chart.refs == 0)
553 chart.hidden = true;
554 this.drawChart(chart);
555 }, this);
556
303 }, 557 },
304 558
305 /** 559 /**
306 * Request new metric data, assuming the metric table and chart already 560 * Request new metric data, assuming the metric table and chart already
307 * exist. 561 * exist.
308 * @param {string} metric The metric for which to get data. 562 * @param {string} metricDetails The metric details for which to get data.
309 */ 563 */
310 refreshMetric: function(metric) { 564 refreshMetric: function(metricDetails) {
311 var metricValue = this.metricMap_[metric]; 565 metricDetails.data = null; // Mark metric as awaiting response.
312 566 chrome.send('getMetric', [metricDetails.metricId,
313 metricValue.data = null; // Mark metric as awaiting response.
314 chrome.send('getMetric', [metricValue.id,
315 this.start, this.end, this.range.resolution]); 567 this.start, this.end, this.range.resolution]);
316 }, 568 },
317 569
318 /** 570 /**
319 * Receive new datapoints for a metric, convert the data to Flot-usable 571 * Receive new datapoints for a metric, convert the data to Flot-usable
320 * form, and redraw all affected charts. 572 * form, and redraw all affected charts.
321 * @param {!{ 573 * @param {!{
322 * type: number, 574 * id: number,
323 * points: !Array.<{time: number, value: number}> 575 * max: number,
324 * }} result An object giving metric ID, and time/value point pairs for 576 * metrics: !Array.<{time: number, value: number}>
325 * that id. 577 * }} result An object giving metric ID, max expected value of the data,
578 * and time/value point pairs for that id.
326 */ 579 */
327 getMetricCallback: function(result) { 580 getMetricCallback: function(result) {
328 var metricValue = this.metricMap_[result.metricType]; 581 var metricDetails = this.metricDetailsMap_[result.metricId];
329 // Might have been dropped while waiting for data. 582 // Might have been dropped while waiting for data.
330 if (metricValue.divs.length == 0) 583 if (metricDetails.divs.length == 0)
331 return; 584 return;
332 585
333 var series = []; 586 var series = [];
334 metricValue.data = [series]; // Data ends with current open series. 587 metricDetails.data = [series]; // Data ends with current open series.
335 588
336 // Traverse the points, and the intervals, in parallel. Both are in 589 // Traverse the points, and the intervals, in parallel. Both are in
337 // ascending time order. Create a sequence of data "series" (per Flot) 590 // ascending time order. Create a sequence of data 'series' (per Flot)
338 // arrays, with each series comprising all points within a given interval. 591 // arrays, with each series comprising all points within a given interval.
339 var interval = this.intervals_[0]; 592 var interval = this.intervals_[0];
340 var intervalIndex = 0; 593 var intervalIndex = 0;
341 var pointIndex = 0; 594 var pointIndex = 0;
342 while (pointIndex < result.points.length && 595 while (pointIndex < result.metrics.length &&
343 intervalIndex < this.intervals_.length) { 596 intervalIndex < this.intervals_.length) {
344 var point = result.points[pointIndex++]; 597 var point = result.metrics[pointIndex++];
345 while (intervalIndex < this.intervals_.length && 598 while (intervalIndex < this.intervals_.length &&
346 point.time > interval.end) { 599 point.time > interval.end) {
347 interval = this.intervals_[++intervalIndex]; // Jump to new interval. 600 interval = this.intervals_[++intervalIndex]; // Jump to new interval.
348 if (series.length > 0) { 601 if (series.length > 0) {
349 series = []; // Start a new series. 602 series = []; // Start a new series.
350 metricValue.data.push(series); // Put it on the end of the data. 603 metricDetails.data.push(series); // Put it on the end of the data.
351 } 604 }
352 } 605 }
353 if (intervalIndex < this.intervals_.length && 606 if (intervalIndex < this.intervals_.length &&
354 point.time > interval.start) { 607 point.time > interval.start) {
355 series.push([point.time - timezoneOffset, point.value]); 608 series.push([point.time - timezoneOffset_, point.value]);
356 } 609 }
357 } 610 }
358 metricValue.divs.forEach(this.drawChart, this); 611 metricDetails.maxValue = Math.max(metricDetails.maxValue,
612 result.maxValue);
613
614 metricDetails.divs.forEach(this.drawChart, this);
359 }, 615 },
360 616
361 /** 617 /**
362 * Add a new event to the chart(s). 618 * Add a new event to the chart(s).
363 * @param {string} eventType The type of event to start displaying. 619 * @param {string} eventType The type of event to start displaying.
364 */ 620 */
365 addEventType: function(eventType) { 621 addEventType: function(eventType) {
366 // Events show on all charts. 622 // Events show on all charts.
367 this.eventMap_[eventType].divs = this.charts; 623 this.eventDetailsMap_[eventType].divs = this.charts_;
368 this.refreshEventType(eventType); 624 this.refreshEventType(eventType);
369 }, 625 },
370 626
371 /* 627 /*
372 * Remove an event from the chart(s). 628 * Remove an event from the chart(s).
373 * @param {string} eventType The type of event to stop displaying. 629 * @param {string} eventType The type of event to stop displaying.
374 */ 630 */
375 dropEventType: function(eventType) { 631 dropEventType: function(eventType) {
376 var eventValue = this.eventMap_[eventType]; 632 var eventValue = this.eventDetailsMap_[eventType];
377 var affectedCharts = eventValue.divs; 633 var affectedCharts = eventValue.divs;
378 eventValue.divs = [];
379 634
635 eventValue.divs = []; // Gotta do this now for correct drawChart results.
380 affectedCharts.forEach(this.drawChart, this); 636 affectedCharts.forEach(this.drawChart, this);
381 }, 637 },
382 638
383 /** 639 /**
384 * Request new data for |eventType|, for times in the current range. 640 * Request new data for |eventType|, for times in the current range.
385 * @param {string} eventType The type of event to get new data for. 641 * @param {string} eventType The type of event to get new data for.
386 */ 642 */
387 refreshEventType: function(eventType) { 643 refreshEventType: function(eventType) {
388 // Mark eventType as awaiting response. 644 // Mark eventType as awaiting response.
389 this.eventMap_[eventType].data = null; 645 this.eventDetailsMap_[eventType].data = null;
390 646
391 chrome.send('getEvents', [eventType, this.start, this.end]); 647 chrome.send('getEvents', [eventType, this.start, this.end]);
392 }, 648 },
393 649
394 /** 650 /**
395 * Receive new events for |eventType|. If |eventType| has been deselected 651 * Receive new events for |eventType|. If |eventType| has been deselected
396 * while awaiting webui handler response, do nothing. Otherwise, save the 652 * while awaiting webui handler response, do nothing. Otherwise, save the
397 * data directly, since events are handled differently than metrics 653 * data directly, since events are handled differently than metrics
398 * when drawing (no "series"), and redraw all the affected charts. 654 * when drawing (no 'series'), and redraw all the affected charts.
399 * @param {!{ 655 * @param {!{
400 * type: number, 656 * id: number,
401 * points: !Array.<{time: number, longDescription: string}> 657 * events: !Array.<{time: number}>
402 * }} result An object giving eventType ID, and time/description pairs for 658 * }} result An object giving eventType id, and times at which that event
403 * each event of that type in the range requested. 659 * type occured in the range requested. Each object in the array may
660 * also have an arbitrary list of properties to be displayed as
661 * a tooltip message for the event.
404 */ 662 */
405 getEventsCallback: function(result) { 663 getEventsCallback: function(result) {
406 var eventValue = this.eventMap_[result.eventType]; 664 var eventValue = this.eventDetailsMap_[result.eventId];
407 665
408 if (eventValue.divs.length == 0) 666 if (eventValue.divs.length == 0)
409 return; 667 return;
410 668
411 result.points.forEach(function(element) { 669 result.events.forEach(function(element) {
412 element.time -= timezoneOffset; 670 element.time -= timezoneOffset_;
413 }); 671 });
414 672
415 eventValue.data = result.points; 673 eventValue.data = result.events;
416 eventValue.divs.forEach(this.drawChart, this); 674 eventValue.divs.forEach(this.drawChart, this);
417 }, 675 },
418 676
419 /** 677 /**
420 * Return an object containing an array of metrics and another of events 678 * Return an object containing an array of metrics and another of events
421 * that include |chart| as one of the divs into which they display. 679 * that include |chart| as one of the divs into which they display.
422 * @param {HTMLDivElement} chart The <div> for which to get relevant items. 680 * @param {HTMLDivElement} chart The <div> for which to get relevant items.
423 * @return {!{metrics: !Array,<Object>, events: !Array.<Object>}} 681 * @return {!{metrics: !Array,<Object>, events: !Array.<Object>}}
424 * @private 682 * @private
425 */ 683 */
426 getChartData_: function(chart) { 684 getChartData_: function(chart) {
427 var result = {metrics: [], events: []}; 685 var result = {metrics: [], events: []};
428 686
429 for (var metric in this.metricMap_) { 687 for (var metric in this.metricDetailsMap_) {
430 var metricValue = this.metricMap_[metric]; 688 var metricDetails = this.metricDetailsMap_[metric];
431 689
432 if (metricValue.divs.indexOf(chart) != -1) 690 if (metricDetails.divs.indexOf(chart) != -1)
433 result.metrics.push(metricValue); 691 result.metrics.push(metricDetails);
434 } 692 }
435 693
436 for (var eventType in this.eventMap_) { 694 for (var eventType in this.eventDetailsMap_) {
437 var eventValue = this.eventMap_[eventType]; 695 var eventValue = this.eventDetailsMap_[eventType];
438 696
439 // Events post to all divs, if they post to any. 697 // Events post to all divs, if they post to any.
440 if (eventValue.divs.length > 0) 698 if (eventValue.divs.length > 0)
441 result.events.push(eventValue); 699 result.events.push(eventValue);
442 } 700 }
443 701
444 return result; 702 return result;
445 }, 703 },
446 704
447 /** 705 /**
(...skipping 14 matching lines...) Expand all
462 720
463 for (var i = 0; i < chartData.events.length; i++) { 721 for (var i = 0; i < chartData.events.length; i++) {
464 if (!chartData.events[i].data) 722 if (!chartData.events[i].data)
465 return false; 723 return false;
466 } 724 }
467 725
468 return true; 726 return true;
469 }, 727 },
470 728
471 /** 729 /**
472 * Create and return an array of "markings" (per Flot), representing 730 * Create and return an array of 'markings' (per Flot), representing
473 * vertical lines at the event time, in the event's color. Also add 731 * vertical lines at the event time, in the event's color. Also add
474 * (not per Flot) a |description| property to each, to be used for hand 732 * (not per Flot) a |popupTitle| property to each, to be used for
475 * creating description boxes. 733 * labelling description popups.
476 * @param {!Array.<{ 734 * @param {!Array.<{
477 * description: string, 735 * description: string,
478 * color: string, 736 * color: string,
479 * data: !Array.<{time: number}> 737 * data: !Array.<{time: number}>
480 * }>} eventValues The events to make markings for. 738 * }>} eventValues The events to make markings for.
481 * @return {!Array.<{ 739 * @return {!Array.<{
482 * color: string, 740 * color: string,
483 * description: string, 741 * description: string,
484 * xaxis: {from: number, to: number} 742 * xaxis: {from: number, to: number}
485 * }>} A marks data structure for Flot to use. 743 * }>} A marks data structure for Flot to use.
486 * @private 744 * @private
487 */ 745 */
488 getEventMarks_: function(eventValues) { 746 getEventMarks_: function(eventValues) {
489 var markings = []; 747 var markings = [];
748 var explanation;
749 var date, hours, minutes;
490 750
491 for (var i = 0; i < eventValues.length; i++) { 751 for (var i = 0; i < eventValues.length; i++) {
492 var eventValue = eventValues[i]; 752 var eventValue = eventValues[i];
493 for (var d = 0; d < eventValue.data.length; d++) { 753 for (var d = 0; d < eventValue.data.length; d++) {
494 var point = eventValue.data[d]; 754 var point = eventValue.data[d];
495 if (point.time >= this.start - timezoneOffset && 755 if (point.time >= this.start - timezoneOffset_ &&
496 point.time <= this.end - timezoneOffset) { 756 point.time <= this.end - timezoneOffset_) {
757
758 // Date wants Zulu time.
759 date = new Date(point.time + timezoneOffset_);
760 hours = date.getHours();
761 minutes = date.getMinutes();
762 explanation = eventValue.popupTitle + '\nAt: ' +
763 (date.getMonth() + 1) + '/' + date.getDate() + ' ' +
764 (hours < 10 ? '0' : '') + hours + ':' +
765 (minutes < 10 ? '0' : '') + minutes + '\n';
766
767 for (var key in point) {
768 if (key != 'time') {
769 var datum = point[key];
770 if ('label' in datum && 'value' in datum)
771 explanation = explanation + datum.label + ': ' +
772 datum.value + '\n';
773 }
774 }
497 markings.push({ 775 markings.push({
498 color: eventValue.color, 776 color: eventValue.color,
499 description: eventValue.description, 777 popupContent: explanation,
500 xaxis: {from: point.time, to: point.time} 778 xaxis: {from: point.time, to: point.time}
501 }); 779 });
502 } else { 780 } else {
503 console.log('Event out of time range ' + this.start + ' -> ' + 781 console.log('Event out of time range ' + this.start + ' -> ' +
504 this.end + ' at: ' + point.time); 782 this.end + ' at: ' + point.time);
505 } 783 }
506 } 784 }
507 } 785 }
508 786
509 return markings; 787 return markings;
510 }, 788 },
511 789
512 /** 790 /**
513 * Redraw the chart in div |chart|, *if* all its dependent data is present. 791 * Redraw the chart in div |chart|, *if* all its dependent data is present.
514 * Otherwise simply return, and await another call when all data is 792 * Otherwise simply return, and await another call when all data is
515 * available. 793 * available.
516 * @param {HTMLDivElement} chart The <div> to redraw. 794 * @param {HTMLDivElement} chart The <div> to redraw.
517 */ 795 */
518 drawChart: function(chart) { 796 drawChart: function(chart) {
519 var chartData = this.getChartData_(chart); 797 var chartData = this.getChartData_(chart);
798 var axisMap = {}; // Maps category ids to yAxis numbers
520 799
521 if (!this.isDataReady_(chartData)) 800 if (chart.hidden || !this.isDataReady_(chartData))
522 return; 801 return;
523 802
524 var seriesSeq = []; 803 var seriesSeq = [];
525 var yAxes = []; 804 var yAxes = [];
526 chartData.metrics.forEach(function(value) { 805 chartData.metrics.forEach(function(metricDetails) {
527 yAxes.push(value.yAxis); 806 var metricCategory = metricDetails.category;
528 for (var i = 0; i < value.data.length; i++) { 807 var yAxisNumber = axisMap[metricCategory.metricCategoryId];
808
809 // Add a new y-axis if we are encountering this category of metric
810 // for the first time. Otherwise, update the existing y-axis with
811 // a new max value if needed. (Presently, we expect only one category
812 // of metric per chart, but this design permits more in the future.)
813 if (yAxisNumber === undefined) {
814 yAxes.push({min: 0, max: metricDetails.maxValue * yAxisMargin_,
815 labelWidth: 60});
816 axisMap[metricCategory.metricCategoryId] = yAxisNumber = yAxes.length;
817 } else {
818 yAxes[yAxisNumber - 1].max = Math.max(yAxes[yAxisNumber - 1].max,
819 metricDetails.maxValue * yAxisMargin_);
820 }
821
822 for (var i = 0; i < metricDetails.data.length; i++) {
529 seriesSeq.push({ 823 seriesSeq.push({
530 color: value.yAxis.color, 824 color: metricDetails.color,
531 data: value.data[i], 825 data: metricDetails.data[i],
532 label: i == 0 ? value.description + ' (' + value.units + ')' : null, 826 label: i == 0 ? metricDetails.name +
533 yaxis: yAxes.length, // Use just-added Y axis. 827 ' (' + metricCategory.unit + ')' : null,
828 yaxis: yAxisNumber
534 }); 829 });
535 } 830 }
536 }); 831 });
537 832
538 // Ensure at least one y axis, as a reference for event placement.
539 if (yAxes.length == 0)
540 yAxes.push({max: 1.0});
541
542 var markings = this.getEventMarks_(chartData.events); 833 var markings = this.getEventMarks_(chartData.events);
543 var chart = this.charts[0];
544 var plot = $.plot(chart, seriesSeq, { 834 var plot = $.plot(chart, seriesSeq, {
545 yaxes: yAxes, 835 yaxes: yAxes,
546 xaxis: { 836 xaxis: {
547 mode: 'time', 837 mode: 'time',
548 min: this.start - timezoneOffset, 838 min: this.start - timezoneOffset_,
549 max: this.end - timezoneOffset 839 max: this.end - timezoneOffset_
550 }, 840 },
551 points: {show: true, radius: 1}, 841 points: {show: true, radius: 1},
552 lines: {show: true}, 842 lines: {show: true},
553 grid: {markings: markings} 843 grid: {markings: markings, hoverable: true, autoHighlight: true}
554 }); 844 });
555 845
556 // For each event in |markings|, create also a label div, with left 846 // For each event in |markings|, create also a label div, with left
557 // edge colinear with the event vertical line. Top of label is 847 // edge colinear with the event vertical line. Top of label is
558 // presently a hack-in, putting labels in three tiers of 25px height 848 // presently a hack-in, putting labels in three tiers of 25px height
559 // each to avoid overlap. Will need something better. 849 // each to avoid overlap. Will need something better.
560 var labelTemplate = $('#label-template')[0]; 850 var labelTemplate = $('#label-template')[0];
561 for (var i = 0; i < markings.length; i++) { 851 for (var i = 0; i < markings.length; i++) {
562 var mark = markings[i]; 852 var mark = markings[i];
563 var point = 853 var point =
564 plot.pointOffset({x: mark.xaxis.to, y: yAxes[0].max, yaxis: 1}); 854 plot.pointOffset({x: mark.xaxis.to, y: yAxes[0].max, yaxis: 1});
565 var labelDiv = labelTemplate.cloneNode(true); 855 var labelDiv = labelTemplate.cloneNode(true);
566 labelDiv.innerText = mark.description; 856 labelDiv.innerText = mark.popupContent;
567 labelDiv.style.left = point.left + 'px'; 857 labelDiv.style.left = point.left + 'px';
568 labelDiv.style.top = (point.top + 25 * (i % 3)) + 'px'; 858 labelDiv.style.top = (point.top + 100 * (i % 3)) + 'px';
569 859
570 chart.appendChild(labelDiv); 860 chart.appendChild(labelDiv);
861 labelDiv.hidden = true;
862 chart.hovers.push({x: mark.xaxis.to, div: labelDiv});
571 } 863 }
572 } 864 }
573 }; 865 };
574 return { 866 return {
575 PerformanceMonitor: PerformanceMonitor 867 PerformanceMonitor: PerformanceMonitor
576 }; 868 };
577 }); 869 });
578 870
579 var PerformanceMonitor = new performance_monitor.PerformanceMonitor(); 871 var PerformanceMonitor = new performance_monitor.PerformanceMonitor();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698