A collaboration between Ed Rantanen and myself to provide basic visualization of a trace route in a flexible manner. This should allow the swapping of different graphic libraries such as Graphviz, Flot, etc.

trace.html 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <html>
  3. <head>
  4. <title>Flot Visual</title>
  5. <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="excanvas.min.js"></script><![endif]-->
  6. <script language="javascript" type="text/javascript" src="jquery.min.js"></script>
  7. <script language="javascript" type="text/javascript" src="jquery.flot.min.js"></script>
  8. <script language="javascript" type="text/javascript" src="jquery.flot.resize.min.js"></script>
  9. <script language="javascript" type="text/javascript" src="jquery.flot.selection.min.js"></script>
  10. <script type="text/javascript">
  11. $(function () {
  12. var canvas = $("#canvas");
  13. var marking = "EndersPsyche.com";
  14. ////////////////////////////////////////////////////////////////////////////////
  15. //
  16. // Data sets
  17. //
  18. ////////////////////////////////////////////////////////////////////////////////
  19. var datasets = [];
  20. ////////////////////////////////////////////////////////////////////////////////
  21. //
  22. // Custom options for the Flot canvas
  23. //
  24. ////////////////////////////////////////////////////////////////////////////////
  25. var options = {
  26. series: {
  27. lines: { show: true },
  28. points: { show: true }
  29. },
  30. grid: {
  31. hoverable: true,
  32. clickable: false
  33. },
  34. yaxis: { min: 0 },
  35. xaxis: { tickDecimals: 0 },
  36. selection: { mode: "x" }
  37. };
  38. ////////////////////////////////////////////////////////////////////////////////
  39. //
  40. // Generic method to pull relevant data
  41. //
  42. ////////////////////////////////////////////////////////////////////////////////
  43. function getData(choices) {
  44. return [ datasets ];
  45. }
  46. ////////////////////////////////////////////////////////////////////////////////
  47. //
  48. // Apply the watermark or branding
  49. //
  50. ////////////////////////////////////////////////////////////////////////////////
  51. function applyBrand(left, top, marking) {
  52. canvas.append
  53. (
  54. '<div style="position: absolute;'
  55. + 'left: ' + (left + 30) + 'px;'
  56. + 'top: ' + (top + 10) + 'px;'
  57. + 'color: #000;'
  58. + 'font-variant: small-caps;'
  59. + 'font-weight: bolder;'
  60. + '">'
  61. + marking
  62. + '</div>'
  63. );
  64. }
  65. ////////////////////////////////////////////////////////////////////////////////
  66. //
  67. // Zoom In/Out
  68. // Example from: http://people.iola.dk/olau/flot/examples/selection.html
  69. //
  70. ////////////////////////////////////////////////////////////////////////////////
  71. canvas.bind("plotselected", function (event, ranges) {
  72. var plot = $.plot(canvas, getData(), $.extend(
  73. true,
  74. {},
  75. options,
  76. { xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to } }
  77. )
  78. );
  79. applyBrand(ranges.xaxis.from, ranges.yaxis.from, marking);
  80. });
  81. canvas.dblclick(function () {
  82. plotAccordingToChoices();
  83. return false;
  84. });
  85. ////////////////////////////////////////////////////////////////////////////////
  86. //
  87. // Tooltips
  88. // Example from: http://people.iola.dk/olau/flot/examples/interacting.html
  89. //
  90. ////////////////////////////////////////////////////////////////////////////////
  91. function showTooltip(x, y, contents) {
  92. $('<div id="tooltip">' + contents + '</div>').css( {
  93. position: 'absolute',
  94. display: 'none',
  95. top: y + 5,
  96. left: x + 5,
  97. border: '1px solid #BDEDFF',
  98. padding: '2px',
  99. 'background-color': '#E0FFFF',
  100. opacity: 0.80
  101. }).appendTo("body").fadeIn(200);
  102. }
  103. var previousPoint = null;
  104. canvas.bind("plothover", function (event, pos, item) {
  105. if (item) {
  106. if (previousPoint != item.dataIndex) {
  107. previousPoint = item.dataIndex;
  108. $("#tooltip").remove();
  109. var ttl = item.datapoint[1].toFixed(2);
  110. showTooltip
  111. (
  112. item.pageX,
  113. item.pageY,
  114. "TTL: " + ttl + " ms"
  115. );
  116. }
  117. }
  118. else {
  119. $("#tooltip").remove();
  120. previousPoint = null;
  121. }
  122. });
  123. ////////////////////////////////////////////////////////////////////////////////
  124. //
  125. // Dataset Toggle
  126. // Example from: http://people.iola.dk/olau/flot/examples/turning-series.html
  127. //
  128. ////////////////////////////////////////////////////////////////////////////////
  129. function plotAccordingToChoices() {
  130. var data = getData();
  131. if (data.length > 0) {
  132. var plot = $.plot(canvas, data, options);
  133. applyBrand(0, 0, marking);
  134. }
  135. };
  136. plotAccordingToChoices();
  137. });
  138. </script>
  139. </head>
  140. <body>
  141. <!-- The actual canvas and working area -->
  142. <p>
  143. <div id="canvas" style="width: 50%; height: 50%;"></div>
  144. </p>
  145. </body>
  146. </html>