Repository navigation
Let modules called by modules in inset know of shrinking - #6751
Conversation
See this post for background. The problem was that the coast command called another module (plot) while inside the inset section but the called module was unaware that because of the -R -J and inset size setting there was a scaling of 0.73 applied. That meant plot was off by that factor. THe same would happen with any other module called inside the inset section that might call another module. The solution is to remember the computed inset scale in the API so that when the secondary module is initialized it can apply the same scaling as the mother module.
| gmt_reload_history (API->GMT); | ||
| gmt_reload_settings (API->GMT); | ||
| /* Undo any shrink scaling memory */ | ||
| API->inset_shrink_scale = 1.0; |
There was a problem hiding this comment.
I'm afraid this precaution might not be enough as it only happens inside inset.c
Because whatever is set in API carries to other modules calls in Julia/MEX this undoing should be done in end_session as well, I think.
There was a problem hiding this comment.
Hm, it is only set when gmt inset is called and shrinking is required, and it is guaranteed there will be a gmt inset end call to follow. So it only lives as long as we are in an inset. It wont hurt to add it to gmt end but not sure if it would make a difference. Can you demonstrate the need?
There was a problem hiding this comment.
Imagine there is an error before the gmt inset end call?
What I know is that there are still some of these shits that manage to survive and there are cases where I'm forced to call a gmt("destroy") to workaround the unknown trouble.
There was a problem hiding this comment.
OK, I dont mind. So you think gmt_end (which is called by GMT_Destroy_Session) is the place then?
There was a problem hiding this comment.
Yes, probably gmt_end. It's the place where all this kind of stuff is undone.
|
As I look at this a bit more, note that this is also a better way to determine the inset: Let gmt inset decide from the -R -J: Here, -D does not specify the size but we give the desired -R -J and now the inset is computed correctly with a tight fit. If you dont want a width of 3c but a height of 3c then you append +dh to -J, for instance. In the original user's case, this is the preferred way of doing things. But, this PR is still useful since it fixes a bug. |
|
We have one failure (insetlegend.sh) so I will check that one before this can be merged or revised. |
|
I will let @seisman give this branch a test tonight/tomorrow before merging. |
Great! It's definitely a better solution! Just want to let you know that inset may not works well in subplot, as shown by the script below. But I think it can be addressed in a separate PR instead. |
|
Just realized that the inset in subplot issue was already reported in #6415. I'll repost the example there. |
|
Thanks @seisman - we will look at the old sublot + inset issues separately. OK to merge this PR though? |

See this post for background. The problem was that the coast module called another module (plot) while inside the inset section but the called module was unaware that because of the -R -J and inset size setting there was a scaling of 0.73 applied. That meant plot was off by that factor (unless we countered that by appending +du to -J, which the user would not know was needed). The same would happen with any other module called inside the inset section that might call another module (e.g., plot calls plot when dealing with decorated lines, for instance).
The solution is to remember the computed inset scale in the API so that when the secondary module is initialized it can apply the same scaling as the mother module; this scaling happens in the belly of gmt_proj_setup.
With those changes, this works correctly: