The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Imager::Plot::Axis - Axis handling of Imager::Plot.

SYNOPSIS

  use Imager;
  use Imager::Plot::Axis;

  # Create our dummy data
  @X = 0..10;
  @Y = map { $_**3 } @X;

  # Create Axis object

  $Axis = Imager::Plot::Axis->new(Width => 200, Height => 180, GlobalFont=>"ImUgly.ttf");
  $Axis->AddDataSet(X => \@X, Y => \@Y);

  $Axis->{XgridShow} = 1;  # Xgrid enabled
  $Axis->{YgridShow} = 0;  # Ygrid disabled

  $Axis->{Border} = "lrb"; # left right and bottom edges

  # See Imager::Color manpage for color specification
  $Axis->{BackGround} = "#cccccc";

  # Override the default function that chooses the x range
  # of the graph, similar exists for y range

  $Axis->{make_xrange} = sub {
      $self = shift;
      my $min = $self->{XDRANGE}->[0]-1;
      my $max = $self->{XDRANGE}->[1]+1;
      $self->{XRANGE} = [$min, $max];
  };

  $img = Imager->new(xsize=>600, ysize => 400);
  $img->box(filled=>1, color=>"white");

  $Axis->Render(Xoff=>50, Yoff=>370, Image=>$img);

  $img->write(file=>"foo.ppm") or die $img->errstr;

DESCRIPTION

This part of Imager::Plot takes care of managing the graph area itself. It handles the grid, tickmarks, background in axis area and the data sets of course. All the data sets have to be given to the Axis object before rendering it so that everything is only written only once and scaling of axis can be done automatically. This also helps in doing chartjunk tricks like shadows.

The size of the Axis area is controlled by the Width and Height parameters of the new method. The border region/frame of the axis is considered to lie in the coordinate system. The default order of drawing is the following: Background image, grid, frame, ticks.

Note that the Axis currently renders the ticklabels. This might change in the near future.

AUTHOR

Arnar M. Hrafnkelsson, addi@umich.edu

SEE ALSO Imager, Imager::Plot, Imager::DataSet, Imager::Style perl(1).