refactor: adjust text render of axis

This commit is contained in:
vicanso 2022-07-06 20:44:52 +08:00
parent eef3a2f97b
commit 0a3ac7096a
2 changed files with 9 additions and 2 deletions

View file

@ -153,8 +153,14 @@ func (a *axisPainter) Render() (Box, error) {
top.SetDrawingStyle(style).OverrideTextStyle(style)
textMaxWidth, textMaxHeight := top.MeasureTextMaxWidthHeight(data)
textCount := ceilFloatToInt(float64(top.Width()) / float64(textMaxWidth))
textFillWidth := float64(textMaxWidth) * 1.3
textCount := ceilFloatToInt(float64(top.Width()) / textFillWidth)
unit := ceilFloatToInt(float64(dataCount) / float64(chart.MaxInt(textCount, opt.SplitNumber)))
// 偶数
if unit%2 == 0 && dataCount%(unit+1) == 0 {
unit++
}
width := 0
height := 0

View file

@ -653,8 +653,9 @@ func (p *Painter) MultiText(opt MultiTextOption) *Painter {
} else {
values = autoDivide(width, count)
}
showIndex := opt.Unit / 2
for index, text := range opt.TextList {
if opt.Unit != 0 && index%opt.Unit != 0 {
if opt.Unit != 0 && index%opt.Unit != showIndex {
continue
}
box := p.MeasureText(text)