{"action":"created","comment":{"url":"https://api.github.com/repos/nengo/nengo_viz/pulls/comments/27187199","id":27187199,"diff_hunk":"@@ -0,0 +1,452 @@\n+/**\n+ * Network diagram individual item (node)\n+ * @constructor\n+ *\n+ * @param {VIZ.NetGraph} ng - The VIZ.NetGraph this Item is inside\n+ * @param {dict} info - A dictionary of settings for the item, including:\n+ * @param {float array} info.pos - x,y position\n+ * @param {float array} info.size - half width, half height of item\n+ * @param {string} info.type - one of ['net', 'ens', 'node']\n+ * @param {string} info.uid - unique identifier\n+ * @param {string or null} info.parent - a NetGraphItem with .type=='net'\n+ */\n+VIZ.NetGraphItem = function(ng, info) {\n+    this.ng = ng;\n+    this.pos = info.pos;\n+    this.size = info.size;\n+    this.type = info.type;\n+    this.uid = info.uid;\n+\n+    /** if this is a network, the children list is the set of NetGraphItems\n+     *  and NetGraphConnections that are inside this network */\n+    this.children = [];\n+    this.child_connections = [];\n+\n+    /** NetGraphConnections leading into and out of this item */\n+    this.conn_out = [];\n+    this.conn_in = [];\n+\n+    /** determine the parent NetGraphItem (if any) and the nested depth\n+     *  of this item */\n+    if (info.parent == null) {\n+        this.parent = null;\n+        this.depth = 1;\n+    } else {\n+        this.parent = ng.svg_objects[info.parent];\n+        this.depth = this.parent.depth + 1;\n+        this.parent.children.push(this);\n+    }\n+    this.expanded = false;\n+    \n+    /** minimum and maximum drawn size, in pixels */\n+    this.minWidth = 5;\n+    this.minHeight = 5;\n+\n+    /** create the SVG group to hold this item */\n+    var g = this.ng.createSVGElement('g');\n+    this.g = g;\n+    ng.g_items.appendChild(g);    \n+    g.classList.add(this.type);\n+    \n+    /** different types use different SVG elements for display */\n+    if (info.type == 'node') {\n+        this.shape = this.ng.createSVGElement('rect');\n+    } else if (info.type == 'net') {\n+        this.shape = this.ng.createSVGElement('rect');\n+        this.shape.setAttribute('rx', '15');\n+        this.shape.setAttribute('ry', '15');\n+    } else if (info.type == 'ens') {\n+        this.shape = this.ng.createSVGElement('ellipse');\n+        this.shape.setAttribute('cx', '0');\n+        this.shape.setAttribute('cy', '0');\n+    } else {\n+        console.log(\"Unknown NetGraphItem type\");\n+        console.log(item);\n+    }\n+\n+    this.compute_fill();\n+\n+    this.set_position(info.pos[0], info.pos[1]);\n+    this.set_size(info.size[0], info.size[1]);\n+\n+    g.appendChild(this.shape);\n+    \n+    var label = this.ng.createSVGElement('text');\n+    this.label = label;\n+    label.innerHTML = info.label;\n+    g.appendChild(label);\n+\n+    /** dragging an item to change its position */\n+    var uid = this.uid;\n+    var ng = ng;\n+    interact(g)\n+        .draggable({\n+            onmove: function(event) {\n+                var w = ng.get_scaled_width();\n+                var h = ng.get_scaled_height();    \n+                var item = ng.svg_objects[uid];\n+                var parent = item.parent;\n+                while (parent != null) {\n+                    w = w * parent.size[0] * 2;\n+                    h = h * parent.size[1] * 2;\n+                    parent = parent.parent;\n+                }\n+                item.set_position(item.pos[0] + event.dx / w, \n+                                  item.pos[1] + event.dy / h);\n+            },\n+            onend: function(event) {\n+                var item = ng.svg_objects[uid];\n+                item.constrain_position();                \n+                ng.notify({act:\"pos\", uid:uid, x:item.pos[0], y:item.pos[1]});\n+            }});\n+            \n+    /** dragging the edge of item to change its size */\n+    interact(this.shape)\n+        .resizable({\n+            edges: { left: true, right: true, bottom: true, top: true }\n+            })\n+        .on('resizemove', function(event) {            \n+            var item = ng.svg_objects[uid];\n+            var w = ng.get_scaled_width();\n+            var h = ng.get_scaled_height();    \n+            var parent = item.parent;\n+            while (parent != null) {\n+                w = w * parent.size[0] * 2;\n+                h = h * parent.size[1] * 2;\n+                parent = parent.parent;\n+            }\n+            \n+            item.set_size(item.size[0] + event.deltaRect.width / w / 2, \n+                          item.size[1] + event.deltaRect.height / h / 2);\n+            item.set_position(item.pos[0] + event.deltaRect.width / w / 2 + \n+                                            event.deltaRect.left / w, \n+                              item.pos[1] + event.deltaRect.height / h / 2 + \n+                                            event.deltaRect.top / h);\n+            })\n+        .on('resizeend', function(event) {\n+            var item = ng.svg_objects[uid];\n+            item.constrain_position();                \n+            ng.notify({act:\"pos_size\", uid:uid, \n+                       x:item.pos[0], y:item.pos[1],\n+                       width:item.size[0], height:item.size[1]});\n+            });\n+            \n+    interact(this.g)\n+        .on('wheel', function(event) {\n+            var item = ng.svg_objects[uid];\n+            var step_size = 1.1; // size of zoom per wheel click\n+\n+            var delta = event.wheelDeltaY || -event.deltaY\n+            var scale = delta > 0 ? step_size : 1.0 / step_size;\n+            \n+            item.set_size(item.size[0] * scale, item.size[1] * scale);\n+            \n+            item.constrain_position();                \n+            ng.notify({act:\"pos_size\", uid:uid, \n+                       x:item.pos[0], y:item.pos[1],\n+                       width:item.size[0], height:item.size[1]});\n+                       \n+            event.stopPropagation();           \n+            });\n+            \n+    if (info.type == 'net') {","path":"nengo_viz/static/viz_netgraph_item.js","position":153,"original_position":152,"commit_id":"15ebfaac28d76e4a64ce1e41a257455f338d881c","original_commit_id":"af82229986e0490ab81e20889d5118df112ca034","user":{"login":"amaziying","id":5950571,"avatar_url":"https://avatars.githubusercontent.com/u/5950571?v=3","gravatar_id":"","url":"https://api.github.com/users/amaziying","html_url":"https://github.com/amaziying","followers_url":"https://api.github.com/users/amaziying/followers","following_url":"https://api.github.com/users/amaziying/following{/other_user}","gists_url":"https://api.github.com/users/amaziying/gists{/gist_id}","starred_url":"https://api.github.com/users/amaziying/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amaziying/subscriptions","organizations_url":"https://api.github.com/users/amaziying/orgs","repos_url":"https://api.github.com/users/amaziying/repos","events_url":"https://api.github.com/users/amaziying/events{/privacy}","received_events_url":"https://api.github.com/users/amaziying/received_events","type":"User","site_admin":false},"body":"When you can, use '===' instead of '==', because it's always better to have strict-er conditions","created_at":"2015-03-26T04:03:13Z","updated_at":"2015-03-26T04:03:13Z","html_url":"https://github.com/nengo/nengo_viz/pull/74#discussion_r27187199","pull_request_url":"https://api.github.com/repos/nengo/nengo_viz/pulls/74","_links":{"self":{"href":"https://api.github.com/repos/nengo/nengo_viz/pulls/comments/27187199"},"html":{"href":"https://github.com/nengo/nengo_viz/pull/74#discussion_r27187199"},"pull_request":{"href":"https://api.github.com/repos/nengo/nengo_viz/pulls/74"}}},"pull_request":{"url":"https://api.github.com/repos/nengo/nengo_viz/pulls/74","id":31986989,"html_url":"https://github.com/nengo/nengo_viz/pull/74","diff_url":"https://github.com/nengo/nengo_viz/pull/74.diff","patch_url":"https://github.com/nengo/nengo_viz/pull/74.patch","issue_url":"https://api.github.com/repos/nengo/nengo_viz/issues/74","number":74,"state":"open","locked":false,"title":"Network diagram","user":{"login":"tcstewar","id":2380772,"avatar_url":"https://avatars.githubusercontent.com/u/2380772?v=3","gravatar_id":"","url":"https://api.github.com/users/tcstewar","html_url":"https://github.com/tcstewar","followers_url":"https://api.github.com/users/tcstewar/followers","following_url":"https://api.github.com/users/tcstewar/following{/other_user}","gists_url":"https://api.github.com/users/tcstewar/gists{/gist_id}","starred_url":"https://api.github.com/users/tcstewar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tcstewar/subscriptions","organizations_url":"https://api.github.com/users/tcstewar/orgs","repos_url":"https://api.github.com/users/tcstewar/repos","events_url":"https://api.github.com/users/tcstewar/events{/privacy}","received_events_url":"https://api.github.com/users/tcstewar/received_events","type":"User","site_admin":false},"body":"A new component that shows the network diagram\r\n\r\nBasic features:\r\n - networks are expandable and collapsable (by clicking on them)\r\n - automatic layer-based layouts\r\n - automatically saves layout\r\n - scrollwheel zooming (and resizing)\r\n - drag to move items (and pan background)\r\n - constrains items to stay inside their parent network","created_at":"2015-03-26T03:35:51Z","updated_at":"2015-03-26T04:03:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"577122d0b6910f888205166d92dfbb8ce7d32d7c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/nengo/nengo_viz/pulls/74/commits","review_comments_url":"https://api.github.com/repos/nengo/nengo_viz/pulls/74/comments","review_comment_url":"https://api.github.com/repos/nengo/nengo_viz/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nengo/nengo_viz/issues/74/comments","statuses_url":"https://api.github.com/repos/nengo/nengo_viz/statuses/15ebfaac28d76e4a64ce1e41a257455f338d881c","head":{"label":"nengo:network_diagram","ref":"network_diagram","sha":"15ebfaac28d76e4a64ce1e41a257455f338d881c","user":{"login":"nengo","id":9197486,"avatar_url":"https://avatars.githubusercontent.com/u/9197486?v=3","gravatar_id":"","url":"https://api.github.com/users/nengo","html_url":"https://github.com/nengo","followers_url":"https://api.github.com/users/nengo/followers","following_url":"https://api.github.com/users/nengo/following{/other_user}","gists_url":"https://api.github.com/users/nengo/gists{/gist_id}","starred_url":"https://api.github.com/users/nengo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nengo/subscriptions","organizations_url":"https://api.github.com/users/nengo/orgs","repos_url":"https://api.github.com/users/nengo/repos","events_url":"https://api.github.com/users/nengo/events{/privacy}","received_events_url":"https://api.github.com/users/nengo/received_events","type":"Organization","site_admin":false},"repo":{"id":28949681,"name":"nengo_viz","full_name":"nengo/nengo_viz","owner":{"login":"nengo","id":9197486,"avatar_url":"https://avatars.githubusercontent.com/u/9197486?v=3","gravatar_id":"","url":"https://api.github.com/users/nengo","html_url":"https://github.com/nengo","followers_url":"https://api.github.com/users/nengo/followers","following_url":"https://api.github.com/users/nengo/following{/other_user}","gists_url":"https://api.github.com/users/nengo/gists{/gist_id}","starred_url":"https://api.github.com/users/nengo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nengo/subscriptions","organizations_url":"https://api.github.com/users/nengo/orgs","repos_url":"https://api.github.com/users/nengo/repos","events_url":"https://api.github.com/users/nengo/events{/privacy}","received_events_url":"https://api.github.com/users/nengo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nengo/nengo_viz","description":"Nengo interactive visualizer","fork":false,"url":"https://api.github.com/repos/nengo/nengo_viz","forks_url":"https://api.github.com/repos/nengo/nengo_viz/forks","keys_url":"https://api.github.com/repos/nengo/nengo_viz/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nengo/nengo_viz/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nengo/nengo_viz/teams","hooks_url":"https://api.github.com/repos/nengo/nengo_viz/hooks","issue_events_url":"https://api.github.com/repos/nengo/nengo_viz/issues/events{/number}","events_url":"https://api.github.com/repos/nengo/nengo_viz/events","assignees_url":"https://api.github.com/repos/nengo/nengo_viz/assignees{/user}","branches_url":"https://api.github.com/repos/nengo/nengo_viz/branches{/branch}","tags_url":"https://api.github.com/repos/nengo/nengo_viz/tags","blobs_url":"https://api.github.com/repos/nengo/nengo_viz/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nengo/nengo_viz/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nengo/nengo_viz/git/refs{/sha}","trees_url":"https://api.github.com/repos/nengo/nengo_viz/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nengo/nengo_viz/statuses/{sha}","languages_url":"https://api.github.com/repos/nengo/nengo_viz/languages","stargazers_url":"https://api.github.com/repos/nengo/nengo_viz/stargazers","contributors_url":"https://api.github.com/repos/nengo/nengo_viz/contributors","subscribers_url":"https://api.github.com/repos/nengo/nengo_viz/subscribers","subscription_url":"https://api.github.com/repos/nengo/nengo_viz/subscription","commits_url":"https://api.github.com/repos/nengo/nengo_viz/commits{/sha}","git_commits_url":"https://api.github.com/repos/nengo/nengo_viz/git/commits{/sha}","comments_url":"https://api.github.com/repos/nengo/nengo_viz/comments{/number}","issue_comment_url":"https://api.github.com/repos/nengo/nengo_viz/issues/comments{/number}","contents_url":"https://api.github.com/repos/nengo/nengo_viz/contents/{+path}","compare_url":"https://api.github.com/repos/nengo/nengo_viz/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nengo/nengo_viz/merges","archive_url":"https://api.github.com/repos/nengo/nengo_viz/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nengo/nengo_viz/downloads","issues_url":"https://api.github.com/repos/nengo/nengo_viz/issues{/number}","pulls_url":"https://api.github.com/repos/nengo/nengo_viz/pulls{/number}","milestones_url":"https://api.github.com/repos/nengo/nengo_viz/milestones{/number}","notifications_url":"https://api.github.com/repos/nengo/nengo_viz/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nengo/nengo_viz/labels{/name}","releases_url":"https://api.github.com/repos/nengo/nengo_viz/releases{/id}","created_at":"2015-01-08T05:00:06Z","updated_at":"2015-03-24T20:02:24Z","pushed_at":"2015-03-26T03:56:52Z","git_url":"git://github.com/nengo/nengo_viz.git","ssh_url":"git@github.com:nengo/nengo_viz.git","clone_url":"https://github.com/nengo/nengo_viz.git","svn_url":"https://github.com/nengo/nengo_viz","homepage":"","size":2419,"stargazers_count":3,"watchers_count":3,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":33,"forks":2,"open_issues":33,"watchers":3,"default_branch":"master"}},"base":{"label":"nengo:master","ref":"master","sha":"c7583bcd4f0e47a8ebf879cfdacd1252df12f753","user":{"login":"nengo","id":9197486,"avatar_url":"https://avatars.githubusercontent.com/u/9197486?v=3","gravatar_id":"","url":"https://api.github.com/users/nengo","html_url":"https://github.com/nengo","followers_url":"https://api.github.com/users/nengo/followers","following_url":"https://api.github.com/users/nengo/following{/other_user}","gists_url":"https://api.github.com/users/nengo/gists{/gist_id}","starred_url":"https://api.github.com/users/nengo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nengo/subscriptions","organizations_url":"https://api.github.com/users/nengo/orgs","repos_url":"https://api.github.com/users/nengo/repos","events_url":"https://api.github.com/users/nengo/events{/privacy}","received_events_url":"https://api.github.com/users/nengo/received_events","type":"Organization","site_admin":false},"repo":{"id":28949681,"name":"nengo_viz","full_name":"nengo/nengo_viz","owner":{"login":"nengo","id":9197486,"avatar_url":"https://avatars.githubusercontent.com/u/9197486?v=3","gravatar_id":"","url":"https://api.github.com/users/nengo","html_url":"https://github.com/nengo","followers_url":"https://api.github.com/users/nengo/followers","following_url":"https://api.github.com/users/nengo/following{/other_user}","gists_url":"https://api.github.com/users/nengo/gists{/gist_id}","starred_url":"https://api.github.com/users/nengo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nengo/subscriptions","organizations_url":"https://api.github.com/users/nengo/orgs","repos_url":"https://api.github.com/users/nengo/repos","events_url":"https://api.github.com/users/nengo/events{/privacy}","received_events_url":"https://api.github.com/users/nengo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nengo/nengo_viz","description":"Nengo interactive visualizer","fork":false,"url":"https://api.github.com/repos/nengo/nengo_viz","forks_url":"https://api.github.com/repos/nengo/nengo_viz/forks","keys_url":"https://api.github.com/repos/nengo/nengo_viz/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nengo/nengo_viz/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nengo/nengo_viz/teams","hooks_url":"https://api.github.com/repos/nengo/nengo_viz/hooks","issue_events_url":"https://api.github.com/repos/nengo/nengo_viz/issues/events{/number}","events_url":"https://api.github.com/repos/nengo/nengo_viz/events","assignees_url":"https://api.github.com/repos/nengo/nengo_viz/assignees{/user}","branches_url":"https://api.github.com/repos/nengo/nengo_viz/branches{/branch}","tags_url":"https://api.github.com/repos/nengo/nengo_viz/tags","blobs_url":"https://api.github.com/repos/nengo/nengo_viz/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nengo/nengo_viz/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nengo/nengo_viz/git/refs{/sha}","trees_url":"https://api.github.com/repos/nengo/nengo_viz/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nengo/nengo_viz/statuses/{sha}","languages_url":"https://api.github.com/repos/nengo/nengo_viz/languages","stargazers_url":"https://api.github.com/repos/nengo/nengo_viz/stargazers","contributors_url":"https://api.github.com/repos/nengo/nengo_viz/contributors","subscribers_url":"https://api.github.com/repos/nengo/nengo_viz/subscribers","subscription_url":"https://api.github.com/repos/nengo/nengo_viz/subscription","commits_url":"https://api.github.com/repos/nengo/nengo_viz/commits{/sha}","git_commits_url":"https://api.github.com/repos/nengo/nengo_viz/git/commits{/sha}","comments_url":"https://api.github.com/repos/nengo/nengo_viz/comments{/number}","issue_comment_url":"https://api.github.com/repos/nengo/nengo_viz/issues/comments{/number}","contents_url":"https://api.github.com/repos/nengo/nengo_viz/contents/{+path}","compare_url":"https://api.github.com/repos/nengo/nengo_viz/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nengo/nengo_viz/merges","archive_url":"https://api.github.com/repos/nengo/nengo_viz/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nengo/nengo_viz/downloads","issues_url":"https://api.github.com/repos/nengo/nengo_viz/issues{/number}","pulls_url":"https://api.github.com/repos/nengo/nengo_viz/pulls{/number}","milestones_url":"https://api.github.com/repos/nengo/nengo_viz/milestones{/number}","notifications_url":"https://api.github.com/repos/nengo/nengo_viz/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nengo/nengo_viz/labels{/name}","releases_url":"https://api.github.com/repos/nengo/nengo_viz/releases{/id}","created_at":"2015-01-08T05:00:06Z","updated_at":"2015-03-24T20:02:24Z","pushed_at":"2015-03-26T03:56:52Z","git_url":"git://github.com/nengo/nengo_viz.git","ssh_url":"git@github.com:nengo/nengo_viz.git","clone_url":"https://github.com/nengo/nengo_viz.git","svn_url":"https://github.com/nengo/nengo_viz","homepage":"","size":2419,"stargazers_count":3,"watchers_count":3,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":33,"forks":2,"open_issues":33,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nengo/nengo_viz/pulls/74"},"html":{"href":"https://github.com/nengo/nengo_viz/pull/74"},"issue":{"href":"https://api.github.com/repos/nengo/nengo_viz/issues/74"},"comments":{"href":"https://api.github.com/repos/nengo/nengo_viz/issues/74/comments"},"review_comments":{"href":"https://api.github.com/repos/nengo/nengo_viz/pulls/74/comments"},"review_comment":{"href":"https://api.github.com/repos/nengo/nengo_viz/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nengo/nengo_viz/pulls/74/commits"},"statuses":{"href":"https://api.github.com/repos/nengo/nengo_viz/statuses/15ebfaac28d76e4a64ce1e41a257455f338d881c"}}}}