fix: fix unit count of xasix
This commit is contained in:
parent
3d20bea846
commit
cac6fd03d3
3 changed files with 10 additions and 4 deletions
7
axis.go
7
axis.go
|
|
@ -156,8 +156,11 @@ func (a *axisPainter) Render() (Box, error) {
|
||||||
|
|
||||||
// 增加30px来计算文本展示区域
|
// 增加30px来计算文本展示区域
|
||||||
textFillWidth := float64(textMaxWidth + 20)
|
textFillWidth := float64(textMaxWidth + 20)
|
||||||
textCount := ceilFloatToInt(float64(top.Width()) / textFillWidth)
|
// 根据文本宽度计算较为符合的展示项
|
||||||
unit := ceilFloatToInt(float64(dataCount) / float64(chart.MaxInt(textCount, opt.SplitNumber)))
|
fitTextCount := ceilFloatToInt(float64(top.Width()) / textFillWidth)
|
||||||
|
|
||||||
|
unit := ceilFloatToInt(float64(dataCount) / float64(fitTextCount))
|
||||||
|
unit = chart.MaxInt(unit, opt.SplitNumber)
|
||||||
// 偶数
|
// 偶数
|
||||||
if unit%2 == 0 && dataCount%(unit+1) == 0 {
|
if unit%2 == 0 && dataCount%(unit+1) == 0 {
|
||||||
unit++
|
unit++
|
||||||
|
|
|
||||||
|
|
@ -108,9 +108,12 @@ func TitleOptionFunc(title TitleOption) OptionFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TitleTextOptionFunc set title text of chart
|
// TitleTextOptionFunc set title text of chart
|
||||||
func TitleTextOptionFunc(text string) OptionFunc {
|
func TitleTextOptionFunc(text string, subtext ...string) OptionFunc {
|
||||||
return func(opt *ChartOption) {
|
return func(opt *ChartOption) {
|
||||||
opt.Title.Text = text
|
opt.Title.Text = text
|
||||||
|
if len(subtext) != 0 {
|
||||||
|
opt.Title.Subtext = subtext[0]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -232,7 +232,7 @@ func (l *legendPainter) Render() (Box, error) {
|
||||||
x0 += measureList[index].Width()
|
x0 += measureList[index].Width()
|
||||||
if opt.Align == AlignRight {
|
if opt.Align == AlignRight {
|
||||||
x0 += textOffset
|
x0 += textOffset
|
||||||
x0 = drawIcon(0, x0)
|
x0 = drawIcon(y0, x0)
|
||||||
}
|
}
|
||||||
if opt.Orient == OrientVertical {
|
if opt.Orient == OrientVertical {
|
||||||
y0 += offset
|
y0 += offset
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue