cvsuser     05/11/08 09:45:33

  Modified:    App-Widget/lib/App/Widget Graph.pm
  Log:
  first attempt to get x/y series right when only one graph column specified
  
  Revision  Changes    Path
  1.2       +55 -21    p5ee/App-Widget/lib/App/Widget/Graph.pm
  
  Index: Graph.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Widget/lib/App/Widget/Graph.pm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Graph.pm  8 Nov 2005 05:12:34 -0000       1.1
  +++ Graph.pm  8 Nov 2005 17:45:32 -0000       1.2
  @@ -178,41 +178,75 @@
           $graph_dims = $data_dims;
           $objects = $object_set->get_objects();
       }
  -    my (@x, @yn, $object, $column);
  -    for (my $i = 0; $i <= $#$objects; $i++) {
  -        $object = $objects->[$i];
  -        for (my $j = 0; $j <= $#$columns; $j++) {
  -            $column = $columns->[$j];
  -            $yn[$j][$i] = $object->{$column};
  -        }
  -    }
  -    $spec->{y} = [EMAIL PROTECTED];
   
  +    my (@x, @yn, $object, $column);
       my ($label);
       my $column_defs = $object_set->get_column_defs();
   
  -    if ($column_dims) {
  -        my (@y_labels);
  -        foreach my $column (@$columns) {
  -            $label = $column_defs->{$column}{label} || $column;
  -            $label =~ s/<br>//g;
  -            push(@y_labels, $label);
  +    if ($#$columns > 0 || $graph_dims < 2) {
  +        for (my $i = 0; $i <= $#$objects; $i++) {
  +            $object = $objects->[$i];
  +            for (my $j = 0; $j <= $#$columns; $j++) {
  +                $column = $columns->[$j];
  +                $yn[$j][$i] = $object->{$column};
  +            }
  +        }
  +        $spec->{y} = [EMAIL PROTECTED];
  +
  +        if ($column_dims) {
  +            my (@y_labels);
  +            foreach my $column (@$columns) {
  +                $label = $column_defs->{$column}{label} || $column;
  +                $label =~ s/<br>//g;
  +                push(@y_labels, $label);
  +            }
  +            $spec->{y_labels} = [EMAIL PROTECTED];
           }
  -        $spec->{y_labels} = [EMAIL PROTECTED];
  -    }
   
  -    {
           my $x_dim = $#$keys;
           my $x_column = $keys->[$x_dim];
           $label = $column_defs->{$x_column}{label};
           $label =~ s/<br>//g;
           $spec->{x_title} = $label if (!$spec->{x_title});
  -        my (@x);
  +        my (@x, %x_seen, $x_value);
  +        foreach my $object (@$objects) {
  +            $x_value = $object->{$x_column};
  +            if (!$x_seen{$x_value}) {
  +                push(@x, $x_value);
  +                $x_seen{$x_value} = 1;
  +            }
  +        }
  +        $spec->{x} = [EMAIL PROTECTED];
  +    }
  +    else {  # there is only one column ($#$columns == 0)
  +        my $x_dim = $#$keys - 1;
  +        my $x_column = $keys->[$x_dim];
  +        my $y_dim = $#$keys;
  +        my $y_column = $keys->[$y_dim];
  +        my $column = $columns->[0];
  +        $label = $column_defs->{$x_column}{label};
  +        $label =~ s/<br>//g;
  +        $spec->{x_title} = $label if (!$spec->{x_title});
  +        my (@x, %x_idx, $x_value, @y, %y_idx, $y_value);
           foreach my $object (@$objects) {
  -            push(@x, $object->{$x_column});
  +            $x_value = $object->{$x_column};
  +            $y_value = $object->{$y_column};
  +            if (! defined $x_idx{$x_value}) {
  +                push(@x, $x_value);
  +                $x_idx{$x_value} = $#x;
  +            }
  +            if (! defined $y_idx{$y_value}) {
  +                push(@y, $y_value);
  +                $y_idx{$y_value} = $#y;
  +            }
  +            $yn[$y_idx{$y_value}][$x_idx{$x_value}] = $object->{$column};
           }
           $spec->{x} = [EMAIL PROTECTED];
  +        $spec->{y} = [EMAIL PROTECTED];
  +
  +        $spec->{y_labels} = [EMAIL PROTECTED];
       }
  +
       &App::sub_exit() if ($App::trace);
   }
   
  
  
  

Reply via email to