1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776 |
- #include "sys-defines.h"
- #include "libcommon.h"
- #include "plot.h"
- #include "extern.h"
- #define PLOT_SIZE 4096.0
- #define FUZZ 0.000001
- #define NEAR_EQUALITY(a, b, scale) (fabs((a) - (b)) < (FUZZ * fabs(scale)))
- typedef unsigned int outcode; /* for Cohen-Sutherland clipper */
- enum { TOP = 0x1, BOTTOM = 0x2, RIGHT = 0x4, LEFT = 0x8 };
- enum { ACCEPTED = 0x1, CLIPPED_FIRST = 0x2, CLIPPED_SECOND = 0x4 };
- #define TRIAL_NUMBER_OF_TICK_INTERVALS 5
- #define MAX_NUM_SUBTICKS 29 /* max num. of linearly spaced subticks */
- #define RELATIVE_SUBTICK_SIZE 0.4 /* subtick_size / tick_size */
- /* if a log axis spans >5.0 orders of magnitude, don't plot log subsubticks */
- #define MAX_DECADES_WITH_LOG_SUBSUBTICKS 5.0
- /* inter-tick spacing types, returned by scale1() and spacing_type() */
- #define S_ONE 0
- #define S_TWO 1
- #define S_FIVE 2
- #define S_TWO_FIVE 3 /* we don't use this one, but user may request it */
- #define S_UNKNOWN -2
- #define A_LINEAR 0
- #define A_LOG10 1
- typedef struct
- {
-
- double input_min, input_max;
- double input_range;
-
- bool reverse;
-
- double squeezed_min, squeezed_max;
- double squeezed_range;
-
- double output_min, output_max;
- double output_range;
- } Transform;
- #define XS(x) (((x) - multigrapher->x_trans.input_min)/multigrapher->x_trans.input_range)
- #define XSI(x) (((x)*multigrapher->x_trans.input_range) + multigrapher->x_trans.input_min)
- #define XR(x) (multigrapher->x_trans.reverse ? 1.0 - (x) : (x))
- #define XSQ(x) (multigrapher->x_trans.squeezed_min + (x) * multigrapher->x_trans.squeezed_range)
- #define XSQI(x) (((x) - multigrapher->x_trans.squeezed_min)/multigrapher->x_trans.squeezed_range)
- #define XP(x) (multigrapher->x_trans.output_min + (x) * multigrapher->x_trans.output_range)
- #define XPI(x) (((x) - multigrapher->x_trans.output_min)/multigrapher->x_trans.output_range)
- #define XV(x) XP(XSQ(XR(XS(x))))
- #define XVI(x) XSI(XR(XSQI(XPI(x))))
- #define XN(y) XP(XSQ(XS(y)))
- #define YS(y) (((y) - multigrapher->y_trans.input_min)/multigrapher->y_trans.input_range)
- #define YSI(y) (((y)*multigrapher->y_trans.input_range) + multigrapher->y_trans.input_min)
- #define YR(y) (multigrapher->y_trans.reverse ? 1.0 - (y) : (y))
- #define YSQ(y) (multigrapher->y_trans.squeezed_min + (y) * multigrapher->y_trans.squeezed_range)
- #define YSQI(y) (((y) - multigrapher->y_trans.squeezed_min)/multigrapher->y_trans.squeezed_range)
- #define YP(y) (multigrapher->y_trans.output_min + (y) * multigrapher->y_trans.output_range)
- #define YPI(y) (((y) - multigrapher->y_trans.output_min)/multigrapher->y_trans.output_range)
- #define YV(y) YP(YSQ(YR(YS(y))))
- #define YVI(x) YSI(YR(YSQI(YPI(x))))
- #define YN(y) YP(YSQ(YS(y)))
- #define SS(x) \
- (DMIN(multigrapher->x_trans.output_range * multigrapher->x_trans.squeezed_range, \
- multigrapher->y_trans.output_range * multigrapher->y_trans.squeezed_range) * (x))
- typedef struct
- {
- const char *font_name;
- double font_size;
- const char *label;
- int type;
- double tick_spacing;
- int min_tick_count, max_tick_count;
- bool have_lin_subticks;
- double lin_subtick_spacing;
- int min_lin_subtick_count, max_lin_subtick_count;
- bool have_normal_subsubticks;
- bool user_specified_subsubticks;
- double subsubtick_spacing;
- double other_axis_loc;
- double alt_other_axis_loc;
- bool switch_axis_end;
- bool omit_ticks;
- double max_label_width;
- int labelled_ticks;
- } Axis;
- struct MultigrapherStruct
- {
-
- plPlotter *plotter;
- const char *output_format;
- const char *bg_color;
- bool save_screen;
-
- Transform x_trans, y_trans;
- Axis x_axis, y_axis;
- grid_type grid_spec;
- double blankout_fraction;
- bool no_rotate_y_label;
- double tick_size;
- double subtick_size;
- double frame_line_width;
- double half_line_width;
- const char *frame_color;
- const char *title;
- const char *title_font_name;
- double title_font_size;
- int clip_mode;
-
- bool first_point_of_polyline;
- double oldpoint_x, oldpoint_y;
- int symbol;
- int linemode;
- };
- static int clip_line (Multigrapher *multigrapher, double *x0_p, double *y0_p, double *x1_p, double *y1_p);
- static int spacing_type (double spacing);
- static outcode compute_outcode (Multigrapher *multigrapher, double x, double y, bool tolerant);
- static void plot_abscissa_log_subsubtick (Multigrapher *multigrapher, double xval);
- static void plot_errorbar (Multigrapher *multigrapher, const Point *p);
- static void plot_ordinate_log_subsubtick (Multigrapher *multigrapher, double xval);
- static void prepare_axis (Axis *axisp, Transform *trans, double min, double max, double spacing, const char *font_name, double font_size, const char *label, double subsubtick_spacing, bool user_specified_subsubticks, bool round_to_next_tick, bool log_axis, bool reverse_axis, bool switch_axis_end, bool omit_ticks);
- static void print_tick_label (char *labelbuf, const Axis *axis, const Transform *transform, double val);
- static void scale1 (double min, double max, double *tick_spacing, int *tick_spacing_type);
- static void set_line_style (Multigrapher *multigrapher, int style, const char *line_color, bool use_color);
- static void transpose_portmanteau (int *val);
- static void
- print_tick_label (char *labelbuf, const Axis *axis, const Transform *transform, double val)
- {
- int prec;
- char *eloc, *ptr;
- char labelbuf_tmp[64], incrbuf[64];
- double spacing;
- bool big_exponents;
- double min, max;
-
- min = (axis->type == A_LOG10
- ? pow (10.0, transform->input_min) : transform->input_min);
- max = (axis->type == A_LOG10
- ? pow (10.0, transform->input_max) : transform->input_max);
- big_exponents = (((min != 0.0 && fabs (log10 (fabs (min))) >= 4.0)
- || (max != 0.0 && fabs (log10 (fabs (max))) >= 4.0))
- ? true : false);
- if (big_exponents)
-
- {
- char *src = labelbuf_tmp, *dst = labelbuf;
- int exponent;
- char floatbuf[64];
- char *fptr = floatbuf;
- double prefactor;
- sprintf (labelbuf_tmp, "%e", val);
- if ((eloc = strchr (labelbuf_tmp, (int)'e')) == NULL)
- return;
- if (axis->type == A_LOG10 && !axis->user_specified_subsubticks)
-
- {
- sscanf (++eloc, "%d", &exponent);
- sprintf (dst, "10\\sp%d\\ep", exponent);
- return;
- }
-
- if (val == 0.0)
- {
- *dst++ = '0';
- *dst = '\0';
- return;
- }
- while (src < eloc)
- *fptr++ = *src++;
- *fptr = '\0';
- sscanf (floatbuf, "%lf", &prefactor);
- sscanf (++src, "%d", &exponent);
- spacing = (axis->type == A_LINEAR
- ? axis->tick_spacing
- : axis->subsubtick_spacing);
- sprintf (incrbuf, "%f",
- spacing / pow (10.0, (double)exponent));
- ptr = strchr (incrbuf, (int)'.');
- prec = 0;
- if (ptr != NULL)
- {
- int count = 0;
- while (*(++ptr))
- {
- count++;
- if (*ptr != '0')
- prec = count;
- }
- }
-
- sprintf (dst, "%.*f\\r6\\mu10\\sp%d\\ep",
- prec, prefactor, exponent);
- return;
- }
- else
- {
- if (axis->type == A_LOG10 && !axis->user_specified_subsubticks)
-
- {
- sprintf (labelbuf, "%.9g", val);
- return;
- }
-
- spacing = (axis->type == A_LINEAR
- ? axis->tick_spacing
- : axis->subsubtick_spacing);
- sprintf (incrbuf, "%.9f", spacing);
- ptr = strchr (incrbuf, (int)'.');
- prec = 0;
- if (ptr != NULL)
- {
- int count = 0;
- while (*(++ptr))
- {
- count++;
- if (*ptr != '0')
- prec = count;
- }
- }
- sprintf (labelbuf, "%.*f", prec, val);
- return;
- }
- }
- static void
- scale1 (double min, double max, double *tick_spacing, int *tick_spacing_type)
- {
- int k;
- double nal;
- double a, b;
-
- static const double vint[] =
- {
- 1.0, 2.0, 5.0, 10.0
- };
-
- static const double sqr[] =
- {
- M_SQRT2, 3.16228, 7.07107
- };
-
- a = (max - min) / TRIAL_NUMBER_OF_TICK_INTERVALS;
- a *= (max > min) ? 1.0 : -1.0;
- if (a <= 0.0)
- {
- fprintf(stderr, "%s: error: the trial inter-tick spacing '%g' is bad\n",
- progname, a);
- exit (EXIT_FAILURE);
- }
- nal = floor(log10(a));
- b = a * pow (10.0, -nal);
-
- k = 0;
- do
- {
- if (b < sqr[k])
- break;
- k++;
- }
- while (k < 3);
- *tick_spacing = (max > min ? 1.0 : -1.0) * vint[k] * pow (10.0, nal);
-
- *tick_spacing_type = (k == 3 ? 0 : k);
- return;
- }
- static int
- spacing_type (double incr)
- {
- int i;
- int i_tenpower = (int)(floor(log10(incr)));
- double tenpower = 1.0;
- bool neg_power = false;
- if (i_tenpower < 0)
- {
- neg_power = true;
- i_tenpower = -i_tenpower;
- }
- for (i = 0; i < i_tenpower; i++)
- tenpower *= 10;
- if (neg_power)
- tenpower = 1.0 / tenpower;
- if (NEAR_EQUALITY(incr, tenpower, tenpower))
- return S_ONE;
- else if (NEAR_EQUALITY(incr, 2 * tenpower, tenpower))
- return S_TWO;
- else if (NEAR_EQUALITY(incr, 2.5 * tenpower, tenpower))
- return S_TWO_FIVE;
- else if (NEAR_EQUALITY(incr, 5 * tenpower, tenpower))
- return S_FIVE;
- else
- return S_UNKNOWN;
- }
- static void
- prepare_axis (Axis *axisp, Transform *trans, double min, double max, double spacing, const char *font_name, double font_size, const char *label, double subsubtick_spacing, bool user_specified_subsubticks, bool round_to_next_tick, bool log_axis, bool reverse_axis, bool switch_axis_end, bool omit_ticks)
- {
- double range;
- int tick_spacing_type = 0;
- double tick_spacing, lin_subtick_spacing;
- int min_tick_count, max_tick_count;
- int min_lin_subtick_count, max_lin_subtick_count;
- bool have_lin_subticks;
- if (min > max)
-
- {
- fprintf(stderr, "%s: error: min > max for an axis, which is not allowed\n",
- progname);
- exit (EXIT_FAILURE);
- }
- if (min == max)
- {
- max = floor (max + 1.0);
- min = ceil (min - 1.0);
- }
- if (log_axis)
-
- {
- scale1 (min, max, &tick_spacing, &tick_spacing_type);
- if (tick_spacing <= 1.0)
- {
- tick_spacing = 1.0;
- tick_spacing_type = S_ONE;
- }
- }
- else
- {
- if (spacing == 0.0)
- scale1 (min, max, &tick_spacing, &tick_spacing_type);
- else
- {
- tick_spacing = spacing;
- tick_spacing_type = spacing_type (spacing);
- }
- }
- range = max - min;
- if (round_to_next_tick)
- {
- if (user_specified_subsubticks)
-
- {
- double true_min = pow (10.0, min), true_max = pow (10.0, max);
- double true_range = true_max - true_min;
- int min_count, max_count;
- min_count = (int)(floor ((true_min + FUZZ * true_range)
- / subsubtick_spacing));
- max_count = (int)(ceil ((true_max - FUZZ * true_range)
- / subsubtick_spacing));
-
- if (min_count > 0)
- min = log10 (min_count * subsubtick_spacing);
- max = log10 (max_count * subsubtick_spacing);
- range = max - min;
- min_tick_count = max_tick_count = 0;
- }
- else
- {
- min_tick_count = (int)(floor((min + FUZZ * range)/ tick_spacing));
- max_tick_count = (int)(ceil((max - FUZZ * range)/ tick_spacing));
-
-
- min = tick_spacing * min_tick_count;
- max = tick_spacing * max_tick_count;
- range = max - min;
- }
- }
- else
- {
- min_tick_count = (int)(ceil((min - FUZZ * range)/ tick_spacing));
- max_tick_count = (int)(floor((max + FUZZ * range)/ tick_spacing));
-
-
- }
-
- switch (tick_spacing_type)
- {
- case S_FIVE:
- case S_TWO_FIVE:
- lin_subtick_spacing = tick_spacing / 5;
- break;
- case S_TWO:
- lin_subtick_spacing = tick_spacing / 2;
- break;
- case S_ONE:
- lin_subtick_spacing = tick_spacing / 10;
- min_lin_subtick_count = (int)(ceil((min - FUZZ * range)/ lin_subtick_spacing));
- max_lin_subtick_count = (int)(floor((max + FUZZ * range)/ lin_subtick_spacing));
- if (max_lin_subtick_count - min_lin_subtick_count > MAX_NUM_SUBTICKS)
- {
- lin_subtick_spacing = tick_spacing / 5;
- min_lin_subtick_count = (int)(ceil((min - FUZZ * range)/ lin_subtick_spacing));
- max_lin_subtick_count = (int)(floor((max + FUZZ * range)/ lin_subtick_spacing));
- if (max_lin_subtick_count - min_lin_subtick_count > MAX_NUM_SUBTICKS)
- lin_subtick_spacing = tick_spacing / 2;
- }
- break;
- default:
-
- lin_subtick_spacing = tick_spacing;
- break;
- }
-
- if (log_axis && lin_subtick_spacing <= 1.0)
- lin_subtick_spacing = 1.0;
- min_lin_subtick_count = (int)(ceil((min - FUZZ * range)/ lin_subtick_spacing));
- max_lin_subtick_count = (int)(floor((max + FUZZ * range)/ lin_subtick_spacing));
- have_lin_subticks
- = ((tick_spacing_type != S_UNKNOWN
- && (max_lin_subtick_count - min_lin_subtick_count) <= MAX_NUM_SUBTICKS)
- ? true : false);
-
- trans->input_min = min;
- trans->input_max = max;
- trans->input_range = range;
- trans->reverse = reverse_axis;
-
- axisp->switch_axis_end = switch_axis_end;
- axisp->omit_ticks = omit_ticks;
- axisp->label = label;
- axisp->font_name = font_name;
- axisp->font_size = font_size;
- axisp->max_label_width = 0.0;
- axisp->type = log_axis ? A_LOG10 : A_LINEAR;
- axisp->tick_spacing = tick_spacing;
- axisp->min_tick_count = min_tick_count;
- axisp->max_tick_count = max_tick_count;
- axisp->have_lin_subticks = have_lin_subticks;
- axisp->lin_subtick_spacing = lin_subtick_spacing;
- axisp->min_lin_subtick_count = min_lin_subtick_count;
- axisp->max_lin_subtick_count = max_lin_subtick_count;
- axisp->user_specified_subsubticks = user_specified_subsubticks;
- axisp->subsubtick_spacing = subsubtick_spacing;
- axisp->labelled_ticks = 0;
- if (log_axis)
-
- {
- if (max - min <=
- MAX_DECADES_WITH_LOG_SUBSUBTICKS + FUZZ)
-
- axisp->have_normal_subsubticks = true;
- else
-
- axisp->have_normal_subsubticks = false;
- }
- else
- axisp->have_normal_subsubticks = false;
- }
- Multigrapher *
- new_multigrapher (const char *output_format, const char *bg_color, const char *bitmap_size, const char *emulate_color, const char *max_line_length, const char *meta_portable, const char *page_size, const char *rotation_angle, bool save_screen)
- {
- plPlotterParams *plotter_params;
- plPlotter *plotter;
- Multigrapher *multigrapher;
- multigrapher = (Multigrapher *)xmalloc (sizeof (Multigrapher));
-
- plotter_params = pl_newplparams ();
- pl_setplparam (plotter_params, "BG_COLOR", (void *)bg_color);
- pl_setplparam (plotter_params, "BITMAPSIZE", (void *)bitmap_size);
- pl_setplparam (plotter_params, "EMULATE_COLOR", (void *)emulate_color);
- pl_setplparam (plotter_params, "MAX_LINE_LENGTH", (void *)max_line_length);
- pl_setplparam (plotter_params, "META_PORTABLE", (void *)meta_portable);
- pl_setplparam (plotter_params, "PAGESIZE", (void *)page_size);
- pl_setplparam (plotter_params, "ROTATION", (void *)rotation_angle);
-
- plotter = pl_newpl_r (output_format, NULL, stdout, stderr, plotter_params);
- if (plotter == (plPlotter *)NULL)
- return (Multigrapher *)NULL;
- pl_deleteplparams (plotter_params);
- multigrapher->plotter = plotter;
- if (pl_openpl_r (plotter) < 0)
- return (Multigrapher *)NULL;
- multigrapher->bg_color = bg_color;
-
- if (!save_screen || bg_color)
- pl_erase_r (plotter);
- pl_fspace_r (plotter, 0.0, 0.0, (double)PLOT_SIZE, (double)PLOT_SIZE);
- return multigrapher;
- }
- int
- delete_multigrapher (Multigrapher *multigrapher)
- {
- int retval;
- retval = pl_closepl_r (multigrapher->plotter);
- if (retval >= 0)
- retval = pl_deletepl_r (multigrapher->plotter);
- free (multigrapher);
- return retval;
- }
- void
- begin_graph (Multigrapher *multigrapher, double scale, double trans_x, double trans_y)
- {
- pl_savestate_r (multigrapher->plotter);
- pl_fconcat_r (multigrapher->plotter,
- scale, 0.0, 0.0, scale,
- trans_x * PLOT_SIZE, trans_y * PLOT_SIZE);
- }
- void
- end_graph (Multigrapher *multigrapher)
- {
- pl_restorestate_r (multigrapher->plotter);
- }
- void
- set_graph_parameters (Multigrapher *multigrapher, double frame_line_width, const char *frame_color, const char *title, const char *title_font_name, double title_font_size, double tick_size, grid_type grid_spec, double x_min, double x_max, double x_spacing, double y_min, double y_max, double y_spacing, bool spec_x_spacing, bool spec_y_spacing, double width, double height, double up, double right, const char *x_font_name, double x_font_size, const char *x_label, const char *y_font_name, double y_font_size, const char *y_label, bool no_rotate_y_label, int log_axis, int round_to_next_tick, int switch_axis_end, int omit_ticks, int clip_mode, double blankout_fraction, bool transpose_axes)
- {
- double x_subsubtick_spacing = 0.0, y_subsubtick_spacing = 0.0;
-
- int reverse_axis = 0;
- int user_specified_subsubticks = 0;
- if (log_axis & X_AXIS)
- {
- if (spec_x_spacing)
-
- {
- spec_x_spacing = false;
- user_specified_subsubticks |= X_AXIS;
- x_subsubtick_spacing = x_spacing;
- }
- }
- if (log_axis & Y_AXIS)
- {
- if (spec_y_spacing)
- {
-
- spec_y_spacing = false;
- user_specified_subsubticks |= Y_AXIS;
- y_subsubtick_spacing = y_spacing;
- }
- }
-
- if (x_max < x_min)
- {
- reverse_axis |= X_AXIS;
- {
- double temp;
- temp = x_min;
- x_min = x_max;
- x_max = temp;
- }
- }
- if (x_max == x_min)
- {
- fprintf (stderr,
- "%s: identical upper and lower x limits (%f, %f) are separated\n",
- progname, x_max, x_min);
-
- x_max += 1.0;
- x_min -= 1.0;
- }
-
- if (y_max < y_min)
- {
- reverse_axis |= Y_AXIS;
- {
- double temp;
- temp = y_min;
- y_min = y_max;
- y_max = temp;
- }
- }
- if (y_max == y_min)
- {
- fprintf (stderr,
- "%s: identical upper and lower x limits (%f, %f) are separated\n",
- progname, y_max, y_min);
-
- y_max += 1.0;
- y_min -= 1.0;
- }
-
-
- if (spec_x_spacing)
- {
- if (x_spacing == 0.0)
- {
- fprintf (stderr,
- "%s: error: the spacing between ticks on an axis is zero\n",
- progname);
- exit (EXIT_FAILURE);
- }
- x_spacing = fabs (x_spacing);
- }
- if (spec_y_spacing)
- {
- if (y_spacing == 0.0)
- {
- fprintf (stderr,
- "%s: error: the spacing between ticks on an axis is zero\n",
- progname);
- exit (EXIT_FAILURE);
- }
- y_spacing = fabs (y_spacing);
- }
-
- if (transpose_axes)
- {
- const char *temp_string;
- double temp_double;
- transpose_portmanteau (&log_axis);
- transpose_portmanteau (&round_to_next_tick);
- transpose_portmanteau (&switch_axis_end);
- transpose_portmanteau (&omit_ticks);
- transpose_portmanteau (&reverse_axis);
- transpose_portmanteau (&user_specified_subsubticks);
- temp_string = x_label;
- x_label = y_label;
- y_label = temp_string;
- temp_double = x_min;
- x_min = y_min;
- y_min = temp_double;
- temp_double = x_max;
- x_max = y_max;
- y_max = temp_double;
- temp_double = x_spacing;
- x_spacing = y_spacing;
- y_spacing = temp_double;
- temp_double = x_subsubtick_spacing;
- x_subsubtick_spacing = y_subsubtick_spacing;
- y_subsubtick_spacing = temp_double;
- }
-
- multigrapher->frame_line_width = frame_line_width;
- multigrapher->frame_color = frame_color;
- multigrapher->no_rotate_y_label = no_rotate_y_label;
- multigrapher->blankout_fraction = blankout_fraction;
- if (title != NULL)
- multigrapher->title = xstrdup (title);
- else
- multigrapher->title = NULL;
- if (title_font_name != NULL)
- multigrapher->title_font_name = xstrdup (title_font_name);
- else
- multigrapher->title_font_name = NULL;
- multigrapher->title_font_size = title_font_size;
- multigrapher->tick_size = tick_size;
- multigrapher->subtick_size = RELATIVE_SUBTICK_SIZE * tick_size;
- multigrapher->grid_spec = grid_spec;
- multigrapher->clip_mode = clip_mode;
-
- prepare_axis (&multigrapher->x_axis, &multigrapher->x_trans,
- x_min, x_max, x_spacing,
- x_font_name, x_font_size, x_label,
- x_subsubtick_spacing,
- (bool)(user_specified_subsubticks & X_AXIS),
- (bool)(round_to_next_tick & X_AXIS),
- (bool)(log_axis & X_AXIS),
- (bool)(reverse_axis & X_AXIS),
- (bool)(switch_axis_end & X_AXIS),
- (bool)(omit_ticks & X_AXIS));
- prepare_axis (&multigrapher->y_axis, &multigrapher->y_trans,
- y_min, y_max, y_spacing,
- y_font_name, y_font_size, y_label,
- y_subsubtick_spacing,
- (bool)(user_specified_subsubticks & Y_AXIS),
- (bool)(round_to_next_tick & Y_AXIS),
- (bool)(log_axis & Y_AXIS),
- (bool)(reverse_axis & Y_AXIS),
- (bool)(switch_axis_end & Y_AXIS),
- (bool)(omit_ticks & Y_AXIS));
-
- multigrapher->x_trans.squeezed_min = right;
- multigrapher->x_trans.squeezed_max = right + width;
- multigrapher->x_trans.squeezed_range = width;
- multigrapher->y_trans.squeezed_min = up;
- multigrapher->y_trans.squeezed_max = up + height;
- multigrapher->y_trans.squeezed_range = height;
-
- multigrapher->x_trans.output_min = 0.0;
- multigrapher->x_trans.output_max = (double)PLOT_SIZE;
- multigrapher->x_trans.output_range = multigrapher->x_trans.output_max - multigrapher->x_trans.output_min;
- multigrapher->x_trans.output_min = 0.0;
- multigrapher->y_trans.output_max = (double)PLOT_SIZE;
- multigrapher->y_trans.output_range = multigrapher->y_trans.output_max - multigrapher->y_trans.output_min;
-
- if (multigrapher->grid_spec != AXES_AT_ORIGIN)
-
- {
-
- multigrapher->x_axis.other_axis_loc = multigrapher->x_trans.input_min;
- multigrapher->y_axis.other_axis_loc = multigrapher->y_trans.input_min;
-
- multigrapher->x_axis.alt_other_axis_loc = multigrapher->x_trans.input_max;
- multigrapher->y_axis.alt_other_axis_loc = multigrapher->y_trans.input_max;
- }
- else
-
- {
-
- multigrapher->x_axis.other_axis_loc
- = (multigrapher->x_trans.input_min * multigrapher->x_trans.input_max <= 0.0) ? 0.0 :
- (multigrapher->x_trans.input_min > 0.0 ? multigrapher->x_trans.input_min : multigrapher->x_trans.input_max);
- multigrapher->y_axis.other_axis_loc
- = (multigrapher->y_trans.input_min * multigrapher->y_trans.input_max <= 0.0) ? 0.0 :
- (multigrapher->y_trans.input_min > 0.0 ? multigrapher->y_trans.input_min : multigrapher->y_trans.input_max);
-
- multigrapher->x_axis.alt_other_axis_loc = multigrapher->x_axis.other_axis_loc;
- multigrapher->y_axis.alt_other_axis_loc = multigrapher->y_axis.other_axis_loc;
- multigrapher->x_axis.switch_axis_end = (((multigrapher->x_trans.input_max - multigrapher->x_axis.other_axis_loc)
- < (multigrapher->x_axis.other_axis_loc - multigrapher->x_trans.input_min))
- ? true : false);
- multigrapher->y_axis.switch_axis_end = (((multigrapher->y_trans.input_max - multigrapher->y_axis.other_axis_loc)
- < (multigrapher->y_axis.other_axis_loc - multigrapher->y_trans.input_min))
- ? true : false);
- }
-
- if (frame_line_width < 0.0
- || pl_havecap_r (multigrapher->plotter, "WIDE_LINES") == 0)
- multigrapher->half_line_width = 0.0;
- else
- multigrapher->half_line_width = 0.5 * frame_line_width * multigrapher->x_trans.output_range;
-
- multigrapher->first_point_of_polyline = true;
- multigrapher->oldpoint_x = 0.0;
- multigrapher->oldpoint_y = 0.0;
- }
-
- void
- draw_frame_of_graph (Multigrapher *multigrapher, bool draw_canvas)
- {
- static bool tick_warning_printed = false;
-
- pl_savestate_r (multigrapher->plotter);
-
- if (multigrapher->frame_color)
- pl_pencolorname_r (multigrapher->plotter, multigrapher->frame_color);
-
- pl_flinewidth_r (multigrapher->plotter,
- multigrapher->frame_line_width * (double)PLOT_SIZE);
-
- pl_linemod_r (multigrapher->plotter, "solid");
-
- pl_filltype_r (multigrapher->plotter, 0);
-
- if (draw_canvas)
- {
- pl_savestate_r (multigrapher->plotter);
-
- if (pl_havecap_r (multigrapher->plotter, "SETTABLE_BACKGROUND") != 0
- && multigrapher->bg_color)
- pl_colorname_r (multigrapher->plotter, multigrapher->bg_color);
- else
- pl_colorname_r (multigrapher->plotter, "white");
- pl_filltype_r (multigrapher->plotter, 1);
- pl_fbox_r (multigrapher->plotter,
- XP(XSQ(0.5 - 0.5 * multigrapher->blankout_fraction)),
- YP(YSQ(0.5 - 0.5 * multigrapher->blankout_fraction)),
- XP(XSQ(0.5 + 0.5 * multigrapher->blankout_fraction)),
- YP(YSQ(0.5 + 0.5 * multigrapher->blankout_fraction)));
- pl_restorestate_r (multigrapher->plotter);
- }
-
- if (multigrapher->grid_spec != NO_AXES
- && !multigrapher->y_axis.switch_axis_end
- && multigrapher->title != NULL && *multigrapher->title != '\0')
- {
- double title_font_size;
-
- pl_fontname_r (multigrapher->plotter, multigrapher->title_font_name);
- title_font_size = pl_ffontsize_r (multigrapher->plotter,
- SS(multigrapher->title_font_size));
- pl_fmove_r (multigrapher->plotter,
- XP(XSQ(0.5)),
- YP(YSQ(1.0
- + (((multigrapher->grid_spec == AXES_AND_BOX
- || multigrapher->grid_spec == AXES
- || multigrapher->grid_spec == BOX)
- && (multigrapher->tick_size <= 0.0) ? 1.0 : 0.5)
- * fabs(multigrapher->tick_size))))
- + 0.65 * title_font_size
- + multigrapher->half_line_width);
-
- pl_alabel_r (multigrapher->plotter, 'c', 'b', multigrapher->title);
- }
-
- switch (multigrapher->grid_spec)
- {
- case AXES_AND_BOX_AND_GRID:
- case AXES_AND_BOX:
- case BOX:
-
- pl_fbox_r (multigrapher->plotter,
- XP(XSQ(0.0)), YP(YSQ(0.0)), XP(XSQ(1.0)), YP(YSQ(1.0)));
- break;
- case AXES:
- {
- double xstart, ystart, xmid, ymid, xend, yend;
- xstart = (multigrapher->x_axis.switch_axis_end
- ? XN(multigrapher->x_axis.other_axis_loc) - multigrapher->half_line_width
- : XN(multigrapher->x_axis.alt_other_axis_loc) + multigrapher->half_line_width);
- ystart = (multigrapher->y_axis.switch_axis_end
- ? YN(multigrapher->y_axis.alt_other_axis_loc)
- : YN(multigrapher->y_axis.other_axis_loc));
- xmid = (multigrapher->x_axis.switch_axis_end
- ? XN(multigrapher->x_axis.alt_other_axis_loc)
- : XN(multigrapher->x_axis.other_axis_loc));
- ymid = ystart;
- xend = xmid;
- yend = (multigrapher->y_axis.switch_axis_end
- ? YN(multigrapher->y_axis.other_axis_loc) - multigrapher->half_line_width
- : YN(multigrapher->y_axis.alt_other_axis_loc) + multigrapher->half_line_width);
- pl_fmove_r (multigrapher->plotter, xstart, ystart);
- pl_fcont_r (multigrapher->plotter, xmid, ymid);
- pl_fcont_r (multigrapher->plotter, xend, yend);
- }
- break;
- case AXES_AT_ORIGIN:
- {
- double xpos, ypos;
- xpos = (multigrapher->x_axis.switch_axis_end
- ? XN(multigrapher->x_axis.other_axis_loc)
- : XN(multigrapher->x_axis.alt_other_axis_loc));
- ypos = (multigrapher->y_axis.switch_axis_end
- ? YN(multigrapher->y_axis.alt_other_axis_loc)
- : YN(multigrapher->y_axis.other_axis_loc));
- pl_fline_r (multigrapher->plotter,
- xpos, YP(YSQ(0.0)) - multigrapher->half_line_width,
- xpos, YP(YSQ(1.0)) + multigrapher->half_line_width);
- pl_fline_r (multigrapher->plotter,
- XP(XSQ(0.0)) - multigrapher->half_line_width, ypos,
- XP(XSQ(1.0)) + multigrapher->half_line_width, ypos);
- }
- break;
- case NO_AXES:
- default:
- break;
- }
-
- if (multigrapher->grid_spec != NO_AXES && !multigrapher->x_axis.omit_ticks
- && !multigrapher->x_axis.user_specified_subsubticks)
- {
- int i;
- double xval, xrange = multigrapher->x_trans.input_max - multigrapher->x_trans.input_min;
-
- char labelbuf[2048];
-
- pl_fontname_r (multigrapher->plotter, multigrapher->x_axis.font_name);
- pl_ffontsize_r (multigrapher->plotter, SS(multigrapher->x_axis.font_size));
- for (i = multigrapher->x_axis.min_tick_count; i <= multigrapher->x_axis.max_tick_count; i++)
-
- {
- xval = i * multigrapher->x_axis.tick_spacing;
-
- if (xval < multigrapher->x_trans.input_min - FUZZ * xrange
- || xval > multigrapher->x_trans.input_max + FUZZ * xrange)
- continue;
-
- if (!multigrapher->y_axis.switch_axis_end
- && !(multigrapher->grid_spec == AXES_AT_ORIGIN
-
- && NEAR_EQUALITY (xval, multigrapher->x_axis.other_axis_loc,
- multigrapher->x_trans.input_range)
- && (multigrapher->y_axis.other_axis_loc != multigrapher->y_trans.input_min)
- && (multigrapher->y_axis.other_axis_loc != multigrapher->y_trans.input_max)))
-
- {
- pl_fmove_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.other_axis_loc)
- - (SS ((multigrapher->tick_size >= 0.0 ? 0.75 : 1.75) * fabs(multigrapher->tick_size))
- + multigrapher->half_line_width));
- print_tick_label (labelbuf,
- &multigrapher->x_axis, &multigrapher->x_trans,
- (multigrapher->x_axis.type == A_LOG10) ? pow (10.0, xval) : xval);
- pl_alabel_r (multigrapher->plotter, 'c', 't', labelbuf);
- multigrapher->x_axis.labelled_ticks++;
- }
- else
-
- if (multigrapher->y_axis.switch_axis_end
- && !(multigrapher->grid_spec == AXES_AT_ORIGIN
-
- && NEAR_EQUALITY (xval, multigrapher->x_axis.other_axis_loc,
- multigrapher->x_trans.input_range)
- && (multigrapher->y_axis.other_axis_loc != multigrapher->y_trans.input_min)
- && (multigrapher->y_axis.other_axis_loc != multigrapher->y_trans.input_max)))
- {
- pl_fmove_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.alt_other_axis_loc)
- + (SS ((multigrapher->tick_size >= 0.0 ? 0.75 : 1.75) * fabs(multigrapher->tick_size))
- + multigrapher->half_line_width));
- print_tick_label (labelbuf,
- &multigrapher->x_axis, &multigrapher->x_trans,
- (multigrapher->x_axis.type == A_LOG10) ? pow (10.0, xval) : xval);
- pl_alabel_r (multigrapher->plotter, 'c', 'b', labelbuf);
- multigrapher->x_axis.labelled_ticks++;
- }
-
- switch (multigrapher->grid_spec)
- {
- case AXES_AND_BOX_AND_GRID:
- pl_linemod_r (multigrapher->plotter, "dotted");
- pl_fmove_r (multigrapher->plotter, XV(xval), YP(YSQ(0.0)));
- pl_fcont_r (multigrapher->plotter, XV(xval), YP(YSQ(1.0)));
- pl_linemod_r (multigrapher->plotter, "solid");
-
- case AXES_AND_BOX:
- case BOX:
- if (!multigrapher->y_axis.switch_axis_end)
- {
- pl_fmove_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.alt_other_axis_loc));
- pl_fcont_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.alt_other_axis_loc)
- - (SS (multigrapher->tick_size)
- + (multigrapher->tick_size > 0.0 ? multigrapher->half_line_width
- : -multigrapher->half_line_width)));
- }
- else
- {
- pl_fmove_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.other_axis_loc));
- pl_fcont_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.other_axis_loc)
- + (SS (multigrapher->tick_size)
- + (multigrapher->tick_size > 0.0 ? multigrapher->half_line_width
- : -multigrapher->half_line_width)));
- }
-
- case AXES:
- case AXES_AT_ORIGIN:
- if (!multigrapher->y_axis.switch_axis_end)
- {
- pl_fmove_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.other_axis_loc));
- pl_fcont_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.other_axis_loc)
- + (SS (multigrapher->tick_size)
- + (multigrapher->tick_size > 0.0 ? multigrapher->half_line_width
- : -multigrapher->half_line_width)));
- }
- else
- {
- pl_fmove_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.alt_other_axis_loc));
- pl_fcont_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.alt_other_axis_loc)
- - (SS (multigrapher->tick_size)
- + (multigrapher->tick_size > 0.0 ? multigrapher->half_line_width
- : -multigrapher->half_line_width)));
- }
- break;
- default:
- break;
- }
- }
- if (multigrapher->x_axis.have_lin_subticks)
- {
- double subtick_size;
-
- subtick_size = (multigrapher->x_axis.type == A_LOG10
- ? SS(multigrapher->tick_size) : SS(multigrapher->subtick_size));
-
- for (i = multigrapher->x_axis.min_lin_subtick_count; i <= multigrapher->x_axis.max_lin_subtick_count; i++)
-
- {
- xval = i * multigrapher->x_axis.lin_subtick_spacing;
-
- if (xval < multigrapher->x_trans.input_min - FUZZ * xrange
- || xval > multigrapher->x_trans.input_max + FUZZ * xrange)
- continue;
- switch (multigrapher->grid_spec)
- {
- case AXES_AND_BOX_AND_GRID:
- case AXES_AND_BOX:
- case BOX:
-
- if (!multigrapher->y_axis.switch_axis_end)
- {
- pl_fmove_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.alt_other_axis_loc));
- pl_fcont_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.alt_other_axis_loc)
- - (subtick_size
- + (subtick_size > 0.0 ? multigrapher->half_line_width
- : -multigrapher->half_line_width)));
- }
- else
- {
- pl_fmove_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.other_axis_loc));
- pl_fcont_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.other_axis_loc)
- + (subtick_size
- + (subtick_size > 0.0 ? multigrapher->half_line_width
- : -multigrapher->half_line_width)));
- }
-
- case AXES:
- case AXES_AT_ORIGIN:
- if (!multigrapher->y_axis.switch_axis_end)
-
- {
- pl_fmove_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.other_axis_loc));
- pl_fcont_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.other_axis_loc)
- + (subtick_size
- + (subtick_size > 0.0 ? multigrapher->half_line_width
- : -multigrapher->half_line_width)));
- }
- else
- {
- pl_fmove_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.alt_other_axis_loc));
- pl_fcont_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.alt_other_axis_loc)
- - (subtick_size
- + (subtick_size > 0.0 ? multigrapher->half_line_width
- : -multigrapher->half_line_width)));
- }
- break;
- default:
- break;
- }
- }
- }
-
- if (multigrapher->grid_spec != AXES_AT_ORIGIN
- && multigrapher->grid_spec != BOX
- && multigrapher->x_axis.type == A_LINEAR
- && multigrapher->x_trans.input_min * multigrapher->x_trans.input_max < 0.0)
- {
- pl_linemod_r (multigrapher->plotter, "dotted");
- pl_fline_r (multigrapher->plotter,
- XV(0.0), YP(YSQ(0.0)), XV(0.0), YP(YSQ(1.0)));
- pl_linemod_r (multigrapher->plotter, "solid");
- }
- }
-
- if (multigrapher->grid_spec != NO_AXES && !multigrapher->y_axis.omit_ticks
- && !multigrapher->y_axis.user_specified_subsubticks)
- {
- int i;
- double yval, yrange = multigrapher->y_trans.input_max - multigrapher->y_trans.input_min;
-
- char labelbuf[2048];
-
- pl_fontname_r (multigrapher->plotter, multigrapher->y_axis.font_name);
- pl_ffontsize_r (multigrapher->plotter, SS(multigrapher->y_axis.font_size));
- for (i = multigrapher->y_axis.min_tick_count; i <= multigrapher->y_axis.max_tick_count; i++)
-
- {
- yval = i * multigrapher->y_axis.tick_spacing;
-
- if (yval < multigrapher->y_trans.input_min - FUZZ * yrange
- || yval > multigrapher->y_trans.input_max + FUZZ * yrange)
- continue;
-
- if (!multigrapher->x_axis.switch_axis_end
- && !(multigrapher->grid_spec == AXES_AT_ORIGIN
-
- && NEAR_EQUALITY (yval, multigrapher->y_axis.other_axis_loc,
- multigrapher->y_trans.input_range)
- && (multigrapher->x_axis.other_axis_loc != multigrapher->x_trans.input_min)
- && (multigrapher->x_axis.other_axis_loc != multigrapher->x_trans.input_max)))
-
- {
- double new_width;
- pl_fmove_r (multigrapher->plotter,
- XN (multigrapher->x_axis.other_axis_loc)
- - (SS((multigrapher->tick_size >= 0.0 ? 0.75 : 1.75)
- * fabs(multigrapher->tick_size))
- + multigrapher->half_line_width),
- YV (yval));
- print_tick_label (labelbuf,
- &multigrapher->y_axis, &multigrapher->y_trans,
- (multigrapher->y_axis.type == A_LOG10) ? pow (10.0, yval) : yval);
- new_width = pl_flabelwidth_r (multigrapher->plotter, labelbuf);
- pl_alabel_r (multigrapher->plotter, 'r', 'c', labelbuf);
- multigrapher->y_axis.max_label_width = DMAX(multigrapher->y_axis.max_label_width, new_width);
- multigrapher->y_axis.labelled_ticks++;
- }
- else
-
- if (multigrapher->x_axis.switch_axis_end
- && !(multigrapher->grid_spec == AXES_AT_ORIGIN
-
- && NEAR_EQUALITY (yval, multigrapher->y_axis.other_axis_loc,
- multigrapher->y_trans.input_range)
- && (multigrapher->x_axis.other_axis_loc != multigrapher->x_trans.input_min)
- && (multigrapher->x_axis.other_axis_loc != multigrapher->x_trans.input_max)))
- {
- double new_width;
- pl_fmove_r (multigrapher->plotter,
- XN (multigrapher->x_axis.alt_other_axis_loc)
- + (SS((multigrapher->tick_size >= 0.0 ? 0.75 : 1.75)
- * fabs(multigrapher->tick_size))
- + multigrapher->half_line_width),
- YV (yval));
- print_tick_label (labelbuf,
- &multigrapher->y_axis, &multigrapher->y_trans,
- (multigrapher->y_axis.type == A_LOG10) ? pow (10.0, yval) : yval);
- new_width = pl_flabelwidth_r (multigrapher->plotter, labelbuf);
- pl_alabel_r (multigrapher->plotter, 'l', 'c', labelbuf);
- multigrapher->y_axis.max_label_width = DMAX(multigrapher->y_axis.max_label_width, new_width);
- multigrapher->y_axis.labelled_ticks++;
- }
-
- switch (multigrapher->grid_spec)
- {
- case AXES_AND_BOX_AND_GRID:
- pl_linemod_r (multigrapher->plotter, "dotted");
- pl_fmove_r (multigrapher->plotter, XP(XSQ(0.0)), YV (yval));
- pl_fcont_r (multigrapher->plotter, XP(XSQ(1.0)), YV (yval));
- pl_linemod_r (multigrapher->plotter, "solid");
-
- case AXES_AND_BOX:
- case BOX:
- if (!multigrapher->x_axis.switch_axis_end)
- {
- pl_fmove_r (multigrapher->plotter,
- XN (multigrapher->x_axis.alt_other_axis_loc),
- YV (yval));
- pl_fcont_r (multigrapher->plotter,
- XN (multigrapher->x_axis.alt_other_axis_loc)
- - (SS (multigrapher->tick_size)
- + (multigrapher->tick_size > 0.0 ? multigrapher->half_line_width
- : -multigrapher->half_line_width)),
- YV (yval));
- }
- else
- {
- pl_fmove_r (multigrapher->plotter,
- XN (multigrapher->x_axis.other_axis_loc),
- YV (yval));
- pl_fcont_r (multigrapher->plotter,
- XN (multigrapher->x_axis.other_axis_loc)
- + (SS (multigrapher->tick_size)
- + (multigrapher->tick_size > 0.0 ? multigrapher->half_line_width
- : -multigrapher->half_line_width)),
- YV (yval));
- }
-
- case AXES:
- case AXES_AT_ORIGIN:
- if (!multigrapher->x_axis.switch_axis_end)
- {
- pl_fmove_r (multigrapher->plotter,
- XN (multigrapher->x_axis.other_axis_loc),
- YV (yval));
- pl_fcont_r (multigrapher->plotter,
- XN (multigrapher->x_axis.other_axis_loc)
- + (SS (multigrapher->tick_size)
- + (multigrapher->tick_size > 0.0 ? multigrapher->half_line_width
- : -multigrapher->half_line_width)),
- YV (yval));
- }
- else
- {
- pl_fmove_r (multigrapher->plotter,
- XN (multigrapher->x_axis.alt_other_axis_loc),
- YV (yval));
- pl_fcont_r (multigrapher->plotter,
- XN (multigrapher->x_axis.alt_other_axis_loc)
- - (SS (multigrapher->tick_size)
- + (multigrapher->tick_size > 0.0 ? multigrapher->half_line_width
- : -multigrapher->half_line_width)),
- YV (yval));
- }
- break;
- default:
- break;
- }
- }
- if (multigrapher->y_axis.have_lin_subticks)
- {
- double subtick_size;
-
- subtick_size = (multigrapher->y_axis.type == A_LOG10
- ? SS(multigrapher->tick_size) : SS(multigrapher->subtick_size));
-
- for (i = multigrapher->y_axis.min_lin_subtick_count; i <= multigrapher->y_axis.max_lin_subtick_count; i++)
-
- {
- yval = i * multigrapher->y_axis.lin_subtick_spacing;
-
- if (yval < multigrapher->y_trans.input_min - FUZZ * yrange
- || yval > multigrapher->y_trans.input_max + FUZZ * yrange)
- continue;
-
- switch (multigrapher->grid_spec)
- {
- case AXES_AND_BOX_AND_GRID:
- case AXES_AND_BOX:
- case BOX:
- if (!multigrapher->x_axis.switch_axis_end)
- {
- pl_fmove_r (multigrapher->plotter,
- XN (multigrapher->x_axis.alt_other_axis_loc),
- YV (yval));
- pl_fcont_r (multigrapher->plotter,
- XN (multigrapher->x_axis.alt_other_axis_loc)
- - (subtick_size
- + (subtick_size > 0.0 ? multigrapher->half_line_width
- : -multigrapher->half_line_width)),
- YV (yval));
- }
- else
- {
- pl_fmove_r (multigrapher->plotter,
- XN (multigrapher->x_axis.other_axis_loc),
- YV (yval));
- pl_fcont_r (multigrapher->plotter,
- XN (multigrapher->x_axis.other_axis_loc)
- + (subtick_size
- + (subtick_size > 0.0 ? multigrapher->half_line_width
- : -multigrapher->half_line_width)),
- YV (yval));
- }
-
- case AXES:
- case AXES_AT_ORIGIN:
- if (!multigrapher->x_axis.switch_axis_end)
- {
- pl_fmove_r (multigrapher->plotter,
- XN (multigrapher->x_axis.other_axis_loc),
- YV (yval));
- pl_fcont_r (multigrapher->plotter,
- XN (multigrapher->x_axis.other_axis_loc)
- + (subtick_size
- + (subtick_size > 0.0 ? multigrapher->half_line_width
- : -multigrapher->half_line_width)),
- YV (yval));
- }
- else
- {
- pl_fmove_r (multigrapher->plotter,
- XN (multigrapher->x_axis.alt_other_axis_loc),
- YV (yval));
- pl_fcont_r (multigrapher->plotter,
- XN (multigrapher->x_axis.alt_other_axis_loc)
- - (subtick_size
- + (subtick_size > 0.0 ? multigrapher->half_line_width
- : -multigrapher->half_line_width)),
- YV (yval));
- }
- break;
- default:
- break;
- }
- }
- }
-
- if (multigrapher->grid_spec != AXES_AT_ORIGIN
- && multigrapher->grid_spec != BOX
- && multigrapher->y_axis.type == A_LINEAR
- && multigrapher->y_trans.input_min * multigrapher->y_trans.input_max < 0.0)
- {
- pl_linemod_r (multigrapher->plotter, "dotted");
- pl_fline_r (multigrapher->plotter,
- XP(XSQ(0.0)), YV(0.0), XP(XSQ(1.0)), YV(0.0));
- pl_linemod_r (multigrapher->plotter, "solid");
- }
- }
-
-
- if (multigrapher->grid_spec != NO_AXES && multigrapher->x_axis.have_normal_subsubticks
- && !multigrapher->x_axis.user_specified_subsubticks && !multigrapher->x_axis.omit_ticks)
- {
- int i, m, imin, imax;
- double xval, xrange = multigrapher->x_trans.input_max - multigrapher->x_trans.input_min;
-
- imin = (int)(floor (multigrapher->x_trans.input_min - FUZZ * xrange));
- imax = (int)(ceil (multigrapher->x_trans.input_max + FUZZ * xrange));
- for (i = imin; i < imax; i++)
- {
- for (m = 1; m <= 9 ; m++)
- {
- xval = i + log10 ((double)m);
-
-
- plot_abscissa_log_subsubtick (multigrapher, xval);
- }
- }
- }
-
- if (multigrapher->grid_spec != NO_AXES && multigrapher->x_axis.user_specified_subsubticks
- && !multigrapher->x_axis.omit_ticks)
- {
- int i, imin, imax;
- double xval, xrange = multigrapher->x_trans.input_max - multigrapher->x_trans.input_min;
-
- imin = (int)(floor (pow (10.0, multigrapher->x_trans.input_min - FUZZ * xrange)
- / multigrapher->x_axis.subsubtick_spacing));
- imax = (int)(ceil (pow (10.0, multigrapher->x_trans.input_max + FUZZ * xrange)
- / multigrapher->x_axis.subsubtick_spacing));
-
- for (i = imin; i <= imax; i++)
- {
- xval = log10 (i * multigrapher->x_axis.subsubtick_spacing);
-
-
- plot_abscissa_log_subsubtick (multigrapher, xval);
- }
- }
-
-
- if (multigrapher->grid_spec != NO_AXES && multigrapher->y_axis.have_normal_subsubticks
- && !multigrapher->y_axis.user_specified_subsubticks && !multigrapher->y_axis.omit_ticks)
- {
- int i, m, imin, imax;
- double yval, yrange = multigrapher->y_trans.input_max - multigrapher->y_trans.input_min;
-
- imin = (int)(floor (multigrapher->y_trans.input_min - FUZZ * yrange));
- imax = (int)(ceil (multigrapher->y_trans.input_max + FUZZ * yrange));
-
- for (i = imin; i < imax; i++)
- {
- for (m = 1; m <= 9; m++)
- {
- yval = i + log10 ((double)m);
-
-
- plot_ordinate_log_subsubtick (multigrapher, yval);
- }
- }
- }
-
- if (multigrapher->grid_spec != NO_AXES && multigrapher->y_axis.user_specified_subsubticks
- && !multigrapher->y_axis.omit_ticks)
- {
- int i, imin, imax;
- double yval, yrange = multigrapher->y_trans.input_max - multigrapher->y_trans.input_min;
-
- imin = (int)(floor (pow (10.0, multigrapher->y_trans.input_min - FUZZ * yrange)
- / multigrapher->y_axis.subsubtick_spacing));
- imax = (int)(ceil (pow (10.0, multigrapher->y_trans.input_max + FUZZ * yrange)
- / multigrapher->y_axis.subsubtick_spacing));
-
- for (i = imin; i <= imax; i++)
- {
- yval = log10 (i * multigrapher->y_axis.subsubtick_spacing);
-
-
- plot_ordinate_log_subsubtick (multigrapher, yval);
- }
- }
-
- if ((multigrapher->grid_spec != NO_AXES)
- && multigrapher->x_axis.label != NULL && multigrapher->x_axis.label != '\0')
- {
- double x_axis_font_size;
- double xloc;
-
- pl_fontname_r (multigrapher->plotter, multigrapher->x_axis.font_name);
- x_axis_font_size = pl_ffontsize_r (multigrapher->plotter,
- SS(multigrapher->x_axis.font_size));
- if (multigrapher->grid_spec != AXES_AT_ORIGIN)
-
- xloc = 0.5 * (multigrapher->x_trans.input_max + multigrapher->x_trans.input_min);
- else
- {
- if ((multigrapher->y_axis.other_axis_loc == multigrapher->y_trans.input_min)
- || (multigrapher->y_axis.other_axis_loc == multigrapher->y_trans.input_max))
- xloc = 0.5 * (multigrapher->x_trans.input_max + multigrapher->x_trans.input_min);
- else
-
- xloc =
- multigrapher->x_trans.input_max-multigrapher->x_axis.other_axis_loc >= multigrapher->x_axis.other_axis_loc-multigrapher->x_trans.input_min ?
- 0.5 * (multigrapher->x_trans.input_max + multigrapher->x_axis.other_axis_loc) :
- 0.5 * (multigrapher->x_axis.other_axis_loc + multigrapher->x_trans.input_min);
- }
- if (!multigrapher->y_axis.switch_axis_end)
- {
- pl_fmove_r (multigrapher->plotter,
- XV (xloc),
- YN (multigrapher->y_axis.other_axis_loc)
- - (SS ((multigrapher->tick_size >= 0.0 ? 0.875 : 2.125)
- * fabs(multigrapher->tick_size))
- + (6 * x_axis_font_size)/5
- + multigrapher->half_line_width));
- pl_alabel_r (multigrapher->plotter,
- 'c', 't', multigrapher->x_axis.label);
- }
- else
- {
- pl_fmove_r (multigrapher->plotter,
- XV (xloc),
- YN (multigrapher->y_axis.alt_other_axis_loc)
- + (SS ((multigrapher->tick_size >= 0.0 ? 0.875 : 2.125)
- * fabs(multigrapher->tick_size))
- + (6 * x_axis_font_size)/5
- + multigrapher->half_line_width));
- pl_alabel_r (multigrapher->plotter,
- 'c', 'b', multigrapher->x_axis.label);
- }
- }
-
- if ((multigrapher->grid_spec != NO_AXES)
- && (multigrapher->y_axis.label != NULL && *(multigrapher->y_axis.label) != '\0'))
- {
- double y_axis_font_size;
- double yloc;
-
- pl_fontname_r (multigrapher->plotter, multigrapher->y_axis.font_name);
- y_axis_font_size = pl_ffontsize_r (multigrapher->plotter,
- SS(multigrapher->y_axis.font_size));
- if (multigrapher->grid_spec != AXES_AT_ORIGIN)
-
- yloc = 0.5 * (multigrapher->y_trans.input_min + multigrapher->y_trans.input_max);
- else
- {
- if ((multigrapher->x_axis.other_axis_loc == multigrapher->x_trans.input_min)
- || (multigrapher->x_axis.other_axis_loc == multigrapher->x_trans.input_max))
- yloc = 0.5 * (multigrapher->y_trans.input_min + multigrapher->y_trans.input_max);
- else
-
- yloc =
- multigrapher->y_trans.input_max-multigrapher->y_axis.other_axis_loc >= multigrapher->y_axis.other_axis_loc-multigrapher->y_trans.input_min ?
- 0.5 * (multigrapher->y_trans.input_max + multigrapher->y_axis.other_axis_loc) :
- 0.5 * (multigrapher->y_axis.other_axis_loc + multigrapher->y_trans.input_min);
- }
- #define libplot_has_font_metrics 1
- if (!multigrapher->x_axis.switch_axis_end)
- {
- pl_fmove_r (multigrapher->plotter,
- XN (multigrapher->x_axis.other_axis_loc)
- - (libplot_has_font_metrics ?
- (SS((multigrapher->tick_size >= 0.0 ? 0.75 : 1.75)
- * fabs(multigrapher->tick_size))
- + 1.15 * multigrapher->y_axis.max_label_width
- + 0.5 * y_axis_font_size
- + multigrapher->half_line_width)
- : (SS((multigrapher->tick_size >= 0.0 ? 0.75 : 1.75)
- * fabs(multigrapher->tick_size))
- + 1.0 * y_axis_font_size
- + multigrapher->half_line_width)),
- YV(yloc));
- if (libplot_has_font_metrics
- && !multigrapher->no_rotate_y_label)
- {
- pl_textangle_r (multigrapher->plotter, 90);
- pl_alabel_r (multigrapher->plotter,
- 'c', 'x', multigrapher->y_axis.label);
- pl_textangle_r (multigrapher->plotter, 0);
- }
- else
-
- pl_alabel_r (multigrapher->plotter,
- 'r', 'c', multigrapher->y_axis.label);
- }
- else
- {
- pl_fmove_r (multigrapher->plotter,
- XN (multigrapher->x_axis.alt_other_axis_loc)
- + (libplot_has_font_metrics ?
- (SS((multigrapher->tick_size >= 0.0 ? 0.75 : 1.75)
- * fabs(multigrapher->tick_size))
- + 1.15 * multigrapher->y_axis.max_label_width
- + 0.5 * y_axis_font_size
- + multigrapher->half_line_width)
- : (SS((multigrapher->tick_size >= 0.0 ? 0.75 : 1.75)
- * fabs(multigrapher->tick_size))
- + 1.0 * y_axis_font_size
- + multigrapher->half_line_width)),
- YV(yloc));
- if (libplot_has_font_metrics
- && !multigrapher->no_rotate_y_label)
- {
- pl_textangle_r (multigrapher->plotter, 90);
- pl_alabel_r (multigrapher->plotter,
- 'c', 't', multigrapher->y_axis.label);
- pl_textangle_r (multigrapher->plotter, 0);
- }
- else
-
- pl_alabel_r (multigrapher->plotter,
- 'l', 'c', multigrapher->y_axis.label);
- }
- }
-
-
- pl_flushpl_r (multigrapher->plotter);
- pl_restorestate_r (multigrapher->plotter);
- if (multigrapher->grid_spec != NO_AXES)
- {
- if (!tick_warning_printed &&
- ((!multigrapher->x_axis.omit_ticks && multigrapher->x_axis.labelled_ticks <= 2)
- || (!multigrapher->y_axis.omit_ticks && multigrapher->y_axis.labelled_ticks <= 2)))
- {
- fprintf (stderr,
- "%s: the tick spacing is adjusted, as there were too few labelled axis ticks\n",
- progname);
- tick_warning_printed = true;
- }
- }
- }
- static void
- plot_abscissa_log_subsubtick (Multigrapher *multigrapher, double xval)
- {
- double xrange = multigrapher->x_trans.input_max - multigrapher->x_trans.input_min;
-
- char labelbuf[2048];
- double tick_size = SS(multigrapher->tick_size);
- double subsubtick_size = SS(multigrapher->subtick_size);
-
- pl_fontname_r (multigrapher->plotter, multigrapher->x_axis.font_name);
- pl_ffontsize_r (multigrapher->plotter, SS(multigrapher->x_axis.font_size));
-
- if (xval < multigrapher->x_trans.input_min - FUZZ * xrange
- || xval > multigrapher->x_trans.input_max + FUZZ * xrange)
- return;
-
- if (multigrapher->x_axis.user_specified_subsubticks)
- {
- print_tick_label (labelbuf,
- &multigrapher->x_axis, &multigrapher->x_trans,
- pow (10.0, xval));
- if (!multigrapher->y_axis.switch_axis_end)
- {
- pl_fmove_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.other_axis_loc)
- - ((tick_size >= 0 ? 0.75 : 1.75)
- * fabs((double)tick_size)
- + multigrapher->half_line_width));
- pl_alabel_r (multigrapher->plotter, 'c', 't', labelbuf);
- multigrapher->x_axis.labelled_ticks++;
- }
- else
- {
- pl_fmove_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.alt_other_axis_loc)
- + ((tick_size >= 0 ? 0.75 : 1.75)
- * fabs((double)tick_size)
- + multigrapher->half_line_width));
- pl_alabel_r (multigrapher->plotter, 'c', 'b', labelbuf);
- multigrapher->x_axis.labelled_ticks++;
- }
- }
-
- switch (multigrapher->grid_spec)
- {
- case AXES_AND_BOX_AND_GRID:
- pl_linemod_r (multigrapher->plotter, "dotted");
- pl_fmove_r (multigrapher->plotter, XV (xval), YP(YSQ(0.0)));
- pl_fcont_r (multigrapher->plotter, XV (xval), YP(YSQ(1.0)));
- pl_linemod_r (multigrapher->plotter, "solid");
-
- case AXES_AND_BOX:
- case BOX:
- if (!multigrapher->y_axis.switch_axis_end)
- {
- pl_fmove_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.alt_other_axis_loc));
- pl_fcont_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.alt_other_axis_loc)
- - (subsubtick_size
- + (subsubtick_size > 0.0
- ? multigrapher->half_line_width
- : -multigrapher->half_line_width)));
- }
- else
- {
- pl_fmove_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.other_axis_loc));
- pl_fcont_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.other_axis_loc)
- + (subsubtick_size
- + (subsubtick_size > 0.0
- ? multigrapher->half_line_width
- : -multigrapher->half_line_width)));
- }
-
- case AXES:
- case AXES_AT_ORIGIN:
- if (!multigrapher->y_axis.switch_axis_end)
- {
- pl_fmove_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.other_axis_loc));
- pl_fcont_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.other_axis_loc)
- + (subsubtick_size
- + (subsubtick_size > 0.0
- ? multigrapher->half_line_width
- : -multigrapher->half_line_width)));
- }
- else
- {
- pl_fmove_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.alt_other_axis_loc));
- pl_fcont_r (multigrapher->plotter,
- XV (xval),
- YN (multigrapher->y_axis.alt_other_axis_loc)
- - (subsubtick_size
- + (subsubtick_size > 0.0
- ? multigrapher->half_line_width
- : -multigrapher->half_line_width)));
- }
- break;
- default:
- break;
- }
- }
- static void
- plot_ordinate_log_subsubtick (Multigrapher *multigrapher, double yval)
- {
- double yrange = multigrapher->y_trans.input_max - multigrapher->y_trans.input_min;
-
- char labelbuf[2048];
- double tick_size = SS(multigrapher->tick_size);
- double subsubtick_size = SS(multigrapher->subtick_size);
-
- pl_fontname_r (multigrapher->plotter, multigrapher->y_axis.font_name);
- pl_ffontsize_r (multigrapher->plotter, SS(multigrapher->y_axis.font_size));
-
- if (yval < multigrapher->y_trans.input_min - FUZZ * yrange
- || yval > multigrapher->y_trans.input_max + FUZZ * yrange)
- return;
-
- if (multigrapher->y_axis.user_specified_subsubticks)
- {
- double new_width;
- print_tick_label (labelbuf,
- &multigrapher->y_axis, &multigrapher->y_trans,
- pow (10.0, yval));
- if (!multigrapher->x_axis.switch_axis_end)
- {
- pl_fmove_r (multigrapher->plotter,
- XN(multigrapher->x_axis.other_axis_loc)
- - ((tick_size >= 0 ? 0.75 : 1.75)
- * fabs((double)tick_size)
- + multigrapher->half_line_width),
- YV (yval));
- new_width = pl_flabelwidth_r (multigrapher->plotter, labelbuf);
- pl_alabel_r (multigrapher->plotter, 'r', 'c', labelbuf);
- multigrapher->y_axis.max_label_width = DMAX(multigrapher->y_axis.max_label_width, new_width);
- multigrapher->y_axis.labelled_ticks++;
- }
- else
- {
- pl_fmove_r (multigrapher->plotter,
- XN(multigrapher->x_axis.alt_other_axis_loc)
- + ((tick_size >= 0 ? 0.75 : 1.75)
- * fabs((double)tick_size)
- + multigrapher->half_line_width),
- YV (yval));
- new_width = pl_flabelwidth_r (multigrapher->plotter, labelbuf);
- pl_alabel_r (multigrapher->plotter, 'l', 'c', labelbuf);
- multigrapher->y_axis.max_label_width = DMAX(multigrapher->y_axis.max_label_width, new_width);
- multigrapher->y_axis.labelled_ticks++;
- }
- }
-
- switch (multigrapher->grid_spec)
- {
- case AXES_AND_BOX_AND_GRID:
- pl_linemod_r (multigrapher->plotter, "dotted");
- pl_fmove_r (multigrapher->plotter, XP(XSQ(0.0)), YV (yval));
- pl_fcont_r (multigrapher->plotter, XP(XSQ(1.0)), YV (yval));
- pl_linemod_r (multigrapher->plotter, "solid");
-
- case AXES_AND_BOX:
- case BOX:
- if (!multigrapher->x_axis.switch_axis_end)
- {
- pl_fmove_r (multigrapher->plotter,
- XN (multigrapher->x_axis.alt_other_axis_loc),
- YV (yval));
- pl_fcont_r (multigrapher->plotter,
- XN (multigrapher->x_axis.alt_other_axis_loc)
- - (subsubtick_size
- + (subsubtick_size > 0.0
- ? multigrapher->half_line_width
- : -multigrapher->half_line_width)),
- YV (yval));
- }
- else
- {
- pl_fmove_r (multigrapher->plotter,
- XN (multigrapher->x_axis.other_axis_loc),
- YV (yval));
- pl_fcont_r (multigrapher->plotter,
- XN (multigrapher->x_axis.other_axis_loc)
- + (subsubtick_size
- + (subsubtick_size > 0.0
- ? multigrapher->half_line_width
- : -multigrapher->half_line_width)),
- YV (yval));
- }
-
- case AXES:
- case AXES_AT_ORIGIN:
- if (!multigrapher->x_axis.switch_axis_end)
- {
- pl_fmove_r (multigrapher->plotter,
- XN (multigrapher->x_axis.other_axis_loc),
- YV (yval));
- pl_fcont_r (multigrapher->plotter,
- XN (multigrapher->x_axis.other_axis_loc)
- + (subsubtick_size
- + (subsubtick_size > 0.0
- ? multigrapher->half_line_width
- : -multigrapher->half_line_width)),
- YV (yval));
- }
- else
- {
- pl_fmove_r (multigrapher->plotter,
- XN (multigrapher->x_axis.alt_other_axis_loc),
- YV (yval));
- pl_fcont_r (multigrapher->plotter,
- XN (multigrapher->x_axis.alt_other_axis_loc)
- - (subsubtick_size
- + (multigrapher->tick_size > 0.0
- ? multigrapher->half_line_width
- : -multigrapher->half_line_width)),
- YV (yval));
- }
- break;
- default:
- break;
- }
- }
- static void
- set_line_style (Multigrapher *multigrapher, int style, const char *line_color,
- bool use_color)
- {
- if (!use_color)
- {
- if (style > 0)
-
- {
- int i;
- i = (style - 1) % NO_OF_LINEMODES;
- pl_linemod_r (multigrapher->plotter, linemodes[i]);
- }
-
- pl_colorname_r (multigrapher->plotter, multigrapher->frame_color);
- }
- else
- {
- int i, j;
- if (style > 0)
- {
- if (line_color && line_color[0])
- i = (style - 1) % NO_OF_LINEMODES;
- else
- {
- i = ((style - 1) / NO_OF_LINEMODES) % NO_OF_LINEMODES;
- j = (style - 1) % NO_OF_LINEMODES;
- }
- pl_linemod_r (multigrapher->plotter, linemodes[i]);
- }
- else if (style == 0)
-
- j = 0;
- else
- j = (-style - 1) % (NO_OF_LINEMODES - 1);
- pl_colorname_r (multigrapher->plotter,
- line_color && line_color[0] ? line_color
- : colorstyle[j]);
- }
- }
- void
- plot_point_array (Multigrapher *multigrapher, const Point *p, int length)
- {
- int index;
- for (index = 0; index < length; index++)
- plot_point (multigrapher, &(p[index]));
- }
- void
- plot_legend (Multigrapher *multigrapher, Legend *legends, int length, double x, double y, double font_size)
- {
- if (length==0)
- return;
- pl_savestate_r (multigrapher->plotter);
- pl_fontname_r (multigrapher->plotter, multigrapher->x_axis.font_name);
- font_size = pl_ffontsize_r (multigrapher->plotter, SS(font_size));
- double legend_width = 0.;
- int i;
- for (i=0; i!=length; ++i)
- legend_width = fmax(legend_width, pl_flabelwidth_r(multigrapher->plotter, legends[i].label));
- double posx1 = XP(XSQ(1.0)) - legend_width - font_size*0.5;
- double posx0 = XP(XSQ(0.0)) + font_size*4.0;
- x = x * posx1 + (1-x) * posx0;
- double posy1 = YP(YSQ(1.0)) - font_size*1.0;
- double posy0 = YP(YSQ(0.0)) + font_size*length;
- y = y * posy1 + (1-y) * posy0;
- double xunscale = 1/(XV (1.) - XV (0.));
- double yunscale = 1/(YV (1.) - YV (0.));
- double dimx = font_size * xunscale;
- pl_savestate_r (multigrapher->plotter);
-
- if (pl_havecap_r (multigrapher->plotter, "SETTABLE_BACKGROUND") != 0
- && multigrapher->bg_color)
- pl_colorname_r (multigrapher->plotter, multigrapher->bg_color);
- else
- pl_colorname_r (multigrapher->plotter, "white");
- pl_filltype_r (multigrapher->plotter, 1);
- pl_fbox_r (multigrapher->plotter,
- x - 3.5*dimx - 0.25*font_size
- - 2.5*dimx ,
- y - font_size*(length-0.25),
- x + legend_width + font_size*0.25,
- y + font_size*0.5);
- pl_restorestate_r (multigrapher->plotter);
- for (i=0; i!=length; ++i)
- {
- Point *p = &(legends[i].point);
- double ystep = -(i * font_size);
- int symbol = p->symbol;
- if (p->linemode > 0)
- {
- p->y = YVI(y) + ystep*yunscale;
- p->pendown = false;
- p->symbol = 0;
- p->x = XVI(x) - 3.5*dimx;
- plot_point (multigrapher, p);
- p->pendown = true;
- p->symbol = symbol;
- p->x = XVI(x) - 2*dimx;
- plot_point (multigrapher, p);
- p->x = XVI(x) - 0.5*dimx;
- p->symbol = 0;
- plot_point (multigrapher, p);
- p->pendown = false;
- }
- else
- {
- p->y = YVI(y) + ystep*yunscale;
- p->pendown = false;
- p->symbol = 0;
- if (p->linemode == 0)
- p->linemode = -1;
- p->x = XVI(x) - 1.0*dimx;
- plot_point (multigrapher, p);
- p->pendown = true;
- p->symbol = symbol;
- plot_point (multigrapher, p);
- p->pendown = false;
- }
- pl_fmove_r (multigrapher->plotter, x, y+ystep);
- pl_colorname_r (multigrapher->plotter, "black");
- pl_alabel_r (multigrapher->plotter, 'l', 'c', legends[i].label);
- }
- pl_restorestate_r (multigrapher->plotter);
- }
- void
- plot_point (Multigrapher *multigrapher, const Point *point)
- {
- double local_x0, local_y0, local_x1, local_y1;
- int clipval;
-
- if (!(point->pendown) || multigrapher->first_point_of_polyline)
- {
- int intfill;
- set_line_style (multigrapher, point->linemode, point->line_color,
- point->use_color);
-
- pl_flinewidth_r (multigrapher->plotter,
- point->line_width * (double)PLOT_SIZE);
- if (point->fill_fraction < 0.0)
- intfill = 0;
- else
- intfill = 1 + IROUND((1.0 - point->fill_fraction) * 0xfffe);
- pl_filltype_r (multigrapher->plotter, intfill);
- }
-
- if (multigrapher->first_point_of_polyline)
- {
- local_x0 = point->x;
- local_y0 = point->y;
- }
- else
- {
- local_x0 = multigrapher->oldpoint_x;
- local_y0 = multigrapher->oldpoint_y;
- }
- local_x1 = point->x;
- local_y1 = point->y;
-
- multigrapher->oldpoint_x = point->x;
- multigrapher->oldpoint_y = point->y;
-
- clipval = clip_line (multigrapher,
- &local_x0, &local_y0, &local_x1, &local_y1);
- if (!(clipval & ACCEPTED))
- {
- pl_fmove_r (multigrapher->plotter,
- XV (point->x), YV (point->y));
- multigrapher->first_point_of_polyline = false;
- return;
- }
-
- if (point->pendown && (point->linemode > 0))
- {
- switch (multigrapher->clip_mode)
- {
- case 0:
- if ((clipval & CLIPPED_FIRST) || (clipval & CLIPPED_SECOND))
-
- pl_fmove_r (multigrapher->plotter, XV (point->x), YV (point->y));
- else
-
- {
- if (!multigrapher->first_point_of_polyline)
- pl_fcont_r (multigrapher->plotter,
- XV (point->x), YV (point->y));
- else
- pl_fmove_r (multigrapher->plotter,
- XV (point->x), YV (point->y));
- }
- break;
- case 1:
- default:
- if ((clipval & CLIPPED_FIRST) && (clipval & CLIPPED_SECOND))
-
- pl_fmove_r (multigrapher->plotter, XV (point->x), YV (point->y));
- else
-
- {
- if (clipval & CLIPPED_FIRST)
- {
- if (!multigrapher->first_point_of_polyline)
- {
-
- pl_fmove_r (multigrapher->plotter,
- XV (local_x0), YV (local_y0));
- pl_fcont_r (multigrapher->plotter,
- XV (point->x), YV (point->y));
- }
- else
- pl_fmove_r (multigrapher->plotter,
- XV (point->x), YV (point->y));
- }
- else
- {
- if (!multigrapher->first_point_of_polyline)
- {
-
- pl_fcont_r (multigrapher->plotter,
- XV (local_x1), YV (local_y1));
-
- }
- else
- pl_fmove_r (multigrapher->plotter,
- XV (point->x), YV (point->y));
- }
- }
- break;
- case 2:
- if ((clipval & CLIPPED_FIRST) || multigrapher->first_point_of_polyline)
-
- pl_fmove_r (multigrapher->plotter, XV (local_x0), YV (local_y0));
-
- pl_fcont_r (multigrapher->plotter, XV (local_x1), YV (local_y1));
- if (clipval & CLIPPED_SECOND)
-
- pl_fmove_r (multigrapher->plotter, XV (point->x), YV (point->y));
- break;
- }
- }
- else
- pl_fmove_r (multigrapher->plotter, XV (point->x), YV (point->y));
- multigrapher->first_point_of_polyline = false;
-
- if (clipval & CLIPPED_SECOND)
- return;
-
- if (point->symbol >= 32)
- {
-
- pl_savestate_r (multigrapher->plotter);
- plot_errorbar (multigrapher, point);
- pl_fontname_r (multigrapher->plotter, point->symbol_font_name);
- pl_fmarker_r (multigrapher->plotter, XV(point->x), YV(point->y),
- point->symbol, SS(point->symbol_size));
- pl_restorestate_r (multigrapher->plotter);
- }
- else if (point->symbol > 0)
- {
- if (point->linemode > 0)
-
- {
- pl_savestate_r (multigrapher->plotter);
- plot_errorbar (multigrapher, point);
- pl_fmarker_r (multigrapher->plotter, XV(point->x), YV(point->y),
- point->symbol, SS(point->symbol_size));
- pl_restorestate_r (multigrapher->plotter);
- }
- else
-
- {
- plot_errorbar (multigrapher, point);
- pl_fmarker_r (multigrapher->plotter, XV(point->x), YV(point->y),
- point->symbol, SS(point->symbol_size));
- }
- }
- else if (point->symbol == 0 && point->linemode == 0)
-
- {
- plot_errorbar (multigrapher, point);
- pl_fmarker_r (multigrapher->plotter,
- XV(point->x), YV(point->y), M_DOT, SS(point->symbol_size));
- }
- else
- plot_errorbar (multigrapher, point);
- return;
- }
- static int
- clip_line (Multigrapher *multigrapher, double *x0_p, double *y0_p, double *x1_p, double *y1_p)
- {
- double x0 = *x0_p;
- double y0 = *y0_p;
- double x1 = *x1_p;
- double y1 = *y1_p;
- outcode outcode0 = compute_outcode (multigrapher, x0, y0, true);
- outcode outcode1 = compute_outcode (multigrapher, x1, y1, true);
- bool accepted;
- int clipval = 0;
- for ( ; ; )
- {
- if (!(outcode0 | outcode1))
- {
- accepted = true;
- break;
- }
- else if (outcode0 & outcode1)
- {
- accepted = false;
- break;
- }
- else
- {
-
- outcode outcode_out = (outcode0 ? outcode0 : outcode1);
- double x, y;
- if (outcode_out & RIGHT)
- {
- x = multigrapher->x_trans.input_max;
- y = isinf (x0) ? y1 : y0 + (y1 - y0) * (x - x0) / (x1 - x0);
- }
- else if (outcode_out & LEFT)
- {
- x = multigrapher->x_trans.input_min;
- y = isinf (x0) ? y1 : y0 + (y1 - y0) * (x - x0) / (x1 - x0);
- }
- else if (outcode_out & TOP)
- {
- y = multigrapher->y_trans.input_max;
- x = isinf (y0) ? x1 : x0 + (x1 - x0) * (y - y0) / (y1 - y0);
- }
- else
- {
- y = multigrapher->y_trans.input_min;
- x = isinf (y0) ? x1 : x0 + (x1 - x0) * (y - y0) / (y1 - y0);
- }
- if (outcode_out == outcode0)
- {
- x0 = x;
- y0 = y;
- outcode0 = compute_outcode (multigrapher, x0, y0, true);
- }
- else
- {
- x1 = x;
- y1 = y;
- outcode1 = compute_outcode (multigrapher, x1, y1, true);
- }
- }
- }
- if (accepted)
- {
- clipval |= ACCEPTED;
- if ((x0 != *x0_p) || (y0 != *y0_p))
- clipval |= CLIPPED_FIRST;
- if ((x1 != *x1_p) || (y1 != *y1_p))
- clipval |= CLIPPED_SECOND;
- *x0_p = x0;
- *y0_p = y0;
- *x1_p = x1;
- *y1_p = y1;
- }
- return clipval;
- }
- static outcode
- compute_outcode (Multigrapher *multigrapher, double x, double y, bool tolerant)
- {
- outcode code = 0;
- double xfuzz = FUZZ * multigrapher->x_trans.input_range;
- double yfuzz = FUZZ * multigrapher->y_trans.input_range;
- int sign = (tolerant == true ? 1 : -1);
- if (x > multigrapher->x_trans.input_max + sign * xfuzz)
- code |= RIGHT;
- else if (x < multigrapher->x_trans.input_min - sign * xfuzz)
- code |= LEFT;
- if (y > multigrapher->y_trans.input_max + sign * yfuzz)
- code |= TOP;
- else if (y < multigrapher->y_trans.input_min - sign * yfuzz)
- code |= BOTTOM;
- return code;
- }
- static void
- transpose_portmanteau (int *val)
- {
- bool xtrue, ytrue;
- int newval;
- xtrue = ((*val & X_AXIS) ? true : false);
- ytrue = ((*val & Y_AXIS) ? true : false);
- newval = (xtrue ? Y_AXIS : 0) | (ytrue ? X_AXIS : 0);
- *val = newval;
- }
- static void
- plot_errorbar (Multigrapher *multigrapher, const Point *p)
- {
- if (p->have_x_errorbar || p->have_y_errorbar)
-
- {
- pl_savestate_r (multigrapher->plotter);
- pl_linemod_r (multigrapher->plotter, "solid");
- if (p->have_x_errorbar)
- {
- pl_fline_r (multigrapher->plotter,
- XV(p->xmin), YV(p->y) - 0.5 * SS(p->symbol_size),
- XV(p->xmin), YV(p->y) + 0.5 * SS(p->symbol_size));
- pl_fline_r (multigrapher->plotter,
- XV(p->xmin), YV(p->y), XV(p->xmax), YV(p->y));
- pl_fline_r (multigrapher->plotter,
- XV(p->xmax), YV(p->y) - 0.5 * SS(p->symbol_size),
- XV(p->xmax), YV(p->y) + 0.5 * SS(p->symbol_size));
- }
- if (p->have_y_errorbar)
- {
- pl_fline_r (multigrapher->plotter,
- XV(p->x) - 0.5 * SS(p->symbol_size), YV(p->ymin),
- XV(p->x) + 0.5 * SS(p->symbol_size), YV(p->ymin));
- pl_fline_r (multigrapher->plotter,
- XV(p->x), YV(p->ymin), XV(p->x), YV(p->ymax));
- pl_fline_r (multigrapher->plotter,
- XV(p->x) - 0.5 * SS(p->symbol_size), YV(p->ymax),
- XV(p->x) + 0.5 * SS(p->symbol_size), YV(p->ymax));
- }
- pl_restorestate_r (multigrapher->plotter);
- }
- }
- void
- end_polyline_and_flush (Multigrapher *multigrapher)
- {
- pl_endpath_r (multigrapher->plotter);
- pl_flushpl_r (multigrapher->plotter);
- multigrapher->first_point_of_polyline = true;
- }
|