even more agressicly script export path
[MojoFacets.git] / lib / MojoFacets / Gnuplot.pm
index 95aafa2..67b484f 100644 (file)
@@ -7,13 +7,19 @@ use base 'Mojolicious::Controller';
 
 use Data::Dump qw(dump);
 use Digest::MD5 qw(md5_hex);
+use Text::Unaccent::PurePerl;
 
 sub index {
        my $self = shift;
 
        my $columns = $self->session('columns') || $self->redirect_to('/data/columns');
 
-       my $url = '/export/' . $self->session('path') . '/' . join('.', @$columns);
+       my $name = unac_string( join('.', 'items', @$columns) );
+       $name =~ s/\W+/_/g;
+
+       warn "# name $name\n";
+
+       my $url = '/export/' . $self->session('path') . '/' . $name;
        my $dir = $self->app->home->rel_dir('public');
 
        if ( -e "$dir/$url" ) {
@@ -21,7 +27,7 @@ sub index {
                my @plot;
                foreach ( 1 .. $#$columns ) {
                        my $n = $_ + 1;
-                       push @plot, qq|"$dir/$url" using 1:$n title "$columns->[$_]" with linespoints|;
+                       push @plot, qq|"$dir/$url" using 1:$n title "$columns->[$_]" with points|;
                }
 
                my $g = qq|
@@ -29,14 +35,22 @@ sub index {
 set terminal png
 set output '$dir/$url.png'
 
+               |;
+
+               if ( my $timefmt = $self->param('timefmt') ) {
+                       $g .= qq|
+
 set xdata time
-set timefmt "%Y-%m-%d"
-#set format x "%d.%m."
-#set format x "%Y-%m-%d"
+set timefmt "$timefmt"
+set format x "$timefmt"
+
+                       |;
+               }
+
 #set xrange [ "2009-01-01":"2010-01-01" ]
 #set yrange [ 0 : ]
 
-plot | . join(',', @plot) . "\n";
+               $g .= "\n\nplot " . join(',', @plot) . "\n";
 
 warn "gnuplot $g";