| 1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
| 2 |
"http://www.w3.org/TR/html4/loose.dtd"> |
| 3 |
<html> |
| 4 |
<!-- |
| 5 |
Copyright 2010 The Closure Library Authors. All Rights Reserved. |
| 6 |
|
| 7 |
Use of this source code is governed by the Apache License, Version 2.0. |
| 8 |
See the COPYING file for details. |
| 9 |
--> |
| 10 |
<head> |
| 11 |
<title>Deps Tree</title> |
| 12 |
<script type="text/javascript" src="../base.js"></script> |
| 13 |
<script type="text/javascript"> |
| 14 |
goog.require('goog.object'); |
| 15 |
goog.require('goog.array'); |
| 16 |
goog.require('goog.debug'); |
| 17 |
goog.require('goog.events'); |
| 18 |
</script> |
| 19 |
<style type="text/css"> |
| 20 |
|
| 21 |
h1 { |
| 22 |
font: bold 24px verdana,sans-serif; |
| 23 |
margin: 0px; |
| 24 |
margin-bottom: 14px; |
| 25 |
} |
| 26 |
|
| 27 |
div { |
| 28 |
position: relative; |
| 29 |
font: normal 9px verdana,sans-serif; |
| 30 |
padding: 3px; |
| 31 |
margin: 5px; |
| 32 |
background-color: #EEE; |
| 33 |
border: 1px solid #999; |
| 34 |
cursor: pointer; |
| 35 |
color: #333; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
div.hover { |
| 40 |
background-color: #EE6; |
| 41 |
border: 1px solid #990; |
| 42 |
color: #000; |
| 43 |
} |
| 44 |
|
| 45 |
div.hilite { |
| 46 |
background-color: #AFA; |
| 47 |
border: 1px solid #090; |
| 48 |
} |
| 49 |
|
| 50 |
div.infile { |
| 51 |
background-color: #FFA; |
| 52 |
border: 1px solid #990; |
| 53 |
} |
| 54 |
|
| 55 |
div.required { |
| 56 |
background-color: #FAA; |
| 57 |
border: 1px solid #900; |
| 58 |
} |
| 59 |
|
| 60 |
</style> |
| 61 |
</head> |
| 62 |
<body> |
| 63 |
<h1>Closure Dependency Graph</h1> |
| 64 |
<script type="text/javascript"> |
| 65 |
|
| 66 |
// HackHack |
| 67 |
// Hacked together quickly to provide a quick visible analysis. Not meant to be |
| 68 |
// a complete or long lived tool. |
| 69 |
|
| 70 |
var levels = []; |
| 71 |
var visited = []; |
| 72 |
|
| 73 |
var change = true; |
| 74 |
var i = 0; |
| 75 |
while (change) { |
| 76 |
change = false; |
| 77 |
levels[i] = []; |
| 78 |
var newVisited = goog.array.clone(visited); |
| 79 |
goog.object.forEach(goog.dependencies_.nameToPath, function(path, ns) { |
| 80 |
var deps = goog.object.clone(goog.dependencies_.requires[path]); |
| 81 |
goog.array.forEach(newVisited, function(value) { |
| 82 |
goog.object.remove(deps, value); |
| 83 |
}); |
| 84 |
|
| 85 |
if (goog.object.getCount(deps) == 0 && !goog.object.contains(visited, ns)) { |
| 86 |
change = true; |
| 87 |
levels[i].push(ns); |
| 88 |
visited.push(ns); |
| 89 |
} |
| 90 |
}); |
| 91 |
i++; |
| 92 |
} |
| 93 |
|
| 94 |
var errors = []; |
| 95 |
goog.object.forEach(goog.dependencies_.nameToPath, function(path, ns) { |
| 96 |
if (!goog.array.contains(visited, ns)) { |
| 97 |
errors.push(ns); |
| 98 |
} |
| 99 |
}); |
| 100 |
if (errors.length > 0) { |
| 101 |
alert('The following files were not added to dependency graph: \n' + |
| 102 |
errors.join('\n')); |
| 103 |
} |
| 104 |
|
| 105 |
document.write('<table><tr>') |
| 106 |
goog.array.forEach(levels, function(level) { |
| 107 |
document.write('<td>'); |
| 108 |
goog.array.forEach(level, function(ns) { |
| 109 |
document.write( |
| 110 |
goog.getMsg('<div id="{$ns}" class="dep">{$ns}</div>', {ns:ns})); |
| 111 |
}); |
| 112 |
}); |
| 113 |
document.write('</tr></table>') |
| 114 |
|
| 115 |
|
| 116 |
var currentTarget = null; |
| 117 |
var hilited = []; |
| 118 |
var required = []; |
| 119 |
var infile = []; |
| 120 |
goog.events.listen(document, 'mouseover', handleMouse); |
| 121 |
goog.events.listen(document, 'keydown', handleKeys); |
| 122 |
|
| 123 |
|
| 124 |
function handleMouse(e) { |
| 125 |
highlightElement(e.target); |
| 126 |
} |
| 127 |
|
| 128 |
function handleKeys(e) { |
| 129 |
if (currentTarget) { |
| 130 |
switch (e.keyCode) { |
| 131 |
case 40: |
| 132 |
highlightElement(currentTarget.nextSibling); |
| 133 |
break; |
| 134 |
|
| 135 |
case 38: |
| 136 |
highlightElement(currentTarget.previousSibling); |
| 137 |
break; |
| 138 |
|
| 139 |
case 39: |
| 140 |
// right |
| 141 |
break; |
| 142 |
|
| 143 |
case 37: |
| 144 |
// left |
| 145 |
break; |
| 146 |
|
| 147 |
default: |
| 148 |
return; |
| 149 |
} |
| 150 |
e.preventDefault(); |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
function highlightElement(el) { |
| 156 |
if (el && el.id) { |
| 157 |
|
| 158 |
goog.array.forEach(hilited.concat(required).concat(infile), function(ns) { |
| 159 |
document.getElementById(ns).className = 'dep'; |
| 160 |
}); |
| 161 |
hilited.length = 0; |
| 162 |
required.length = 0; |
| 163 |
infile.length = 0; |
| 164 |
|
| 165 |
if (currentTarget) { |
| 166 |
currentTarget.className = 'dep'; |
| 167 |
} |
| 168 |
|
| 169 |
highlightDeps(el.id); |
| 170 |
highlightRequired(el.id); |
| 171 |
highlightFile(el.id); |
| 172 |
|
| 173 |
el.className = 'dep hover'; |
| 174 |
currentTarget = el; |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
function highlightFile(ns) { |
| 179 |
var names = goog.dependencies_.pathToNames[goog.dependencies_.nameToPath[ns]]; |
| 180 |
goog.object.forEach(names, function(value, name) { |
| 181 |
document.getElementById(name).className = 'dep infile'; |
| 182 |
infile.push(name); |
| 183 |
}); |
| 184 |
} |
| 185 |
|
| 186 |
function highlightRequired(ns) { |
| 187 |
goog.object.forEach(goog.dependencies_.requires, function(value, key) { |
| 188 |
if (goog.object.containsKey(value, ns)) { |
| 189 |
var names = goog.dependencies_.pathToNames[key]; |
| 190 |
goog.object.forEach(names, function(val, id) { |
| 191 |
if (!goog.array.contains(required, id)) { |
| 192 |
document.getElementById(id).className = 'dep required'; |
| 193 |
required.push(id); |
| 194 |
highlightRequired(id); |
| 195 |
} |
| 196 |
}); |
| 197 |
} |
| 198 |
}); |
| 199 |
} |
| 200 |
|
| 201 |
function highlightDeps(ns) { |
| 202 |
var deps = goog.dependencies_.requires[goog.dependencies_.nameToPath[ns]]; |
| 203 |
goog.object.forEach(deps, function(value, key) { |
| 204 |
if (!goog.array.contains(hilited, key)) { |
| 205 |
document.getElementById(key).className = 'dep hilite'; |
| 206 |
hilited.push(key); |
| 207 |
highlightDeps(key); |
| 208 |
} |
| 209 |
}); |
| 210 |
} |
| 211 |
|
| 212 |
</script> |
| 213 |
|
| 214 |
|
| 215 |
<div class="hover">selected item</div> |
| 216 |
<div class="infile">...is in same file as the selected item</div> |
| 217 |
<div class="hilite">...is a dependency of the selected item</div> |
| 218 |
<div class="required">the selected item is a dependency of...</div> |
| 219 |
</body> |
| 220 |
</html> |