vis.js is a dynamic, browser-based visualization library
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.

131 lines
3.1 KiB

  1. <html>
  2. <head>
  3. <title>Timeline | Tooltip on item onUpdateTime Option</title>
  4. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
  5. <script src="../../../dist/vis.js"></script>
  6. <link href="../../../dist/vis.css" rel="stylesheet" type="text/css" />
  7. <style type="text/css">
  8. .vis-item .vis-onUpdateTime-tooltip {
  9. border-radius: 4px;
  10. }
  11. </style>
  12. </head>
  13. <body>
  14. <h1>Timeline Tooltip on item onUpdateTime Option</h1>
  15. <h2>With <code>tooltipOnItemUpdateTime: true</code>
  16. </h2>
  17. <div id="mytimeline1"></div>
  18. <h2>With <code>tooltipOnItemUpdateTime: { template: [Function] }</code>
  19. </h2>
  20. <div id="mytimeline2"></div>
  21. <h2>With groups</h2>
  22. <div id="mytimeline3"></div>
  23. <script>
  24. // create items
  25. var numberOfItems = 10;
  26. var items = new vis.DataSet();
  27. var types = [ 'box', 'point', 'range']
  28. for (var order = 0; order < numberOfItems; order++) {
  29. var date = vis.moment();
  30. date.add(Math.round(Math.random() * 2), 'hour');
  31. items.add({
  32. id: order,
  33. type: types[Math.floor(3 * Math.random())],
  34. content: 'Item ' + order,
  35. start: date.clone().add(order + 1, 'hour'),
  36. end: date.clone().add(order + 3, 'hour')
  37. });
  38. }
  39. // specify options
  40. var options = {
  41. multiselect: true,
  42. maxHeight: 400,
  43. start: new Date((new Date()).valueOf() - 10000000),
  44. end: new Date(1000*60*60*24 + (new Date()).valueOf()),
  45. editable: true
  46. };
  47. var options1 = jQuery.extend(options, {
  48. tooltipOnItemUpdateTime: true
  49. })
  50. var container1 = document.getElementById('mytimeline1');
  51. timeline1 = new vis.Timeline(container1, items, null, options1);
  52. var options2 = jQuery.extend(options, {
  53. orientation: 'top',
  54. tooltipOnItemUpdateTime: {
  55. template: function(item) {
  56. return 'html template for tooltip with <b>item.start</b>: ' + item.start;
  57. }
  58. }
  59. })
  60. var container2 = document.getElementById('mytimeline2');
  61. timeline2 = new vis.Timeline(container2, items, null, options2);
  62. // create groups
  63. var numberOfGroups = 25;
  64. var groups = new vis.DataSet()
  65. for (var i = 0; i < numberOfGroups; i++) {
  66. groups.add({
  67. id: i,
  68. content: 'Truck&nbsp;' + i
  69. })
  70. }
  71. // create items for groups
  72. var numberOfItems = 1000;
  73. var itemsWithGroups = new vis.DataSet();
  74. var itemsPerGroup = Math.round(numberOfItems/numberOfGroups);
  75. for (var truck = 0; truck < numberOfGroups; truck++) {
  76. var date = new Date();
  77. for (var order = 0; order < itemsPerGroup; order++) {
  78. date.setHours(date.getHours() + 4 * (Math.random() < 0.2));
  79. var start = new Date(date);
  80. date.setHours(date.getHours() + 2 + Math.floor(Math.random()*4));
  81. var end = new Date(date);
  82. itemsWithGroups.add({
  83. id: order + itemsPerGroup * truck,
  84. group: truck,
  85. start: start,
  86. end: end,
  87. content: 'Order ' + order
  88. });
  89. }
  90. }
  91. var options3 = jQuery.extend(options, {
  92. orientation: 'top',
  93. tooltipOnItemUpdateTime: true
  94. })
  95. var container3 = document.getElementById('mytimeline3');
  96. timeline3 = new vis.Timeline(container3, itemsWithGroups, groups, options3);
  97. </script>
  98. </body>
  99. </html>