example16_performance_grouping.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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>
  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. // Instantiate our timeline object.
  24. timeline = new links.Timeline(document.getElementById('mytimeline'));
  25. // Create and populate a data table.
  26. data = new google.visualization.DataTable();
  27. data.addColumn('datetime', 'start');
  28. data.addColumn('datetime', 'end');
  29. data.addColumn('string', 'content');
  30. data.addColumn('string', 'group');
  31. addData();
  32. // specify options
  33. options = {
  34. //width: "100%",
  35. //height: "auto",
  36. //minHeight: 50, // pixels
  37. //height: "300px",
  38. //layout: "box",
  39. start: new Date(),
  40. end: new Date(1000*60*60*24 + (new Date()).valueOf()),
  41. editable: true,
  42. animate: false,
  43. eventMargin: 10, // minimal margin between events
  44. eventMarginAxis: 5, // minimal margin beteen events and the axis
  45. showMajorLabels: true,
  46. showCustomTime: true,
  47. showNavigation: true,
  48. axisOnTop: true,
  49. snapEvents: true,
  50. dragAreaWidth: 20,
  51. //groupsWidth : "100px",
  52. groupsOnRight: false
  53. };
  54. // Draw our timeline with the created data and options
  55. timeline.draw(data, options);
  56. google.visualization.events.addListener(timeline, 'select',
  57. function () {
  58. //console.log('select', timeline.getSelection()[0]);
  59. }
  60. );
  61. google.visualization.events.addListener(timeline, 'edit',
  62. function() {
  63. //console.log('edit')
  64. }
  65. );
  66. google.visualization.events.addListener(timeline, 'change',
  67. function() {
  68. //console.log('change')
  69. //timeline.cancelChange();
  70. }
  71. );
  72. google.visualization.events.addListener(timeline, 'add',
  73. function() {
  74. //console.log('add')
  75. //timeline.cancelAdd();
  76. }
  77. );
  78. /*
  79. console.profile();
  80. var count = 10;
  81. for (var i = 0; i < count; i++) {
  82. timeline.redraw();
  83. }
  84. console.profileEnd();
  85. //*/
  86. }
  87. /**
  88. * Get URL parameter
  89. * http://www.netlobo.com/url_query_string_javascript.html
  90. */
  91. function gup( name ) {
  92. name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  93. var regexS = "[\\?&]"+name+"=([^&#]*)";
  94. var regex = new RegExp( regexS );
  95. var results = regex.exec( window.location.href );
  96. if( results == null )
  97. return "";
  98. else
  99. return results[1];
  100. }
  101. var count = (Number(gup('count')) || 100);
  102. function addData() {
  103. for (var j = 0; j < 4; j++) {
  104. var date = new Date();
  105. for (var i = 0; i < count/4; i++) {
  106. date.setHours(date.getHours() + 1 * 4 * (Math.random() < 0.2));
  107. var start = new Date(date);
  108. date.setHours(date.getHours() + 2 + Math.floor(Math.random()*4));
  109. var end = new Date(date);
  110. var orderText = "Order " + order;
  111. var truckText = "Truck " + truck;
  112. data.addRow([start, end, orderText, truckText]);
  113. order++;
  114. }
  115. truck++;
  116. }
  117. }
  118. </script>
  119. </head>
  120. <body onresize="/*timeline.checkResize();*/">
  121. <h1>Timeline grouping performance</h1>
  122. <p>
  123. Choose a number of items:
  124. <a href="?count=20">20</a>,
  125. <a href="?count=100">100</a>,
  126. <a href="?count=1000">1000</a>,
  127. <a href="?count=10000">10000</a>
  128. <p>
  129. <p>
  130. Current number of items: <span id='count'>100</span>
  131. </p>
  132. <div id="mytimeline"></div>
  133. <div id="info"></div>
  134. <script>
  135. document.getElementById('count').innerHTML = count;
  136. </script>
  137. </body>
  138. </html>