From 959377542e2a1fa1daaec7defdfd56195d3ea4d9 Mon Sep 17 00:00:00 2001 From: vicanso Date: Fri, 8 Jul 2022 21:11:47 +0800 Subject: [PATCH] fix: fix multi line label --- chart_option_test.go | 4 ++-- legend.go | 7 +++++-- line_chart_test.go | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/chart_option_test.go b/chart_option_test.go index 1238422..0cdc2aa 100644 --- a/chart_option_test.go +++ b/chart_option_test.go @@ -204,7 +204,7 @@ func TestLineRender(t *testing.T) { assert.Nil(err) data, err := p.Bytes() assert.Nil(err) - assert.Equal("\\nEmailUnion AdsVideo AdsDirectSearch EngineLine1.44k1.2k9607204802400MonTueWedThuFriSatSun", string(data)) + assert.Equal("\\nEmailUnion AdsVideo AdsDirectSearch EngineLine1.44k1.2k9607204802400MonTueWedThuFriSatSun", string(data)) } func TestBarRender(t *testing.T) { @@ -277,7 +277,7 @@ func TestBarRender(t *testing.T) { assert.Nil(err) data, err := p.Bytes() assert.Nil(err) - assert.Equal("\\nRainfallEvaporation24020016012080400FebMayAugNov162.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/legend.go b/legend.go index d3b135e..820f1b5 100644 --- a/legend.go +++ b/legend.go @@ -146,6 +146,8 @@ func (l *legendPainter) Render() (Box, error) { width += item.Width() } } + // 增加padding + itemMaxHeight += 10 if opt.Orient == OrientVertical { width = maxTextWidth + textOffset + legendWidth height = offset * len(opt.Data) @@ -207,9 +209,10 @@ func (l *legendPainter) Render() (Box, error) { FillColor: color, StrokeColor: color, }) - if x0+measureList[index].Width() > p.Width() { + if x0+measureList[index].Width()+textOffset+offset+legendWidth > p.Width() { x0 = 0 - y0 += itemMaxHeight + y += itemMaxHeight + y0 = y } if opt.Align != AlignRight { x0 = drawIcon(y0, x0) diff --git a/line_chart_test.go b/line_chart_test.go index 856cdf3..ff80741 100644 --- a/line_chart_test.go +++ b/line_chart_test.go @@ -117,7 +117,7 @@ func TestLineChart(t *testing.T) { } return p.Bytes() }, - result: "\\nEmailUnion AdsVideo AdsDirectSearch EngineLine1.44k1.2k9607204802400MonTueWedThuFriSatSun", + result: "\\nEmailUnion AdsVideo AdsDirectSearch EngineLine1.44k1.2k9607204802400MonTueWedThuFriSatSun", }, { render: func(p *Painter) ([]byte, error) { @@ -201,7 +201,7 @@ func TestLineChart(t *testing.T) { } return p.Bytes() }, - result: "\\nEmailUnion AdsVideo AdsDirectSearch EngineLine1.44k1.2k9607204802400MonTueWedThuFriSatSun", + result: "\\nEmailUnion AdsVideo AdsDirectSearch EngineLine1.44k1.2k9607204802400MonTueWedThuFriSatSun", }, }