fix: fix label overflow, #13

This commit is contained in:
vicanso 2022-07-06 20:28:46 +08:00
parent b56d0c5460
commit eef3a2f97b

View file

@ -135,7 +135,11 @@ func (l *legendPainter) Render() (Box, error) {
textOffset := 2 textOffset := 2
legendWidth := 30 legendWidth := 30
legendHeight := 20 legendHeight := 20
itemMaxHeight := 0
for _, item := range measureList { for _, item := range measureList {
if item.Height() > itemMaxHeight {
itemMaxHeight = item.Height()
}
if opt.Orient == OrientVertical { if opt.Orient == OrientVertical {
height += item.Height() height += item.Height()
} else { } else {
@ -170,6 +174,10 @@ func (l *legendPainter) Render() (Box, error) {
} }
top, _ := strconv.Atoi(opt.Top) top, _ := strconv.Atoi(opt.Top)
if left < 0 {
left = 0
}
x := int(left) x := int(left)
y := int(top) + 10 y := int(top) + 10
x0 := x x0 := x
@ -199,6 +207,10 @@ func (l *legendPainter) Render() (Box, error) {
FillColor: color, FillColor: color,
StrokeColor: color, StrokeColor: color,
}) })
if x0+measureList[index].Width() > p.Width() {
x0 = 0
y0 += itemMaxHeight
}
if opt.Align != AlignRight { if opt.Align != AlignRight {
x0 = drawIcon(y0, x0) x0 = drawIcon(y0, x0)
x0 += textOffset x0 += textOffset