results.webkit.org: Add ability to display time on bubbles
https://bugs.webkit.org/show_bug.cgi?id=203202
<rdar://problem/56436621>

Rubber-stamped by Aakash Jain.

* resultsdbpy/resultsdbpy/view/static/js/timeline.js: Add switch to show times under each bubble.
* resultsdbpy/resultsdbpy/view/templates/search.html: Correctly update timeline on callback.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@251401 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Tools/ChangeLog b/Tools/ChangeLog
index 3f574af..9cabe74 100644
--- a/Tools/ChangeLog
+++ b/Tools/ChangeLog
@@ -1,3 +1,14 @@
+2019-10-21  Jonathan Bedard  <jbedard@apple.com>
+
+        results.webkit.org: Add ability to display time on bubbles
+        https://bugs.webkit.org/show_bug.cgi?id=203202
+        <rdar://problem/56436621>
+
+        Rubber-stamped by Aakash Jain.
+
+        * resultsdbpy/resultsdbpy/view/static/js/timeline.js: Add switch to show times under each bubble.
+        * resultsdbpy/resultsdbpy/view/templates/search.html: Correctly update timeline on callback.
+
 2019-10-21  Dean Jackson  <dino@apple.com>
 
         Dispatch AR event on the originating anchor element
diff --git a/Tools/resultsdbpy/resultsdbpy/view/static/js/timeline.js b/Tools/resultsdbpy/resultsdbpy/view/static/js/timeline.js
index 7f0c103a..611bc72 100644
--- a/Tools/resultsdbpy/resultsdbpy/view/static/js/timeline.js
+++ b/Tools/resultsdbpy/resultsdbpy/view/static/js/timeline.js
@@ -34,6 +34,7 @@
 const DEFAULT_LIMIT = 100;
 
 let willFilterExpected = false;
+let showTestTimes = false;
 
 function minimumUuidForResults(results, limit) {
     const now = Math.floor(Date.now() / 10);
@@ -253,6 +254,15 @@
                 return;
             }
 
+            // Some special combination logic
+            if (key === 'time') {
+                out[key] = Math.max(
+                    out[key] ? out[key] : 0,
+                    obj[key] ? obj[key] : 0,
+                );
+                return;
+            }
+
             // If the key exists, but doesn't match, delete it
             if (!(key in obj) || out[key] !== obj[key]) {
                 delete out[key];
@@ -534,6 +544,9 @@
                         }
                     });
                 }
+                const time = data.time ? Math.round(data.time / 1000) : 0;
+                if (time && showTestTimes)
+                    tag = time;
 
                 return drawDot(context, x, y, false, tag ? tag : null, symbol, false, color);
             },
@@ -858,7 +871,7 @@
         </div>`;
 
     if (callback) {
-        const swtch = REF.createRef({
+        const filterSwitch = REF.createRef({
             onElementMount: (element) => {
                 element.onchange = () => {
                     if (element.checked)
@@ -872,14 +885,33 @@
                 };
             },
         });
+        const showTimesSwitch = REF.createRef({
+            onElementMount: (element) => {
+                element.onchange = () => {
+                    if (element.checked)
+                        showTestTimes = true;
+                    else
+                        showTestTimes = false;
+                    callback();
+                };
+            },
+        });
 
         result += `<div class="input">
             <label>Filter expected results</label>
             <label class="switch">
-                <input type="checkbox"${willFilterExpected ? ' checked': ''} ref="${swtch}">
+                <input type="checkbox"${willFilterExpected ? ' checked': ''} ref="${filterSwitch}">
                 <span class="slider"></span>
             </label>
-        </div>`;
+        </div>`
+        if (!plural)
+            result += `<div class="input">
+                <label>Show test times</label>
+                <label class="switch">
+                    <input type="checkbox"${showTestTimes ? ' checked': ''} ref="${showTimesSwitch}">
+                    <span class="slider"></span>
+                </label>
+            </div>`;
     }
 
     return `${result}`;
diff --git a/Tools/resultsdbpy/resultsdbpy/view/templates/search.html b/Tools/resultsdbpy/resultsdbpy/view/templates/search.html
index 6327fb6..f14b469 100644
--- a/Tools/resultsdbpy/resultsdbpy/view/templates/search.html
+++ b/Tools/resultsdbpy/resultsdbpy/view/templates/search.html
@@ -229,7 +229,7 @@
     ${InvestigateDrawer}
     ${Drawer([
         Legend(() => {
-            view.children.forEach((child) => {
+            view.ref.state.children.forEach((child) => {
                 child.timeline.update();
             });
         }, false),