{"action":"created","comment":{"url":"https://api.github.com/repos/gambitproject/jsgte/pulls/comments/30366807","id":30366807,"diff_hunk":"@@ -0,0 +1,195 @@\n+GAMBIT.TREE = (function (parentModule) {\n+    \"use strict\";\n+\n+    /**\n+    * Creates a new Tree.\n+    * @class\n+    * @param {Node} root Root node for the tree\n+    */\n+    function Tree(root) {\n+        this.root = root;\n+        this.positionsUpdated = false;\n+    }\n+\n+    /**\n+    * Function that draws the Game in the global canvas starting from a node\n+    * Takes care of updating the positions, clearing the canvas and drawing in it\n+    */\n+    Tree.prototype.draw = function(){\n+        if (!this.positionsUpdated) {\n+            this.updatePositions();\n+        }\n+        GAMBIT.canvas.clear();\n+        this.recursiveDraw();\n+    };\n+\n+    /**\n+    * Recursive function that draws the Game in the global canvas starting from a node\n+    * If no param is given it will start from root\n+    * Stopping criteria: that the current node is a leaf\n+    * Recursive expansion: to all of the node's children\n+    * @param {Node} [node] Node to start drawing from\n+    */\n+    Tree.prototype.recursiveDraw = function (node) {\n+        // In case there is no arguments start from root\n+        if (node === undefined) { node = this.root; }\n+\n+        if (!node.isLeaf()) {\n+            for (var i = 0; i < node.children.length; i++) {\n+                this.drawLineBetweenNodes(node, node.children[i]);\n+                this.recursiveDraw(node.children[i]);\n+            }\n+        }\n+        node.draw();\n+    };\n+\n+    /**\n+    * Function that draws a line between two given nodes\n+    * @param {Node} node1 Node A\n+    * @param {Node} node2 Node B\n+    */\n+    Tree.prototype.drawLineBetweenNodes = function(node1, node2){\n+        var circleRadius = GAMBIT.CONSTANTS.CIRCLE_SIZE/2;\n+        GAMBIT.canvas.line(node1.x + circleRadius, node1.y + circleRadius, node2.x + circleRadius, node2.y +circleRadius).stroke({ width: 1 });\n+    };\n+\n+    /**\n+    * Function that returns the number of leaves in the tree\n+    * @return {Number} leafCounter Number of Leaves\n+    */\n+    Tree.prototype.numberLeaves = function () {\n+        this.leaves = [];\n+        return this.recursiveNumberLeaves(this.root);\n+    };\n+\n+\n+    /**\n+    * Recursive function that returns the number of leaves below a determinate node\n+    * Leaves positions are updated in a different function.\n+    * Stopping criteria: that the current node is a leaf\n+    * Recursive expansion: to all of the node's children\n+    * @param    {Node}      node        Node to start from\n+    * @return   {Number}    leafCounter Number of Leaves\n+    */\n+    Tree.prototype.recursiveNumberLeaves = function (node) {\n+        if (node.isLeaf()) {\n+            this.leaves.push(node);\n+            return 1;\n+        } else {\n+            var leafCounter = 0;\n+            for (var i = 0; i < node.children.length; i++) {\n+                leafCounter += this.recursiveNumberLeaves(node.children[i]);\n+            }\n+            return leafCounter;\n+        }\n+    };\n+\n+    /**\n+    * Function that updates the positions of the nodes in the tree\n+    */\n+    Tree.prototype.updatePositions = function () {\n+        this.updateLeavesPositions();\n+        this.recursiveUpdatePositions(this.root);\n+        this.positionsUpdated = true;\n+    };\n+\n+    /**\n+    * Recursive function that updates the positions of the node children.\n+    * Leaves positions are updated in a different function.\n+    * Stopping criteria: that the current node is a leaf\n+    * Recursive expansion: to all of the node's children\n+    * @param {Node} node Node that will get their children's positions updated\n+    */\n+    Tree.prototype.recursiveUpdatePositions = function (node) {\n+        if (!node.isLeaf()) {\n+            for (var i = 0; i < node.children.length; i++) {\n+                this.recursiveUpdatePositions(node.children[i]);\n+            }\n+            // Get middle point between the children most in the left and most\n+            // in the right\n+            // TODO: apply level weighted function for special cases\n+            node.x = node.children[0].x +\n+                (node.children[node.children.length-1].x - node.children[0].x)/2;\n+            node.y = node.level * GAMBIT.CONSTANTS.DIST_BETWEEN_LEVELS;\n+        }\n+    };\n+\n+    /**\n+    * Updates the positions (x and y) of the Tree leaves\n+    */\n+    Tree.prototype.updateLeavesPositions = function () {\n+        var numberLeaves = this.numberLeaves();\n+        var widthPerNode = GAMBIT.canvas.viewbox().width/numberLeaves;\n+        if (widthPerNode < GAMBIT.CONSTANTS.CIRCLE_SIZE) {\n+            this.zoomOut();\n+            this.updateLeavesPositions();\n+        } else {\n+            for (var i = 0; i < numberLeaves; i++) {\n+                this.leaves[i].x = (widthPerNode*i)+(widthPerNode/2) -\n+                                        GAMBIT.CONSTANTS.CIRCLE_SIZE/2;\n+                this.leaves[i].y = this.leaves[i].level * GAMBIT.CONSTANTS.DIST_BETWEEN_LEVELS;\n+            }\n+        }\n+    };\n+\n+    /**\n+    * Adds a child to a given node\n+    * @param  {Node} parentNode Node that will get a new child\n+    * @return {Node} newNode    Node that has been added\n+    */\n+    Tree.prototype.addChildNodeTo = function (parentNode) {\n+        var newNode = new GAMBIT.TREE.Node(parentNode);\n+        if ((newNode.y + GAMBIT.CONSTANTS.CIRCLE_SIZE) > GAMBIT.canvas.viewbox().height) {\n+            this.zoomOut();\n+        }\n+        this.positionsUpdated = false;\n+        return newNode;\n+    };\n+\n+    /**\n+     * Function that deletes the node. It changes children's parent to their\n+     * grandparent.\n+     * @param {Node} nodeToDelete Node to be deleted\n+     */\n+    Tree.prototype.deleteNode = function (nodeToDelete) {\n+        // Check if it has children\n+        if (!nodeToDelete.isLeaf()) {\n+            // Change parent of children to own parent\n+            for (var i=0; i < nodeToDelete.children.length; i++) {\n+                nodeToDelete.children[i].changeFather(nodeToDelete.parent);","path":"html/js/tree/Tree.js","position":159,"original_position":159,"commit_id":"287f8e223046b7eb54a24d5c5d02c199525346bc","original_commit_id":"287f8e223046b7eb54a24d5c5d02c199525346bc","user":{"login":"alfongj","id":822670,"avatar_url":"https://avatars.githubusercontent.com/u/822670?v=3","gravatar_id":"","url":"https://api.github.com/users/alfongj","html_url":"https://github.com/alfongj","followers_url":"https://api.github.com/users/alfongj/followers","following_url":"https://api.github.com/users/alfongj/following{/other_user}","gists_url":"https://api.github.com/users/alfongj/gists{/gist_id}","starred_url":"https://api.github.com/users/alfongj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alfongj/subscriptions","organizations_url":"https://api.github.com/users/alfongj/orgs","repos_url":"https://api.github.com/users/alfongj/repos","events_url":"https://api.github.com/users/alfongj/events{/privacy}","received_events_url":"https://api.github.com/users/alfongj/received_events","type":"User","site_admin":false},"body":"r/changeFather/changeParent","created_at":"2015-05-14T21:47:29Z","updated_at":"2015-05-14T21:47:29Z","html_url":"https://github.com/gambitproject/jsgte/pull/5#discussion_r30366807","pull_request_url":"https://api.github.com/repos/gambitproject/jsgte/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/gambitproject/jsgte/pulls/comments/30366807"},"html":{"href":"https://github.com/gambitproject/jsgte/pull/5#discussion_r30366807"},"pull_request":{"href":"https://api.github.com/repos/gambitproject/jsgte/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/gambitproject/jsgte/pulls/5","id":35251514,"html_url":"https://github.com/gambitproject/jsgte/pull/5","diff_url":"https://github.com/gambitproject/jsgte/pull/5.diff","patch_url":"https://github.com/gambitproject/jsgte/pull/5.patch","issue_url":"https://api.github.com/repos/gambitproject/jsgte/issues/5","number":5,"state":"open","locked":false,"title":"Bootstrap","user":{"login":"vegaro","id":664544,"avatar_url":"https://avatars.githubusercontent.com/u/664544?v=3","gravatar_id":"","url":"https://api.github.com/users/vegaro","html_url":"https://github.com/vegaro","followers_url":"https://api.github.com/users/vegaro/followers","following_url":"https://api.github.com/users/vegaro/following{/other_user}","gists_url":"https://api.github.com/users/vegaro/gists{/gist_id}","starred_url":"https://api.github.com/users/vegaro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vegaro/subscriptions","organizations_url":"https://api.github.com/users/vegaro/orgs","repos_url":"https://api.github.com/users/vegaro/repos","events_url":"https://api.github.com/users/vegaro/events{/privacy}","received_events_url":"https://api.github.com/users/vegaro/received_events","type":"User","site_admin":false},"body":"- Creates all classes needed for basic functionality\r\n- Uses [normalize.css] (https://github.com/necolas/normalize.css) so that styles are as expected in all browsers.\r\n- Used [svg.js] (https://github.com/wout/svg.js) for faster development. It is a really lightweight javascript function with basic SVG functions like creating a canvas, circles and lines. It does not have dependencies either.\r\n- User can create a tree, and add/delete nodes.\r\n- Canvas is zoomed out when nodes don't fit inside.\r\n- Canvas is full screen and there is only one scroll bar.\r\n- Creates basic toolbar with new, add and delete buttons.\r\n- Code is documented by using JSDoc syntax as suggested by [Google Javascript Style Guide] (https://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml)","created_at":"2015-05-12T17:41:24Z","updated_at":"2015-05-14T21:47:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1b3e9b47db31913d4a508d06bbaf8d9841227b87","assignee":{"login":"stengel","id":798638,"avatar_url":"https://avatars.githubusercontent.com/u/798638?v=3","gravatar_id":"","url":"https://api.github.com/users/stengel","html_url":"https://github.com/stengel","followers_url":"https://api.github.com/users/stengel/followers","following_url":"https://api.github.com/users/stengel/following{/other_user}","gists_url":"https://api.github.com/users/stengel/gists{/gist_id}","starred_url":"https://api.github.com/users/stengel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stengel/subscriptions","organizations_url":"https://api.github.com/users/stengel/orgs","repos_url":"https://api.github.com/users/stengel/repos","events_url":"https://api.github.com/users/stengel/events{/privacy}","received_events_url":"https://api.github.com/users/stengel/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/gambitproject/jsgte/pulls/5/commits","review_comments_url":"https://api.github.com/repos/gambitproject/jsgte/pulls/5/comments","review_comment_url":"https://api.github.com/repos/gambitproject/jsgte/pulls/comments{/number}","comments_url":"https://api.github.com/repos/gambitproject/jsgte/issues/5/comments","statuses_url":"https://api.github.com/repos/gambitproject/jsgte/statuses/287f8e223046b7eb54a24d5c5d02c199525346bc","head":{"label":"gambitproject:bootstrap","ref":"bootstrap","sha":"287f8e223046b7eb54a24d5c5d02c199525346bc","user":{"login":"gambitproject","id":771825,"avatar_url":"https://avatars.githubusercontent.com/u/771825?v=3","gravatar_id":"","url":"https://api.github.com/users/gambitproject","html_url":"https://github.com/gambitproject","followers_url":"https://api.github.com/users/gambitproject/followers","following_url":"https://api.github.com/users/gambitproject/following{/other_user}","gists_url":"https://api.github.com/users/gambitproject/gists{/gist_id}","starred_url":"https://api.github.com/users/gambitproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gambitproject/subscriptions","organizations_url":"https://api.github.com/users/gambitproject/orgs","repos_url":"https://api.github.com/users/gambitproject/repos","events_url":"https://api.github.com/users/gambitproject/events{/privacy}","received_events_url":"https://api.github.com/users/gambitproject/received_events","type":"Organization","site_admin":false},"repo":{"id":31477644,"name":"jsgte","full_name":"gambitproject/jsgte","owner":{"login":"gambitproject","id":771825,"avatar_url":"https://avatars.githubusercontent.com/u/771825?v=3","gravatar_id":"","url":"https://api.github.com/users/gambitproject","html_url":"https://github.com/gambitproject","followers_url":"https://api.github.com/users/gambitproject/followers","following_url":"https://api.github.com/users/gambitproject/following{/other_user}","gists_url":"https://api.github.com/users/gambitproject/gists{/gist_id}","starred_url":"https://api.github.com/users/gambitproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gambitproject/subscriptions","organizations_url":"https://api.github.com/users/gambitproject/orgs","repos_url":"https://api.github.com/users/gambitproject/repos","events_url":"https://api.github.com/users/gambitproject/events{/privacy}","received_events_url":"https://api.github.com/users/gambitproject/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/gambitproject/jsgte","description":"JavaScript GTE","fork":false,"url":"https://api.github.com/repos/gambitproject/jsgte","forks_url":"https://api.github.com/repos/gambitproject/jsgte/forks","keys_url":"https://api.github.com/repos/gambitproject/jsgte/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gambitproject/jsgte/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gambitproject/jsgte/teams","hooks_url":"https://api.github.com/repos/gambitproject/jsgte/hooks","issue_events_url":"https://api.github.com/repos/gambitproject/jsgte/issues/events{/number}","events_url":"https://api.github.com/repos/gambitproject/jsgte/events","assignees_url":"https://api.github.com/repos/gambitproject/jsgte/assignees{/user}","branches_url":"https://api.github.com/repos/gambitproject/jsgte/branches{/branch}","tags_url":"https://api.github.com/repos/gambitproject/jsgte/tags","blobs_url":"https://api.github.com/repos/gambitproject/jsgte/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gambitproject/jsgte/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gambitproject/jsgte/git/refs{/sha}","trees_url":"https://api.github.com/repos/gambitproject/jsgte/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gambitproject/jsgte/statuses/{sha}","languages_url":"https://api.github.com/repos/gambitproject/jsgte/languages","stargazers_url":"https://api.github.com/repos/gambitproject/jsgte/stargazers","contributors_url":"https://api.github.com/repos/gambitproject/jsgte/contributors","subscribers_url":"https://api.github.com/repos/gambitproject/jsgte/subscribers","subscription_url":"https://api.github.com/repos/gambitproject/jsgte/subscription","commits_url":"https://api.github.com/repos/gambitproject/jsgte/commits{/sha}","git_commits_url":"https://api.github.com/repos/gambitproject/jsgte/git/commits{/sha}","comments_url":"https://api.github.com/repos/gambitproject/jsgte/comments{/number}","issue_comment_url":"https://api.github.com/repos/gambitproject/jsgte/issues/comments{/number}","contents_url":"https://api.github.com/repos/gambitproject/jsgte/contents/{+path}","compare_url":"https://api.github.com/repos/gambitproject/jsgte/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gambitproject/jsgte/merges","archive_url":"https://api.github.com/repos/gambitproject/jsgte/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gambitproject/jsgte/downloads","issues_url":"https://api.github.com/repos/gambitproject/jsgte/issues{/number}","pulls_url":"https://api.github.com/repos/gambitproject/jsgte/pulls{/number}","milestones_url":"https://api.github.com/repos/gambitproject/jsgte/milestones{/number}","notifications_url":"https://api.github.com/repos/gambitproject/jsgte/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gambitproject/jsgte/labels{/name}","releases_url":"https://api.github.com/repos/gambitproject/jsgte/releases{/id}","created_at":"2015-02-28T21:36:36Z","updated_at":"2015-04-01T12:45:23Z","pushed_at":"2015-05-14T21:23:54Z","git_url":"git://github.com/gambitproject/jsgte.git","ssh_url":"git@github.com:gambitproject/jsgte.git","clone_url":"https://github.com/gambitproject/jsgte.git","svn_url":"https://github.com/gambitproject/jsgte","homepage":null,"size":432,"stargazers_count":1,"watchers_count":1,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":1,"default_branch":"master"}},"base":{"label":"gambitproject:master","ref":"master","sha":"fce59a65015358683751511ad703fc3598fd799e","user":{"login":"gambitproject","id":771825,"avatar_url":"https://avatars.githubusercontent.com/u/771825?v=3","gravatar_id":"","url":"https://api.github.com/users/gambitproject","html_url":"https://github.com/gambitproject","followers_url":"https://api.github.com/users/gambitproject/followers","following_url":"https://api.github.com/users/gambitproject/following{/other_user}","gists_url":"https://api.github.com/users/gambitproject/gists{/gist_id}","starred_url":"https://api.github.com/users/gambitproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gambitproject/subscriptions","organizations_url":"https://api.github.com/users/gambitproject/orgs","repos_url":"https://api.github.com/users/gambitproject/repos","events_url":"https://api.github.com/users/gambitproject/events{/privacy}","received_events_url":"https://api.github.com/users/gambitproject/received_events","type":"Organization","site_admin":false},"repo":{"id":31477644,"name":"jsgte","full_name":"gambitproject/jsgte","owner":{"login":"gambitproject","id":771825,"avatar_url":"https://avatars.githubusercontent.com/u/771825?v=3","gravatar_id":"","url":"https://api.github.com/users/gambitproject","html_url":"https://github.com/gambitproject","followers_url":"https://api.github.com/users/gambitproject/followers","following_url":"https://api.github.com/users/gambitproject/following{/other_user}","gists_url":"https://api.github.com/users/gambitproject/gists{/gist_id}","starred_url":"https://api.github.com/users/gambitproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gambitproject/subscriptions","organizations_url":"https://api.github.com/users/gambitproject/orgs","repos_url":"https://api.github.com/users/gambitproject/repos","events_url":"https://api.github.com/users/gambitproject/events{/privacy}","received_events_url":"https://api.github.com/users/gambitproject/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/gambitproject/jsgte","description":"JavaScript GTE","fork":false,"url":"https://api.github.com/repos/gambitproject/jsgte","forks_url":"https://api.github.com/repos/gambitproject/jsgte/forks","keys_url":"https://api.github.com/repos/gambitproject/jsgte/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gambitproject/jsgte/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gambitproject/jsgte/teams","hooks_url":"https://api.github.com/repos/gambitproject/jsgte/hooks","issue_events_url":"https://api.github.com/repos/gambitproject/jsgte/issues/events{/number}","events_url":"https://api.github.com/repos/gambitproject/jsgte/events","assignees_url":"https://api.github.com/repos/gambitproject/jsgte/assignees{/user}","branches_url":"https://api.github.com/repos/gambitproject/jsgte/branches{/branch}","tags_url":"https://api.github.com/repos/gambitproject/jsgte/tags","blobs_url":"https://api.github.com/repos/gambitproject/jsgte/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gambitproject/jsgte/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gambitproject/jsgte/git/refs{/sha}","trees_url":"https://api.github.com/repos/gambitproject/jsgte/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gambitproject/jsgte/statuses/{sha}","languages_url":"https://api.github.com/repos/gambitproject/jsgte/languages","stargazers_url":"https://api.github.com/repos/gambitproject/jsgte/stargazers","contributors_url":"https://api.github.com/repos/gambitproject/jsgte/contributors","subscribers_url":"https://api.github.com/repos/gambitproject/jsgte/subscribers","subscription_url":"https://api.github.com/repos/gambitproject/jsgte/subscription","commits_url":"https://api.github.com/repos/gambitproject/jsgte/commits{/sha}","git_commits_url":"https://api.github.com/repos/gambitproject/jsgte/git/commits{/sha}","comments_url":"https://api.github.com/repos/gambitproject/jsgte/comments{/number}","issue_comment_url":"https://api.github.com/repos/gambitproject/jsgte/issues/comments{/number}","contents_url":"https://api.github.com/repos/gambitproject/jsgte/contents/{+path}","compare_url":"https://api.github.com/repos/gambitproject/jsgte/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gambitproject/jsgte/merges","archive_url":"https://api.github.com/repos/gambitproject/jsgte/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gambitproject/jsgte/downloads","issues_url":"https://api.github.com/repos/gambitproject/jsgte/issues{/number}","pulls_url":"https://api.github.com/repos/gambitproject/jsgte/pulls{/number}","milestones_url":"https://api.github.com/repos/gambitproject/jsgte/milestones{/number}","notifications_url":"https://api.github.com/repos/gambitproject/jsgte/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gambitproject/jsgte/labels{/name}","releases_url":"https://api.github.com/repos/gambitproject/jsgte/releases{/id}","created_at":"2015-02-28T21:36:36Z","updated_at":"2015-04-01T12:45:23Z","pushed_at":"2015-05-14T21:23:54Z","git_url":"git://github.com/gambitproject/jsgte.git","ssh_url":"git@github.com:gambitproject/jsgte.git","clone_url":"https://github.com/gambitproject/jsgte.git","svn_url":"https://github.com/gambitproject/jsgte","homepage":null,"size":432,"stargazers_count":1,"watchers_count":1,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/gambitproject/jsgte/pulls/5"},"html":{"href":"https://github.com/gambitproject/jsgte/pull/5"},"issue":{"href":"https://api.github.com/repos/gambitproject/jsgte/issues/5"},"comments":{"href":"https://api.github.com/repos/gambitproject/jsgte/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/gambitproject/jsgte/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/gambitproject/jsgte/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/gambitproject/jsgte/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/gambitproject/jsgte/statuses/287f8e223046b7eb54a24d5c5d02c199525346bc"}}}}