diff --git a/examples/painter/main.go b/examples/painter/main.go index d0eec73..8b0a157 100644 --- a/examples/painter/main.go +++ b/examples/painter/main.go @@ -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) diff --git a/painter.go b/painter.go index 78d8925..95469f3 100644 --- a/painter.go +++ b/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 +}