index.html 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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: Selection and zooming</title>
  6. <link href="../examples.css" rel="stylesheet" type="text/css">
  7. <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../../excanvas.min.js"></script><![endif]-->
  8. <script language="javascript" type="text/javascript" src="../../jquery.js"></script>
  9. <script language="javascript" type="text/javascript" src="../../jquery.flot.js"></script>
  10. <script language="javascript" type="text/javascript" src="../../jquery.flot.selection.js"></script>
  11. <script type="text/javascript">
  12. $(function() {
  13. // setup plot
  14. function getData(x1, x2) {
  15. var d = [];
  16. for (var i = 0; i <= 100; ++i) {
  17. var x = x1 + i * (x2 - x1) / 100;
  18. d.push([x, Math.sin(x * Math.sin(x))]);
  19. }
  20. return [
  21. { label: "sin(x sin(x))", data: d }
  22. ];
  23. }
  24. var options = {
  25. legend: {
  26. show: false
  27. },
  28. series: {
  29. lines: {
  30. show: true
  31. },
  32. points: {
  33. show: true
  34. }
  35. },
  36. yaxis: {
  37. ticks: 10
  38. },
  39. selection: {
  40. mode: "xy"
  41. }
  42. };
  43. var startData = getData(0, 3 * Math.PI);
  44. var plot = $.plot("#placeholder", startData, options);
  45. // Create the overview plot
  46. var overview = $.plot("#overview", startData, {
  47. legend: {
  48. show: false
  49. },
  50. series: {
  51. lines: {
  52. show: true,
  53. lineWidth: 1
  54. },
  55. shadowSize: 0
  56. },
  57. xaxis: {
  58. ticks: 4
  59. },
  60. yaxis: {
  61. ticks: 3,
  62. min: -2,
  63. max: 2
  64. },
  65. grid: {
  66. color: "#999"
  67. },
  68. selection: {
  69. mode: "xy"
  70. }
  71. });
  72. // now connect the two
  73. $("#placeholder").bind("plotselected", function (event, ranges) {
  74. // clamp the zooming to prevent eternal zoom
  75. if (ranges.xaxis.to - ranges.xaxis.from < 0.00001) {
  76. ranges.xaxis.to = ranges.xaxis.from + 0.00001;
  77. }
  78. if (ranges.yaxis.to - ranges.yaxis.from < 0.00001) {
  79. ranges.yaxis.to = ranges.yaxis.from + 0.00001;
  80. }
  81. // do the zooming
  82. plot = $.plot("#placeholder", getData(ranges.xaxis.from, ranges.xaxis.to),
  83. $.extend(true, {}, options, {
  84. xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to },
  85. yaxis: { min: ranges.yaxis.from, max: ranges.yaxis.to }
  86. })
  87. );
  88. // don't fire event on the overview to prevent eternal loop
  89. overview.setSelection(ranges, true);
  90. });
  91. $("#overview").bind("plotselected", function (event, ranges) {
  92. plot.setSelection(ranges);
  93. });
  94. // Add the Flot version string to the footer
  95. $("#footer").prepend("Flot " + $.plot.version + " &ndash; ");
  96. });
  97. </script>
  98. </head>
  99. <body>
  100. <div id="header">
  101. <h2>Selection and zooming</h2>
  102. </div>
  103. <div id="content">
  104. <div class="demo-container">
  105. <div id="placeholder" class="demo-placeholder" style="float:left; width:650px;"></div>
  106. <div id="overview" class="demo-placeholder" style="float:right;width:160px; height:125px;"></div>
  107. </div>
  108. <p>Selection support makes it easy to construct flexible zooming schemes. With a few lines of code, the small overview plot to the right has been connected to the large plot. Try selecting a rectangle on either of them.</p>
  109. </div>
  110. <div id="footer">
  111. Copyright &copy; 2007 - 2013 IOLA and Ole Laursen
  112. </div>
  113. </body>
  114. </html>