-
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
Plotter: fix grid and axis labels #5827
Conversation
77142f4
to
9365364
Compare
I've rebased this branch onto #4511 to avoid conflicts with updates in that PR, so it should be merged AFTER that one. |
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!
Also distinguish between x and y grid edges when getting label size
00cf6d9
to
3585fc7
Compare
OK, I've rebased onto Update: regarding the failed jobs, there are 2 failed tests in |
Yes, some tests that use the server occasionally and inconsistently fail, unfortunately. |
While I was resuming work on #5161, I noticed that this PR dropped ControlSpec units from the Grid labels. I understand that having a single label in the plotter is better, but it also made (
c = ControlSpec.new(20,20000, \lin, units:"Hz");
g = GridLines(c);
d = DrawGrid.test(g, g, 300@300);
) before this PR: I have a workaround for the cropping that I'm using while I work on the other PR, but I'm not sure what's the best/easiest way to add units to What do you think @mtmccrea @telephon ? For reference, here's my current workaround for DrawGrid {
(...)
*test { arg horzGrid,vertGrid,bounds;
var w, grid, insetW = 0, insetH = 0;
bounds = bounds ?? {Rect(0,0,500,400)};
grid = DrawGrid(bounds,horzGrid,vertGrid);
grid.x.labelOffset = 20 @ 18;
grid.y.labelOffset = 20 @ 20;
horzGrid !? {insetH = 20};
vertGrid !? {insetW = 26};
w = Window("Grid",bounds).front;
UserView(w,bounds ?? {w.bounds.moveTo(0,0)})
.resize_(5)
.drawFunc_({ arg v;
grid.bounds = v.bounds.insetAll(insetW, 0, 0, insetH);
grid.draw
})
.background_(Color.white)
^grid
}
} |
Thanks for catching this, @dyfer! This gave me the opportunity to look more closely at code ...*test { arg horzGrid, vertGrid, bounds;
var w, grid;
var insetH = 40, insetV = 20; // left, bottom margins for labels
var pad = 15; // right, top margin
bounds = bounds ?? { Rect(0, 0, 500, 400) };
bounds = bounds.asRect; // in case bounds are a Point
insetH = insetH + pad;
insetV = insetV + pad;
grid = DrawGrid(
bounds.insetBy(insetH.half, insetV.half).moveTo(insetH-pad, pad),
horzGrid, vertGrid
);
grid.x.labelOffset = insetH @ insetV.half;
grid.y.labelOffset = insetH @ insetV.half;
w = Window("Grid", bounds).front;
UserView(w, bounds ?? { w.bounds.moveTo(0,0) })
.drawFunc_({ |v| grid.draw })
.onResize_({ |v|
grid.bounds = v.bounds.insetBy(insetH.half, insetV.half).moveTo(insetH - pad, pad);
})
.resize_(5)
.background_(Color.white);
^grid
} The full fix would also need this setter to be swapped into
But may not be wouldn't be necessary for your testing...
My example also hard-codes margins, but wide enough for testing default specs, I think.
That's my impression also. The docs make it seem like
That's because the spec goes from 20 -> 20k, so GridLines doesn't return a label for 20 Hz (steps are 5k). changing the spec from 0 -> 20k would show a label for 0. This is also in part because the recent PR also makes sure grid lines are drawn at the boundaries of the grid, whether or not a labeled gridline coincides with the boundaries. Without this, you would have "uncapped" edges of the plot, which looks strange (see my screenshots in the first post). I think it's still reasonable to have made these design decisions based on the In any case, is the best way to patch this by creating a new PR or somehow amend this one? I'd like to revisit this tomorrow, re-test and update docs before pushing. |
Almost... in this case, previously, there would have been no first line/label, just blank space (the 'quantized' GridLines would have started at 5k). This PR added lines at the extents of the grid. You can see this behavior by dynamically resizing the window and watching how the grid behaves at the extents.
Yes, this would actually be a change in
Ok, I'll put together a new PR 👍
I'll look into this...
The 'before' and 'after' images above aren't exact comparisons, because the plot sizes were just adjusted by hand to show a variety of behavior, including when labels automatically disappear below window size limits. So the case you highlighted likely isn't omitting units in particular, it's omitting all of the y-labels (axis and grid labels) altogether because of the size of the window, but I'll confirm this too. |
See #5858 for the updated behavior: |
Purpose and Motivation
This adds full support for grid labels and axis labels for
Plotter
.Types of changes
Changes
.0
if all grid labels are whole numberssetProperties
[x] Documentation
[x] Bug fix
[x] New feature
Some examples of the changes:
Note axis labels, grid labels, labels disappearing under height/width size limits, units listed as axis labels instead of grid labels, grid lines appearing at max/min plot bounds, etc.
To-do list
TestPlotter
)