| 1 | package School::Evaluation::Gibbmers::Chart; | ||
| 2 | $School::Evaluation::Gibbmers::Chart::VERSION = '0.004'; | ||
| 3 | # No guarantee given, use at own risk and will | ||
| 4 | # ABSTRACT: render a chart | ||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | use Chart::Clicker; | ||
| 9 | use Chart::Clicker::Context; | ||
| 10 | use Chart::Clicker::Data::DataSet; | ||
| 11 | use Chart::Clicker::Data::Marker; | ||
| 12 | use Chart::Clicker::Data::Series::Size; | ||
| 13 | use Geometry::Primitive::Rectangle; | ||
| 14 | use Chart::Clicker::Renderer::Bubble; | ||
| 15 | use Geometry::Primitive::Circle; | ||
| 16 | |||
| 17 | # only needed to monkey with color changing | ||
| 18 | use Graphics::Color::RGB; | ||
| 19 | use Chart::Clicker::Drawing::ColorAllocator; | ||
| 20 | |||
| 21 | sub new { | ||
| 22 | my $class = shift; | ||
| 23 | my $self = { | ||
| 24 | bad => [0, 0, 0], | ||
| 25 | mid => [0, 0, 0], | ||
| 26 | hig => [0, 0, 0], | ||
| 27 | sup => [0, 0, 0], | ||
| 28 | }; | ||
| 29 | bless ($self, $class); | ||
| 30 | } | ||
| 31 | sub set_1bad_sizes { | ||
| 32 | my $self = shift; | ||
| 33 | $self->{bad} = shift; | ||
| 34 | } | ||
| 35 | sub set_2mid_sizes { | ||
| 36 | my $self = shift; | ||
| 37 | $self->{mid} = shift; | ||
| 38 | } | ||
| 39 | sub set_3hig_sizes { | ||
| 40 | my $self = shift; | ||
| 41 | $self->{hig} = shift; | ||
| 42 | } | ||
| 43 | sub set_4sup_sizes { | ||
| 44 | my $self = shift; | ||
| 45 | $self->{sup} = shift; | ||
| 46 | } | ||
| 47 | |||
| 48 | sub render_chart { | ||
| 49 | my $self = shift; | ||
| 50 | my $title = shift; | ||
| 51 | my $filename = shift; | ||
| 52 | |||
| 53 | my $cc = Chart::Clicker->new( width => 400, | ||
| 54 | height => 300, | ||
| 55 | format => 'png'); | ||
| 56 | |||
| 57 | my $values_bad = Chart::Clicker::Data::Series::Size->new( | ||
| 58 | keys => [qw(1 2 3)], | ||
| 59 | values => [qw(1 1 1)], | ||
| 60 | sizes => $self->{bad}, | ||
| 61 | name => "Schlecht" | ||
| 62 | ); | ||
| 63 | |||
| 64 | my $values_mid = Chart::Clicker::Data::Series::Size->new( | ||
| 65 | keys => [qw(1 2 3)], | ||
| 66 | values => [qw(2 2 2)], | ||
| 67 | sizes => $self->{mid}, | ||
| 68 | name => "Naja" | ||
| 69 | ); | ||
| 70 | |||
| 71 | my $values_hig = Chart::Clicker::Data::Series::Size->new( | ||
| 72 | keys => [qw(1 2 3)], | ||
| 73 | values => [qw(3 3 3)], | ||
| 74 | sizes => $self->{hig}, | ||
| 75 | name => "Gut" | ||
| 76 | ); | ||
| 77 | |||
| 78 | my $values_sup = Chart::Clicker::Data::Series::Size->new( | ||
| 79 | keys => [qw(1 2 3)], | ||
| 80 | values => [qw(4 4 4)], | ||
| 81 | sizes => $self->{sup}, | ||
| 82 | name => "Super" | ||
| 83 | ); | ||
| 84 | |||
| 85 | $cc->title->text($title); | ||
| 86 | $cc->title->padding->bottom(5); | ||
| 87 | |||
| 88 | my $ds = Chart::Clicker::Data::DataSet->new( | ||
| 89 | series => [ $values_bad, | ||
| 90 | $values_mid, | ||
| 91 | $values_hig, | ||
| 92 | $values_sup, | ||
| 93 | ]); | ||
| 94 | |||
| 95 | $cc->add_to_datasets($ds); | ||
| 96 | |||
| 97 | # COLORS # | ||
| 98 | ########## | ||
| 99 | # build the color allocator | ||
| 100 | my $ca = Chart::Clicker::Drawing::ColorAllocator->new; | ||
| 101 | # this hash is simply here to make things readable and cleaner, | ||
| 102 | # can always call G::C::R inline | ||
| 103 | my $green = Graphics::Color::RGB->new({ | ||
| 104 | red => 0,green => 1, blue=> 0, alpha=> .9 | ||
| 105 | }); | ||
| 106 | my $green_red = Graphics::Color::RGB->new({ | ||
| 107 | red => 0.25,green => .75, blue=> 0, alpha=> .9 | ||
| 108 | }); | ||
| 109 | my $red_green = Graphics::Color::RGB->new({ | ||
| 110 | red => .75, green => 0.25, blue => 0, alpha => .9 | ||
| 111 | }); | ||
| 112 | my $red= Graphics::Color::RGB->new({ | ||
| 113 | red => 1, green => 0, blue => 0, alpha => .9 | ||
| 114 | }); | ||
| 115 | # add colors | ||
| 116 | $ca->add_to_colors($red); | ||
| 117 | $ca->add_to_colors($red_green); | ||
| 118 | $ca->add_to_colors($green_red); | ||
| 119 | $ca->add_to_colors($green); | ||
| 120 | $cc->color_allocator($ca); | ||
| 121 | |||
| 122 | |||
| 123 | my $cnf = $cc->get_context('default'); | ||
| 124 | |||
| 125 | $cnf->range_axis->fudge_amount(.2); | ||
| 126 | $cnf->domain_axis->fudge_amount(.2); | ||
| 127 | $cnf->range_axis->hidden(0); | ||
| 128 | $cnf->domain_axis->hidden(0); | ||
| 129 | $cnf->range_axis->tick_values([qw(1 2 3 4)]); | ||
| 130 | $cnf->range_axis->tick_labels(['Schlecht', 'Naja', 'Gut', 'Super']); | ||
| 131 | $cnf->domain_axis->tick_values([qw(1 2 3)]); | ||
| 132 | $cnf->domain_axis->tick_labels(['wenig Interesse', 'Interessant', 'Lieblingsfach']); | ||
| 133 | $cnf->renderer(Chart::Clicker::Renderer::Bubble->new); | ||
| 134 | |||
| 135 | $cc->write_output($filename); | ||
| 136 | } | ||
| 137 | |||
| 138 | 1; | ||
| 139 | |||
| 140 | __END__ |