App/Chart/Series/Indicator.pm

filter: Statementstmt 100% 17 / 17 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 100% 23 / 23 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« App/Chart/Series/Derived/LaguerreFilter.pm ↑ Summary
1 # Copyright 2008, 2009, 2013, 2024 Kevin Ryde
2  
3 # This file is part of Chart.
4 #
5 # Chart is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3, or (at your option) any later version.
8 #
9 # Chart is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12 # details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with Chart. If not, see <http://www.gnu.org/licenses/>.
16  
17 package App::Chart::Series::Indicator;
18 6 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 6 ▶use List::Util qw(min max);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 6 ▶use Locale::TextDomain ('App-Chart');
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 6 ▶use base 'App::Chart::Series';
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 use constant DEBUG => 0;
27  
28 use constant decimals => 0; # none needed normally
29  
30 sub name {
31 my ($self) = @_;
32 my $name = $self->shortname;
33 if (my $parameters = $self->{'parameters'}) {
34 my $parameter_info = $self->parameter_info;
35 my @parameters;
36 foreach my $i (0 .. $#$parameters) {
37 my $pinfo = $parameter_info->[$i];
38 if ($pinfo->{'type'} eq 'boolean') {
39 $parameters[$i] = ($parameters->[$i] ? $pinfo->{'name'} : '');
40 } elsif ($pinfo->{'type'} eq 'float') {
41 # display just 1 decimal is that's enough
42 my $nf = App::Chart::number_formatter();
43 my $value = $parameters->[$i];
44 my $percent = $pinfo->{'type_hint'}//'' eq 'percent';
45 my $decimals = max ($pinfo->{'decimals'} // 0,
46 App::Chart::count_decimals($value));
47 $parameters[$i] = $nf->format_number ($value, $decimals, 1);
48 if ($percent) {
49 $parameters[$i] .= '%';
50 }
51 } else {
52 $parameters[$i] = $parameters->[$i];
53 }
54 }
55 $parameters = join (__p('separator',',') . ' ', @parameters);
56 $name = join (' ', $name, $parameters);
57 }
58 my $parent_name = $self->parent->name;
59 if (defined $parent_name) {
60 $name = join (' - ', $parent_name, $name);
61 }
62 return $name;
63 }
64  
65 sub fill_part_from_proc {
66 my ($self, $lo, $hi) = @_;
67 if (DEBUG) { print "fill_part_from_proc $lo $hi,",
68 " self=$self parent=$self->{'parent'}\n"; }
69 my $parent = $self->{'parent'};
70  
71 my $warmup_count = $self->warmup_count_for_position ($lo);
72 my $start = $parent->find_before ($lo, $warmup_count);
73 $parent->fill ($lo, $hi);
74 my $p = $parent->values_array;
75  
76 my $s = $self->values_array;
77 $hi = min ($hi, $#$p);
78 if ($#$s < $hi) { $#$s = $hi; } # pre-extend
79  
80 my $proc = $self->proc (@{$self->{'parameters'}});
81 if (DEBUG) { print " start $start\n"; }
82  
83 foreach my $i ($start .. $lo-1) {
84 my $value = $p->[$i] // next;
85 $proc->($value);
86 }
87 foreach my $i ($lo .. $hi) {
88 my $value = $p->[$i] // next;
89 $s->[$i] = $proc->($value);
90 }
91 }
92 sub warmup_count_for_position {
93 my ($self, $lo) = @_;
94 return $self->warmup_count (@{$self->{'parameters'}});
95 }
96  
97 1;
98 __END__
« App/Chart/Series/Derived/LaguerreFilter.pm ↑ Summary