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.

205 lines
8.1 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Timeline demo</title>
  5. <style>
  6. body {
  7. font-family: verdana, sans, arial;
  8. font-size: 10pt;
  9. }
  10. </style>
  11. <script type="text/javascript" src="http://www.google.com/jsapi"></script>
  12. <script type="text/javascript" src="../timeline.js"></script>
  13. <link rel="stylesheet" type="text/css" href="../timeline.css">
  14. <script type="text/javascript">
  15. google.load("visualization", "1");
  16. // Set callback to run when API is loaded
  17. google.setOnLoadCallback(drawVisualization);
  18. var timeline;
  19. var data;
  20. function getSelectedRow() {
  21. var row = undefined;
  22. var sel = timeline.getSelection();
  23. if (sel.length) {
  24. if (sel[0].row != undefined) {
  25. row = sel[0].row;
  26. }
  27. }
  28. return row;
  29. }
  30. // Called when the Visualization API is loaded.
  31. function drawVisualization() {
  32. // Create and populate a data table.
  33. data = new google.visualization.DataTable();
  34. data.addColumn('datetime', 'start');
  35. data.addColumn('datetime', 'end');
  36. data.addColumn('string', 'content');
  37. data.addRows([
  38. [new Date(2011,1,23), , '<div>Conversation</div><img src="img/comments-icon.png" style="width:32px; height:32px;">'],
  39. [new Date(2011,1,23,23,0,0), , '<div>Mail from boss</div><img src="img/mail-icon.png" style="width:32px; height:32px;">'],
  40. [new Date(2011,1,24,16,0,0), , 'Report'],
  41. [new Date(2011,1,26), new Date(2011,2,2), 'Traject A'],
  42. [new Date(2011,1,27), , '<div>Memo</div><img src="img/notes-edit-icon.png" style="width:48px; height:48px;">'],
  43. [new Date(2011,1,29), , '<div>Phone call</div><img src="img/Hardware-Mobile-Phone-icon.png" style="width:32px; height:32px;">'],
  44. [new Date(2011,1,28), new Date(2011,2,3), 'Traject B'],
  45. [new Date(2011,2,4,12,0,0), , '<div>Report</div><img src="img/attachment-icon.png" style="width:32px; height:32px;">']
  46. ]);
  47. // specify options
  48. var options = {
  49. width: "100%",
  50. height: "300px",
  51. //height: "auto",
  52. editable: true, // enable dragging and editing items
  53. //axisOnTop: true,
  54. style: "box"
  55. };
  56. // Instantiate our timeline object.
  57. timeline = new links.Timeline(document.getElementById('mytimeline'), options);
  58. // Add event listeners
  59. google.visualization.events.addListener(timeline, 'select', onselect);
  60. google.visualization.events.addListener(timeline, 'change', onchange);
  61. google.visualization.events.addListener(timeline, 'add', onadd);
  62. google.visualization.events.addListener(timeline, 'edit', onedit);
  63. google.visualization.events.addListener(timeline, 'delete', ondelete);
  64. google.visualization.events.addListener(timeline, 'rangechange', onrangechange);
  65. google.visualization.events.addListener(timeline, 'rangechanged', onrangechanged);
  66. // Draw our timeline with the created data and options
  67. timeline.draw(data);
  68. onrangechange();
  69. }
  70. // Make a callback function for the select item
  71. var onselect = function (event) {
  72. var row = getSelectedRow();
  73. if (row != undefined) {
  74. document.getElementById("info").innerHTML += "item " + row + " selected<br>";
  75. // Note: you can retrieve the contents of the selected row with
  76. // data.getValue(row, 2);
  77. }
  78. else {
  79. document.getElementById("info").innerHTML += "no item selected<br>";
  80. }
  81. };
  82. // callback function for the change item
  83. var onchange = function () {
  84. var row = getSelectedRow();
  85. document.getElementById("info").innerHTML += "item " + row + " changed<br>";
  86. };
  87. // callback function for the delete item
  88. var ondelete = function () {
  89. var row = getSelectedRow();
  90. document.getElementById("info").innerHTML += "item " + row + " deleted<br>";
  91. };
  92. // callback function for the edit item
  93. var onedit = function () {
  94. var row = getSelectedRow();
  95. document.getElementById("info").innerHTML += "item " + row + " edit<br>";
  96. var content = data.getValue(row, 2);
  97. var newContent = prompt("Enter content", content);
  98. if (newContent != undefined) {
  99. data.setValue(row, 2, newContent);
  100. }
  101. timeline.redraw();
  102. };
  103. // callback function for the add item
  104. var onadd = function () {
  105. var row = getSelectedRow();
  106. document.getElementById("info").innerHTML += "item " + row + " created<br>";
  107. var content = data.getValue(row, 2);
  108. var newContent = prompt("Enter content", content);
  109. if (newContent != undefined) {
  110. data.setValue(row, 2, newContent);
  111. timeline.redraw();
  112. }
  113. else {
  114. // cancel adding the item
  115. timeline.cancelAdd();
  116. }
  117. };
  118. function onrangechange() {
  119. // adjust the values of startDate and endDate
  120. var range = timeline.getVisibleChartRange();
  121. document.getElementById('startDate').value = dateFormat(range.start);
  122. document.getElementById('endDate').value = dateFormat(range.end);
  123. }
  124. function onrangechanged() {
  125. document.getElementById("info").innerHTML += "range changed<br>";
  126. }
  127. // adjust start and end time.
  128. function setTime() {
  129. if (!timeline) return;
  130. var newStartDate = new Date(document.getElementById('startDate').value);
  131. var newEndDate = new Date(document.getElementById('endDate').value);
  132. timeline.setVisibleChartRange(newStartDate, newEndDate);
  133. }
  134. // set the visible range to the current time
  135. function setCurrentTime() {
  136. if (!timeline) return;
  137. timeline.setVisibleChartRangeNow();
  138. onrangechange();
  139. }
  140. // Format given date as "yyyy-mm-dd hh:ii:ss"
  141. // @param datetime A Date object.
  142. function dateFormat(date) {
  143. var datetime = date.getFullYear() + "-" +
  144. ((date.getMonth() < 9) ? "0" : "") + (date.getMonth() + 1) + "-" +
  145. ((date.getDate() < 10) ? "0" : "") + date.getDate() + " " +
  146. ((date.getHours() < 10) ? "0" : "") + date.getHours() + ":" +
  147. ((date.getMinutes() < 10) ? "0" : "") + date.getMinutes() + ":" +
  148. ((date.getSeconds() < 10) ? "0" : "") + date.getSeconds();
  149. return datetime;
  150. }
  151. </script>
  152. </head>
  153. <body>
  154. <p>This page demonstrates the timeline visualization.</p>
  155. <ul>
  156. <li>Click and drag on the time axis to move the timeline, scroll to zoom the timeline</li>
  157. <li>Click and drag an item to change its date, double-click to change its text</li>
  158. <li>Click or drag on an empty spot in the timeline to create a new item</li>
  159. </ul>
  160. <p>
  161. Starttime: <input type="text" id="startDate" value="">
  162. Endtime: <input type="text" id="endDate" value="">
  163. <input type="button" id="setRange" value="Set" onclick="setTime();">
  164. <input type="button" id="setCurrentTime" value="Current time" onclick="setCurrentTime();">
  165. </p>
  166. <div id="mytimeline"></div>
  167. <!-- Information about where the used icons come from -->
  168. <p style="color:gray; font-size:10px; font-style:italic;">
  169. Icons by <a href="http://dryicons.com" target="_blank" title="Aesthetica 2 Icons by DryIcons" style="color:gray;" >DryIcons</a>
  170. and <a href="http://www.tpdkdesign.net" target="_blank" title="Refresh Cl Icons by TpdkDesign.net" style="color:gray;" >TpdkDesign.net</a>
  171. </p>
  172. <br>
  173. <div id="info"></div>
  174. </body>
  175. </html>