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.

432 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. </style>
  130. <div id="graph-container" style="width:100%; height:100%"></div>
  131. </div>
  132. <script>
  133. var s;
  134. var g = {
  135. nodes: [],
  136. edges: []
  137. };
  138. /**
  139. * Creates a new sigma graph
  140. */
  141. s = new sigma({
  142. graph: g,
  143. settings: {
  144. enableHovering: false
  145. }
  146. });
  147. /**
  148. * Sets the sigma graph to render using svg
  149. */
  150. s.addRenderer({
  151. id: 'main',
  152. type: 'svg',
  153. container: document.getElementById('graph-container'),
  154. freeStyle: true
  155. });
  156. /**
  157. * Simple function to get the get data from the url
  158. */
  159. function getUrlVars()
  160. {
  161. var vars = {};
  162. window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,
  163. function(m,key,value) {
  164. vars[key] = value;
  165. });
  166. return vars;
  167. }
  168. /** Web socket to communicate with the steam friend java server */
  169. connection = new WebSocket('ws://steam.student.rit.edu:4444');
  170. setTimeout(function()
  171. {
  172. if (this.connection.readyState != 1)
  173. {
  174. document.location.href = "error.html";
  175. }
  176. }, 6000);
  177. /**
  178. * When the web socket is opened, this function
  179. * fetches the get data and requests the server
  180. * to start giving it graph information
  181. */
  182. connection.onopen = function ()
  183. {
  184. var getData = getUrlVars();
  185. if(getData["id"] != undefined && getData["id"] != "")
  186. {
  187. connection.send("{id:'" + getData["id"] + "', graph:" +
  188. getData["graph"] + "}");
  189. connection.send("{go:1}");
  190. }
  191. else
  192. {
  193. connection.close();
  194. }
  195. };
  196. /**
  197. * Logs any errors with the web socket -- usually error
  198. * connecting to the server
  199. * @param error
  200. */
  201. connection.onerror = function (error)
  202. {
  203. console.log('WebSocket Error ' + error);
  204. };
  205. /**
  206. * Helper function to add a new node to the sigma graph
  207. *
  208. * @param request
  209. */
  210. function addNodeToGraph(request)
  211. {
  212. if(s.graph.nodes(request.id) == undefined)
  213. {
  214. s.graph.addNode({
  215. id: request.id,
  216. label: request.name,
  217. x: request.x,
  218. y: request.y,
  219. size: request.size
  220. });
  221. s.refresh();
  222. }
  223. }
  224. /**
  225. * Helper function to add an edge between two nodes on the
  226. * sigma graph
  227. *
  228. * @param request
  229. */
  230. function addEdgeToGraph(request)
  231. {
  232. s.graph.addEdge({
  233. id: request.id,
  234. source: request.p1,
  235. target: request.p2,
  236. size: 1
  237. });
  238. s.refresh();
  239. }
  240. /**
  241. * Parses any events from the server
  242. * action 1: add a new node to the graph
  243. * action 2: add a new edge to the graph
  244. * action 3: start applying forces to the graph
  245. *
  246. * @param e
  247. */
  248. connection.onmessage = function (e)
  249. {
  250. var request = JSON.parse(e.data);
  251. if(request.action == 1)
  252. {
  253. setTimeout(function()
  254. {
  255. addNodeToGraph(request);
  256. connection.send("{go:1}");
  257. }, 0);
  258. }
  259. else if(request.action == 2)
  260. {
  261. setTimeout(function()
  262. {
  263. addEdgeToGraph(request);
  264. connection.send("{go:1}");
  265. }, 0);
  266. }
  267. else if(request.action == 3)
  268. {
  269. var getData = getUrlVars();
  270. if(getData["graph"] == 2)
  271. {
  272. s.startForceAtlas2({worker: true, barnesHutOptimize: false,
  273. scalingRatio: 3, slowDown: 5, gravity: 10});
  274. setTimeout(function () {
  275. s.stopForceAtlas2();
  276. }, 15000);
  277. }
  278. else
  279. {
  280. s.startForceAtlas2({worker: true, barnesHutOptimize: false,
  281. scalingRatio: 6, slowDown: 4, gravity: 40});
  282. setTimeout(function () {
  283. s.stopForceAtlas2();
  284. }, 30000);
  285. }
  286. }
  287. else if(request.action == -1)
  288. {
  289. alert("The provided steamID was invalid.");
  290. }
  291. };
  292. // Binding silly interactions
  293. function mute(node)
  294. {
  295. if (!~node.getAttribute('class').search(/muted/))
  296. node.setAttributeNS(null, 'class',
  297. node.getAttribute('class') + ' muted');
  298. }
  299. function unmute(node)
  300. {
  301. node.setAttributeNS(null, 'class',
  302. node.getAttribute('class').replace(/(\s|^)muted(\s|$)/g, '$2'));
  303. }
  304. /**
  305. * jquery stuff for hiding and displaying users when clicked
  306. */
  307. s.bind('clickNode doubleClickNode rightClickNode', function(e)
  308. {
  309. $('.sigma-node, .sigma-edge, .sigma-label').each(function()
  310. {
  311. mute(this);
  312. });
  313. var neighbors = s.graph.neighborhood(e.data.node.id);
  314. neighbors.nodes.forEach(function(node)
  315. {
  316. unmute($('[data-node-id="' + node.id + '"]')[0]);
  317. unmute($('[data-label-target="' + node.id + '"]')[0]);
  318. });
  319. neighbors.edges.forEach(function(edge) {
  320. unmute($('[data-edge-id="' + edge.id + '"]')[0]);
  321. });
  322. });
  323. $('.sigma-node').click(function()
  324. {
  325. $('.sigma-node, .sigma-edge').each(function()
  326. {
  327. mute(this);
  328. });
  329. // Unmuting neighbors
  330. var neighbors = s.graph.neighborhood($(this).attr('data-node-id'));
  331. neighbors.nodes.forEach(function(node)
  332. {
  333. unmute($('[data-node-id="' + node.id + '"]')[0]);
  334. unmute($('[data-label-target="' + node.id + '"]')[0]);
  335. });
  336. neighbors.edges.forEach(function(edge)
  337. {
  338. unmute($('[data-edge-id="' + edge.id + '"]')[0]);
  339. });
  340. });
  341. s.bind('clickStage', function()
  342. {
  343. $('.sigma-node, .sigma-edge, .sigma-label').each(function()
  344. {
  345. unmute(this);
  346. });
  347. });
  348. </script>
  349. <!-
  350. ┈┈╱▔▔▔▔▔╲┈┈┈HM┈HM
  351. ┈╱┈┈╱▔╲╲╲▏┈┈┈HMMM
  352. ╱┈┈╱━╱▔▔▔▔▔╲━╮┈┈
  353. ▏┈▕┃▕╱▔╲╱▔╲▕╮┃┈┈
  354. ▏┈▕╰━▏▊▕▕▋▕▕━╯┈┈
  355. ╲┈┈╲╱▔╭╮▔▔┳╲╲┈┈┈
  356. ┈╲┈┈▏╭━━━━╯▕▕┈┈┈
  357. ┈┈╲┈╲▂▂▂▂▂▂╱╱┈┈┈
  358. ┈┈┈┈▏┊┈┈┈┈┊┈┈┈╲┈
  359. ┈┈┈┈▏┊┈┈┈┈┊▕╲┈┈╲
  360. ┈╱▔╲▏┊┈┈┈┈┊▕╱▔╲▕
  361. ┈▏ ┈┈┈╰┈┈┈┈╯┈┈┈▕▕
  362. ┈╲┈┈┈╲┈┈┈┈╱┈┈┈╱┈╲
  363. ┈┈╲┈┈▕▔▔▔▔▏┈┈╱╲╲╲▏
  364. ┈╱▔┈┈▕┈┈┈┈▏┈┈▔╲▔▔
  365. ┈╲▂▂▂╱┈┈┈┈╲▂▂▂╱┈
  366. If you are seeing this monkey that means that you are interested in my
  367. code. Yay!! If you are not here to hack me ... you should really consider
  368. contributing to some of my public projects on github.
  369. https://github.com/jrtechs
  370. -->
  371. <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>
  372. <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
  373. </body>
  374. </html>