How could I optimize this code / make it look better? Any advice on things I'm doing wrong?
class SvgChart{
private $_settings;
private $_data;
private $_countValues;
function __construct($pdo, $settings, $data){
$this->_settings = $settings;
$this->_data = $data;
$this->ArrayGroupByCountPrice();
$this->DataToValues();
}
function DataToValues(){
$start = $this->_settings->start;
$end = $start + 3;
$max = max($this->_countValues);
$max10 = max($this->_countValues)/10;
$start2 = $start - 1;
$svg = '<svg width="100%" height="100%">';
for($i = $start; $i < $end + 1; $i++){
$i2 = ($i - $start2);
$y = 100 - ($i2 * 20);
$svg .= '<text x="0%" y="'. ( $y - 10) .'%" font-family="Verdana" fill="black">'.round((($max + $max10) / 4) * $i2).'</text>'.
'<line x1="8%" x2="90%" y1="'. ( $y - 12) .'%" y2="'. ( $y - 12) .'%" style="'. ($color = $i2 < 4 ? "stroke:rgb(104,104,104)" : "stroke:rgb(0,0,0)") .'; stroke-width:0.5%; z-index: -1;"/>';
}
$i3 = 1;
$i = $start;
foreach($this->_countValues as $key => $data){
if($i3 > $start2){
$i2 = ($i - $start2);
$x = 82 / 5 * $i2 + 8;
$recty = (90 - (82 * $data / (max($this->_countValues) + $max10)));
$height = 82 * ($data / (max($this->_countValues) + (max($this->_countValues)/10)));
$svg .= '<line x1="'. $x .'%" x2="'. $x .'%" y1="8%" y2="90%" style="stroke:'. ($color = $i2 < 5 ? "rgb(104, 104, 104)" : "rgb(0, 0, 0)") .'; stroke-width:0.5%"/>'.
'<rect x="'. ($x + 5 - 82/5) .'%" y="'. $recty.'%" width="5%">'.
'<animate attributeName="height"'.
'from="0" to="'. $height .'%" dur="1s" fill="freeze"/>'.
'<animate attributeName="y"'.
'from="90%" to="'. $recty .'%" dur="1s" fill="freeze"/>'.
'</rect>'.
'<text x="'. ($x - 11) .'%" y="95%" font-family="Verdana" fill="black">'. $key .'</text>';
if($i > $end){
break;
}
$i++;
}
$i3++;
}
$svg .= '<text x="1%" y="90%" font-family="Verdana" fill="black">0</text>'.
'<line x1="8%" x2="8%" y1="8%" y2="90%" style="stroke:rgb(0,0,0); stroke-width:0.5%"/>'.
'<line x1="8%" x2="90%" y1="90%" y2="90%" style="stroke:rgb(0,0,0); stroke-width:0.5%"/>';
echo $svg;
}
function ArrayGroupByCountPrice(){
$countValues = array();
foreach($this->_data as $value){
if(!isset($countValues[$value->origin])){
$countValues[$value->origin] = 0;
}
$countValues[$value->origin] += $value->data;
}
$this->_countValues = $countValues;
}
}