index.html 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. <script language="javascript" type="text/javascript" src="../../source/jquery.js"></script>
  24. <script language="javascript" type="text/javascript" src="../../lib/jquery.event.drag.js"></script>
  25. <script language="javascript" type="text/javascript" src="../../lib/jquery.mousewheel.js"></script>
  26. <script language="javascript" type="text/javascript" src="../../source/jquery.canvaswrapper.js"></script>
  27. <script language="javascript" type="text/javascript" src="../../source/jquery.colorhelpers.js"></script>
  28. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.js"></script>
  29. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.saturated.js"></script>
  30. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.browser.js"></script>
  31. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.drawSeries.js"></script>
  32. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.errorbars.js"></script>
  33. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.uiConstants.js"></script>
  34. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.logaxis.js"></script>
  35. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.symbol.js"></script>
  36. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.flatdata.js"></script>
  37. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.navigate.js"></script>
  38. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.fillbetween.js"></script>
  39. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.stack.js"></script>
  40. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.touchNavigate.js"></script>
  41. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.hover.js"></script>
  42. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.touch.js"></script>
  43. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.time.js"></script>
  44. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.axislabels.js"></script>
  45. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.selection.js"></script>
  46. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.composeImages.js"></script>
  47. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.legend.js"></script>
  48. <script type="text/javascript">
  49. $(function() {
  50. function sumf(f, t, m) {
  51. var res = 0;
  52. for (var i = 1; i < m; ++i) {
  53. res += f(i * i * t) / (i * i);
  54. }
  55. return res;
  56. }
  57. function panMessage(placeholder) {
  58. placeholder.bind("plotpan", function (event, plot) {
  59. var axes = plot.getAxes();
  60. $(".message").html("Panning to x: " + axes.xaxis.min.toFixed(2)
  61. + " &ndash; " + axes.xaxis.max.toFixed(2)
  62. + " and y: " + axes.yaxis.min.toFixed(2)
  63. + " &ndash; " + axes.yaxis.max.toFixed(2));
  64. });
  65. }
  66. function zoomMessage(placeholder) {
  67. placeholder.bind("plotzoom", function (event, plot) {
  68. var axes = plot.getAxes();
  69. $(".message").html("Zooming to x: " + axes.xaxis.min.toFixed(2)
  70. + " &ndash; " + axes.xaxis.max.toFixed(2)
  71. + " and y: " + axes.yaxis.min.toFixed(2)
  72. + " &ndash; " + axes.yaxis.max.toFixed(2));
  73. });
  74. }
  75. var d0 = [];
  76. for (var t = 0; t <= 2 * Math.PI; t += 0.01) {
  77. d0.push([sumf(Math.cos, t, 10), sumf(Math.sin, t, 10)]);
  78. }
  79. var data = [d0],
  80. placeholder = $("#placeholder"),
  81. plot = $.plot(placeholder, data, {
  82. series: {
  83. lines: {
  84. show: true
  85. },
  86. shadowSize: 0
  87. },
  88. xaxis: {
  89. zoomRange: [0.1, 10],
  90. panRange: [-10, 10],
  91. gridLines: true,
  92. autoScale: 'exact'
  93. },
  94. yaxis: {
  95. zoomRange: [0.1, 10],
  96. panRange: [-10, 10],
  97. gridLines: true,
  98. autoScale: 'exact'
  99. },
  100. zoom: {
  101. interactive: true,
  102. enableTouch: true
  103. },
  104. pan: {
  105. interactive: true,
  106. enableTouch: true
  107. }
  108. });
  109. function piTickGenerator(axis) {
  110. var res = [],
  111. i = Math.floor(axis.min / Math.PI);
  112. do {
  113. var v = i * Math.PI;
  114. res.push([v, i + "\u03c0"]);
  115. ++i;
  116. } while (v < axis.max);
  117. return res;
  118. }
  119. var d1 = [],
  120. d2 = [[0.1, 3], [4, 8], [8, 5], [9, 13]],
  121. d3 = [[0.1, 12], [5, 5], null, [9, 2.5], [12, 5]],
  122. d4 = [];
  123. for (var i = 0; i < 14; i += 0.2) {
  124. d1.push([i, (10 + Math.sin(i))]);
  125. }
  126. for (var i = 0; i < 14; i += 0.5) {
  127. d4.push([i, 1000 + 300 * Math.sin(i)]);
  128. }
  129. var placeholder2 = $("#placeholder2"),
  130. plot2 = $.plot(placeholder2, [ { data: d4, label: "a", xaxis: 1, yaxis: 1 },
  131. { data: d1, label: "b", xaxis: 2, yaxis: 2 } ], {
  132. series: {
  133. lines: {
  134. show: true
  135. },
  136. points: {
  137. show: true
  138. }
  139. },
  140. xaxes: [ {autoScale: 'exact'}, {autoScale: 'exact'} ],
  141. yaxes: [ { mode: 'log', showTickLabels: 'all', autoScale: 'exact'},
  142. { mode: 'log', showTickLabels: 'all', autoScale: 'exact'} ],
  143. zoom: {
  144. interactive: true,
  145. enableTouch: true
  146. },
  147. pan: {
  148. interactive: true,
  149. enableTouch: true
  150. }
  151. });
  152. panMessage(placeholder);
  153. zoomMessage(placeholder);
  154. panMessage(placeholder2);
  155. zoomMessage(placeholder2);
  156. // Add the Flot version string to the footer
  157. $("#footer").prepend("Flot " + $.plot.version + " &ndash; ");
  158. });
  159. </script>
  160. </head>
  161. <body>
  162. <div id="header">
  163. <h2>Navigation</h2>
  164. </div>
  165. <div id="content">
  166. <div class="demo-container">
  167. <div id="placeholder" class="demo-placeholder"></div>
  168. </div>
  169. <div class="demo-container">
  170. <div id="placeholder2" class="demo-placeholder"></div>
  171. </div>
  172. <p class="message"></p>
  173. <p>With the navigateTouch plugin it is easy to add panning and zooming. Drag to pan with one or two fingers, pinch to zoom.</p>
  174. <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>
  175. </div>
  176. <div id="footer">
  177. Copyright &copy; 2007 - 2014 IOLA and Ole Laursen
  178. </div>
  179. </body>
  180. </html>