tick_labels Subroutine

public subroutine tick_labels(wx1, wx2, wy1, wy2, xstep, ystep, xlim, dry, crowded)

Write tick labels of giza_box option 'N', minus any that would clip.

Strings and placement match giza_box. Drops x labels past left page edge or page fraction xlim, x labels within one character height of previous (sets crowded), and y labels whose along-axis text would run into an x label.

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(in) :: wx1

Left window edge, in world coords.

real(kind=real64), intent(in) :: wx2

Right window edge, in world coords.

real(kind=real64), intent(in) :: wy1

Bottom window edge, in world coords.

real(kind=real64), intent(in) :: wy2

Top window edge, in world coords.

real(kind=real64), intent(in) :: xstep

x tick step, unused on log axis.

real(kind=real64), intent(in) :: ystep

y tick step, unused on log axis.

real(kind=real64), intent(in) :: xlim

Right limit of x labels, as fraction of page width.

logical, intent(in) :: dry

Only test x labels for crowding, writing nothing.

logical, intent(out) :: crowded

An x label was dropped for sitting too close to previous one.


Source Code

   subroutine tick_labels(wx1, wx2, wy1, wy2, xstep, ystep, xlim, dry, crowded)
      !! Write tick labels of `giza_box` option 'N', minus any that would clip.
      !!
      !! Strings and placement match `giza_box`. Drops x labels past left page edge or page fraction
      !! `xlim`, x labels within one character height of previous (sets `crowded`), and y labels
      !! whose along-axis text would run into an x label.
      ! Arguments
      real(real64), intent(in) :: wx1
         !! Left window edge, in world coords.
      real(real64), intent(in) :: wx2
         !! Right window edge, in world coords.
      real(real64), intent(in) :: wy1
         !! Bottom window edge, in world coords.
      real(real64), intent(in) :: wy2
         !! Top window edge, in world coords.
      real(real64), intent(in) :: xstep
         !! x tick step, unused on log axis.
      real(real64), intent(in) :: ystep
         !! y tick step, unused on log axis.
      real(real64), intent(in) :: xlim
         !! Right limit of x labels, as fraction of page width.
      logical, intent(in) :: dry
         !! Only test x labels for crowding, writing nothing.
      logical, intent(out) :: crowded
         !! An x label was dropped for sitting too close to previous one.
      integer(int32), parameter :: NBOX = 64
      real(real64) :: px1, px2, py1, py2, nx1, nx2, ny1, ny2, cw, ch, lo, hi, last
      real(real64) :: bx(4, NBOX)        ! kept x label boxes, mm: x1 x2 y1 y2
      integer(int32) :: nb
      character(len=32) :: txt

      call giza_get_viewport(giza_units_mm, px1, px2, py1, py2)
      call giza_get_viewport(giza_units_normalized, nx1, nx2, ny1, ny2)
      call giza_get_character_size(giza_units_mm, cw, ch)
      lo = px1 - nx1*(px2 - px1)/(nx2 - nx1)
      hi = px1 + (xlim - nx1)*(px2 - px1)/(nx2 - nx1)
      crowded = .false.; nb = 0; last = -huge(1.d0)
      call axis(.true., wx1, wx2, xstep, st%xlog)
      if (.not. dry) call axis(.false., wy1, wy2, ystep, st%ylog)
   contains
      subroutine axis(isx, w1, w2, step, logax)
         !! Put label candidates of one axis, ascending.
         !!
         !! Log axis labels each decade, plus 2 and 5 times each decade when it spans under two
         !! decades.
         ! Arguments
         logical, intent(in) :: isx
            !! x axis, else y axis.
         real(real64), intent(in) :: w1
            !! Lower window edge on this axis, in world coords.
         real(real64), intent(in) :: w2
            !! Upper window edge on this axis, in world coords.
         real(real64), intent(in) :: step
            !! Tick step, unused on log axis.
         logical, intent(in) :: logax
            !! Axis is logarithmic.
         integer(int32), parameter :: MANT(2) = [2, 5]
         integer(int32) :: i, k, np, nv
         if (logax) then
            do i = nint(w1) - 1, nint(w2)
               select case (i)
               case (0); txt = '1'
               case (1); txt = '10'
               case default; write (txt, '(a,i0,a)') '10^{', i, '}'
               end select
               call put(isx, (real(i, real64) - w1)/(w2 - w1))
               if (w2 - w1 >= 2.d0) cycle
               do k = 1, 2
                  call giza_format_number(MANT(k), i, giza_number_format_auto, txt)
                  call put(isx, (i + log10(real(MANT(k), real64)) - w1)/(w2 - w1))
               end do
            end do
         else
            np = floor(log10(step)); nv = nint(step/10.d0**np)
            do i = nint(w1/step), nint(w2/step)
               call giza_format_number(i*nv, np, giza_number_format_auto, txt)
               call put(isx, (i*step - w1)/(w2 - w1))
            end do
         end if
      end subroutine axis

      subroutine put(isx, ratio)
         !! Write label `txt` at one point of an axis, unless it would clip.
         !!
         !! As `giza_box`: x labels 1.2, y labels 0.7 character heights out from axis, centred on
         !! tick, y labels along axis.
         ! Arguments
         logical, intent(in) :: isx
            !! x axis, else y axis.
         real(real64), intent(in) :: ratio
            !! Position along axis, 0 at lower window edge, 1 at upper.
         real(real64) :: w, h, c, b(4)
         integer(int32) :: k
         if (ratio < 0.d0 .or. ratio > 1.d0) return
         call giza_qtextlen(giza_units_mm, trim(txt), w, h)
         if (isx) then
            c = px1 + ratio*(px2 - px1)
            b = [c - 0.5d0*w, c + 0.5d0*w, py1 - 1.2d0*ch, py1 - 1.2d0*ch + h]
            if (b(1) < last + ch) then
               crowded = .true.
               return
            end if
            if (b(1) < lo .or. b(2) > hi) return
            last = b(2)
            if (nb < NBOX) then
               nb = nb + 1
               bx(:, nb) = b
            end if
            if (.not. dry) call giza_annotate('B', 1.2, real(ratio), 0.5, trim(txt))
         else
            c = py1 + ratio*(py2 - py1)
            b = [px1 - 0.7d0*ch - h, px1 - 0.7d0*ch, c - 0.5d0*w, c + 0.5d0*w]
            do k = 1, nb
               if (b(1) < bx(2, k) .and. bx(1, k) < b(2) .and. &
                   b(3) < bx(4, k) .and. bx(3, k) < b(4)) return
            end do
            call giza_annotate('L', 0.7, real(ratio), 0.5, trim(txt))
         end if
      end subroutine put
   end subroutine tick_labels