Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use grids to render stats #9

Merged
merged 3 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 59 additions & 6 deletions tui/render_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,20 @@ func RenderStats(username string, accType string, s *spinner.Spinner) {
log.Fatalf("failed to initialize termui: %v", err)
}
defer ui.Close()
width, height := ui.TerminalDimensions()
grid := ui.NewGrid()
grid.SetRect(0, 0, width, height)

if accType == "(user)" {
renderUser(username, s)
renderUser(username, s, grid)
}

if accType == "(organization)" {
renderOrganization(username, s)
renderOrganization(username, s, grid)
}
}

func renderUser(username string, s *spinner.Spinner) {
func renderUser(username string, s *spinner.Spinner, grid *ui.Grid) {
user, err := g.UserDetails(qlClient, username)
if err != nil {
log.Fatalf("Couldn't get user details for: %v: %v", username, err)
Expand All @@ -57,7 +60,39 @@ func renderUser(username string, s *spinner.Spinner) {

render := func() {
img.Image = images[0]
ui.Render(img, p, p2, pc, pc2, sl, bc, bc2, p3)
grid.Set(
ui.NewCol(
0.25,
ui.NewRow(1.0/3, img),
ui.NewRow(2.0/3, p),
),
ui.NewCol(
0.25,
ui.NewRow(0.625, p2),
ui.NewRow(0.375, pc),
),
ui.NewCol(
0.5,
ui.NewRow(
0.25,
sl,
),
ui.NewRow(
0.75,
ui.NewCol(
0.5,
ui.NewRow(0.5, p3),
ui.NewRow(0.5, pc2),
),
ui.NewCol(
0.5,
ui.NewRow(0.5, bc2),
ui.NewRow(0.5, bc),
),
),
),
)
ui.Render(grid)
}
s.Stop()
render()
Expand All @@ -80,7 +115,7 @@ func renderUser(username string, s *spinner.Spinner) {
}
}

func renderOrganization(username string, s *spinner.Spinner) {
func renderOrganization(username string, s *spinner.Spinner, grid *ui.Grid) {
org, err := g.OrganizationDetails(qlClient, username)
if err != nil {
log.Fatalf("Couldn't get org details for: %v: %v", username, err)
Expand All @@ -100,7 +135,25 @@ func renderOrganization(username string, s *spinner.Spinner) {

render := func() {
img.Image = images[0]
ui.Render(img, p, p2, p3, bc, bc2, pc2)
grid.Set(
ui.NewCol(
0.25,
ui.NewRow(1.0/3, img),
ui.NewRow(2.0/3, p),
),
ui.NewCol(
0.25,
ui.NewRow(0.25, p2),
ui.NewRow(0.75, p3),
),
ui.NewCol(
0.5,
ui.NewRow(0.25, bc2),
ui.NewRow(0.25, bc),
ui.NewRow(0.5, pc2),
),
)
ui.Render(grid)
}
s.Stop()
render()
Expand Down
30 changes: 0 additions & 30 deletions tui/widgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func SetupProfileInfo(user g.User) *widgets.Paragraph {
p.WrapText = true
p.Border = true
p.Text = gh.BuildUserInfo(user)
p.SetRect(0, 35, 35, 14)

return p
}
Expand All @@ -37,7 +36,6 @@ func SetupProfileStats(user g.User, allRepos []*github.Repository) *widgets.Para
p.WrapText = true
p.Text = gh.BuildUserStats(Ctx, RestClient, qlClient, user, allRepos)
p.Border = true
p.SetRect(35, 0, 70, 20)

return p
}
Expand All @@ -47,7 +45,6 @@ func SetupReposStats(user g.User, allRepos []*github.Repository) *widgets.Paragr
p.WrapText = true
p.Border = true
p.Text = gh.BuildUserRepos(RestClient, user, allRepos)
p.SetRect(70, 10, 105, 20)

return p
}
Expand All @@ -57,7 +54,6 @@ func SetupOrgInfo(org g.Organization) *widgets.Paragraph {
p.WrapText = true
p.Border = true
p.Text = gh.BuildOrgInfo(org)
p.SetRect(0, 35, 35, 14)

return p
}
Expand All @@ -67,7 +63,6 @@ func SetupOrgStats(org g.Organization, allRepos []*github.Repository) *widgets.P
p.WrapText = true
p.Text = gh.BuildOrgStats(Ctx, RestClient, qlClient, org, allRepos)
p.Border = true
p.SetRect(35, 0, 70, 12)

return p
}
Expand All @@ -77,7 +72,6 @@ func SetupOrgRepos(org g.Organization, allRepos []*github.Repository) *widgets.P
p.WrapText = true
p.Border = true
p.Text = gh.BuildOrgRepos(RestClient, allRepos)
p.SetRect(35, 12, 70, 35)

return p
}
Expand All @@ -98,7 +92,6 @@ func SetupImage(profileImg string, login string) (*widgets.Image, []image.Image)
images = append(images, image)

img := widgets.NewImage(nil)
img.SetRect(0, 0, 30, 14)
img.Title = login + "'s GitHub"

return img, images
Expand All @@ -113,7 +106,6 @@ func SetupLangsByCommits(user g.User) *widgets.PieChart {

pc := widgets.NewPieChart()
pc.Title = "Languages by commit"
pc.SetRect(35, 35, 70, 20)

boundNum := h.UserDataBound(langs)
if boundNum == 0 {
Expand All @@ -136,12 +128,7 @@ func SetupLangsByRepo(allRepos []*github.Repository, accType string) *widgets.Pi
pc := widgets.NewPieChart()
pc.Title = "Languages by repo"

userCords := [4]int{105, 35, 70, 20}
orgCords := [4]int{115, 16, 70, 35}

if accType == "user" {
pc.SetRect(userCords[0], userCords[1], userCords[2], userCords[3])

boundNum := h.UserDataBound(usedLangs)
if boundNum == 0 {
pc.Title = "Langs by repo (no repos)"
Expand All @@ -151,8 +138,6 @@ func SetupLangsByRepo(allRepos []*github.Repository, accType string) *widgets.Pi
}

if accType == "organization" {
pc.SetRect(orgCords[0], orgCords[1], orgCords[2], orgCords[3])

boundNum := h.OrgDataBound(usedLangs)
if boundNum == 0 {
pc.Title = "Langs by repo (no repos)"
Expand All @@ -175,12 +160,7 @@ func SetupStarsPerLangs(allRepos []*github.Repository, accType string) *widgets.
bc := widgets.NewBarChart()
bc.Title = "Stars per language"

userCords := [4]int{150, 35, 105, 20}
orgCords := [4]int{70, 16, 150, 8}

if accType == "user" {
bc.SetRect(userCords[0], userCords[1], userCords[2], userCords[3])

bound := h.UserDataBound(starsPerL)
if bound == 0 || h.AllZero(starsNum[:bound]) {
bc.Title = "Stars per language (no stars)"
Expand All @@ -191,8 +171,6 @@ func SetupStarsPerLangs(allRepos []*github.Repository, accType string) *widgets.
}

if accType == "organization" {
bc.SetRect(orgCords[0], orgCords[1], orgCords[2], orgCords[3])

bound := h.OrgDataBound(starsPerL)
if bound == 0 || h.AllZero(starsNum[:bound]) {
bc.Title = "Stars per language (no stars)"
Expand All @@ -217,12 +195,7 @@ func SetupForksPerLangs(allRepos []*github.Repository, accType string) *widgets.
bc := widgets.NewBarChart()
bc.Title = "Forks per language"

userCords := [4]int{150, 10, 105, 20}
orgCords := [4]int{70, 0, 150, 8}

if accType == "user" {
bc.SetRect(userCords[0], userCords[1], userCords[2], userCords[3])

bound := h.UserDataBound(forksPerL)
if bound == 0 || h.AllZero(forksNum[:bound]) {
bc.Title = "Forks per language (no forks)"
Expand All @@ -233,8 +206,6 @@ func SetupForksPerLangs(allRepos []*github.Repository, accType string) *widgets.
}

if accType == "organization" {
bc.SetRect(orgCords[0], orgCords[1], orgCords[2], orgCords[3])

bound := h.OrgDataBound(forksPerL)
if bound == 0 || h.AllZero(forksNum[:bound]) {
bc.Title = "Forks per language (no forks)"
Expand Down Expand Up @@ -267,7 +238,6 @@ func SetupContribsSparkline(user g.User) *widgets.SparklineGroup {

slg := widgets.NewSparklineGroup(sl)
slg.Title = "Activity for the last " + strconv.Itoa(timeSpan) + " days"
slg.SetRect(150, 0, 70, 10)

return slg
}