| Total Complexity | 69 |
| Total Lines | 320 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like RadarGraph often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use RadarGraph, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 18 | class RadarGraph extends Graph |
||
| 19 | { |
||
| 20 | public $grid; |
||
| 21 | public $axis; |
||
| 22 | private $posx; |
||
| 23 | private $posy; |
||
| 24 | private $len; |
||
| 25 | private $axis_title; |
||
| 26 | |||
| 27 | public function __construct($width = 300, $height = 200, $cachedName = '', $timeout = 0, $inline = 1) |
||
| 28 | { |
||
| 29 | parent::__construct($width, $height, $cachedName, $timeout, $inline); |
||
| 30 | $this->posx = $width / 2; |
||
| 31 | $this->posy = $height / 2; |
||
| 32 | $this->len = min($width, $height) * 0.35; |
||
| 33 | $this->SetColor([255, 255, 255]); |
||
| 34 | $this->SetTickDensity(TICKD_NORMAL); |
||
| 35 | $this->SetScale('lin'); |
||
| 36 | $this->SetGridDepth(DEPTH_FRONT); |
||
| 37 | } |
||
| 38 | |||
| 39 | public function HideTickMarks($aFlag = true) |
||
| 40 | { |
||
| 41 | $this->axis->scale->ticks->SupressTickMarks($aFlag); |
||
| 42 | } |
||
| 43 | |||
| 44 | public function ShowMinorTickmarks($aFlag = true) |
||
| 45 | { |
||
| 46 | $this->yscale->ticks->SupressMinorTickMarks(!$aFlag); |
||
| 47 | } |
||
| 48 | |||
| 49 | public function SetScale($axtype, $ymin = 1, $ymax = 1, $dummy1 = null, $dumy2 = null) |
||
| 50 | { |
||
| 51 | if ($axtype != 'lin' && $axtype != 'log') { |
||
| 52 | Util\JpGraphError::RaiseL(18003, $axtype); |
||
| 53 | //("Illegal scale for radarplot ($axtype). Must be \"lin\" or \"log\""); |
||
| 54 | } |
||
| 55 | if ($axtype == 'lin') { |
||
| 56 | $this->yscale = new LinearScale($ymin, $ymax); |
||
| 57 | $this->yscale->ticks = new RadarLinearTicks(); |
||
| 58 | $this->yscale->ticks->SupressMinorTickMarks(); |
||
| 59 | } elseif ($axtype == 'log') { |
||
| 60 | $this->yscale = new LogScale($ymin, $ymax); |
||
| 61 | $this->yscale->ticks = new RadarLogTicks(); |
||
| 62 | } |
||
| 63 | |||
| 64 | $this->axis = new RadarAxis($this->img, $this->yscale); |
||
| 65 | $this->grid = new RadarGrid(); |
||
| 66 | } |
||
| 67 | |||
| 68 | public function SetSize($aSize) |
||
| 69 | { |
||
| 70 | if ($aSize < 0.1 || $aSize > 1) { |
||
| 71 | Util\JpGraphError::RaiseL(18004, $aSize); |
||
| 72 | //("Radar Plot size must be between 0.1 and 1. (Your value=$s)"); |
||
| 73 | } |
||
| 74 | $this->len = min($this->img->width, $this->img->height) * $aSize / 2; |
||
| 75 | } |
||
| 76 | |||
| 77 | public function SetPlotSize($aSize) |
||
| 80 | } |
||
| 81 | |||
| 82 | public function SetTickDensity($densy = TICKD_NORMAL, $dummy1 = null) |
||
| 83 | { |
||
| 84 | $this->ytick_factor = 25; |
||
| 85 | switch ($densy) { |
||
| 86 | case TICKD_DENSE: |
||
| 87 | $this->ytick_factor = 12; |
||
| 88 | |||
| 89 | break; |
||
| 90 | case TICKD_NORMAL: |
||
| 91 | $this->ytick_factor = 25; |
||
| 92 | |||
| 93 | break; |
||
| 94 | case TICKD_SPARSE: |
||
| 95 | $this->ytick_factor = 40; |
||
| 96 | |||
| 97 | break; |
||
| 98 | case TICKD_VERYSPARSE: |
||
| 99 | $this->ytick_factor = 70; |
||
| 100 | |||
| 101 | break; |
||
| 102 | default: |
||
| 103 | Util\JpGraphError::RaiseL(18005, $densy); |
||
| 104 | //("RadarPlot Unsupported Tick density: $densy"); |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | public function SetPos($px, $py = 0.5) |
||
| 111 | } |
||
| 112 | |||
| 113 | public function SetCenter($px, $py = 0.5) |
||
| 114 | { |
||
| 115 | if ($px >= 0 && $px <= 1) { |
||
| 116 | $this->posx = $this->img->width * $px; |
||
| 117 | } else { |
||
| 118 | $this->posx = $px; |
||
| 119 | } |
||
| 120 | if ($py >= 0 && $py <= 1) { |
||
| 121 | $this->posy = $this->img->height * $py; |
||
| 122 | } else { |
||
| 123 | $this->posy = $py; |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | public function SetColor($aColor) |
||
| 128 | { |
||
| 129 | $this->SetMarginColor($aColor); |
||
| 130 | } |
||
| 131 | |||
| 132 | public function SetTitles($aTitleArray) |
||
| 133 | { |
||
| 134 | $this->axis_title = $aTitleArray; |
||
| 135 | } |
||
| 136 | |||
| 137 | public function Add($aPlot) |
||
| 138 | { |
||
| 139 | if ($aPlot == null) { |
||
| 140 | Util\JpGraphError::RaiseL(25010); //("Graph::Add() You tried to add a null plot to the graph."); |
||
| 141 | } |
||
| 142 | if (is_array($aPlot) && safe_count($aPlot) > 0) { |
||
| 143 | $cl = $aPlot[0]; |
||
| 144 | } else { |
||
| 145 | $cl = $aPlot; |
||
| 146 | } |
||
| 147 | |||
| 148 | if ($cl instanceof Text\Text) { |
||
| 149 | $this->AddText($aPlot); |
||
| 150 | } elseif (($cl instanceof Plot\IconPlot)) { |
||
| 151 | $this->AddIcon($aPlot); |
||
| 152 | } else { |
||
| 153 | $this->plots[] = $aPlot; |
||
| 154 | } |
||
| 155 | } |
||
| 156 | |||
| 157 | public function GetPlotsYMinMax($aPlots) |
||
| 158 | { |
||
| 159 | $min = $aPlots[0]->Min(); |
||
| 160 | $max = $aPlots[0]->Max(); |
||
| 161 | foreach ($this->plots as $p) { |
||
| 162 | $max = max($max, $p->Max()); |
||
| 163 | $min = min($min, $p->Min()); |
||
| 164 | } |
||
| 165 | if ($min < 0) { |
||
| 166 | Util\JpGraphError::RaiseL(18006, $min); |
||
| 167 | //("Minimum data $min (Radar plots should only be used when all data points > 0)"); |
||
| 168 | } |
||
| 169 | |||
| 170 | return [$min, $max]; |
||
| 171 | } |
||
| 172 | |||
| 173 | public function StrokeIcons() |
||
| 174 | { |
||
| 175 | if ($this->iIcons != null) { |
||
| 176 | $n = safe_count($this->iIcons); |
||
| 177 | for ($i = 0; $i < $n; ++$i) { |
||
| 178 | $this->iIcons[$i]->Stroke($this->img); |
||
| 179 | } |
||
| 180 | } |
||
| 181 | } |
||
| 182 | |||
| 183 | public function StrokeTexts() |
||
| 184 | { |
||
| 185 | if ($this->texts != null) { |
||
| 186 | $n = safe_count($this->texts); |
||
| 187 | for ($i = 0; $i < $n; ++$i) { |
||
| 188 | $this->texts[$i]->Stroke($this->img); |
||
| 189 | } |
||
| 190 | } |
||
| 191 | } |
||
| 192 | |||
| 193 | // Stroke the Radar graph |
||
| 194 | public function Stroke($aStrokeFileName = '') |
||
| 338 | } |
||
| 339 | } |
||
| 340 | } // @class |
||
| 341 |