Issues (459)

src/plot/StockPlot.php (6 issues)

1
<?php
2
3
/**
4
 * JPGraph v4.0.3
5
 */
6
7
namespace Amenadiel\JpGraph\Plot;
8
9
use Amenadiel\JpGraph\Util;
10
11
/**
12
 * File:        JPGRAPH_STOCK.PHP
13
 * // Description: Stock plot extension for JpGraph
14
 * // Created:     2003-01-27
15
 * // Ver:         $Id: jpgraph_stock.php 1364 2009-06-24 07:07:44Z ljp $
16
 * //
17
 * // Copyright (c) Asial Corporation. All rights reserved.
18
 */
19
20
/**
21
 * @class StockPlot
22
 */
23
class StockPlot extends Plot
24
{
25
    protected $iTupleSize = 4;
26
    private $iWidth       = 9;
27
    private $iEndLines    = 1;
28
    private $iStockColor1 = 'white';
29
    private $iStockColor2 = 'darkred';
30
    private $iStockColor3 = 'darkred';
31
32
    /**
33
     * CONSTRUCTOR.
34
     *
35
     * @param mixed $datay
36
     * @param mixed $datax
37
     */
38
    public function __construct($datay, $datax = false)
39
    {
40
        if (safe_count($datay) % $this->iTupleSize) {
41
            Util\JpGraphError::RaiseL(21001, $this->iTupleSize);
42
            //('Data values for Stock charts must contain an even multiple of '.$this->iTupleSize.' data points.');
43
        }
44
        parent::__construct($datay, $datax);
45
        $this->numpoints /= $this->iTupleSize;
46
    }
47
48
    /**
49
     * PUBLIC METHODS.
50
     *
51
     * @param mixed $aColor
52
     * @param mixed $aColor1
53
     * @param mixed $aColor2
54
     * @param mixed $aColor3
55
     */
56
    public function SetColor($aColor, $aColor1 = 'white', $aColor2 = 'darkred', $aColor3 = 'darkred')
57
    {
58
        $this->color        = $aColor;
59
        $this->iStockColor1 = $aColor1;
60
        $this->iStockColor2 = $aColor2;
61
        $this->iStockColor3 = $aColor3;
62
    }
63
64
    public function SetWidth($aWidth)
65
    {
66
        // Make sure it's odd
67
        $this->iWidth = 2 * floor($aWidth / 2) + 1;
68
    }
69
70
    public function HideEndLines($aHide = true)
71
    {
72
        $this->iEndLines = !$aHide;
73
    }
74
75
    // Gets called before any axis are stroked
76
    public function PreStrokeAdjust($graph)
77
    {
78
        if ($this->center) {
79
            $a = 0.5;
80
            $b = 0.5;
81
            ++$this->numpoints;
82
        } else {
83
            $a = 0;
84
            $b = 0;
85
        }
86
        $graph->xaxis->scale->ticks->SetXLabelOffset($a);
87
        $graph->SetTextScaleOff($b);
88
    }
89
90
    // Method description
91
    public function Stroke($img, $xscale, $yscale)
92
    {
93
        $n = $this->numpoints;
94
        if ($this->center) {
95
            --$n;
96
        }
97
98
        if (isset($this->coords[1])) {
99
            if (safe_count($this->coords[1]) != $n) {
100
                Util\JpGraphError::RaiseL(2003, safe_count($this->coords[1]), $n);
101
            // ("Number of X and Y points are not equal. Number of X-points:". safe_count($this->coords[1])." Number of Y-points:$numpoints");
102
            } else {
103
                $exist_x = true;
104
            }
105
        } else {
106
            $exist_x = false;
107
        }
108
109
        if ($exist_x) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $exist_x does not seem to be defined for all execution paths leading up to this point.
Loading history...
110
            $xs = $this->coords[1][0];
0 ignored issues
show
The assignment to $xs is dead and can be removed.
Loading history...
111
        } else {
112
            $xs = 0;
113
        }
114
115
        $ts              = $this->iTupleSize;
116
        $this->csimareas = '';
117
        for ($i = 0; $i < $n; ++$i) {
118
            //If value is NULL, then don't draw a bar at all
119
            if ($this->coords[0][$i * $ts] === null) {
120
                continue;
121
            }
122
123
            if ($exist_x) {
124
                $x = $this->coords[1][$i];
125
                if ($x === null) {
126
                    continue;
127
                }
128
            } else {
129
                $x = $i;
130
            }
131
            $xt = $xscale->Translate($x);
132
133
            $neg    = $this->coords[0][$i * $ts] > $this->coords[0][$i * $ts + 1];
134
            $yopen  = $yscale->Translate($this->coords[0][$i * $ts]);
135
            $yclose = $yscale->Translate($this->coords[0][$i * $ts + 1]);
136
            $ymin   = $yscale->Translate($this->coords[0][$i * $ts + 2]);
137
            $ymax   = $yscale->Translate($this->coords[0][$i * $ts + 3]);
138
139
            $dx = floor($this->iWidth / 2);
140
            $xl = $xt - $dx;
141
            $xr = $xt + $dx;
142
143
            if ($neg) {
144
                $img->SetColor($this->iStockColor3);
145
            } else {
146
                $img->SetColor($this->iStockColor1);
147
            }
148
            $img->FilledRectangle($xl, $yopen, $xr, $yclose);
149
            $img->SetLineWeight($this->weight);
150
            if ($neg) {
151
                $img->SetColor($this->iStockColor2);
152
            } else {
153
                $img->SetColor($this->color);
154
            }
155
156
            $img->Rectangle($xl, $yopen, $xr, $yclose);
157
158
            if ($yopen < $yclose) {
159
                $ytop    = $yopen;
160
                $ybottom = $yclose;
161
            } else {
162
                $ytop    = $yclose;
163
                $ybottom = $yopen;
164
            }
165
            $img->SetColor($this->color);
166
            $img->Line($xt, $ytop, $xt, $ymax);
167
            $img->Line($xt, $ybottom, $xt, $ymin);
168
169
            if ($this->iEndLines) {
170
                $img->Line($xl, $ymax, $xr, $ymax);
171
                $img->Line($xl, $ymin, $xr, $ymin);
172
            }
173
174
            // A chance for subclasses to add things to the bar
175
            // for data point i
176
            $this->ModBox($img, $xscale, $yscale, $i, $xl, $xr, $neg);
177
178
            // Setup image maps
179
            if (!empty($this->csimtargets[$i])) {
180
                $this->csimareas .= '<area shape="rect" coords="' .
181
                round($xl) . ',' . round($ytop) . ',' .
182
                round($xr) . ',' . round($ybottom) . '" ';
183
                $this->csimareas .= ' href="' . $this->csimtargets[$i] . '"';
184
                if (!empty($this->csimalts[$i])) {
185
                    $sval = $this->csimalts[$i];
186
                    $this->csimareas .= " title=\"${sval}\" alt=\"${sval}\" ";
187
                }
188
                $this->csimareas .= "  />\n";
189
            }
190
        }
191
192
        return true;
193
    }
194
195
    // A hook for subclasses to modify the plot
196
    public function ModBox($img, $xscale, $yscale, $i, $xl, $xr, $neg)
0 ignored issues
show
The parameter $neg is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

196
    public function ModBox($img, $xscale, $yscale, $i, $xl, $xr, /** @scrutinizer ignore-unused */ $neg)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $xl is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

196
    public function ModBox($img, $xscale, $yscale, $i, /** @scrutinizer ignore-unused */ $xl, $xr, $neg)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $xr is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

196
    public function ModBox($img, $xscale, $yscale, $i, $xl, /** @scrutinizer ignore-unused */ $xr, $neg)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $i is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

196
    public function ModBox($img, $xscale, $yscale, /** @scrutinizer ignore-unused */ $i, $xl, $xr, $neg)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
197
    {
198
    }
199
} // @class
200