@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PHUISegmentBarSegmentView extends AphrontTagView {
4
5 private $width;
6 private $color;
7 private $position;
8 private $tooltip;
9
10 public function setWidth($width) {
11 $this->width = $width;
12 return $this;
13 }
14
15 public function getWidth() {
16 return $this->width;
17 }
18
19 public function setColor($color) {
20 $this->color = $color;
21 return $this;
22 }
23
24 public function setPosition($position) {
25 $this->position = $position;
26 return $this;
27 }
28
29 /**
30 * Set a Tooltip.
31 * @param string|null $tooltip
32 * @return self
33 */
34 public function setTooltip($tooltip) {
35 $this->tooltip = $tooltip;
36 return $this;
37 }
38
39 protected function canAppendChild() {
40 return false;
41 }
42
43 protected function getTagAttributes() {
44 $classes = array(
45 'phui-segment-bar-segment-view',
46 );
47
48 if ($this->color) {
49 $classes[] = $this->color;
50 }
51
52 // Convert width to a percentage, and round it up slightly so that bars
53 // are full if they have, e.g., three segments at 1/3 + 1/3 + 1/3.
54 $width = 100 * $this->width;
55 $width = ceil(100 * $width) / 100;
56 $width = sprintf('%.2f%%', $width);
57
58 $left = 100 * $this->position;
59 $left = floor(100 * $left) / 100;
60 $left = sprintf('%.2f%%', $left);
61
62 $tooltip = $this->tooltip;
63 if (phutil_nonempty_string($tooltip)) {
64 Javelin::initBehavior('phabricator-tooltips');
65
66 $sigil = 'has-tooltip';
67 $meta = array(
68 'tip' => $tooltip,
69 'align' => 'E',
70 );
71 } else {
72 $sigil = null;
73 $meta = null;
74 }
75
76 return array(
77 'class' => implode(' ', $classes),
78 'style' => "left: {$left}; width: {$width};",
79 'sigil' => $sigil,
80 'meta' => $meta,
81 );
82 }
83
84}