<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[188916] trunk/Source/WebInspectorUI</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/188916">188916</a></dd>
<dt>Author</dt> <dd>mattbaker@apple.com</dd>
<dt>Date</dt> <dd>2015-08-25 10:55:07 -0700 (Tue, 25 Aug 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Web Inspector: Rendering Frames pie chart should use the needsLayout/updateLayout idiom
https://bugs.webkit.org/show_bug.cgi?id=148412

Reviewed by Timothy Hatcher.

* UserInterface/Views/ChartDetailsSectionRow.js:
(WebInspector.ChartDetailsSectionRow):
(WebInspector.ChartDetailsSectionRow.prototype.set innerLabel):
(WebInspector.ChartDetailsSectionRow.prototype.set innerRadius):
Schedule a layout.
(WebInspector.ChartDetailsSectionRow.prototype.set data): Deleted.
Replaced by addItem, setItemValue, and clearItems.
(WebInspector.ChartDetailsSectionRow.prototype.addItem):
(WebInspector.ChartDetailsSectionRow.prototype.setItemValue):
(WebInspector.ChartDetailsSectionRow.prototype.clearItems):
Add/update data points and schedule a layout.
(WebInspector.ChartDetailsSectionRow.prototype._needsLayout):
(WebInspector.ChartDetailsSectionRow.prototype.updateLayout):
Update legend and draw pie chart.
(WebInspector.ChartDetailsSectionRow.prototype._createLegend): Deleted.
Refactored as _updateLegend.
(WebInspector.ChartDetailsSectionRow.prototype._refresh): Deleted.
Refactored as updateLayout.

* UserInterface/Views/TimelineSidebarPanel.js:
(WebInspector.TimelineSidebarPanel):
Add chart data points once.
(WebInspector.TimelineSidebarPanel._refreshFrameSelectionChart):
Update chart values.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebInspectorUIChangeLog">trunk/Source/WebInspectorUI/ChangeLog</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceViewsChartDetailsSectionRowjs">trunk/Source/WebInspectorUI/UserInterface/Views/ChartDetailsSectionRow.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceViewsTimelineSidebarPaneljs">trunk/Source/WebInspectorUI/UserInterface/Views/TimelineSidebarPanel.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebInspectorUIChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/ChangeLog (188915 => 188916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/ChangeLog        2015-08-25 17:36:41 UTC (rev 188915)
+++ trunk/Source/WebInspectorUI/ChangeLog        2015-08-25 17:55:07 UTC (rev 188916)
</span><span class="lines">@@ -1,3 +1,35 @@
</span><ins>+2015-08-25  Matt Baker  &lt;mattbaker@apple.com&gt;
+
+        Web Inspector: Rendering Frames pie chart should use the needsLayout/updateLayout idiom
+        https://bugs.webkit.org/show_bug.cgi?id=148412
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Views/ChartDetailsSectionRow.js:
+        (WebInspector.ChartDetailsSectionRow):
+        (WebInspector.ChartDetailsSectionRow.prototype.set innerLabel):
+        (WebInspector.ChartDetailsSectionRow.prototype.set innerRadius):
+        Schedule a layout.
+        (WebInspector.ChartDetailsSectionRow.prototype.set data): Deleted.
+        Replaced by addItem, setItemValue, and clearItems.
+        (WebInspector.ChartDetailsSectionRow.prototype.addItem):
+        (WebInspector.ChartDetailsSectionRow.prototype.setItemValue):
+        (WebInspector.ChartDetailsSectionRow.prototype.clearItems):
+        Add/update data points and schedule a layout.
+        (WebInspector.ChartDetailsSectionRow.prototype._needsLayout):
+        (WebInspector.ChartDetailsSectionRow.prototype.updateLayout):
+        Update legend and draw pie chart.
+        (WebInspector.ChartDetailsSectionRow.prototype._createLegend): Deleted.
+        Refactored as _updateLegend.
+        (WebInspector.ChartDetailsSectionRow.prototype._refresh): Deleted.
+        Refactored as updateLayout.
+
+        * UserInterface/Views/TimelineSidebarPanel.js:
+        (WebInspector.TimelineSidebarPanel):
+        Add chart data points once.
+        (WebInspector.TimelineSidebarPanel._refreshFrameSelectionChart):
+        Update chart values.
+
</ins><span class="cx"> 2015-08-24  Brian Burg  &lt;bburg@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Web Inspector: add protocol test for existing error handling performed by the backend
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceViewsChartDetailsSectionRowjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ChartDetailsSectionRow.js (188915 => 188916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Views/ChartDetailsSectionRow.js        2015-08-25 17:36:41 UTC (rev 188915)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ChartDetailsSectionRow.js        2015-08-25 17:55:07 UTC (rev 188916)
</span><span class="lines">@@ -48,7 +48,7 @@
</span><span class="cx">         chartContentElement.appendChild(this._legendElement);
</span><span class="cx"> 
</span><span class="cx">         this._delegate = delegate;
</span><del>-        this._items = [];
</del><ins>+        this._items = new Map;
</ins><span class="cx">         this._title = &quot;&quot;;
</span><span class="cx">         this._innerLabel = &quot;&quot;;
</span><span class="cx">         this._innerRadius = 0;
</span><span class="lines">@@ -83,7 +83,7 @@
</span><span class="cx"> 
</span><span class="cx">         this._innerLabel = label;
</span><span class="cx"> 
</span><del>-        this._refresh();
</del><ins>+        this._needsLayout();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     set innerRadius(radius)
</span><span class="lines">@@ -93,7 +93,7 @@
</span><span class="cx"> 
</span><span class="cx">         this._innerRadius = radius;
</span><span class="cx"> 
</span><del>-        this._refresh();
</del><ins>+        this._needsLayout();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     get total()
</span><span class="lines">@@ -101,25 +101,50 @@
</span><span class="cx">         return this._total;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    set data(items)
</del><ins>+    addItem(id, label, value, color, checkbox, checked)
</ins><span class="cx">     {
</span><del>-        if (!(items instanceof Array))
-            items = [items];
</del><ins>+        console.assert(!this._items.has(id), &quot;Already added item with id: &quot; + id);
+        if (this._items.has(id))
+            return;
</ins><span class="cx"> 
</span><del>-        items = items.filter(function(item) { return item.value &gt;= 0; });
-        if (!this._items.length &amp;&amp; !items.length)
</del><ins>+        console.assert(value &gt;= 0, &quot;Value cannot be negative.&quot;);
+        if (value &lt; 0)
</ins><span class="cx">             return;
</span><span class="cx"> 
</span><del>-        if (this._items.length === items.length &amp;&amp; this._items.every(function(item, index) { return JSON.stringify(item) === JSON.stringify(items[index]); }))
</del><ins>+        this._items.set(id, {label, value, color, checkbox, checked});
+        this._total += value;
+
+        this._needsLayout();
+    }
+
+    setItemValue(id, value)
+    {
+        let item = this._items.get(id);
+        console.assert(item, &quot;Cannot set value for invalid item id: &quot; + id);
+        if (!item)
</ins><span class="cx">             return;
</span><span class="cx"> 
</span><del>-        this._items = items;
-        this._total = this._items.reduce(function(previousValue, currentValue) { return previousValue + currentValue.value; }, 0);;
</del><ins>+        console.assert(value &gt;= 0, &quot;Value cannot be negative.&quot;);
+        if (value &lt; 0)
+            return;
</ins><span class="cx"> 
</span><del>-        this._createLegend();
-        this._refresh();
</del><ins>+        if (item.value === value)
+            return;
+
+        this._total += value - item.value;
+        item.value = value;
+
+        this._needsLayout();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    clearItems()
+    {
+        this._total = 0;
+        this._items.clear();
+
+        this._needsLayout();
+    }
+
</ins><span class="cx">     // Private
</span><span class="cx"> 
</span><span class="cx">     _addCheckboxColorFilter(id, r, g, b)
</span><span class="lines">@@ -165,15 +190,31 @@
</span><span class="cx">         styleSheet.insertRule(&quot;.details-section &gt; .content &gt; .group &gt; .row.chart &gt; .chart-content &gt; .legend &gt; .legend-item &gt; label &gt; input[type=checkbox].&quot; + id + &quot; { filter: grayscale(1) url(#&quot; + id + &quot;) }&quot;, 0);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    _createLegend()
</del><ins>+    _updateLegend()
</ins><span class="cx">     {
</span><del>-        this._legendElement.removeChildren();
</del><ins>+        if (!this._items.size) {
+            this._legendElement.removeChildren();
+            return;
+        }
</ins><span class="cx"> 
</span><del>-        for (let item of this._items) {
</del><ins>+        function formatItemValue(item)
+        {
+            if (this._delegate &amp;&amp; typeof this._delegate.formatChartValue === &quot;function&quot;)
+                return this._delegate.formatChartValue(item.value);
+            return item.value;
+        }
+
+        for (let [id, item] of this._items) {
+            if (item[WebInspector.ChartDetailsSectionRow.LegendItemValueElementSymbol]) {
+                let valueElement = item[WebInspector.ChartDetailsSectionRow.LegendItemValueElementSymbol];
+                valueElement.textContent = formatItemValue.call(this, item);
+                continue;
+            }
+
</ins><span class="cx">             let labelElement = document.createElement(&quot;label&quot;);
</span><span class="cx">             let keyElement;
</span><span class="cx">             if (item.checkbox) {
</span><del>-                let className = item.id.toLowerCase();
</del><ins>+                let className = id.toLowerCase();
</ins><span class="cx">                 let rgb = item.color.substring(4, item.color.length - 1).replace(/ /g, &quot;&quot;).split(&quot;,&quot;);
</span><span class="cx">                 if (rgb[0] === rgb[1] &amp;&amp; rgb[1] === rgb[2])
</span><span class="cx">                     rgb[0] = rgb[1] = rgb[2] = Math.min(160, rgb[0]);
</span><span class="lines">@@ -182,7 +223,7 @@
</span><span class="cx">                 keyElement.type = &quot;checkbox&quot;;
</span><span class="cx">                 keyElement.classList.add(className);
</span><span class="cx">                 keyElement.checked = item.checked;
</span><del>-                keyElement[WebInspector.ChartDetailsSectionRow.DataItemIdSymbol] = item.id;
</del><ins>+                keyElement[WebInspector.ChartDetailsSectionRow.DataItemIdSymbol] = id;
</ins><span class="cx"> 
</span><span class="cx">                 keyElement.addEventListener(&quot;change&quot;, this._legendItemCheckboxValueChanged.bind(this));
</span><span class="cx"> 
</span><span class="lines">@@ -197,11 +238,9 @@
</span><span class="cx"> 
</span><span class="cx">             let valueElement = document.createElement(&quot;div&quot;);
</span><span class="cx">             valueElement.classList.add(&quot;value&quot;);
</span><ins>+            valueElement.textContent = formatItemValue.call(this, item);
</ins><span class="cx"> 
</span><del>-            if (this._delegate &amp;&amp; typeof this._delegate.formatChartValue === &quot;function&quot;)
-                valueElement.textContent = this._delegate.formatChartValue(item.value);
-            else
-                valueElement.textContent = item.value;
</del><ins>+            item[WebInspector.ChartDetailsSectionRow.LegendItemValueElementSymbol] = valueElement;
</ins><span class="cx"> 
</span><span class="cx">             let legendItemElement = document.createElement(&quot;div&quot;);
</span><span class="cx">             legendItemElement.classList.add(&quot;legend-item&quot;);
</span><span class="lines">@@ -218,8 +257,23 @@
</span><span class="cx">         this.dispatchEventToListeners(WebInspector.ChartDetailsSectionRow.Event.LegendItemChecked, {id, checked: checkbox.checked});
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    _refresh()
</del><ins>+    _needsLayout()
</ins><span class="cx">     {
</span><ins>+        if (this._scheduledLayoutUpdateIdentifier)
+            return;
+
+        this._scheduledLayoutUpdateIdentifier = requestAnimationFrame(this.updateLayout.bind(this));
+    }
+
+    updateLayout()
+    {
+        if (this._scheduledLayoutUpdateIdentifier) {
+            cancelAnimationFrame(this._scheduledLayoutUpdateIdentifier);
+            this._scheduledLayoutUpdateIdentifier = undefined;
+        }
+
+        this._updateLegend();
+
</ins><span class="cx">         var width = this._canvas.clientWidth * window.devicePixelRatio;
</span><span class="cx">         var height = this._canvas.clientHeight * window.devicePixelRatio;
</span><span class="cx">         this._canvas.width = width;
</span><span class="lines">@@ -253,7 +307,7 @@
</span><span class="cx">         drawSlice(x, y, 0, 2.0 * Math.PI, &quot;rgb(242, 242, 242)&quot;);
</span><span class="cx">         context.restore();
</span><span class="cx"> 
</span><del>-        for (var item of this._items) {
</del><ins>+        for (let [id, item] of this._items) {
</ins><span class="cx">             if (item.value === 0)
</span><span class="cx">                 continue;
</span><span class="cx">             endAngle += (item.value / this._total) * 2.0 * Math.PI;
</span><span class="lines">@@ -272,6 +326,7 @@
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> WebInspector.ChartDetailsSectionRow.DataItemIdSymbol = Symbol(&quot;chart-details-section-row-data-item-id&quot;);
</span><ins>+WebInspector.ChartDetailsSectionRow.LegendItemValueElementSymbol = Symbol(&quot;chart-details-section-row-legend-item-value-element&quot;);
</ins><span class="cx"> 
</span><span class="cx"> WebInspector.ChartDetailsSectionRow.Event = {
</span><span class="cx">     LegendItemChecked: &quot;chart-details-section-row-legend-item-checked&quot;
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceViewsTimelineSidebarPaneljs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Views/TimelineSidebarPanel.js (188915 => 188916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Views/TimelineSidebarPanel.js        2015-08-25 17:36:41 UTC (rev 188915)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/TimelineSidebarPanel.js        2015-08-25 17:55:07 UTC (rev 188916)
</span><span class="lines">@@ -97,6 +97,14 @@
</span><span class="cx">             this._frameSelectionChartRow.innerRadius = 0.5;
</span><span class="cx">             this._frameSelectionChartRow.addEventListener(WebInspector.ChartDetailsSectionRow.Event.LegendItemChecked, this._frameSelectionLegendItemChecked, this);
</span><span class="cx"> 
</span><ins>+            for (let key in WebInspector.RenderingFrameTimelineRecord.TaskType) {
+                let taskType = WebInspector.RenderingFrameTimelineRecord.TaskType[key];
+                let label = WebInspector.RenderingFrameTimelineRecord.displayNameForTaskType(taskType);
+                let color = this._chartColors.get(taskType);
+                let checkbox = taskType !== WebInspector.RenderingFrameTimelineRecord.TaskType.Other;
+                this._frameSelectionChartRow.addItem(taskType, label, 0, color, checkbox, true);
+            }
+
</ins><span class="cx">             this._renderingFrameTaskFilter = new Set;
</span><span class="cx"> 
</span><span class="cx">             var chartGroup = new WebInspector.DetailsSectionGroup([this._frameSelectionChartRow]);
</span><span class="lines">@@ -893,20 +901,13 @@
</span><span class="cx">             return selectedRecords;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        var chart = this._frameSelectionChartRow;
-        var records = getSelectedRecords.call(this);
-        var chartData = Object.keys(WebInspector.RenderingFrameTimelineRecord.TaskType).map(function(taskTypeKey) {
-            let taskType = WebInspector.RenderingFrameTimelineRecord.TaskType[taskTypeKey];
-            let label = WebInspector.RenderingFrameTimelineRecord.displayNameForTaskType(taskType);
</del><ins>+        let records = getSelectedRecords.call(this);
+        for (let key in WebInspector.RenderingFrameTimelineRecord.TaskType) {
+            let taskType = WebInspector.RenderingFrameTimelineRecord.TaskType[key];
</ins><span class="cx">             let value = records.reduce(function(previousValue, currentValue) { return previousValue + currentValue.durationForTask(taskType); }, 0);
</span><del>-            let color = this._chartColors.get(taskType);
-            let checkbox = taskType !== WebInspector.RenderingFrameTimelineRecord.TaskType.Other;
-            let checked = checkbox &amp;&amp; !this._renderingFrameTaskFilter.has(taskType);
-            return {id: taskType, label, value, color, checkbox, checked};
-        }, this);
</del><ins>+            this._frameSelectionChartRow.setItemValue(taskType, value);
+        }
</ins><span class="cx"> 
</span><del>-        this._frameSelectionChartRow.data = chartData;
-
</del><span class="cx">         if (!records.length) {
</span><span class="cx">             this._frameSelectionChartRow.title = WebInspector.UIString(&quot;Frames: None Selected&quot;);
</span><span class="cx">             return;
</span></span></pre>
</div>
</div>

</body>
</html>