diff --git a/plotter/field.go b/plotter/field.go index 34a47e32..6817f2f7 100644 --- a/plotter/field.go +++ b/plotter/field.go @@ -44,10 +44,14 @@ type Field struct { // but should not be used to determine size or // directions of the glyph. // - // If DrawGlyph is nil, a simple black arrow will - // be drawn. + // If DrawGlyph is nil, a simple arrow will be + // drawn. DrawGlyph func(c vg.Canvas, v XY) + // LineStyle is the style of the line used to + // render vectors if DrawGlyph is nil. + LineStyle draw.LineStyle + // max define the dynamic range of the field. max float64 } @@ -68,13 +72,18 @@ func NewField(f FieldXY) *Field { } return &Field{ - FieldXY: f, - max: max, + FieldXY: f, + LineStyle: DefaultLineStyle, + max: max, } } // Plot implements the Plot method of the plot.Plotter interface. func (f *Field) Plot(c draw.Canvas, plt *plot.Plot) { + c.Push() + c.SetLineStyle(f.LineStyle) + defer c.Pop() + trX, trY := plt.Transforms(&c) cols, rows := f.FieldXY.Dims() diff --git a/plotter/field_test.go b/plotter/field_test.go index 0e42b65e..7702840d 100644 --- a/plotter/field_test.go +++ b/plotter/field_test.go @@ -48,6 +48,7 @@ func ExampleField() { } }, }) + f.LineStyle.Width = 0.2 p, err := plot.New() if err != nil { diff --git a/plotter/testdata/field_golden.png b/plotter/testdata/field_golden.png index ba739acd..ccb426b8 100644 Binary files a/plotter/testdata/field_golden.png and b/plotter/testdata/field_golden.png differ