Issues (459)

src/plot/FieldPlot.php (1 issue)

1
<?php
2
3
/**
4
 * JPGraph v4.0.3
5
 */
6
7
namespace Amenadiel\JpGraph\Plot;
8
9
use Amenadiel\JpGraph\Image;
10
use Amenadiel\JpGraph\Util;
11
12
/**
13
 * @class FieldPlot
14
 * // Description: Render a field plot
15
 */
16
class FieldPlot extends Plot
17
{
18
    public $arrow      = '';
19
    private $iAngles   = [];
20
    private $iCallback = '';
21
22 1
    public function __construct($datay, $datax, $angles)
23
    {
24 1
        if ((safe_count($datax) != safe_count($datay))) {
25
            Util\JpGraphError::RaiseL(20001);
26
        }
27
        //("Fieldplots must have equal number of X and Y points.");
28 1
        if ((safe_count($datax) != safe_count($angles))) {
29
            Util\JpGraphError::RaiseL(20002);
30
        }
31
        //("Fieldplots must have an angle specified for each X and Y points.");
32
33 1
        $this->iAngles = $angles;
34
35 1
        parent::__construct($datay, $datax);
36 1
        $this->value->SetAlign('center', 'center');
37 1
        $this->value->SetMargin(15);
38
39 1
        $this->arrow = new Image\FieldArrow();
40 1
    }
41
42 1
    public function SetCallback($aFunc)
43
    {
44 1
        $this->iCallback = $aFunc;
45 1
    }
46
47 1
    public function Stroke($img, $xscale, $yscale)
48
    {
49
        // Remeber base color and size
50 1
        $bc  = $this->arrow->iColor;
51 1
        $bs  = $this->arrow->iSize;
52 1
        $bas = $this->arrow->iArrowSize;
53
54 1
        for ($i = 0; $i < $this->numpoints; ++$i) {
55
            // Skip null values
56 1
            if ($this->coords[0][$i] === '') {
57
                continue;
58
            }
59
60 1
            $f = $this->iCallback;
61 1
            if ($f != '') {
62 1
                list($cc, $cs, $cas) = call_user_func($f, $this->coords[1][$i], $this->coords[0][$i], $this->iAngles[$i]);
63
                // Fall back on global data if the callback isn't set
64 1
                if ($cc == '') {
65
                    $cc = $bc;
66
                }
67
68 1
                if ($cs == '') {
69 1
                    $cs = $bs;
70
                }
71
72 1
                if ($cas == '') {
73 1
                    $cas = $bas;
74
                }
75
76 1
                $this->arrow->SetColor($cc);
77 1
                $this->arrow->SetSize($cs, $cas);
78
            }
79
80 1
            $xt = $xscale->Translate($this->coords[1][$i]);
81 1
            $yt = $yscale->Translate($this->coords[0][$i]);
82
83 1
            $this->arrow->Stroke($img, $xt, $yt, $this->iAngles[$i]);
84 1
            $this->value->Stroke($img, $this->coords[0][$i], $xt, $yt);
85
        }
86 1
    }
87
88
    // Framework function
89 1
    public function Legend($aGraph)
90
    {
91 1
        if ($this->legend != '') {
92
            $aGraph->legend->Add(
93
                $this->legend,
94
                $this->mark->fill_color,
0 ignored issues
show
Bug Best Practice introduced by
The property mark does not exist on Amenadiel\JpGraph\Plot\FieldPlot. Did you maybe forget to declare it?
Loading history...
95
                $this->mark,
96
                0,
97
                $this->legendcsimtarget,
98
                $this->legendcsimalt,
99
                $this->legendcsimwintarget
100
            );
101
        }
102 1
    }
103
}
104