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.

85 lines
3.2 KiB

9 years ago
  1. /**
  2. * Created by Alex on 4/21/2015.
  3. */
  4. /**
  5. * it works like this:
  6. *
  7. * the toggle row has the onclick with the table id, the parent name and this. The function will look through all trs with matching parent and check the class
  8. * if hidden, it shows them, else it hides them.
  9. *
  10. * The caret is also flipped and the toggle class is changed.
  11. *
  12. *
  13. <tr class='toggle collapsible' onclick="toggleTable('physicsTable','barnesHut', this);"><td><span parent="barnesHut" class="right-caret"></span> barnesHut</td></tr>
  14. <tr parent="barnesHut" class="hidden"><td>barnesHut.gravitationalConstant</td></tr>
  15. <tr parent="barnesHut" class="hidden"><td>barnesHut.centralGravity</td></tr>
  16. <tr parent="barnesHut" class="hidden"><td>barnesHut.springLength</td></tr>
  17. <tr parent="barnesHut" class="hidden"><td>barnesHut.springConstant</td></tr>
  18. <tr parent="barnesHut" class="hidden"><td>barnesHut.damping</td></tr>
  19. *
  20. *
  21. * @param tableId
  22. * @param parent
  23. * @param clickedRow
  24. */
  25. function toggleTable(tableId, parent, clickedRow) {
  26. var table = document.getElementById(tableId);
  27. var wasOpen = false;
  28. for (var i = 0, row; row = table.rows[i]; i++) {
  29. if (row.getAttribute('parent') === parent) {
  30. if (row.className.indexOf('hidden') !== -1) {
  31. row.className = row.className.replace(' hidden','').replace('hidden','');
  32. row.className += ' visible';
  33. }
  34. else {
  35. row.className = row.className.replace(' visible','').replace('visible','');;
  36. row.className += ' hidden';
  37. wasOpen = true;
  38. }
  39. }
  40. }
  41. var spans;
  42. if (wasOpen === true) {
  43. spans = document.getElementsByClassName('caret');
  44. clickedRow.className += ' collapsible';
  45. }
  46. else {
  47. spans = document.getElementsByClassName('right-caret')
  48. clickedRow.className = clickedRow.className.replace(' collapsible','').replace('collapsible','');;
  49. }
  50. for (var i = 0; i < spans.length; i++) {
  51. if (spans[i].getAttribute('parent') === parent) {
  52. spans[i].className = wasOpen === true ? 'right-caret' : 'caret';
  53. }
  54. }
  55. }
  56. function toggleTab(showTabId, showPreId, hideTabId, hidePreId) {
  57. if (hideTabId !== undefined) {
  58. document.getElementById(hideTabId).className = '';
  59. document.getElementById(hidePreId).className = document.getElementById(hidePreId).className.replace(' hidden','');
  60. document.getElementById(hidePreId).className += ' hidden';
  61. }
  62. document.getElementById('hiddenTab').className = '';
  63. document.getElementById(showTabId).className = 'active';
  64. document.getElementById(showPreId).className = document.getElementById(showPreId).className.replace(' hidden','');
  65. }
  66. function hideOptions(hideTabId1, hidePreId1, hideTabId2, hidePreId2) {
  67. document.getElementById('hiddenTab').className = 'active';
  68. document.getElementById(hideTabId1).className = '';
  69. document.getElementById(hidePreId1).className = document.getElementById(hidePreId1).className.replace(' hidden','');
  70. document.getElementById(hidePreId1).className += ' hidden';
  71. if (hideTabId2 !== undefined) {
  72. document.getElementById(hideTabId2).className = '';
  73. document.getElementById(hidePreId2).className = document.getElementById(hidePreId2).className.replace(' hidden','');
  74. document.getElementById(hidePreId2).className += ' hidden';
  75. }
  76. }