public function _ratio($part = 0, $percent = false) { $whole = $this->_value; if (!DevNumber::isValid($part)) { $part = 0; } if (!DevNumber::isValid($whole)) { $whole = 1; } $ratio = $part * 100 / $whole; return $ratio * ($percent ? 100 : 1); }
static function barGraph($data, $height = '', $width = '', $max = '', $is_percent = '') { $output = ''; if (DevArray::isAssoc($data)) { if ($max == '') { $max = DevArray::max($data); } $output .= '<table width = "' . ($width > 0 ? $width : 200) . '" height = "' . ($height > 0 ? $height : 100) . '">'; $output .= "\n"; foreach ($data as $a => $b) { $output .= '<tr>'; $output .= "<td>{$a}</td>" . ($hori ? '<tr>' : '<td>'); $output .= '<td width="80%" class="dev_bar"><table width="100%" cellpadding="0" cellspacing="0" border="1" bgcolor="#ffffff"><tr><td width="' . DevNumber::ratio($b, $max, false) . '%" height="5" bgcolor="#c0c0c0"></td><td></td></tr></table></td>'; $output .= "<td>" . ($is_percent ? DevNumber::ratio($b, $max, $is_percent) : $b) . "</td>"; $output .= "</tr>"; } $output .= "\n"; $output .= '</table>'; } return $output; }
public function _percentage($part = 0, $percent = false) { $whole = $this->_data; if (!DevNumber::isValid($part)) { $part = 0; } if (!DevNumber::isValid($whole)) { $whole = 1; } $ratio = $whole / ($part * 100); return $ratio * ($percent ? 100 : 1); }