{"action":"created","comment":{"url":"https://api.github.com/repos/ScottLogic/d3fc/pulls/comments/55394257","id":55394257,"diff_hunk":"@@ -112,35 +112,20 @@ var data = [\n ];\n \n //START\n-// measure the dimension of the given text\n-function boundingBox(textToMeasure) {\n-    var svg = d3.select('body').append('svg')\n-        .attr('width', 1000)\n-        .attr('height', 1000);\n-    var text = svg.append('text')\n-        .text(textToMeasure);\n-    var bbox = text[0][0].getBBox();\n-    svg.remove();\n-    return [bbox.width, bbox.height];\n-}\n+var labelMargin = 2;\n \n-// a very simple example component\n-function label(selection) {\n-    selection.append('rect')\n-            .layout('flex', 1);\n-    selection.append('text')\n-            .text(function(d) { return d.language; })\n-            .layout({\n-                position: 'absolute',\n-                bottom: 0\n-            })\n-            .attr({\n-                // vertically centre the text in the container\n-                'dominant-baseline': 'middle',\n-                'dy': '-0.5em'\n-            });\n-    selection.layout();\n-}\n+var label = fc.tool.container()\n+    .padding(labelMargin)\n+    .component(function(sel) {","path":"site/src/components/layout/rectangles-example-measure.js","position":36,"original_position":36,"commit_id":"bcb58e7e21d579e7b53c860c11c0e9629c703835","original_commit_id":"bcb58e7e21d579e7b53c860c11c0e9629c703835","user":{"login":"ColinEberhardt","id":1098110,"avatar_url":"https://avatars.githubusercontent.com/u/1098110?v=3","gravatar_id":"","url":"https://api.github.com/users/ColinEberhardt","html_url":"https://github.com/ColinEberhardt","followers_url":"https://api.github.com/users/ColinEberhardt/followers","following_url":"https://api.github.com/users/ColinEberhardt/following{/other_user}","gists_url":"https://api.github.com/users/ColinEberhardt/gists{/gist_id}","starred_url":"https://api.github.com/users/ColinEberhardt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ColinEberhardt/subscriptions","organizations_url":"https://api.github.com/users/ColinEberhardt/orgs","repos_url":"https://api.github.com/users/ColinEberhardt/repos","events_url":"https://api.github.com/users/ColinEberhardt/events{/privacy}","received_events_url":"https://api.github.com/users/ColinEberhardt/received_events","type":"User","site_admin":false},"body":"You're missing one small step ...\r\n\r\n\r\n```\r\n.decorate(function(g) {\r\n  g.enter()\r\n    .select('g')\r\n    .append('text')\r\n    .attr('dy', '0.7em')\r\n    .text(function(d) { return d.language; });\r\n})\r\n```\r\n\r\nYou need to select the inner `g` element that has the padding. It's a small thing, but couples this code to the internal structure.","created_at":"2016-03-08T17:29:15Z","updated_at":"2016-03-08T17:29:15Z","html_url":"https://github.com/ScottLogic/d3fc/pull/924#discussion_r55394257","pull_request_url":"https://api.github.com/repos/ScottLogic/d3fc/pulls/924","_links":{"self":{"href":"https://api.github.com/repos/ScottLogic/d3fc/pulls/comments/55394257"},"html":{"href":"https://github.com/ScottLogic/d3fc/pull/924#discussion_r55394257"},"pull_request":{"href":"https://api.github.com/repos/ScottLogic/d3fc/pulls/924"}}},"pull_request":{"url":"https://api.github.com/repos/ScottLogic/d3fc/pulls/924","id":61990936,"html_url":"https://github.com/ScottLogic/d3fc/pull/924","diff_url":"https://github.com/ScottLogic/d3fc/pull/924.diff","patch_url":"https://github.com/ScottLogic/d3fc/pull/924.patch","issue_url":"https://api.github.com/repos/ScottLogic/d3fc/issues/924","number":924,"state":"open","locked":false,"title":"Rectangles includes a measure then layout pass","user":{"login":"ColinEberhardt","id":1098110,"avatar_url":"https://avatars.githubusercontent.com/u/1098110?v=3","gravatar_id":"","url":"https://api.github.com/users/ColinEberhardt","html_url":"https://github.com/ColinEberhardt","followers_url":"https://api.github.com/users/ColinEberhardt/followers","following_url":"https://api.github.com/users/ColinEberhardt/following{/other_user}","gists_url":"https://api.github.com/users/ColinEberhardt/gists{/gist_id}","starred_url":"https://api.github.com/users/ColinEberhardt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ColinEberhardt/subscriptions","organizations_url":"https://api.github.com/users/ColinEberhardt/orgs","repos_url":"https://api.github.com/users/ColinEberhardt/repos","events_url":"https://api.github.com/users/ColinEberhardt/events{/privacy}","received_events_url":"https://api.github.com/users/ColinEberhardt/received_events","type":"User","site_admin":false},"body":"@chrisprice - this seems to work quite nicely, by having `rectangles` render the component before invoking `size` and `position` you can measure the added elements directly. I like the way this gives a two pass rendering, measure then layout.\r\n\r\nTODO:\r\n- [ ] update docs","created_at":"2016-03-07T22:19:34Z","updated_at":"2016-03-08T17:29:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"64f9783caa7f7aa9cd59fb9395ec280298527f74","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ScottLogic/d3fc/pulls/924/commits","review_comments_url":"https://api.github.com/repos/ScottLogic/d3fc/pulls/924/comments","review_comment_url":"https://api.github.com/repos/ScottLogic/d3fc/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ScottLogic/d3fc/issues/924/comments","statuses_url":"https://api.github.com/repos/ScottLogic/d3fc/statuses/bcb58e7e21d579e7b53c860c11c0e9629c703835","head":{"label":"ColinEberhardt:rectangles-measure-layout","ref":"rectangles-measure-layout","sha":"bcb58e7e21d579e7b53c860c11c0e9629c703835","user":{"login":"ColinEberhardt","id":1098110,"avatar_url":"https://avatars.githubusercontent.com/u/1098110?v=3","gravatar_id":"","url":"https://api.github.com/users/ColinEberhardt","html_url":"https://github.com/ColinEberhardt","followers_url":"https://api.github.com/users/ColinEberhardt/followers","following_url":"https://api.github.com/users/ColinEberhardt/following{/other_user}","gists_url":"https://api.github.com/users/ColinEberhardt/gists{/gist_id}","starred_url":"https://api.github.com/users/ColinEberhardt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ColinEberhardt/subscriptions","organizations_url":"https://api.github.com/users/ColinEberhardt/orgs","repos_url":"https://api.github.com/users/ColinEberhardt/repos","events_url":"https://api.github.com/users/ColinEberhardt/events{/privacy}","received_events_url":"https://api.github.com/users/ColinEberhardt/received_events","type":"User","site_admin":false},"repo":{"id":26486000,"name":"d3-financial-components","full_name":"ColinEberhardt/d3-financial-components","owner":{"login":"ColinEberhardt","id":1098110,"avatar_url":"https://avatars.githubusercontent.com/u/1098110?v=3","gravatar_id":"","url":"https://api.github.com/users/ColinEberhardt","html_url":"https://github.com/ColinEberhardt","followers_url":"https://api.github.com/users/ColinEberhardt/followers","following_url":"https://api.github.com/users/ColinEberhardt/following{/other_user}","gists_url":"https://api.github.com/users/ColinEberhardt/gists{/gist_id}","starred_url":"https://api.github.com/users/ColinEberhardt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ColinEberhardt/subscriptions","organizations_url":"https://api.github.com/users/ColinEberhardt/orgs","repos_url":"https://api.github.com/users/ColinEberhardt/repos","events_url":"https://api.github.com/users/ColinEberhardt/events{/privacy}","received_events_url":"https://api.github.com/users/ColinEberhardt/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ColinEberhardt/d3-financial-components","description":"A set of re-useable components for building financial charts with D3","fork":true,"url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components","forks_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/forks","keys_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/teams","hooks_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/hooks","issue_events_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/issues/events{/number}","events_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/events","assignees_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/assignees{/user}","branches_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/branches{/branch}","tags_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/tags","blobs_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/git/refs{/sha}","trees_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/statuses/{sha}","languages_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/languages","stargazers_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/stargazers","contributors_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/contributors","subscribers_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/subscribers","subscription_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/subscription","commits_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/commits{/sha}","git_commits_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/git/commits{/sha}","comments_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/comments{/number}","issue_comment_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/issues/comments{/number}","contents_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/contents/{+path}","compare_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/merges","archive_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/downloads","issues_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/issues{/number}","pulls_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/pulls{/number}","milestones_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/milestones{/number}","notifications_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/labels{/name}","releases_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/releases{/id}","deployments_url":"https://api.github.com/repos/ColinEberhardt/d3-financial-components/deployments","created_at":"2014-11-11T13:25:33Z","updated_at":"2016-01-13T16:28:04Z","pushed_at":"2016-03-07T22:25:05Z","git_url":"git://github.com/ColinEberhardt/d3-financial-components.git","ssh_url":"git@github.com:ColinEberhardt/d3-financial-components.git","clone_url":"https://github.com/ColinEberhardt/d3-financial-components.git","svn_url":"https://github.com/ColinEberhardt/d3-financial-components","homepage":"","size":6153,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":2,"mirror_url":null,"open_issues_count":0,"forks":2,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"ScottLogic:master","ref":"master","sha":"e4e721dbde7b7add9c24b686d94dab9df747b985","user":{"login":"ScottLogic","id":2046037,"avatar_url":"https://avatars.githubusercontent.com/u/2046037?v=3","gravatar_id":"","url":"https://api.github.com/users/ScottLogic","html_url":"https://github.com/ScottLogic","followers_url":"https://api.github.com/users/ScottLogic/followers","following_url":"https://api.github.com/users/ScottLogic/following{/other_user}","gists_url":"https://api.github.com/users/ScottLogic/gists{/gist_id}","starred_url":"https://api.github.com/users/ScottLogic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ScottLogic/subscriptions","organizations_url":"https://api.github.com/users/ScottLogic/orgs","repos_url":"https://api.github.com/users/ScottLogic/repos","events_url":"https://api.github.com/users/ScottLogic/events{/privacy}","received_events_url":"https://api.github.com/users/ScottLogic/received_events","type":"Organization","site_admin":false},"repo":{"id":24850617,"name":"d3fc","full_name":"ScottLogic/d3fc","owner":{"login":"ScottLogic","id":2046037,"avatar_url":"https://avatars.githubusercontent.com/u/2046037?v=3","gravatar_id":"","url":"https://api.github.com/users/ScottLogic","html_url":"https://github.com/ScottLogic","followers_url":"https://api.github.com/users/ScottLogic/followers","following_url":"https://api.github.com/users/ScottLogic/following{/other_user}","gists_url":"https://api.github.com/users/ScottLogic/gists{/gist_id}","starred_url":"https://api.github.com/users/ScottLogic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ScottLogic/subscriptions","organizations_url":"https://api.github.com/users/ScottLogic/orgs","repos_url":"https://api.github.com/users/ScottLogic/repos","events_url":"https://api.github.com/users/ScottLogic/events{/privacy}","received_events_url":"https://api.github.com/users/ScottLogic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ScottLogic/d3fc","description":"A collection of components that make it easy to build interactive charts with D3","fork":false,"url":"https://api.github.com/repos/ScottLogic/d3fc","forks_url":"https://api.github.com/repos/ScottLogic/d3fc/forks","keys_url":"https://api.github.com/repos/ScottLogic/d3fc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ScottLogic/d3fc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ScottLogic/d3fc/teams","hooks_url":"https://api.github.com/repos/ScottLogic/d3fc/hooks","issue_events_url":"https://api.github.com/repos/ScottLogic/d3fc/issues/events{/number}","events_url":"https://api.github.com/repos/ScottLogic/d3fc/events","assignees_url":"https://api.github.com/repos/ScottLogic/d3fc/assignees{/user}","branches_url":"https://api.github.com/repos/ScottLogic/d3fc/branches{/branch}","tags_url":"https://api.github.com/repos/ScottLogic/d3fc/tags","blobs_url":"https://api.github.com/repos/ScottLogic/d3fc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ScottLogic/d3fc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ScottLogic/d3fc/git/refs{/sha}","trees_url":"https://api.github.com/repos/ScottLogic/d3fc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ScottLogic/d3fc/statuses/{sha}","languages_url":"https://api.github.com/repos/ScottLogic/d3fc/languages","stargazers_url":"https://api.github.com/repos/ScottLogic/d3fc/stargazers","contributors_url":"https://api.github.com/repos/ScottLogic/d3fc/contributors","subscribers_url":"https://api.github.com/repos/ScottLogic/d3fc/subscribers","subscription_url":"https://api.github.com/repos/ScottLogic/d3fc/subscription","commits_url":"https://api.github.com/repos/ScottLogic/d3fc/commits{/sha}","git_commits_url":"https://api.github.com/repos/ScottLogic/d3fc/git/commits{/sha}","comments_url":"https://api.github.com/repos/ScottLogic/d3fc/comments{/number}","issue_comment_url":"https://api.github.com/repos/ScottLogic/d3fc/issues/comments{/number}","contents_url":"https://api.github.com/repos/ScottLogic/d3fc/contents/{+path}","compare_url":"https://api.github.com/repos/ScottLogic/d3fc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ScottLogic/d3fc/merges","archive_url":"https://api.github.com/repos/ScottLogic/d3fc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ScottLogic/d3fc/downloads","issues_url":"https://api.github.com/repos/ScottLogic/d3fc/issues{/number}","pulls_url":"https://api.github.com/repos/ScottLogic/d3fc/pulls{/number}","milestones_url":"https://api.github.com/repos/ScottLogic/d3fc/milestones{/number}","notifications_url":"https://api.github.com/repos/ScottLogic/d3fc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ScottLogic/d3fc/labels{/name}","releases_url":"https://api.github.com/repos/ScottLogic/d3fc/releases{/id}","deployments_url":"https://api.github.com/repos/ScottLogic/d3fc/deployments","created_at":"2014-10-06T15:03:11Z","updated_at":"2016-02-29T16:57:36Z","pushed_at":"2016-03-07T22:25:07Z","git_url":"git://github.com/ScottLogic/d3fc.git","ssh_url":"git@github.com:ScottLogic/d3fc.git","clone_url":"https://github.com/ScottLogic/d3fc.git","svn_url":"https://github.com/ScottLogic/d3fc","homepage":"https://d3fc.io/","size":7509,"stargazers_count":229,"watchers_count":229,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":41,"mirror_url":null,"open_issues_count":72,"forks":41,"open_issues":72,"watchers":229,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ScottLogic/d3fc/pulls/924"},"html":{"href":"https://github.com/ScottLogic/d3fc/pull/924"},"issue":{"href":"https://api.github.com/repos/ScottLogic/d3fc/issues/924"},"comments":{"href":"https://api.github.com/repos/ScottLogic/d3fc/issues/924/comments"},"review_comments":{"href":"https://api.github.com/repos/ScottLogic/d3fc/pulls/924/comments"},"review_comment":{"href":"https://api.github.com/repos/ScottLogic/d3fc/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ScottLogic/d3fc/pulls/924/commits"},"statuses":{"href":"https://api.github.com/repos/ScottLogic/d3fc/statuses/bcb58e7e21d579e7b53c860c11c0e9629c703835"}}}}