-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[graf2d] allow zero outer margins when dividing canvas #20209
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
base: master
Are you sure you want to change the base?
Conversation
When nx or ny is negative, the pads is divided according to abs(nx) or abs(ny), but the outer margins is set to 0. The inner margins are equal to xmargin and ymargin, respectively.
ad4dab7 to
9eb99eb
Compare
|
I force pushed small fix. In the previous version I was generating margins twice smaller than in the original implementation. So in my implementation whenever I use |
|
@couet But I started to have a second thoughts. Unfortunately, my proposed solution, if run on older ROOT version, will fall for the previous behavior: if (nx <= 0) nx = 1;
if (ny <= 0) ny = 1;and if someones does So perhaps other idea would be one of two:
void TPad::Divide(Int_t nx, Int_t ny, Float_t xmargin, Float_t ymargin, Int_t color, Float_t xmargin_outer = 999.0, Float_t ymargin_outer = 999.0)or make an overload: void TPad::Divide(Int_t nx, Int_t ny, Float_t xmargin, Float_t ymargin, Int_t color, Float_t xmargin_outer, Float_t ymargin_outer)This is more flexible as allows to adjust the outer margin - may not be 0 but may also be smaller than inner margins. If value is 1 or more (for the case with defaults), then inner |
|
I do not think a negative marging has some meaning. It is not allowed. In SetMargin one can see this protection: |
But documentation says something else. Please see this comment: #20138 (comment) and see the image which is just above. The lower row of canavses has odd behavior - non-zero top-right margins. I reported that in my first issue. And in the code the top-right margin is somehow treated in a special way. So perhaps this special case should be removed? Perhaps it is some very obsolete code and not relevant today? |
|
Ok I need to check.... |
|
The margins <0 means there is now space between the pads. May be there is somthing wrong in that case. Does your PR fixes it ? That's very old code which was not change since 21 years. May be it can be improved as you suggest. |
|
I tried to not modify this behavior as it was explicitly documented, so assumed that it is important to keep it as it is. So I changed from initial idea of using negative margins to negative divisions numbers. But if you say, I can get back to initial idea of negative margins, and remove the this old obsolete code. |
|
Yes negative margins means no spaces betwen the pads. This code was introduced by this PR: e2cbbfc it says: Extend the functionality of TPad::Divide when xmargin=0 and ymargin=0. When you run this example it looks fine. |
|
Margins set to 0 are fine. But margins set to negative number give the odd top-right non-negative margin, and left-bottom zero margin. See the middle row of the image on top of the page. |
|
In the example above (given in the original PR) if i put negative margins like: I get exactly the same plot as the original with margins = 0. |
I guess it leaves as much margin on the right part as the space on the left for the y axis labels? Same for top vs bottom x labels. So that the axes lines are centered. |
|
Ok, after this explanation it is much more clearer for me why this mode is introduced, so also it shouldn't be touched. I don't know, maybe it is only me, but perhaps the documentation could be slightly reworded to made it clearer. But as I just say, maybe it's only me who didn't get the idea. But that means I have no good way to implement my idea of outer margins. The only idea left for me for now is to:
void TPad::Divide(Int_t nx, Int_t ny, Float_t xmargin, Float_t ymargin, Int_t color, Float_t xmargin_outer = 999.0, Float_t ymargin_outer = 999.0)
void TPad::Divide(Int_t nx, Int_t ny, Float_t xmargin, Float_t ymargin, Int_t color, Float_t xmargin_outer, Float_t ymargin_outer) |
|
Yes a better explanation will be useful. Also this example is may be useful. |
|
No, this example works only if you use the optimized mode. It will not work if both margins are non-negative. As it was in the old code (before my PR): dy = 1/Double_t(ny);
dx = 1/Double_t(nx);
for (iy=0;iy<ny;iy++) {
y2 = 1 - iy*dy - ymargin;
y1 = y2 - dy + 2*ymargin;so this line ignores the top canvas margins. It could be changed to work with top margins and in my opinion it would be most elegant, but will break existing macros. But with proper documentation, could we live with this backward compatibility breakage? |
e5aa4ef to
23f2d45
Compare
With this design pad is divided into subpads respecting the pad margins (old behavior: outer margins were equal to x/y margin). The x/y margin argument of the TPad::Divide is now a distance between subpads (old behavior: distance between pads was 2* x/y margin). This design allows to control the exact layout of subpads. This change will break existing code. If the old code was: c->Divide(3, 2, 0.02, 0.01); new code must be: c->SetLeftMargin(0.02); // old xmargin c->SetBottomMargin(0.01); // old ymargin c->SetRightMargin(0.02); // old xmargin c->SetTopMargin(0.01); // old ymargin c->Divide(3, 2, 0.04, 0.02); // two times old x,y margins to achieve the same result.
23f2d45 to
b948427
Compare
|
I also updated the documentation. In case that this PR would not be accepted, one has to update the doc of /// - xmargin is the space along x between pads in percent of canvas.
/// - ymargin is the space along y between pads in percent of canvas.This is more correct (could be add to #20260): /// - xmargin is the space around each pad along x, distance between pads along x is equal to 2*xmargin.
/// - ymargin is the space around each pad along y, distance between pads along y is equal to 2*ymargin.With this PR, the old documentation is correct as |






This Pull request:
Implements feature proposed here: #20165 (comment)
Changes:
nxornyis negative, the pads is divided according toabs(nx)orabs(ny), but the outer margins is set to 0. The inner margins are equal toxmarginandymargin, respectively. Demo of the new feature in the bottom row of the image:Created with macro:
Checklist:
Also related to #20138