X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=lib%2FMojoFacets%2FGnuplot.pm;h=12e8bcad5d078814d98a7d60783214c95742b671;hb=HEAD;hp=7f8ab08cab80ad8b5391c1cd728ff3db32475250;hpb=304597a2a8795434601c012065e6a113ec55931c;p=MojoFacets.git diff --git a/lib/MojoFacets/Gnuplot.pm b/lib/MojoFacets/Gnuplot.pm index 7f8ab08..12e8bca 100644 --- a/lib/MojoFacets/Gnuplot.pm +++ b/lib/MojoFacets/Gnuplot.pm @@ -8,36 +8,69 @@ use base 'Mojolicious::Controller'; use Data::Dump qw(dump); use Digest::MD5 qw(md5_hex); use Text::Unaccent::PurePerl; +use MojoFacets::Data; sub index { my $self = shift; - my $columns = $self->session('columns') || $self->redirect_to('/data/columns'); + my $columns = $self->session('columns') || return $self->redirect_to('/data/columns'); + my $path = $self->session('path') || return $self->redirect_to('/data/load'); + my $with = $self->param('with') || 'points'; - my $url = '/export/' . $self->session('path') . '/' . unac_string( join('.', 'items', @$columns) ); - my $dir = $self->app->home->rel_dir('public'); + my $gnuplot_hide = $self->every_param('gnuplot_hide'); + warn "## gnuplot_hide=",dump( $gnuplot_hide ); + my $hide_columns; + $hide_columns->{$_}++ foreach @$gnuplot_hide; + warn "## hide_columns ", dump $hide_columns; + +# my $name = join('.', 'items', map { my $n = unac_string($_); $n =~ s/\W+/_/g; $n } @$columns ); + my $name = MojoFacets::Data::__export_path_name( $path, 'items', @$columns ); + + warn "# name $name\n"; + + my $url = "/export/$path/$name"; + my $dir = $self->app->home->rel_file('public'); if ( -e "$dir/$url" ) { + my $timefmt = $self->param('timefmt'); + + my $timefmt_x = $timefmt; + $timefmt_x =~ s/[ T]%H/\\n%H/; + + my $spaces = $timefmt; + $spaces =~ s/\S+//g; +warn "# spaces: [$spaces]",dump( $spaces ); + $spaces = length( $spaces ); +warn "# spaces: $spaces"; + my @plot; foreach ( 1 .. $#$columns ) { - my $n = $_ + 1; - push @plot, qq|"$dir/$url" using 1:$n title "$columns->[$_]" with points|; + my $title = $columns->[$_]; + next if $hide_columns->{$title}; + $title =~ s/_/ /g; + next if $hide_columns->{ $title }; + + my $n = $_ + 1 + $spaces; + push @plot, qq|"$dir/$url" using 1:$n notitle with $with lc $_ pt 7 ps 0.5|, # pt 7 - circle, ps 2 - size 2 + qq|NaN lc $_ title "$title" with lines| + ; } my $g = qq| -set terminal png +set terminal png size 1000,400 set output '$dir/$url.png' |; - if ( my $timefmt = $self->param('timefmt') ) { + if ( $timefmt ) { $g .= qq| set xdata time set timefmt "$timefmt" -set format x "$timefmt" +#set format x "$timefmt" +set format x "$timefmt_x" |; } @@ -46,6 +79,7 @@ set format x "$timefmt" #set yrange [ 0 : ] $g .= "\n\nplot " . join(',', @plot) . "\n"; + $g =~ s/\n\n+/\n/sg; warn "gnuplot $g"; @@ -53,8 +87,12 @@ warn "gnuplot $g"; print $gnuplot $g; close $gnuplot; - $self->redirect_to( "$url.png" ); - #$self->render_text( "$url.png" ); + if ( -e "$dir/$url.png" ) { + warn "redirect $url.png"; + return $self->redirect_to( "$url.png" ); + } else { + $self->render_text( "no $dir/$url.png" ); + } } else { $self->render_text("no graph for $url"); }