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.

64 lines
2.0 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Timeline | Select items</title>
  5. <style>
  6. body, html {
  7. font-family: arial, sans-serif;
  8. font-size: 11pt;
  9. }
  10. </style>
  11. <script src="../../dist/vis.js"></script>
  12. <link href="../../dist/vis.css" rel="stylesheet" type="text/css" />
  13. </head>
  14. <body>
  15. <h1>Set selection</h1>
  16. <p style="max-width: 600px;">
  17. Enter one or multiple ids of items, then press select to select the items. This demo uses the function <code>Timeline.setSelection(ids)</code>. Optionally, the window can be moved to the selected items.
  18. </p>
  19. <p>
  20. Select item(s): <input type="text" id="selection" value="5, 6"><input type="button" id="select" value="Select"><br>
  21. <label><input type="checkbox" id="focus" checked> Focus on selection</label>
  22. </p>
  23. <div id="visualization"></div>
  24. <script>
  25. // create a dataset with items
  26. // we specify the type of the fields `start` and `end` here to be strings
  27. // containing an ISO date. The fields will be outputted as ISO dates
  28. // automatically getting data from the DataSet via items.get().
  29. var items = new vis.DataSet({
  30. type: { start: 'ISODate', end: 'ISODate' }
  31. });
  32. // add items to the DataSet
  33. items.add([
  34. {id: 1, content: 'item 1<br>start', start: '2014-01-23'},
  35. {id: 2, content: 'item 2', start: '2014-01-18'},
  36. {id: 3, content: 'item 3', start: '2014-01-21'},
  37. {id: 4, content: 'item 4', start: '2014-01-19', end: '2014-01-24'},
  38. {id: 5, content: 'item 5', start: '2014-01-28', type:'point'},
  39. {id: 6, content: 'item 6', start: '2014-01-26'}
  40. ]);
  41. var container = document.getElementById('visualization');
  42. var options = {
  43. editable: true
  44. };
  45. var timeline = new vis.Timeline(container, items, options);
  46. var selection = document.getElementById('selection');
  47. var select = document.getElementById('select');
  48. var focus = document.getElementById('focus');
  49. select.onclick = function () {
  50. var ids = selection.value.split(',').map(function (value) {
  51. return value.trim();
  52. });
  53. timeline.setSelection(ids, {focus: focus.checked});
  54. };
  55. </script>
  56. </body>
  57. </html>