Skip to content

Commit

Permalink
plotter: add line styling to Field
Browse files Browse the repository at this point in the history
  • Loading branch information
kortschak committed Apr 4, 2019
1 parent c7c0a3c commit 0735d75
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
17 changes: 13 additions & 4 deletions plotter/field.go
Expand Up @@ -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
}
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions plotter/field_test.go
Expand Up @@ -48,6 +48,7 @@ func ExampleField() {
}
},
})
f.LineStyle.Width = 0.2

p, err := plot.New()
if err != nil {
Expand Down
Binary file modified plotter/testdata/field_golden.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0735d75

Please sign in to comment.