Path: blob/master/src/view/widget/bars/AphrontBarView.php
12256 views
<?php12abstract class AphrontBarView extends AphrontView {34private $color;5private $caption = '';67const COLOR_DEFAULT = 'default';8const COLOR_WARNING = 'warning';9const COLOR_DANGER = 'danger';1011const COLOR_AUTO_BADNESS = 'auto_badness'; // more = bad! :(12const COLOR_AUTO_GOODNESS = 'auto_goodness'; // more = good! :)1314const THRESHOLD_DANGER = 0.85;15const THRESHOLD_WARNING = 0.75;1617abstract protected function getRatio();1819abstract protected function getDefaultColor();2021final public function setColor($color) {22$this->color = $color;23return $this;24}2526final public function setCaption($text) {27$this->caption = $text;28return $this;29}3031final protected function getColor() {32$color = $this->color;33if (!$color) {34$color = $this->getDefaultColor();35}3637switch ($color) {38case self::COLOR_DEFAULT:39case self::COLOR_WARNING:40case self::COLOR_DANGER:41return $color;42}4344$ratio = $this->getRatio();45if ($color === self::COLOR_AUTO_GOODNESS) {46$ratio = 1.0 - $ratio;47}4849if ($ratio >= self::THRESHOLD_DANGER) {50return self::COLOR_DANGER;51} else if ($ratio >= self::THRESHOLD_WARNING) {52return self::COLOR_WARNING;53} else {54return self::COLOR_DEFAULT;55}56}5758final protected function getCaption() {59return $this->caption;60}6162}636465