Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions doc/rst/source/explain_-B.rst_
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,10 @@ direction of increasing coordinates (i.e., to make the y-axis positive down).
[**a**\|\ **f**\|\ **g**]\ [*stride*][*phase*][*unit*].

The choice of **a**\|\ **f**\|\ **g** sets the axis item of interest, which are detailed in the Table
:ref:`interval types <tbl-inttype>`. Optionally, append *phase* to shift the annotations by that amount (positive or
negative with the sign being required). Optionally, append *unit* to specify the units of *stride*, where *unit* is one
:ref:`interval types <tbl-inttype>`. Optionally, append *phase* to shift that item by that amount (positive or
negative with the sign being required); the shift only affects the item it is appended to, so
**-Ba5f1g1+0.5** offsets the grid lines only while **-Ba5+0.5f1+0.5g1+0.5** offsets annotations, ticks and grid
lines alike. Optionally, append *unit* to specify the units of *stride*, where *unit* is one
of the 18 supported :ref:`unit codes <tbl-units>`. For custom annotations and intervals, *intervals* can be given as
**c**\ *intfile*, where *intfile* contains any number of records with *coord* *type* [*label*]. See the section
:ref:`Custom axes <custom_axes>` for more details.
Expand Down
4 changes: 2 additions & 2 deletions src/gmt_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -4275,7 +4275,6 @@ GMT_LOCAL int gmtinit_set_titem (struct GMT_CTRL *GMT, struct GMT_PLOT_AXIS *A,
break;
}

if (phase != 0.0) A->phase = phase; /* phase must apply to entire axis */
if (I->active) {
GMT_Report (GMT->parent, GMT_MSG_INFORMATION, "Axis sub-item %c set more than once (typo?)\n", flag);
return (GMT_NOERROR);
Expand All @@ -4293,6 +4292,7 @@ GMT_LOCAL int gmtinit_set_titem (struct GMT_CTRL *GMT, struct GMT_PLOT_AXIS *A,
I->type = flag;
I->unit = unit;
I->interval = val;
I->phase = phase; /* Phase shift only applies to this axis item [0] */
I->flavor = 0;
I->active = true;
if (!custom && in[0] && val == 0.0) I->active = false;
Expand Down Expand Up @@ -7752,7 +7752,7 @@ void gmtlib_explain_options (struct GMT_CTRL *GMT, char *options) {
"more substrings of the form [a|f|g][<stride>[+-<phase>]], where the (optional) a "
"indicates annotation and major tick interval, f minor tick interval, and g grid interval. "
"Here, <stride> is the spacing between ticks or annotations, the (optional, and with required sign)"
"<phase> specifies phase-shifted annotations/ticks by that amount, and the (optional) "
"<phase> shifts that item (only) by that amount, and the (optional) "
"<unit> specifies the <stride> unit [Default is the unit implied in -R]. There can be "
"no spaces between the substrings; just append items to make one very long string. "
"For custom annotations or intervals, let <intervals> be c<intfile>; see documentation for details. "
Expand Down
2 changes: 1 addition & 1 deletion src/gmt_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ EXTERN_MSC unsigned int gmtlib_unit_lookup (struct GMT_CTRL *GMT, int c, unsigne
EXTERN_MSC void gmtlib_get_annot_label (struct GMT_CTRL *GMT, double val, char *label, bool do_minutes, bool do_seconds, bool do_hemi, unsigned int lonlat, bool worldmap);
EXTERN_MSC unsigned int gmtlib_coordinate_array (struct GMT_CTRL *GMT, double min, double max, struct GMT_PLOT_AXIS_ITEM *T, double **array, char ***labels);
EXTERN_MSC unsigned int gmtlib_linear_array (struct GMT_CTRL *GMT, double min, double max, double delta, double phase, double **array);
EXTERN_MSC unsigned int gmtlib_pow_array (struct GMT_CTRL *GMT, double min, double max, double delta, unsigned int x_or_y_or_z, double **array);
EXTERN_MSC unsigned int gmtlib_pow_array (struct GMT_CTRL *GMT, double min, double max, double delta, double phase, unsigned int x_or_y_or_z, double **array);
EXTERN_MSC int gmtlib_prepare_label (struct GMT_CTRL *GMT, double angle, unsigned int side, double x, double y, unsigned int type, double *line_angle, double *text_angle, unsigned int *justify);
EXTERN_MSC unsigned int gmtlib_time_array (struct GMT_CTRL *GMT, double min, double max, struct GMT_PLOT_AXIS_ITEM *T, double **array);
EXTERN_MSC void gmtlib_get_lon_minmax (struct GMT_CTRL *GMT, double *lon, uint64_t n, double *min, double *max);
Expand Down
94 changes: 48 additions & 46 deletions src/gmt_plot.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/gmt_project.h
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ enum GMT_enum_tick {GMT_ANNOT_UPPER = 0, /* Tick annotations closest to the axis

struct GMT_PLOT_AXIS_ITEM { /* Information for one type of tick/annotation */
double interval; /* Distance between ticks in user units */
double phase; /* Phase offset for this item's stride: (knot-phase)%interval = 0 */
unsigned int parent; /* Id of axis this item belongs to (0,1,2) */
bool active; /* true if we want to use this item */
bool generated; /* true if this is an auto-generated interval */
Expand All @@ -505,7 +506,6 @@ struct GMT_PLOT_AXIS { /* Information for one time axis */
bool use_angle[2]; /* True if we got +a<angle>|n|p for this axis, for [GMT_PRIMARY] and [GMT_SECONDARY] annotations */
bool skip[2]; /* Determines if we skip annotations at the lower or upper bounds of an axis [false/false] */
struct GMT_PLOT_AXIS_ITEM item[8]; /* see above defines for which is which */
double phase; /* Phase offset for strides: (knot-phase)%interval = 0 */
double angle[2]; /* Annotations angle set by user, for [GMT_PRIMARY] and [GMT_SECONDARY] annotations (issue #7036) */
char label[GMT_LEN256]; /* Label of the axis */
char secondary_label[GMT_LEN256]; /* Optionally use this label when axis is right or top */
Expand Down
2 changes: 1 addition & 1 deletion src/gmt_prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ EXTERN_MSC double gmt_inch_to_degree_scale (struct GMT_CTRL *GMT, double lon0, d
EXTERN_MSC bool gmt_text_is_latex (struct GMT_CTRL *GMT, const char *string);
EXTERN_MSC void gmt_map_text (struct GMT_CTRL *GMT, double x, double y, struct GMT_FONT *font, char *label, double angle, int just, unsigned int form);
EXTERN_MSC void gmt_map_title (struct GMT_CTRL *GMT, double x, double y);
EXTERN_MSC void gmt_linearx_grid (struct GMT_CTRL *GMT, struct PSL_CTRL *P, double w, double e, double s, double n, double dval);
EXTERN_MSC void gmt_linearx_grid (struct GMT_CTRL *GMT, struct PSL_CTRL *P, double w, double e, double s, double n, double dval, double phase);
EXTERN_MSC int gmt_ps_append (struct GMT_CTRL *GMT, char *source, unsigned int mode, FILE *dest);
EXTERN_MSC char *gmt_export2proj4 (struct GMT_CTRL *GMT);
EXTERN_MSC char *gmt_importproj4 (struct GMT_CTRL *GMT, char *szProj4, int *scale_pos, char *epsg2proj);
Expand Down
8 changes: 4 additions & 4 deletions src/gmt_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -15729,9 +15729,9 @@ unsigned int gmtlib_log2_array (struct GMT_CTRL *GMT, double min, double max, do
}

/*! . */
unsigned int gmtlib_pow_array(struct GMT_CTRL *GMT, double min, double max, double delta, unsigned int x_or_y_or_z, double **array) {
unsigned int gmtlib_pow_array(struct GMT_CTRL *GMT, double min, double max, double delta, double phase, unsigned int x_or_y_or_z, double **array) {
int i, n = 0;
double *val = NULL, v0, v1, phase = GMT->current.map.frame.axis[x_or_y_or_z].phase;
double *val = NULL, v0, v1;

if (delta <= 0.0) return (0);

Expand Down Expand Up @@ -15917,13 +15917,13 @@ unsigned int gmtlib_coordinate_array(struct GMT_CTRL *GMT, double min, double ma

switch (GMT->current.proj.xyz_projection[T->parent]) {
case GMT_LINEAR:
n = gmtlib_linear_array (GMT, min, max, gmtlib_get_map_interval (GMT, GMT_LINEAR, T), GMT->current.map.frame.axis[T->parent].phase, array);
n = gmtlib_linear_array (GMT, min, max, gmtlib_get_map_interval (GMT, GMT_LINEAR, T), T->phase, array);
break;
case GMT_LOG10:
n = gmtlib_log_array (GMT, min, max, gmtlib_get_map_interval (GMT, GMT_LOG10, T), array);
break;
case GMT_POW:
n = gmtlib_pow_array (GMT, min, max, gmtlib_get_map_interval (GMT, GMT_POW, T), T->parent, array);
n = gmtlib_pow_array (GMT, min, max, gmtlib_get_map_interval (GMT, GMT_POW, T), T->phase, T->parent, array);
break;
case GMT_TIME:
n = gmtlib_time_array (GMT, min, max, T, array);
Expand Down
4 changes: 2 additions & 2 deletions src/psscale.c
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,7 @@ GMT_LOCAL void psscale_draw_colorbar (struct GMT_CTRL *GMT, struct PSSCALE_CTRL
if (A->type == GMT_TIME)
gmt_plot_timex_grid(GMT, PSL, P->data[0].z_low, P->data[P->n_colors-1].z_high, 0.0, width, GMT_GRID_UPPER);
else
gmt_linearx_grid(GMT, PSL, P->data[0].z_low, P->data[P->n_colors-1].z_high, 0.0, width, dx);
gmt_linearx_grid(GMT, PSL, P->data[0].z_low, P->data[P->n_colors-1].z_high, 0.0, width, dx, A->item[GMT_GRID_UPPER].phase);
}
}
else if (!GMT->current.map.frame.no_frame) { /* When no -B we annotate every CPT bound which may be non-equidistant, hence this code (i.e., we cannot fake a call to -B) */
Expand Down Expand Up @@ -1812,7 +1812,7 @@ GMT_LOCAL void psscale_draw_colorbar (struct GMT_CTRL *GMT, struct PSSCALE_CTRL
if (A->type == GMT_TIME)
gmt_plot_timex_grid (GMT, PSL, P->data[0].z_low, P->data[P->n_colors-1].z_high, 0.0, width, GMT_GRID_UPPER);
else
gmt_linearx_grid (GMT, PSL, P->data[0].z_low, P->data[P->n_colors-1].z_high, 0.0, width, dx);
gmt_linearx_grid (GMT, PSL, P->data[0].z_low, P->data[P->n_colors-1].z_high, 0.0, width, dx, A->item[GMT_GRID_UPPER].phase);
}
PSL_setorigin (PSL, 0.0, 0.0, -90.0, PSL_FWD); /* Rotate back so we can plot y-axis */
/* Copy x-axis annotation and scale info to y-axis. We don't need to undo this since gmt_end_module will restore it for us */
Expand Down
38 changes: 38 additions & 0 deletions test/psbasemap/axis_phase.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
#
# Test that a phase shift appended to a -B interval only shifts the item it belongs to.
# See https://github.com/GenericMappingTools/gmt/issues/8993
#
# No baseline PostScript is needed: we compare the plot records from a single -B call
# with those from the two-call sequence that has always placed the items correctly.

# Keep the moveto/lineto records and the annotation strings of the plot itself. The
# two-call reference draws the frame twice, hence the sort -u.
extract () {
sed -n '/BeginObject/,/EndObject/p' "$1" | grep -E '^(N )?-?[0-9]+ -?[0-9]+ (M|D)|^\(.*\) (mr|bc) Z' | sort -u
}

# 1. Phase on the grid interval only: annotations and ticks must stay put
gmt psbasemap -R0/10/0/10 -JX5c -Ba5f1g1+0.5 -P > one.ps
gmt psbasemap -R0/10/0/10 -JX5c -Ba5f1 -P -K > two.ps
gmt psbasemap -R -J -Bg1+0.5 -O >> two.ps
extract one.ps > one.txt
extract two.ps > two.txt
diff one.txt two.txt > fail

# 2. Repeating the phase on every item still shifts everything alike
gmt psbasemap -R0/10/0/10 -JX5c -Ba5+0.5f1+0.5g1+0.5 -P > all.ps
gmt psbasemap -R0/10/0/10 -JX5c -Ba5+0.5f1+0.5 -P -K > allref.ps
gmt psbasemap -R -J -Bg1+0.5 -O >> allref.ps
extract all.ps > all.txt
extract allref.ps > allref.txt
diff all.txt allref.txt >> fail

# 3. The annotations of case 1 are the unshifted 0, 5 and 10
cat << EOF > annot_answer.txt
0
5
10
EOF
grep -E '^\(.*\) bc Z' one.ps | tr -d '()' | awk '{print $1}' | sort -n -u > annot.txt
diff annot.txt annot_answer.txt >> fail
4 changes: 2 additions & 2 deletions test/pscoast/pscoast_180.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

ps=pscoast_180.ps

gmt pscoast -R-10/180/20/50 -JM6i -Bxa20g20 -Bya20g20+10 -Dc -G221/204/170 -A0/0/1 -P -Xc -K > $ps
gmt pscoast -R0/180/20/50 -JM6i -Bxa20g20 -Bya20g20+10 -Dc -G221/204/170 -A0/0/1 -O -Y2.5i >> $ps
gmt pscoast -R-10/180/20/50 -JM6i -Bxa20g20 -Bya20+10g20+10 -Dc -G221/204/170 -A0/0/1 -P -Xc -K > $ps
gmt pscoast -R0/180/20/50 -JM6i -Bxa20g20 -Bya20+10g20+10 -Dc -G221/204/170 -A0/0/1 -O -Y2.5i >> $ps
2 changes: 1 addition & 1 deletion test/psxy/units.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Test that symbol units is picked up from datafile, symbol option, and GMT default, in that order
ps=units.ps
# No unit in data, PROJ_LENGTH_UNIT decides the size
echo "-2 2 1" | gmt psxy -JX6i -R-3/3/-3/3 -Ba1g1+0.5 -BWeSn -P -Sc -Ggray --PROJ_LENGTH_UNIT=inch -Xc -K > $ps
echo "-2 2 1" | gmt psxy -JX6i -R-3/3/-3/3 -Ba1+0.5g1+0.5 -BWeSn -P -Sc -Ggray --PROJ_LENGTH_UNIT=inch -Xc -K > $ps
# Unit in data, whatever PROJ_LENGTH_UNIT says should be ignored
echo "2 2 1i" | gmt psxy -J -R -O -K -Sc -Ggray --PROJ_LENGTH_UNIT=point >> $ps
# No unit in data, PROJ_LENGTH_UNIT decides the size
Expand Down
Loading