-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.go
More file actions
149 lines (126 loc) · 4.13 KB
/
render.go
File metadata and controls
149 lines (126 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package main
import (
"fmt"
"sort"
"strings"
"github.com/fatih/color"
)
// TagSegment represents a colored segment within a bar
type TagSegment struct {
Tag string
Mins int
Color *color.Color
}
func getTagColorMap(projects []Project) map[string]*color.Color {
tagTotals := make(map[string]int)
for _, project := range projects {
for _, record := range project.Data.Records {
for _, entry := range record.Entries {
for _, tag := range entry.Tags {
tagTotals[tag] += entry.TotalMins
}
}
}
}
var tags []string
for tag := range tagTotals {
tags = append(tags, tag)
}
sort.Strings(tags)
const selectedPalette = "tableau10"
palette := colorPalettes[selectedPalette]
paletteSize := len(palette.Colors)
colorMap := make(map[string]*color.Color)
for i, tag := range tags {
if i < paletteSize {
colorMap[tag] = palette.Colors[i]
} else {
colorMap[tag] = generateOverflowColor(i, paletteSize)
}
}
return colorMap
}
func printBar(label string, mins int, maxMins int, barColor *color.Color, maxLabelWidth int) {
maxBarLength := 30
barLength := 0
if maxMins > 0 {
barLength = (mins * maxBarLength) / maxMins
}
if barLength == 0 && mins > 0 {
barLength = 1
}
bar := strings.Repeat("█", barLength)
duration := formatDuration(mins)
fmt.Printf(" %-*s ", maxLabelWidth, label)
barColor.Print(bar)
fmt.Printf(" %s\n", color.HiWhiteString(duration))
}
// printSegmentedBar creates a bar with colored segments for tag distribution
func printSegmentedBar(label string, segments []TagSegment, totalMins int, maxMins int, maxLabelWidth int) {
maxBarLength := 30
totalBarLength := 0
if maxMins > 0 {
totalBarLength = (totalMins * maxBarLength) / maxMins
}
if totalBarLength == 0 && totalMins > 0 {
totalBarLength = 1
}
// Calculate segment lengths proportionally
var segmentLengths []int
usedLength := 0
for i, segment := range segments {
var segmentLength int
if i == len(segments)-1 {
// Last segment gets remaining length to avoid rounding errors
segmentLength = totalBarLength - usedLength
} else {
segmentLength = (segment.Mins * totalBarLength) / totalMins
if segmentLength == 0 && segment.Mins > 0 {
segmentLength = 1 // Ensure visible representation
}
}
segmentLengths = append(segmentLengths, segmentLength)
usedLength += segmentLength
}
// Print the bar
fmt.Printf(" %-*s ", maxLabelWidth, label)
for i, segment := range segments {
if segmentLengths[i] > 0 {
bar := strings.Repeat("█", segmentLengths[i])
segment.Color.Print(bar)
}
}
duration := formatDuration(totalMins)
fmt.Printf(" %s\n", color.HiWhiteString(duration))
}
func calculateMaxLabelWidth(labels []string) int {
maxWidth := 0
for _, label := range labels {
if len(label) > maxWidth {
maxWidth = len(label)
}
}
return maxWidth
}
func printSectionHeader(title string) {
fmt.Println()
color.HiCyanString("┌" + strings.Repeat("─", len(title)+2) + "┐")
color.HiCyan("│ %s │", title)
color.HiCyanString("└" + strings.Repeat("─", len(title)+2) + "┘")
fmt.Println()
}
func printSubsectionHeader(title string) {
fmt.Printf(" %s\n", color.HiYellowString(title))
}
func printHeader() {
fmt.Println()
color.HiCyan("═══════════════════════════════════════════════════════════")
color.HiCyan(" KLOG TIME REPORT ")
color.HiCyan("═══════════════════════════════════════════════════════════")
}
func printFooter(projectCount int) {
fmt.Println()
color.HiBlack("─────────────────────────────────────────────────────────────")
color.HiBlack("%d project(s) processed", projectCount)
color.HiBlack("─────────────────────────────────────────────────────────────")
}