example02_interactive.html 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  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,01,23), , '<div>Conversation</div><img src="img/comments-icon.png" style="width:32px; height:32px;">'],
  39. [new Date(2011,01,23,23,00,00), , '<div>Mail from boss</div><img src="img/mail-icon.png" style="width:32px; height:32px;">'],
  40. [new Date(2011,01,24,16,00,00), , 'Report'],
  41. [new Date(2011,01,26), new Date(2011,02,02), 'Traject A'],
  42. [new Date(2011,01,27), , '<div>Memo</div><img src="img/notes-edit-icon.png" style="width:48px; height:48px;">'],
  43. [new Date(2011,01,29), , '<div>Phone call</div><img src="img/Hardware-Mobile-Phone-icon.png" style="width:32px; height:32px;">'],
  44. [new Date(2011,01,28), new Date(2011,02,03), 'Traject B'],
  45. [new Date(2011,02,04,12,00,00), , '<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 events
  53. enableKeys: true,
  54. axisOnTop: false,
  55. showNavigation: true,
  56. style: "box"
  57. };
  58. // Instantiate our timeline object.
  59. timeline = new links.Timeline(document.getElementById('mytimeline'));
  60. // Add event listeners
  61. google.visualization.events.addListener(timeline, 'select', onselect);
  62. google.visualization.events.addListener(timeline, 'change', onchange);
  63. google.visualization.events.addListener(timeline, 'add', onadd);
  64. google.visualization.events.addListener(timeline, 'edit', onedit);
  65. google.visualization.events.addListener(timeline, 'delete', ondelete);
  66. google.visualization.events.addListener(timeline, 'rangechange', onrangechange);
  67. google.visualization.events.addListener(timeline, 'rangechanged', onrangechanged);
  68. // Draw our timeline with the created data and options
  69. timeline.draw(data, options);
  70. onrangechange();
  71. }
  72. // Make a callback function for the select event
  73. var onselect = function (event) {
  74. var row = getSelectedRow();
  75. document.getElementById("info").innerHTML += "event " + row + " selected<br>";
  76. // Note: you can retrieve the contents of the selected row with
  77. // data.getValue(row, 2);
  78. };
  79. // callback function for the change event
  80. var onchange = function () {
  81. var row = getSelectedRow();
  82. document.getElementById("info").innerHTML += "event " + row + " changed<br>";
  83. };
  84. // callback function for the delete event
  85. var ondelete = function () {
  86. var row = getSelectedRow();
  87. document.getElementById("info").innerHTML += "event " + row + " deleted<br>";
  88. };
  89. // callback function for the edit event
  90. var onedit = function () {
  91. var row = getSelectedRow();
  92. document.getElementById("info").innerHTML += "event " + row + " edit<br>";
  93. var content = data.getValue(row, 2);
  94. var newContent = prompt("Enter content", content);
  95. if (newContent != undefined) {
  96. data.setValue(row, 2, newContent);
  97. }
  98. timeline.redraw();
  99. };
  100. // callback function for the add event
  101. var onadd = function () {
  102. var row = getSelectedRow();
  103. document.getElementById("info").innerHTML += "event " + row + " created<br>";
  104. var content = data.getValue(row, 2);
  105. var newContent = prompt("Enter content", content);
  106. if (newContent != undefined) {
  107. data.setValue(row, 2, newContent);
  108. timeline.redraw();
  109. }
  110. else {
  111. // cancel adding the event
  112. timeline.cancelAdd();
  113. }
  114. };
  115. function onrangechange() {
  116. // adjust the values of startDate and endDate
  117. var range = timeline.getVisibleChartRange();
  118. document.getElementById('startDate').value = dateFormat(range.start);
  119. document.getElementById('endDate').value = dateFormat(range.end);
  120. }
  121. function onrangechanged() {
  122. document.getElementById("info").innerHTML += "range changed<br>";
  123. }
  124. // adjust start and end time.
  125. function setTime() {
  126. if (!timeline) return;
  127. var newStartDate = new Date(document.getElementById('startDate').value);
  128. var newEndDate = new Date(document.getElementById('endDate').value);
  129. timeline.setVisibleChartRange(newStartDate, newEndDate);
  130. }
  131. // set the visible range to the current time
  132. function setCurrentTime() {
  133. if (!timeline) return;
  134. timeline.setVisibleChartRangeNow();
  135. onrangechange();
  136. }
  137. // Format given date as "yyyy-mm-dd hh:ii:ss"
  138. // @param datetime A Date object.
  139. function dateFormat(date) {
  140. var datetime = date.getFullYear() + "-" +
  141. ((date.getMonth() < 9) ? "0" : "") + (date.getMonth() + 1) + "-" +
  142. ((date.getDate() < 10) ? "0" : "") + date.getDate() + " " +
  143. ((date.getHours() < 10) ? "0" : "") + date.getHours() + ":" +
  144. ((date.getMinutes() < 10) ? "0" : "") + date.getMinutes() + ":" +
  145. ((date.getSeconds() < 10) ? "0" : "") + date.getSeconds();
  146. return datetime;
  147. }
  148. </script>
  149. </head>
  150. <body>
  151. <p>This page demonstrates the timeline visualization.</p>
  152. <p>
  153. <ul>
  154. <li>Click and drag on the time axis to move the timeline, scroll to zoom the timeline</li>
  155. <li>Click and drag an event to change its date, double-click to change its text</li>
  156. <li>Click or drag on an empty spot in the timeline to create a new event</li>
  157. </ul>
  158. </p>
  159. <p>
  160. Starttime: <input type="text" id="startDate" value="">
  161. Endtime: <input type="text" id="endDate" value="">
  162. <input type="button" id="setRange" value="Set" onclick="setTime();">
  163. <input type="button" id="setCurrentTime" value="Current time" onclick="setCurrentTime();">
  164. </p>
  165. <div id="mytimeline"></div>
  166. <!-- Information about where the used icons come from -->
  167. <p style="color:gray; font-size:10px; font-style:italic;">
  168. Icons by <a href="http://dryicons.com" target="_blank" title="Aesthetica 2 Icons by DryIcons" style="color:gray;" >DryIcons</a>
  169. and <a href="http://www.tpdkdesign.net" target="_blank" title="Refresh Cl Icons by TpdkDesign.net" style="color:gray;" >TpdkDesign.net</a>
  170. </p>
  171. <br>
  172. <div id="info"></div>
  173. </body>
  174. </html>