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.

174 lines
6.8 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 {font: 11pt arial;}
  9. input {font: 11pt arial;}
  10. div.myParagraph {
  11. width: 200px;
  12. white-space: normal;
  13. }
  14. </style>
  15. <script type="text/javascript">
  16. google.load("visualization", "1");
  17. // Set callback to run when API is loaded
  18. google.setOnLoadCallback(drawVisualization);
  19. var timeline;
  20. var data;
  21. // Called when the timelineualization API is loaded.
  22. function drawVisualization() {
  23. // Create and populate a data table.
  24. data = new google.visualization.DataTable();
  25. data.addColumn('datetime', 'start');
  26. data.addColumn('datetime', 'end');
  27. data.addColumn('string', 'content');
  28. function addRow(startDate, endDate, content, backgroundColor, borderColor)
  29. {
  30. // we make our own customized layout for the events
  31. if (backgroundColor == undefined)
  32. backgroundColor = "yellow";
  33. if (borderColor == undefined)
  34. borderColor = "gold";
  35. var fill = endDate ? "pink" : "yellow";
  36. var div = '<div style="background-color:' + backgroundColor +
  37. '; border:1px solid ' + borderColor + ';padding:5px;">' +
  38. content + '</div>';
  39. data.addRows([
  40. [startDate, endDate, div]
  41. ]);
  42. }
  43. data.addRows([
  44. [
  45. new Date(2010, 7, 19),
  46. null,
  47. 'Some html<br>containing an image<br>' +
  48. '<img src="img/notes-edit-icon.png">'
  49. ],
  50. [
  51. new Date(2010, 7, 23),
  52. null,
  53. '<h3>Lorem ipsum</h3>' +
  54. '<div class="myParagraph">' +
  55. 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque eget sem arcu. Pellentesque habitant morbi tristique senectus et netus et.' +
  56. '</div>'
  57. ],
  58. [
  59. new Date(2010, 7, 22),
  60. new Date(2010, 7, 30),
  61. 'This text contains some <span style="font-weight: bold;">bold</span> text,<br>' +
  62. 'some <span style="font-style: italic;">italic</span> text,<br>' +
  63. 'and some <span style="color: red;">red</span> text.'
  64. ],
  65. [
  66. new Date(2010, 7, 29),
  67. null,
  68. '<div style="text-align:left;">There are a few limitations<br>' +
  69. '<ul>' +
  70. '<li>A box can have either non-wrapped text and a<br>flexible width, or a fixed width and wrapping text.</li>' +
  71. '<li>A range cannot automatically wrap text</li>' +
  72. '<li>The css styles <i>min-width</i> and <i>max-width</i><br>are not working well together with the timeline.</li>' +
  73. '</ul></div>'
  74. ]
  75. ]);
  76. // specify options
  77. var options = {
  78. width: "75%",
  79. height: "auto",
  80. start: new Date(2010, 7, 17),
  81. end: new Date(2010, 8, 2),
  82. style: "box" // optional. choose "dot" (default), "box", or "none"
  83. };
  84. // Instantiate our table object.
  85. timeline = new links.Timeline(document.getElementById('mytimeline'), options);
  86. // Attach event listeners
  87. google.visualization.events.addListener(timeline, 'select', onselect);
  88. google.visualization.events.addListener(timeline, 'rangechange', onrangechange);
  89. // Draw our table with the data we created locally.
  90. timeline.draw(data);
  91. // Set the scale by hand. Autoscaling will be disabled.
  92. // Note: you can achieve the same by specifying scale and step in the
  93. // options for the timeline.
  94. timeline.setScale(links.Timeline.StepDate.SCALE.DAY, 1);
  95. }
  96. // adjust start and end time.
  97. function setTime() {
  98. if (!timeline) return;
  99. var newStartDate = new Date(document.getElementById('startDate').value);
  100. var newEndDate = new Date(document.getElementById('endDate').value);
  101. timeline.setVisibleChartRange(newStartDate, newEndDate);
  102. timeline.redraw();
  103. }
  104. function onrangechange() {
  105. // adjust the values of startDate and endDate
  106. var range = timeline.getVisibleChartRange();
  107. document.getElementById('startDate').value = dateFormat(range.start);
  108. document.getElementById('endDate').value = dateFormat(range.end);
  109. }
  110. function onselect() {
  111. var sel = timeline.getSelection();
  112. if (sel.length) {
  113. if (sel[0].row != undefined) {
  114. var row = sel[0].row;
  115. alert("event " + row + " selected");
  116. }
  117. }
  118. }
  119. // Format given date as "yyyy-mm-dd hh:ii:ss"
  120. // @param datetime A Date object.
  121. function dateFormat(date) {
  122. var datetime = date.getFullYear() + "-" +
  123. ((date.getMonth() < 9) ? "0" : "") + (date.getMonth() + 1) + "-" +
  124. ((date.getDate() < 10) ? "0" : "") + date.getDate() + " " +
  125. ((date.getHours() < 10) ? "0" : "") + date.getHours() + ":" +
  126. ((date.getMinutes() < 10) ? "0" : "") + date.getMinutes() + ":" +
  127. ((date.getSeconds() < 10) ? "0" : "") + date.getSeconds();
  128. return datetime;
  129. }
  130. </script>
  131. </head>
  132. <body onresize="if (timeline) {timeline.redraw();}">
  133. <p>This page demonstrates the timeline visualization.</p>
  134. <p>Click and drag to move the timeline, scroll to zoom the timeline.</p>
  135. <p>
  136. Starttime: <input type="text" id="startDate" value="2010-08-16">
  137. Endtime: <input type="text" id="endDate" value="2010-09-07">
  138. <input type="button" id="setStartDate" value="set" onclick="setTime();">
  139. </p>
  140. <div id="mytimeline"></div>
  141. <!-- Information about where the used icons come from -->
  142. <p style="color:gray; font-size:10px; font-style:italic;">
  143. Icons by <a href="http://dryicons.com" target="_blank" title="Aesthetica 2 Icons by DryIcons" style="color:gray;" >DryIcons</a>
  144. and <a href="http://www.tpdkdesign.net" target="_blank" title="Refresh Cl Icons by TpdkDesign.net" style="color:gray;" >TpdkDesign.net</a>
  145. </p>
  146. <div id="info"></div>
  147. </body>
  148. </html>