Chromium Code Reviews| 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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 * @param {string} title | 395 * @param {string} title |
| 396 * @param {string} currentValueLabel | 396 * @param {string} currentValueLabel |
| 397 * @param {string} graphColor | 397 * @param {string} graphColor |
| 398 * @param {!WebInspector.CountersGraph.Counter} counter | 398 * @param {!WebInspector.CountersGraph.Counter} counter |
| 399 */ | 399 */ |
| 400 WebInspector.CountersGraph.CounterUI = function(memoryCountersPane, title, curre ntValueLabel, graphColor, counter) | 400 WebInspector.CountersGraph.CounterUI = function(memoryCountersPane, title, curre ntValueLabel, graphColor, counter) |
| 401 { | 401 { |
| 402 this._memoryCountersPane = memoryCountersPane; | 402 this._memoryCountersPane = memoryCountersPane; |
| 403 this.counter = counter; | 403 this.counter = counter; |
| 404 var container = memoryCountersPane._infoWidget.element.createChild("div", "m emory-counter-sidebar-info"); | 404 var container = memoryCountersPane._infoWidget.element.createChild("div", "m emory-counter-sidebar-info"); |
| 405 var swatchColor = graphColor; | 405 |
| 406 this._swatch = new WebInspector.SwatchCheckbox(WebInspector.UIString(title), swatchColor); | 406 this._filter = new WebInspector.CheckboxFilterUI(title, WebInspector.UIStrin g(title)); |
|
alph
2015/08/24 17:19:50
No need to use UIString here. It should be used ri
paulirish
2015/08/25 23:18:46
Done
| |
| 407 this._swatch.addEventListener(WebInspector.SwatchCheckbox.Events.Changed, th is._toggleCounterGraph.bind(this)); | 407 var color = WebInspector.Color.parse(graphColor).setAlpha(0.5).asString(WebI nspector.Color.Format.RGBA); |
| 408 container.appendChild(this._swatch.element); | 408 if (color !== null) |
|
alph
2015/08/24 17:19:50
if (color)
paulirish
2015/08/25 23:18:46
Done
| |
| 409 this._range = this._swatch.element.createChild("span"); | 409 this._filter.setColor(color, "rgba(0,0,0,0.3)"); |
| 410 this._filter.addEventListener(WebInspector.FilterUI.Events.FilterChanged, th is._toggleCounterGraph.bind(this)); | |
| 411 container.appendChild(this._filter.element()); | |
| 412 this._range = this._filter.labelElement().createChild("span", "range"); | |
|
alph
2015/08/24 17:19:50
I see the span text goes one pixel higher than the
paulirish
2015/08/25 23:18:46
Tried that but that makes the label clickable and
| |
| 410 | 413 |
| 411 this._value = memoryCountersPane._currentValuesBar.createChild("span", "memo ry-counter-value"); | 414 this._value = memoryCountersPane._currentValuesBar.createChild("span", "memo ry-counter-value"); |
| 412 this._value.style.color = graphColor; | 415 this._value.style.color = graphColor; |
| 413 this.graphColor = graphColor; | 416 this.graphColor = graphColor; |
| 414 this.limitColor = WebInspector.Color.parse(graphColor).setAlpha(0.3).asStrin g(WebInspector.Color.Format.RGBA); | 417 this.limitColor = WebInspector.Color.parse(graphColor).setAlpha(0.3).asStrin g(WebInspector.Color.Format.RGBA); |
| 415 this.graphYValues = []; | 418 this.graphYValues = []; |
| 416 this._verticalPadding = 10; | 419 this._verticalPadding = 10; |
| 417 | 420 |
| 418 this._currentValueLabel = currentValueLabel; | 421 this._currentValueLabel = currentValueLabel; |
| 419 this._marker = memoryCountersPane._canvasContainer.createChild("div", "memor y-counter-marker"); | 422 this._marker = memoryCountersPane._canvasContainer.createChild("div", "memor y-counter-marker"); |
| 420 this._marker.style.backgroundColor = graphColor; | 423 this._marker.style.backgroundColor = graphColor; |
| 421 this._clearCurrentValueAndMarker(); | 424 this._clearCurrentValueAndMarker(); |
| 422 } | 425 } |
| 423 | 426 |
| 424 WebInspector.CountersGraph.CounterUI.prototype = { | 427 WebInspector.CountersGraph.CounterUI.prototype = { |
| 425 reset: function() | 428 reset: function() |
| 426 { | 429 { |
| 427 this._range.textContent = ""; | 430 this._range.textContent = ""; |
| 428 }, | 431 }, |
| 429 | 432 |
| 430 /** | 433 /** |
| 431 * @param {number} minValue | 434 * @param {number} minValue |
| 432 * @param {number} maxValue | 435 * @param {number} maxValue |
| 436 * @param {!WebInspector.CountersGraph.Counter} counter | |
| 433 */ | 437 */ |
| 434 setRange: function(minValue, maxValue) | 438 setRange: function(minValue, maxValue, counter) |
| 435 { | 439 { |
| 436 this._range.textContent = WebInspector.UIString("[%.0f:%.0f]", minValue, maxValue); | 440 if (counter == this._memoryCountersPane.counters("jsHeapSizeUsed")) { |
|
alph
2015/08/24 17:19:50
There should be no knowledge of a particular count
paulirish
2015/08/25 23:18:46
good idea. Does the new patch handle this how you'
| |
| 441 var min = Number.bytesToString(minValue); | |
| 442 var max = Number.bytesToString(maxValue); | |
| 443 } else { | |
| 444 var min = Number.withThousandsSeparator(minValue); | |
| 445 var max = Number.withThousandsSeparator(maxValue); | |
| 446 } | |
| 447 this._range.textContent = WebInspector.UIString("[%s\u2009\u2013\u2009%s ]", min, max); | |
| 437 }, | 448 }, |
| 438 | 449 |
| 439 _toggleCounterGraph: function(event) | 450 _toggleCounterGraph: function(event) |
|
alph
2015/08/24 17:19:50
nit: could you please annotate.
paulirish
2015/08/25 23:18:46
Done.
| |
| 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 14 matching lines...) Expand all Loading... | |
| 487 var originY = this._verticalPadding; | 499 var originY = this._verticalPadding; |
| 488 var counter = this.counter; | 500 var counter = this.counter; |
| 489 var values = counter.values; | 501 var values = counter.values; |
| 490 | 502 |
| 491 if (!values.length) | 503 if (!values.length) |
| 492 return; | 504 return; |
| 493 | 505 |
| 494 var bounds = counter._calculateBounds(); | 506 var bounds = counter._calculateBounds(); |
| 495 var minValue = bounds.min; | 507 var minValue = bounds.min; |
| 496 var maxValue = bounds.max; | 508 var maxValue = bounds.max; |
| 497 this.setRange(minValue, maxValue); | 509 this.setRange(minValue, maxValue, counter); |
| 498 | 510 |
| 499 if (!this.visible()) | 511 if (!this.visible()) |
| 500 return; | 512 return; |
| 501 | 513 |
| 502 var yValues = this.graphYValues; | 514 var yValues = this.graphYValues; |
| 503 var maxYRange = maxValue - minValue; | 515 var maxYRange = maxValue - minValue; |
| 504 var yFactor = maxYRange ? height / (maxYRange) : 1; | 516 var yFactor = maxYRange ? height / (maxYRange) : 1; |
| 505 | 517 |
| 506 ctx.save(); | 518 ctx.save(); |
| 507 ctx.lineWidth = window.devicePixelRatio; | 519 ctx.lineWidth = window.devicePixelRatio; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 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 } | |
| OLD | NEW |