@@ -9,31 +9,32 @@ import (
99 "github.com/go-analyze/charts/chartdraw"
1010)
1111
12+ // ValueFormatter defines a function that can be used to format numeric values.
1213type ValueFormatter func (float64 ) string
1314
1415var defaultValueFormatter = func (val float64 ) string {
1516 return FormatValueHumanizeShort (val , 2 , false )
1617}
1718
19+ // Painter is the primary struct for drawing charts/graphs.
1820type Painter struct {
1921 render chartdraw.Renderer
2022 box Box
21- parent * Painter
2223 style chartdraw.Style
2324 theme ColorPalette
2425 font * truetype.Font
2526 outputFormat string
2627 valueFormatter ValueFormatter
2728}
2829
30+ // PainterOptions contains parameters for creating a new Painter.
2931type PainterOptions struct {
30- // OutputFormat specifies the output type, "svg" or "png", default value is "png"
32+ // OutputFormat specifies the output type, "svg" or "png", default is "png".
3133 OutputFormat string
3234 // Width is the width of the draw painter.
3335 Width int
3436 // Height is the height of the draw painter.
3537 Height int
36- // TODO - is this the best place for font configuration?
3738 // Font is the font used for rendering text.
3839 Font * truetype.Font
3940}
@@ -87,7 +88,7 @@ func PainterPaddingOption(padding Box) PainterOption {
8788 }
8889}
8990
90- // PainterBoxOption sets the box of draw painter
91+ // PainterBoxOption sets a specific box for the Painter to draw within.
9192func PainterBoxOption (box Box ) PainterOption {
9293 return func (p * Painter ) {
9394 if box .IsZero () {
@@ -114,7 +115,8 @@ func PainterStyleOption(style chartdraw.Style) PainterOption {
114115 }
115116}
116117
117- // PainterThemeOption sets the theme of draw painter
118+ // PainterThemeOption sets a color palette theme default for the Painter.
119+ // This theme is used if the specific chart options don't have a theme set.
118120func PainterThemeOption (theme ColorPalette ) PainterOption {
119121 return func (p * Painter ) {
120122 if theme == nil {
@@ -184,13 +186,13 @@ func (p *Painter) setOptions(opts ...PainterOption) {
184186
185187func (p * Painter ) Child (opt ... PainterOption ) * Painter {
186188 child := & Painter {
187- valueFormatter : p .valueFormatter ,
188189 render : p .render ,
189190 box : p .box .Clone (),
190- parent : p ,
191191 style : p .style ,
192192 theme : p .theme ,
193193 font : p .font ,
194+ outputFormat : p .outputFormat ,
195+ valueFormatter : p .valueFormatter ,
194196 }
195197 child .setOptions (opt ... )
196198 return child
@@ -412,14 +414,17 @@ func (p *Painter) Fill() *Painter {
412414 return p
413415}
414416
417+ // Width returns the drawable width of the painter's box.
415418func (p * Painter ) Width () int {
416419 return p .box .Width ()
417420}
418421
422+ // Height returns the drawable height of the painter's box.
419423func (p * Painter ) Height () int {
420424 return p .box .Height ()
421425}
422426
427+ // MeasureText will provide the rendered size of the text for the provided font style.
423428func (p * Painter ) MeasureText (text string ) Box {
424429 return p .render .MeasureText (text )
425430}
@@ -439,6 +444,9 @@ func (p *Painter) MeasureTextMaxWidthHeight(textList []string) (int, int) {
439444 return maxWidth , maxHeight
440445}
441446
447+ // LineStroke draws a line in the graph from point to point with the specified stroke color/width.
448+ // Points with values of math.MaxInt32 will be skipped, resulting in a gap.
449+ // Single or isolated points will result in just a dot being drawn at the point.
442450func (p * Painter ) LineStroke (points []Point ) * Painter {
443451 var valid []Point
444452 for _ , pt := range points {
@@ -457,6 +465,8 @@ func (p *Painter) LineStroke(points []Point) *Painter {
457465 return p .Stroke ()
458466}
459467
468+ // drawStraightPath draws a simple (non-curved) path for the given points.
469+ // If dotForSinglePoint is true, single points are drawn as 2px radius dots.
460470func (p * Painter ) drawStraightPath (points []Point , dotForSinglePoint bool ) {
461471 pointCount := len (points )
462472 if pointCount == 0 {
@@ -576,6 +586,8 @@ func (p *Painter) SetBackground(width, height int, color Color, inside ...bool)
576586 p .FillStroke ()
577587 return p
578588}
589+
590+ // MarkLine draws a horizontal line with a small circle and arrow at the right.
579591func (p * Painter ) MarkLine (x , y , width int ) * Painter {
580592 arrowWidth := 16
581593 arrowHeight := 10
@@ -590,6 +602,7 @@ func (p *Painter) MarkLine(x, y, width int) *Painter {
590602 return p
591603}
592604
605+ // Polygon draws a polygon with the specified center, radius, and number of sides.
593606func (p * Painter ) Polygon (center Point , radius float64 , sides int ) * Painter {
594607 points := getPolygonPoints (center , radius , sides )
595608 for i , item := range points {
0 commit comments