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

Side by Side Diff: Source/devtools/front_end/CountersGraph.js

Issue 211403002: DevTools: Support drawing limit value on counters graph (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 var ctx = canvas.getContext("2d"); 271 var ctx = canvas.getContext("2d");
272 var width = canvas.width; 272 var width = canvas.width;
273 var height = this._clippedHeight; 273 var height = this._clippedHeight;
274 var originY = this._originY; 274 var originY = this._originY;
275 var counter = counterUI.counter; 275 var counter = counterUI.counter;
276 var values = counter.values; 276 var values = counter.values;
277 277
278 if (!values.length) 278 if (!values.length)
279 return; 279 return;
280 280
281 var maxValue; 281 var bounds = counter._calculateBounds();
282 var minValue; 282 var minValue = bounds.min;
283 for (var i = counter._minimumIndex; i <= counter._maximumIndex; i++) { 283 var maxValue = bounds.max;
284 var value = values[i];
285 if (minValue === undefined || value < minValue)
286 minValue = value;
287 if (maxValue === undefined || value > maxValue)
288 maxValue = value;
289 }
290 minValue = minValue || 0;
291 maxValue = maxValue || 1;
292 284
293 counterUI.setRange(minValue, maxValue); 285 counterUI.setRange(minValue, maxValue);
294 286
295 if (!counterUI.visible()) 287 if (!counterUI.visible())
296 return; 288 return;
297 289
298 var yValues = counterUI.graphYValues; 290 var yValues = counterUI.graphYValues;
299 yValues.length = this._counters.length; 291 yValues.length = this._counters.length;
300 292
301 var maxYRange = maxValue - minValue; 293 var maxYRange = maxValue - minValue;
(...skipping 12 matching lines...) Expand all
314 if (typeof currentValue !== "undefined") 306 if (typeof currentValue !== "undefined")
315 value = currentValue; 307 value = currentValue;
316 currentY = Math.round(originY + height - (value - minValue) * yFact or); 308 currentY = Math.round(originY + height - (value - minValue) * yFact or);
317 ctx.lineTo(x, currentY); 309 ctx.lineTo(x, currentY);
318 yValues[i] = currentY; 310 yValues[i] = currentY;
319 } 311 }
320 ctx.lineTo(width, currentY); 312 ctx.lineTo(width, currentY);
321 ctx.lineWidth = 1; 313 ctx.lineWidth = 1;
322 ctx.strokeStyle = counterUI.graphColor; 314 ctx.strokeStyle = counterUI.graphColor;
323 ctx.stroke(); 315 ctx.stroke();
316 if (counter._limitValue) {
317 var limitLineY = Math.round(originY + height - (counter._limitValue - minValue) * yFactor);
318 ctx.moveTo(0, limitLineY);
319 ctx.lineTo(width, limitLineY);
320 ctx.strokeStyle = counterUI.limitColor;
321 ctx.stroke();
322 }
324 ctx.closePath(); 323 ctx.closePath();
325 ctx.restore(); 324 ctx.restore();
326 }, 325 },
327 326
328 __proto__: WebInspector.SplitView.prototype 327 __proto__: WebInspector.SplitView.prototype
329 } 328 }
330 329
331 /** 330 /**
332 * @constructor 331 * @constructor
333 */ 332 */
(...skipping 16 matching lines...) Expand all
350 this.values.push(value); 349 this.values.push(value);
351 }, 350 },
352 351
353 reset: function() 352 reset: function()
354 { 353 {
355 this.times = []; 354 this.times = [];
356 this.values = []; 355 this.values = [];
357 }, 356 },
358 357
359 /** 358 /**
359 * @param {number} value
360 */
361 setLimit: function(value)
362 {
363 this._limitValue = value;
364 },
365
366 /**
367 * @return {!{min: number, max: number}}
368 */
369 _calculateBounds: function()
370 {
371 var maxValue;
372 var minValue;
373 for (var i = this._minimumIndex; i <= this._maximumIndex; i++) {
374 var value = this.values[i];
375 if (minValue === undefined || value < minValue)
376 minValue = value;
377 if (maxValue === undefined || value > maxValue)
378 maxValue = value;
379 }
380 minValue = minValue || 0;
381 maxValue = maxValue || 1;
382 if (this._limitValue) {
383 if (maxValue > this._limitValue * 0.5)
384 maxValue = Math.max(maxValue, this._limitValue);
385 minValue = Math.min(minValue, this._limitValue);
386 }
387 return { min: minValue, max: maxValue };
388 },
389
390 /**
360 * @param {!WebInspector.TimelineCalculator} calculator 391 * @param {!WebInspector.TimelineCalculator} calculator
361 */ 392 */
362 _calculateVisibleIndexes: function(calculator) 393 _calculateVisibleIndexes: function(calculator)
363 { 394 {
364 var start = calculator.minimumBoundary(); 395 var start = calculator.minimumBoundary();
365 var end = calculator.maximumBoundary(); 396 var end = calculator.maximumBoundary();
366 397
367 // Maximum index of element whose time <= start. 398 // Maximum index of element whose time <= start.
368 this._minimumIndex = Number.constrain(this.times.upperBound(start) - 1, 0, this.times.length - 1); 399 this._minimumIndex = Number.constrain(this.times.upperBound(start) - 1, 0, this.times.length - 1);
369 400
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 var container = memoryCountersPane.sidebarElement().createChild("div", "memo ry-counter-sidebar-info"); 439 var container = memoryCountersPane.sidebarElement().createChild("div", "memo ry-counter-sidebar-info");
409 var swatchColor = graphColor; 440 var swatchColor = graphColor;
410 this._swatch = new WebInspector.SwatchCheckbox(WebInspector.UIString(title), swatchColor); 441 this._swatch = new WebInspector.SwatchCheckbox(WebInspector.UIString(title), swatchColor);
411 this._swatch.addEventListener(WebInspector.SwatchCheckbox.Events.Changed, th is._toggleCounterGraph.bind(this)); 442 this._swatch.addEventListener(WebInspector.SwatchCheckbox.Events.Changed, th is._toggleCounterGraph.bind(this));
412 container.appendChild(this._swatch.element); 443 container.appendChild(this._swatch.element);
413 this._range = this._swatch.element.createChild("span"); 444 this._range = this._swatch.element.createChild("span");
414 445
415 this._value = memoryCountersPane._currentValuesBar.createChild("span", "memo ry-counter-value"); 446 this._value = memoryCountersPane._currentValuesBar.createChild("span", "memo ry-counter-value");
416 this._value.style.color = graphColor; 447 this._value.style.color = graphColor;
417 this.graphColor = graphColor; 448 this.graphColor = graphColor;
418 this.strokeColor = graphColor; 449 this.limitColor = WebInspector.Color.parse(graphColor).setAlpha(0.3).toStrin g(WebInspector.Color.Format.RGBA);
419 this.graphYValues = []; 450 this.graphYValues = [];
420 451
421 this._currentValueLabel = currentValueLabel; 452 this._currentValueLabel = currentValueLabel;
422 this._marker = memoryCountersPane._canvasContainer.createChild("div", "memor y-counter-marker"); 453 this._marker = memoryCountersPane._canvasContainer.createChild("div", "memor y-counter-marker");
423 this._marker.style.backgroundColor = graphColor; 454 this._marker.style.backgroundColor = graphColor;
424 this._clearCurrentValueAndMarker(); 455 this._clearCurrentValueAndMarker();
425 } 456 }
426 457
427 WebInspector.CountersGraph.CounterUI.prototype = { 458 WebInspector.CountersGraph.CounterUI.prototype = {
428 reset: function() 459 reset: function()
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 }, 551 },
521 552
522 _toggleCheckbox: function(event) 553 _toggleCheckbox: function(event)
523 { 554 {
524 this.checked = !this.checked; 555 this.checked = !this.checked;
525 this.dispatchEventToListeners(WebInspector.SwatchCheckbox.Events.Changed ); 556 this.dispatchEventToListeners(WebInspector.SwatchCheckbox.Events.Changed );
526 }, 557 },
527 558
528 __proto__: WebInspector.Object.prototype 559 __proto__: WebInspector.Object.prototype
529 } 560 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698