| 1 | package Lab::Moose::DataFile::Gnuplot; | ||||||||||||||||||||||||||||
| 2 | 5 | $Lab::Moose::DataFile::Gnuplot::VERSION = '3.931'; | |||||||||||||||||||||||||||
| 3 | #ABSTRACT: Text based data file ('Gnuplot style') | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use v5.20; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use MooseX::Params::Validate; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Moose::Util::TypeConstraints 'enum'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use PDL::Core qw/topdl/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use Scalar::Util 'looks_like_number'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use Module::Load 'load'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use Lab::Moose::DataFile::Read; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 5 | ▶ | use List::Util 'any'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 5 | ▶ | use Time::HiRes 'time'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 5 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 5 | extends 'Lab::Moose::DataFile'; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 5 | has columns => ( | |||||||||||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||||||||||
| 24 | isa => 'ArrayRef[Str]', | ||||||||||||||||||||||||||||
| 25 | required => 1, | ||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 5 | has num_data_rows => ( | |||||||||||||||||||||||||||
| 29 | is => 'ro', | ||||||||||||||||||||||||||||
| 30 | isa => 'Int', | ||||||||||||||||||||||||||||
| 31 | default => 0, | ||||||||||||||||||||||||||||
| 32 | writer => '_num_data_rows', | ||||||||||||||||||||||||||||
| 33 | init_arg => undef | ||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 5 | has num_blocks => ( | |||||||||||||||||||||||||||
| 37 | is => 'ro', | ||||||||||||||||||||||||||||
| 38 | isa => 'Int', | ||||||||||||||||||||||||||||
| 39 | default => 0, | ||||||||||||||||||||||||||||
| 40 | writer => '_num_blocks', | ||||||||||||||||||||||||||||
| 41 | init_arg => undef, | ||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 5 | has precision => ( | |||||||||||||||||||||||||||
| 45 | is => 'ro', | ||||||||||||||||||||||||||||
| 46 | isa => enum( [ 1 .. 17 ] ), | ||||||||||||||||||||||||||||
| 47 | default => 10, | ||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | has plots => ( | ||||||||||||||||||||||||||||
| 51 | is => 'ro', | ||||||||||||||||||||||||||||
| 52 | isa => 'ArrayRef', | ||||||||||||||||||||||||||||
| 53 | 37 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 54 | 5 | init_arg => undef | |||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 5 | has comment_string => ( | |||||||||||||||||||||||||||
| 58 | is => 'rw', | ||||||||||||||||||||||||||||
| 59 | isa => 'Str', | ||||||||||||||||||||||||||||
| 60 | default => ' ', | ||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 37 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 64 | 37 | my $self = shift; | |||||||||||||||||||||||||||
| 65 | 37 | my @columns = @{ $self->columns() }; | |||||||||||||||||||||||||||
| 66 | 37 | ▶ | if ( @columns == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | croak "need at least one column"; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | 37 | $self->log_comment( comment => $self->comment_string().join( "\t", @columns ) ); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 137 | ▶ | sub log { | ||||||||||||||||||||||||||
|
Subroutine
log: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | 137 | my $self = shift; | |||||||||||||||||||||||||||
| 75 | 137 | $self->_log_bare(@_); | |||||||||||||||||||||||||||
| 76 | 137 | $self->refresh_plots( refresh => 'point' ); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | # Log of one row of data. Do not trigger plots. | ||||||||||||||||||||||||||||
| 80 | 172 | ▶ | sub _log_bare { | ||||||||||||||||||||||||||
|
Subroutine
_log_bare: called CC=7 SCAR=20.3
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | # We do not use MooseX::Params::Validate for performance reasons. | ||||||||||||||||||||||||||||
| 83 | 172 | my $self = shift; | |||||||||||||||||||||||||||
| 84 | 172 | my %args; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 172 | ▶ | if ( ref $_[0] eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | %args = %{ $_[0] }; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | else { | ||||||||||||||||||||||||||||
| 90 | 172 | %args = @_; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 172 | my @columns = @{ $self->columns() }; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 172 | my $line = ""; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 172 | ▶ | while ( my ( $idx, $column ) = each(@columns) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 445 | my $value = delete $args{$column}; | |||||||||||||||||||||||||||
| 99 | 445 | ▶ | if ( not defined $value ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | croak "missing value for column '$column'"; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | 445 | ▶ | if ( not looks_like_number($value) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 0 | croak "value '$value' for column '$column' isn't numeric"; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | 445 | my $precision = $self->precision(); | |||||||||||||||||||||||||||
| 106 | 445 | $line .= sprintf( "%.${precision}g", $value ); | |||||||||||||||||||||||||||
| 107 | 445 | ▶ | if ( $idx != $#columns ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 273 | $line .= "\t"; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | 172 | $line .= "\n"; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 172 | ▶ | if ( keys %args ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | croak "unknown colums in log call: ", join( ' ', keys %args ); | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 172 | my $fh = $self->filehandle(); | |||||||||||||||||||||||||||
| 118 | 172 | print {$fh} $line; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 172 | my $num = $self->num_data_rows; | |||||||||||||||||||||||||||
| 121 | 172 | $self->_num_data_rows( ++$num ); | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 7 | ▶ | sub log_block { | ||||||||||||||||||||||||||
|
Subroutine
log_block: called CC=10 SCAR=25.6
Pod
documented
| |||||||||||||||||||||||||||||
| 126 | 7 | my $self = shift; | |||||||||||||||||||||||||||
| 127 | 7 | my ( $prefix, $block, $add_newline, $refresh_plots ) = validated_list( | |||||||||||||||||||||||||||
| 128 | \@_, | ||||||||||||||||||||||||||||
| 129 | prefix => { isa => 'HashRef[Num]', optional => 1 }, | ||||||||||||||||||||||||||||
| 130 | block => {}, | ||||||||||||||||||||||||||||
| 131 | add_newline => { isa => 'Bool', default => 0 }, | ||||||||||||||||||||||||||||
| 132 | refresh_plots => { isa => 'Bool', default => 0 }, | ||||||||||||||||||||||||||||
| 133 | ); | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 7 | $block = topdl($block); | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 7 | my @dims = $block->dims(); | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 7 | ▶ | if ( @dims == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 140 | 0 | $block = $block->dummy(1); | |||||||||||||||||||||||||||
| 141 | 0 | @dims = $block->dims(); | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | elsif ( @dims != 2 ) { | ||||||||||||||||||||||||||||
| 144 | 0 | croak "log_block needs 1D or 2D piddle"; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 7 | ▶ | my $num_prefix_cols = $prefix ? ( keys %{$prefix} ) : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 7 | my $num_block_cols = $dims[1]; | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 7 | my @columns = @{ $self->columns() }; | |||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 7 | my $num_cols = @columns; | |||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 7 | ▶ | if ( $num_prefix_cols + $num_block_cols != $num_cols ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 0 | croak "need $num_cols columns, got $num_prefix_cols prefix columns" | |||||||||||||||||||||||||||
| 156 | . " and $num_block_cols block columns"; | ||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 7 | my $num_rows = $dims[0]; | |||||||||||||||||||||||||||
| 160 | 7 | for my $i ( 0 .. $num_rows - 1 ) { | |||||||||||||||||||||||||||
| 161 | 35 | my %log; | |||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | # Add prefix columns to %log. | ||||||||||||||||||||||||||||
| 164 | 35 | for my $j ( 0 .. $num_prefix_cols - 1 ) { | |||||||||||||||||||||||||||
| 165 | 35 | my $name = $columns[$j]; | |||||||||||||||||||||||||||
| 166 | 35 | $log{$name} = $prefix->{$name}; | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | # Add block columns to %log. | ||||||||||||||||||||||||||||
| 170 | 35 | for my $j ( 0 .. $num_block_cols - 1 ) { | |||||||||||||||||||||||||||
| 171 | 70 | my $name = $columns[ $j + $num_prefix_cols ]; | |||||||||||||||||||||||||||
| 172 | 70 | $log{$name} = $block->at( $i, $j ); | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | 35 | $self->_log_bare(%log); | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 7 | ▶ | if ($add_newline) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 178 | 0 | $self->new_block(); | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | elsif ($refresh_plots) { | ||||||||||||||||||||||||||||
| 181 | 0 | $self->refresh_plots( refresh => 'block' ); | |||||||||||||||||||||||||||
| 182 | 0 | $self->refresh_plots( refresh => 'point' ); | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 19 | ▶ | sub new_block { | ||||||||||||||||||||||||||
|
Subroutine
new_block: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 188 | 19 | my $self = shift; | |||||||||||||||||||||||||||
| 189 | 19 | my $fh = $self->filehandle; | |||||||||||||||||||||||||||
| 190 | 19 | print {$fh} "\n"; | |||||||||||||||||||||||||||
| 191 | 19 | $self->_num_blocks( $self->num_blocks + 1 ); | |||||||||||||||||||||||||||
| 192 | 19 | $self->refresh_plots( refresh => 'block' ); | |||||||||||||||||||||||||||
| 193 | 19 | $self->refresh_plots( refresh => 'point' ); | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 38 | ▶ | sub log_comment { | ||||||||||||||||||||||||||
|
Subroutine
log_comment: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 198 | 38 | my $self = shift; | |||||||||||||||||||||||||||
| 199 | 38 | my ($comment) = validated_list( | |||||||||||||||||||||||||||
| 200 | \@_, | ||||||||||||||||||||||||||||
| 201 | comment => { isa => 'Str' } | ||||||||||||||||||||||||||||
| 202 | ); | ||||||||||||||||||||||||||||
| 203 | 38 | my @lines = split( "\n", $comment ); | |||||||||||||||||||||||||||
| 204 | 38 | my $fh = $self->filehandle(); | |||||||||||||||||||||||||||
| 205 | 38 | for my $line (@lines) { | |||||||||||||||||||||||||||
| 206 | 38 | print {$fh} "#$line\n"; | |||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 0 | ▶ | sub _add_plot_handle { | ||||||||||||||||||||||||||
|
Subroutine
_add_plot_handle: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 212 | 0 | my ( $self, %args ) = validated_hash( | |||||||||||||||||||||||||||
| 213 | \@_, | ||||||||||||||||||||||||||||
| 214 | plot => { isa => 'Lab::Moose::Plot' }, | ||||||||||||||||||||||||||||
| 215 | type => { isa => enum( [qw/2d pm3d/] ) }, | ||||||||||||||||||||||||||||
| 216 | curves => { isa => 'ArrayRef[HashRef]' }, | ||||||||||||||||||||||||||||
| 217 | legend => { isa => 'Maybe[Str]', optional => 1 }, | ||||||||||||||||||||||||||||
| 218 | refresh => { isa => 'Str' }, | ||||||||||||||||||||||||||||
| 219 | refresh_interval => { isa => 'Lab::Moose::PosNum' }, | ||||||||||||||||||||||||||||
| 220 | ); | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 0 | my $plots = $self->plots(); | |||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 0 | push @{$plots}, { %args, last_refresh_time => time() }; | |||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 0 | ▶ | sub _add_2d_plot { | ||||||||||||||||||||||||||
|
Subroutine
_add_2d_plot: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 228 | 0 | my ( $self, %args ) = validated_hash( | |||||||||||||||||||||||||||
| 229 | \@_, | ||||||||||||||||||||||||||||
| 230 | x => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 231 | y => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 232 | curves => { isa => 'ArrayRef[HashRef]', optional => 1 }, | ||||||||||||||||||||||||||||
| 233 | terminal => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 234 | terminal_options => { isa => 'HashRef', optional => 1 }, | ||||||||||||||||||||||||||||
| 235 | plot_options => { isa => 'HashRef', default => {} }, | ||||||||||||||||||||||||||||
| 236 | curve_options => { isa => 'HashRef', default => {} }, | ||||||||||||||||||||||||||||
| 237 | legend => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 238 | refresh => { isa => 'Str', default => 'point' }, | ||||||||||||||||||||||||||||
| 239 | refresh_interval => { isa => 'Lab::Moose::PosNum', default => 0 }, | ||||||||||||||||||||||||||||
| 240 | ); | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 0 | my $error_msg = "Provide either 'x/y' or 'curves' arguments"; | |||||||||||||||||||||||||||
| 243 | 0 | my $x_column = delete $args{x}; | |||||||||||||||||||||||||||
| 244 | 0 | my $y_column = delete $args{y}; | |||||||||||||||||||||||||||
| 245 | 0 | my $legend_column = delete $args{legend}; | |||||||||||||||||||||||||||
| 246 | 0 | my $curves = delete $args{curves}; | |||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | 0 | my %default_curve_options = ( | |||||||||||||||||||||||||||
| 249 | with => 'points', | ||||||||||||||||||||||||||||
| 250 | ); | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | $args{curve_options} | ||||||||||||||||||||||||||||
| 253 | 0 | = { %default_curve_options, %{ $args{curve_options} } }; | |||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 0 | ▶ | if ( defined $x_column ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 256 | 0 | ▶ | if ( not defined $y_column ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 257 | 0 | croak $error_msg; | |||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | $curves = [ | ||||||||||||||||||||||||||||
| 260 | { | ||||||||||||||||||||||||||||
| 261 | x => $x_column, y => $y_column, | ||||||||||||||||||||||||||||
| 262 | curve_options => $args{curve_options} | ||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||
| 264 | 0 | ]; | |||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||
| 266 | else { | ||||||||||||||||||||||||||||
| 267 | 0 | ▶ | if ( not defined $curves ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 268 | 0 | croak $error_msg; | |||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | 0 | my $refresh = delete $args{refresh}; | |||||||||||||||||||||||||||
| 273 | 0 | my $refresh_interval = delete $args{refresh_interval}; | |||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | my %default_plot_options = ( | ||||||||||||||||||||||||||||
| 276 | xlabel => $curves->[0]->{x}, | ||||||||||||||||||||||||||||
| 277 | ylabel => $curves->[0]->{y}, | ||||||||||||||||||||||||||||
| 278 | 0 | title => $self->path(), | |||||||||||||||||||||||||||
| 279 | grid => 1, | ||||||||||||||||||||||||||||
| 280 | ); | ||||||||||||||||||||||||||||
| 281 | 0 | $args{plot_options} = { %default_plot_options, %{ $args{plot_options} } }; | |||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 0 | my @check_columns = (); | |||||||||||||||||||||||||||
| 284 | 0 | for my $curve ( @{$curves} ) { | |||||||||||||||||||||||||||
| 285 | 0 | push @check_columns, ( $curve->{x}, $curve->{y} ); | |||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||
| 287 | 0 | ▶ | if ( defined $legend_column ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 288 | 0 | push @check_columns, $legend_column; | |||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||
| 290 | 0 | for my $column (@check_columns) { | |||||||||||||||||||||||||||
| 291 | 0 | ▶ | if ( not any { $column eq $_ } @{ $self->columns } ) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 292 | 0 | croak "column $column does not exist"; | |||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | 0 | my $plot = Lab::Moose::Plot->new(%args); | |||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | 0 | $self->_add_plot_handle( | |||||||||||||||||||||||||||
| 299 | plot => $plot, | ||||||||||||||||||||||||||||
| 300 | type => '2d', | ||||||||||||||||||||||||||||
| 301 | curves => $curves, | ||||||||||||||||||||||||||||
| 302 | legend => $legend_column, | ||||||||||||||||||||||||||||
| 303 | refresh => $refresh, | ||||||||||||||||||||||||||||
| 304 | refresh_interval => $refresh_interval, | ||||||||||||||||||||||||||||
| 305 | ); | ||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | 0 | ▶ | sub _add_pm3d_plot { | ||||||||||||||||||||||||||
|
Subroutine
_add_pm3d_plot: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 309 | 0 | my ( $self, %args ) = validated_hash( | |||||||||||||||||||||||||||
| 310 | \@_, | ||||||||||||||||||||||||||||
| 311 | x => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 312 | y => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 313 | z => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 314 | curves => { isa => 'ArrayRef[HashRef]', optional => 1 }, | ||||||||||||||||||||||||||||
| 315 | terminal => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 316 | terminal_options => { isa => 'HashRef', optional => 1 }, | ||||||||||||||||||||||||||||
| 317 | plot_options => { isa => 'HashRef', default => {} }, | ||||||||||||||||||||||||||||
| 318 | curve_options => { isa => 'HashRef', default => {} }, | ||||||||||||||||||||||||||||
| 319 | refresh => { isa => 'Str', default => 'block' }, | ||||||||||||||||||||||||||||
| 320 | refresh_interval => { isa => 'Lab::Moose::PosNum', default => 0 }, | ||||||||||||||||||||||||||||
| 321 | ); | ||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | 0 | my $error_msg = "Provide either 'x/y/z' or 'curves' arguments"; | |||||||||||||||||||||||||||
| 324 | 0 | my $x_column = delete $args{x}; | |||||||||||||||||||||||||||
| 325 | 0 | my $y_column = delete $args{y}; | |||||||||||||||||||||||||||
| 326 | 0 | my $z_column = delete $args{z}; | |||||||||||||||||||||||||||
| 327 | 0 | my $curves = delete $args{curves}; | |||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | 0 | ▶ | if ( defined $x_column ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 330 | 0 | ▶ | if ( not defined $y_column or not defined $z_column ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $y_column and defined $z_column
MC/DC0%0/2
defined $y_column and defined $z_column
defined $y_column
defined $z_column
Truth table0%0/3
A and B
A= defined $y_columnB= defined $z_column
| |||||||||||||||||||||||||||||
| 331 | 0 | croak $error_msg; | |||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||
| 333 | 0 | $curves = [ { x => $x_column, y => $y_column, z => $z_column } ]; | |||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||
| 335 | else { | ||||||||||||||||||||||||||||
| 336 | 0 | ▶ | if ( not defined $curves ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 337 | 0 | croak $error_msg; | |||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | 0 | my $refresh = delete $args{refresh}; | |||||||||||||||||||||||||||
| 342 | 0 | my $refresh_interval = delete $args{refresh_interval}; | |||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | 0 | my %default_plot_options = ( | |||||||||||||||||||||||||||
| 345 | pm3d => 'implicit map corners2color c1', | ||||||||||||||||||||||||||||
| 346 | surface => 0, | ||||||||||||||||||||||||||||
| 347 | xlabel => $x_column, | ||||||||||||||||||||||||||||
| 348 | ylabel => $y_column, | ||||||||||||||||||||||||||||
| 349 | title => $self->path(), | ||||||||||||||||||||||||||||
| 350 | grid => 1, | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | # border => '4095 front linetype -1 linewidth 1.000'); | ||||||||||||||||||||||||||||
| 353 | ); | ||||||||||||||||||||||||||||
| 354 | 0 | my %default_curve_options = (); | |||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | 0 | $args{plot_options} = { %default_plot_options, %{ $args{plot_options} } }; | |||||||||||||||||||||||||||
| 357 | $args{curve_options} | ||||||||||||||||||||||||||||
| 358 | 0 | = { %default_curve_options, %{ $args{curve_options} } }; | |||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | 0 | for my $curve ( @{$curves} ) { | |||||||||||||||||||||||||||
| 361 | 0 | for my $column ( $curve->{x}, $curve->{y}, $curve->{z} ) { | |||||||||||||||||||||||||||
| 362 | 0 | ▶ | if ( not any { $column eq $_ } @{ $self->columns } ) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 363 | 0 | croak "column $column does not exist"; | |||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | 0 | my $plot = Lab::Moose::Plot->new(%args); | |||||||||||||||||||||||||||
| 369 | 0 | $self->_add_plot_handle( | |||||||||||||||||||||||||||
| 370 | plot => $plot, | ||||||||||||||||||||||||||||
| 371 | type => 'pm3d', | ||||||||||||||||||||||||||||
| 372 | curves => $curves, | ||||||||||||||||||||||||||||
| 373 | refresh => $refresh, | ||||||||||||||||||||||||||||
| 374 | refresh_interval => $refresh_interval, | ||||||||||||||||||||||||||||
| 375 | ); | ||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | 0 | ▶ | sub add_plot { | ||||||||||||||||||||||||||
|
Subroutine
add_plot: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||
| 379 | 0 | my ( $self, %args ) = validated_hash( | |||||||||||||||||||||||||||
| 380 | \@_, | ||||||||||||||||||||||||||||
| 381 | type => { isa => 'Str', default => 'points' }, | ||||||||||||||||||||||||||||
| 382 | live => { isa => 'Bool', default => 1 }, # only for testing | ||||||||||||||||||||||||||||
| 383 | hard_copy => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 384 | hard_copy_suffix => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 385 | hard_copy_terminal => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 386 | hard_copy_terminal_options => { isa => 'HashRef', default => {} }, | ||||||||||||||||||||||||||||
| 387 | terminal_options => { isa => 'HashRef', default => {} }, | ||||||||||||||||||||||||||||
| 388 | MX_PARAMS_VALIDATE_ALLOW_EXTRA => 1, | ||||||||||||||||||||||||||||
| 389 | ); | ||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | # only load PDL::Graphics::Gnuplot when needed. No gnuplot is needed | ||||||||||||||||||||||||||||
| 392 | # unless 'add_plot' is called. | ||||||||||||||||||||||||||||
| 393 | 0 | load 'Lab::Moose::Plot'; | |||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | 0 | my $type = delete $args{type}; | |||||||||||||||||||||||||||
| 396 | 0 | my $hard_copy = delete $args{hard_copy}; | |||||||||||||||||||||||||||
| 397 | 0 | my $hard_copy_suffix = delete $args{hard_copy_suffix}; | |||||||||||||||||||||||||||
| 398 | 0 | my $terminal = $args{terminal}; | |||||||||||||||||||||||||||
| 399 | 0 | ▶ | my $hard_copy_terminal = delete $args{hard_copy_terminal} // 'png'; | ||||||||||||||||||||||||||
|
Condition0%0/2
delete $args{"hard_copy_terminal"} // "png"
MC/DC0%0/1
delete $args{"hard_copy_terminal"} // "png"
delete $args{"hard_copy_terminal"}
Truth table0%0/2
A
A= delete $args{"hard_copy_terminal"}
| |||||||||||||||||||||||||||||
| 400 | 0 | my $hard_copy_terminal_options = delete $args{hard_copy_terminal_options}; | |||||||||||||||||||||||||||
| 401 | 0 | my $live = delete $args{live}; | |||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | 0 | ▶ | if ( defined $hard_copy and defined $hard_copy_suffix ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $hard_copy and defined $hard_copy_suffix
MC/DC0%0/2
defined $hard_copy and defined $hard_copy_suffix
defined $hard_copy
defined $hard_copy_suffix
Truth table0%0/3
A and B
A= defined $hard_copyB= defined $hard_copy_suffix
| |||||||||||||||||||||||||||||
| 404 | 0 | croak "Give either 'hard_copy' or 'hard_copy_suffix' parameter"; | |||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | 0 | ▶ | if ( not defined $hard_copy ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 408 | 0 | $hard_copy = $self->filename(); | |||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | # Remove suffix | ||||||||||||||||||||||||||||
| 411 | 0 | $hard_copy =~ s/\.\w*$//; | |||||||||||||||||||||||||||
| 412 | 0 | ▶ | if ( defined $hard_copy_suffix ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 413 | 0 | $hard_copy .= $hard_copy_suffix; | |||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||
| 415 | 0 | $hard_copy .= ".$hard_copy_terminal"; | |||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | 0 | my %default_terminal_options; | |||||||||||||||||||||||||||
| 419 | 0 | ▶ | if ( not( defined $terminal and $terminal eq 'dumb' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $terminal and $terminal eq "dumb"
MC/DC0%0/2
defined $terminal and $terminal eq "dumb"
defined $terminal
$terminal eq "dumb"
Truth table0%0/3
A and B
A= defined $terminalB= $terminal eq "dumb"
| |||||||||||||||||||||||||||||
| 420 | 0 | %default_terminal_options | |||||||||||||||||||||||||||
| 421 | = ( enhanced => 0, raise => 0, persist => 1 ); | ||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | $args{terminal_options} | ||||||||||||||||||||||||||||
| 425 | 0 | = { %default_terminal_options, %{ $args{terminal_options} } }; | |||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | # Set enhanced to 0: png terminal needs to draw underscores in title | ||||||||||||||||||||||||||||
| 428 | 0 | my %default_hard_copy_terminal_options = ( enhanced => 0 ); | |||||||||||||||||||||||||||
| 429 | $hard_copy_terminal_options = { | ||||||||||||||||||||||||||||
| 430 | %default_hard_copy_terminal_options, | ||||||||||||||||||||||||||||
| 431 | 0 | %{$hard_copy_terminal_options} | |||||||||||||||||||||||||||
| 432 | }; | ||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||
| 434 | 0 | my $plot_generator_sub; | |||||||||||||||||||||||||||
| 435 | 0 | ▶ | if ( $type =~ /points?/i ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 436 | 0 | $plot_generator_sub = '_add_2d_plot'; | |||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||
| 438 | elsif ( $type =~ /pm3d/i ) { | ||||||||||||||||||||||||||||
| 439 | 0 | $plot_generator_sub = '_add_pm3d_plot'; | |||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||
| 441 | else { | ||||||||||||||||||||||||||||
| 442 | 0 | croak "unknown plot type '$type'"; | |||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | 0 | ▶ | if ($live) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 446 | 0 | $self->$plot_generator_sub(%args); | |||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | # add hard copy plot. Use Lab::Moose::DataFile to ensure that | ||||||||||||||||||||||||||||
| 450 | # no filename is used twice and content is overwritten. | ||||||||||||||||||||||||||||
| 451 | 0 | my $hard_copy_file = Lab::Moose::DataFile->new( | |||||||||||||||||||||||||||
| 452 | folder => $self->folder(), | ||||||||||||||||||||||||||||
| 453 | filename => $hard_copy, | ||||||||||||||||||||||||||||
| 454 | ); | ||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | 0 | delete $args{terminal}; | |||||||||||||||||||||||||||
| 457 | 0 | delete $args{terminal_options}; | |||||||||||||||||||||||||||
| 458 | 0 | my $hard_copy_path = $hard_copy_file->path(); | |||||||||||||||||||||||||||
| 459 | 0 | ▶ | if ( $hard_copy_path =~ /\\/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 460 | 0 | carp | |||||||||||||||||||||||||||
| 461 | "gnuplot on windows has problems with '\\' character. (hard copy filename: $hard_copy_path"; | ||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||
| 463 | $self->$plot_generator_sub( | ||||||||||||||||||||||||||||
| 464 | terminal => $hard_copy_terminal, | ||||||||||||||||||||||||||||
| 465 | terminal_options => { | ||||||||||||||||||||||||||||
| 466 | 0 | output => $hard_copy_file->path(), %{$hard_copy_terminal_options} | |||||||||||||||||||||||||||
| 467 | }, | ||||||||||||||||||||||||||||
| 468 | %args, | ||||||||||||||||||||||||||||
| 469 | ); | ||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | 0 | ▶ | sub _refresh_plot { | ||||||||||||||||||||||||||
|
Subroutine
_refresh_plot: not called CC=15 SCAR=54.8
| |||||||||||||||||||||||||||||
| 473 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 474 | 0 | my ( $index, $force ) = validated_list( | |||||||||||||||||||||||||||
| 475 | \@_, | ||||||||||||||||||||||||||||
| 476 | index => { isa => 'Int' }, | ||||||||||||||||||||||||||||
| 477 | force => { isa => 'Bool' }, | ||||||||||||||||||||||||||||
| 478 | ); | ||||||||||||||||||||||||||||
| 479 | 0 | my $plots = $self->plots(); | |||||||||||||||||||||||||||
| 480 | 0 | my $plot = $plots->[$index]; | |||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||
| 482 | # Is it time to replot? | ||||||||||||||||||||||||||||
| 483 | 0 | ▶ | if ( not $force | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $force and &Lab::Moose::DataFile::Gnuplot::time() - $plot->{"last_refresh_time"} < $plot->{"refresh_interval"}
MC/DC0%0/2
not $force and &Lab::Moose::DataFile::Gnuplot::time() - $plot->{"last_refresh_time"} < $plot->{"refresh_interval"}
not $force
&Lab::Moose::DataFile::Gnuplot::time() - $plot->{"last_refresh_time"} < $plot->{"refresh_interval"}
Truth table0%0/3
not(A) and B
A= not $forceB= &Lab::Moose::DataFile::Gnuplot::time() - $plot->{"last_refresh_time"} < $plot->{"refresh_interval"}
| |||||||||||||||||||||||||||||
| 484 | and time() - $plot->{last_refresh_time} < $plot->{refresh_interval} ) | ||||||||||||||||||||||||||||
| 485 | { | ||||||||||||||||||||||||||||
| 486 | 0 | return; | |||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||
| 488 | 0 | $plot->{last_refresh_time} = time(); | |||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||
| 490 | 0 | ▶ | if ( not defined $plot ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 491 | 0 | croak "no plot with name at index $index"; | |||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||
| 494 | 0 | my $type = $plot->{type}; | |||||||||||||||||||||||||||
| 495 | 0 | my $legend_column = $plot->{legend}; | |||||||||||||||||||||||||||
| 496 | 0 | my @curves = @{ $plot->{curves} }; | |||||||||||||||||||||||||||
| 497 | 0 | my $column_names = $self->columns(); | |||||||||||||||||||||||||||
| 498 | 0 | my $num_columns = @{ $self->columns() }; | |||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||
| 500 | 0 | ▶ | if ( $self->num_data_rows() < 2 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 501 | 0 | return; | |||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||
| 504 | 0 | my @data; | |||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||
| 506 | 0 | ▶ | if ( $type eq '2d' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 507 | 0 | my $blocks = read_gnuplot_format( | |||||||||||||||||||||||||||
| 508 | type => 'bare', | ||||||||||||||||||||||||||||
| 509 | fh => $self->filehandle(), | ||||||||||||||||||||||||||||
| 510 | num_columns => $num_columns, | ||||||||||||||||||||||||||||
| 511 | ); | ||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||
| 513 | # $block is 3d PDL with dimensions (column, line, block) | ||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||
| 515 | # split along last dimension | ||||||||||||||||||||||||||||
| 516 | 0 | my @blocks = $blocks->dog(); | |||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||
| 518 | 0 | my $legend_index; | |||||||||||||||||||||||||||
| 519 | 0 | ▶ | if ( defined $legend_column ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 520 | ($legend_index) | ||||||||||||||||||||||||||||
| 521 | 0 | = grep { $column_names->[$_] eq $legend_column } | |||||||||||||||||||||||||||
| 522 | 0 | 0 .. $#{$column_names}; | |||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||
| 525 | # draw separate line for each curve | ||||||||||||||||||||||||||||
| 526 | 0 | for my $curve (@curves) { | |||||||||||||||||||||||||||
| 527 | 0 | my $x = $curve->{x}; | |||||||||||||||||||||||||||
| 528 | 0 | my $y = $curve->{y}; | |||||||||||||||||||||||||||
| 529 | 0 | ▶ | my $curve_options = $curve->{curve_options} // {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$curve->{"curve_options"} // {}
MC/DC0%0/1
$curve->{"curve_options"} // {}
$curve->{"curve_options"}
Truth table0%0/2
A
A= $curve->{"curve_options"}
| |||||||||||||||||||||||||||||
| 530 | my ($x_index) | ||||||||||||||||||||||||||||
| 531 | 0 | = grep { $column_names->[$_] eq $x } 0 .. $#{$column_names}; | |||||||||||||||||||||||||||
| 532 | my ($y_index) | ||||||||||||||||||||||||||||
| 533 | 0 | = grep { $column_names->[$_] eq $y } 0 .. $#{$column_names}; | |||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||
| 535 | # draw separate line for each block | ||||||||||||||||||||||||||||
| 536 | 0 | for my $block (@blocks) { | |||||||||||||||||||||||||||
| 537 | 0 | my %curve_options = %{$curve_options}; | |||||||||||||||||||||||||||
| 538 | 0 | ▶ | if ( defined $legend_column ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 539 | 0 | my $legend_value = $block->at( $legend_index, 0 ); | |||||||||||||||||||||||||||
| 540 | 0 | %curve_options = ( %curve_options, legend => | |||||||||||||||||||||||||||
| 541 | sprintf( "$legend_column = %g", $legend_value ) ); | ||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||
| 543 | 0 | push @data, | |||||||||||||||||||||||||||
| 544 | ( | ||||||||||||||||||||||||||||
| 545 | {%curve_options}, $block->slice("$x_index,:")->flat, | ||||||||||||||||||||||||||||
| 546 | $block->slice("$y_index,:")->flat | ||||||||||||||||||||||||||||
| 547 | ); | ||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||
| 551 | 0 | $plot->{plot}->plot( data => \@data ); | |||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||
| 553 | elsif ( $type eq 'pm3d' ) { | ||||||||||||||||||||||||||||
| 554 | 0 | ▶ | if ( $self->num_blocks < 2 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 555 | 0 | return; | |||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||
| 557 | 0 | my @pixel_fields = read_gnuplot_format( | |||||||||||||||||||||||||||
| 558 | type => 'maps', | ||||||||||||||||||||||||||||
| 559 | fh => $self->filehandle(), | ||||||||||||||||||||||||||||
| 560 | num_columns => $num_columns, | ||||||||||||||||||||||||||||
| 561 | ); | ||||||||||||||||||||||||||||
| 562 | 0 | for my $curve (@curves) { | |||||||||||||||||||||||||||
| 563 | 0 | my $x = $curve->{x}; | |||||||||||||||||||||||||||
| 564 | 0 | my $y = $curve->{y}; | |||||||||||||||||||||||||||
| 565 | 0 | my $z = $curve->{z}; | |||||||||||||||||||||||||||
| 566 | 0 | ▶ | my $curve_options = $curve->{curve_options} // {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$curve->{"curve_options"} // {}
MC/DC0%0/1
$curve->{"curve_options"} // {}
$curve->{"curve_options"}
Truth table0%0/2
A
A= $curve->{"curve_options"}
| |||||||||||||||||||||||||||||
| 567 | my ($x_index) | ||||||||||||||||||||||||||||
| 568 | 0 | = grep { $column_names->[$_] eq $x } 0 .. $#{$column_names}; | |||||||||||||||||||||||||||
| 569 | my ($y_index) | ||||||||||||||||||||||||||||
| 570 | 0 | = grep { $column_names->[$_] eq $y } 0 .. $#{$column_names}; | |||||||||||||||||||||||||||
| 571 | my ($z_index) | ||||||||||||||||||||||||||||
| 572 | 0 | = grep { $column_names->[$_] eq $z } 0 .. $#{$column_names}; | |||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||
| 574 | 0 | push @data, | |||||||||||||||||||||||||||
| 575 | ( | ||||||||||||||||||||||||||||
| 576 | $curve_options, | ||||||||||||||||||||||||||||
| 577 | @pixel_fields[ $x_index, $y_index, $z_index ] | ||||||||||||||||||||||||||||
| 578 | ); | ||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||
| 580 | 0 | $plot->{plot}->splot( data => \@data ); | |||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||
| 582 | else { | ||||||||||||||||||||||||||||
| 583 | 0 | croak "unknown plot type '$type'"; | |||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||
| 589 | 171 | ▶ | sub refresh_plots { | ||||||||||||||||||||||||||
|
Subroutine
refresh_plots: called CC=6 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 590 | 171 | my $self = shift; | |||||||||||||||||||||||||||
| 591 | 171 | my ( $refresh, $force ) = validated_list( | |||||||||||||||||||||||||||
| 592 | \@_, | ||||||||||||||||||||||||||||
| 593 | refresh => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 594 | force => { isa => 'Bool', default => 0 }, | ||||||||||||||||||||||||||||
| 595 | ); | ||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||
| 597 | 171 | my @plots = @{ $self->plots() }; | |||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||
| 599 | 171 | my @indices; | |||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||
| 601 | 171 | ▶ | if ( defined $refresh ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 602 | 171 | for my $index ( 0 .. $#plots ) { | |||||||||||||||||||||||||||
| 603 | 0 | my $plot = $plots[$index]; | |||||||||||||||||||||||||||
| 604 | 0 | ▶ | if ( defined $plot->{refresh} and $plot->{refresh} eq $refresh ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $plot->{"refresh"} and $plot->{"refresh"} eq $refresh
MC/DC0%0/2
defined $plot->{"refresh"} and $plot->{"refresh"} eq $refresh
defined $plot->{"refresh"}
$plot->{"refresh"} eq $refresh
Truth table0%0/3
A and B
A= defined $plot->{"refresh"}B= $plot->{"refresh"} eq $refresh
| |||||||||||||||||||||||||||||
| 605 | 0 | push @indices, $index; | |||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||
| 610 | else { | ||||||||||||||||||||||||||||
| 611 | 0 | @indices = ( 0 .. $#plots ); | |||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||
| 614 | 171 | for my $index (@indices) { | |||||||||||||||||||||||||||
| 615 | 0 | $self->_refresh_plot( index => $index, force => $force ); | |||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||
| 619 | 5 | __PACKAGE__->meta->make_immutable(); | |||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||
| 621 | 5 | 1; | |||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||
| 623 | __END__ | ||||||||||||||||||||||||||||