Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 255
Enhance text with extra functionality and aliases#481
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
4c52613
Allow passing str type into angle argument of text
weiji14 138617f
Alias pen(W) for text
weiji14 45a9858
Alias clearance(C) for text
weiji14 9b8e837
Alias fill(G) for text
weiji14 46e98d7
Remove documentation on clip for fill in text
weiji14 9e7a353
Allow text placement using position argument instead of x/y pairs
weiji14 187a733
Alias offset(D) for text
weiji14 9f42ce1
Remove some lines in docstring
weiji14 ada1f6d
Reorder as angle, font, justify instead of font, angle, justify
weiji14 0b80786
Add centre-middle text to set up map frame first
weiji14 1f1d323
Remove check for missing file in textfiles
weiji14 8b8a1ba
Fix some pylint errors about unused arguments
weiji14 d48bfb5
Refactor text to use -F+t argument when position is set
weiji14 3d942d1
Have test_text_position plot at all 9 possible positions
weiji14 0682c28
Check that plotting text from an external file (@Table_5_11.txt) works
weiji14 f92beb2
Change test name from external to remote
weiji14 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -7,7 +7,8 @@ | ||
| import pytest | ||
| from .. import Figure | ||
| from ..exceptions import GMTInvalidInput | ||
| from ..exceptions import GMTCLibError, GMTInvalidInput | ||
| from ..helpers import GMTTempFile | ||
| TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "data") | ||
| POINTS_DATA = os.path.join(TEST_DATA_DIR, "points.txt") | ||
| @@ -77,6 +78,16 @@ def test_text_input_single_filename(): | ||
| return fig | ||
| @pytest.mark.mpl_image_compare | ||
| def test_text_input_remote_filename(): | ||
| """ | ||
| Run text by passing in a remote filename to textfiles | ||
| """ | ||
| fig = Figure() | ||
| fig.text(region=[0, 6.5, 0, 6.5], textfiles="@Table_5_11.txt") | ||
| return fig | ||
| @pytest.mark.mpl_image_compare | ||
| def test_text_input_multiple_filenames(): | ||
| """ | ||
| @@ -92,10 +103,48 @@ def test_text_nonexistent_filename(): | ||
| Run text by passing in a list of filenames with one that does not exist | ||
| """ | ||
| fig = Figure() | ||
| with pytest.raises(GMTInvalidInput): | ||
| with pytest.raises(GMTCLibError): | ||
| fig.text(region=[10, 70, -5, 10], textfiles=[POINTS_DATA, "notexist.txt"]) | ||
| @pytest.mark.mpl_image_compare | ||
| def test_text_position(region): | ||
| """ | ||
| Print text at center middle (CM) and eight other positions | ||
| (Top/Middle/Bottom x Left/Centre/Right). | ||
| """ | ||
| fig = Figure() | ||
| fig.text(region=region, projection="x1c", frame="a", position="CM", text="C M") | ||
seisman marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| for position in ("TL", "TC", "TR", "ML", "MR", "BL", "BC", "BR"): | ||
| fig.text(position=position, text=position) | ||
| return fig | ||
| def test_text_xy_with_position_fails(region): | ||
| """ | ||
| Run text by providing both x/y pairs and position arguments. | ||
| """ | ||
| fig = Figure() | ||
| with pytest.raises(GMTInvalidInput): | ||
| fig.text( | ||
| region=region, projection="x1c", x=1.2, y=2.4, position="MC", text="text" | ||
| ) | ||
| @pytest.mark.mpl_image_compare | ||
| def test_text_position_offset_with_line(region): | ||
weiji14 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| """ | ||
| Print text at centre middle (CM) and eight other positions | ||
| (Top/Middle/Bottom x Left/Centre/Right), offset by 0.5 cm, with a line | ||
| drawn from the original to the shifted point. | ||
| """ | ||
| fig = Figure() | ||
| fig.text(region=region, projection="x1c", frame="a", position="CM", text="C M") | ||
| for position in ("TL", "TC", "TR", "ML", "MR", "BL", "BC", "BR"): | ||
| fig.text(position=position, text=position, offset="j0.5c+v") | ||
| return fig | ||
| @pytest.mark.mpl_image_compare | ||
| def test_text_angle_30(region, projection): | ||
| """ | ||
| @@ -130,6 +179,58 @@ def test_text_font_bold(region, projection): | ||
| return fig | ||
| @pytest.mark.mpl_image_compare | ||
| def test_text_fill(region, projection): | ||
| """ | ||
| Print text with blue color fill | ||
| """ | ||
| fig = Figure() | ||
| fig.text( | ||
| region=region, | ||
| projection=projection, | ||
| x=1.2, | ||
| y=1.2, | ||
| text="blue fill around text", | ||
| fill="blue", | ||
| ) | ||
| return fig | ||
| @pytest.mark.mpl_image_compare | ||
| def test_text_pen(region, projection): | ||
| """ | ||
| Print text with thick green dashed pen | ||
| """ | ||
| fig = Figure() | ||
| fig.text( | ||
| region=region, | ||
| projection=projection, | ||
| x=1.2, | ||
| y=1.2, | ||
| text="green pen around text", | ||
| pen="thick,green,dashed", | ||
| ) | ||
| return fig | ||
| @pytest.mark.mpl_image_compare | ||
| def test_text_round_clearance(region, projection): | ||
| """ | ||
| Print text with round rectangle box clearance | ||
| """ | ||
| fig = Figure() | ||
| fig.text( | ||
| region=region, | ||
| projection=projection, | ||
| x=1.2, | ||
| y=1.2, | ||
| text="clearance around text", | ||
| clearance="90%+tO", | ||
| pen="default,black,dashed", | ||
| ) | ||
| return fig | ||
| @pytest.mark.mpl_image_compare | ||
| def test_text_justify_bottom_right_and_top_left(region, projection): | ||
| """ | ||
| @@ -172,3 +273,25 @@ def test_text_justify_parsed_from_textfile(): | ||
| D="j0.45/0+vred", # draw red-line from xy point to text label (city name) | ||
| ) | ||
| return fig | ||
| @pytest.mark.mpl_image_compare | ||
| def test_text_angle_font_justify_from_textfile(): | ||
| """ | ||
| Print text with x, y, angle, font, justify, and text arguments parsed from | ||
| the textfile. | ||
| """ | ||
| fig = Figure() | ||
| with GMTTempFile(suffix=".txt") as tempfile: | ||
| with open(tempfile.name, "w") as tmpfile: | ||
| tmpfile.write("114 0.5 30 22p,Helvetica-Bold,black LM BORNEO") | ||
| fig.text( | ||
| region=[113, 117.5, -0.5, 3], | ||
| projection="M5c", | ||
| frame="a", | ||
| textfiles=tempfile.name, | ||
| angle=True, | ||
| font=True, | ||
| justify=True, | ||
| ) | ||
| return fig | ||
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.
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.
@leouieda mentioned before at #321 (comment) to use virtualfiles, and I finally figured out what he meant. Unfortunately,
virtualfile_from_vectorsdoesn't yet supportstrtypes. This is the error on_check_dtype_and_dim:From what I can tell, we'll need to use
GMT_Put_Stringsis that right? We should do this refactor in a separate PR, this one is already getting a bit too long.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, as I understand it, we need to use
GMT_Put_Stringsto pass trailing strings to GMT.