GIFgraph_Map

 view release on metacpan or  search on metacpan

CHANGES  view on Meta::CPAN

Version 1.02	September 18 1999

- Added GIFgraph bar_spacing option handling.
- Fixed bug with showing information in status line.
- Fixed bug with formating info and legend strings.
- Fixed bug with opening new navigator window. See BUGS.
- Modifing constructor. Now it has following syntax:
  new GIFgraph::Map($gr_object, [key1 => value1, key2 => value2, ...]);
  and you can seting options in constructor immediately.


Version 1.01	August 4 1999

- Enable using the same format as use printf routine, for set %x
  and %y parameters. If x or y values is floating numbers your

GIFgraph/Map.pm  view on Meta::CPAN

$VERSION = 1.02;

#--------------------------------------------- set defaults
my $ANGLE_OFFSET = 90;
my %Defaults = ( #Default Href is JavaScript code, which do nothing
                 href   => 'javascript:;',
                 hrefs  => [],
                 lhrefs => [],
                 #Open new navigator window?
                 newWindow => 0,
                 #Default information and legend
                 info   => 'x=%x   y=%y',
                 legend => '%l',
               );

my @No_Tags = ('img_src', 'img_usemap', 'img_ismap', 'img_width', 
               'img_height', 'img_border');

#********************************************* PUBLIC methods of class

#--------------------------------------------- constructor of object
sub new #($graphics, [%options])
{ my $type = shift;

GIFgraph/Map.pm  view on Meta::CPAN

        { $s .= "\t<Area Shape=\"circle\" Coords=\"$xp, $yp, ".2 * $gr->{marker_size}."\" ";
	  last MARKER;
	}; #do
      } #MARKER:
      my $href = @{$self->{hrefs}}->[$_ - 1][$i];
      $href = $self->{href} unless defined($href);
      my $info = $self->{info};
      $info =~ s/%x/$data->[0][$i]/g; $info =~ s/%y/$data->[$_][$i]/g;
      $info = $1.(sprintf "%$2f", $data->[0][$i]).$3 if ($info =~ /(^.*)%(\.\d)x(.*&)/);
      $info = $1.(sprintf "%$2f", $data->[$_][$i]).$3 if ($info =~ /(^.*)%(\.\d)y(.*$)/);
      $info =~ s/%l/@{$gr->{legend}}->[$_ - 1]/g;
      $s .= "Href=\"$href\" Alt=\"$info\" onMouseOver=\"window.status=\'$info\'; return true;\" onMouseOut=\"window.status=\'\'; return true;\"";
      if ($self->{newWindow} and not $href =~ /javascript:/)
      { my $s_;
        map
        { $s_ .= "$1=".$self->{$_}."," if (($_ =~ /window_(\w*)/) and ($self->{$_} != 0))
        } keys %{$self};
        chop $s_;
        $s .= " Target=\"".($name + 1)."\"";
        $s .= " onClick=\"window.open(\'\', \'".($name + 1)."\', \'$s_\'); return true;\"";
      } #if
      $s .= ">\n";
    } #foreach
  } #foreach
  if (defined($gr->{legend}))
  { my $xl = $gr->{lg_xs} + $gr->{legend_spacing};
    my $y = $gr->{lg_ys} + $gr->{legend_spacing} - 1;
    my $i = 0;
    my $row = 1;
    my $x = $xl;
    foreach (@{$gr->{legend}})
    { $i++;
      last if ($i > $gr->{numsets});
      my $xe = $x;
      next if (!defined($_) or $_ eq "");
      my $lhref = @{$self->{lhrefs}}->[$i - 1];
      $lhref = $self->{href} unless defined($lhref);
      my $legend = $self->{legend};
      $legend =~ s/%l/$_/g;
      my $old_ms = $gr->{marker_size};
      my $ms = _min($gr->{legend_marker_height}, $gr->{legend_marker_width});
      ($gr->{marker_size} > $ms/2) and $gr->{marker_size} = $ms/2;
      my $x1 += $xe + int($gr->{legend_marker_width}/2);
      my $y1 += $y + int($gr->{lg_el_height}/2);
      my $n = $gr->pick_marker($i);
      my $l = $x1 - $gr->{marker_size};
      my $r = $x1 - $gr->{marker_size} + $gr->{lg_el_width};
      my $b = $y1 + $gr->{marker_size};
      my $t = $y1 - $gr->{marker_size};
      $s .= "\t<Area Shape=\"rect\" Coords=\"$l, $t, $r, $b\" Href=\"$lhref\" Alt=\"$legend\" onMouseOver=\"window.status=\'$legend\'; return true;\" onMouseOut=\"window.status=\'\'; return true;\"";
      if ($self->{newWindow} and $lhref ne $self->{href})
      { my $s_;
        map
        { $s_ .= "$1=".$self->{$_}."," if (($_ =~ /window_(\w*)/) and ($self->{$_} != 0))
        } keys %{$self};
        chop $s_;
        $s .= " Target=\"".($name + 1)."\"";
        $s .= " onClick=\"window.open(\'\', \'".($name + 1)."\', \'$s_\'); return true;\"";
      } #if
      $s .= ">\n";
      $gr->{marker_size} = $old_ms;
      $xe += $gr->{legend_marker_width} + $gr->{legend_spacing};
      my $ys = int($y + $gr->{lg_el_height}/2 - $gr->{lgfh}/2);
      $x += $gr->{lg_el_width};
      if (++$row > $gr->{lg_cols})
      { $row = 1;
        $y += $gr->{lg_el_height};
        $x = $xl;
      } #if
    } #foreach
  } #if				  
  $s .= "</Map>\n";

GIFgraph/Map.pm  view on Meta::CPAN

        my $r = int($xp - $gr->{x_step}/2 + _round($i *  $gr->{x_step}/$gr->{numsets})) - $bar_s;
	$t = int $t;
	$s .= ($$data[$i][$_] >= 0) ? "$l, $t, $r, $zero\" " : "$l, $zero, $r, $t\" ";
      } #else
      my $href = @{$self->{hrefs}}->[$i - 1][$_];
      $href = $self->{href} unless defined($href);
      my $info = $self->{info};
      $info =~ s/%x/$data->[0][$_]/g; $info =~ s/%y/$data->[$i][$_]/g;
      $info = $1.(sprintf "%$2f", $data->[0][$_]).$3 if ($info =~ /(^.*)%(\.\d)x(.*$)/);
      $info = $1.(sprintf "%$2f", $data->[$i][$_]).$3 if ($info =~ /(^.*)%(\.\d)y(.*$)/);
      $info =~ s/%l/@{$gr->{legend}}->[$i - 1]/g;
      $s .= "Href=\"$href\" Alt=\"$info\" onMouseOver=\"window.status=\'$info\'; return true;\" onMouseOut=\"window.status=\'\'; return true;\"";
      if ($self->{newWindow} and not $href =~ /javascript:/)
      { my $s_;
        map
        { $s_ .= "$1=".$self->{$_}."," if (($_ =~ /window_(\w*)/) and ($self->{$_} != 0))
        } keys %{$self};
        chop $s_;
        $s .= " Target=\"".($name + 1)."\"";
        $s .= " onClick=\"window.open(\'\', \'".($name + 1)."\', \'$s_\'); return true;\"";
      } #if
      $s .= ">\n";
    } #foreach
  } #foreach
  if (defined($gr->{legend}))
  { my $xl = $gr->{lg_xs} + $gr->{legend_spacing};
    my $y = $gr->{lg_ys} + $gr->{legend_spacing} - 1;
    my $i = 0;
    my $row = 1;
    my $x = $xl;
    foreach (@{$gr->{legend}})
    { $i++;
      last if ($i > $gr->{numsets});
      my $xe = $x;
      next if (!defined($_) or $_ eq "");
      my $lhref = @{$self->{lhrefs}}->[$i - 1];
      $lhref = $self->{href} unless defined($lhref);
      my $legend = $self->{legend};
      $legend =~ s/%l/$_/g;	
      my $ye = $y + int($gr->{lg_el_height}/2 - $gr->{legend_marker_height}/2);
      $s .= "\t<Area Shape=\"rect\" Coords=\"$xe, $ye, ".($xe + $gr->{lg_el_width}).", ".($ye + $gr->{legend_marker_height})."\" Href=\"$lhref\" Alt=\"$legend\" onMouseOver=\"window.status=\'$legend\'; return true;\" onMouseOut=\"window.status=\'\'; ...
      if ($self->{newWindow} and $lhref ne $self->{href})
      { my $s_;
        map
        { $s_ .= "$1=".$self->{$_}."," if (($_ =~ /window_(\w*)/) and ($self->{$_} != 0))
        } keys %{$self};
        chop $s_;
        $s .= " Target=\"".($name + 1)."\"";
        $s .= " onClick=\"window.open(\'\', \'".($name + 1)."\', \'$s_\'); return true;\"";
      } #if
      $s .= ">\n";
      $xe += $gr->{legend_marker_width} + $gr->{legend_spacing};
      my $ys = int($y + $gr->{lg_el_height}/2 - $gr->{lgfh}/2);
      $x += $gr->{lg_el_width};
      if (++$row > $gr->{lg_cols})
      { $row = 1;
	$y += $gr->{lg_el_height};
	$x = $xl;
      } #if
    } #foreach
  } #if
  $s .= "</Map>\n";

GIFgraph/Map.pm  view on Meta::CPAN

Set options. See OPTIONS.

=back

=head1 OPTIONS

=over *

=item B<hrefs>, B<lhrefs>

Set hyper reference for each data (hrefs), and for each legend (lhrefs).
Array @hrefs must the same size as arrays in @data list, otherwise null
elements of @hrefs set to default. Similarly array @lhrefs must the same
size as legend array. Default use the simple JavaScript code 'javascript:;'
instead reference, which do nothing.

Example of I<@hrefs> array:

for I<GIFgraph::pie>

if     @data  = ([  "1st",  "2nd",  "3rd"],
                 [      4,      2,      3]);

then   @hrefs =  ["1.htm","2.htm","3.htm"];

GIFgraph/Map.pm  view on Meta::CPAN


if     @data  = ([  "1st",  "2nd",  "3rd"],
                 [      5,     12,     24],
                 [      1,      2,      5]);

then   @hrefs = (["1.htm","2.htm","3.htm"],
                 ["4.htm","5.htm","6.htm"]);

Example of I<@lhrefs> array;

if    @legend = [  'one',  'two','three'];

then  @lhrefs = ["1.htm","2.htm","3.htm"];



=item B<info>, B<legend>

Set information string for data and for legend. It will be show in status line of your
browser. Format of this string the same for each data, but you may use special
symbols for receive individual information. Now available following symbols:
I<%x> - Is replaced on x values in @data (first array)
I<%y> - Is replaced on y values in @data (other arrays)
I<%s> - Is replaced on sum of all y values. Only for GIFgraph::pie object.
I<%p> - Is replaced on value, which show what part of all contains this data. Only for
B<GIFgraph::pie> object.
%l - Is replaced on legend. Only for B<GIFgraph::bars>, B<GIFgraph::points> and
B<GIFgraph::linespoints> objects.
For %x, %y, %s and %p parameters you may use special format (the same as use
sprintf routine) for round data: %.d{x|y|p|s}, where d is a digit from 0 to 9. For example
%.0p or %.3x. It is desirable use if %x, %y, %s or %p if floating numbers
Default is 'x=%x y=%y' for info, and '%l' for legend.

=item B<img_*>

You can set any attribute in IMG tag (except UseMap, Src, Width, Height and Border,
they will be set automatically) use set routine: set(img_option => value), where option
is IMG attribute. For example: routine set(img_Alt => 'Example'); include Alt='Example'
to IMG tag.

=item B<newWindow>, B<window_*>

README  view on Meta::CPAN

This package extends GIFgraph. It's allow generates HTML map text 
for following graph objects GIFgraph::pie, GIFgraph::bars,
GIFgraph::point and GIFgraph::linespoints

In this version done following CHANGES:
- Added GIFgraph bar_spacing option handling.
- Fixed bug with opening new navigator window. See BUGS.
- Fixed bug with formating info and legend strings. 
- Fixed bug with showing information in status line.
- Modifing constructor. Now it has following syntax:
  new GIFgraph::Map($gr_object, [key1 => value1, key2 => value2, ...]);
  and you can seting options in constructor immediately.


To install, first install GIFgraph module (it available on CPAN).
Then cd to the directory that contains this README file 
and type the following:

samples/sample12.pl  view on Meta::CPAN


$my_graph->set( 
	'x_label' => 'X Label',
	'y_label' => 'Y label',
	'title' => 'Two data sets',
	'y_max_value' => 40,
	'y_tick_number' => 8,
	'y_label_skip' => 2,
);

$my_graph->set_legend( 'Data set 1', 'Data set 2' );

$my_graph->plot_to_gif( "sample12.gif", \@data );

open(OUT, ">sample12.html");

$map = new GIFgraph::Map($my_graph);

print OUT "<html>\n<body>\n";

print OUT $map->imagemap("sample12.gif", \@data);

samples/sample14.pl  view on Meta::CPAN

	'x_label' => 'X Label',
	'y1_label' => 'Y1 label',
	'y2_label' => 'Y2 label',
	'title' => 'Using two axes',
	'y1_max_value' => 40,
	'y2_max_value' => 8,
	'y_tick_number' => 8,
	'y_label_skip' => 2,
	'long_ticks' => 1,
	'two_axes' => 1,
	'legend_placement' => 'RT',
);

$my_graph->set_legend( 'left axis', 'right axis');

$my_graph->plot_to_gif( "sample14.gif", \@data );

open(OUT, ">sample14.html");

$map = new GIFgraph::Map($my_graph);

print OUT "<html>\n<body>\n";

print OUT $map->imagemap("sample14.gif", \@data);

samples/sample15.pl  view on Meta::CPAN


$my_graph->set( 
	'x_label' => 'X Label',
	'y_label' => 'Y label',
	'title' => 'Bars on top of each other (incremental)',
	'y_tick_number' => 8,
	'y_label_skip' => 2,
	'overwrite' => 2,
);

$my_graph->set_legend( 'offset', 'increment');

$my_graph->plot_to_gif( "sample15.gif", \@data );

open(OUT, ">sample15.html");

$map = new GIFgraph::Map($my_graph);

print OUT "<html>\n<body>\n";

print OUT $map->imagemap("sample15.gif", \@data);

samples/sample16.pl  view on Meta::CPAN


$my_graph->set( 
	'x_label' => 'Day',
	'y_label' => 'AUD',
	'title' => 'Credits and Debits',
	'y_tick_number' => 12,
	'y_label_skip' => 2,
	'overwrite' => 1, 
	'dclrs' => [ qw( green lred ) ],
	'axislabelclr' => 'black',
	'legend_placement' => 'RB',
	'zero_axis_only' => 0,

);

$my_graph->set_legend( 'credits', 'debets' );

$my_graph->plot_to_gif( "sample16.gif", \@data );

open(OUT, ">sample16.html");

$map = new GIFgraph::Map($my_graph);

print OUT "<html>\n<body>\n";

print OUT $map->imagemap("sample16.gif", \@data);

samples/sample31.pl  view on Meta::CPAN


$my_graph = new GIFgraph::points(600, 400);

$my_graph->set( 
	'x_label' => 'X Label',
	'y_label' => 'Y label',
	'title' => 'A Points Graph',
	'y_max_value' => 40,
	'y_tick_number' => 8,
	'y_label_skip' => 2, 
	'legend_placement' => 'RC',
	'long_ticks' => 1,
	'marker_size' => 6,
	'markers' => [ 1, 7, 5 ],
);

$my_graph->set_legend( qw( one two ) );

$my_graph->plot_to_gif( "sample31.gif", \@data );


open(OUT, ">sample31.html");

$map = new GIFgraph::Map($my_graph);

$map->set(info => '%l:  x=%x  y=%y');

samples/sample41.pl  view on Meta::CPAN

$my_graph->set( 
	'x_label' => 'X Label',
	'y_label' => 'Y label',
	'title' => 'A Lines and Points Graph',
	'y_max_value' => 40,
	'y_tick_number' => 8,
	'y_label_skip' => 2,
	'markers' => [ 1, 5 ],
);

$my_graph->set_legend( 'data set 1', 'data set 2' );

$my_graph->plot_to_gif( "sample41.gif", \@data );


open(OUT, ">sample41.html");

$map = new GIFgraph::Map($my_graph);

$map->set(info =>'%l:  x=%x  y=%y');



( run in 0.857 second using v1.01-cache-2.11-cpan-49f99fa48dc )