1 package MojoFacets::Gnuplot;
6 use base 'Mojolicious::Controller';
8 use Data::Dump qw(dump);
9 use Digest::MD5 qw(md5_hex);
10 use Text::Unaccent::PurePerl;
16 my $columns = $self->session('columns') || return $self->redirect_to('/data/columns');
17 my $path = $self->session('path') || return $self->redirect_to('/data/load');
18 my $with = $self->param('with') || 'points';
20 my $gnuplot_hide = $self->every_param('gnuplot_hide');
21 warn "## gnuplot_hide=",dump( $gnuplot_hide );
23 $hide_columns->{$_}++ foreach @$gnuplot_hide;
24 warn "## hide_columns ", dump $hide_columns;
26 # my $name = join('.', 'items', map { my $n = unac_string($_); $n =~ s/\W+/_/g; $n } @$columns );
27 my $name = MojoFacets::Data::__export_path_name( $path, 'items', @$columns );
29 warn "# name $name\n";
31 my $url = "/export/$path/$name";
32 my $dir = $self->app->home->rel_file('public');
34 if ( -e "$dir/$url" ) {
36 my $timefmt = $self->param('timefmt');
38 my $spaces = $timefmt;
40 $spaces = length( $spaces );
43 foreach ( 1 .. $#$columns ) {
44 my $title = $columns->[$_];
45 next if $hide_columns->{$title};
47 my $n = $_ + 1 + $spaces;
48 push @plot, qq|"$dir/$url" using 1:$n title "$title" with $with| unless $hide_columns->{ $title };
54 set output '$dir/$url.png'
62 set timefmt "$timefmt"
63 set format x "$timefmt"
68 #set xrange [ "2009-01-01":"2010-01-01" ]
71 $g .= "\n\nplot " . join(',', @plot) . "\n";
76 open(my $gnuplot, '|-', 'gnuplot') || die "gnuplot $!";
80 if ( -e "$dir/$url.png" ) {
81 warn "redirect $url.png";
82 return $self->redirect_to( "$url.png" );
84 $self->render_text( "no $dir/$url.png" );
87 $self->render_text("no graph for $url");