From d1c0f1009706b85aa8d3321df77c116247ed4428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9E=E3=83=AA=E3=82=A6=E3=82=B9?= Date: Fri, 16 Oct 2020 19:38:00 +0100 Subject: [PATCH] Fixed coloring --- z/calendar.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/z/calendar.go b/z/calendar.go index 4b7dfcd..af5ee22 100644 --- a/z/calendar.go +++ b/z/calendar.go @@ -2,6 +2,7 @@ package z import ( "fmt" + "math" "time" "github.com/gookit/color" "github.com/shopspring/decimal" @@ -53,7 +54,7 @@ func GetOutputBarForHours(hours decimal.Decimal, stats []Statistic) ([]string) { colorFractionPrevAmount := 0.0 for _, stat := range stats { - statHoursInt := int((stat.Hours.Round(0)).IntPart()) + statHoursInt, _ := stat.Hours.Float64() statRest := (stat.Hours.Round(0)).Mod(decimal.NewFromInt(4)) statRestFloat, _ := statRest.Float64() @@ -62,7 +63,15 @@ func GetOutputBarForHours(hours decimal.Decimal, stats []Statistic) ([]string) { colorFraction = stat.Color } - fullColoredParts := int(statHoursInt / 4) + fmt.Printf("%f\n", statHoursInt) + fullColoredParts := int(math.Round(statHoursInt) / 4) + + if fullColoredParts == 0 && statHoursInt > colorFractionPrevAmount { + colorFractionPrevAmount = statHoursInt + colorFraction = stat.Color + } + + fmt.Printf("Full parts: %d\n", fullColoredParts) for i := 0; i < fullColoredParts; i++ { colorsFull[colorsFullIdx] = stat.Color colorsFullIdx++ @@ -75,7 +84,7 @@ func GetOutputBarForHours(hours decimal.Decimal, stats []Statistic) ([]string) { bar[i] = " " + GetOutputBoxForNumber(4, colorsFull[iColor]) + " " iColor++ } else { - bar[i] = " " + GetOutputBoxForNumber(4, color.FgWhite.Render) + " " + bar[i] = " " + GetOutputBoxForNumber(4, colorFraction) + " " } }