From 0a3ac7096a30b41861faa8cb96bfa1bf84a7465c Mon Sep 17 00:00:00 2001 From: vicanso Date: Wed, 6 Jul 2022 20:44:52 +0800 Subject: [PATCH] refactor: adjust text render of axis --- axis.go | 8 +++++++- painter.go | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/axis.go b/axis.go index 53b5362..17e8e9f 100644 --- a/axis.go +++ b/axis.go @@ -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 diff --git a/painter.go b/painter.go index 62a4378..0771288 100644 --- a/painter.go +++ b/painter.go @@ -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)