-
Notifications
You must be signed in to change notification settings - Fork 205
plotter: add vector field plotter #543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
e870227
to
8ca2bf2
Compare
Codecov Report
@@ Coverage Diff @@
## master #543 +/- ##
==========================================
+ Coverage 68.77% 69.15% +0.37%
==========================================
Files 50 51 +1
Lines 5208 5304 +96
==========================================
+ Hits 3582 3668 +86
- Misses 1456 1464 +8
- Partials 170 172 +2
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #543 +/- ##
==========================================
+ Coverage 68.77% 69.15% +0.37%
==========================================
Files 50 51 +1
Lines 5208 5304 +96
==========================================
+ Hits 3582 3668 +86
- Misses 1456 1464 +8
- Partials 170 172 +2
Continue to review full report at Codecov.
|
874ca5f
to
f7aefe5
Compare
f7aefe5
to
e4119b4
Compare
plotter/field.go
Outdated
// Dims returns the dimensions of the grid. | ||
Dims() (c, r int) | ||
|
||
// Vector returns the value of a grid value at (c, r). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe Vector returns the magnitude in the X and Y directions at grid column and row (c, r).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Vector returns the value of a vector field at (c, r).
// It will panic if c or r are out of bounds for the field.
field.go is derived heavily from heat.go and there are copy/paste errors that reflect that. This is one of those.
plotter/field.go
Outdated
// It will panic if c or r are out of bounds for the grid. | ||
Vector(c, r int) XY | ||
|
||
// X returns the coordinate for the column at the index x. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/index x/index c/g
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. This will also need to be fixed in heat.go.
plotter/field.go
Outdated
} | ||
|
||
// NewField creates as new heat map plotter for the given data, | ||
// using the provided palette. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provided palette?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
// | ||
// If DrawGlyph is nil, a simple black arrow will | ||
// be drawn. | ||
DrawGlyph func(c vg.Canvas, v XY) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if a user wants to change the color of the glyph based on the field magnitude? What if a user wants to scale the size of the glyph based on the square root of magnitude, or some other transform?
I think both of these things would be allowed if we made the field magnitude an argument here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or maybe the normalized magnitude.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or, actually, providing the row and column indexes as arguments would probably be better, because then the user can pull in whatever external information they need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the user wants to change the colour based on the magnitude, they can calculate the magnitude from v
. This was the major reason v was included (which is the normalised vector).
I don't like the idea of a completely free approach to transforms. It opens up whole new world of issues to have to answer. This is simple and works for the vast majority of cases with close to zero work for the user. Allowing scaling by other than linear seems to me like an anti-pattern; the two commonly used scalings are length and area (in that order). People are bad at assessing area compared to length (this is a reason why pie charts are bad).
I can see some merits in providing the row/column, but I need to think about it some more. I'm not sure the additional complexity wins much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I somehow missed the fact that v
was already included as an argument.
@@ -0,0 +1,146 @@ | |||
// Copyright ©2019 The Gonum Authors. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make the examples more legible in godoc, it might make sense to split the examples and tests up into individual files. From the documentation:
A whole file example is a file that ends in _test.go and contains exactly one example function, no test or benchmark functions, and at least one other package-level declaration. When displaying such examples godoc will show the entire file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is another PR. The example code that this is adapted from, heat_test.go is the same. In fact I think they all are because the TestX
funcs are in the same files.
plotter/field_test.go
Outdated
func (f field) Vector(c, r int) plotter.XY { return f.fn(f.X(c), f.Y(r)) } | ||
func (f field) X(c int) float64 { | ||
if c < 0 || c >= f.c { | ||
panic("index out of range") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"x index out of range"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is example code, but OK.
Same in heat_test.go.
plotter/field_test.go
Outdated
} | ||
func (f field) Y(r int) float64 { | ||
if r < 0 || r >= f.r { | ||
panic("index out of range") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"y index out of range"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
// | ||
// If DrawGlyph is nil, a simple black arrow will | ||
// be drawn. | ||
DrawGlyph func(c vg.Canvas, v XY) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I somehow missed the fact that v
was already included as an argument.
I'll wait for @sbinet as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (modulo 2 minor nit-picks)
PTAL |
AppVeyor is horrifically slow here. Do we use your identity on that @sbinet? We probably shouldn't since you're doing other things as well. Do they have organisation accounts like travis does? I have to say, the service they have is pretty disappointing. |
their handling of org accounts is a bit confusing, and, at the very least not very straighforward, indeed... |
Please take a look.
/cc @chewxy