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

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

Issue 1309723003: DevTools: Refactor memory counter display (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: range inside label Created 5 years, 4 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
« no previous file with comments | « no previous file | Source/devtools/front_end/timeline/MemoryCountersGraph.js » ('j') | 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 20 matching lines...) Expand all
31 /** 31 /**
32 * @constructor 32 * @constructor
33 * @extends {WebInspector.SplitWidget} 33 * @extends {WebInspector.SplitWidget}
34 * @implements {WebInspector.TimelineModeView} 34 * @implements {WebInspector.TimelineModeView}
35 * @param {string} title 35 * @param {string} title
36 * @param {!WebInspector.TimelineModeViewDelegate} delegate 36 * @param {!WebInspector.TimelineModeViewDelegate} delegate
37 * @param {!WebInspector.TimelineModel} model 37 * @param {!WebInspector.TimelineModel} model
38 */ 38 */
39 WebInspector.CountersGraph = function(title, delegate, model) 39 WebInspector.CountersGraph = function(title, delegate, model)
40 { 40 {
41 WebInspector.SplitWidget.call(this, true, false); 41 WebInspector.SplitWidget.call(this, true, false, "memoryCountersSidebar");
42 42
43 this.element.id = "memory-graphs-container"; 43 this.element.id = "memory-graphs-container";
44 44
45 this._delegate = delegate; 45 this._delegate = delegate;
46 this._model = model; 46 this._model = model;
47 this._calculator = new WebInspector.TimelineCalculator(this._model); 47 this._calculator = new WebInspector.TimelineCalculator(this._model);
48 48
49 this._graphsContainer = new WebInspector.VBox(); 49 this._graphsContainer = new WebInspector.VBox();
50 this.setMainWidget(this._graphsContainer); 50 this.setMainWidget(this._graphsContainer);
51 this._createCurrentValuesBar(); 51 this._createCurrentValuesBar();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 _createCurrentValuesBar: function() 85 _createCurrentValuesBar: function()
86 { 86 {
87 this._currentValuesBar = this._graphsContainer.element.createChild("div" ); 87 this._currentValuesBar = this._graphsContainer.element.createChild("div" );
88 this._currentValuesBar.id = "counter-values-bar"; 88 this._currentValuesBar.id = "counter-values-bar";
89 }, 89 },
90 90
91 /** 91 /**
92 * @param {string} uiName 92 * @param {string} uiName
93 * @param {string} uiValueTemplate 93 * @param {string} uiValueTemplate
94 * @param {string} color 94 * @param {string} color
95 * @param {function(number): string} formatter
95 * @return {!WebInspector.CountersGraph.Counter} 96 * @return {!WebInspector.CountersGraph.Counter}
96 */ 97 */
97 createCounter: function(uiName, uiValueTemplate, color) 98 createCounter: function(uiName, uiValueTemplate, color, formatter)
98 { 99 {
99 var counter = new WebInspector.CountersGraph.Counter(); 100 var counter = new WebInspector.CountersGraph.Counter();
100 this._counters.push(counter); 101 this._counters.push(counter);
101 this._counterUI.push(new WebInspector.CountersGraph.CounterUI(this, uiNa me, uiValueTemplate, color, counter)); 102 this._counterUI.push(new WebInspector.CountersGraph.CounterUI(this, uiNa me, uiValueTemplate, color, counter, formatter));
102 return counter; 103 return counter;
103 }, 104 },
104 105
105 /** 106 /**
106 * @override 107 * @override
107 * @return {!WebInspector.Widget} 108 * @return {!WebInspector.Widget}
108 */ 109 */
109 view: function() 110 view: function()
110 { 111 {
111 return this; 112 return this;
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 } 390 }
390 } 391 }
391 392
392 /** 393 /**
393 * @constructor 394 * @constructor
394 * @param {!WebInspector.CountersGraph} memoryCountersPane 395 * @param {!WebInspector.CountersGraph} memoryCountersPane
395 * @param {string} title 396 * @param {string} title
396 * @param {string} currentValueLabel 397 * @param {string} currentValueLabel
397 * @param {string} graphColor 398 * @param {string} graphColor
398 * @param {!WebInspector.CountersGraph.Counter} counter 399 * @param {!WebInspector.CountersGraph.Counter} counter
400 * @param {function(number): string} formatter
alph 2015/08/25 23:59:56 nit: If you want, you can make it optional default
399 */ 401 */
400 WebInspector.CountersGraph.CounterUI = function(memoryCountersPane, title, curre ntValueLabel, graphColor, counter) 402 WebInspector.CountersGraph.CounterUI = function(memoryCountersPane, title, curre ntValueLabel, graphColor, counter, formatter)
401 { 403 {
402 this._memoryCountersPane = memoryCountersPane; 404 this._memoryCountersPane = memoryCountersPane;
403 this.counter = counter; 405 this.counter = counter;
406 this.formatter = formatter;
alph 2015/08/25 23:59:56 nit: this._formatter
404 var container = memoryCountersPane._infoWidget.element.createChild("div", "m emory-counter-sidebar-info"); 407 var container = memoryCountersPane._infoWidget.element.createChild("div", "m emory-counter-sidebar-info");
405 var swatchColor = graphColor; 408
406 this._swatch = new WebInspector.SwatchCheckbox(WebInspector.UIString(title), swatchColor); 409 this._filter = new WebInspector.CheckboxFilterUI(title, title);
407 this._swatch.addEventListener(WebInspector.SwatchCheckbox.Events.Changed, th is._toggleCounterGraph.bind(this)); 410 var color = WebInspector.Color.parse(graphColor).setAlpha(0.5).asString(WebI nspector.Color.Format.RGBA);
408 container.appendChild(this._swatch.element); 411 if (color)
409 this._range = this._swatch.element.createChild("span"); 412 this._filter.setColor(color, "rgba(0,0,0,0.3)");
413 this._filter.addEventListener(WebInspector.FilterUI.Events.FilterChanged, th is._toggleCounterGraph.bind(this));
414 container.appendChild(this._filter.element());
415 this._range = this._filter.labelElement().createChild("span", "range");
410 416
411 this._value = memoryCountersPane._currentValuesBar.createChild("span", "memo ry-counter-value"); 417 this._value = memoryCountersPane._currentValuesBar.createChild("span", "memo ry-counter-value");
412 this._value.style.color = graphColor; 418 this._value.style.color = graphColor;
413 this.graphColor = graphColor; 419 this.graphColor = graphColor;
414 this.limitColor = WebInspector.Color.parse(graphColor).setAlpha(0.3).asStrin g(WebInspector.Color.Format.RGBA); 420 this.limitColor = WebInspector.Color.parse(graphColor).setAlpha(0.3).asStrin g(WebInspector.Color.Format.RGBA);
415 this.graphYValues = []; 421 this.graphYValues = [];
416 this._verticalPadding = 10; 422 this._verticalPadding = 10;
417 423
418 this._currentValueLabel = currentValueLabel; 424 this._currentValueLabel = currentValueLabel;
419 this._marker = memoryCountersPane._canvasContainer.createChild("div", "memor y-counter-marker"); 425 this._marker = memoryCountersPane._canvasContainer.createChild("div", "memor y-counter-marker");
420 this._marker.style.backgroundColor = graphColor; 426 this._marker.style.backgroundColor = graphColor;
421 this._clearCurrentValueAndMarker(); 427 this._clearCurrentValueAndMarker();
422 } 428 }
423 429
424 WebInspector.CountersGraph.CounterUI.prototype = { 430 WebInspector.CountersGraph.CounterUI.prototype = {
425 reset: function() 431 reset: function()
426 { 432 {
427 this._range.textContent = ""; 433 this._range.textContent = "";
428 }, 434 },
429 435
430 /** 436 /**
431 * @param {number} minValue 437 * @param {number} minValue
432 * @param {number} maxValue 438 * @param {number} maxValue
433 */ 439 */
434 setRange: function(minValue, maxValue) 440 setRange: function(minValue, maxValue)
435 { 441 {
436 this._range.textContent = WebInspector.UIString("[%.0f:%.0f]", minValue, maxValue); 442 var min = this.formatter(minValue);
443 var max = this.formatter(maxValue);
444 this._range.textContent = WebInspector.UIString("[%s\u2009\u2013\u2009%s ]", min, max);
437 }, 445 },
438 446
447 /**
448 * @param {!WebInspector.Event} event
449 */
439 _toggleCounterGraph: function(event) 450 _toggleCounterGraph: function(event)
440 { 451 {
441 this._value.classList.toggle("hidden", !this._swatch.checked); 452 this._value.classList.toggle("hidden", !this._filter.checked());
442 this._memoryCountersPane.refresh(); 453 this._memoryCountersPane.refresh();
443 }, 454 },
444 455
445 /** 456 /**
446 * @param {number} x 457 * @param {number} x
447 * @return {number} 458 * @return {number}
448 */ 459 */
449 _recordIndexAt: function(x) 460 _recordIndexAt: function(x)
450 { 461 {
451 return this.counter.x.upperBound(x * window.devicePixelRatio, null, this .counter._minimumIndex + 1, this.counter._maximumIndex + 1) - 1; 462 return this.counter.x.upperBound(x * window.devicePixelRatio, null, this .counter._minimumIndex + 1, this.counter._maximumIndex + 1) - 1;
452 }, 463 },
453 464
454 /** 465 /**
455 * @param {number} x 466 * @param {number} x
456 */ 467 */
457 updateCurrentValue: function(x) 468 updateCurrentValue: function(x)
458 { 469 {
459 if (!this.visible() || !this.counter.values.length || !this.counter.x) 470 if (!this.visible() || !this.counter.values.length || !this.counter.x)
460 return; 471 return;
461 var index = this._recordIndexAt(x); 472 var index = this._recordIndexAt(x);
462 this._value.textContent = WebInspector.UIString(this._currentValueLabel, this.counter.values[index]); 473 var value = Number.withThousandsSeparator(this.counter.values[index]);
474 this._value.textContent = WebInspector.UIString(this._currentValueLabel, value);
463 var y = this.graphYValues[index] / window.devicePixelRatio; 475 var y = this.graphYValues[index] / window.devicePixelRatio;
464 this._marker.style.left = x + "px"; 476 this._marker.style.left = x + "px";
465 this._marker.style.top = y + "px"; 477 this._marker.style.top = y + "px";
466 this._marker.classList.remove("hidden"); 478 this._marker.classList.remove("hidden");
467 }, 479 },
468 480
469 _clearCurrentValueAndMarker: function() 481 _clearCurrentValueAndMarker: function()
470 { 482 {
471 this._value.textContent = ""; 483 this._value.textContent = "";
472 this._marker.classList.add("hidden"); 484 this._marker.classList.add("hidden");
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 } 546 }
535 ctx.closePath(); 547 ctx.closePath();
536 ctx.restore(); 548 ctx.restore();
537 }, 549 },
538 550
539 /** 551 /**
540 * @return {boolean} 552 * @return {boolean}
541 */ 553 */
542 visible: function() 554 visible: function()
543 { 555 {
544 return this._swatch.checked; 556 return this._filter.checked();
545 } 557 }
546 } 558 }
547
548
549 /**
550 * @constructor
551 * @extends {WebInspector.Object}
552 */
553 WebInspector.SwatchCheckbox = function(title, color)
554 {
555 this.element = createElement("div");
556 this._swatch = this.element.createChild("div", "swatch");
557 this.element.createChild("span", "title").textContent = title;
558 this._color = color;
559 this.checked = true;
560
561 this.element.addEventListener("click", this._toggleCheckbox.bind(this), true );
562 }
563
564 WebInspector.SwatchCheckbox.Events = {
565 Changed: "Changed"
566 }
567
568 WebInspector.SwatchCheckbox.prototype = {
569 get checked()
570 {
571 return this._checked;
572 },
573
574 set checked(v)
575 {
576 this._checked = v;
577 if (this._checked)
578 this._swatch.style.backgroundColor = this._color;
579 else
580 this._swatch.style.backgroundColor = "";
581 },
582
583 _toggleCheckbox: function(event)
584 {
585 this.checked = !this.checked;
586 this.dispatchEventToListeners(WebInspector.SwatchCheckbox.Events.Changed );
587 },
588
589 __proto__: WebInspector.Object.prototype
590 }
OLDNEW
« no previous file with comments | « no previous file | Source/devtools/front_end/timeline/MemoryCountersGraph.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698