Total Complexity | 89 |
Total Lines | 469 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Complex classes like LinePlot 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 LinePlot, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
29 | class LinePlot extends Plot |
||
30 | { |
||
31 | public $mark; |
||
32 | protected $filled = false; |
||
33 | protected $fill_color = 'blue'; |
||
34 | protected $step_style = false; |
||
35 | protected $center = false; |
||
36 | protected $line_style = 1; // Default to solid |
||
37 | protected $filledAreas = []; // array of arrays(with min,max,col,filled in them) |
||
38 | public $barcenter = false; // When we mix line and bar. Should we center the line in the bar. |
||
39 | protected $fillFromMin = false; |
||
40 | protected $fillFromMax = false; |
||
41 | protected $fillgrad = false; |
||
42 | protected $fillgrad_fromcolor = 'navy'; |
||
43 | protected $fillgrad_tocolor = 'silver'; |
||
44 | protected $fillgrad_numcolors = 100; |
||
45 | protected $iFastStroke = false; |
||
46 | |||
47 | /** |
||
48 | * CONSTRUCTOR. |
||
49 | * |
||
50 | * @param mixed $datay |
||
51 | * @param mixed $datax |
||
52 | */ |
||
53 | public function __construct($datay, $datax = false) |
||
54 | { |
||
55 | parent::__construct($datay, $datax); |
||
56 | $this->mark = new PlotMark(); |
||
57 | $this->color = Util\ColorFactory::getColor(); |
||
58 | $this->fill_color = $this->color; |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * PUBLIC METHODS. |
||
63 | * |
||
64 | * @param mixed $aFlg |
||
65 | */ |
||
66 | public function SetFilled($aFlg = true) |
||
67 | { |
||
68 | $this->filled = $aFlg; |
||
69 | } |
||
70 | |||
71 | public function SetBarCenter($aFlag = true) |
||
72 | { |
||
73 | $this->barcenter = $aFlag; |
||
74 | } |
||
75 | |||
76 | public function SetStyle($aStyle) |
||
77 | { |
||
78 | $this->line_style = $aStyle; |
||
79 | } |
||
80 | |||
81 | public function SetStepStyle($aFlag = true) |
||
82 | { |
||
83 | $this->step_style = $aFlag; |
||
84 | } |
||
85 | |||
86 | public function SetColor($aColor) |
||
87 | { |
||
88 | parent::SetColor($aColor); |
||
89 | } |
||
90 | |||
91 | public function SetFillFromYMin($f = true) |
||
92 | { |
||
93 | $this->fillFromMin = $f; |
||
94 | } |
||
95 | |||
96 | public function SetFillFromYMax($f = true) |
||
97 | { |
||
98 | $this->fillFromMax = $f; |
||
99 | } |
||
100 | |||
101 | public function SetFillColor($aColor, $aFilled = true) |
||
102 | { |
||
103 | //$this->color = $aColor; |
||
104 | $this->fill_color = $aColor; |
||
105 | $this->filled = $aFilled; |
||
106 | } |
||
107 | |||
108 | public function SetFillGradient($aFromColor, $aToColor, $aNumColors = 100, $aFilled = true) |
||
109 | { |
||
110 | $this->fillgrad_fromcolor = $aFromColor; |
||
111 | $this->fillgrad_tocolor = $aToColor; |
||
112 | $this->fillgrad_numcolors = $aNumColors; |
||
113 | $this->filled = $aFilled; |
||
114 | $this->fillgrad = true; |
||
115 | } |
||
116 | |||
117 | public function Legend($graph) |
||
118 | { |
||
119 | if ($this->legend != '') { |
||
120 | if ($this->filled && !$this->fillgrad) { |
||
121 | $graph->legend->Add( |
||
122 | $this->legend, |
||
123 | $this->fill_color, |
||
124 | $this->mark, |
||
125 | 0, |
||
126 | $this->legendcsimtarget, |
||
127 | $this->legendcsimalt, |
||
128 | $this->legendcsimwintarget |
||
129 | ); |
||
130 | } elseif ($this->fillgrad) { |
||
131 | $color = [$this->fillgrad_fromcolor, $this->fillgrad_tocolor]; |
||
132 | // In order to differentiate between gradients and cooors specified as an Image\RGB triple |
||
133 | $graph->legend->Add( |
||
134 | $this->legend, |
||
135 | $color, |
||
136 | '', |
||
137 | -2/* -GRAD_HOR */, |
||
138 | $this->legendcsimtarget, |
||
139 | $this->legendcsimalt, |
||
140 | $this->legendcsimwintarget |
||
141 | ); |
||
142 | } else { |
||
143 | $graph->legend->Add( |
||
144 | $this->legend, |
||
145 | $this->color, |
||
146 | $this->mark, |
||
147 | $this->line_style, |
||
148 | $this->legendcsimtarget, |
||
149 | $this->legendcsimalt, |
||
150 | $this->legendcsimwintarget |
||
151 | ); |
||
152 | } |
||
153 | } |
||
154 | } |
||
155 | |||
156 | public function AddArea($aMin = 0, $aMax = 0, $aFilled = LP_AREA_NOT_FILLED, $aColor = 'gray9', $aBorder = LP_AREA_BORDER) |
||
165 | } |
||
166 | |||
167 | // Gets called before any axis are stroked |
||
168 | public function PreStrokeAdjust($graph) |
||
169 | { |
||
170 | // If another plot type have already adjusted the |
||
171 | // offset we don't touch it. |
||
172 | // (We check for empty in case the scale is a log scale |
||
173 | // and hence doesn't contain any xlabel_offset) |
||
174 | if (empty($graph->xaxis->scale->ticks->xlabel_offset) || $graph->xaxis->scale->ticks->xlabel_offset == 0) { |
||
175 | if ($this->center) { |
||
176 | ++$this->numpoints; |
||
177 | $a = 0.5; |
||
178 | $b = 0.5; |
||
179 | } else { |
||
180 | $a = 0; |
||
181 | $b = 0; |
||
182 | } |
||
183 | $graph->xaxis->scale->ticks->SetXLabelOffset($a); |
||
184 | $graph->SetTextScaleOff($b); |
||
185 | //$graph->xaxis->scale->ticks->SupressMinorTickMarks(); |
||
186 | } |
||
187 | } |
||
188 | |||
189 | public function SetFastStroke($aFlg = true) |
||
190 | { |
||
191 | $this->iFastStroke = $aFlg; |
||
192 | } |
||
193 | |||
194 | public function FastStroke($img, $xscale, $yscale, $aStartPoint = 0, $exist_x = true) |
||
230 | } |
||
231 | |||
232 | public function Stroke($img, $xscale, $yscale) |
||
233 | { |
||
498 | } |
||
499 | } |
||
500 | } |
||
501 | } // @class |
||
502 |