1#!/usr/bin/perl 2 3use strict; 4use Statistics::Descriptive; 5use SVG::Graph; 6use SVG::Graph::Data; 7use SVG::Graph::Data::Datum; 8 9my %stat; 10 11my $graph = SVG::Graph->new( width => 1000, height => 800, margin => 40 ); 12my $parentgroup = $graph->add_group; 13my $statgroup = $parentgroup->add_group; 14my $bargroup = $parentgroup->add_group; 15 16my @data; 17my $ymax = undef; 18my $stat = Statistics::Descriptive::Full->new; 19while (<>) { 20 chomp; 21 if (/^#stat:/) { 22 process_stat($_); 23 next; 24 } 25 my ( $x, $y ) = split /\s+/; 26 $ymax = $y > $ymax ? $y : $ymax; 27 $stat->add_data($x); 28 push @data, SVG::Graph::Data::Datum->new( x => $x, y => $y ); 29} 30 31$parentgroup->add_glyph('axis'); 32 33warn $stat{mean}; 34 35my @statdata = ( 36 SVG::Graph::Data::Datum->new( x => $stat->min, y => 0 ), 37 38# SVG::Graph::Data::Datum->new(x => $stat{mean}, y => $ymax), 39# SVG::Graph::Data::Datum->new(x => $stat{mean} - $stat{standard_deviation}, y => $ymax), 40# SVG::Graph::Data::Datum->new(x => $stat{mean} + $stat{standard_deviation}, y => 0), 41 42 SVG::Graph::Data::Datum->new( x => $stat{median}, y => $ymax ), 43 SVG::Graph::Data::Datum->new( x => $stat{quartile1}, y => $ymax ), 44 SVG::Graph::Data::Datum->new( x => $stat{quartile3}, y => 0 ), 45 46 SVG::Graph::Data::Datum->new( x => $stat->max, y => 0 ), 47 48); 49$statgroup->add_data( SVG::Graph::Data->new( data => \@statdata ) ); 50$statgroup->add_glyph( 51 'barflex', 52 'stroke' => 'black', 53 'fill' => 'black', 54 'stroke-opacity' => 1.0, 55 'fill-opacity' => 0.4 56); 57 58$bargroup->add_data( SVG::Graph::Data->new( data => \@data ) ); 59$bargroup->add_glyph( 60 'bar', 61 'stroke' => 'red', 62 'fill' => 'red', 63 'stroke-opacity' => 1.0, 64 'fill-opacity' => 0.8 65); 66 67print $graph->draw; 68 69sub process_stat { 70 my $line = shift; 71 my ( $name, $value ) = $line =~ /^#stat:(\S+)\t(\S+)$/; 72 $stat{$name} = $value; 73} 74