2013-03-05 16:46:09 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class AphrontProgressBarView extends AphrontBarView {
|
|
|
|
|
|
|
|
const WIDTH = 100;
|
|
|
|
|
|
|
|
private $value;
|
|
|
|
private $max = 100;
|
|
|
|
private $alt = '';
|
|
|
|
|
2015-01-07 07:35:05 +11:00
|
|
|
protected function getDefaultColor() {
|
2015-12-03 07:44:23 +11:00
|
|
|
return parent::COLOR_AUTO_BADNESS;
|
2013-03-05 16:46:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setValue($value) {
|
|
|
|
$this->value = $value;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setMax($max) {
|
|
|
|
$this->max = $max;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setAlt($text) {
|
|
|
|
$this->alt = $text;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getRatio() {
|
|
|
|
return min($this->value, $this->max) / $this->max;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render() {
|
|
|
|
require_celerity_resource('aphront-bars');
|
|
|
|
$ratio = $this->getRatio();
|
|
|
|
$width = self::WIDTH * $ratio;
|
|
|
|
|
|
|
|
$color = $this->getColor();
|
|
|
|
|
2013-11-09 10:48:19 -08:00
|
|
|
return phutil_tag_div(
|
|
|
|
"aphront-bar progress color-{$color}",
|
2013-03-05 16:46:09 +00:00
|
|
|
array(
|
|
|
|
phutil_tag(
|
|
|
|
'div',
|
|
|
|
array('title' => $this->alt),
|
|
|
|
phutil_tag(
|
|
|
|
'div',
|
2013-11-09 10:48:19 -08:00
|
|
|
array('style' => "width: {$width}px;"),
|
2013-03-05 16:46:09 +00:00
|
|
|
'')),
|
|
|
|
phutil_tag(
|
|
|
|
'span',
|
|
|
|
array(),
|
2014-10-08 00:01:04 +11:00
|
|
|
$this->getCaption()),
|
|
|
|
));
|
2013-03-05 16:46:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|