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.

391 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. <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
  63. <a class="navbar-brand" href="#">Steam Graph Project</a>
  64. <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
  65. <span class="navbar-toggler-icon"></span>
  66. </button>
  67. <div class="collapse navbar-collapse" id="navbarSupportedContent">
  68. <ul class="navbar-nav mr-auto">
  69. <li class="nav-item">
  70. <a class="nav-link" href="index.html">Home</a>
  71. </li>
  72. <li class="nav-item">
  73. <a class="nav-link" href="graphs.html">Graphs<span class="sr-only">(current)</span></a>
  74. </li>
  75. <li class="nav-item">
  76. <a class="nav-link" href="profile.html">Profile Look-Up</a>
  77. </li>
  78. <li class="nav-item">
  79. <a class="nav-link" href="faq.html">FAQ</a>
  80. </li>
  81. </ul>
  82. <ul class="nav navbar-nav navbar-right">
  83. <li>
  84. <a class="nav-link" href="https://jrtechs.net">Blog</a>
  85. </li>
  86. <li>
  87. <a class="nav-link" href="https://jrtechs.me">Resume</a>
  88. </li>
  89. <li>
  90. <a class="nav-link" href="https://github.com/jrtechs">Github</a>
  91. </li>
  92. </ul>
  93. </div>
  94. </nav>
  95. <!-- END SIGMA IMPORTS -->
  96. <div id="container">
  97. <style>
  98. #graph-container {
  99. top: 0;
  100. bottom: 0;
  101. left: 0;
  102. right: 0;
  103. position: absolute;
  104. /*background-color: #455660;*/
  105. }
  106. .sigma-node:hover {
  107. fill: blue;
  108. }
  109. .muted {
  110. fill-opacity: 0.1;
  111. stroke-opacity: 0.1;
  112. font-size: 0;
  113. }
  114. </style>
  115. <div id="graph-container" style="width:100%; height:100%"></div>
  116. </div>
  117. <script>
  118. var s,
  119. g = {
  120. nodes: [],
  121. edges: []
  122. },
  123. colors = [
  124. '#4281a4',
  125. '#5da9e9',
  126. '#003f91',
  127. '#b793ae',
  128. '#6d326d'
  129. ];
  130. /**
  131. * Creates a new sigma graph
  132. */
  133. s = new sigma({
  134. graph: g,
  135. settings: {
  136. enableHovering: false
  137. }
  138. });
  139. /**
  140. * Sets the sigma graph to render using svg
  141. */
  142. s.addRenderer({
  143. id: 'main',
  144. type: 'svg',
  145. container: document.getElementById('graph-container'),
  146. freeStyle: true
  147. });
  148. /**
  149. * Simple function to get the get data from the url
  150. */
  151. function getUrlVars()
  152. {
  153. var vars = {};
  154. window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,
  155. function(m,key,value) {
  156. vars[key] = value;
  157. });
  158. return vars;
  159. }
  160. /** Web socket to communicate with the steam friend java server */
  161. connection = new WebSocket('ws://localhost:4444');
  162. /**
  163. * When the web socket is opened, this function
  164. * fetches the get data and requests the server
  165. * to start giving it graph information
  166. */
  167. connection.onopen = function ()
  168. {
  169. var getData = getUrlVars();
  170. if(getData["id"] != undefined && getData["id"] != "")
  171. {
  172. connection.send("{id:'" + getData["id"] + "', graph:" +
  173. getData["graph"] + "}");
  174. connection.send("{go:1}");
  175. }
  176. else
  177. {
  178. connection.close();
  179. }
  180. };
  181. /**
  182. * Logs any errors with the web socket -- usually error
  183. * connecting to the server
  184. * @param error
  185. */
  186. connection.onerror = function (error)
  187. {
  188. console.log('WebSocket Error ' + error);
  189. };
  190. /**
  191. * Helper function to add a new node to the sigma graph
  192. *
  193. * @param request
  194. */
  195. function addNodeToGraph(request)
  196. {
  197. if(s.graph.nodes(request.id) == undefined)
  198. {
  199. s.graph.addNode({
  200. id: request.id,
  201. label: request.name,
  202. x: request.x,
  203. y: request.y,
  204. size: request.size,
  205. color: colors[Math.floor(Math.random() * colors.length)]
  206. });
  207. s.refresh();
  208. }
  209. }
  210. /**
  211. * Helper function to add an edge between two nodes on the
  212. * sigma graph
  213. *
  214. * @param request
  215. */
  216. function addEdgeToGraph(request)
  217. {
  218. s.graph.addEdge({
  219. id: request.id,
  220. source: request.p1,
  221. target: request.p2,
  222. size: 1
  223. });
  224. s.refresh();
  225. }
  226. /**
  227. * Parses any events from the server
  228. * action 1: add a new node to the graph
  229. * action 2: add a new edge to the graph
  230. * action 3: start applying forces to the graph
  231. *
  232. * @param e
  233. */
  234. connection.onmessage = function (e)
  235. {
  236. var request = JSON.parse(e.data);
  237. if(request.action == 1)
  238. {
  239. setTimeout(function()
  240. {
  241. addNodeToGraph(request);
  242. connection.send("{go:1}");
  243. }, 0);
  244. }
  245. else if(request.action == 2)
  246. {
  247. setTimeout(function()
  248. {
  249. addEdgeToGraph(request);
  250. connection.send("{go:1}");
  251. }, 0);
  252. }
  253. else if(request.action == 3) {
  254. s.startForceAtlas2({worker: true, barnesHutOptimize: false,
  255. scalingRatio: 3, slowDown: 5, gravity: 20});
  256. setTimeout(function () {
  257. s.stopForceAtlas2();
  258. }, 30000);
  259. }
  260. };
  261. /**
  262. * jquery stuff for hiding and displaying users when clicked
  263. */
  264. s.bind('clickNode doubleClickNode rightClickNode', function(e)
  265. {
  266. $('.sigma-node, .sigma-edge').each(function()
  267. {
  268. mute(this);
  269. });
  270. var neighbors = s.graph.neighborhood(e.data.node.id);
  271. neighbors.nodes.forEach(function(node)
  272. {
  273. unmute($('[data-node-id="' + node.id + '"]')[0]);
  274. });
  275. neighbors.edges.forEach(function(edge) {
  276. unmute($('[data-edge-id="' + edge.id + '"]')[0]);
  277. });
  278. });
  279. // Binding silly interactions
  280. function mute(node)
  281. {
  282. if (!~node.getAttribute('class').search(/muted/))
  283. node.setAttributeNS(null, 'class',
  284. node.getAttribute('class') + ' muted');
  285. }
  286. function unmute(node)
  287. {
  288. node.setAttributeNS(null, 'class',
  289. node.getAttribute('class').replace(/(\s|^)muted(\s|$)/g, '$2'));
  290. }
  291. $('.sigma-node').click(function()
  292. {
  293. $('.sigma-node, .sigma-edge').each(function()
  294. {
  295. mute(this);
  296. });
  297. // Unmuting neighbors
  298. var neighbors = s.graph.neighborhood($(this).attr('data-node-id'));
  299. neighbors.nodes.forEach(function(node)
  300. {
  301. unmute($('[data-node-id="' + node.id + '"]')[0]);
  302. });
  303. neighbors.edges.forEach(function(edge)
  304. {
  305. unmute($('[data-edge-id="' + edge.id + '"]')[0]);
  306. });
  307. });
  308. s.bind('clickStage', function()
  309. {
  310. $('.sigma-node, .sigma-edge').each(function()
  311. {
  312. unmute(this);
  313. });
  314. });
  315. </script>
  316. <!-
  317. ┈┈╱▔▔▔▔▔╲┈┈┈HM┈HM
  318. ┈╱┈┈╱▔╲╲╲▏┈┈┈HMMM
  319. ╱┈┈╱━╱▔▔▔▔▔╲━╮┈┈
  320. ▏┈▕┃▕╱▔╲╱▔╲▕╮┃┈┈
  321. ▏┈▕╰━▏▊▕▕▋▕▕━╯┈┈
  322. ╲┈┈╲╱▔╭╮▔▔┳╲╲┈┈┈
  323. ┈╲┈┈▏╭━━━━╯▕▕┈┈┈
  324. ┈┈╲┈╲▂▂▂▂▂▂╱╱┈┈┈
  325. ┈┈┈┈▏┊┈┈┈┈┊┈┈┈╲┈
  326. ┈┈┈┈▏┊┈┈┈┈┊▕╲┈┈╲
  327. ┈╱▔╲▏┊┈┈┈┈┊▕╱▔╲▕
  328. ┈▏ ┈┈┈╰┈┈┈┈╯┈┈┈▕▕
  329. ┈╲┈┈┈╲┈┈┈┈╱┈┈┈╱┈╲
  330. ┈┈╲┈┈▕▔▔▔▔▏┈┈╱╲╲╲▏
  331. ┈╱▔┈┈▕┈┈┈┈▏┈┈▔╲▔▔
  332. ┈╲▂▂▂╱┈┈┈┈╲▂▂▂╱┈
  333. If you are seeing this monkey that means that you are interested in my
  334. code. Yay!! If you are not here to hack me ... you should really consider
  335. contributing to some of my public projects on github.
  336. https://github.com/jrtechs
  337. -->
  338. <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>
  339. <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
  340. </body>
  341. </html>