add split string func
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"cpone/db"
|
||||
"cpone/models"
|
||||
dbx "cpone/package/database"
|
||||
"cpone/utils"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
@@ -241,8 +242,9 @@ func (tkf *TabKelainanFisikServices) GetKelainanFisikPresentase(mcuID string) (m
|
||||
percentage := float64(d.Total) / float64(jumlahPeserta.Peserta) * 100
|
||||
roundedPercentage := math.Round(percentage*100) / 100
|
||||
percentStr := strconv.FormatFloat(roundedPercentage, 'f', -1, 64)
|
||||
newText := utils.SplitStrings(d.Mcu_KelainanName, 2)
|
||||
chartData.Source = append(chartData.Source, []interface{}{
|
||||
i, d.Total, d.Mcu_KelainanName, percentStr,
|
||||
i, d.Total, newText, percentStr,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"cpone/db"
|
||||
"cpone/models"
|
||||
dbx "cpone/package/database"
|
||||
"cpone/utils"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
@@ -310,8 +311,9 @@ func (tkg *TabKelainanGlobalServices) GetKelainanGlobalV2(mcuID string) (models.
|
||||
percentage := float64(d.Total) / float64(jumlahPeserta.Peserta) * 100
|
||||
roundedPercentage := math.Round(percentage*100) / 100
|
||||
percentStr := strconv.FormatFloat(roundedPercentage, 'f', -1, 64)
|
||||
newText := utils.SplitStrings(d.Test, 2)
|
||||
chartData.Source = append(chartData.Source, []interface{}{
|
||||
i, d.Total, d.Test, percentStr,
|
||||
i, d.Total, newText, percentStr,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"cpone/db"
|
||||
"cpone/models"
|
||||
dbx "cpone/package/database"
|
||||
"cpone/utils"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
@@ -132,8 +133,9 @@ func (tkl *TabKelainanLabServices) ConfBarchartVertical(title string, data []mod
|
||||
|
||||
cnt := len(data)
|
||||
for idx, d := range data {
|
||||
newText := utils.SplitStrings(d.Mcu_KelainanName, 2)
|
||||
chartData.Source = append(chartData.Source, []interface{}{
|
||||
idx, d.Total, d.Mcu_KelainanName,
|
||||
idx, d.Total, newText,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -166,7 +168,7 @@ func (tkl *TabKelainanLabServices) ConfBarchartVertical(title string, data []mod
|
||||
Rotate int "json:\"rotate\""
|
||||
}{
|
||||
Interval: 0,
|
||||
Rotate: 20,
|
||||
Rotate: 0,
|
||||
},
|
||||
},
|
||||
YAxis: struct {
|
||||
@@ -336,8 +338,9 @@ func (tkl *TabKelainanLabServices) GetDataPresentaseKelainanLab(mcuID string) (m
|
||||
percentage := float64(d.Total) / float64(jumlahPeserta.Peserta) * 100
|
||||
roundedPercentage := math.Round(percentage*100) / 100
|
||||
percentStr := strconv.FormatFloat(roundedPercentage, 'f', -1, 64)
|
||||
newText := utils.SplitStrings(d.Mcu_KelainanName, 2)
|
||||
chartData.Source = append(chartData.Source, []interface{}{
|
||||
i, d.Total, d.Mcu_KelainanName, percentStr,
|
||||
i, d.Total, newText, percentStr,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"cpone/db"
|
||||
"cpone/models"
|
||||
dbx "cpone/package/database"
|
||||
"cpone/utils"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
@@ -132,15 +133,16 @@ func (tknl *TabKelainanNonLabServices) ConfBarchartVertical(title string, data [
|
||||
|
||||
cnt := len(data)
|
||||
for idx, d := range data {
|
||||
if len(d.Test) > 30 {
|
||||
var newText = d.Test[:30] + "- \n" + d.Test[30:]
|
||||
chartData.Source = append(chartData.Source, []interface{}{
|
||||
idx, d.Total, newText,
|
||||
})
|
||||
continue
|
||||
}
|
||||
// if len(d.Test) > 30 {
|
||||
// var newText = d.Test[:30] + "- \n" + d.Test[30:]
|
||||
// chartData.Source = append(chartData.Source, []interface{}{
|
||||
// idx, d.Total, newText,
|
||||
// })
|
||||
// continue
|
||||
// }
|
||||
newText := utils.SplitStrings(d.Test, 2)
|
||||
chartData.Source = append(chartData.Source, []interface{}{
|
||||
idx, d.Total, d.Test,
|
||||
idx, d.Total, newText,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -173,7 +175,7 @@ func (tknl *TabKelainanNonLabServices) ConfBarchartVertical(title string, data [
|
||||
Rotate int "json:\"rotate\""
|
||||
}{
|
||||
Interval: 0,
|
||||
Rotate: 20,
|
||||
Rotate: 0,
|
||||
},
|
||||
},
|
||||
YAxis: struct {
|
||||
@@ -343,8 +345,9 @@ func (tknl *TabKelainanNonLabServices) GetDataKelNonLab(mcuID string) (models.Ba
|
||||
percentage := float64(d.Total) / float64(jumlahPeserta.Peserta) * 100
|
||||
roundedPercentage := math.Round(percentage*100) / 100
|
||||
percentStr := strconv.FormatFloat(roundedPercentage, 'f', -1, 64)
|
||||
newText := utils.SplitStrings(d.Test, 2)
|
||||
chartData.Source = append(chartData.Source, []interface{}{
|
||||
i, d.Total, d.Test, percentStr,
|
||||
i, d.Total, newText, percentStr,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
// InterpolateColor calculates a color between two given colors based on progress (0 to 1)
|
||||
func InterpolateColor(start, end string, progress float64) string {
|
||||
r1, g1, b1 := HexToRGB(start)
|
||||
r2, g2, b2 := HexToRGB(end)
|
||||
|
||||
r := int(math.Round(float64(r1)*(1-progress) + float64(r2)*progress))
|
||||
g := int(math.Round(float64(g1)*(1-progress) + float64(g2)*progress))
|
||||
b := int(math.Round(float64(b1)*(1-progress) + float64(b2)*progress))
|
||||
|
||||
return fmt.Sprintf("#%02x%02x%02x", r, g, b)
|
||||
}
|
||||
|
||||
// Helper function to convert hex to RGB
|
||||
func HexToRGB(hex string) (int, int, int) {
|
||||
var r, g, b int
|
||||
_, err := fmt.Sscanf(hex, "#%02x%02x%02x", &r, &g, &b)
|
||||
if err != nil {
|
||||
return 0, 0, 0
|
||||
}
|
||||
return r, g, b
|
||||
}
|
||||
18
utils/splitStrings.utils.go
Normal file
18
utils/splitStrings.utils.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package utils
|
||||
|
||||
import "strings"
|
||||
|
||||
func SplitStrings(text string, count int) string {
|
||||
words := strings.Split(text, " ")
|
||||
var result strings.Builder
|
||||
|
||||
for i := 0; i < len(words); i += count {
|
||||
if i+count < len(words) {
|
||||
result.WriteString(strings.Join(words[i:i+count], " ") + "\n")
|
||||
} else {
|
||||
result.WriteString(strings.Join(words[i:], " "))
|
||||
}
|
||||
}
|
||||
|
||||
return result.String()
|
||||
}
|
||||
Reference in New Issue
Block a user