Gadabout

 view release on metacpan or  search on metacpan

Gadabout.pm  view on Meta::CPAN

  $self->CreateColor("lightgreen", 0  , 140, 0  , 125);
} # sub InitGraph



sub SetGraphSize{
  my $self = shift;
  my $noLegend = shift;
  $noLegend = 0 if (!defined($noLegend));
  if (!$self->{noLegend}) {
    $self->{legendHeight} = $self->{perLegendHeight} * ($self->{num_data_sets} + 1);
  } else {
    $self->{legendHeight} = 0;
  }

  $self->{graph_height} = $self->{image_height} - (2 * $self->{ypad}) - $self->{legendHeight};
  $self->{graph_width}  = $self->{image_width}  - (2 * $self->{xpad});
} # sub SetGraphSize


sub CreateColor{
  my $self = shift;
  my $name = shift;
  my $red = shift;
  my $green = shift;
  my $blue = shift;

Gadabout.pm  view on Meta::CPAN

  my $title = shift;
  $self->{axis2Title} = $title;
} # sub SetAxis2Title


sub AddData{
  my ($self, $xdata, $ydata, $name) = @_;
  $name = "" if (!defined($name));

  $self->SetGraphSize($self->{image_height},$self->{image_width});
  $self->{legendText}[$self->{num_data_sets}] = $name;

  #sort(@xdata);

  my $dataSetIndex = $self->{num_data_sets};
  for (my $i=0; $i < @$xdata; $i++){
    $self->{data_set}[$dataSetIndex]{"x"}[$i] = $xdata->[$i];
    $self->{data_set}[$dataSetIndex]{"y"}[$i] = $ydata->[$i];
  }

  my $XSize = @$xdata;

Gadabout.pm  view on Meta::CPAN


  $self->DrawLine($im_xmax-1, $im_ymax, $im_xmax, $im_ymax, $color);
  $self->DrawLine($im_xmax, $im_ymax+1, $im_xmax, $im_ymax, $color);
} # sub DrawGrid


sub LineGraph{
  my ($self, $dataset, $color) = @_;

  $self->{current_dataset} = $dataset;
  $self->{legend}{$dataset}{'LineGraph'} = {"color" => $color};

  my $lastx = $self->{data_set}[$dataset]{"x"}[0];
  my $lasty = $self->{data_set}[$dataset]{"y"}[0];
		
  for (my $i = 1; $i < $self->{num_points}[$dataset]; $i++) {
    $self->GraphLine($lastx, $lasty, $self->{data_set}[$dataset]{"x"}[$i], $self->{data_set}[$dataset]{"y"}[$i], $color);
    $lastx = $self->{data_set}[$dataset]{"x"}[$i];
    $lasty = $self->{data_set}[$dataset]{"y"}[$i];
  }

Gadabout.pm  view on Meta::CPAN

  my $self = shift;
  my $dataset = shift;
  my $color = shift;

  $self->{current_dataset} = -1;
  my $min = $self->min($self->{ymin}, $self->{axis2}{ymin});

  my ($graph_left, $graph_bottom) = $self->translate($self->{xmin},$min);

  $self->{current_dataset} = $dataset;
  $self->{legend}{$dataset}{'FilledLineGraph'} = {'color' => $color};

  my ($last_x, $last_y) = $self->translate($self->{data_set}[$dataset]{"x"}[0],$self->{data_set}[$dataset]{"y"}[0]);
  $graph_bottom = int($graph_bottom+.5);
  my $first_x  = int($last_x+.5);
  my $first_y  = int($last_y+.5);

  my %graphed;
  my @verts;

  $verts[0] = {"x" => $first_x, "y" => $first_y};

Gadabout.pm  view on Meta::CPAN


  if (scalar(@verts) > 3) {
    $self->DrawFilledPolygon(\@verts,$color);
  }
} # sub FilledLineGraph


sub DrawLegend{
  my $self = shift;

  if (defined($self->{legend})) { 
    my $legend_top  = $self->{graph_height} + 2 * $self->{ypad};
    my $current_top = $legend_top;

    $self->DrawText($self->{font},10,$legend_top - 18,"Legend:","black",0);
    $self->DrawLine(10,$legend_top - 4,47,$legend_top - 4,"black");

    my $dataset;
    my $type;
    my $datasetInfo;
    my $legendInfo;
    my $tmpHash = $self->{legend};
    while (($dataset, $legendInfo) = each %$tmpHash) {
      my $legend_left = 10;
      while(($type, $datasetInfo) = each %$legendInfo) {
        my $legendMod;
        if (exists($legendInfo->{'FilledLineGraph'}) || exists($legendInfo->{'VBarGraph'})) {
          $legendMod = 0;
        } else {
          $legendMod = 8;
        }

        if ($type eq "FilledLineGraph"){
          $self->DrawFilledRectangle($legend_left,$current_top,15,15,$datasetInfo->{"color"});
        }
        else{
          if ($type eq "DashedLineGraph"){
            $self->DrawDashedLine($legend_left,$current_top + $legendMod, $legend_left + 15, $current_top + $legendMod, 3, 4, $datasetInfo->{"color"});
          }
          else{
            if ($type eq "ScatterGraph"){
              $self->DrawBrush($legend_left + 8,$current_top + $legendMod,$datasetInfo->{'shape'},$datasetInfo->{"color"});
            }
            else{
              if ($type eq "LineGraph"){
                $self->DrawLine($legend_left,$current_top + $legendMod, $legend_left + 15, $current_top + $legendMod, $datasetInfo->{"color"});
              }
              else{
                if ($type eq "VBarGraph"){
                  $self->DrawGradientRectangle($legend_left + (15 - $self->{vBarWidth}) / 2, $current_top , $self->{vBarWidth}, 15, $datasetInfo->{"color"});
                }
              }
            }
          }
        }
      }
      my $mesg;
      if (defined($self->{axis2_data}[$dataset])) {
        $mesg = " (Right Hand Scale)";
      } else {
        $mesg = "";
      }

      $legend_left += 20;
      my $label;
      if (defined($self->{legendText}[$dataset])){
        $label = $self->{legendText}[$dataset];
      }
      else{
        $label = "Dataset: " . $dataset;
      }
      $label = $label . $mesg;
      $self->DrawText($self->{font}, $legend_left, $current_top, $label, "black", 0);
      $current_top += 20;
      #$dataset++;
    }
  }
} #sub DrawLegend



sub DrawAxis{
  my $self = shift;

Gadabout.pm  view on Meta::CPAN

  $self->{yAxisSpacing} = $spacing;
}#sub SetYAxisSpacing


sub ScatterGraph{
  my $self = shift;
  my $dataset = shift;
  my $shape = shift;
  my $color = shift;
  $self->{current_dataset} = $dataset;
  $self->{legend}{$dataset}{'ScatterGraph'} = {"color" => $color, 'shape' => $shape};

  reset($self->{data_set}[$dataset]{"x"});

  for (my $i=0; $i < $self->{num_points}[$dataset]; $i++) {
    my $x = $self->{data_set}[$dataset]{"x"}[$i];
    my $y = $self->{data_set}[$dataset]{"y"}[$i];
    $self->GraphBrush($x,$y,$shape,$color);
  }
}#sub ScatterGraph

sub VBarGraph{
  my $self = shift;
  my $dataset = shift;
  my $color = shift;
  $self->{current_dataset} = $dataset;
  $self->{legend}{$dataset}{'VBarGraph'} = {"color" => $color};

  for (my $i = 0; $i < $self->{num_points}[$dataset]; $i++) {
    $self->GraphVBar($self->{data_set}[$dataset]{"x"}[$i], $self->{data_set}[$dataset]{"y"}[$i], $color);
  }
}#sub BarGraph



sub PieChart{
  my $self = shift;

Gadabout.pm  view on Meta::CPAN

  my $xAngle          = $pieProps->{"xAngle"};
  my $yAngle          = $pieProps->{"yAngle"};
  my $zAngle          = $pieProps->{"zAngle"};
  my $dMod            = $pieProps->{"dMod"};
  my $defaultRadMod   = $pieProps->{"radMod"};
  my $startHeightMod  = $pieProps->{"startHeightMod"};
  my $edgeColor       = $pieProps->{"edgeColor"};
  my $maxDepth        = $pieProps->{"maxDepth"};

  my $titlePad        = 15;
  my $legendBoxHeight = 15;
  my $legendBoxSpace  = 8;
  my $legendHeightMod = $legendBoxHeight + $legendBoxSpace + 1;
  my $maxMod = $self->max($defaultRadMod,($self->ArrayMax($radMod)));
  $self->{image_width} = $self->max($self->{image_width},$maxMod+(0.75 * $self->{image_width})); # + ($maxLength * 1));
  my $radius = ($self->{image_width} - 10) * .2;
  #my $radius = ($self->{image_width} - 10) * .3;

  $self->{image_height} = $self->max(2 * ($radius + $maxMod/2) + $self->{ypad},scalar(@$data) * $legendHeightMod + $titlePad);

  $self->InitGraph($self->{image_width},$self->{image_height});

  my $color          = $self->GeneratePieChartColors(scalar(@$data));

  #$radius = ($self->{image_width} - 10) * .3;
  $radius      = $self->min(($self->{image_width} - 10-(.75*$maxMod)) * .2,($self->{image_height} - 40-(.75*$maxMod)) * .5);
  my $absCenterX  = int(($radius + ($radius / 10) + (.75*$maxMod)) + 20 +.5);
  my $absCenterY  = int($radius + 10 + .75*$maxMod +.5);
  my $legend_left = 2 * $absCenterX;
  my $legend_top  = 10;
  my $degreeSteps = 6;

  if (defined($title)) {
    $self->DrawText($self->{font},$legend_left,$legend_top,$title,"black",0);
    $self->DrawLine($legend_left - 2,$legend_top + $titlePad,$legend_left + (length($title) * 5.2),$legend_top + $titlePad,"black");
    $legend_top =  $legend_top + 25;
  }

  #arsort($data);

  my $total = 0;
  for (my $i = 0;  $i < scalar(@$data); $i++){
    $total = $total + @$data->[$i];
  }

  if (!defined(@$data)) {

Gadabout.pm  view on Meta::CPAN

      push(@{$side2Polys{$pieceNumber}},$topPoint);
    }

    my $orderX = $absCenterX + $radius * cos($self->deg2rad($bisector));
    my $orderY = $absCenterY + $radius * sin($self->deg2rad($bisector));
    my $depth;
    my $order  = $self->GetPerspectiveXY($absCenterX,$absCenterY,$orderX,$orderY,$dMod * $depth,$xAngle,$yAngle,$zAngle);
    $polyOrder{$pieceNumber} = $order->{"y"};

    if (defined($total)) {
      $self->DrawFilledRectangle($legend_left,$legend_top,$legendBoxHeight,$legendBoxHeight,$color->[$colorCount]);
      $self->DrawRectangle($legend_left,$legend_top,$legendBoxHeight,$legendBoxHeight,"black");

      my $totalPercentage = ($total ? (int(($value / $total * 1000)+.5) / 10) : "0");
      my $strLegend = " - " . @$name->[$pieceNumber] . ": " . @$data->[$pieceNumber] . " (" . $totalPercentage . "%)";
      $self->DrawText($self->{font},$legend_left + 20, $legend_top, $strLegend,"black",0);
      $legend_top = $legend_top + $legendBoxHeight + $legendBoxSpace;
      $pieColors[$pieceNumber] = $colorCount;
      $colorCount++;
    }

  }

  foreach my $pieceNumber (sort keys %polyOrder){
    $colorCount = $pieColors[$pieceNumber];
    my $startDepth = $pieceNumber * $startHeightMod;
    my $lastVert   = scalar(@{$piePolys{$pieceNumber}{"bottom"}}) - 1;

Gadabout.pm  view on Meta::CPAN

  my $totalDataSets = scalar(@$self->{chartData}[$chartID]);

  if ($totalDataSets) {
    my $colors = $self->GeneratePieChartColors($totalDataSets,0);

    my $offSet = 6;
    my $count  = ceil(($totalDataSets / 2) - $totalDataSets);

    my %tempHash = %$self->{chartData}[$chartID];
    while (my ($foo,$dataset) = each %tempHash) {
      $self->{legend}{$dataset}{"VBarGraph"} = {"color" => @$colors[$foo]};

      my $xOffset = $offSet * $count;

      for (my $i = 0; $i < $self->{num_points}[$dataset]; $i++) {
        $self->GraphVBar($self->{data_set}[$dataset]{"x"}[$i], $self->{data_set}[$dataset]{"y"}[$i], @$colors[$foo], $xOffset);
      }

      $count++;
    }



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