Advertisement
Guest User

Bizarre JavaScript Bug

a guest
Jul 1st, 2012
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.19 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  2. <html>
  3.  
  4. <head>
  5. <title>Cytoscape Web example</title>
  6.  
  7. <script type="text/javascript" src="js/min/json2.min.js"></script>
  8. <script type="text/javascript" src="js/min/AC_OETags.min.js"></script>
  9. <script type="text/javascript" src="js/min/cytoscapeweb.min.js"></script>
  10.  
  11. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
  12.  
  13. <script type="text/javascript">
  14.  
  15. // These two topmost functions are the only ones that I wrote, the rest is copied from the Cytoscape tutorial
  16.  
  17. function get_filename()
  18. {
  19.  
  20. // Dirty trick, will be replaced in next version
  21.  
  22. var output = false;
  23.  
  24. var url = document.location;
  25. url = url.toString();
  26. url = url.split("?");
  27.  
  28. if (url.length > 1)
  29.  
  30. { output = url[1]; }
  31.  
  32. else
  33.  
  34. { output = "xml/example.xml"; }
  35.  
  36. return output;
  37.  
  38. }
  39.  
  40. function get_network(filename)
  41. {
  42.  
  43. var output = "";
  44.  
  45. $.ajax({url: filename, type: "GET", dataType: "text", success: function(result) { output = result; } });
  46.  
  47. alert("ASDFSADF");
  48.  
  49. return output;
  50.  
  51. }
  52.  
  53. window.onload = function() {
  54. // id of Cytoscape Web container div
  55. var div_id = "cytoscapeweb";
  56.  
  57. // NOTE: - the attributes on nodes and edges
  58. // - it also has directed edges, which will automatically display edge arrows
  59.  
  60. var xml = get_network(get_filename());
  61.  
  62. function rand_color() {
  63. function rand_channel() {
  64. return Math.round( Math.random() * 255 );
  65. }
  66.  
  67. function hex_string(num) {
  68. var ret = num.toString(16);
  69.  
  70. if (ret.length < 2) {
  71. return "0" + ret;
  72. } else {
  73. return ret;
  74. }
  75. }
  76.  
  77. var r = rand_channel();
  78. var g = rand_channel();
  79. var b = rand_channel();
  80.  
  81. return "#" + hex_string(r) + hex_string(g) + hex_string(b);
  82. }
  83.  
  84. // visual style we will use
  85. var visual_style = {
  86. global: {
  87. backgroundColor: "#ABCFD6"
  88. },
  89. nodes: {
  90. shape: "OCTAGON",
  91. borderWidth: 3,
  92. borderColor: "#ffffff",
  93. size: {
  94. defaultValue: 25,
  95. continuousMapper: { attrName: "weight", minValue: 25, maxValue: 75 }
  96. },
  97. color: {
  98. discreteMapper: {
  99. attrName: "id",
  100. entries: [
  101. { attrValue: 1, value: "#0B94B1" },
  102. { attrValue: 2, value: "#9A0B0B" },
  103. { attrValue: 3, value: "#dddd00" }
  104. ]
  105. }
  106. },
  107. labelHorizontalAnchor: "center"
  108. },
  109. edges: {
  110. width: 3,
  111. color: "#0B94B1"
  112. }
  113. };
  114.  
  115. // initialization options
  116. var options = {
  117. swfPath: "swf/CytoscapeWeb",
  118. flashInstallerPath: "swf/playerProductInstall"
  119. };
  120.  
  121. var vis = new org.cytoscapeweb.Visualization(div_id, options);
  122.  
  123. vis.ready(function() {
  124. // set the style programmatically
  125. document.getElementById("color").onclick = function(){
  126. visual_style.global.backgroundColor = rand_color();
  127. vis.visualStyle(visual_style);
  128. };
  129. });
  130.  
  131. var draw_options = {
  132. // your data goes here
  133. network: xml,
  134.  
  135. // show edge labels too
  136. edgeLabelsVisible: true,
  137.  
  138. // let's try another layout
  139. layout: "Tree",
  140.  
  141. // set the style at initialisation
  142. visualStyle: visual_style,
  143.  
  144. // hide pan zoom
  145. panZoomControlVisible: false
  146. };
  147.  
  148. vis.draw(draw_options);
  149. };
  150. </script>
  151.  
  152. <style>
  153. * { margin: 0; padding: 0; font-family: Helvetica, Arial, Verdana, sans-serif; }
  154. html, body { height: 100%; width: 100%; padding: 0; margin: 0; background-color: #f0f0f0; }
  155. body { line-height: 1.5; color: #000000; font-size: 14px; }
  156. /* The Cytoscape Web container must have its dimensions set. */
  157. #cytoscapeweb { width: 100%; height: 80%; }
  158. #note { width: 100%; text-align: center; padding-top: 1em; }
  159. .link { text-decoration: underline; color: #0b94b1; cursor: pointer; }
  160. </style>
  161. </head>
  162.  
  163. <body>
  164. <div id="cytoscapeweb">
  165. Cytoscape Web will replace the contents of this div with your graph.
  166. </div>
  167. <div id="note">
  168. <span class="link" id="color">Color me surprised</span>
  169. </div>
  170. </body>
  171.  
  172. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement