From cb535f1cee27ebe0b57a891beb372f8f637a4a7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20M=C3=A9tais?= Date: Fri, 27 Feb 2015 17:41:54 +0100 Subject: [PATCH] Scroll to the profiler on timeline click --- front/src/css/timeline.css | 12 +++++++ front/src/js/app.js | 1 + front/src/js/controllers/timelineCtrl.js | 44 ++++++++++++++++++++++-- front/src/less/timeline.less | 17 +++++++++ front/src/main.html | 1 + front/src/views/timeline.html | 8 +++-- 6 files changed, 77 insertions(+), 6 deletions(-) diff --git a/front/src/css/timeline.css b/front/src/css/timeline.css index 53d22e9..bdc8a9d 100644 --- a/front/src/css/timeline.css +++ b/front/src/css/timeline.css @@ -39,6 +39,9 @@ bottom: 0; width: 100%; } +.timeline .interval .color.clickable { + cursor: pointer; +} .timeline div.interval:hover { background: #9C4274; } @@ -171,6 +174,15 @@ input.textFilter { .table > div.showingDetails > div { background: #f1c40f; } +.table > div.highlight > div.startTime { + background-color: #C0F090; +} +.table > div.highlight-remove { + transition: 3s; +} +.table > div.highlight-remove > div.startTime { + transition: background-color 3s ease-in; +} .table > div > .index { color: #bbb; } diff --git a/front/src/js/app.js b/front/src/js/app.js index 923e474..8a601df 100644 --- a/front/src/js/app.js +++ b/front/src/js/app.js @@ -1,6 +1,7 @@ var yltApp = angular.module('YellowLabTools', [ 'ngRoute', 'ngSanitize', + 'ngAnimate', 'indexCtrl', 'dashboardCtrl', 'queueCtrl', diff --git a/front/src/js/controllers/timelineCtrl.js b/front/src/js/controllers/timelineCtrl.js index 6ea6a0c..06ad191 100644 --- a/front/src/js/controllers/timelineCtrl.js +++ b/front/src/js/controllers/timelineCtrl.js @@ -1,6 +1,6 @@ var timelineCtrl = angular.module('timelineCtrl', []); -timelineCtrl.controller('TimelineCtrl', ['$scope', '$rootScope', '$routeParams', '$location', '$timeout', 'Menu', 'Results', 'API', function($scope, $rootScope, $routeParams, $location, $timeout, Menu, Results, API) { +timelineCtrl.controller('TimelineCtrl', ['$scope', '$rootScope', '$routeParams', '$location', '$anchorScroll', '$timeout', 'Menu', 'Results', 'API', function($scope, $rootScope, $routeParams, $location, $anchorScroll, $timeout, Menu, Results, API) { $scope.runId = $routeParams.runId; $scope.Menu = Menu.setCurrentPage('timeline', $scope.runId); @@ -106,8 +106,22 @@ timelineCtrl.controller('TimelineCtrl', ['$scope', '$rootScope', '$routeParams', return out; } - $scope.filter = function(textFilter, scriptName) { + $scope.findLineIndexByTimestamp = function(timestamp) { + var lineIndex = 0; + for (var i = 0; i < $scope.executionTree.length; i ++) { + var delta = $scope.executionTree[i].data.timestamp - timestamp; + + if (delta < $scope.timelineIntervalDuration) { + lineIndex = i; + } + + if (delta > 0) { + break; + } + } + + return lineIndex; }; $scope.onNodeDetailsClick = function(node) { @@ -137,4 +151,28 @@ timelineCtrl.controller('TimelineCtrl', ['$scope', '$rootScope', '$routeParams', loadResults(); -}]); \ No newline at end of file +}]); + +timelineCtrl.directive('scrollOnClick', ['$animate', '$timeout', function($animate, $timeout) { + return { + restrict: 'A', + link: function (scope, element, attributes) { + // When the user clicks on the timeline, find the right profiler line and scroll to it + element.on('click', function() { + var lineIndex = scope.findLineIndexByTimestamp(attributes.scrollOnClick); + var lineElement = angular.element(document.getElementById('line_' + lineIndex)); + + // Animate the background color to "flash" the row + lineElement.addClass('highlight'); + $timeout(function() { + $animate.removeClass(lineElement, 'highlight'); + scope.$digest(); + }, 50); + + + window.scrollTo(0, lineElement[0].offsetTop); + console.log(lineElement[0]); + }); + } + }; +}]); diff --git a/front/src/less/timeline.less b/front/src/less/timeline.less index 1f189fc..8a61949 100644 --- a/front/src/less/timeline.less +++ b/front/src/less/timeline.less @@ -49,6 +49,10 @@ position: absolute; bottom: 0; width: 100%; + + &.clickable { + cursor: pointer; + } } .timeline div.interval:hover { background: #9C4274; @@ -189,6 +193,19 @@ input.textFilter { background: #f1c40f; } +.table > div.highlight { + > div.startTime { + background-color: #C0F090; + } +} +.table > div.highlight-remove { + transition: 3s; + + > div.startTime { + transition: background-color 3s ease-in; + } +} + .table > div > .index { color: #bbb; } diff --git a/front/src/main.html b/front/src/main.html index 083d943..ccc57e7 100644 --- a/front/src/main.html +++ b/front/src/main.html @@ -23,6 +23,7 @@ + diff --git a/front/src/views/timeline.html b/front/src/views/timeline.html index 33bbedd..55c5fb8 100644 --- a/front/src/views/timeline.html +++ b/front/src/views/timeline.html @@ -18,9 +18,11 @@ && $index * timelineIntervalDuration < result.toolsResults.phantomas.metrics.domComplete, domComplete: $index * timelineIntervalDuration >= result.toolsResults.phantomas.metrics.domComplete }"> -
+
-
Timestamp: {{$index * timelineIntervalDuration | number: 0}} ms
+
+ Timestamp: {{$index * timelineIntervalDuration | number: 0}} ms +
@@ -75,7 +77,7 @@ showingDetails: node.showDetails, jsError: node.error, windowPerformance: node.windowPerformance - }"> + }" id="line_{{$index}}">
{{$index + 1}}