Repository where I mostly put random python scripts.
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.

92 lines
2.5 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Graph2d | Performance</title>
  5. <style>
  6. body, html {
  7. font-family: arial, sans-serif;
  8. font-size: 11pt;
  9. }
  10. span.label {
  11. width:150px;
  12. display:inline-block;
  13. }
  14. </style>
  15. <!-- note: moment.js must be loaded before vis.js, else vis.js uses its embedded version of moment.js -->
  16. <script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js"></script>
  17. <script src="https://code.jquery.com/jquery-3.3.1.min.js"
  18. integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
  19. crossorigin="anonymous">
  20. </script>
  21. <script src="./dist/vis.js"></script>
  22. <link href="./dist/vis-timeline-graph2d.min.css" rel="stylesheet" type="text/css" />
  23. </head>
  24. <body>
  25. <br />
  26. Click the button then choose a file to graph.
  27. <button onclick="openFile(dispFile)">Open a file</button>
  28. <pre id="contents"></pre>
  29. <div id="visualization">
  30. <script type="text/javascript">
  31. function dispFile(contents)
  32. {
  33. console.log(contents);
  34. console.log(typeof contents);
  35. var container = document.getElementById('visualization');
  36. var items = JSON.parse(contents);
  37. var dataset = new vis.DataSet(items);
  38. var options = {};
  39. var graph2d = new vis.Graph2d(container, dataset, options);
  40. }
  41. function clickElem(elem)
  42. {
  43. // Thx user1601638 on Stack Overflow (6/6/2018 - https://stackoverflow.com/questions/13405129/javascript-create-and-save-file )
  44. var eventMouse = document.createEvent("MouseEvents");
  45. eventMouse.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  46. elem.dispatchEvent(eventMouse);
  47. }
  48. function openFile(func)
  49. {
  50. readFile = function(e)
  51. {
  52. var file = e.target.files[0];
  53. if (!file)
  54. {
  55. return;
  56. }
  57. var reader = new FileReader();
  58. reader.onload = function(e)
  59. {
  60. var contents = e.target.result;
  61. fileInput.func(contents);
  62. document.body.removeChild(fileInput);
  63. }
  64. reader.readAsText(file);
  65. }
  66. fileInput = document.createElement("input");
  67. fileInput.type='file';
  68. fileInput.style.display='none';
  69. fileInput.onchange=readFile;
  70. fileInput.func=func;
  71. document.body.appendChild(fileInput);
  72. clickElem(fileInput);
  73. }
  74. </script>
  75. </div>
  76. </body>
  77. </html>