Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 function DiffViewController($scope) { | 1 angular.module('diff_viewer', []). |
| 2 config(['$routeProvider', function($routeProvider) { | |
| 3 // Show the list of differences by default | |
| 4 $routeProvider. | |
| 5 otherwise({ templateUrl: '/diff_list.html', controller: DiffListController}) ; | |
| 6 }]). | |
| 7 directive('swapimg', function() { | |
|
djsollen
2013/07/10 14:44:07
swap_img?
Zach Reizner
2013/07/10 15:00:10
underscores and dashes are illegal characters in H
| |
| 8 // Custom directive for showing an image that gets swapped my mouseover. | |
| 9 return { | |
| 10 restrict: 'E', // The directive can be used as an element name | |
| 11 replace: true, // The directive replaces itself with the template | |
| 12 template: '<canvas ng-mouseenter="swap()" ng-mouseleave="swap()"></canva s>', | |
| 13 scope: { // The attributes below are bound to the scope | |
| 14 leftSrc: '@', | |
| 15 rightSrc: '@', | |
| 16 side: '@' | |
| 17 }, | |
| 18 link: function(scope, elm, attrs, ctrl) { | |
| 19 var leftImage = new Image(); | |
| 20 var rightImage = new Image(); | |
| 21 var ctx = elm[0].getContext('2d'); | |
| 22 | |
| 23 scope.render = function() { | |
| 24 var image; | |
| 25 if (scope.side == "left") { | |
| 26 image = leftImage; | |
| 27 } else { | |
| 28 image = rightImage; | |
| 29 } | |
| 30 | |
| 31 // Make it so the maximum size of an image is 500, and the image s are scaled | |
| 32 // down in halves. | |
| 33 var divisor = 1; | |
| 34 while ((image.width / divisor) > 500) { | |
| 35 divisor *= 2; | |
| 36 } | |
| 37 | |
| 38 // Set canvas to correct size and draw the image into it | |
| 39 elm[0].width = image.width / divisor; | |
| 40 elm[0].height = image.height / divisor; | |
| 41 ctx.drawImage(image, 0, 0, elm[0].width, elm[0].height); | |
| 42 }; | |
| 43 | |
| 44 // When the leftSrc attribute changes, load the image and then reren der | |
| 45 attrs.$observe('leftSrc', function(value) { | |
| 46 leftImage.src = value; | |
| 47 leftImage.onload = function() { | |
| 48 if (scope.side == "left") { | |
| 49 scope.render(); | |
| 50 } | |
| 51 }; | |
| 52 }); | |
| 53 | |
| 54 // When the rightSrc attribute changes, load the image and then rere nder | |
| 55 attrs.$observe('rightSrc', function(value) { | |
| 56 rightImage.src = value; | |
| 57 rightImage.onload = function() { | |
| 58 if (scope.side == "right") { | |
| 59 scope.render(); | |
| 60 } | |
| 61 }; | |
| 62 }); | |
| 63 | |
| 64 // Swap which side to draw onto the canvas and then rerender | |
| 65 scope.swap = function() { | |
| 66 if (scope.side == "left") { | |
| 67 scope.side = "right"; | |
| 68 } else { | |
| 69 scope.side = "left"; | |
| 70 } | |
| 71 scope.render(); | |
| 72 }; | |
| 73 } | |
| 74 }; | |
| 75 }); | |
| 76 | |
| 77 function DiffListController($scope) { | |
| 78 // Label each kind of differ for the sort buttons. | |
| 2 $scope.differs = [ | 79 $scope.differs = [ |
| 3 { | 80 { |
| 4 "title": "Different Pixels" | 81 "title": "Different Pixels" |
| 5 }, | 82 }, |
| 6 { | 83 { |
| 7 "title": "Perceptual Difference" | 84 "title": "Perceptual Difference" |
| 8 } | 85 } |
| 9 ]; | 86 ]; |
| 87 | |
| 88 // Puts the records within AngularJS scope | |
| 89 $scope.records = SkPDiffRecords.records; | |
| 90 | |
| 91 // Indicates which diff metric is used for sorting | |
| 10 $scope.sortIndex = 1; | 92 $scope.sortIndex = 1; |
| 11 $scope.records = SkPDiffRecords.records; | 93 |
| 12 $scope.highlight = function(differName) { | 94 // Called by the sort buttons to adjust the metric used for sorting |
| 13 console.debug(differName); | 95 $scope.setSortIndex = function(idx) { |
| 14 } | 96 $scope.sortIndex = idx; |
| 15 $scope.setSortIndex = function(a) { | 97 }; |
| 16 $scope.sortIndex = a; | 98 |
| 17 } | 99 // A predicate for pulling out the number used for sorting |
| 18 $scope.sortingDiffer = function(a) { | 100 $scope.sortingDiffer = function(record) { |
| 19 console.debug($scope.sortIndex); | 101 return record.diffs[$scope.sortIndex].result; |
| 20 return a.diffs[$scope.sortIndex].result; | 102 }; |
| 21 } | 103 } |
| 22 } | |
| OLD | NEW |