rename gitgraph => graph

This commit is contained in:
2023-01-30 15:07:13 -08:00
parent 02cd017227
commit f2fa0500fb
9 changed files with 7 additions and 7 deletions

78
graph/term/term.go Normal file
View File

@@ -0,0 +1,78 @@
package term
import (
"os"
"strings"
"sync"
"github.com/muesli/termenv"
sc "github.com/taigrr/simplecolorpalettes/simplecolor"
"github.com/taigrr/gico/graph/common"
)
var (
colorsLoaded sync.Once
colorScheme []sc.SimpleColor
)
func GetWeekUnicode(frequencies []int) string {
squareColors := []sc.SimpleColor{}
min, max := common.MinMax(frequencies)
for _, f := range frequencies {
squareColors = append(squareColors, common.ColorForFrequency(f, min, max))
}
return drawWeekUnicode(squareColors)
}
func drawWeekUnicode(c []sc.SimpleColor) string {
// o := termenv.NewOutput(os.Stdout)
s := strings.Builder{}
o := termenv.NewOutputWithProfile(os.Stdout, termenv.TrueColor)
for w, color := range c {
style := o.String(block).Foreground(termenv.TrueColor.Color(color.ToHex()))
s.WriteString(style.String())
// termenv.SetForegroundColor(termenv.ForegroundColor())
if w == len(c)-1 {
s.WriteString("\n")
} else {
s.WriteString(" ")
}
}
return s.String()
}
func GetYearUnicode(frequencies []int) string {
squareColors := []sc.SimpleColor{}
min, max := common.MinMax(frequencies)
for _, f := range frequencies {
squareColors = append(squareColors, common.ColorForFrequency(f, min, max))
}
return drawYearUnicode(squareColors)
}
func drawYearUnicode(c []sc.SimpleColor) string {
// o := termenv.NewOutput(os.Stdout)
var s strings.Builder
o := termenv.NewOutputWithProfile(os.Stdout, termenv.TrueColor)
weeks := [7][]sc.SimpleColor{{}}
for i := 0; i < 7; i++ {
weeks[i] = []sc.SimpleColor{}
}
for i := range c {
weeks[i%7] = append(weeks[i%7], c[i])
}
for _, row := range weeks {
for w, d := range row {
style := o.String(block).Foreground(termenv.TrueColor.Color(d.ToHex()))
s.WriteString(style.String())
if w == len(row)-1 {
s.WriteString("\n")
} else {
s.WriteString(" ")
}
}
}
return s.String()
}

3
graph/term/unicode.go Normal file
View File

@@ -0,0 +1,3 @@
package term
const block = "▅"