sub dates {}
sub update_data{}
####
@data0 = @data1 = @data2 = @data3 =([0..200], [300..500]);
####
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
use Tk::Chart;
use Tk::Chart::Lines;
use Tk::Canvas::GradientColor;
use Tk::Pane;
use DBI;
use utf8;
use Tk::DateEntry;
use POSIX qw/strftime/;
use Time::Local;
no warnings qw/uninitialized/;
my ( $mw, $pane );
my ( @data0, @data1, @data2, @data3 );
@data0 = @data1 = @data2 = @data3 = ( [ 0 .. 200 ], [ 300 .. 500 ] );
my $datemin;
my $datemax;
my $color_start = '#ffffff';
#my $color_end = '#DF776F';
my $color_end = '#bbbbbb';
&dates;
my ( $chart0, $chart1, $chart2, $chart3, $xlabelskip );
my ( $powermax, $powermin, $poweravg );
my ( $speedmax, $speedmin, $speedavg, $powersum );
my ( $battmax, $battmin, $battavg );
my ( $powersunmax, $powersunmin, $powersunavg, $powersunsum );
my ( @timeline, @speed, @power, @v_acc, @powersun );
&update_data;
&create_mw;
&set_charts;
&render;
MainLoop();
sub draw_charts {
$chart0->clearchart;
$chart1->clearchart;
$chart2->clearchart;
$chart3->clearchart;
$chart0->destroy;
$chart1->destroy;
$chart2->destroy;
$chart3->destroy;
$mw->destroy;
&create_mw;
&update_data;
&set_charts;
&render;
}
sub render {
$chart0->plot( \@data0 ); #u akb
$chart1->plot( \@data1 ); #sun p
$chart2->plot( \@data2 ); #wind p
$chart3->plot( \@data3 ); #wind speed
unless ($^O =~ /Win32/){
for my $w ( $chart0, $chart1, $chart2, $chart3 ) {
$w->CanvasBind( '<4>', sub { $pane->yview( 'scroll', -3, 'units' ); $w->yviewMoveto(0); return;} );
$w->CanvasBind( '<5>', sub { $pane->yview( 'scroll', 3, 'units' ); $w->yviewMoveto(1); return;} );
}
}
}
sub create_mw {
$mw = MainWindow->new();
$mw->geometry("840x800");
$mw->title("SA wind generation from $datemin to $datemax");
$mw->optionAdd( "*font", "*utf-8" );
$mw->fontCreate(
'giant_rus',
-family => 'nimbus sans l',
-weight => 'normal',
-size => int( -13 * 13 / 10 )
);
$mw->fontCreate(
'tiny_rus',
-family => 'nimbus sans l',
-weight => 'normal',
-size => int( -12 * 12 / 10 )
);
$pane = $mw->Scrolled(qw/Pane -scrollbars e -width 990 -height 960/)->pack;
my $dateframe =
$pane->Frame()->pack( -side => 'top', -anchor => 'nw', -padx => '15' );
my $datelabel = $dateframe->Label(
-text =>
"\x{0414}\x{0438}\x{0430}\x{043f}\x{0430}\x{0439}\x{043e}\x{1085}: ",
-font => 'giant_rus'
)->pack( -side => 'left' );
my @daynames = ();
foreach ( 0 .. 6 ) {
push @daynames, strftime( "%a", 0, 0, 0, 1, 1, 1, $_ );
}
my $datebegin = $dateframe->DateEntry(
-font => 'giant_rus',
-daynames => \@daynames,
-todaybackground => 'green',
-textvariable => \$datemin,
-formatcmd =>
sub { sprintf( "%d-%02d-%02d 00:00:00", $_[0], $_[1], $_[2] ); },
-width => 18
)->pack( -side => 'left' );
my $dateend = $dateframe->DateEntry(
-font => 'giant_rus',
-daynames => \@daynames,
-todaybackground => 'green',
-textvariable => \$datemax,
-formatcmd =>
sub { sprintf( "%d-%02d-%02d 00:00:00", $_[0], $_[1], $_[2] ); },
-width => 18
)->pack( -side => 'left' );
my $buttonok =
$dateframe->Button( -text => 'Ok', -command => \&draw_charts )
->pack( -side => 'left' );
bindmousewheel($pane);
$pane->focus;
for ( $datebegin, $dateend, $buttonok ) {
$_->bind( '', sub { $pane->focus } );
}
}
sub set_charts {
$chart0 = $pane->Lines(
-title =>
"U \x{0430}\x{043a}\x{0431} min: $battmin max: $battmax avg: $battavg (m/s)",
-titlefont => 'giant_rus',
-textfont => 'tiny_rus',
-titleheight => '5',
-xlabelfont => 'tiny_rus',
-ylabelfont => 'tiny_rus',
-ylabel => 'V',
-boxaxis => 1,
-yticknumber => 5,
-linewidth => 2,
-bezier => 1,
-alltickview => 1,
-pointline => 0,
-markers => [ 10, 9, 9 ],
-xtickheight => 5,
-ylongticks => 1,
-ylongtickscolor => 'white',
-xlongticks => 1,
-xlongtickscolor => 'white',
-width => 800,
-height => 220,
-yminvalue => $battmin,
-ymaxvalue => $battmax,
-xlabelskip => $xlabelskip,
)->pack();
$chart0->enabled_gradientcolor();
$chart0->set_gradientcolor(
-start_color => $color_start,
-end_color => $color_end,
-type => 'linear_vertical',
);
$chart3 = $pane->Lines(
-title =>
"\x{0421}\x{043e}\x{043b}\x{043d}\x{0446}\x{0435}\x{0433}\x{0435}\x{043d}\x{0435}\x{0440}\x{0430}\x{0446}\x{0438}\x{044f} min: $powersunmin max: $powersunmax avg: $powersunavg (Wt) sum: $powersunsum (kWt*h)",
-titlefont => 'giant_rus',
-textfont => 'tiny_rus',
-titleheight => '5',
-xlabelfont => 'tiny_rus',
-ylabelfont => 'tiny_rus',
-ylabel => 'P',
-boxaxis => 1,
-yticknumber => 5,
-linewidth => 2,
-bezier => 1,
-alltickview => 1,
-pointline => 0,
-markers => [ 10, 9, 9 ],
-xtickheight => 5,
-ylongticks => 1,
-ylongtickscolor => 'white',
-xlongticks => 1,
-xlongtickscolor => 'white',
-width => 800,
-height => 220,
-yminvalue => $powersunmin,
-ymaxvalue => $powersunmax,
-xlabelskip => $xlabelskip,
-colordata => [qw(orange)],
)->pack();
$chart3->enabled_gradientcolor();
$chart3->set_gradientcolor(
-start_color => $color_start,
-end_color => $color_end,
-type => 'linear_vertical',
);
$chart2 = $pane->Lines(
-title =>
"\x{0412}\x{0435}\x{0442}\x{0440}\x{043e}\x{0433}\x{0435}\x{043d}\x{0435}\x{0440}\x{0430}\x{0446}\x{044f} min: $powermin max: $powermax avg: $poweravg (Wt) sum: $powersum (kWt*h)",
-titlefont => 'giant_rus',
-textfont => 'tiny_rus',
-titleheight => '5',
-xlabelfont => 'tiny_rus',
-ylabelfont => 'tiny_rus',
-ylabel => 'P',
-boxaxis => 1,
-yticknumber => 5,
-linewidth => 2,
-bezier => 1,
-alltickview => 1,
-pointline => 0,
-markers => [ 10, 9, 9 ],
-xtickheight => 5,
-ylongticks => 1,
-ylongtickscolor => 'white',
-xlongticks => 1,
-xlongtickscolor => 'white',
-width => 800,
-height => 220,
-yminvalue => $powermin,
-ymaxvalue => $powermax,
-xlabelskip => $xlabelskip,
-colordata => [qw(blue)],
)->pack();
$chart2->enabled_gradientcolor();
$chart2->set_gradientcolor(
-start_color => $color_start,
-end_color => $color_end,
-type => 'linear_vertical',
);
$chart1 = $pane->Lines(
-title =>
"\x{0421}\x{043a}\x{043e}\x{0440}\x{043e}\x{0441}\x{0442}\x{044c} \x{0432}\x{0435}\x{0442}\x{0440}\x{0430}min: $speedmin max: $speedmax avg: $speedavg (m/s)",
-titlefont => 'giant_rus',
-textfont => 'tiny_rus',
-titleheight => '5',
-xlabelfont => 'tiny_rus',
-ylabelfont => 'tiny_rus',
-ylabel => 'V',
-boxaxis => 1,
-yticknumber => 5,
-linewidth => 2,
-bezier => 1,
-alltickview => 1,
-pointline => 0,
-markers => [ 10, 9, 9 ],
-xtickheight => 5,
-ylongticks => 1,
-ylongtickscolor => 'white',
-xlongticks => 1,
-xlongtickscolor => 'white',
-width => 800,
-height => 220,
-yminvalue => $speedmin,
-ymaxvalue => $speedmax,
-xlabelskip => $xlabelskip,
-colordata => [qw(green)],
)->pack();
$chart1->enabled_gradientcolor();
$chart1->set_gradientcolor(
-start_color => $color_start,
-end_color => $color_end,
-type => 'linear_vertical',
);
}
sub dates { }
sub update_data { }
sub bindmousewheel {
my ($w) = @_;
if ( $^O =~ /Win32/ ) {
$w->bind(
'' => [
sub {
$w->yview( 'scroll', -( $_[1] / 120 ) * 3, 'units' );
},
Ev('D')
]
);
}
else {
$w->bind(
'<4>' => sub {
$w->yview( 'scroll', -3, 'units' ) unless $Tk::strictMotif;
}
);
$w->bind(
'<5>' => sub {
$w->yview( 'scroll', +3, 'units' ) unless $Tk::strictMotif;
}
);
}
}