-
Notifications
You must be signed in to change notification settings - Fork 757
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
Topic/plotter fix resample #4223
Topic/plotter fix resample #4223
Conversation
The previous version assumed a linear distribution of gridlines, so if, e.g. a Plotter’s specs or domainSpecs were set to anything other than a linear spec, the gridlines were drawn at incorrect locations.
Resampling the data changes the number of values in the plot, and when domain is specified, there is one domain value for every original data point. So if resampling is to be supported when the domain is set, domain values will also need to be resampled.
…values. Previous used resamp1, which allows floating-point resample argument, resulting in a last value which isn’t the last in the data, but rather one just short of it. For example resampled data that’s fairly linear may appear to not reach its final value. This method ensures correct start and end values, and has evenly spaced sampling within those values that is a least ‘resolution’ pixels.
…l as resolution. And clarify resolution method description.
eccc665
to
6280aaf
Compare
Update: rebased onto |
@@ -114,11 +116,11 @@ Plot { | |||
drawGrid.vertGrid = if(gridOnY,{spec.grid},{nil}); | |||
} | |||
|
|||
draw { | |||
draw { |mode = \linear| |
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.
There are many properties that are local to each Plot
channel. Is there a reason that mode
is special? Normally, I would tend to keep all the local properties as instance variable in the Plot
object, so that we don't have to pass it around. So far, it is global, so it is in the Plotter
.
If it should be local, it is more efficient to keep it in the object. But of course there are sometimes reasons you may want to draw the same plot object differently - but this doesn't seem the case 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.
Thanks for giving me the opportunity to rethink this.
The goal here was to add the ability to have each plot be different mode (similar to how each plot can be a different color). When I jumped into this I tried quickly to make plotMode
local, but there was a conflict with the way Plot
shape-shifts when superposed
—it becomes a single plot with multiple lines, not multiple plots overlaid. This meant that the plotMode
would need to be passed in, or queried from Plotter
(as it is with a single plotMode
). I opted to be able to pass it in, assuming that there was a use case for using Plot
without Plotter
. This review gave me the opportunity to look closer to see that this isn't really a valid use case—Plot
is only used through a Plotter
—so I've modeled an update on the way plotColor
is handled. See my comments in the main conversation about how that should be submitted...
var ycoord = this.dataCoordinates; | ||
var xcoord = this.domainCoordinates(ycoord.size); | ||
mode = (mode ?? plotter.plotMode).asArray; |
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 would then just be the instance variable of the Plot
object.
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.
As described above, because there was originally no instance variable for this in Plot
, in an attempt to keep it global and free the dependency on Plotter
, I opted to pass this in from outside. I've rethought this though, see more following...
@@ -201,8 +204,8 @@ Plot { | |||
Pen.beginPath; | |||
Pen.strokeColor = plotColor.at(0); | |||
Pen.fillColor= plotColor.at(0); | |||
this.perform(mode, xcoord, ycoord); | |||
if (this.needsPenFill(mode)) { | |||
this.perform(mode.at(0), xcoord, ycoord); |
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.
mode.at(0)
seems not correct if the mode of each plot is different.
Maybe you intended that there could be different modes for each channel?
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.
Yes, the new feature here is to add the ability for multiple plot modes, as you can have multiple plot colors. When Plotter
is not superpose
d, each Plot
has only one plot mode, whereas when superpose
is true
the plot mode is an array of modes. IIC, I've redesigned this. See the main thread...
@telephon, thanks for getting the review underway! I'll be following up shortly. It's been a while since I started this PR so I'll need to review it myself! |
OK, I've had a chance to review this and you raised good points that gave me the opportunity to redesign the behavior of To digress a bit, when I revisited this PR recently, I hastily assumed this was actually a different PR in the same part of the code (I forgot this other one had already been merged). This So now that I've revised the change, I'm thinking it may be better to roll back this PR to 64081f5 to confine it on the resampling topic, and submit this new |
9ab7d22
to
64081f5
Compare
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.
thank you!
scratch that, I see this has the |
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.
Everything looks good to me. Grids reflect ControlSpec properly now, resample works as intended.
Purpose and Motivation
This PR brings more support to specifying specs in
Plotter
, and related issues regarding GridLines andresolution
.Types of changes
This fixes a few issues regarding plotting:
Grid
now follows the warping of its spec. Before the warp was assumed to be linear, so if, e.g. you assigned an exponential spec to the domain (domainSpecs_
) or codomain (specs_
) inPlotter
, the gridlines wouldn't be at the correct locations.Plotter
resamples values if the number of values exceeded the plot width (or specified resolution). However setting the domain requires one domain value for every data point, so domain locations aren't correct when resampling. So now if the domain is set, the values won't be resampled.prResampValues
method, which enforces theresolution
, now also catches a change in resolution, which before wouldn't be caught unless the window was resized (wouldn't be caught on refresh either).prResampValues
method now resamples differently. The previous approach usedSequenceableCollection : resamp1
, which allows floating-point resample argument resulting in a last value which isn’t the last in the array, but rather one just short of it. In plotting, this means that resampled data may appear to not reach the final value. This new approach ensures correct start and end values, and has evenly spaced (re)sampling that is at leastresolution
pixels.resolution
setter method.An example of improper resampling:
An example of resolution not updating:
Checklist