You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
4.7 KiB

  1. <html>
  2. <head>
  3. <title>Timeline demo</title>
  4. <script type="text/javascript" src="http://www.google.com/jsapi"></script>
  5. <script type="text/javascript" src="../timeline.js"></script>
  6. <link rel="stylesheet" type="text/css" href="../timeline.css">
  7. <style type="text/css">
  8. body {
  9. color: #4D4D4D;
  10. font: 10pt arial;
  11. }
  12. </style>
  13. <script type="text/javascript">
  14. var timeline = null;
  15. var data = null;
  16. var order = 1;
  17. var truck = 1;
  18. google.load("visualization", "1");
  19. // Set callback to run when API is loaded
  20. google.setOnLoadCallback(drawVisualization);
  21. // Called when the Visualization API is loaded.
  22. function drawVisualization() {
  23. // specify options
  24. var options = {
  25. stackEvents: false,
  26. start: new Date(),
  27. end: new Date(1000*60*60*24 + (new Date()).valueOf()),
  28. editable: true,
  29. animate: false,
  30. eventMargin: 10, // minimal margin between events
  31. eventMarginAxis: 5, // minimal margin between events and the axis
  32. showMajorLabels: true,
  33. cluster: true,
  34. axisOnTop: true,
  35. snapEvents: true,
  36. dragAreaWidth: 20
  37. };
  38. // Instantiate our timeline object.
  39. timeline = new links.Timeline(document.getElementById('mytimeline'), options);
  40. // Create and populate a data table.
  41. data = new google.visualization.DataTable();
  42. data.addColumn('datetime', 'start');
  43. data.addColumn('datetime', 'end');
  44. data.addColumn('string', 'content');
  45. data.addColumn('string', 'group');
  46. addData();
  47. // Draw our timeline with the created data and options
  48. timeline.draw(data);
  49. google.visualization.events.addListener(timeline, 'select',
  50. function () {
  51. //console.log('select', timeline.getSelection()[0]);
  52. }
  53. );
  54. google.visualization.events.addListener(timeline, 'edit',
  55. function() {
  56. //console.log('edit')
  57. }
  58. );
  59. google.visualization.events.addListener(timeline, 'change',
  60. function() {
  61. //console.log('change')
  62. //timeline.cancelChange();
  63. }
  64. );
  65. google.visualization.events.addListener(timeline, 'add',
  66. function() {
  67. //console.log('add')
  68. //timeline.cancelAdd();
  69. }
  70. );
  71. /*
  72. console.profile();
  73. var count = 10;
  74. for (var i = 0; i < count; i++) {
  75. timeline.redraw();
  76. }
  77. console.profileEnd();
  78. //*/
  79. }
  80. /**
  81. * Get URL parameter
  82. * http://www.netlobo.com/url_query_string_javascript.html
  83. */
  84. function gup( name ) {
  85. name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  86. var regexS = "[\\?&]"+name+"=([^&#]*)";
  87. var regex = new RegExp( regexS );
  88. var results = regex.exec( window.location.href );
  89. if( results == null )
  90. return "";
  91. else
  92. return results[1];
  93. }
  94. var count = (Number(gup('count')) || 100);
  95. function addData() {
  96. for (var j = 0; j < 4; j++) {
  97. var date = new Date();
  98. for (var i = 0; i < count/4; i++) {
  99. date.setHours(date.getHours() + 4 * (Math.random() < 0.2));
  100. var start = new Date(date);
  101. date.setHours(date.getHours() + 2 + Math.floor(Math.random()*4));
  102. var end = new Date(date);
  103. var orderText = "Order " + order;
  104. var truckText = "Truck " + truck;
  105. data.addRow([start, end, orderText, truckText]);
  106. order++;
  107. }
  108. truck++;
  109. }
  110. }
  111. </script>
  112. </head>
  113. <body onresize="/*timeline.checkResize();*/">
  114. <h1>Timeline grouping performance</h1>
  115. <p>
  116. Choose a number of items:
  117. <a href="?count=20">20</a>,
  118. <a href="?count=100">100</a>,
  119. <a href="?count=1000">1000</a>,
  120. <a href="?count=10000">10000</a>
  121. <p>
  122. <p>
  123. Current number of items: <span id='count'>100</span>
  124. </p>
  125. <div id="mytimeline"></div>
  126. <div id="info"></div>
  127. <script>
  128. document.getElementById('count').innerHTML = count;
  129. </script>
  130. </body>
  131. </html>