Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.96 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Pipe layout</title>
  5. </head>
  6. <body>
  7. <h2>Pipe layout viewer</h2>
  8.  
  9. <input id="spinner" class='selector' size=3><button id=btn_submit >Submit value</button>
  10. <div id=d1></div>
  11.  
  12. <button style="margin: 10px;" onclick="loadJSON()">Load pipes</button>
  13.  
  14. <div id="myDiagramDiv"
  15. style="width:500px; height:500px; background-color: #DAE4E4;"></div>
  16. <p id="selectedPipeInfo">Click a pipe to get info</p>
  17.  
  18. <html>
  19. <head>
  20. <meta charset="utf-8"/>
  21.  
  22. <title>Ammount of pipes</title>
  23. </head>
  24. </body>
  25. </html>
  26.  
  27.  
  28. </body>
  29.  
  30. <script src="https://cdnjs.cloudflare.com/ajax/libs/gojs/1.8.33/go-debug.js"></script>
  31. <!-- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> -->
  32. <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
  33. <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
  34. <link href="https://code.jquery.com/ui/1.12.1/themes/blitzer/jquery-ui.css" rel="stylesheet">
  35.  
  36. <script>
  37. $(document).ready(function() {
  38. $( "#spinner" ).spinner();
  39. $('#btn_submit').click(function(){
  40. var value = $( "#spinner" ).spinner( "value" );
  41. $('#d1').html("Ammount pipes : " + value);
  42. })
  43. })
  44. </script>
  45.  
  46. <script type = "application/javascript">
  47.  
  48. function loadJSON(){
  49. var data_location = "http://127.0.0.1:8080/json?type=pipeInst";
  50. var http_request = new XMLHttpRequest();
  51. try{
  52. // Opera 8.0+, Firefox, Chrome, Safari
  53. http_request = new XMLHttpRequest();
  54. }catch (e){
  55. // Internet Explorer Browsers
  56. try{
  57. http_request = new ActiveXObject("Msxml2.XMLHTTP");
  58.  
  59. }catch (e) {
  60.  
  61. try{
  62. http_request = new ActiveXObject("Microsoft.XMLHTTP");
  63. }catch (e){
  64. // Something went wrong
  65. alert("Your browser broke!");
  66. return false;
  67. }
  68.  
  69. }
  70. }
  71.  
  72. http_request.onreadystatechange = function(){
  73.  
  74. if (http_request.readyState == 4 && http_request.status == 200 ){
  75. var jsonObj = JSON.parse(http_request.responseText);
  76.  
  77. let nodeArray = [];
  78. let linkArray = [];
  79.  
  80. for(var i = 0; i < jsonObj.results.length; i++) {
  81. var element = jsonObj.results[i];
  82. nodeArray.push({key: element.resInst, color: "yellow", text: "pipe "+i, object: element});
  83.  
  84. if(i === jsonObj.results.length - 1) {
  85. linkArray.push({from: element.resInst, to: jsonObj.results[0].resInst});
  86. } else {
  87. linkArray.push({from: element.resInst, to: jsonObj.results[i+1].resInst})
  88. }
  89. }
  90.  
  91. drawPipes(nodeArray, linkArray);
  92. }
  93. }
  94.  
  95. http_request.open("GET", data_location, true);
  96. http_request.send();
  97. }
  98.  
  99.  
  100. function nodeClicked(e, obj) {
  101. var node = obj.part;
  102. var msg = "Pipe instance pid: " + node.data.object.resInst + "\n"
  103. + "Connectors: " + JSON.stringify(node.data.object.cList) + "\n"
  104. + "Chambers: " + JSON.stringify(node.data.object.chambers) + "\n";
  105. $("#selectedPipeInfo").text("Selected: \n" + msg);
  106. }
  107.  
  108. function drawPipes(array, linkArray) {
  109. var $$ = go.GraphObject.make; // for conciseness in defining templates, avoid $ due to jQuery
  110. myDiagram = $$(go.Diagram, "myDiagramDiv", // create a Diagram for the DIV HTML element
  111. {
  112. initialContentAlignment: go.Spot.TopCenter, // center the content
  113. "undoManager.isEnabled": true // enable undo & redo
  114. });
  115. // define a simple Node template
  116. myDiagram.nodeTemplate =
  117. $$(go.Node, "Auto", {
  118. click: nodeClicked,
  119. }, // the Shape will go around the TextBlock
  120. $$(go.Shape, "RoundedRectangle", { strokeWidth: 0},
  121. // Shape.fill is bound to Node.data.color
  122. new go.Binding("fill", "color")),
  123. $$(go.TextBlock,
  124. { margin: 8 }, // some room around the text
  125. // TextBlock.text is bound to Node.data.key
  126. new go.Binding("text", "key"))
  127. );
  128.  
  129. myDiagram.linkTemplate =
  130. $$(go.Link,
  131. {
  132. curve: go.Link.JumpOver,
  133. reshapable: true,
  134. resegmentable: true,
  135. relinkableFrom: false,
  136. relinkableTo: false,
  137. fromPortId: "",
  138. toPortId: "",
  139. corner: 2,
  140. name: 'LINK'
  141. },
  142. $$(go.Shape, {stroke: 'black', strokeWidth: 1 }),
  143. $$(go.Shape, { toArrow: "Standard", fill: 'gray', stroke: null })
  144. );
  145.  
  146. myDiagram.model = new go.GraphLinksModel(array, linkArray);
  147. }
  148.  
  149. function LayeredLayout() {
  150. go.LayeredDigraphLayout.call(this);
  151. }
  152. </script>
  153. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement