FIX: makes sure an hex is always at 6 chars (#6608)

eg: #aaa should be converted to #aaaaaa
This commit is contained in:
Joffrey JAFFEUX 2018-11-15 00:52:47 +01:00 committed by GitHub
parent 1c678c8c54
commit 761003c8bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

View File

@ -1325,6 +1325,15 @@ class Report
end
def rgba_color(hex, opacity = 1)
if hex.length === 3
chars = hex.scan(/\w/)
hex = chars.zip(chars).flatten.join.ljust(6)
end
if hex.length < 3
hex = hex.ljust(6, hex.last)
end
rgbs = hex_to_rgbs(hex)
"rgba(#{rgbs.join(',')},#{opacity})"