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.

186 lines
3.9 KiB

  1. var assert = require('assert'),
  2. fs = require('fs'),
  3. dot = require('../lib/network/dotparser.js');
  4. describe('dotparser', function () {
  5. it('should parse a DOT file into JSON', function (done) {
  6. fs.readFile('test/dot.txt', function (err, data) {
  7. data = String(data);
  8. var graph = dot.parseDOT(data);
  9. assert.deepEqual(graph, {
  10. "type": "digraph",
  11. "id": "test_graph",
  12. "rankdir": "LR",
  13. "size": "8,5",
  14. "font": "arial",
  15. "nodes": [
  16. {
  17. "id": "node1",
  18. "attr": {
  19. "shape": "doublecircle"
  20. }
  21. },
  22. {
  23. "id": "node2",
  24. "attr": {
  25. "shape": "doublecircle"
  26. }
  27. },
  28. {
  29. "id": "node3",
  30. "attr": {
  31. "shape": "doublecircle"
  32. }
  33. },
  34. {
  35. "id": "node4",
  36. "attr": {
  37. "shape": "diamond",
  38. "color": "red"
  39. }
  40. },
  41. {
  42. "id": "node5",
  43. "attr": {
  44. "shape": "square",
  45. "color": "blue",
  46. "width": 3
  47. }
  48. },
  49. {
  50. "id": 6,
  51. "attr": {
  52. "shape": "circle"
  53. }
  54. },
  55. {
  56. "id": "A",
  57. "attr": {
  58. "shape": "circle"
  59. }
  60. },
  61. {
  62. "id": "B",
  63. "attr": {
  64. "shape": "circle"
  65. }
  66. },
  67. {
  68. "id": "C",
  69. "attr": {
  70. "shape": "circle"
  71. }
  72. }
  73. ],
  74. "edges": [
  75. {
  76. "from": "node1",
  77. "to": "node1",
  78. "type": "->",
  79. "attr": {
  80. "length": 170,
  81. "fontSize": 12,
  82. "label": "a"
  83. }
  84. },
  85. {
  86. "from": "node2",
  87. "to": "node3",
  88. "type": "->",
  89. "attr": {
  90. "length": 170,
  91. "fontSize": 12,
  92. "label": "b"
  93. }
  94. },
  95. {
  96. "from": "node1",
  97. "to": "node4",
  98. "type": "--",
  99. "attr": {
  100. "length": 170,
  101. "fontSize": 12,
  102. "label": "c"
  103. }
  104. },
  105. {
  106. "from": "node3",
  107. "to": "node4",
  108. "type": "->",
  109. "attr": {
  110. "length": 170,
  111. "fontSize": 12,
  112. "label": "d"
  113. }
  114. },
  115. {
  116. "from": "node4",
  117. "to": "node5",
  118. "type": "->",
  119. "attr": {
  120. "length": 170,
  121. "fontSize": 12
  122. }
  123. },
  124. {
  125. "from": "node5",
  126. "to": 6,
  127. "type": "->",
  128. "attr": {
  129. "length": 170,
  130. "fontSize": 12
  131. }
  132. },
  133. {
  134. "from": "A",
  135. "to": {
  136. "nodes": [
  137. {
  138. "id": "B",
  139. "attr": {
  140. "shape": "circle"
  141. }
  142. },
  143. {
  144. "id": "C",
  145. "attr": {
  146. "shape": "circle"
  147. }
  148. }
  149. ]
  150. },
  151. "type": "->",
  152. "attr": {
  153. "length": 170,
  154. "fontSize": 12
  155. }
  156. }
  157. ],
  158. "subgraphs": [
  159. {
  160. "nodes": [
  161. {
  162. "id": "B",
  163. "attr": {
  164. "shape": "circle"
  165. }
  166. },
  167. {
  168. "id": "C",
  169. "attr": {
  170. "shape": "circle"
  171. }
  172. }
  173. ]
  174. }
  175. ]
  176. });
  177. done();
  178. });
  179. });
  180. });