Graph database Analysis of the Steam Network
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.

381 lines
12 KiB

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Jrtechs Steam Friend Graph Project</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  8. <link rel="stylesheet" href="css/bootstrap.css" media="screen">
  9. <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
  10. <script src="src/sigma.core.js"></script>
  11. <script src="src/conrad.js"></script>
  12. <script src="src/utils/sigma.utils.js"></script>
  13. <script src="src/utils/sigma.polyfills.js"></script>
  14. <script src="src/sigma.settings.js"></script>
  15. <script src="src/classes/sigma.classes.dispatcher.js"></script>
  16. <script src="src/classes/sigma.classes.configurable.js"></script>
  17. <script src="src/classes/sigma.classes.graph.js"></script>
  18. <script src="src/classes/sigma.classes.camera.js"></script>
  19. <script src="src/classes/sigma.classes.quad.js"></script>
  20. <script src="src/classes/sigma.classes.edgequad.js"></script>
  21. <script src="src/captors/sigma.captors.mouse.js"></script>
  22. <script src="src/captors/sigma.captors.touch.js"></script>
  23. <script src="src/renderers/sigma.renderers.canvas.js"></script>
  24. <script src="src/renderers/sigma.renderers.webgl.js"></script>
  25. <script src="src/renderers/sigma.renderers.svg.js"></script>
  26. <script src="src/renderers/sigma.renderers.def.js"></script>
  27. <script src="src/renderers/webgl/sigma.webgl.nodes.def.js"></script>
  28. <script src="src/renderers/webgl/sigma.webgl.nodes.fast.js"></script>
  29. <script src="src/renderers/webgl/sigma.webgl.edges.def.js"></script>
  30. <script src="src/renderers/webgl/sigma.webgl.edges.fast.js"></script>
  31. <script src="src/renderers/webgl/sigma.webgl.edges.arrow.js"></script>
  32. <script src="src/renderers/canvas/sigma.canvas.labels.def.js"></script>
  33. <script src="src/renderers/canvas/sigma.canvas.hovers.def.js"></script>
  34. <script src="src/renderers/canvas/sigma.canvas.nodes.def.js"></script>
  35. <script src="src/renderers/canvas/sigma.canvas.edges.def.js"></script>
  36. <script src="src/renderers/canvas/sigma.canvas.edges.curve.js"></script>
  37. <script src="src/renderers/canvas/sigma.canvas.edges.arrow.js"></script>
  38. <script src="src/renderers/canvas/sigma.canvas.edges.curvedArrow.js"></script>
  39. <script src="src/renderers/canvas/sigma.canvas.edgehovers.def.js"></script>
  40. <script src="src/renderers/canvas/sigma.canvas.edgehovers.curve.js"></script>
  41. <script src="src/renderers/canvas/sigma.canvas.edgehovers.arrow.js"></script>
  42. <script src="src/renderers/canvas/sigma.canvas.edgehovers.curvedArrow.js"></script>
  43. <script src="src/renderers/canvas/sigma.canvas.extremities.def.js"></script>
  44. <script src="src/renderers/svg/sigma.svg.utils.js"></script>
  45. <script src="src/renderers/svg/sigma.svg.nodes.def.js"></script>
  46. <script src="src/renderers/svg/sigma.svg.edges.def.js"></script>
  47. <script src="src/renderers/svg/sigma.svg.edges.curve.js"></script>
  48. <script src="src/renderers/svg/sigma.svg.labels.def.js"></script>
  49. <script src="src/renderers/svg/sigma.svg.hovers.def.js"></script>
  50. <script src="src/middlewares/sigma.middlewares.rescale.js"></script>
  51. <script src="src/middlewares/sigma.middlewares.copy.js"></script>
  52. <script src="src/misc/sigma.misc.animation.js"></script>
  53. <script src="src/misc/sigma.misc.bindEvents.js"></script>
  54. <script src="src/misc/sigma.misc.bindDOMEvents.js"></script>
  55. <script src="src/misc/sigma.misc.drawHovers.js"></script>
  56. <script src="src/plugins/sigma.plugins.neighborhoods/sigma.plugins.neighborhoods.js"></script>
  57. <script src="src/plugins/sigma.layout.forceAtlas2/supervisor.js"></script>
  58. <script src="src/plugins/sigma.layout.forceAtlas2/worker.js"></script>
  59. <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  60. </head>
  61. <body>
  62. <div class="navbar navbar-expand-lg fixed-top navbar-dark bg-primary">
  63. <div class="container">
  64. <a href="index.html" class="navbar-brand">Jrtechs Steam Graph Project</a>
  65. <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
  66. <span class="navbar-toggler-icon"></span>
  67. </button>
  68. <div class="collapse navbar-collapse" id="navbarResponsive">
  69. <ul class="navbar-nav">
  70. <li class="nav-item">
  71. <a class="nav-link" href="graphs.html">Graphs</a>
  72. </li>
  73. <li class="nav-item">
  74. <a class="nav-link" href="https://jrtechs.net">Blog</a>
  75. </li>
  76. <li class="nav-item">
  77. <a class="nav-link" href="https://jrtechs.me">Resume</a>
  78. </li>
  79. <li class="nav-item">
  80. <a class="nav-link" href="https://github.com/jrtechs">Github</a>
  81. </li>
  82. </ul>
  83. </div>
  84. </div>
  85. </div>
  86. <!-- END SIGMA IMPORTS -->
  87. <div id="container">
  88. <style>
  89. #graph-container {
  90. top: 0;
  91. bottom: 0;
  92. left: 0;
  93. right: 0;
  94. position: absolute;
  95. /*background-color: #455660;*/
  96. }
  97. .sigma-node:hover {
  98. fill: blue;
  99. }
  100. .muted {
  101. fill-opacity: 0.1;
  102. stroke-opacity: 0.1;
  103. font-size: 0;
  104. }
  105. </style>
  106. <div id="graph-container" style="width:100%; height:100%"></div>
  107. </div>
  108. <script>
  109. var s,
  110. g = {
  111. nodes: [],
  112. edges: []
  113. },
  114. colors = [
  115. '#4281a4',
  116. '#5da9e9',
  117. '#003f91',
  118. '#b793ae',
  119. '#6d326d'
  120. ];
  121. /**
  122. * Creates a new sigma graph
  123. */
  124. s = new sigma({
  125. graph: g,
  126. settings: {
  127. enableHovering: false
  128. }
  129. });
  130. /**
  131. * Sets the sigma graph to render using svg
  132. */
  133. s.addRenderer({
  134. id: 'main',
  135. type: 'svg',
  136. container: document.getElementById('graph-container'),
  137. freeStyle: true
  138. });
  139. /**
  140. * Simple function to get the get data from the url
  141. */
  142. function getUrlVars()
  143. {
  144. var vars = {};
  145. window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,
  146. function(m,key,value) {
  147. vars[key] = value;
  148. });
  149. return vars;
  150. }
  151. /** Web socket to communicate with the steam friend java server */
  152. connection = new WebSocket('ws://localhost:4444');
  153. /**
  154. * When the web socket is opened, this function
  155. * fetches the get data and requests the server
  156. * to start giving it graph information
  157. */
  158. connection.onopen = function ()
  159. {
  160. var getData = getUrlVars();
  161. if(getData["id"] != undefined && getData["id"] != "")
  162. {
  163. connection.send("{id:'" + getData["id"] + "', graph:" +
  164. getData["graph"] + "}");
  165. connection.send("{go:1}");
  166. }
  167. else
  168. {
  169. connection.close();
  170. }
  171. };
  172. /**
  173. * Logs any errors with the web socket -- usually error
  174. * connecting to the server
  175. * @param error
  176. */
  177. connection.onerror = function (error)
  178. {
  179. console.log('WebSocket Error ' + error);
  180. };
  181. /**
  182. * Helper function to add a new node to the sigma graph
  183. *
  184. * @param request
  185. */
  186. function addNodeToGraph(request)
  187. {
  188. if(s.graph.nodes(request.id) == undefined)
  189. {
  190. s.graph.addNode({
  191. id: request.id,
  192. label: request.name,
  193. x: request.x,
  194. y: request.y,
  195. size: request.size,
  196. color: colors[Math.floor(Math.random() * colors.length)]
  197. });
  198. s.refresh();
  199. }
  200. }
  201. /**
  202. * Helper function to add an edge between two nodes on the
  203. * sigma graph
  204. *
  205. * @param request
  206. */
  207. function addEdgeToGraph(request)
  208. {
  209. s.graph.addEdge({
  210. id: request.id,
  211. source: request.p1,
  212. target: request.p2,
  213. size: 1
  214. });
  215. s.refresh();
  216. }
  217. /**
  218. * Parses any events from the server
  219. * action 1: add a new node to the graph
  220. * action 2: add a new edge to the graph
  221. * action 3: start applying forces to the graph
  222. *
  223. * @param e
  224. */
  225. connection.onmessage = function (e)
  226. {
  227. var request = JSON.parse(e.data);
  228. if(request.action == 1)
  229. {
  230. setTimeout(function()
  231. {
  232. addNodeToGraph(request);
  233. connection.send("{go:1}");
  234. }, 0);
  235. }
  236. else if(request.action == 2)
  237. {
  238. setTimeout(function()
  239. {
  240. addEdgeToGraph(request);
  241. connection.send("{go:1}");
  242. }, 0);
  243. }
  244. else if(request.action == 3) {
  245. s.startForceAtlas2({worker: true, barnesHutOptimize: false,
  246. scalingRatio: 3, slowDown: 5, gravity: 20});
  247. setTimeout(function () {
  248. s.stopForceAtlas2();
  249. }, 30000);
  250. }
  251. };
  252. /**
  253. * jquery stuff for hiding and displaying users when clicked
  254. */
  255. s.bind('clickNode doubleClickNode rightClickNode', function(e)
  256. {
  257. $('.sigma-node, .sigma-edge').each(function()
  258. {
  259. mute(this);
  260. });
  261. var neighbors = s.graph.neighborhood(e.data.node.id);
  262. neighbors.nodes.forEach(function(node)
  263. {
  264. unmute($('[data-node-id="' + node.id + '"]')[0]);
  265. });
  266. neighbors.edges.forEach(function(edge) {
  267. unmute($('[data-edge-id="' + edge.id + '"]')[0]);
  268. });
  269. });
  270. // Binding silly interactions
  271. function mute(node)
  272. {
  273. if (!~node.getAttribute('class').search(/muted/))
  274. node.setAttributeNS(null, 'class',
  275. node.getAttribute('class') + ' muted');
  276. }
  277. function unmute(node)
  278. {
  279. node.setAttributeNS(null, 'class',
  280. node.getAttribute('class').replace(/(\s|^)muted(\s|$)/g, '$2'));
  281. }
  282. $('.sigma-node').click(function()
  283. {
  284. $('.sigma-node, .sigma-edge').each(function()
  285. {
  286. mute(this);
  287. });
  288. // Unmuting neighbors
  289. var neighbors = s.graph.neighborhood($(this).attr('data-node-id'));
  290. neighbors.nodes.forEach(function(node)
  291. {
  292. unmute($('[data-node-id="' + node.id + '"]')[0]);
  293. });
  294. neighbors.edges.forEach(function(edge)
  295. {
  296. unmute($('[data-edge-id="' + edge.id + '"]')[0]);
  297. });
  298. });
  299. s.bind('clickStage', function()
  300. {
  301. $('.sigma-node, .sigma-edge').each(function()
  302. {
  303. unmute(this);
  304. });
  305. });
  306. </script>
  307. <!-
  308. ┈┈╱▔▔▔▔▔╲┈┈┈HM┈HM
  309. ┈╱┈┈╱▔╲╲╲▏┈┈┈HMMM
  310. ╱┈┈╱━╱▔▔▔▔▔╲━╮┈┈
  311. ▏┈▕┃▕╱▔╲╱▔╲▕╮┃┈┈
  312. ▏┈▕╰━▏▊▕▕▋▕▕━╯┈┈
  313. ╲┈┈╲╱▔╭╮▔▔┳╲╲┈┈┈
  314. ┈╲┈┈▏╭━━━━╯▕▕┈┈┈
  315. ┈┈╲┈╲▂▂▂▂▂▂╱╱┈┈┈
  316. ┈┈┈┈▏┊┈┈┈┈┊┈┈┈╲┈
  317. ┈┈┈┈▏┊┈┈┈┈┊▕╲┈┈╲
  318. ┈╱▔╲▏┊┈┈┈┈┊▕╱▔╲▕
  319. ┈▏ ┈┈┈╰┈┈┈┈╯┈┈┈▕▕
  320. ┈╲┈┈┈╲┈┈┈┈╱┈┈┈╱┈╲
  321. ┈┈╲┈┈▕▔▔▔▔▏┈┈╱╲╲╲▏
  322. ┈╱▔┈┈▕┈┈┈┈▏┈┈▔╲▔▔
  323. ┈╲▂▂▂╱┈┈┈┈╲▂▂▂╱┈
  324. If you are seeing this monkey that means that you are interested in my
  325. code. Yay!! If you are not here to hack me ... you should really consider
  326. contributing to some of my public projects on github.
  327. https://github.com/jrtechs
  328. -->
  329. <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
  330. <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
  331. </body>
  332. </html>