{"action":"created","comment":{"url":"https://api.github.com/repos/gonum/plot/pulls/comments/41466650","id":41466650,"diff_hunk":"@@ -89,65 +97,111 @@ func (b *BarChart) StackOn(on *BarChart) {\n \n // Plot implements the plot.Plotter interface.\n func (b *BarChart) Plot(c draw.Canvas, plt *plot.Plot) {\n-\ttrX, trY := plt.Transforms(&c)\n+\tvar trCat, trVal func(float64) vg.Length\n+\tswitch b.Horizontal {\n+\tcase false:\n+\t\ttrCat, trVal = plt.Transforms(&c)\n+\tcase true:\n+\t\ttrVal, trCat = plt.Transforms(&c)\n+\t}\n \n \tfor i, ht := range b.Values {\n-\t\tx := b.XMin + float64(i)\n-\t\txmin := trX(float64(x))\n-\t\tif !c.ContainsX(xmin) {\n-\t\t\tcontinue\n+\t\tcatVal := b.XMin + float64(i)\n+\t\tcatMin := trCat(float64(catVal))\n+\t\tswitch b.Horizontal {\n+\t\tcase false:\n+\t\t\tif !c.ContainsX(catMin) {\n+\t\t\t\tcontinue\n+\t\t\t}\n+\t\tcase true:\n+\t\t\tif !c.ContainsY(catMin) {\n+\t\t\t\tcontinue\n+\t\t\t}\n \t\t}\n-\t\txmin = xmin - b.Width/2 + b.Offset\n-\t\txmax := xmin + b.Width\n+\t\tcatMin = catMin - b.Width/2 + b.Offset\n+\t\tcatMax := catMin + b.Width\n \t\tbottom := b.stackedOn.BarHeight(i)\n-\t\tymin := trY(bottom)\n-\t\tymax := trY(bottom + ht)\n-\n-\t\tpts := []draw.Point{\n-\t\t\t{xmin, ymin},\n-\t\t\t{xmin, ymax},\n-\t\t\t{xmax, ymax},\n-\t\t\t{xmax, ymin},\n+\t\tvalMin := trVal(bottom)\n+\t\tvalMax := trVal(bottom + ht)\n+\n+\t\tvar pts []draw.Point\n+\t\tvar poly []draw.Point\n+\t\tswitch b.Horizontal {\n+\t\tcase false:\n+\t\t\tpts = []draw.Point{\n+\t\t\t\t{catMin, valMin},\n+\t\t\t\t{catMin, valMax},\n+\t\t\t\t{catMax, valMax},\n+\t\t\t\t{catMax, valMin},\n+\t\t\t}\n+\t\t\tpoly = c.ClipPolygonY(pts)\n+\t\tcase true:\n+\t\t\tpts = []draw.Point{\n+\t\t\t\t{valMin, catMin},\n+\t\t\t\t{valMin, catMax},\n+\t\t\t\t{valMax, catMax},\n+\t\t\t\t{valMax, catMin},\n+\t\t\t}\n+\t\t\tpoly = c.ClipPolygonX(pts)\n \t\t}\n-\t\tpoly := c.ClipPolygonY(pts)\n \t\tc.FillPolygon(b.Color, poly)\n \n-\t\tpts = append(pts, draw.Point{xmin, ymin})\n-\t\toutline := c.ClipLinesY(pts)\n+\t\tvar outline [][]draw.Point\n+\t\tswitch b.Horizontal {\n+\t\tcase false:\n+\t\t\tpts = append(pts, draw.Point{X: catMin, Y: valMin})\n+\t\t\toutline = c.ClipLinesY(pts)\n+\t\tcase true:\n+\t\t\tpts = append(pts, draw.Point{X: valMin, Y: catMin})\n+\t\t\toutline = c.ClipLinesX(pts)\n+\t\t}\n \t\tc.StrokeLines(b.LineStyle, outline...)\n \t}\n }\n \n // DataRange implements the plot.DataRanger interface.\n func (b *BarChart) DataRange() (xmin, xmax, ymin, ymax float64) {\n-\txmin = b.XMin\n-\txmax = xmin + float64(len(b.Values)-1)\n-\n-\tymin = math.Inf(1)\n-\tymax = math.Inf(-1)\n-\tfor i, y := range b.Values {\n-\t\tybot := b.stackedOn.BarHeight(i)\n-\t\tytop := ybot + y\n-\t\tymin = math.Min(ymin, math.Min(ybot, ytop))\n-\t\tymax = math.Max(ymax, math.Max(ybot, ytop))\n+\tcatMin := b.XMin\n+\tcatMax := catMin + float64(len(b.Values)-1)\n+\n+\tvalMin := math.Inf(1)\n+\tvalMax := math.Inf(-1)\n+\tfor i, val := range b.Values {\n+\t\tvalBot := b.stackedOn.BarHeight(i)\n+\t\tvalTop := valBot + val\n+\t\tvalMin = math.Min(valMin, math.Min(valBot, valTop))\n+\t\tvalMax = math.Max(valMax, math.Max(valBot, valTop))\n+\t}\n+\tif !b.Horizontal {\n+\t\treturn catMin, catMax, valMin, valMax\n \t}\n-\treturn\n+\treturn valMin, valMax, catMin, catMax\n }\n \n // GlyphBoxes implements the GlyphBoxer interface.\n func (b *BarChart) GlyphBoxes(plt *plot.Plot) []plot.GlyphBox {\n \tboxes := make([]plot.GlyphBox, len(b.Values))\n \tfor i := range b.Values {\n-\t\tx := b.XMin + float64(i)\n-\t\tboxes[i].X = plt.X.Norm(x)\n-\t\tboxes[i].Rectangle = draw.Rectangle{\n-\t\t\tMin: draw.Point{X: b.Offset - b.Width/2},\n-\t\t\tMax: draw.Point{X: b.Offset + b.Width/2},\n+\t\tcat := b.XMin + float64(i)\n+\t\tswitch b.Horizontal {","path":"plotter/barchart.go","position":158,"original_position":158,"commit_id":"c75c18f383ac9e67e5db1e79ea16adb2f67bf4fa","original_commit_id":"c75c18f383ac9e67e5db1e79ea16adb2f67bf4fa","user":{"login":"kortschak","id":275221,"avatar_url":"https://avatars.githubusercontent.com/u/275221?v=3","gravatar_id":"","url":"https://api.github.com/users/kortschak","html_url":"https://github.com/kortschak","followers_url":"https://api.github.com/users/kortschak/followers","following_url":"https://api.github.com/users/kortschak/following{/other_user}","gists_url":"https://api.github.com/users/kortschak/gists{/gist_id}","starred_url":"https://api.github.com/users/kortschak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kortschak/subscriptions","organizations_url":"https://api.github.com/users/kortschak/orgs","repos_url":"https://api.github.com/users/kortschak/repos","events_url":"https://api.github.com/users/kortschak/events{/privacy}","received_events_url":"https://api.github.com/users/kortschak/received_events","type":"User","site_admin":false},"body":"ditto","created_at":"2015-10-08T00:57:56Z","updated_at":"2015-10-08T00:57:56Z","html_url":"https://github.com/gonum/plot/pull/229#discussion_r41466650","pull_request_url":"https://api.github.com/repos/gonum/plot/pulls/229","_links":{"self":{"href":"https://api.github.com/repos/gonum/plot/pulls/comments/41466650"},"html":{"href":"https://github.com/gonum/plot/pull/229#discussion_r41466650"},"pull_request":{"href":"https://api.github.com/repos/gonum/plot/pulls/229"}}},"pull_request":{"url":"https://api.github.com/repos/gonum/plot/pulls/229","id":47099946,"html_url":"https://github.com/gonum/plot/pull/229","diff_url":"https://github.com/gonum/plot/pull/229.diff","patch_url":"https://github.com/gonum/plot/pull/229.patch","issue_url":"https://api.github.com/repos/gonum/plot/issues/229","number":229,"state":"open","locked":false,"title":"Added horizontal BarChart","user":{"login":"ctessum","id":6193153,"avatar_url":"https://avatars.githubusercontent.com/u/6193153?v=3","gravatar_id":"","url":"https://api.github.com/users/ctessum","html_url":"https://github.com/ctessum","followers_url":"https://api.github.com/users/ctessum/followers","following_url":"https://api.github.com/users/ctessum/following{/other_user}","gists_url":"https://api.github.com/users/ctessum/gists{/gist_id}","starred_url":"https://api.github.com/users/ctessum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ctessum/subscriptions","organizations_url":"https://api.github.com/users/ctessum/orgs","repos_url":"https://api.github.com/users/ctessum/repos","events_url":"https://api.github.com/users/ctessum/events{/privacy}","received_events_url":"https://api.github.com/users/ctessum/received_events","type":"User","site_admin":false},"body":"...and corresponding tests. I've formatted the tests as examples.","created_at":"2015-10-08T00:35:59Z","updated_at":"2015-10-08T00:57:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dbd1b70d7d3138aa5316c3f21f1f9180904205f6","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/gonum/plot/pulls/229/commits","review_comments_url":"https://api.github.com/repos/gonum/plot/pulls/229/comments","review_comment_url":"https://api.github.com/repos/gonum/plot/pulls/comments{/number}","comments_url":"https://api.github.com/repos/gonum/plot/issues/229/comments","statuses_url":"https://api.github.com/repos/gonum/plot/statuses/c75c18f383ac9e67e5db1e79ea16adb2f67bf4fa","head":{"label":"gonum:barplot","ref":"barplot","sha":"c75c18f383ac9e67e5db1e79ea16adb2f67bf4fa","user":{"login":"gonum","id":3771091,"avatar_url":"https://avatars.githubusercontent.com/u/3771091?v=3","gravatar_id":"","url":"https://api.github.com/users/gonum","html_url":"https://github.com/gonum","followers_url":"https://api.github.com/users/gonum/followers","following_url":"https://api.github.com/users/gonum/following{/other_user}","gists_url":"https://api.github.com/users/gonum/gists{/gist_id}","starred_url":"https://api.github.com/users/gonum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gonum/subscriptions","organizations_url":"https://api.github.com/users/gonum/orgs","repos_url":"https://api.github.com/users/gonum/repos","events_url":"https://api.github.com/users/gonum/events{/privacy}","received_events_url":"https://api.github.com/users/gonum/received_events","type":"Organization","site_admin":false},"repo":{"id":11601889,"name":"plot","full_name":"gonum/plot","owner":{"login":"gonum","id":3771091,"avatar_url":"https://avatars.githubusercontent.com/u/3771091?v=3","gravatar_id":"","url":"https://api.github.com/users/gonum","html_url":"https://github.com/gonum","followers_url":"https://api.github.com/users/gonum/followers","following_url":"https://api.github.com/users/gonum/following{/other_user}","gists_url":"https://api.github.com/users/gonum/gists{/gist_id}","starred_url":"https://api.github.com/users/gonum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gonum/subscriptions","organizations_url":"https://api.github.com/users/gonum/orgs","repos_url":"https://api.github.com/users/gonum/repos","events_url":"https://api.github.com/users/gonum/events{/privacy}","received_events_url":"https://api.github.com/users/gonum/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/gonum/plot","description":"A repository for plotting and visualizing data","fork":false,"url":"https://api.github.com/repos/gonum/plot","forks_url":"https://api.github.com/repos/gonum/plot/forks","keys_url":"https://api.github.com/repos/gonum/plot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gonum/plot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gonum/plot/teams","hooks_url":"https://api.github.com/repos/gonum/plot/hooks","issue_events_url":"https://api.github.com/repos/gonum/plot/issues/events{/number}","events_url":"https://api.github.com/repos/gonum/plot/events","assignees_url":"https://api.github.com/repos/gonum/plot/assignees{/user}","branches_url":"https://api.github.com/repos/gonum/plot/branches{/branch}","tags_url":"https://api.github.com/repos/gonum/plot/tags","blobs_url":"https://api.github.com/repos/gonum/plot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gonum/plot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gonum/plot/git/refs{/sha}","trees_url":"https://api.github.com/repos/gonum/plot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gonum/plot/statuses/{sha}","languages_url":"https://api.github.com/repos/gonum/plot/languages","stargazers_url":"https://api.github.com/repos/gonum/plot/stargazers","contributors_url":"https://api.github.com/repos/gonum/plot/contributors","subscribers_url":"https://api.github.com/repos/gonum/plot/subscribers","subscription_url":"https://api.github.com/repos/gonum/plot/subscription","commits_url":"https://api.github.com/repos/gonum/plot/commits{/sha}","git_commits_url":"https://api.github.com/repos/gonum/plot/git/commits{/sha}","comments_url":"https://api.github.com/repos/gonum/plot/comments{/number}","issue_comment_url":"https://api.github.com/repos/gonum/plot/issues/comments{/number}","contents_url":"https://api.github.com/repos/gonum/plot/contents/{+path}","compare_url":"https://api.github.com/repos/gonum/plot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gonum/plot/merges","archive_url":"https://api.github.com/repos/gonum/plot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gonum/plot/downloads","issues_url":"https://api.github.com/repos/gonum/plot/issues{/number}","pulls_url":"https://api.github.com/repos/gonum/plot/pulls{/number}","milestones_url":"https://api.github.com/repos/gonum/plot/milestones{/number}","notifications_url":"https://api.github.com/repos/gonum/plot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gonum/plot/labels{/name}","releases_url":"https://api.github.com/repos/gonum/plot/releases{/id}","created_at":"2013-07-23T07:01:13Z","updated_at":"2015-10-04T00:26:59Z","pushed_at":"2015-10-08T00:35:59Z","git_url":"git://github.com/gonum/plot.git","ssh_url":"git@github.com:gonum/plot.git","clone_url":"https://github.com/gonum/plot.git","svn_url":"https://github.com/gonum/plot","homepage":"","size":2550,"stargazers_count":140,"watchers_count":140,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":23,"mirror_url":null,"open_issues_count":46,"forks":23,"open_issues":46,"watchers":140,"default_branch":"master"}},"base":{"label":"gonum:master","ref":"master","sha":"a7931a76bdbca3a494e34a9db17fe48a4850624f","user":{"login":"gonum","id":3771091,"avatar_url":"https://avatars.githubusercontent.com/u/3771091?v=3","gravatar_id":"","url":"https://api.github.com/users/gonum","html_url":"https://github.com/gonum","followers_url":"https://api.github.com/users/gonum/followers","following_url":"https://api.github.com/users/gonum/following{/other_user}","gists_url":"https://api.github.com/users/gonum/gists{/gist_id}","starred_url":"https://api.github.com/users/gonum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gonum/subscriptions","organizations_url":"https://api.github.com/users/gonum/orgs","repos_url":"https://api.github.com/users/gonum/repos","events_url":"https://api.github.com/users/gonum/events{/privacy}","received_events_url":"https://api.github.com/users/gonum/received_events","type":"Organization","site_admin":false},"repo":{"id":11601889,"name":"plot","full_name":"gonum/plot","owner":{"login":"gonum","id":3771091,"avatar_url":"https://avatars.githubusercontent.com/u/3771091?v=3","gravatar_id":"","url":"https://api.github.com/users/gonum","html_url":"https://github.com/gonum","followers_url":"https://api.github.com/users/gonum/followers","following_url":"https://api.github.com/users/gonum/following{/other_user}","gists_url":"https://api.github.com/users/gonum/gists{/gist_id}","starred_url":"https://api.github.com/users/gonum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gonum/subscriptions","organizations_url":"https://api.github.com/users/gonum/orgs","repos_url":"https://api.github.com/users/gonum/repos","events_url":"https://api.github.com/users/gonum/events{/privacy}","received_events_url":"https://api.github.com/users/gonum/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/gonum/plot","description":"A repository for plotting and visualizing data","fork":false,"url":"https://api.github.com/repos/gonum/plot","forks_url":"https://api.github.com/repos/gonum/plot/forks","keys_url":"https://api.github.com/repos/gonum/plot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gonum/plot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gonum/plot/teams","hooks_url":"https://api.github.com/repos/gonum/plot/hooks","issue_events_url":"https://api.github.com/repos/gonum/plot/issues/events{/number}","events_url":"https://api.github.com/repos/gonum/plot/events","assignees_url":"https://api.github.com/repos/gonum/plot/assignees{/user}","branches_url":"https://api.github.com/repos/gonum/plot/branches{/branch}","tags_url":"https://api.github.com/repos/gonum/plot/tags","blobs_url":"https://api.github.com/repos/gonum/plot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gonum/plot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gonum/plot/git/refs{/sha}","trees_url":"https://api.github.com/repos/gonum/plot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gonum/plot/statuses/{sha}","languages_url":"https://api.github.com/repos/gonum/plot/languages","stargazers_url":"https://api.github.com/repos/gonum/plot/stargazers","contributors_url":"https://api.github.com/repos/gonum/plot/contributors","subscribers_url":"https://api.github.com/repos/gonum/plot/subscribers","subscription_url":"https://api.github.com/repos/gonum/plot/subscription","commits_url":"https://api.github.com/repos/gonum/plot/commits{/sha}","git_commits_url":"https://api.github.com/repos/gonum/plot/git/commits{/sha}","comments_url":"https://api.github.com/repos/gonum/plot/comments{/number}","issue_comment_url":"https://api.github.com/repos/gonum/plot/issues/comments{/number}","contents_url":"https://api.github.com/repos/gonum/plot/contents/{+path}","compare_url":"https://api.github.com/repos/gonum/plot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gonum/plot/merges","archive_url":"https://api.github.com/repos/gonum/plot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gonum/plot/downloads","issues_url":"https://api.github.com/repos/gonum/plot/issues{/number}","pulls_url":"https://api.github.com/repos/gonum/plot/pulls{/number}","milestones_url":"https://api.github.com/repos/gonum/plot/milestones{/number}","notifications_url":"https://api.github.com/repos/gonum/plot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gonum/plot/labels{/name}","releases_url":"https://api.github.com/repos/gonum/plot/releases{/id}","created_at":"2013-07-23T07:01:13Z","updated_at":"2015-10-04T00:26:59Z","pushed_at":"2015-10-08T00:35:59Z","git_url":"git://github.com/gonum/plot.git","ssh_url":"git@github.com:gonum/plot.git","clone_url":"https://github.com/gonum/plot.git","svn_url":"https://github.com/gonum/plot","homepage":"","size":2550,"stargazers_count":140,"watchers_count":140,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":23,"mirror_url":null,"open_issues_count":46,"forks":23,"open_issues":46,"watchers":140,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/gonum/plot/pulls/229"},"html":{"href":"https://github.com/gonum/plot/pull/229"},"issue":{"href":"https://api.github.com/repos/gonum/plot/issues/229"},"comments":{"href":"https://api.github.com/repos/gonum/plot/issues/229/comments"},"review_comments":{"href":"https://api.github.com/repos/gonum/plot/pulls/229/comments"},"review_comment":{"href":"https://api.github.com/repos/gonum/plot/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/gonum/plot/pulls/229/commits"},"statuses":{"href":"https://api.github.com/repos/gonum/plot/statuses/c75c18f383ac9e67e5db1e79ea16adb2f67bf4fa"}}}}