OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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)|undefined} formatter | |
alph
2015/08/26 16:59:09
Use {function(number):string=} to make the argumen
paulirish
2015/08/26 18:04:57
Done.
| |
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 Loading... | |
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)|undefined} formatter | |
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; | |
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 formatter = this._formatter || Number.withThousandsSeparator; |
alph
2015/08/26 16:59:08
Move "|| Number.withThousandsSeparator" to the con
paulirish
2015/08/26 18:04:57
Done.
| |
443 var min = formatter(minValue); | |
444 var max = formatter(maxValue); | |
445 this._range.textContent = WebInspector.UIString("[%s\u2009\u2013\u2009%s ]", min, max); | |
437 }, | 446 }, |
438 | 447 |
448 /** | |
449 * @param {!WebInspector.Event} event | |
450 */ | |
439 _toggleCounterGraph: function(event) | 451 _toggleCounterGraph: function(event) |
440 { | 452 { |
441 this._value.classList.toggle("hidden", !this._swatch.checked); | 453 this._value.classList.toggle("hidden", !this._filter.checked()); |
442 this._memoryCountersPane.refresh(); | 454 this._memoryCountersPane.refresh(); |
443 }, | 455 }, |
444 | 456 |
445 /** | 457 /** |
446 * @param {number} x | 458 * @param {number} x |
447 * @return {number} | 459 * @return {number} |
448 */ | 460 */ |
449 _recordIndexAt: function(x) | 461 _recordIndexAt: function(x) |
450 { | 462 { |
451 return this.counter.x.upperBound(x * window.devicePixelRatio, null, this .counter._minimumIndex + 1, this.counter._maximumIndex + 1) - 1; | 463 return this.counter.x.upperBound(x * window.devicePixelRatio, null, this .counter._minimumIndex + 1, this.counter._maximumIndex + 1) - 1; |
452 }, | 464 }, |
453 | 465 |
454 /** | 466 /** |
455 * @param {number} x | 467 * @param {number} x |
456 */ | 468 */ |
457 updateCurrentValue: function(x) | 469 updateCurrentValue: function(x) |
458 { | 470 { |
459 if (!this.visible() || !this.counter.values.length || !this.counter.x) | 471 if (!this.visible() || !this.counter.values.length || !this.counter.x) |
460 return; | 472 return; |
461 var index = this._recordIndexAt(x); | 473 var index = this._recordIndexAt(x); |
462 this._value.textContent = WebInspector.UIString(this._currentValueLabel, this.counter.values[index]); | 474 var value = Number.withThousandsSeparator(this.counter.values[index]); |
475 this._value.textContent = WebInspector.UIString(this._currentValueLabel, value); | |
463 var y = this.graphYValues[index] / window.devicePixelRatio; | 476 var y = this.graphYValues[index] / window.devicePixelRatio; |
464 this._marker.style.left = x + "px"; | 477 this._marker.style.left = x + "px"; |
465 this._marker.style.top = y + "px"; | 478 this._marker.style.top = y + "px"; |
466 this._marker.classList.remove("hidden"); | 479 this._marker.classList.remove("hidden"); |
467 }, | 480 }, |
468 | 481 |
469 _clearCurrentValueAndMarker: function() | 482 _clearCurrentValueAndMarker: function() |
470 { | 483 { |
471 this._value.textContent = ""; | 484 this._value.textContent = ""; |
472 this._marker.classList.add("hidden"); | 485 this._marker.classList.add("hidden"); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
534 } | 547 } |
535 ctx.closePath(); | 548 ctx.closePath(); |
536 ctx.restore(); | 549 ctx.restore(); |
537 }, | 550 }, |
538 | 551 |
539 /** | 552 /** |
540 * @return {boolean} | 553 * @return {boolean} |
541 */ | 554 */ |
542 visible: function() | 555 visible: function() |
543 { | 556 { |
544 return this._swatch.checked; | 557 return this._filter.checked(); |
545 } | 558 } |
546 } | 559 } |
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 } | |
OLD | NEW |