Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / view / phui / PHUISegmentBarSegmentView.php
blob6bd3c530ef0fdc2fe8243a44bff7865ef35cec60
1 <?php
3 final class PHUISegmentBarSegmentView extends AphrontTagView {
5 private $width;
6 private $color;
7 private $position;
8 private $tooltip;
10 public function setWidth($width) {
11 $this->width = $width;
12 return $this;
15 public function getWidth() {
16 return $this->width;
19 public function setColor($color) {
20 $this->color = $color;
21 return $this;
24 public function setPosition($position) {
25 $this->position = $position;
26 return $this;
29 public function setTooltip($tooltip) {
30 $this->tooltip = $tooltip;
31 return $this;
34 protected function canAppendChild() {
35 return false;
38 protected function getTagAttributes() {
39 $classes = array(
40 'phui-segment-bar-segment-view',
43 if ($this->color) {
44 $classes[] = $this->color;
47 // Convert width to a percentage, and round it up slightly so that bars
48 // are full if they have, e.g., three segments at 1/3 + 1/3 + 1/3.
49 $width = 100 * $this->width;
50 $width = ceil(100 * $width) / 100;
51 $width = sprintf('%.2f%%', $width);
53 $left = 100 * $this->position;
54 $left = floor(100 * $left) / 100;
55 $left = sprintf('%.2f%%', $left);
57 $tooltip = $this->tooltip;
58 if (strlen($tooltip)) {
59 Javelin::initBehavior('phabricator-tooltips');
61 $sigil = 'has-tooltip';
62 $meta = array(
63 'tip' => $tooltip,
64 'align' => 'E',
66 } else {
67 $sigil = null;
68 $meta = null;
71 return array(
72 'class' => implode(' ', $classes),
73 'style' => "left: {$left}; width: {$width};",
74 'sigil' => $sigil,
75 'meta' => $meta,