Skip to content

A platform for community discussion. Free, open, simple.

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

Joffrey JAFFEUX761003c8bde1
diff --git a/app/models/report.rb b/app/models/report.rb
index 8dba01e9d58..0c894769a0d 100644
--- a/app/models/report.rb
+++ b/app/models/report.rb
@@ -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})"