From c220b10ae600c68112792277c5a1103499964e38 Mon Sep 17 00:00:00 2001 From: vicanso Date: Thu, 7 Jul 2022 20:50:29 +0800 Subject: [PATCH] refactor: adjust label padding of axis --- axis.go | 3 ++- bar_chart_test.go | 2 +- chart_option_test.go | 2 +- echarts_test.go | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/axis.go b/axis.go index 17e8e9f..ebc6782 100644 --- a/axis.go +++ b/axis.go @@ -154,7 +154,8 @@ func (a *axisPainter) Render() (Box, error) { textMaxWidth, textMaxHeight := top.MeasureTextMaxWidthHeight(data) - textFillWidth := float64(textMaxWidth) * 1.3 + // 增加30px来计算文本展示区域 + textFillWidth := float64(textMaxWidth + 20) textCount := ceilFloatToInt(float64(top.Width()) / textFillWidth) unit := ceilFloatToInt(float64(dataCount) / float64(chart.MaxInt(textCount, opt.SplitNumber))) // 偶数 diff --git a/bar_chart_test.go b/bar_chart_test.go index 138b3ca..f1bd688 100644 --- a/bar_chart_test.go +++ b/bar_chart_test.go @@ -102,7 +102,7 @@ func TestBarChart(t *testing.T) { } return p.Bytes() }, - result: "\\n24020016012080400JanFebMarAprMayJunJulAugSepOctNovDec24.9723.225.676.7135.6162.232.6206.43.32.65.9926.428.770.7175.6182.248.718.862.3", + result: "\\n24020016012080400FebMayAugNov24.9723.225.676.7135.6162.232.6206.43.32.65.9926.428.770.7175.6182.248.718.862.3", }, } diff --git a/chart_option_test.go b/chart_option_test.go index 5e53e46..1238422 100644 --- a/chart_option_test.go +++ b/chart_option_test.go @@ -277,7 +277,7 @@ func TestBarRender(t *testing.T) { assert.Nil(err) data, err := p.Bytes() assert.Nil(err) - assert.Equal("\\nRainfallEvaporation24020016012080400JanFebMarAprMayJunJulAugSepOctNovDec162.22182.22.341.6248.07", string(data)) + assert.Equal("\\nRainfallEvaporation24020016012080400FebMayAugNov162.22182.22.341.6248.07", string(data)) } func TestHorizontalBarRender(t *testing.T) { diff --git a/echarts_test.go b/echarts_test.go index 4d50d9e..8deda2d 100644 --- a/echarts_test.go +++ b/echarts_test.go @@ -578,5 +578,5 @@ func TestRenderEChartsToSVG(t *testing.T) { ] }`) assert.Nil(err) - assert.Equal("\\nRainfallEvaporationRainfall vs EvaporationFake Data24020016012080400JanFebMarAprMayJunJulAugSepOctNovDec162.22182.22.341.6248.07", string(data)) + assert.Equal("\\nRainfallEvaporationRainfall vs EvaporationFake Data24020016012080400FebMayAugNov162.22182.22.341.6248.07", string(data)) }