Fit 3-D subplot panels, and their heading, inside the figure (#4450) - #9152
Open
joa-quim wants to merge 1 commit into
Open
Fit 3-D subplot panels, and their heading, inside the figure (#4450)#9152joa-quim wants to merge 1 commit into
joa-quim wants to merge 1 commit into
Conversation
A perspective panel is drawn as a projected box that is larger than the flat map rectangle subplot lays its panels out from, and nothing ever fitted that box to the panel. In the reported example both cubes burst out of the -Ff20c/10c figure area and the heading was laid out against the flat rectangle, so it ended up among them. gmt_map_setup could not have fitted the box earlier: it is only known once gmtmap_init_three_D has run, at the very end of the setup. So the fit now happens there, for a panel in 3-D: the footprint is measured from the eight corners of the x/y/z region, padded for the ticks and annotations that the frame draws outside it (a quarter of that above the box, where nothing is annotated), and if it does not fit the panel the projection is scaled down and the box centered in the panel via z_project.x_off/y_off. The scaling includes proj.zmax/zmin, the z-axis length in plot units that the PostScript perspective matrix works from; without those the numbers changed but the picture did not. The heading is now placed at subplot end rather than at subplot begin, since only then is it known how far a 3-D panel reaches: begin records the position it would have used in gmt.subplotheading.<fig> together with the canvas corner (as PSL_SUBPLOT_ox/oy in the PostScript, so no assumption about -X -Y is needed), gmt_plotinit records the highest projected y of any 3-D panel in gmt.subplottop.<fig>, and end returns to that corner, raises the heading by any excess and puts the origin back for whatever follows. The panel settings are cleared around that call, or the heading is scaled into the last panel, and restored afterwards since the -R history is built from them. 2-D figures write no gmt.subplottop file and are unaffected; test/subplot is unchanged apart from the new test. test/subplot/subplot_3d_fit.sh plots the example from the issue and requires the drawn height to stay near the 10 cm of the figure; the unfitted cubes reach some 19 cm. It measures the plot instead of comparing it, so it needs no baseline PostScript. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A perspective panel is drawn as a projected box that is larger than the flat map rectangle subplot lays its panels out from, and nothing ever fitted that box to the panel. In the reported example both cubes burst out of the -Ff20c/10c figure area and the heading was laid out against the flat rectangle, so it ended up among them.
gmt_map_setup could not have fitted the box earlier: it is only known once gmtmap_init_three_D has run, at the very end of the setup. So the fit now happens there, for a panel in 3-D: the footprint is measured from the eight corners of the x/y/z region, padded for the ticks and annotations that the frame draws outside it (a quarter of that above the box, where nothing is annotated), and if it does not fit the panel the projection is scaled down and the box centered in the panel via z_project.x_off/y_off. The scaling includes proj.zmax/zmin, the z-axis length in plot units that the PostScript perspective matrix works from; without those the numbers changed but the picture did not.
The heading is now placed at subplot end rather than at subplot begin, since only then is it known how far a 3-D panel reaches: begin records the position it would have used in gmt.subplotheading. together with the canvas corner (as PSL_SUBPLOT_ox/oy in the PostScript, so no assumption about -X -Y is needed), gmt_plotinit records the highest projected y of any 3-D panel in gmt.subplottop., and end returns to that corner, raises the heading by any excess and puts the origin back for whatever follows. The panel settings are cleared around that call, or the heading is scaled into the last panel, and restored afterwards since the -R history is built from them.
test/subplot/subplot_3d_fit.sh plots the example from the issue and requires the drawn height to stay near the 10 cm of the figure; the unfitted cubes reach some 19 cm. It measures the plot instead of comparing it, so it needs no baseline PostScript.
Fix #4450
Assisted-by: Claude Opus 5.0 But it resisted like hell to fix this.
The issue's example now produces.
