Logo Search packages:      
Sourcecode: ygraph version File versions  Download package

void axis_draw_x_text ( Plot plot  ) 

Draw the labels on the x-axis.

Parameters:
plot The Plot on which the axis is to be displayed.

Definition at line 425 of file axis.c.

References axis_get_text_height(), axis_get_text_width(), _Axis::font, _Axis::gc, _Plot::i_origin, _Plot::j_origin, _Axis::orientation, _Plot::pixmap, _Tick::str, _Axis::ticks, _Tick::val, _Plot::x_axis, and x_to_i().

Referenced by axis_draw().

{
  Axis* axis;
  GArray* ticks;
  Tick* tick;
  guint i;
  gint len;
  gint text_height;
  gint text_width;
  gint text_ip;
  gint text_jp;
  gint tick_ip;
  gint tick_jp;
  gchar* str;
  
  axis = plot->x_axis;
  ticks = axis->ticks;

  /*
   * Determine the number of pixels between two ticks (assuming uniform grid),
   * and the number of ticks that need to be skipped in order to display the
   * label text without overlap.
   */

  tick_jp = plot->j_origin + 1;

  for (i=0; i<ticks->len; i++)
    {
      tick = g_array_index(ticks, Tick*, i);
      str = tick->str;
      len = strlen(str);

      /*
       * Center the text under a tick mark and draw a long tick at points for
       * which there is a text label.
       */
      text_height = axis_get_text_height(axis->font, str, axis->orientation);
      text_width = axis_get_text_width(axis->font, str, axis->orientation);

      tick_ip = plot->i_origin + x_to_i(plot, tick->val);
      text_ip = tick_ip - 0.5*text_width;
      text_jp = tick_jp + LONG_TICK_LENGTH + text_height;

      g_assert(axis->gc != NULL);
      gdk_draw_text(plot->pixmap, axis->font, axis->gc, text_ip, text_jp, str,
                    len);
      gdk_draw_line(plot->pixmap, axis->gc, tick_ip, tick_jp+LONG_TICK_LENGTH,
                    tick_ip, tick_jp);
    }

  /*
   * At points for which there is no text label, draw a short tick.
   */
  for (i=1; i<ticks->len; ++i)
    {
      if (i)
        {
          tick = g_array_index(ticks, Tick*, i);
          tick_ip = plot->i_origin + x_to_i(plot, tick->val);
          g_assert(axis->gc != NULL);
          gdk_draw_line(plot->pixmap, axis->gc, tick_ip,
                        tick_jp+SHORT_TICK_LENGTH, tick_ip, tick_jp);
        }
    }
}


Generated by  Doxygen 1.6.0   Back to index