From 37a5894e41ad6847b95c1cfdf2cde5fd51c3dd8c Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Thu, 16 Jun 2022 06:00:27 -0600 Subject: [PATCH 01/15] work on svg generation --- .gitignore | 2 + go.mod | 18 ++++++++ go.sum | 39 +++++++++++++++++ graph/graph.go | 116 +++++++++++++++++++++++++++++++++++++++++++++++++ main.go | 21 +++++++++ 5 files changed, 196 insertions(+) create mode 100644 .gitignore create mode 100644 go.mod create mode 100644 go.sum create mode 100644 graph/graph.go create mode 100644 main.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9c4f66c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.svg +gitgraph diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..3859143 --- /dev/null +++ b/go.mod @@ -0,0 +1,18 @@ +module github.com/taigrr/gitgraph + +go 1.18 + +replace github.com/taigrr/go-colorpallettes => ../go-colorpallettes + +require ( + github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b + github.com/srwiley/oksvg v0.0.0-20220128195007-1f435e4c2b44 + github.com/srwiley/rasterx v0.0.0-20220615024203-67b7089efd25 + github.com/taigrr/go-colorpallettes v0.0.0-00010101000000-000000000000 +) + +require ( + golang.org/x/image v0.0.0-20211028202545-6944b10bf410 // indirect + golang.org/x/net v0.0.0-20211118161319-6a13c67c3ce4 // indirect + golang.org/x/text v0.3.6 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..0bcf8d6 --- /dev/null +++ b/go.sum @@ -0,0 +1,39 @@ +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/ajstarks/deck v0.0.0-20200831202436-30c9fc6549a9/go.mod h1:JynElWSGnm/4RlzPXRlREEwqTHAN3T56Bv2ITsFT3gY= +github.com/ajstarks/deck/generate v0.0.0-20210309230005-c3f852c02e19/go.mod h1:T13YZdzov6OU0A1+RfKZiZN9ca6VeKdBdyDV+BY97Tk= +github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b h1:slYM766cy2nI3BwyRiyQj/Ud48djTMtMebDqepE95rw= +github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b/go.mod h1:1KcenG0jGWcpt8ov532z81sp/kMMUG485J2InIOyADM= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/srwiley/oksvg v0.0.0-20220128195007-1f435e4c2b44 h1:XPYXKIuH/n5zpUoEWk2jWV/SjEMNYmqDYmTgbjmhtaI= +github.com/srwiley/oksvg v0.0.0-20220128195007-1f435e4c2b44/go.mod h1:cNQ3dwVJtS5Hmnjxy6AgTPd0Inb3pW05ftPSX7NZO7Q= +github.com/srwiley/rasterx v0.0.0-20220615024203-67b7089efd25 h1:uyi1c8AxAw2b9MTr639iqz45FMFb4dDR7rB++NaVooo= +github.com/srwiley/rasterx v0.0.0-20220615024203-67b7089efd25/go.mod h1:nXTWP6+gD5+LUJ8krVhhoeHjvHTutPxMYl5SvkcnJNE= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/image v0.0.0-20211028202545-6944b10bf410 h1:hTftEOvwiOq2+O8k2D5/Q7COC7k5Qcrgc2TFURJYnvQ= +golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20211118161319-6a13c67c3ce4 h1:DZshvxDdVoeKIbudAdFEKi+f70l51luSy/7b76ibTY0= +golang.org/x/net v0.0.0-20211118161319-6a13c67c3ce4/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las= diff --git a/graph/graph.go b/graph/graph.go new file mode 100644 index 0000000..75ce734 --- /dev/null +++ b/graph/graph.go @@ -0,0 +1,116 @@ +package graph + +import ( + "bufio" + "bytes" + "fmt" + "image" + "image/color" + "image/png" + "os" + "sync" + + svg "github.com/ajstarks/svgo" + "github.com/srwiley/oksvg" + "github.com/srwiley/rasterx" + sc "github.com/taigrr/go-colorpallettes/simplecolor" +) + +var colorsLoaded sync.Once +var colorScheme []sc.SimpleColor + +func CreateGraph() bytes.Buffer { + var x bytes.Buffer + return x +} + +func init() { + colors := []string{"#767960", "#a7297f", "#e8ca89", "#f5efd6", "#858966"} + for _, c := range colors { + color := sc.FromHexString(c) + _ = c + colorScheme = append(colorScheme, color) + } + +} + +func SetColorScheme(c []color.Color) { + for _, c := range c { + colorScheme = append(colorScheme, sc.FromRGBA(c.RGBA())) + } +} + +func ColorForFrequency(freq, min, max int) color.Color { + spread := max - min + interval := float64(spread) / float64(len(colorScheme)) + colorIndex := 0 + for i := float64(min); i < float64(freq); i += float64(interval) { + colorIndex++ + } + if colorIndex > len(colorScheme)-1 { + colorIndex = len(colorScheme) - 1 + } + return colorScheme[colorIndex] +} +func GetImage(frequencies []int) bytes.Buffer { + squareColors := []color.Color{} + min, max := minmax(frequencies) + for _, f := range frequencies { + squareColors = append(squareColors, ColorForFrequency(f, min, max)) + } + return drawImage(squareColors) +} + +func svgToPng() { + w, h := 512, 512 + + in, err := os.Open("in.svg") + if err != nil { + panic(err) + } + defer in.Close() + + icon, _ := oksvg.ReadIconStream(in) + icon.SetTarget(0, 0, float64(w), float64(h)) + rgba := image.NewRGBA(image.Rect(0, 0, w, h)) + icon.Draw(rasterx.NewDasher(w, h, rasterx.NewScannerGV(w, h, rgba, rgba.Bounds())), 1) + + out, err := os.Create("out.png") + if err != nil { + panic(err) + } + defer out.Close() + + err = png.Encode(out, rgba) + if err != nil { + panic(err) + } +} + +func drawImage(c []sc.SimpleColor) bytes.Buffer { + //TODO here, draw suqares in appropriate colors, hopefully as an svg + var sb bytes.Buffer + sbw := bufio.NewWriter(&sb) + width := 500 + height := 500 + canvas := svg.New(sbw) + canvas.Start(width, height) + canvas.Square(width/20, height/300, width/10, fmt.Sprintf("fill:%s", colorScheme[0].HexString())) + canvas.Circle(width/2, height/2, 100) + canvas.Text(width/2, height/2, "Hello, SVG", "text-anchor:middle;font-size:30px;fill:white") + canvas.End() + sbw.Flush() + return sb +} + +func minmax(f []int) (int, int) { + min, max := 0, 0 + for _, x := range f { + if x < min { + min = x + } else if x > max { + max = x + } + } + return min, max +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..6af0efa --- /dev/null +++ b/main.go @@ -0,0 +1,21 @@ +package main + +import ( + "fmt" + "os" + + "github.com/taigrr/gitgraph/graph" +) + +type DayCount [366]int + +func main() { + svg := graph.GetImage([]int{1, 2, 5, 6, 5, 4, 5, 8, 7, 43, 2, 3}) + f, err := os.Create("out.svg") + if err != nil { + fmt.Printf("Error: %v\n", err) + return + } + defer f.Close() + svg.WriteTo(f) +} From 09982ece64636d801a37c9d152a8211055da17db Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Thu, 16 Jun 2022 06:16:39 -0600 Subject: [PATCH 02/15] graphing with random numbers works --- graph/graph.go | 16 +++++++++------- main.go | 9 ++++++++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/graph/graph.go b/graph/graph.go index 75ce734..47e3a2e 100644 --- a/graph/graph.go +++ b/graph/graph.go @@ -40,7 +40,7 @@ func SetColorScheme(c []color.Color) { } } -func ColorForFrequency(freq, min, max int) color.Color { +func ColorForFrequency(freq, min, max int) sc.SimpleColor { spread := max - min interval := float64(spread) / float64(len(colorScheme)) colorIndex := 0 @@ -53,7 +53,7 @@ func ColorForFrequency(freq, min, max int) color.Color { return colorScheme[colorIndex] } func GetImage(frequencies []int) bytes.Buffer { - squareColors := []color.Color{} + squareColors := []sc.SimpleColor{} min, max := minmax(frequencies) for _, f := range frequencies { squareColors = append(squareColors, ColorForFrequency(f, min, max)) @@ -91,13 +91,15 @@ func drawImage(c []sc.SimpleColor) bytes.Buffer { //TODO here, draw suqares in appropriate colors, hopefully as an svg var sb bytes.Buffer sbw := bufio.NewWriter(&sb) - width := 500 - height := 500 + width := 717 + height := 112 + squareLength := 10 canvas := svg.New(sbw) canvas.Start(width, height) - canvas.Square(width/20, height/300, width/10, fmt.Sprintf("fill:%s", colorScheme[0].HexString())) - canvas.Circle(width/2, height/2, 100) - canvas.Text(width/2, height/2, "Hello, SVG", "text-anchor:middle;font-size:30px;fill:white") + for i, c := range c { + canvas.Square(10+squareLength+width/52*(i/7), squareLength/2+height/7*(i%7), squareLength, fmt.Sprintf("fill:%s", c.HexString())) + } + canvas.Text(width/100, squareLength*2+10, "Mon", "text-anchor:middle;font-size:10px;fill:black") canvas.End() sbw.Flush() return sb diff --git a/main.go b/main.go index 6af0efa..de0ad49 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,9 @@ package main import ( "fmt" + "math/rand" "os" + "time" "github.com/taigrr/gitgraph/graph" ) @@ -10,7 +12,12 @@ import ( type DayCount [366]int func main() { - svg := graph.GetImage([]int{1, 2, 5, 6, 5, 4, 5, 8, 7, 43, 2, 3}) + freq := []int{} + rand.Seed(time.Now().UnixMilli()) + for i := 0; i < 366; i++ { + freq = append(freq, rand.Int()) + } + svg := graph.GetImage(freq) f, err := os.Create("out.svg") if err != nil { fmt.Printf("Error: %v\n", err) From 701a622177830a0bddd36105a74c333a15331a21 Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Thu, 16 Jun 2022 09:27:18 -0600 Subject: [PATCH 03/15] make graph slightly resizeable --- graph/graph.go | 69 +++++++++++++++++++++++++------------------------- main.go | 2 +- 2 files changed, 36 insertions(+), 35 deletions(-) diff --git a/graph/graph.go b/graph/graph.go index 47e3a2e..991ad5e 100644 --- a/graph/graph.go +++ b/graph/graph.go @@ -26,12 +26,11 @@ func CreateGraph() bytes.Buffer { func init() { colors := []string{"#767960", "#a7297f", "#e8ca89", "#f5efd6", "#858966"} + colors = []string{"#161b22", "#0e4429", "#006d32", "#26a641", "#39d353"} for _, c := range colors { color := sc.FromHexString(c) - _ = c colorScheme = append(colorScheme, color) } - } func SetColorScheme(c []color.Color) { @@ -52,13 +51,45 @@ func ColorForFrequency(freq, min, max int) sc.SimpleColor { } return colorScheme[colorIndex] } -func GetImage(frequencies []int) bytes.Buffer { +func GetYearImage(frequencies []int) bytes.Buffer { squareColors := []sc.SimpleColor{} min, max := minmax(frequencies) for _, f := range frequencies { squareColors = append(squareColors, ColorForFrequency(f, min, max)) } - return drawImage(squareColors) + return drawYearImage(squareColors) +} + +func drawYearImage(c []sc.SimpleColor) bytes.Buffer { + //TODO here, draw suqares in appropriate colors, hopefully as an svg + var sb bytes.Buffer + sbw := bufio.NewWriter(&sb) + squareLength := 10 + width := (len(c)/7+1)*squareLength*2 + squareLength*5 + height := squareLength*9 + squareLength*3 + canvas := svg.New(sbw) + canvas.Start(width, height) + for i, s := range c { + canvas.Square(2*squareLength+width/(len(c)/7+1)*(i/7)+squareLength*2, squareLength/2+height/7*(i%7), squareLength, fmt.Sprintf("fill:%s", s.HexString())) + } + canvas.Text(2*squareLength, squareLength*3, "Mon", fmt.Sprintf("text-anchor:middle;font-size:%dpx;fill:black", squareLength)) + canvas.Text(2*squareLength, int(float64(squareLength)*6.5), "Wed", fmt.Sprintf("text-anchor:middle;font-size:%dpx;fill:black", squareLength)) + canvas.Text(2*squareLength, int(float64(squareLength))*10, "Fri", fmt.Sprintf("text-anchor:middle;font-size:%dpx;fill:black", squareLength)) + canvas.End() + sbw.Flush() + return sb +} + +func minmax(f []int) (int, int) { + min, max := 0, 0 + for _, x := range f { + if x < min { + min = x + } else if x > max { + max = x + } + } + return min, max } func svgToPng() { @@ -86,33 +117,3 @@ func svgToPng() { panic(err) } } - -func drawImage(c []sc.SimpleColor) bytes.Buffer { - //TODO here, draw suqares in appropriate colors, hopefully as an svg - var sb bytes.Buffer - sbw := bufio.NewWriter(&sb) - width := 717 - height := 112 - squareLength := 10 - canvas := svg.New(sbw) - canvas.Start(width, height) - for i, c := range c { - canvas.Square(10+squareLength+width/52*(i/7), squareLength/2+height/7*(i%7), squareLength, fmt.Sprintf("fill:%s", c.HexString())) - } - canvas.Text(width/100, squareLength*2+10, "Mon", "text-anchor:middle;font-size:10px;fill:black") - canvas.End() - sbw.Flush() - return sb -} - -func minmax(f []int) (int, int) { - min, max := 0, 0 - for _, x := range f { - if x < min { - min = x - } else if x > max { - max = x - } - } - return min, max -} diff --git a/main.go b/main.go index de0ad49..af89bab 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,7 @@ func main() { for i := 0; i < 366; i++ { freq = append(freq, rand.Int()) } - svg := graph.GetImage(freq) + svg := graph.GetYearImage(freq) f, err := os.Create("out.svg") if err != nil { fmt.Printf("Error: %v\n", err) From 5f0293992b85193b7cc53eb2d3048c6628419849 Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Sun, 19 Jun 2022 12:08:26 -0400 Subject: [PATCH 04/15] add working webserver example --- bin/main.go | 41 +++++++++++++++++++++++++++++++++++++++++ go.mod | 1 + go.sum | 2 ++ graph/graph.go | 27 ++++++++++++++++++++++++++- main.go | 28 ---------------------------- 5 files changed, 70 insertions(+), 29 deletions(-) create mode 100644 bin/main.go delete mode 100644 main.go diff --git a/bin/main.go b/bin/main.go new file mode 100644 index 0000000..d16f447 --- /dev/null +++ b/bin/main.go @@ -0,0 +1,41 @@ +package main + +import ( + "math/rand" + "net/http" + "time" + + "github.com/gorilla/mux" + "github.com/taigrr/gitgraph/graph" +) + +type DayCount [366]int + +func init() { + rand.Seed(time.Now().UnixMilli()) +} +func main() { + r := mux.NewRouter() + r.HandleFunc("/weekly.svg", func(w http.ResponseWriter, r *http.Request) { + freq := []int{} + for i := 0; i < 7; i++ { + freq = append(freq, rand.Int()) + } + w.Header().Add("Content-Type", "text/html") + svg := graph.GetWeekImage(freq) + svg.WriteTo(w) + + }) + r.HandleFunc("/yearly.svg", func(w http.ResponseWriter, r *http.Request) { + freq := []int{} + for i := 0; i < 365; i++ { + freq = append(freq, rand.Int()) + } + svg := graph.GetYearImage(freq) + w.Header().Add("Content-Type", "text/html") + svg.WriteTo(w) + + }) + + http.ListenAndServe("0.0.0.0:5578", r) +} diff --git a/go.mod b/go.mod index 3859143..e75dc61 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ replace github.com/taigrr/go-colorpallettes => ../go-colorpallettes require ( github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b + github.com/gorilla/mux v1.8.0 github.com/srwiley/oksvg v0.0.0-20220128195007-1f435e4c2b44 github.com/srwiley/rasterx v0.0.0-20220615024203-67b7089efd25 github.com/taigrr/go-colorpallettes v0.0.0-00010101000000-000000000000 diff --git a/go.sum b/go.sum index 0bcf8d6..e02bc20 100644 --- a/go.sum +++ b/go.sum @@ -3,6 +3,8 @@ github.com/ajstarks/deck v0.0.0-20200831202436-30c9fc6549a9/go.mod h1:JynElWSGnm github.com/ajstarks/deck/generate v0.0.0-20210309230005-c3f852c02e19/go.mod h1:T13YZdzov6OU0A1+RfKZiZN9ca6VeKdBdyDV+BY97Tk= github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b h1:slYM766cy2nI3BwyRiyQj/Ud48djTMtMebDqepE95rw= github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b/go.mod h1:1KcenG0jGWcpt8ov532z81sp/kMMUG485J2InIOyADM= +github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= +github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/srwiley/oksvg v0.0.0-20220128195007-1f435e4c2b44 h1:XPYXKIuH/n5zpUoEWk2jWV/SjEMNYmqDYmTgbjmhtaI= github.com/srwiley/oksvg v0.0.0-20220128195007-1f435e4c2b44/go.mod h1:cNQ3dwVJtS5Hmnjxy6AgTPd0Inb3pW05ftPSX7NZO7Q= diff --git a/graph/graph.go b/graph/graph.go index 991ad5e..7c3fa85 100644 --- a/graph/graph.go +++ b/graph/graph.go @@ -26,7 +26,7 @@ func CreateGraph() bytes.Buffer { func init() { colors := []string{"#767960", "#a7297f", "#e8ca89", "#f5efd6", "#858966"} - colors = []string{"#161b22", "#0e4429", "#006d32", "#26a641", "#39d353"} + // colors = []string{"#000000", "#0e4429", "#006d32", "#26a641", "#39d353"} for _, c := range colors { color := sc.FromHexString(c) colorScheme = append(colorScheme, color) @@ -51,6 +51,31 @@ func ColorForFrequency(freq, min, max int) sc.SimpleColor { } return colorScheme[colorIndex] } +func GetWeekImage(frequencies []int) bytes.Buffer { + squareColors := []sc.SimpleColor{} + min, max := minmax(frequencies) + for _, f := range frequencies { + squareColors = append(squareColors, ColorForFrequency(f, min, max)) + } + return drawWeekImage(squareColors) +} + +func drawWeekImage(c []sc.SimpleColor) bytes.Buffer { + var sb bytes.Buffer + sbw := bufio.NewWriter(&sb) + squareLength := 10 + width := (len(c) + 1) * squareLength * 2 + height := squareLength * 2 + canvas := svg.New(sbw) + canvas.Start(width, height) + canvas.Rect(0, 0, width, height, "fill:black") + for i, s := range c { + canvas.Square(squareLength*2*(i+1), squareLength/2, squareLength, fmt.Sprintf("fill:%s", s.HexString())) + } + canvas.End() + sbw.Flush() + return sb +} func GetYearImage(frequencies []int) bytes.Buffer { squareColors := []sc.SimpleColor{} min, max := minmax(frequencies) diff --git a/main.go b/main.go deleted file mode 100644 index af89bab..0000000 --- a/main.go +++ /dev/null @@ -1,28 +0,0 @@ -package main - -import ( - "fmt" - "math/rand" - "os" - "time" - - "github.com/taigrr/gitgraph/graph" -) - -type DayCount [366]int - -func main() { - freq := []int{} - rand.Seed(time.Now().UnixMilli()) - for i := 0; i < 366; i++ { - freq = append(freq, rand.Int()) - } - svg := graph.GetYearImage(freq) - f, err := os.Create("out.svg") - if err != nil { - fmt.Printf("Error: %v\n", err) - return - } - defer f.Close() - svg.WriteTo(f) -} From 4ec06a59940ee0daf66428d52882133528431789 Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Sun, 19 Jun 2022 12:13:40 -0400 Subject: [PATCH 05/15] rename API call from Image to SVG --- bin/main.go | 4 ++-- graph/graph.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/main.go b/bin/main.go index d16f447..3f8b474 100644 --- a/bin/main.go +++ b/bin/main.go @@ -22,7 +22,7 @@ func main() { freq = append(freq, rand.Int()) } w.Header().Add("Content-Type", "text/html") - svg := graph.GetWeekImage(freq) + svg := graph.GetWeekSVG(freq) svg.WriteTo(w) }) @@ -31,7 +31,7 @@ func main() { for i := 0; i < 365; i++ { freq = append(freq, rand.Int()) } - svg := graph.GetYearImage(freq) + svg := graph.GetYearSVG(freq) w.Header().Add("Content-Type", "text/html") svg.WriteTo(w) diff --git a/graph/graph.go b/graph/graph.go index 7c3fa85..090c54c 100644 --- a/graph/graph.go +++ b/graph/graph.go @@ -51,7 +51,7 @@ func ColorForFrequency(freq, min, max int) sc.SimpleColor { } return colorScheme[colorIndex] } -func GetWeekImage(frequencies []int) bytes.Buffer { +func GetWeekSVG(frequencies []int) bytes.Buffer { squareColors := []sc.SimpleColor{} min, max := minmax(frequencies) for _, f := range frequencies { @@ -76,7 +76,7 @@ func drawWeekImage(c []sc.SimpleColor) bytes.Buffer { sbw.Flush() return sb } -func GetYearImage(frequencies []int) bytes.Buffer { +func GetYearSVG(frequencies []int) bytes.Buffer { squareColors := []sc.SimpleColor{} min, max := minmax(frequencies) for _, f := range frequencies { From e26d84a9dd04a068ad7c682524bef1ec8e121551 Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Sun, 19 Jun 2022 12:21:08 -0400 Subject: [PATCH 06/15] separate out into packages to avoid unnecessary dependencies --- bin/main.go | 8 ++--- common/common.go | 56 +++++++++++++++++++++++++++++++++++ graph/graph.go => svg/svg.go | 57 ++++-------------------------------- 3 files changed, 66 insertions(+), 55 deletions(-) create mode 100644 common/common.go rename graph/graph.go => svg/svg.go (67%) diff --git a/bin/main.go b/bin/main.go index 3f8b474..8144dfc 100644 --- a/bin/main.go +++ b/bin/main.go @@ -6,7 +6,7 @@ import ( "time" "github.com/gorilla/mux" - "github.com/taigrr/gitgraph/graph" + "github.com/taigrr/gitgraph/svg" ) type DayCount [366]int @@ -22,7 +22,7 @@ func main() { freq = append(freq, rand.Int()) } w.Header().Add("Content-Type", "text/html") - svg := graph.GetWeekSVG(freq) + svg := svg.GetWeekSVG(freq) svg.WriteTo(w) }) @@ -31,11 +31,11 @@ func main() { for i := 0; i < 365; i++ { freq = append(freq, rand.Int()) } - svg := graph.GetYearSVG(freq) + svg := svg.GetYearSVG(freq) w.Header().Add("Content-Type", "text/html") svg.WriteTo(w) }) - http.ListenAndServe("0.0.0.0:5578", r) + http.ListenAndServe(":8080", r) } diff --git a/common/common.go b/common/common.go new file mode 100644 index 0000000..d0b0634 --- /dev/null +++ b/common/common.go @@ -0,0 +1,56 @@ +package common + +import ( + "bytes" + "image/color" + "sync" + + sc "github.com/taigrr/go-colorpallettes/simplecolor" +) + +var colorsLoaded sync.Once +var colorScheme []sc.SimpleColor + +func CreateGraph() bytes.Buffer { + var x bytes.Buffer + return x +} + +func init() { + colors := []string{"#767960", "#a7297f", "#e8ca89", "#f5efd6", "#858966"} + // colors = []string{"#000000", "#0e4429", "#006d32", "#26a641", "#39d353"} + for _, c := range colors { + color := sc.FromHexString(c) + colorScheme = append(colorScheme, color) + } +} + +func SetColorScheme(c []color.Color) { + for _, c := range c { + colorScheme = append(colorScheme, sc.FromRGBA(c.RGBA())) + } +} + +func ColorForFrequency(freq, min, max int) sc.SimpleColor { + spread := max - min + interval := float64(spread) / float64(len(colorScheme)) + colorIndex := 0 + for i := float64(min); i < float64(freq); i += float64(interval) { + colorIndex++ + } + if colorIndex > len(colorScheme)-1 { + colorIndex = len(colorScheme) - 1 + } + return colorScheme[colorIndex] +} +func MinMax(f []int) (int, int) { + min, max := 0, 0 + for _, x := range f { + if x < min { + min = x + } else if x > max { + max = x + } + } + return min, max +} diff --git a/graph/graph.go b/svg/svg.go similarity index 67% rename from graph/graph.go rename to svg/svg.go index 090c54c..76822cd 100644 --- a/graph/graph.go +++ b/svg/svg.go @@ -1,11 +1,10 @@ -package graph +package svg import ( "bufio" "bytes" "fmt" "image" - "image/color" "image/png" "os" "sync" @@ -13,49 +12,18 @@ import ( svg "github.com/ajstarks/svgo" "github.com/srwiley/oksvg" "github.com/srwiley/rasterx" + "github.com/taigrr/gitgraph/common" sc "github.com/taigrr/go-colorpallettes/simplecolor" ) var colorsLoaded sync.Once var colorScheme []sc.SimpleColor -func CreateGraph() bytes.Buffer { - var x bytes.Buffer - return x -} - -func init() { - colors := []string{"#767960", "#a7297f", "#e8ca89", "#f5efd6", "#858966"} - // colors = []string{"#000000", "#0e4429", "#006d32", "#26a641", "#39d353"} - for _, c := range colors { - color := sc.FromHexString(c) - colorScheme = append(colorScheme, color) - } -} - -func SetColorScheme(c []color.Color) { - for _, c := range c { - colorScheme = append(colorScheme, sc.FromRGBA(c.RGBA())) - } -} - -func ColorForFrequency(freq, min, max int) sc.SimpleColor { - spread := max - min - interval := float64(spread) / float64(len(colorScheme)) - colorIndex := 0 - for i := float64(min); i < float64(freq); i += float64(interval) { - colorIndex++ - } - if colorIndex > len(colorScheme)-1 { - colorIndex = len(colorScheme) - 1 - } - return colorScheme[colorIndex] -} func GetWeekSVG(frequencies []int) bytes.Buffer { squareColors := []sc.SimpleColor{} - min, max := minmax(frequencies) + min, max := common.MinMax(frequencies) for _, f := range frequencies { - squareColors = append(squareColors, ColorForFrequency(f, min, max)) + squareColors = append(squareColors, common.ColorForFrequency(f, min, max)) } return drawWeekImage(squareColors) } @@ -78,9 +46,9 @@ func drawWeekImage(c []sc.SimpleColor) bytes.Buffer { } func GetYearSVG(frequencies []int) bytes.Buffer { squareColors := []sc.SimpleColor{} - min, max := minmax(frequencies) + min, max := common.MinMax(frequencies) for _, f := range frequencies { - squareColors = append(squareColors, ColorForFrequency(f, min, max)) + squareColors = append(squareColors, common.ColorForFrequency(f, min, max)) } return drawYearImage(squareColors) } @@ -104,19 +72,6 @@ func drawYearImage(c []sc.SimpleColor) bytes.Buffer { sbw.Flush() return sb } - -func minmax(f []int) (int, int) { - min, max := 0, 0 - for _, x := range f { - if x < min { - min = x - } else if x > max { - max = x - } - } - return min, max -} - func svgToPng() { w, h := 512, 512 From 64e1a551682ccbaa991ac2e9dcd68c5acd56f06c Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Sun, 19 Jun 2022 12:21:29 -0400 Subject: [PATCH 07/15] add terminal unicode block --- term/unicode.go | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 term/unicode.go diff --git a/term/unicode.go b/term/unicode.go new file mode 100644 index 0000000..cc27b4b --- /dev/null +++ b/term/unicode.go @@ -0,0 +1,3 @@ +package main + +const block = "▅" From c29a30e68722a6fec47a3303d3ebc68746b8e4e0 Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Sun, 19 Jun 2022 15:53:12 -0400 Subject: [PATCH 08/15] gitgraph term and svg generation complete --- .gitignore | 2 + bin/cli/cli.go | 30 ++++++++++++ bin/{main.go => server/svg-server.go} | 0 go.mod | 8 ++++ go.sum | 17 +++++++ term/term.go | 69 +++++++++++++++++++++++++++ term/unicode.go | 2 +- 7 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 bin/cli/cli.go rename bin/{main.go => server/svg-server.go} (100%) create mode 100644 term/term.go diff --git a/.gitignore b/.gitignore index 9c4f66c..e6bd2f5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ *.svg gitgraph +bin/cli/cli +bin/server/svg-server diff --git a/bin/cli/cli.go b/bin/cli/cli.go new file mode 100644 index 0000000..5334e94 --- /dev/null +++ b/bin/cli/cli.go @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "math/rand" + "time" + + "github.com/taigrr/gitgraph/term" +) + +func init() { + rand.Seed(time.Now().UnixMilli()) +} +func main() { + freq := []int{} + for i := 0; i < 7; i++ { + freq = append(freq, rand.Int()) + } + fmt.Println("week:") + term.GetWeekUnicode(freq) + fmt.Println() + fmt.Println() + fmt.Println() + freq = []int{} + for i := 0; i < 365; i++ { + freq = append(freq, rand.Int()) + } + fmt.Println("year:") + term.GetYearUnicode(freq) +} diff --git a/bin/main.go b/bin/server/svg-server.go similarity index 100% rename from bin/main.go rename to bin/server/svg-server.go diff --git a/go.mod b/go.mod index e75dc61..0206e8b 100644 --- a/go.mod +++ b/go.mod @@ -4,16 +4,24 @@ go 1.18 replace github.com/taigrr/go-colorpallettes => ../go-colorpallettes +replace github.com/muesli/termenv => github.com/taigrr/termenv v0.11.2 + require ( github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b github.com/gorilla/mux v1.8.0 + github.com/muesli/termenv v0.11.1 github.com/srwiley/oksvg v0.0.0-20220128195007-1f435e4c2b44 github.com/srwiley/rasterx v0.0.0-20220615024203-67b7089efd25 github.com/taigrr/go-colorpallettes v0.0.0-00010101000000-000000000000 ) require ( + github.com/lucasb-eyer/go-colorful v1.2.0 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect + github.com/mattn/go-runewidth v0.0.13 // indirect + github.com/rivo/uniseg v0.2.0 // indirect golang.org/x/image v0.0.0-20211028202545-6944b10bf410 // indirect golang.org/x/net v0.0.0-20211118161319-6a13c67c3ce4 // indirect + golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect golang.org/x/text v0.3.6 // indirect ) diff --git a/go.sum b/go.sum index e02bc20..70251fd 100644 --- a/go.sum +++ b/go.sum @@ -6,10 +6,22 @@ github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b/go.mod h1:1KcenG0jGW github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= +github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= +github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/srwiley/oksvg v0.0.0-20220128195007-1f435e4c2b44 h1:XPYXKIuH/n5zpUoEWk2jWV/SjEMNYmqDYmTgbjmhtaI= github.com/srwiley/oksvg v0.0.0-20220128195007-1f435e4c2b44/go.mod h1:cNQ3dwVJtS5Hmnjxy6AgTPd0Inb3pW05ftPSX7NZO7Q= github.com/srwiley/rasterx v0.0.0-20220615024203-67b7089efd25 h1:uyi1c8AxAw2b9MTr639iqz45FMFb4dDR7rB++NaVooo= github.com/srwiley/rasterx v0.0.0-20220615024203-67b7089efd25/go.mod h1:nXTWP6+gD5+LUJ8krVhhoeHjvHTutPxMYl5SvkcnJNE= +github.com/taigrr/termenv v0.11.2 h1:oqZR08HjGIzFWml4ROmoFvWi3KRG4UZYTPRrI9/lrPA= +github.com/taigrr/termenv v0.11.2 h1:oqZR08HjGIzFWml4ROmoFvWi3KRG4UZYTPRrI9/lrPA= +github.com/taigrr/termenv v0.11.2/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs= +github.com/taigrr/termenv v0.11.2/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -28,11 +40,16 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/term/term.go b/term/term.go new file mode 100644 index 0000000..0237e27 --- /dev/null +++ b/term/term.go @@ -0,0 +1,69 @@ +package term + +import ( + "fmt" + "os" + "sync" + + "github.com/muesli/termenv" + "github.com/taigrr/gitgraph/common" + sc "github.com/taigrr/go-colorpallettes/simplecolor" +) + +var colorsLoaded sync.Once +var colorScheme []sc.SimpleColor + +func GetWeekUnicode(frequencies []int) { + squareColors := []sc.SimpleColor{} + min, max := common.MinMax(frequencies) + for _, f := range frequencies { + squareColors = append(squareColors, common.ColorForFrequency(f, min, max)) + } + drawWeekUnicode(squareColors) +} +func drawWeekUnicode(c []sc.SimpleColor) { + //o := termenv.NewOutput(os.Stdout) + o := termenv.NewOutputWithProfile(os.Stdout, termenv.TrueColor) + for w, color := range c { + style := o.String(block).Foreground(termenv.TrueColor.Color(color.HexString())) + fmt.Print(style.String()) + // termenv.SetForegroundColor(termenv.ForegroundColor()) + if w == len(c)-1 { + fmt.Println() + } else { + fmt.Print(" ") + } + } +} + +func GetYearUnicode(frequencies []int) { + squareColors := []sc.SimpleColor{} + min, max := common.MinMax(frequencies) + for _, f := range frequencies { + squareColors = append(squareColors, common.ColorForFrequency(f, min, max)) + } + drawYearUnicode(squareColors) +} +func drawYearUnicode(c []sc.SimpleColor) { + //o := termenv.NewOutput(os.Stdout) + 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.HexString())) + fmt.Print(style.String()) + if w == len(row)-1 { + fmt.Println() + } else { + fmt.Print(" ") + } + + } + } +} diff --git a/term/unicode.go b/term/unicode.go index cc27b4b..53439fb 100644 --- a/term/unicode.go +++ b/term/unicode.go @@ -1,3 +1,3 @@ -package main +package term const block = "▅" From 999d28ffdaa2eca44698a0e619e59165f9ead749 Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Fri, 13 Jan 2023 17:01:34 -0800 Subject: [PATCH 09/15] fix minmax defaults --- common/common.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/common/common.go b/common/common.go index d0b0634..382025e 100644 --- a/common/common.go +++ b/common/common.go @@ -3,6 +3,7 @@ package common import ( "bytes" "image/color" + "math" "sync" sc "github.com/taigrr/go-colorpallettes/simplecolor" @@ -17,7 +18,7 @@ func CreateGraph() bytes.Buffer { } func init() { - colors := []string{"#767960", "#a7297f", "#e8ca89", "#f5efd6", "#858966"} + colors := []string{"#767960", "#a7297f", "#e8ca89", "#f5efd6", "#158266"} // colors = []string{"#000000", "#0e4429", "#006d32", "#26a641", "#39d353"} for _, c := range colors { color := sc.FromHexString(c) @@ -32,7 +33,13 @@ func SetColorScheme(c []color.Color) { } func ColorForFrequency(freq, min, max int) sc.SimpleColor { + if freq == 0 { + return sc.SimpleColor(0) + } spread := max - min + if spread < len(colorScheme) { + return colorScheme[freq-min] + } interval := float64(spread) / float64(len(colorScheme)) colorIndex := 0 for i := float64(min); i < float64(freq); i += float64(interval) { @@ -44,13 +51,22 @@ func ColorForFrequency(freq, min, max int) sc.SimpleColor { return colorScheme[colorIndex] } func MinMax(f []int) (int, int) { - min, max := 0, 0 + min, max := math.MaxInt, math.MinInt for _, x := range f { + if x == 0 { + continue + } if x < min { min = x } else if x > max { max = x } } + if min == math.MaxInt { + min = 0 + } + if max == math.MinInt { + max = 0 + } return min, max } From 3ceeb1ee00ee8211885c7cc43c1bedd39e4db71a Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Fri, 13 Jan 2023 17:03:27 -0800 Subject: [PATCH 10/15] add go mod bump to 1.19 --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 0206e8b..956ecc1 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/taigrr/gitgraph -go 1.18 +go 1.19 replace github.com/taigrr/go-colorpallettes => ../go-colorpallettes From 47f39302883dca4112f81269eaadaaaf1efb71f4 Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Fri, 13 Jan 2023 17:08:17 -0800 Subject: [PATCH 11/15] update ref to sc --- common/common.go | 9 ++++++--- go.mod | 4 +--- go.sum | 6 ++---- svg/svg.go | 12 ++++++++---- term/term.go | 14 +++++++++----- 5 files changed, 26 insertions(+), 19 deletions(-) diff --git a/common/common.go b/common/common.go index 382025e..df84d4c 100644 --- a/common/common.go +++ b/common/common.go @@ -6,11 +6,13 @@ import ( "math" "sync" - sc "github.com/taigrr/go-colorpallettes/simplecolor" + sc "github.com/taigrr/simplecolorpalettes" ) -var colorsLoaded sync.Once -var colorScheme []sc.SimpleColor +var ( + colorsLoaded sync.Once + colorScheme []sc.SimpleColor +) func CreateGraph() bytes.Buffer { var x bytes.Buffer @@ -50,6 +52,7 @@ func ColorForFrequency(freq, min, max int) sc.SimpleColor { } return colorScheme[colorIndex] } + func MinMax(f []int) (int, int) { min, max := math.MaxInt, math.MinInt for _, x := range f { diff --git a/go.mod b/go.mod index 956ecc1..922816d 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,6 @@ module github.com/taigrr/gitgraph go 1.19 -replace github.com/taigrr/go-colorpallettes => ../go-colorpallettes - replace github.com/muesli/termenv => github.com/taigrr/termenv v0.11.2 require ( @@ -12,7 +10,7 @@ require ( github.com/muesli/termenv v0.11.1 github.com/srwiley/oksvg v0.0.0-20220128195007-1f435e4c2b44 github.com/srwiley/rasterx v0.0.0-20220615024203-67b7089efd25 - github.com/taigrr/go-colorpallettes v0.0.0-00010101000000-000000000000 + github.com/taigrr/simplecolorpalettes v0.9.5 ) require ( diff --git a/go.sum b/go.sum index 70251fd..c91e5e5 100644 --- a/go.sum +++ b/go.sum @@ -18,9 +18,9 @@ github.com/srwiley/oksvg v0.0.0-20220128195007-1f435e4c2b44 h1:XPYXKIuH/n5zpUoEW github.com/srwiley/oksvg v0.0.0-20220128195007-1f435e4c2b44/go.mod h1:cNQ3dwVJtS5Hmnjxy6AgTPd0Inb3pW05ftPSX7NZO7Q= github.com/srwiley/rasterx v0.0.0-20220615024203-67b7089efd25 h1:uyi1c8AxAw2b9MTr639iqz45FMFb4dDR7rB++NaVooo= github.com/srwiley/rasterx v0.0.0-20220615024203-67b7089efd25/go.mod h1:nXTWP6+gD5+LUJ8krVhhoeHjvHTutPxMYl5SvkcnJNE= +github.com/taigrr/simplecolorpalettes v0.9.5 h1:XPyRYwCHh+0ra/7Qw5c9yQf/O4yeLkuqx2X1tVuBE2U= +github.com/taigrr/simplecolorpalettes v0.9.5/go.mod h1:MFLQqI3JOfSc+8GiO3amYfzBiozxITaQi+F1iEV8XpQ= github.com/taigrr/termenv v0.11.2 h1:oqZR08HjGIzFWml4ROmoFvWi3KRG4UZYTPRrI9/lrPA= -github.com/taigrr/termenv v0.11.2 h1:oqZR08HjGIzFWml4ROmoFvWi3KRG4UZYTPRrI9/lrPA= -github.com/taigrr/termenv v0.11.2/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs= github.com/taigrr/termenv v0.11.2/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -45,11 +45,9 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbuf golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/svg/svg.go b/svg/svg.go index 76822cd..f9533c2 100644 --- a/svg/svg.go +++ b/svg/svg.go @@ -13,11 +13,13 @@ import ( "github.com/srwiley/oksvg" "github.com/srwiley/rasterx" "github.com/taigrr/gitgraph/common" - sc "github.com/taigrr/go-colorpallettes/simplecolor" + sc "github.com/taigrr/simplecolorpalettes" ) -var colorsLoaded sync.Once -var colorScheme []sc.SimpleColor +var ( + colorsLoaded sync.Once + colorScheme []sc.SimpleColor +) func GetWeekSVG(frequencies []int) bytes.Buffer { squareColors := []sc.SimpleColor{} @@ -44,6 +46,7 @@ func drawWeekImage(c []sc.SimpleColor) bytes.Buffer { sbw.Flush() return sb } + func GetYearSVG(frequencies []int) bytes.Buffer { squareColors := []sc.SimpleColor{} min, max := common.MinMax(frequencies) @@ -54,7 +57,7 @@ func GetYearSVG(frequencies []int) bytes.Buffer { } func drawYearImage(c []sc.SimpleColor) bytes.Buffer { - //TODO here, draw suqares in appropriate colors, hopefully as an svg + // TODO here, draw suqares in appropriate colors, hopefully as an svg var sb bytes.Buffer sbw := bufio.NewWriter(&sb) squareLength := 10 @@ -72,6 +75,7 @@ func drawYearImage(c []sc.SimpleColor) bytes.Buffer { sbw.Flush() return sb } + func svgToPng() { w, h := 512, 512 diff --git a/term/term.go b/term/term.go index 0237e27..53bfb7e 100644 --- a/term/term.go +++ b/term/term.go @@ -7,11 +7,13 @@ import ( "github.com/muesli/termenv" "github.com/taigrr/gitgraph/common" - sc "github.com/taigrr/go-colorpallettes/simplecolor" + sc "github.com/taigrr/simplecolorpalettes" ) -var colorsLoaded sync.Once -var colorScheme []sc.SimpleColor +var ( + colorsLoaded sync.Once + colorScheme []sc.SimpleColor +) func GetWeekUnicode(frequencies []int) { squareColors := []sc.SimpleColor{} @@ -21,8 +23,9 @@ func GetWeekUnicode(frequencies []int) { } drawWeekUnicode(squareColors) } + func drawWeekUnicode(c []sc.SimpleColor) { - //o := termenv.NewOutput(os.Stdout) + // o := termenv.NewOutput(os.Stdout) o := termenv.NewOutputWithProfile(os.Stdout, termenv.TrueColor) for w, color := range c { style := o.String(block).Foreground(termenv.TrueColor.Color(color.HexString())) @@ -44,8 +47,9 @@ func GetYearUnicode(frequencies []int) { } drawYearUnicode(squareColors) } + func drawYearUnicode(c []sc.SimpleColor) { - //o := termenv.NewOutput(os.Stdout) + // o := termenv.NewOutput(os.Stdout) o := termenv.NewOutputWithProfile(os.Stdout, termenv.TrueColor) weeks := [7][]sc.SimpleColor{{}} for i := 0; i < 7; i++ { From 09b897d3c02a5e51135aa2ace31f7dac83af2d9f Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Wed, 25 Jan 2023 00:19:21 -0800 Subject: [PATCH 12/15] update simplecolor deps --- common/common.go | 8 ++++---- go.mod | 2 +- go.sum | 4 ++-- svg/svg.go | 7 ++++--- term/term.go | 7 ++++--- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/common/common.go b/common/common.go index df84d4c..14b4c0d 100644 --- a/common/common.go +++ b/common/common.go @@ -6,7 +6,7 @@ import ( "math" "sync" - sc "github.com/taigrr/simplecolorpalettes" + sc "github.com/taigrr/simplecolorpalettes/simplecolor" ) var ( @@ -21,7 +21,7 @@ func CreateGraph() bytes.Buffer { func init() { colors := []string{"#767960", "#a7297f", "#e8ca89", "#f5efd6", "#158266"} - // colors = []string{"#000000", "#0e4429", "#006d32", "#26a641", "#39d353"} + colors = []string{"#000000", "#0e4429", "#006d32", "#26a641", "#39d353"} for _, c := range colors { color := sc.FromHexString(c) colorScheme = append(colorScheme, color) @@ -39,8 +39,8 @@ func ColorForFrequency(freq, min, max int) sc.SimpleColor { return sc.SimpleColor(0) } spread := max - min - if spread < len(colorScheme) { - return colorScheme[freq-min] + if spread < len(colorScheme)+1 { + return colorScheme[freq-min+1] } interval := float64(spread) / float64(len(colorScheme)) colorIndex := 0 diff --git a/go.mod b/go.mod index 922816d..0c239d2 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/muesli/termenv v0.11.1 github.com/srwiley/oksvg v0.0.0-20220128195007-1f435e4c2b44 github.com/srwiley/rasterx v0.0.0-20220615024203-67b7089efd25 - github.com/taigrr/simplecolorpalettes v0.9.5 + github.com/taigrr/simplecolorpalettes v0.9.6 ) require ( diff --git a/go.sum b/go.sum index c91e5e5..97aaab0 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/srwiley/oksvg v0.0.0-20220128195007-1f435e4c2b44 h1:XPYXKIuH/n5zpUoEW github.com/srwiley/oksvg v0.0.0-20220128195007-1f435e4c2b44/go.mod h1:cNQ3dwVJtS5Hmnjxy6AgTPd0Inb3pW05ftPSX7NZO7Q= github.com/srwiley/rasterx v0.0.0-20220615024203-67b7089efd25 h1:uyi1c8AxAw2b9MTr639iqz45FMFb4dDR7rB++NaVooo= github.com/srwiley/rasterx v0.0.0-20220615024203-67b7089efd25/go.mod h1:nXTWP6+gD5+LUJ8krVhhoeHjvHTutPxMYl5SvkcnJNE= -github.com/taigrr/simplecolorpalettes v0.9.5 h1:XPyRYwCHh+0ra/7Qw5c9yQf/O4yeLkuqx2X1tVuBE2U= -github.com/taigrr/simplecolorpalettes v0.9.5/go.mod h1:MFLQqI3JOfSc+8GiO3amYfzBiozxITaQi+F1iEV8XpQ= +github.com/taigrr/simplecolorpalettes v0.9.6 h1:eEFLPdI1o34t+YHs+QlgxcpN4zOg+5S3SlWt2EMS/6o= +github.com/taigrr/simplecolorpalettes v0.9.6/go.mod h1:MFLQqI3JOfSc+8GiO3amYfzBiozxITaQi+F1iEV8XpQ= github.com/taigrr/termenv v0.11.2 h1:oqZR08HjGIzFWml4ROmoFvWi3KRG4UZYTPRrI9/lrPA= github.com/taigrr/termenv v0.11.2/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/svg/svg.go b/svg/svg.go index f9533c2..a61c42b 100644 --- a/svg/svg.go +++ b/svg/svg.go @@ -12,8 +12,9 @@ import ( svg "github.com/ajstarks/svgo" "github.com/srwiley/oksvg" "github.com/srwiley/rasterx" + sc "github.com/taigrr/simplecolorpalettes/simplecolor" + "github.com/taigrr/gitgraph/common" - sc "github.com/taigrr/simplecolorpalettes" ) var ( @@ -40,7 +41,7 @@ func drawWeekImage(c []sc.SimpleColor) bytes.Buffer { canvas.Start(width, height) canvas.Rect(0, 0, width, height, "fill:black") for i, s := range c { - canvas.Square(squareLength*2*(i+1), squareLength/2, squareLength, fmt.Sprintf("fill:%s", s.HexString())) + canvas.Square(squareLength*2*(i+1), squareLength/2, squareLength, fmt.Sprintf("fill:%s", s.ToHex())) } canvas.End() sbw.Flush() @@ -66,7 +67,7 @@ func drawYearImage(c []sc.SimpleColor) bytes.Buffer { canvas := svg.New(sbw) canvas.Start(width, height) for i, s := range c { - canvas.Square(2*squareLength+width/(len(c)/7+1)*(i/7)+squareLength*2, squareLength/2+height/7*(i%7), squareLength, fmt.Sprintf("fill:%s", s.HexString())) + canvas.Square(2*squareLength+width/(len(c)/7+1)*(i/7)+squareLength*2, squareLength/2+height/7*(i%7), squareLength, fmt.Sprintf("fill:%s", s.ToHex())) } canvas.Text(2*squareLength, squareLength*3, "Mon", fmt.Sprintf("text-anchor:middle;font-size:%dpx;fill:black", squareLength)) canvas.Text(2*squareLength, int(float64(squareLength)*6.5), "Wed", fmt.Sprintf("text-anchor:middle;font-size:%dpx;fill:black", squareLength)) diff --git a/term/term.go b/term/term.go index 53bfb7e..3f3e7e7 100644 --- a/term/term.go +++ b/term/term.go @@ -6,8 +6,9 @@ import ( "sync" "github.com/muesli/termenv" + sc "github.com/taigrr/simplecolorpalettes/simplecolor" + "github.com/taigrr/gitgraph/common" - sc "github.com/taigrr/simplecolorpalettes" ) var ( @@ -28,7 +29,7 @@ func drawWeekUnicode(c []sc.SimpleColor) { // o := termenv.NewOutput(os.Stdout) o := termenv.NewOutputWithProfile(os.Stdout, termenv.TrueColor) for w, color := range c { - style := o.String(block).Foreground(termenv.TrueColor.Color(color.HexString())) + style := o.String(block).Foreground(termenv.TrueColor.Color(color.ToHex())) fmt.Print(style.String()) // termenv.SetForegroundColor(termenv.ForegroundColor()) if w == len(c)-1 { @@ -60,7 +61,7 @@ func drawYearUnicode(c []sc.SimpleColor) { } for _, row := range weeks { for w, d := range row { - style := o.String(block).Foreground(termenv.TrueColor.Color(d.HexString())) + style := o.String(block).Foreground(termenv.TrueColor.Color(d.ToHex())) fmt.Print(style.String()) if w == len(row)-1 { fmt.Println() From 51b3602a41a0677c648c5fbd0d1098cbc390ecec Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Fri, 27 Jan 2023 00:04:42 -0800 Subject: [PATCH 13/15] fix oob --- common/common.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/common.go b/common/common.go index 14b4c0d..35e10fa 100644 --- a/common/common.go +++ b/common/common.go @@ -39,7 +39,7 @@ func ColorForFrequency(freq, min, max int) sc.SimpleColor { return sc.SimpleColor(0) } spread := max - min - if spread < len(colorScheme)+1 { + if spread < len(colorScheme)-1 { return colorScheme[freq-min+1] } interval := float64(spread) / float64(len(colorScheme)) From 81b0f448667caaaffa65fb7dbc9e3b00685e4032 Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Fri, 27 Jan 2023 00:39:52 -0800 Subject: [PATCH 14/15] change default colorscheme, update deps --- common/common.go | 2 +- go.mod | 20 ++++++++++---------- go.sum | 46 ++++++++++++++++++++++++++++++++-------------- term/term.go | 15 +++++++++------ 4 files changed, 52 insertions(+), 31 deletions(-) diff --git a/common/common.go b/common/common.go index 35e10fa..621be6a 100644 --- a/common/common.go +++ b/common/common.go @@ -21,7 +21,7 @@ func CreateGraph() bytes.Buffer { func init() { colors := []string{"#767960", "#a7297f", "#e8ca89", "#f5efd6", "#158266"} - colors = []string{"#000000", "#0e4429", "#006d32", "#26a641", "#39d353"} + // colors = []string{"#000000", "#0e4429", "#006d32", "#26a641", "#39d353"} for _, c := range colors { color := sc.FromHexString(c) colorScheme = append(colorScheme, color) diff --git a/go.mod b/go.mod index 0c239d2..21ed1c3 100644 --- a/go.mod +++ b/go.mod @@ -7,19 +7,19 @@ replace github.com/muesli/termenv => github.com/taigrr/termenv v0.11.2 require ( github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b github.com/gorilla/mux v1.8.0 - github.com/muesli/termenv v0.11.1 - github.com/srwiley/oksvg v0.0.0-20220128195007-1f435e4c2b44 - github.com/srwiley/rasterx v0.0.0-20220615024203-67b7089efd25 + github.com/muesli/termenv v0.13.0 + github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c + github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef github.com/taigrr/simplecolorpalettes v0.9.6 ) require ( github.com/lucasb-eyer/go-colorful v1.2.0 // indirect - github.com/mattn/go-isatty v0.0.14 // indirect - github.com/mattn/go-runewidth v0.0.13 // indirect - github.com/rivo/uniseg v0.2.0 // indirect - golang.org/x/image v0.0.0-20211028202545-6944b10bf410 // indirect - golang.org/x/net v0.0.0-20211118161319-6a13c67c3ce4 // indirect - golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect - golang.org/x/text v0.3.6 // indirect + github.com/mattn/go-isatty v0.0.17 // indirect + github.com/mattn/go-runewidth v0.0.14 // indirect + github.com/rivo/uniseg v0.4.3 // indirect + golang.org/x/image v0.3.0 // indirect + golang.org/x/net v0.5.0 // indirect + golang.org/x/sys v0.4.0 // indirect + golang.org/x/text v0.6.0 // indirect ) diff --git a/go.sum b/go.sum index 97aaab0..069359d 100644 --- a/go.sum +++ b/go.sum @@ -8,48 +8,66 @@ github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7 github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= -github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= +github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= +github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= -github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= +github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= +github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -github.com/srwiley/oksvg v0.0.0-20220128195007-1f435e4c2b44 h1:XPYXKIuH/n5zpUoEWk2jWV/SjEMNYmqDYmTgbjmhtaI= -github.com/srwiley/oksvg v0.0.0-20220128195007-1f435e4c2b44/go.mod h1:cNQ3dwVJtS5Hmnjxy6AgTPd0Inb3pW05ftPSX7NZO7Q= -github.com/srwiley/rasterx v0.0.0-20220615024203-67b7089efd25 h1:uyi1c8AxAw2b9MTr639iqz45FMFb4dDR7rB++NaVooo= -github.com/srwiley/rasterx v0.0.0-20220615024203-67b7089efd25/go.mod h1:nXTWP6+gD5+LUJ8krVhhoeHjvHTutPxMYl5SvkcnJNE= +github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw= +github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c h1:km8GpoQut05eY3GiYWEedbTT0qnSxrCjsVbb7yKY1KE= +github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c/go.mod h1:cNQ3dwVJtS5Hmnjxy6AgTPd0Inb3pW05ftPSX7NZO7Q= +github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef h1:Ch6Q+AZUxDBCVqdkI8FSpFyZDtCVBc2VmejdNrm5rRQ= +github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef/go.mod h1:nXTWP6+gD5+LUJ8krVhhoeHjvHTutPxMYl5SvkcnJNE= github.com/taigrr/simplecolorpalettes v0.9.6 h1:eEFLPdI1o34t+YHs+QlgxcpN4zOg+5S3SlWt2EMS/6o= github.com/taigrr/simplecolorpalettes v0.9.6/go.mod h1:MFLQqI3JOfSc+8GiO3amYfzBiozxITaQi+F1iEV8XpQ= github.com/taigrr/termenv v0.11.2 h1:oqZR08HjGIzFWml4ROmoFvWi3KRG4UZYTPRrI9/lrPA= github.com/taigrr/termenv v0.11.2/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/image v0.0.0-20211028202545-6944b10bf410 h1:hTftEOvwiOq2+O8k2D5/Q7COC7k5Qcrgc2TFURJYnvQ= -golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/image v0.3.0 h1:HTDXbdK9bjfSWkPzDJIw89W8CAtfFGduujWs33NLLsg= +golang.org/x/image v0.3.0/go.mod h1:fXd9211C/0VTlYuAcOhW8dY/RtEJqODXOWBDpmYBf+A= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20211118161319-6a13c67c3ce4 h1:DZshvxDdVoeKIbudAdFEKi+f70l51luSy/7b76ibTY0= -golang.org/x/net v0.0.0-20211118161319-6a13c67c3ce4/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw= +golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= +golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k= +golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/term/term.go b/term/term.go index 3f3e7e7..0c492fa 100644 --- a/term/term.go +++ b/term/term.go @@ -3,6 +3,7 @@ package term import ( "fmt" "os" + "strings" "sync" "github.com/muesli/termenv" @@ -40,17 +41,18 @@ func drawWeekUnicode(c []sc.SimpleColor) { } } -func GetYearUnicode(frequencies []int) { +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)) } - drawYearUnicode(squareColors) + return drawYearUnicode(squareColors) } -func drawYearUnicode(c []sc.SimpleColor) { +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++ { @@ -62,13 +64,14 @@ func drawYearUnicode(c []sc.SimpleColor) { for _, row := range weeks { for w, d := range row { style := o.String(block).Foreground(termenv.TrueColor.Color(d.ToHex())) - fmt.Print(style.String()) + s.WriteString(style.String()) if w == len(row)-1 { - fmt.Println() + s.WriteString("\n") } else { - fmt.Print(" ") + s.WriteString(" ") } } } + return s.String() } From e7cb12cbe944428014b78c7a6d46d8dcdf20c1b3 Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Fri, 27 Jan 2023 22:13:58 -0800 Subject: [PATCH 15/15] preparing for repo merging --- .gitignore => migration/.gitignore | 0 {bin => migration/bin}/cli/cli.go | 0 {bin => migration/bin}/server/svg-server.go | 0 {common => migration/common}/common.go | 0 go.mod => migration/go.mod | 0 go.sum => migration/go.sum | 0 {svg => migration/svg}/svg.go | 0 {term => migration/term}/term.go | 0 {term => migration/term}/unicode.go | 0 9 files changed, 0 insertions(+), 0 deletions(-) rename .gitignore => migration/.gitignore (100%) rename {bin => migration/bin}/cli/cli.go (100%) rename {bin => migration/bin}/server/svg-server.go (100%) rename {common => migration/common}/common.go (100%) rename go.mod => migration/go.mod (100%) rename go.sum => migration/go.sum (100%) rename {svg => migration/svg}/svg.go (100%) rename {term => migration/term}/term.go (100%) rename {term => migration/term}/unicode.go (100%) diff --git a/.gitignore b/migration/.gitignore similarity index 100% rename from .gitignore rename to migration/.gitignore diff --git a/bin/cli/cli.go b/migration/bin/cli/cli.go similarity index 100% rename from bin/cli/cli.go rename to migration/bin/cli/cli.go diff --git a/bin/server/svg-server.go b/migration/bin/server/svg-server.go similarity index 100% rename from bin/server/svg-server.go rename to migration/bin/server/svg-server.go diff --git a/common/common.go b/migration/common/common.go similarity index 100% rename from common/common.go rename to migration/common/common.go diff --git a/go.mod b/migration/go.mod similarity index 100% rename from go.mod rename to migration/go.mod diff --git a/go.sum b/migration/go.sum similarity index 100% rename from go.sum rename to migration/go.sum diff --git a/svg/svg.go b/migration/svg/svg.go similarity index 100% rename from svg/svg.go rename to migration/svg/svg.go diff --git a/term/term.go b/migration/term/term.go similarity index 100% rename from term/term.go rename to migration/term/term.go diff --git a/term/unicode.go b/migration/term/unicode.go similarity index 100% rename from term/unicode.go rename to migration/term/unicode.go