index.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title>Flot Examples: Navigation</title>
  6. <link href="../examples.css" rel="stylesheet" type="text/css">
  7. <style type="text/css">
  8. #placeholder .button {
  9. position: absolute;
  10. cursor: pointer;
  11. }
  12. #placeholder div.button {
  13. font-size: smaller;
  14. color: #999;
  15. background-color: #eee;
  16. padding: 2px;
  17. }
  18. .message {
  19. padding-left: 50px;
  20. font-size: smaller;
  21. }
  22. </style>
  23. <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../../excanvas.min.js"></script><![endif]-->
  24. <script language="javascript" type="text/javascript" src="../../jquery.js"></script>
  25. <script language="javascript" type="text/javascript" src="../../jquery.flot.js"></script>
  26. <script language="javascript" type="text/javascript" src="../../jquery.flot.navigate.js"></script>
  27. <script type="text/javascript">
  28. $(function() {
  29. // generate data set from a parametric function with a fractal look
  30. function sumf(f, t, m) {
  31. var res = 0;
  32. for (var i = 1; i < m; ++i) {
  33. res += f(i * i * t) / (i * i);
  34. }
  35. return res;
  36. }
  37. var d1 = [];
  38. for (var t = 0; t <= 2 * Math.PI; t += 0.01) {
  39. d1.push([sumf(Math.cos, t, 10), sumf(Math.sin, t, 10)]);
  40. }
  41. var data = [ d1 ],
  42. placeholder = $("#placeholder");
  43. var plot = $.plot(placeholder, data, {
  44. series: {
  45. lines: {
  46. show: true
  47. },
  48. shadowSize: 0
  49. },
  50. xaxis: {
  51. zoomRange: [0.1, 10],
  52. panRange: [-10, 10]
  53. },
  54. yaxis: {
  55. zoomRange: [0.1, 10],
  56. panRange: [-10, 10]
  57. },
  58. zoom: {
  59. interactive: true
  60. },
  61. pan: {
  62. interactive: true
  63. }
  64. });
  65. // show pan/zoom messages to illustrate events
  66. placeholder.bind("plotpan", function (event, plot) {
  67. var axes = plot.getAxes();
  68. $(".message").html("Panning to x: " + axes.xaxis.min.toFixed(2)
  69. + " &ndash; " + axes.xaxis.max.toFixed(2)
  70. + " and y: " + axes.yaxis.min.toFixed(2)
  71. + " &ndash; " + axes.yaxis.max.toFixed(2));
  72. });
  73. placeholder.bind("plotzoom", function (event, plot) {
  74. var axes = plot.getAxes();
  75. $(".message").html("Zooming to x: " + axes.xaxis.min.toFixed(2)
  76. + " &ndash; " + axes.xaxis.max.toFixed(2)
  77. + " and y: " + axes.yaxis.min.toFixed(2)
  78. + " &ndash; " + axes.yaxis.max.toFixed(2));
  79. });
  80. // add zoom out button
  81. $("<div class='button' style='right:20px;top:20px'>zoom out</div>")
  82. .appendTo(placeholder)
  83. .click(function (event) {
  84. event.preventDefault();
  85. plot.zoomOut();
  86. });
  87. // and add panning buttons
  88. // little helper for taking the repetitive work out of placing
  89. // panning arrows
  90. function addArrow(dir, right, top, offset) {
  91. $("<img class='button' src='arrow-" + dir + ".gif' style='right:" + right + "px;top:" + top + "px'>")
  92. .appendTo(placeholder)
  93. .click(function (e) {
  94. e.preventDefault();
  95. plot.pan(offset);
  96. });
  97. }
  98. addArrow("left", 55, 60, { left: -100 });
  99. addArrow("right", 25, 60, { left: 100 });
  100. addArrow("up", 40, 45, { top: -100 });
  101. addArrow("down", 40, 75, { top: 100 });
  102. // Add the Flot version string to the footer
  103. $("#footer").prepend("Flot " + $.plot.version + " &ndash; ");
  104. });
  105. </script>
  106. </head>
  107. <body>
  108. <div id="header">
  109. <h2>Navigation</h2>
  110. </div>
  111. <div id="content">
  112. <div class="demo-container">
  113. <div id="placeholder" class="demo-placeholder"></div>
  114. </div>
  115. <p class="message"></p>
  116. <p>With the navigate plugin it is easy to add panning and zooming. Drag to pan, double click to zoom (or use the mouse scrollwheel).</p>
  117. <p>The plugin fires events (useful for synchronizing several plots) and adds a couple of public methods so you can easily build a little user interface around it, like the little buttons at the top right in the plot.</p>
  118. </div>
  119. <div id="footer">
  120. Copyright &copy; 2007 - 2014 IOLA and Ole Laursen
  121. </div>
  122. </body>
  123. </html>