|
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_POLAR.PHP |
|
13
|
|
|
* // Description: Polar plot extension for JpGraph |
|
14
|
|
|
* // Created: 2003-02-02 |
|
15
|
|
|
* // Ver: $Id: jpgraph_polar.php 1796 2009-09-07 09:37:19Z ljp $ |
|
16
|
|
|
* // |
|
17
|
|
|
* // Copyright (c) Asial Corporation. All rights reserved. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
defined('POLAR_360') || define('POLAR_360', 1); |
|
21
|
|
|
defined('POLAR_180') || define('POLAR_180', 2); |
|
22
|
|
|
|
|
23
|
|
|
// |
|
24
|
|
|
// Note. Don't attempt to make sense of this code. |
|
25
|
|
|
// In order not to have to be able to inherit the scaling code |
|
26
|
|
|
// from the main graph package we have had to make some "tricks" since |
|
27
|
|
|
// the original scaling and axis was not designed to do what is |
|
28
|
|
|
// required here. |
|
29
|
|
|
// There were two option. 1: Re-implement everything and get a clean design |
|
30
|
|
|
// and 2: do some "small" trickery and be able to inherit most of |
|
31
|
|
|
// the functionlity from the main graph package. |
|
32
|
|
|
// We choose 2: here in order to save some time. |
|
33
|
|
|
// |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @class PolarPlot |
|
37
|
|
|
*/ |
|
38
|
|
|
class PolarPlot |
|
39
|
|
|
{ |
|
40
|
|
|
public $line_style = 'solid'; |
|
41
|
|
|
public $mark; |
|
42
|
|
|
public $legendcsimtarget = ''; |
|
43
|
|
|
public $legendcsimalt = ''; |
|
44
|
|
|
public $legend = ''; |
|
45
|
|
|
public $csimtargets = []; // Array of targets for CSIM |
|
46
|
|
|
public $csimareas = ''; // Resultant CSIM area tags |
|
47
|
|
|
public $csimalts; // ALT:s for corresponding target |
|
48
|
|
|
public $scale; |
|
49
|
|
|
private $numpoints = 0; |
|
50
|
|
|
private $iColor = 'navy'; |
|
51
|
|
|
private $iFillColor = ''; |
|
52
|
|
|
private $iLineWeight = 1; |
|
53
|
|
|
private $coord; |
|
54
|
|
|
|
|
55
|
|
|
public function __construct($aData) |
|
56
|
|
|
{ |
|
57
|
|
|
$n = safe_count($aData); |
|
58
|
|
|
if ($n & 1) { |
|
59
|
|
|
Util\JpGraphError::RaiseL(17001); |
|
60
|
|
|
//('Polar plots must have an even number of data point. Each data point is a tuple (angle,radius).'); |
|
61
|
|
|
} |
|
62
|
|
|
$this->numpoints = $n / 2; |
|
63
|
|
|
$this->coord = $aData; |
|
64
|
|
|
$this->mark = new PlotMark(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function SetWeight($aWeight) |
|
68
|
|
|
{ |
|
69
|
|
|
$this->iLineWeight = $aWeight; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function SetColor($aColor) |
|
73
|
|
|
{ |
|
74
|
|
|
$this->iColor = $aColor; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function SetFillColor($aColor) |
|
78
|
|
|
{ |
|
79
|
|
|
$this->iFillColor = $aColor; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function Max() |
|
83
|
|
|
{ |
|
84
|
|
|
$m = $this->coord[1]; |
|
85
|
|
|
$i = 1; |
|
86
|
|
|
while ($i < $this->numpoints) { |
|
87
|
|
|
$m = max($m, $this->coord[2 * $i + 1]); |
|
88
|
|
|
++$i; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
return $m; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
// Set href targets for CSIM |
|
95
|
|
|
public function SetCSIMTargets($aTargets, $aAlts = null) |
|
96
|
|
|
{ |
|
97
|
|
|
$this->csimtargets = $aTargets; |
|
98
|
|
|
$this->csimalts = $aAlts; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
// Get all created areas |
|
102
|
|
|
public function GetCSIMareas() |
|
103
|
|
|
{ |
|
104
|
|
|
return $this->csimareas; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function SetLegend($aLegend, $aCSIM = '', $aCSIMAlt = '') |
|
108
|
|
|
{ |
|
109
|
|
|
$this->legend = $aLegend; |
|
110
|
|
|
$this->legendcsimtarget = $aCSIM; |
|
111
|
|
|
$this->legendcsimalt = $aCSIMAlt; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
// Private methods |
|
115
|
|
|
|
|
116
|
|
|
public function Legend($aGraph) |
|
117
|
|
|
{ |
|
118
|
|
|
$color = $this->iColor; |
|
119
|
|
|
if ($this->legend != '') { |
|
120
|
|
|
if ($this->iFillColor != '') { |
|
121
|
|
|
$color = $this->iFillColor; |
|
122
|
|
|
$aGraph->legend->Add( |
|
123
|
|
|
$this->legend, |
|
124
|
|
|
$color, |
|
125
|
|
|
$this->mark, |
|
126
|
|
|
0, |
|
127
|
|
|
$this->legendcsimtarget, |
|
128
|
|
|
$this->legendcsimalt |
|
129
|
|
|
); |
|
130
|
|
|
} else { |
|
131
|
|
|
$aGraph->legend->Add( |
|
132
|
|
|
$this->legend, |
|
133
|
|
|
$color, |
|
134
|
|
|
$this->mark, |
|
135
|
|
|
$this->line_style, |
|
136
|
|
|
$this->legendcsimtarget, |
|
137
|
|
|
$this->legendcsimalt |
|
138
|
|
|
); |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
public function Stroke($img, $scale) |
|
144
|
|
|
{ |
|
145
|
|
|
$i = 0; |
|
146
|
|
|
$p = []; |
|
147
|
|
|
$this->csimareas = ''; |
|
148
|
|
|
while ($i < $this->numpoints) { |
|
149
|
|
|
list($x1, $y1) = $scale->PTranslate($this->coord[2 * $i], $this->coord[2 * $i + 1]); |
|
150
|
|
|
$p[2 * $i] = $x1; |
|
151
|
|
|
$p[2 * $i + 1] = $y1; |
|
152
|
|
|
|
|
153
|
|
|
if (isset($this->csimtargets[$i])) { |
|
154
|
|
|
$this->mark->SetCSIMTarget($this->csimtargets[$i]); |
|
155
|
|
|
$this->mark->SetCSIMAlt($this->csimalts[$i]); |
|
156
|
|
|
$this->mark->SetCSIMAltVal($this->coord[2 * $i], $this->coord[2 * $i + 1]); |
|
157
|
|
|
$this->mark->Stroke($img, $x1, $y1); |
|
158
|
|
|
$this->csimareas .= $this->mark->GetCSIMAreas(); |
|
159
|
|
|
} else { |
|
160
|
|
|
$this->mark->Stroke($img, $x1, $y1); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
++$i; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
if ($this->iFillColor != '') { |
|
167
|
|
|
$img->SetColor($this->iFillColor); |
|
168
|
|
|
$img->FilledPolygon($p); |
|
169
|
|
|
} |
|
170
|
|
|
$img->SetLineWeight($this->iLineWeight); |
|
171
|
|
|
$img->SetColor($this->iColor); |
|
172
|
|
|
$img->Polygon($p, $this->iFillColor != ''); |
|
173
|
|
|
} |
|
174
|
|
|
} |
|
175
|
|
|
|