Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/view/phui/PHUISegmentBarSegmentView.php
12249 views
1
<?php
2
3
final 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
public function setTooltip($tooltip) {
30
$this->tooltip = $tooltip;
31
return $this;
32
}
33
34
protected function canAppendChild() {
35
return false;
36
}
37
38
protected function getTagAttributes() {
39
$classes = array(
40
'phui-segment-bar-segment-view',
41
);
42
43
if ($this->color) {
44
$classes[] = $this->color;
45
}
46
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);
52
53
$left = 100 * $this->position;
54
$left = floor(100 * $left) / 100;
55
$left = sprintf('%.2f%%', $left);
56
57
$tooltip = $this->tooltip;
58
if (strlen($tooltip)) {
59
Javelin::initBehavior('phabricator-tooltips');
60
61
$sigil = 'has-tooltip';
62
$meta = array(
63
'tip' => $tooltip,
64
'align' => 'E',
65
);
66
} else {
67
$sigil = null;
68
$meta = null;
69
}
70
71
return array(
72
'class' => implode(' ', $classes),
73
'style' => "left: {$left}; width: {$width};",
74
'sigil' => $sigil,
75
'meta' => $meta,
76
);
77
}
78
79
}
80
81