Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F93197738
AphrontGlyphBarView.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Nov 26, 23:08
Size
2 KB
Mime Type
text/x-php
Expires
Thu, Nov 28, 23:08 (2 d)
Engine
blob
Format
Raw Data
Handle
22589893
Attached To
rPH Phabricator
AphrontGlyphBarView.php
View Options
<?php
final
class
AphrontGlyphBarView
extends
AphrontBarView
{
const
BLACK_STAR
=
"
\x
E2
\x
98
\x
85"
;
const
WHITE_STAR
=
"
\x
E2
\x
98
\x
86"
;
private
$value
;
private
$max
=
100
;
private
$numGlyphs
=
5
;
private
$fgGlyph
;
private
$bgGlyph
;
protected
function
getDefaultColor
()
{
return
AphrontBarView
::
COLOR_AUTO_GOODNESS
;
}
public
function
setValue
(
$value
)
{
$this
->
value
=
$value
;
return
$this
;
}
public
function
setMax
(
$max
)
{
$this
->
max
=
$max
;
return
$this
;
}
public
function
setNumGlyphs
(
$nn
)
{
$this
->
numGlyphs
=
$nn
;
return
$this
;
}
public
function
setGlyph
(
PhutilSafeHTML
$fg_glyph
)
{
$this
->
fgGlyph
=
$fg_glyph
;
return
$this
;
}
public
function
setBackgroundGlyph
(
PhutilSafeHTML
$bg_glyph
)
{
$this
->
bgGlyph
=
$bg_glyph
;
return
$this
;
}
protected
function
getRatio
()
{
return
min
(
$this
->
value
,
$this
->
max
)
/
$this
->
max
;
}
public
function
render
()
{
require_celerity_resource
(
'aphront-bars'
);
$ratio
=
$this
->
getRatio
();
$percentage
=
100
*
$ratio
;
$is_star
=
false
;
if
(
$this
->
fgGlyph
)
{
$fg_glyph
=
$this
->
fgGlyph
;
if
(
$this
->
bgGlyph
)
{
$bg_glyph
=
$this
->
bgGlyph
;
}
else
{
$bg_glyph
=
$fg_glyph
;
}
}
else
{
$is_star
=
true
;
$fg_glyph
=
self
::
BLACK_STAR
;
$bg_glyph
=
self
::
WHITE_STAR
;
}
$fg_glyphs
=
array_fill
(
0
,
$this
->
numGlyphs
,
$fg_glyph
);
$bg_glyphs
=
array_fill
(
0
,
$this
->
numGlyphs
,
$bg_glyph
);
$color
=
$this
->
getColor
();
return
phutil_tag
(
'div'
,
array
(
'class'
=>
"aphront-bar glyph color-{$color}"
,
),
array
(
phutil_tag
(
'div'
,
array
(
'class'
=>
'glyphs'
.(
$is_star
?
' starstar'
:
''
),
),
array
(
phutil_tag
(
'div'
,
array
(
'class'
=>
'fg'
,
'style'
=>
"width: {$percentage}%;"
,
),
$fg_glyphs
),
phutil_tag
(
'div'
,
array
(),
$bg_glyphs
),
)),
phutil_tag
(
'div'
,
array
(
'class'
=>
'caption'
),
$this
->
getCaption
()),
));
}
}
Event Timeline
Log In to Comment