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

Side by Side Diff: chrome/browser/resources/chromeos/power.js

Issue 140663004: [chromeos] Add a battery discharge rate plot to about:power page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 /** 5 /**
6 * Plot a line graph of data versus time on a HTML canvas element. 6 * Plot a line graph of data versus time on a HTML canvas element.
7 * 7 *
8 * @param {HTMLCanvasElement} canvas The canvas on which the line graph is 8 * @param {HTMLCanvasElement} canvas The canvas on which the line graph is
9 * drawn. 9 * drawn.
10 * @param {Array.<number>} tData The time (in seconds) in the past when the 10 * @param {Array.<number>} tData The time (in seconds) in the past when the
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 } 229 }
230 230
231 /** 231 /**
232 * Display the battery charge vs time on a line graph. 232 * Display the battery charge vs time on a line graph.
233 * 233 *
234 * @param {Array.<Object>} powerSupplyArray An array of objects with fields 234 * @param {Array.<Object>} powerSupplyArray An array of objects with fields
235 * representing the battery charge, time when the charge measurement was 235 * representing the battery charge, time when the charge measurement was
236 * taken, and whether there was external power connected at that time. 236 * taken, and whether there was external power connected at that time.
237 */ 237 */
238 function showBatteryChargeData(powerSupplyArray) { 238 function showBatteryChargeData(powerSupplyArray) {
239 var canvas = $('battery-charge-canvas');
240 var tData = []; 239 var tData = [];
241 var plot = []; 240 var chargePlot = [
241 {
242 color: '#0000FF',
243 data: []
244 }
245 ];
246 var dischargeRatePlot = [
247 {
248 color: '#FF0000',
249 data: []
250 }
251 ];
252 var minDischargeRate = 1000; // A high unrealistic number to begin with.
253 var maxDischargeRate = -1000; // A low unrealistic number to begin with.
242 for (var i = 0; i < powerSupplyArray.length; i++) { 254 for (var i = 0; i < powerSupplyArray.length; i++) {
243 var time = new Date(powerSupplyArray[i].time); 255 var time = new Date(powerSupplyArray[i].time);
244 tData[i] = time.toLocaleTimeString(); 256 tData[i] = time.toLocaleTimeString();
245 plot[i] = powerSupplyArray[i].battery_percent; 257
258 chargePlot[0].data[i] = powerSupplyArray[i].battery_percent;
259
260 var dischargeRate = powerSupplyArray[i].battery_discharge_rate;
261 dischargeRatePlot[0].data[i] = dischargeRate;
262 minDischargeRate = Math.min(dischargeRate, minDischargeRate);
263 maxDischargeRate = Math.max(dischargeRate, maxDischargeRate);
264 }
265 if (minDischargeRate == maxDischargeRate) {
266 // This means that all the samples had the same value. Hence, offset the
267 // extremes by a bit so that the plot looks good.
268 minDischargeRate -= 1;
269 maxDischargeRate += 1;
246 } 270 }
247 271
248 var plots = [ 272 var chargeCanvas = $('battery-charge-percentage-canvas');
249 { 273 var dischargeRateCanvas = $('battery-discharge-rate-canvas');
250 color: '#0000FF', 274 plotLineGraph(chargeCanvas, tData, chargePlot, 0.00, 100.00, 3);
251 data: plot 275 plotLineGraph(dischargeRateCanvas,
252 } 276 tData,
253 ]; 277 dischargeRatePlot,
254 plotLineGraph(canvas, tData, plots, 0.00, 100.00, 3); 278 minDischargeRate,
279 maxDischargeRate,
280 3);
255 } 281 }
256 282
257 function requestBatteryChargeData() { 283 function requestBatteryChargeData() {
258 chrome.send('requestBatteryChargeData'); 284 chrome.send('requestBatteryChargeData');
259 } 285 }
260 286
261 var powerUI = { 287 var powerUI = {
262 showBatteryChargeData: showBatteryChargeData 288 showBatteryChargeData: showBatteryChargeData
263 }; 289 };
264 290
265 document.addEventListener('DOMContentLoaded', function() { 291 document.addEventListener('DOMContentLoaded', function() {
266 requestBatteryChargeData(); 292 requestBatteryChargeData();
267 $('battery-charge-reload-button').onclick = requestBatteryChargeData; 293 $('battery-charge-reload-button').onclick = requestBatteryChargeData;
268 }); 294 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698