example05_format_custom_html.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <html>
  2. <head>
  3. <title>Timeline demo</title>
  4. <style>
  5. body {font: 14pt arial;}
  6. input {font: 14pt arial;}
  7. </style>
  8. <script type="text/javascript" src="http://www.google.com/jsapi"></script>
  9. <script type="text/javascript" src="../timeline.js"></script>
  10. <link rel="stylesheet" type="text/css" href="../timeline.css">
  11. <style>
  12. div.timeline-event {
  13. border-color: black;
  14. }
  15. div.timeline-event-box, div.timeline-event-range {
  16. border-radius: 0px;
  17. border: none;
  18. }
  19. div.timeline-event-content {
  20. margin: 0px;
  21. }
  22. div.timeline-event-dot {
  23. border-width: 3px;
  24. border-radius: 3px;
  25. -moz-border-radius: 3px;
  26. }
  27. </style>
  28. <script type="text/javascript">
  29. google.load("visualization", "1");
  30. // Set callback to run when API is loaded
  31. google.setOnLoadCallback(drawVisualization);
  32. var timeline;
  33. var data;
  34. // Called when the timelineualization API is loaded.
  35. function drawVisualization() {
  36. // Create and populate a data table.
  37. data = new google.visualization.DataTable();
  38. data.addColumn('datetime', 'start');
  39. data.addColumn('datetime', 'end');
  40. data.addColumn('string', 'content');
  41. function addRow(startDate, endDate, content, backgroundColor, borderColor)
  42. {
  43. // we make our own customized layout for the events
  44. if (backgroundColor == undefined)
  45. backgroundColor = "yellow";
  46. if (borderColor == undefined)
  47. borderColor = "gold";
  48. var fill = endDate ? "pink" : "yellow";
  49. var div = '<div style="background-color:' + backgroundColor +
  50. '; border:1px solid ' + borderColor + ';padding:5px;">' +
  51. content + '</div>';
  52. data.addRows([
  53. [startDate, endDate, div]
  54. ]);
  55. }
  56. addRow(new Date(2010,07,19), null, "<img src='img/comments-icon.png' style='width:32;height:32;'>", "orange", "red");
  57. addRow(new Date(2010,07,23), null, "<img src='img/notes-edit-icon.png' style='width:32;height:32;'>", "yellow", "orange");
  58. addRow(new Date(2010,07,25), new Date(2010,08,01), "<img src='img/community-users-icon.png' style='width:32;height:32;'>", "green", "darkgreen");
  59. addRow(new Date(2010,07,27), null, "<img src='img/attachment-icon.png' style='width:32;height:32;'>", "pink", "purple");
  60. addRow(new Date(2010,08,02,12,00,00), null, "<img src='img/mail-icon.png' style='width:32;height:32;'>", "lightblue", "blue");
  61. // specify options
  62. options = {
  63. width: "75%",
  64. height: "200px",
  65. start: new Date(2010,07,16),
  66. end: new Date(2010,08,07),
  67. style: "box" // optional. choose "dot" (default), "box", or "none"
  68. };
  69. // Instantiate our table object.
  70. timeline = new links.Timeline(document.getElementById('mytimeline'));
  71. // Attach event listeners
  72. google.visualization.events.addListener(timeline, 'select', onselect);
  73. google.visualization.events.addListener(timeline, 'rangechange', onrangechange);
  74. // Draw our table with the data we created locally.
  75. timeline.draw(data, options);
  76. // Set the scale by hand. Autoscaling will be disabled.
  77. // Note: you can achieve the same by specifying scale and step in the
  78. // options for the timeline.
  79. timeline.setScale(links.Timeline.StepDate.SCALE.DAY, 1);
  80. }
  81. // adjust start and end time.
  82. function setTime() {
  83. if (!timeline) return;
  84. var newStartDate = new Date(document.getElementById('startDate').value);
  85. var newEndDate = new Date(document.getElementById('endDate').value);
  86. timeline.setVisibleChartRange(newStartDate, newEndDate);
  87. timeline.redraw();
  88. }
  89. function onrangechange() {
  90. // adjust the values of startDate and endDate
  91. var range = timeline.getVisibleChartRange();
  92. document.getElementById('startDate').value = dateFormat(range.start);
  93. document.getElementById('endDate').value = dateFormat(range.end);
  94. }
  95. function onselect() {
  96. var sel = timeline.getSelection();
  97. if (sel.length) {
  98. if (sel[0].row != undefined) {
  99. var row = sel[0].row;
  100. alert("event " + row + " selected");
  101. }
  102. }
  103. }
  104. // Format given date as "yyyy-mm-dd hh:ii:ss"
  105. // @param datetime A Date object.
  106. function dateFormat(date) {
  107. datetime = date.getFullYear() + "-" +
  108. ((date.getMonth() < 9) ? "0" : "") + (date.getMonth() + 1) + "-" +
  109. ((date.getDate() < 10) ? "0" : "") + date.getDate() + " " +
  110. ((date.getHours() < 10) ? "0" : "") + date.getHours() + ":" +
  111. ((date.getMinutes() < 10) ? "0" : "") + date.getMinutes() + ":" +
  112. ((date.getSeconds() < 10) ? "0" : "") + date.getSeconds()
  113. return datetime;
  114. }
  115. </script>
  116. </head>
  117. <body onresize="timeline.redraw();">
  118. <p>This page demonstrates the timeline visualization.</p>
  119. <p>Click and drag to move the timeline, scroll to zoom the timeline.</p>
  120. <p>
  121. Starttime: <input type="text" id="startDate" value="2010-08-16">
  122. Endtime: <input type="text" id="endDate" value="2010-09-07">
  123. <input type="button" id="setStartDate" value="set" onclick="setTime();">
  124. </p>
  125. <div id="mytimeline"></div>
  126. <!-- Information about where the used icons come from -->
  127. <p style="color:gray; font-size:10px; font-style:italic;">
  128. Icons by <a href="http://dryicons.com" target="_blank" title="Aesthetica 2 Icons by DryIcons" style="color:gray;" >DryIcons</a>
  129. and <a href="http://www.tpdkdesign.net" target="_blank" title="Refresh Cl Icons by TpdkDesign.net" style="color:gray;" >TpdkDesign.net</a>
  130. </p>
  131. <div id="info"></div>
  132. </body>
  133. </html>