depsgraph.html 4.9 KB

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