X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=lib%2FMojoFacets%2FGnuplot.pm;h=1af3cc1d830c56a092e9269069918e809eaa2513;hb=930f8527c112615ec45556c5f533d1f229ed6fd4;hp=47c721fc4365ef4af312afb3189c4d6bbbec5ff0;hpb=2b53c44078d50732922110457c903c2926a0d2b5;p=MojoFacets.git diff --git a/lib/MojoFacets/Gnuplot.pm b/lib/MojoFacets/Gnuplot.pm index 47c721f..1af3cc1 100644 --- a/lib/MojoFacets/Gnuplot.pm +++ b/lib/MojoFacets/Gnuplot.pm @@ -12,17 +12,37 @@ use Text::Unaccent::PurePerl; 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 $hide_columns; + if ( $self->param('gnuplot_hide') ) { + $hide_columns->{$_}++ foreach $self->param('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/' . $self->session('path') . '/' . unac_string( join('.', 'items', @$columns) ); - my $dir = $self->app->home->rel_dir('public'); + my $url = "/export/$path/$name"; + my $dir = $self->app->home->rel_file('public'); if ( -e "$dir/$url" ) { + my $timefmt = $self->param('timefmt'); + + my $spaces = $timefmt; + $spaces =~ s/\S//g; + $spaces = length( $spaces ); + my @plot; foreach ( 1 .. $#$columns ) { - my $n = $_ + 1; - push @plot, qq|"$dir/$url" using 1:$n title "$columns->[$_]" with points|; + my $title = $columns->[$_]; + my $n = $_ + 1 + $spaces; + push @plot, qq|"$dir/$url" using 1:$n title "$title" with $with| unless $hide_columns->{ $title }; } my $g = qq| @@ -32,7 +52,7 @@ set output '$dir/$url.png' |; - if ( my $timefmt = $self->session('timefmt') ) { + if ( $timefmt ) { $g .= qq| set xdata time @@ -53,8 +73,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"); }