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.

145 lines
4.9 KiB

  1. <html>
  2. <head>
  3. <title>Timeline demo</title>
  4. <script type="text/javascript" src="../timeline.js"></script>
  5. <link rel="stylesheet" type="text/css" href="../timeline.css">
  6. <style type="text/css">
  7. body {font: 10pt arial;}
  8. div.timeline-event {
  9. border: none;
  10. background: none;
  11. border-radius: 0;
  12. }
  13. div.timeline-event-selected {
  14. border: none;
  15. background: none;
  16. }
  17. div.timeline-event-content {
  18. margin: 0;
  19. }
  20. div.timeline-event-range {
  21. border: none;
  22. border-radius: 0;
  23. height: 100px;
  24. width: 100%;
  25. position: relative;
  26. overflow: visible;
  27. }
  28. div.bar {
  29. position: absolute;
  30. bottom: 0;
  31. left: 0;
  32. width: 100%;
  33. text-align: center;
  34. color: white;
  35. /* height and color is set for each individual bar */
  36. }
  37. div.requirement {
  38. position: absolute;
  39. bottom: 0;
  40. left: 0;
  41. width: 100%;
  42. border-top: 2px solid gray;
  43. background: #e5e5e5;
  44. opacity: 0.5;
  45. }
  46. </style>
  47. <script type="text/javascript">
  48. var timeline;
  49. /**
  50. * Calculate the color based on the given value.
  51. * @param {number} H Hue, a value be between 0 and 360
  52. * @param {number} S Saturation, a value between 0 and 1
  53. * @param {number} V Value, a value between 0 and 1
  54. */
  55. var hsv2rgb = function(H, S, V) {
  56. var R, G, B, C, Hi, X;
  57. C = V * S;
  58. Hi = Math.floor(H/60); // hi = 0,1,2,3,4,5
  59. X = C * (1 - Math.abs(((H/60) % 2) - 1));
  60. switch (Hi) {
  61. case 0: R = C; G = X; B = 0; break;
  62. case 1: R = X; G = C; B = 0; break;
  63. case 2: R = 0; G = C; B = X; break;
  64. case 3: R = 0; G = X; B = C; break;
  65. case 4: R = X; G = 0; B = C; break;
  66. case 5: R = C; G = 0; B = X; break;
  67. default: R = 0; G = 0; B = 0; break;
  68. }
  69. return "RGB(" + parseInt(R*255) + "," + parseInt(G*255) + "," + parseInt(B*255) + ")";
  70. };
  71. // Called when the Visualization API is loaded.
  72. function drawVisualization() {
  73. // Create and populate a data table.
  74. var data = [];
  75. var maxNum = 20;
  76. var d = new Date(2012, 6, 5);
  77. for (var i = 0; i < 20; i++) {
  78. var hours = Math.round(1 + Math.random() * 7);
  79. var start = new Date(d);
  80. var end = new Date(d);
  81. end.setHours(end.getHours() + hours);
  82. // create item with minimum requirement
  83. var num = Math.round(Math.random() * maxNum); // number of members available
  84. var height = Math.round(num / maxNum * 80 + 20); // a percentage, with a lower bound on 20%
  85. var style = 'height:' + height + 'px;';
  86. var requirement = '<div class="requirement" style="' + style + '" ' +
  87. 'title="Minimum requirement: ' + num + ' people"></div>';
  88. // create item with actual number
  89. num = Math.round(Math.random() * maxNum); // number of members available
  90. height = Math.round(num / maxNum * 70 + 20); // a percentage, with a lower bound on 20%
  91. var hue = Math.min(Math.max(height, 20), 80) * 1.2; // hue between 0 (red) and 120 (green)
  92. var color = hsv2rgb(hue, 0.95, 0.95);
  93. var borderColor = hsv2rgb(hue, 0.9, 0.9);
  94. style = 'height:' + height + 'px;' +
  95. 'background-color: ' + color + ';' +
  96. 'border-top: 2px solid ' + borderColor + ';';
  97. var actual = '<div class="bar" style="' + style + '" ' +
  98. ' title="Actual: ' + num + ' people">' + num + '</div>';
  99. var item = {
  100. 'group': 'Team',
  101. 'start': start,
  102. 'end': end,
  103. 'content': requirement + actual
  104. };
  105. data.push(item);
  106. d = new Date(end);
  107. }
  108. // specify options
  109. var options = {
  110. "width": "100%",
  111. "height": "300px",
  112. "style": "box",
  113. "stackEvents": false
  114. };
  115. // Instantiate our timeline object.
  116. timeline = new links.Timeline(document.getElementById('mytimeline'), options);
  117. // Draw our timeline with the created data and options
  118. timeline.draw(data);
  119. }
  120. </script>
  121. </head>
  122. <body onload="drawVisualization();">
  123. <h1>Timeline - Bar Graph Example</h1>
  124. <div id="mytimeline"></div>
  125. </body>
  126. </html>