Back to index

plt-scheme  4.2.1
Defines | Functions
pldtik.c File Reference
#include "plplotP.h"

Go to the source code of this file.

Defines

#define MIN_FLTDIG   3 /* disregarded if fractional part is 0 */
#define MAX_FIXDIG_POS   6
#define MAX_FIXDIG_NEG   4
#define DIGMAX_DEF   5

Functions

void pldtik (PLFLT vmin, PLFLT vmax, PLFLT *tick, PLINT *nsubt)
void pldprec (PLFLT vmin, PLFLT vmax, PLFLT tick, PLINT lf, PLINT *mode, PLINT *prec, PLINT digmax, PLINT *scale)

Define Documentation

#define DIGMAX_DEF   5

Definition at line 113 of file pldtik.c.

#define MAX_FIXDIG_NEG   4

Definition at line 112 of file pldtik.c.

#define MAX_FIXDIG_POS   6

Definition at line 111 of file pldtik.c.

#define MIN_FLTDIG   3 /* disregarded if fractional part is 0 */

Definition at line 110 of file pldtik.c.


Function Documentation

void pldprec ( PLFLT  vmin,
PLFLT  vmax,
PLFLT  tick,
PLINT  lf,
PLINT mode,
PLINT prec,
PLINT  digmax,
PLINT scale 
)

Definition at line 116 of file pldtik.c.

{
    PLFLT chosen, notchosen, vmod, t0;
    PLINT msd, notmsd, np, digmin, digfix;

    *mode = 0;
    *scale = 0;

    if (digmax == 0)
       digmax = DIGMAX_DEF;

/* Choose vmin or vmax depending on magnitudes of vmin and vmax. */
    chosen = (ABS(vmax) >= ABS(vmin))? vmax: vmin;
    notchosen = (ABS(vmax) >= ABS(vmin))? vmin: vmax;
/* Magnitute of chosen to get number of significant digits */

    if(ABS(chosen) > 0.) {
        vmod = ABS(chosen);
        t0 = (PLFLT) log10(vmod);
        msd = (PLINT) floor(t0);
    }
    else {
/* this branch occurs only when 0. --- 0. range put in */
        vmod = 1.;
        t0 = (PLFLT) log10(vmod);
        msd = (PLINT) floor(t0);
    }
        
    if(ABS(notchosen) > 0.)
       notmsd = (PLINT) floor( (PLFLT) log10(ABS(notchosen)));
    else
       notmsd = msd;
/* Autoselect the mode flag */
/* 'digmin' is the minimum number of places taken up by the label */

    if (msd >= 0) {
/* n.b. no decimal point in the minimal case  */
       digmin = msd + 1;
       digfix = MAX_FIXDIG_POS;
       if (digmax > 0)
           digfix = MIN(digmax, MAX_FIXDIG_POS);
    }
    else {
/* adjust digmin to account for leading 0 and decimal point */
       digmin = -msd + 2;
       digfix = MAX_FIXDIG_NEG;
       if (digmax > 0)
           digfix = MIN(digmax, MAX_FIXDIG_NEG);
    }
/* adjust digmin to account for sign on the chosen end of axis or sign on the 
 * nonchosen end of axis if notmsd = msd or (msd <= 0 and notmsd < 0)
 * For the latter case the notchosen label starts with "-0."
 * For checking for the latter case, the notmsd < 0 condition is redundant
 * since notmsd <= msd always and the equal part is selected by the first
 * condition.
 */
    if(chosen < 0.||(notchosen < 0. && (notmsd == msd || msd <= 0)))
        digmin = digmin + 1;

    if (digmin > digfix && !lf) {
       *mode = 1;
       *scale = msd;
    }

/* Establish precision.  */
/* It must be fine enough to resolve the tick spacing */

    np = (PLINT) floor(log10(ABS(tick)));

    if (*mode != 0)
       *prec = msd - np;
    else
       *prec = MAX(-np, 0);

/* One last hack required: if exponent < 0, i.e. number has leading '0.',
 * it's better to change to floating point form if the number of digits
 * is insufficient to represent the tick spacing.
*/
    if (*mode == 0 && digmax > 0 && !lf) {
       if (t0 < 0.0) {
           if (digmax - 2 - *prec < 0) {
              *mode = 1;
              *scale = msd;
           }
       }
       else
           *prec = MAX(MIN(*prec, digmax - msd - 1), 0);
    }
    if (*mode != 0) {
       *prec = msd - np;
       *prec = MAX(MIN(*prec, MAX(digmax-1, MIN_FLTDIG)), 0);
    }
}

Here is the caller graph for this function:

void pldtik ( PLFLT  vmin,
PLFLT  vmax,
PLFLT tick,
PLINT nsubt 
)

Definition at line 20 of file pldtik.c.

{
    PLFLT t1, t2, tick_reasonable;
    PLINT np, ns;

/* Magnitude of min/max difference to get tick spacing */

    t1 = (PLFLT) log10(ABS(vmax - vmin));
    np = (PLINT) floor(t1);
    t1 = t1 - np;

/* Get tick spacing. */

    if (t1 > 0.7781512503) {
       t2 = 2.0;
       ns = 4;
    }
    else if (t1 > 0.4771212549) {
       t2 = 1.0;
       ns = 5;
    }
    else if (t1 > 0.1760912591) {
       t2 = 5.0;
       ns = 5;
       np = np - 1;
    }
    else {
       t2 = 2.0;
       ns = 4;
       np = np - 1;
    }

/* Now compute reasonable tick spacing */

    tick_reasonable = t2 * pow(10.0, (double) np);
    if (*tick == 0) {
       *tick = t2 * pow(10.0, (double) np);
    }
    else {
        *tick = ABS(*tick);
        if(*tick < 1.e-4*tick_reasonable) {
          plexit("pldtik: magnitude of specified tick spacing is much too small");
          return;
       }
    }
    if (*nsubt == 0)
       *nsubt = ns;

    *nsubt = ABS(*nsubt);
}

Here is the call graph for this function:

Here is the caller graph for this function: