refactor: auto count the split number for x axis

This commit is contained in:
vicanso 2022-02-06 09:55:27 +08:00
parent 3219ce521b
commit c01f4001f1
6 changed files with 134 additions and 58 deletions

13
util.go
View file

@ -62,15 +62,6 @@ func autoDivide(max, size int) []int {
values[size] = max
return values
}
func maxInt(values ...int) int {
result := 0
for _, v := range values {
if v > result {
result = v
}
}
return result
}
// measureTextMaxWidthHeight returns maxWidth and maxHeight of text list
func measureTextMaxWidthHeight(textList []string, r chart.Renderer) (int, int) {
@ -78,8 +69,8 @@ func measureTextMaxWidthHeight(textList []string, r chart.Renderer) (int, int) {
maxHeight := 0
for _, text := range textList {
box := r.MeasureText(text)
maxWidth = maxInt(maxWidth, box.Width())
maxHeight = maxInt(maxHeight, box.Height())
maxWidth = chart.MaxInt(maxWidth, box.Width())
maxHeight = chart.MaxInt(maxHeight, box.Height())
}
return maxWidth, maxHeight
}