feat: support rect and legend line point render
This commit is contained in:
parent
8314a2cb37
commit
622bd8491b
2 changed files with 62 additions and 0 deletions
|
|
@ -373,6 +373,42 @@ func main() {
|
|||
},
|
||||
})
|
||||
|
||||
// rect
|
||||
top += 30
|
||||
p.Child(
|
||||
charts.PainterBoxOption(charts.Box{
|
||||
Top: top,
|
||||
Left: 1,
|
||||
Right: 200,
|
||||
Bottom: top + 50,
|
||||
}),
|
||||
).OverrideDrawingStyle(charts.Style{
|
||||
StrokeColor: drawing.ColorBlack,
|
||||
FillColor: drawing.ColorBlack,
|
||||
}).Rect(charts.Box{
|
||||
Left: 10,
|
||||
Top: 0,
|
||||
Right: 110,
|
||||
Bottom: 20,
|
||||
})
|
||||
// legend line dot
|
||||
p.Child(
|
||||
charts.PainterBoxOption(charts.Box{
|
||||
Top: top,
|
||||
Left: 200,
|
||||
Right: p.Width() - 1,
|
||||
Bottom: top + 50,
|
||||
}),
|
||||
).OverrideDrawingStyle(charts.Style{
|
||||
StrokeColor: drawing.ColorBlack,
|
||||
FillColor: drawing.ColorBlack,
|
||||
}).LegendLineDot(charts.Box{
|
||||
Left: 10,
|
||||
Top: 0,
|
||||
Right: 50,
|
||||
Bottom: 20,
|
||||
})
|
||||
|
||||
buf, err := p.Bytes()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
|
|||
26
painter.go
26
painter.go
|
|
@ -687,3 +687,29 @@ func (p *Painter) Dots(points []Point) *Painter {
|
|||
p.FillStroke()
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *Painter) Rect(box Box) *Painter {
|
||||
p.MoveTo(box.Left, box.Top)
|
||||
p.LineTo(box.Right, box.Top)
|
||||
p.LineTo(box.Right, box.Bottom)
|
||||
p.LineTo(box.Left, box.Bottom)
|
||||
p.LineTo(box.Left, box.Top)
|
||||
p.FillStroke()
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *Painter) LegendLineDot(box Box) *Painter {
|
||||
width := box.Width()
|
||||
height := box.Height()
|
||||
strokeWidth := 3
|
||||
dotHeight := 5
|
||||
|
||||
p.render.SetStrokeWidth(float64(strokeWidth))
|
||||
center := (height - strokeWidth) >> 1
|
||||
p.MoveTo(box.Left, box.Top+center)
|
||||
p.LineTo(box.Right, box.Top+center)
|
||||
p.Stroke()
|
||||
p.Circle(float64(dotHeight), box.Left+width>>1, center)
|
||||
p.FillStroke()
|
||||
return p
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue