MCPcopy Create free account
hub / github.com/GenericMappingTools/gmt / gmtplot_prog_indicator_F

Function gmtplot_prog_indicator_F

src/gmt_plot.c:8889–8946  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8887}
8888
8889GMT_LOCAL void gmtplot_prog_indicator_F (struct GMT_CTRL *GMT, double x, double y, double t, double w, int justify, char *P1, char *F1, char *label, char kind, double width, double fsize, struct GMT_FONT *F) {
8890 /* Place time axis indicator via call to basemap plus adding triangle here */
8891 int symbol = PSL_INVTRIANGLE; /* Time marker when labels are below the line */
8892 char cmd[GMT_LEN512] = {""}, region[GMT_LEN256] = {""}, unit[4] = {""}, axis = 0;
8893 bool was = GMT->current.map.frame.init;
8894 double fx, fy, dy, dy2, xt, s = 1.0, angle = 0.0, h;
8895 struct GMT_PEN pen;
8896 struct GMT_FILL fill;
8897
8898 gmtplot_just_f_xy (justify, &fx, &fy);
8899 gmt_M_memset (&pen, 1, struct GMT_PEN);
8900 gmt_getpen (GMT, P1, &pen); /* Pen for the time axis */
8901 dy = pen.width / PSL_POINTS_PER_INCH; /* Need to get pen width to determine triangle size */
8902 dy2 = dy / 2.0; /* Half pen width */
8903 x += fx * w; y += fy * dy; /* Adjust the (x,y) to be mid-point of axis */
8904 xt = w * t; /* Relative fraction of w along the axis from left point */
8905 /* Must allow for the space needed for tick-mark, annot-offset, and possibly annotations */
8906 h = GMT->current.setting.map_tick_length[GMT_PRIMARY] + MAX (0.0, GMT->current.setting.map_annot_offset[GMT_PRIMARY]);
8907 if (kind == 'F') h += GMT_LET_HEIGHT * GMT->current.setting.font_annot[GMT_PRIMARY].size / PSL_POINTS_PER_INCH;
8908 x -= 0.5 * w; /* Let x be start position of axis rather than middle */
8909 switch (justify) { /* Deal with justification and adjust x,y for starting point of axis */
8910 case PSL_BL: case PSL_BC: case PSL_BR: /* At bottom we need to move up to give space for annotations below axis */
8911 axis = 'S'; y += h; break;
8912 case PSL_TL: case PSL_TC: case PSL_TR: case PSL_MC: /* At top (and middle) we likewise need space above, plus switch to TRIANGLE */
8913 axis = 'N'; y-= h; s = -1; symbol = PSL_TRIANGLE; break;
8914 case PSL_ML: angle = 90.0; y -= 0.5*w; axis = 'N'; x += h; s = -1; symbol = PSL_TRIANGLE; break; /* Left is like TC but rotated 90 */
8915 case PSL_MR: angle = 90.0; y -= 0.5*w; axis = 'S'; x += w - h; break; /* Right is like BC but rotated 90 */
8916 }
8917 if (strchr (label, '%')) { /* Cannot have percentages in the -R string */
8918 sprintf (region, "-R0/100/0/1"); /* Always 0-100 % */
8919 strcpy (unit, "+u%");
8920 }
8921 else if (label[2] == ' ') { /* Eliminate leading spaces... */
8922 int k = 2; while (label[k] && label[k] == ' ') k++; /* Find first non-space character */
8923 sprintf (region, "-R%s", &label[k]);
8924 }
8925 else /* Use as is */
8926 strncpy (region, label, GMT_LEN256-1);
8927 PSL_setorigin (GMT->PSL, x, y, angle, PSL_FWD); /* Origin (0,0) is now at left end-point of time axis */
8928 GMT->common.R.active[RSET] = GMT->common.J.active = false;
8929 if (fsize == 0.0)
8930 F->size = 3.0 * dy * PSL_POINTS_PER_INCH; /* Set a scaled font size */
8931 if (kind == 'F') /* Want annotations so add -Baf and set annotation font */
8932 sprintf (cmd, "%s -JX%gi/0.0001i -Baf%s -B%c -X0 -Y0 --MAP_FRAME_PEN=%s --FONT_ANNOT_PRIMARY=+%s --GMT_HISTORY=false", region, width, unit, axis, P1, gmt_putfont (GMT, F));
8933 else /* Only axis with ticks so only -Bf is used */
8934 sprintf (cmd, "%s -JX%gi/0.0001i -Bf%s -B%c -X0 -Y0 --MAP_FRAME_PEN=%s --GMT_HISTORY=false", region, width, unit, axis, P1);
8935 GMT->current.map.frame.init = false; /* To enable more -B parsing */
8936 GMT_Report (GMT->parent, GMT_MSG_DEBUG, "Call basemap from gmtplot_prog_indicator_F with args %s\n", cmd);
8937 if (GMT_Call_Module (GMT->parent, "basemap", GMT_MODULE_CMD, cmd) != GMT_NOERROR) {
8938 GMT_Report (GMT->parent, GMT_MSG_ERROR, "Failed to call basemap with args %s ???\n", cmd);
8939 }
8940 GMT->current.map.frame.init = was; /* Reset how we found it */
8941 if (gmt_getfill (GMT, F1, &fill)) /* Get and set color for the triangle; no outline */
8942 GMT_Report (GMT->parent, GMT_MSG_ERROR, "Bad fill argument %s\n", F1);
8943 PSL_setfill (GMT->PSL, fill.rgb, 0);
8944 w = dy * 2; /* Set triangle size to 2 times the axis width */
8945 PSL_plotsymbol (GMT->PSL, xt, 1.2*s*dy2, &w, symbol);
8946}

Callers 1

gmt_plotinitFunction · 0.85

Calls 9

gmtplot_just_f_xyFunction · 0.85
gmt_getpenFunction · 0.85
PSL_setoriginFunction · 0.85
gmt_putfontFunction · 0.85
GMT_ReportFunction · 0.85
GMT_Call_ModuleFunction · 0.85
gmt_getfillFunction · 0.85
PSL_setfillFunction · 0.85
PSL_plotsymbolFunction · 0.85

Tested by

no test coverage detected