added export checkbox and timefmt for x axis
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 22 Jun 2010 18:32:08 +0000 (20:32 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 22 Jun 2010 18:32:08 +0000 (20:32 +0200)
lib/MojoFacets/Data.pm
lib/MojoFacets/Gnuplot.pm
templates/data/items.html.ep

index b5a74a6..4ed6d69 100644 (file)
@@ -739,20 +739,22 @@ sub items {
                push @$sorted_items, $row;
        }
 
-       my $export_path = "public/export/$path/" . join('.', @columns);
-       open(my $fh, '>', $export_path) || warn "ERROR: can't open $export_path: $!";
-       foreach my $f ( 0 .. $#$filtered ) {
-               print $fh join("\t", map {
-                       my $i = $data->{items}->[ $filtered->[$f] ];
-                       if ( ref $i->{$_} eq 'ARRAY' ) {
-                               join(',', @{ $i->{$_} });
-                       } else {
-                               dump $i->{$_};
-                       }
-               } @columns),"\n";
+       if ( $self->param('export') ) {
+               my $export_path = "public/export/$path/" . join('.', @columns);
+               open(my $fh, '>', $export_path) || warn "ERROR: can't open $export_path: $!";
+               foreach my $f ( 0 .. $#$filtered ) {
+                       print $fh join("\t", map {
+                               my $i = $data->{items}->[ $filtered->[$f] ];
+                               if ( ref $i->{$_} eq 'ARRAY' ) {
+                                       join(',', @{ $i->{$_} });
+                               } else {
+                                       dump $i->{$_};
+                               }
+                       } @columns),"\n";
+               }
+               close($fh);
+               warn "export $export_path ", -s $export_path, " bytes\n";
        }
-       close($fh);
-       warn "$export_path ", -s $export_path, " bytes\n";
 
        warn "# test_changed ",dump( $test_changed );
        my $c = { map { $_ => 1 } @columns };
index 95aafa2..a33e82f 100644 (file)
@@ -21,7 +21,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 +29,22 @@ sub index {
 set terminal png
 set output '$dir/$url.png'
 
+               |;
+
+               if ( my $timefmt = $self->session('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";
 
index 8b6af63..33ad583 100644 (file)
@@ -46,9 +46,18 @@ items
 
 <input type=submit value="refresh">
 
+% my $export = param('export') || session('export');
+% session('export', $export );
+<input type=checkbox name=export value=1 title="export" <%= $export ? 'checked' : '' %> >
+% my $timefmt = param('timefmt') || session('timefmt');
+% session('timefmt', $timefmt );
+timefmt: <input name=timefmt value="<%= $timefmt %>">
+
 </form>
 
+% if ( $export ) {
 <img id=gnuplot src="/gnuplot">
+% }
 
 <%= include 'data/items/' . session('show') %>