Skip to content

foresight_ticks ​

foresight_ticks, axis tick placement and labelling.

Linear axes use the "nice numbers" rule (Heckbert, Graphics Gems, 1990): the step is rounded to m * 10**e with m in {1, 2, 5}. Log axes place majors at integer decades. Tick values are carried as the integer pair (n, e) meaning n * 10**e, so labels are exact decimal strings, free of floating point noise such as 0.30000000000000004.

User settings (tics_object, gnuplot set xtics and set format) replace the automatic rule: a fixed step from an optional start to an optional end (a multiplying factor on log axes), no ticks at all, or a printf-like label format. Fixed steps are kept as the decimal text the user wrote, so linear ticks stay exact decimals too.

The same rules are mirrored by the interactive viewer, which must regenerate identical ticks after a zoom.

Source: src/lib/foresight_ticks.F90

Dependencies

Contents ​

Variables ​

NameTypeAttributesDescription
TICS_AUTOinteger(kind=I4P)parameterTicks by the automatic rule.
TICS_FIXEDinteger(kind=I4P)parameterTicks at a fixed step.
TICS_NONEinteger(kind=I4P)parameterNo ticks.
TOLreal(kind=R8P)parameterTolerance on tick-grid membership, in units of the step.
TICK_SPACINGreal(kind=R8P)parameterTarget distance between major ticks [px].
SCI_HIGHreal(kind=R8P)parameterLabels switch to scientific notation from this magnitude...
SCI_LOWreal(kind=R8P)parameter...or below this one.
MAX_TICKSinteger(kind=I8P)parameterTick count cap: no ticks beyond it (degenerate or extreme zoom).
MAX_POWERinteger(kind=I8P)parameterLargest power of a fixed log step: no ticks beyond it.

Derived Types ​

tick_object ​

Axis tick.

Components ​

NameTypeAttributesDescription
valuereal(kind=R8P)Data value.
majorlogicalMajor (labelled) tick, else minor.
labelcharacter(len=:)allocatableLabel text, empty for minor ticks.
supcharacter(len=:)allocatableSuperscript appended to the label, empty if none.

tics_object ​

User tick settings of an axis, gnuplot set xtics and set format.

Components ​

NameTypeAttributesDescription
modeinteger(kind=I4P)TICS_AUTO, TICS_FIXED or TICS_NONE.
startcharacter(len=:)allocatableFixed ticks start (decimal text), empty for none.
stepcharacter(len=:)allocatableFixed ticks step, a factor on log axes (decimal text).
endcharacter(len=:)allocatableFixed ticks end (decimal text), empty for none.
formatcharacter(len=:)allocatableLabel format, empty for the default labels.
mirrorlogicalTicks also on the opposite border, gnuplot mirror.

Type-Bound Procedures ​

NameAttributesDescription
attributepass(self)Viewer attribute of the tick positions.
enablepass(self)Turn the ticks on, keeping their positions.
has_formatpass(self)Whether a label format is set.
set_autopass(self)Automatic ticks, forgetting a fixed step.
set_fixedpass(self)Set fixed ticks, validated.

Subroutines ​

enable ​

Turn off ticks on again at their last positions, as gnuplot set xtics without positions: the fixed step if one was set (and not reset by set_auto), else automatic. Ticks already on are unchanged.

Attributes: pure

fortran
subroutine enable(self)

Arguments

NameTypeIntentAttributesDescription
selfclass(tics_object)inoutSettings.

Call graph

set_auto ​

Automatic ticks, as gnuplot set xtics auto: the fixed step is forgotten, so enable restores automatic ones.

Attributes: pure

fortran
subroutine set_auto(self)

Arguments

NameTypeIntentAttributesDescription
selfclass(tics_object)inoutSettings.

Call graph

set_fixed ​

Fixed ticks every step (a factor on log axes) from start to end, given as decimal texts (empty for absent); message is empty on success, else the settings are unchanged.

Attributes: pure

fortran
subroutine set_fixed(self, step, start, end, message)

Arguments

NameTypeIntentAttributesDescription
selfclass(tics_object)inoutSettings.
stepcharacter(len=*)inStep.
startcharacter(len=*)inStart, empty for none.
endcharacter(len=*)inEnd, empty for none.
messagecharacter(len=:)outallocatableProblem, empty if none.

Call graph

nice_step ​

Round raw > 0 to the "nice" step m * 10**e with m in {1, 2, 5}.

Attributes: pure

fortran
subroutine nice_step(raw, m, e)

Arguments

NameTypeIntentAttributesDescription
rawreal(kind=R8P)inRaw step.
minteger(kind=I8P)outStep mantissa.
einteger(kind=I4P)outStep exponent.

Call graph

linear_ticks ​

Major ticks of a linear axis npx pixels long; autoscaled ends are extended outward to the tick grid.

With tics: no ticks and no extension (TICS_NONE), or the fixed grid (TICS_FIXED), and the label format.

Attributes: pure

fortran
subroutine linear_ticks(lo, hi, npx, extend_lo, extend_hi, ticks, tics)

Arguments

NameTypeIntentAttributesDescription
loreal(kind=R8P)inoutValue at the axis start (lo > hi: reversed).
hireal(kind=R8P)inoutValue at the axis end.
npxreal(kind=R8P)inAxis length [px].
extend_lologicalinExtend lo outward to the tick grid.
extend_hilogicalinExtend hi outward to the tick grid.
tickstype(tick_object)outallocatableTicks, ascending in value.
ticstype(tics_object)inoptionalUser settings.

Call graph

log_ticks ​

Ticks of a base-10 log axis npx pixels long; autoscaled ends are extended outward to whole decades.

Majors sit at decades (labelled 10 with the exponent as superscript), minors at 2..9 times a decade when the axis spans at most 10 decades. With fewer than two decades in range the minors are labelled too, in plain decimals; if still fewer than two ticks are labelled (a range inside one decade), linear ticks are placed instead.

With tics: no ticks (TICS_NONE), or ticks multiplying by the step (TICS_FIXED), and the label format; the extension to decades applies anyway, as in gnuplot.

Attributes: pure

fortran
subroutine log_ticks(lo, hi, npx, extend_lo, extend_hi, ticks, tics)

Arguments

NameTypeIntentAttributesDescription
loreal(kind=R8P)inoutValue at the axis start, > 0.
hireal(kind=R8P)inoutValue at the axis end, > 0.
npxreal(kind=R8P)inAxis length [px].
extend_lologicalinExtend lo outward to a decade.
extend_hilogicalinExtend hi outward to a decade.
tickstype(tick_object)outallocatableTicks, majors first.
ticstype(tics_object)inoptionalUser settings.

Call graph

common_scale ​

Rescale the decimals n * 10**e to their smallest exponent, keeping every mantissa below 1e15 (exact in the viewer's double precision integers); ok false if impossible.

Attributes: pure

fortran
subroutine common_scale(n, e, ok)

Arguments

NameTypeIntentAttributesDescription
ninteger(kind=I8P)inoutMantissas.
einteger(kind=I4P)inoutExponents, all equal on exit.
oklogicaloutRescaled.

Call graph

fixed_values ​

Decimals of the fixed ticks at a common exponent: n holds step, start (0 if none) and end mantissas.

Attributes: pure

fortran
subroutine fixed_values(tics, n, e, has_start, has_end)

Arguments

NameTypeIntentAttributesDescription
ticstype(tics_object)inSettings, TICS_FIXED (validated by set_fixed).
ninteger(kind=I8P)outMantissas: step, start, end.
einteger(kind=I4P)outExponents, equal.
has_startlogicaloutStart given.
has_endlogicaloutEnd given.

Call graph

fixed_linear_ticks ​

Ticks at start + k * step within [start, end], as gnuplot set xtics START,STEP,END.

An autoscaled end is extended outward to a multiple of the step, unless it lies outside [start, end] (gnuplot).

Attributes: pure

fortran
subroutine fixed_linear_ticks(lo, hi, extend_lo, extend_hi, tics, ticks)

Arguments

NameTypeIntentAttributesDescription
loreal(kind=R8P)inoutValue at the axis start.
hireal(kind=R8P)inoutValue at the axis end.
extend_lologicalinlo autoscaled.
extend_hilogicalinhi autoscaled.
ticstype(tics_object)inSettings, TICS_FIXED.
tickstype(tick_object)outallocatableTicks, ascending in value.

Call graph

fixed_log_ticks ​

Ticks of a log axis at start * step**k (start 1 if absent) within [start, end], as gnuplot set ytics on a log axis: the step is a factor, greater than 1.

Tick values are built by repeated multiplication, so that the viewer reproduces them exactly.

Attributes: pure

fortran
subroutine fixed_log_ticks(lo, hi, tics, ticks)

Arguments

NameTypeIntentAttributesDescription
loreal(kind=R8P)inValue at the axis start, > 0.
hireal(kind=R8P)inValue at the axis end, > 0.
ticstype(tics_object)inSettings, TICS_FIXED.
tickstype(tick_object)outallocatableTicks, ascending in value.

Call graph

tick_label ​

Label of the tick value n * 10**e: by the user format of tics if any, else by format_label.

Attributes: pure

fortran
subroutine tick_label(n, e, sci, label, sup, tics)

Arguments

NameTypeIntentAttributesDescription
ninteger(kind=I8P)inValue mantissa.
einteger(kind=I4P)inValue exponent.
scilogicalinScientific notation (default labels).
labelcharacter(len=:)outallocatableLabel text.
supcharacter(len=:)outallocatableLabel superscript.
ticstype(tics_object)inoptionalUser settings.

Call graph

format_label ​

Label of the tick value n * 10**e: plain decimal, or gnuplot-like 1.5x10 with the exponent as superscript.

Attributes: pure

fortran
subroutine format_label(n, e, sci, label, sup)

Arguments

NameTypeIntentAttributesDescription
ninteger(kind=I8P)inValue mantissa.
einteger(kind=I4P)inValue exponent.
scilogicalinScientific notation.
labelcharacter(len=:)outallocatableLabel text.
supcharacter(len=:)outallocatableLabel superscript.

Call graph

Functions ​

attribute ​

Tick positions for the viewer: empty for automatic, none, or START STEP END with * for an absent end.

Attributes: pure

Returns: character(len=:)

fortran
function attribute(self) result(text)

Arguments

NameTypeIntentAttributesDescription
selfclass(tics_object)inSettings.

Call graph

labels_attribute ​

Text labels for the viewer: labels then value:label pairs, blank separated, each label percent-encoded (every byte but letters, digits and -._~), so blanks and colons in a label never split it.

Attributes: pure

Returns: character(len=:)

fortran
function labels_attribute(labels) result(text)

Arguments

NameTypeIntentAttributesDescription
labelstype(tick_object)inLabelled values.

Call graph

has_format ​

Whether a label format is set.

Attributes: pure

Returns: logical

fortran
function has_format(self) result(has)

Arguments

NameTypeIntentAttributesDescription
selfclass(tics_object)inSettings.

Call graph

power ​

first * factor**k by |k| multiplications or divisions: the operation sequence the viewer repeats.

Attributes: pure

Returns: real(kind=R8P)

fortran
function power(first, factor, k) result(v)

Arguments

NameTypeIntentAttributesDescription
firstreal(kind=R8P)inStart.
factorreal(kind=R8P)inFactor.
kinteger(kind=I8P)inPower.

Call graph

grid_value ​

Value n * 10**e, correctly rounded for |e| <= 22 (powers of ten are exact there); beyond, scaled in steps of 1e22, the operation sequence the viewer repeats.

Attributes: pure

Returns: real(kind=R8P)

fortran
function grid_value(n, e) result(value)

Arguments

NameTypeIntentAttributesDescription
ninteger(kind=I8P)inMantissa.
einteger(kind=I4P)inExponent.

Call graph

is_scientific ​

Whether labels of an axis reaching magnitude use scientific notation.

Attributes: pure

Returns: logical

fortran
function is_scientific(magnitude) result(sci)

Arguments

NameTypeIntentAttributesDescription
magnitudereal(kind=R8P)inLargest absolute value on the axis.

Call graph