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.

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