refactor: adjust text render of axis
This commit is contained in:
parent
eef3a2f97b
commit
0a3ac7096a
2 changed files with 9 additions and 2 deletions
8
axis.go
8
axis.go
|
|
@ -153,8 +153,14 @@ func (a *axisPainter) Render() (Box, error) {
|
||||||
top.SetDrawingStyle(style).OverrideTextStyle(style)
|
top.SetDrawingStyle(style).OverrideTextStyle(style)
|
||||||
|
|
||||||
textMaxWidth, textMaxHeight := top.MeasureTextMaxWidthHeight(data)
|
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)))
|
unit := ceilFloatToInt(float64(dataCount) / float64(chart.MaxInt(textCount, opt.SplitNumber)))
|
||||||
|
// 偶数
|
||||||
|
if unit%2 == 0 && dataCount%(unit+1) == 0 {
|
||||||
|
unit++
|
||||||
|
}
|
||||||
|
|
||||||
width := 0
|
width := 0
|
||||||
height := 0
|
height := 0
|
||||||
|
|
|
||||||
|
|
@ -653,8 +653,9 @@ func (p *Painter) MultiText(opt MultiTextOption) *Painter {
|
||||||
} else {
|
} else {
|
||||||
values = autoDivide(width, count)
|
values = autoDivide(width, count)
|
||||||
}
|
}
|
||||||
|
showIndex := opt.Unit / 2
|
||||||
for index, text := range opt.TextList {
|
for index, text := range opt.TextList {
|
||||||
if opt.Unit != 0 && index%opt.Unit != 0 {
|
if opt.Unit != 0 && index%opt.Unit != showIndex {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
box := p.MeasureText(text)
|
box := p.MeasureText(text)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue