-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
132 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package zess | ||
|
||
import "github.com/charmbracelet/lipgloss" | ||
|
||
var base = lipgloss.NewStyle() | ||
|
||
// Width | ||
var ( | ||
widthAmount = 5 | ||
widthWeek = 8 | ||
) | ||
|
||
// Margin | ||
var mOverview = 2 | ||
|
||
// Barchart | ||
var ( | ||
widthBar = 60 | ||
heightBar = 20 | ||
) | ||
|
||
// Colors | ||
var ( | ||
cBarChart = lipgloss.Color("#FDEDCA") | ||
|
||
cBorder = lipgloss.Color("#383838") | ||
cZeus = lipgloss.Color("#FF7F00") | ||
cStatsTitle = lipgloss.Color("#EE4B2B") | ||
) | ||
|
||
// Styles chart | ||
var ( | ||
sBar = base.Foreground(cBarChart) | ||
) | ||
|
||
// Styles stats | ||
var ( | ||
sStats = base.Border(lipgloss.NormalBorder(), false, false, false, true).BorderForeground(cBorder).MarginLeft(mOverview).PaddingLeft(mOverview) | ||
sStatsTitle = base.Foreground(cStatsTitle).Bold(true).Border(lipgloss.NormalBorder(), false, false, true, false).BorderForeground(cBorder).Width(widthAmount + widthWeek).Align(lipgloss.Center) | ||
sStatsWeek = base.Width(widthWeek) | ||
sStatsAmount = base.Bold(true).Width(widthAmount).Align(lipgloss.Right) | ||
sStatsAmountMax = sStatsAmount.Foreground(cZeus) | ||
sStatsTotal = base.Border(lipgloss.NormalBorder(), true, false, false, false).BorderForeground(cBorder).MarginTop(1) | ||
sStatsTotalTitle = sStatsWeek | ||
sStatsTotalAmount = sStatsAmount | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package zess | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/NimbleMarkets/ntcharts/barchart" | ||
"github.com/charmbracelet/lipgloss" | ||
) | ||
|
||
func (m *Model) viewChart() string { | ||
chart := barchart.New(widthBar, heightBar) | ||
|
||
for _, scan := range m.scans { | ||
bar := barchart.BarData{ | ||
Label: scan.label, | ||
Values: []barchart.BarValue{{ | ||
Name: scan.label, | ||
Value: float64(scan.amount), | ||
Style: sBar, | ||
}}, | ||
} | ||
|
||
chart.Push(bar) | ||
} | ||
|
||
chart.Draw() | ||
|
||
return chart.View() | ||
} | ||
|
||
func (m *Model) viewStats() string { | ||
// Overview of each week | ||
rows := make([]string, 0, len(m.scans)) | ||
|
||
for _, scan := range m.scans { | ||
week := sStatsWeek.Render(scan.label) | ||
|
||
var amount string | ||
if scan.amount == m.maxWeekScans { | ||
amount = sStatsAmountMax.Render(strconv.Itoa(int(scan.amount))) | ||
} else { | ||
amount = sStatsAmount.Render(strconv.Itoa(int(scan.amount))) | ||
} | ||
|
||
text := lipgloss.JoinHorizontal(lipgloss.Top, week, amount) | ||
rows = append(rows, text) | ||
} | ||
|
||
view := lipgloss.JoinVertical(lipgloss.Left, rows...) | ||
|
||
// Title | ||
title := sStatsTitle.Render("Overview") | ||
|
||
// Total scans | ||
total := sStatsTotalTitle.Render("Total") | ||
amount := sStatsTotalAmount.Render(strconv.Itoa(int(m.seasonScans))) | ||
total = lipgloss.JoinHorizontal(lipgloss.Top, total, amount) | ||
total = sStatsTotal.Render(total) | ||
|
||
view = lipgloss.JoinVertical(lipgloss.Left, title, view, total) | ||
|
||
return view | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters