File: chart

package info (click to toggle)
libmath-gsl-perl 0.45-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 192,156 kB
  • sloc: ansic: 895,524; perl: 24,682; makefile: 12
file content (69 lines) | stat: -rwxr-xr-x 2,028 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/perl -w
use strict;
use Chart::Clicker;
use Chart::Clicker::Axis;
use Chart::Clicker::Data::DataSet;
use Chart::Clicker::Data::Series;
use Chart::Clicker::Decoration::Grid;
use Chart::Clicker::Decoration::Legend;
use Chart::Clicker::Decoration::Plot;
use Chart::Clicker::Drawing qw(:positions);
use Chart::Clicker::Drawing::Insets;
use Chart::Clicker::Renderer::Area qw/:options/;
use Math::GSL::SF qw/:bessel/;

my $function = shift || 'gsl_sf_bessel_J0';
my $name     = shift || "Bessel Function J0(x)";
my $filename = shift || 'chart.png';
my $chart    = new Chart::Clicker({ format => 'png', width => 400, height => 300 });
my @x        = map { $_/ 100 } ( 0 .. 3000 ) ;
my @negx     = map { -$_ } reverse @x ;
my $series;

{
    no strict 'refs';
    $series = new Chart::Clicker::Data::Series({
        keys    => [@negx, @x],
        values  => [map { $function->($_) } (@negx,@x) ],
        name    => $name,
    });
}

my $dataset = new Chart::Clicker::Data::DataSet({ series => [ $series ] });
$chart->datasets([ $dataset ]);

my $legend = new Chart::Clicker::Decoration::Legend({
    margins => new Chart::Clicker::Drawing::Insets({
        top => 3
})
});
$chart->add($legend, $CC_BOTTOM);

my $daxis = new Chart::Clicker::Axis({
    orientation => $CC_HORIZONTAL,
    position    => $CC_BOTTOM,
    format      => '%d',
    tick_values => [-25,-20,-15,-10,-5,0,5,10,15,20,25],
});
$chart->add($daxis, $CC_AXIS_BOTTOM);
my $raxis = new Chart::Clicker::Axis({
    orientation => $CC_VERTICAL,
    position    => $CC_LEFT,
    format      => '%0.2f'
});
$chart->add($raxis, $CC_AXIS_LEFT);
$chart->range_axes([ $raxis ]);
$chart->domain_axes([ $daxis ]);

my $grid = new Chart::Clicker::Decoration::Grid();
$chart->add($grid, $CC_CENTER, 0);

my $renderer = new Chart::Clicker::Renderer::Area( { fade => 1 });
my $plot = new Chart::Clicker::Decoration::Plot();

$plot->renderers([$renderer]);
$chart->plot($plot);
$chart->add($plot, $CC_CENTER);
$chart->prepare();
$chart->draw();
$chart->write($filename);