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.

125 lines
3.7 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
  5. <meta content="utf-8" http-equiv="encoding">
  6. <title>Graph2d | Basic Example</title>
  7. <style type="text/css">
  8. body, html {
  9. font-family: sans-serif;
  10. }
  11. </style>
  12. <script src="../dist/vis.js"></script>
  13. <script src="./locationTrace_processed.js"></script>
  14. <script src="./timeTraveled_processed.js"></script>
  15. <link href="../dist/vis.css" rel="stylesheet" type="text/css" />
  16. <body>
  17. <h2>Graph2d | Basic Example</h2>
  18. <div style="width:700px; font-size:14px; text-align: justify;">
  19. </div>
  20. <br />
  21. <div id="visualization"></div>
  22. <div id="visualization2"></div>
  23. <div id="visualization3"></div>
  24. <script type="text/javascript">
  25. var groups = new vis.DataSet();
  26. groups.add({
  27. id: 'accuracy',
  28. content: 'accuracy'
  29. });
  30. //
  31. groups.add({
  32. id: 'latitude',
  33. content: 'latitude'
  34. })
  35. groups.add({
  36. id: 'longitude',
  37. content: 'longitude'
  38. })
  39. groups.add({
  40. id: 'timeTraveled',
  41. content: 'timeTraveled',
  42. options:{
  43. yAxisOrientation:'right',
  44. drawPoints:{style:"square", size:10}
  45. }
  46. })
  47. groups.add({
  48. id: 'db',
  49. content: 'db',
  50. options:{
  51. yAxisOrientation:'right',
  52. drawPoints:{style:"circle"}
  53. }
  54. })
  55. var items = [];
  56. var checkItems = [];
  57. for (var i = 0; i < locationTraceData.length; i++) {
  58. items.push({x:Number(locationTraceData[i].date+'000'), y:locationTraceData[i].value.accuracy === undefined ? 50 : locationTraceData[i].value.accuracy, group:'accuracy', label: {content:locationTraceData[i].value.event}});
  59. items.push({x:Number(locationTraceData[i].date+'000'), y:locationTraceData[i].value.latitude === undefined ? -6.8 : locationTraceData[i].value.latitude, group:'latitude'});
  60. items.push({x:Number(locationTraceData[i].date+'000'), y:locationTraceData[i].value.longitude === undefined ? 107.6 : locationTraceData[i].value.longitude, group:'longitude'});
  61. }
  62. for (var i = 0; i < timeTraveledData.length; i++) {
  63. items.push({x:Number(timeTraveledData[i].date+'000'), y:timeTraveledData[i].value, group:'timeTraveled'});
  64. }
  65. var lastValue = 0;
  66. var timeTraveled = 0;
  67. var dt = 0;
  68. var start = Number(locationTraceData[0].date);
  69. var departed = false;
  70. for (var i = 0; i < locationTraceData.length; i++) {
  71. var event = locationTraceData[i].value.event;
  72. if (event === 'depart') {
  73. dt = Number(locationTraceData[i].date);
  74. departed = true;
  75. }
  76. else {
  77. if (departed === true) {
  78. timeTraveled += Number(locationTraceData[i].date) - dt;
  79. }
  80. departed = false;
  81. dt = 0;
  82. }
  83. checkItems.push({x:Number(locationTraceData[i].date+'000'), y:timeTraveled, group:'db'});
  84. }
  85. var matchingItems = [];
  86. for (var i = 0; i < checkItems.length; i++) {
  87. for (var j = 0; j < items.length; j++) {
  88. if (items[j].group === 'timeTraveled') {
  89. if (items[j].x === checkItems[i].x) {
  90. console.log("check @ ", checkItems[i].x, items[j].y - checkItems[i].y);
  91. matchingItems.push(checkItems[i]);
  92. break;
  93. }
  94. }
  95. }
  96. }
  97. items = items.concat(checkItems)
  98. var container = document.getElementById('visualization');
  99. var dataset = new vis.DataSet(items);
  100. var options = {
  101. interpolation:false,
  102. height:800,
  103. sort:true
  104. };
  105. var graph2d = new vis.Graph2d(container, dataset,groups, options);
  106. </script>
  107. </body>
  108. </html>