Fixed coloring

This commit is contained in:
マリウス 2020-10-16 19:38:00 +01:00
parent 2d8b17d1f4
commit d1c0f10097
No known key found for this signature in database
GPG key ID: C228EF0A530AF06F

View file

@ -2,6 +2,7 @@ package z
import ( import (
"fmt" "fmt"
"math"
"time" "time"
"github.com/gookit/color" "github.com/gookit/color"
"github.com/shopspring/decimal" "github.com/shopspring/decimal"
@ -53,7 +54,7 @@ func GetOutputBarForHours(hours decimal.Decimal, stats []Statistic) ([]string) {
colorFractionPrevAmount := 0.0 colorFractionPrevAmount := 0.0
for _, stat := range stats { for _, stat := range stats {
statHoursInt := int((stat.Hours.Round(0)).IntPart()) statHoursInt, _ := stat.Hours.Float64()
statRest := (stat.Hours.Round(0)).Mod(decimal.NewFromInt(4)) statRest := (stat.Hours.Round(0)).Mod(decimal.NewFromInt(4))
statRestFloat, _ := statRest.Float64() statRestFloat, _ := statRest.Float64()
@ -62,7 +63,15 @@ func GetOutputBarForHours(hours decimal.Decimal, stats []Statistic) ([]string) {
colorFraction = stat.Color 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++ { for i := 0; i < fullColoredParts; i++ {
colorsFull[colorsFullIdx] = stat.Color colorsFull[colorsFullIdx] = stat.Color
colorsFullIdx++ colorsFullIdx++
@ -75,7 +84,7 @@ func GetOutputBarForHours(hours decimal.Decimal, stats []Statistic) ([]string) {
bar[i] = " " + GetOutputBoxForNumber(4, colorsFull[iColor]) + " " bar[i] = " " + GetOutputBoxForNumber(4, colorsFull[iColor]) + " "
iColor++ iColor++
} else { } else {
bar[i] = " " + GetOutputBoxForNumber(4, color.FgWhite.Render) + " " bar[i] = " " + GetOutputBoxForNumber(4, colorFraction) + " "
} }
} }