1 #**************************************************************************
2 # Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu> *
4 # This program is free software; you can redistribute it and/or modify *
5 # it under the terms of the GNU General Public License as published by *
6 # the Free Software Foundation; either version 2 of the License, or *
7 # (at your option) any later version. *
9 # This program is distributed in the hope that it will be useful, *
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 # GNU General Public License for more details. *
14 # You should have received a copy of the GNU General Public License *
15 # along with this program; if not, write to the *
16 # Free Software Foundation, Inc., *
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 #**************************************************************************/
20 package ND::Web::Pages::Graph;
23 use CGI qw/:standard/;
27 use base qw/ND::Web::Image/;
29 $ND::Web::Page::PAGES{graph} = 'ND::Web::Pages::Graph';
33 my $DBH = $self->{DBH};
37 if ($self->{URI} =~ m{^/\w+/(stats|ranks)/(.*)}){
39 if ($2 =~ m{(\d+)(?: |:)(\d+)(?:(?: |:)(\d+))?$}){
46 die "Not a proper type" unless defined $type;
48 my %graph_settings = (
49 y_number_format => sub { prettyValue abs $_[0]},
57 $findGraph = $DBH->prepare(q{SELECT graph FROM planet_graphs WHERE planet = planetid($1,$2,$3,$4) AND tick = $4 AND type = $5});
58 $findGraph->execute($x,$y,$z,$ND::TICK,$type) or die $DBH->errstr;
61 if (defined $findGraph and my $graph = $findGraph->fetchrow_hashref){
62 $img = $graph->{graph};
66 if ($type eq 'stats'){
67 $query = $DBH->prepare(q{SELECT tick,score,size,value,xp*60 AS "xp*60" FROM planets natural join planet_stats WHERE id = planetid($1,$2,$3,$4) ORDER BY tick ASC});
68 }elsif($type eq 'ranks'){
69 $query = $DBH->prepare(q{SELECT tick,-scorerank AS score,-sizerank AS size,-valuerank AS value,-xprank AS xp FROM planets natural join planet_stats WHERE id = planetid($1,$2,$3,$4) ORDER BY tick ASC});
71 $query->execute($x,$y,$z,$ND::TICK) or die $DBH->errstr;
73 if ($type eq 'stats'){
74 $query = $DBH->prepare(q{SELECT tick,score,size,value,xp*60 AS "xp*60" FROM galaxies WHERE x = $1 AND y = $2 ORDER BY tick ASC});
75 }elsif($type eq 'ranks'){
76 $query = $DBH->prepare(q{SELECT tick,-scorerank AS score,-sizerank AS size,-valuerank AS value,-xprank AS xp FROM galaxies WHERE x = $1 AND y = $2 ORDER BY tick ASC});
78 $query->execute($x,$y) or die $DBH->errstr;
81 $graph_settings{two_axes} = 1;
82 $graph_settings{use_axis} = [2,1,2,2];
83 $graph_settings{y_max_value} = 0 if $type eq 'ranks';
84 $img = graphFromQuery 500,300,\%graph_settings,$query;
87 die 'no image' unless defined $img;