#!/usr/bin/perl
use strict;
use warnings;

use List::MoreUtils qw(mesh);
use Mock::Populate;
use SVG::Graph::Kit;

my $i = 0;
my $n = 90;
my $x = Mock::Populate::distributor(type => 'u', prec => 4, dof => 2, N => $n);
my $y = Mock::Populate::distributor(type => 's', prec => 4, dof => 2, N => $n);
my %data = mesh @$x, @$y;
my @data = map { [ $_ => $data{$_} ] } keys %data;

my $g = SVG::Graph::Kit->new(
    data => \@data,
#    axis => { #xticks => 3, yticks => 3,
#      log => 2,
#    },
    plot => {
      type => 'line', # default: scatter
#      'fill-opacity' => 0.5, # etc.
    },
    polar => 1,
);
#print $g->draw;
print $g->svg->xmlify(-inline => 1);
__END__
my $n;
for my $dim (qw(x y z)) {
  for my $stat (qw(min max mean mode median range stdv percentile)) {
    $n = $stat eq 'percentile' ? 90 : undef; # Inspect the 90th percentile.
    printf "%s %s = %0.2f\n", $dim, $stat, $g->stat($dim, $stat, $n);
  }
}

__END__
my @x = qw(2 3 5 7 11 13 17 19 23 29 31 37 41);
my $x = @x;
my $y = $x[-1];

my( $i, $d );

$i = 0;
$d = [ map { [ ++$i, $_ ] } @x ];
my $items = [
    { data => $d, line => { stroke => 'yellow' } },
    { data => $d, scatter => { stroke => 'blue' } },
];

# Explicitly declared SVG::Graph axis.
my $g = SVG::Graph::Kit->new(
    _items => [ {
            axis => {
                x_fractional_ticks => $x,
                y_absolute_ticks => 1,
                stroke => 'palegray', # etc.
            },
            data => [ [0, 0], [$x, $y] ],
            line => { stroke => 'palegray' },
        },
        @items,
    ],
);

=for private
# Absolute x and y ticks on an auto-axis.  Use grid=>0 for large x*y.
my $g = SVG::Graph::Kit->new(
    _axis => { grid => 1, y => $y, x => $x },
    _items => $items,
);
=cut

=for private
# Ticks and grid lines at a locked-step factor apart.
$g = SVG::Graph::Kit->new(
    _axis => { grid => 1, x => $x, y => $y, s => 2 },
    _items => $items,
);
=cut

=for private
# Ticks and grid lines at different step factors apart.
$g = SVG::Graph::Kit->new(
    _axis => { grid => 1,
        x => $x, y => $y,
        xs => 2, ys => 5,
    },
    _items => $items,
);
=cut

=for private
# Scale the x and y ticks.  Use this technique for large data sets.
$g = SVG::Graph::Kit->new(
    _axis => { grid => 1,
        x => $x, y => $y,
        xs => int $x / 10,
        ys => int $y / 10,
    },
    _items => $items,
);
=cut

=for private
# Scale the y ticks to fit x for (possibly) fractional y tick lables.
my $s = $y / $x;
$g = SVG::Graph::Kit->new(
    _axis => { grid => 1,
        x => $x, y => $y,
        ys => $s,
        ylabels => [ map { sprintf '%.2f', $_ * $s } 0 .. $x ],
    },
    _items => $items,
);
=cut

#print $g->draw;
print $g->svg->xmlify(-inline => 0);
