FIX: lighten instead of adding transparency to consolidated pageviews (#7495)

This commit is contained in:
Joffrey JAFFEUX 2019-05-07 18:14:13 +02:00 committed by GitHub
parent 2570311718
commit 626534ad94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 6 deletions

View File

@ -295,7 +295,25 @@ class Report
add_counts report, subject, 'topics.created_at'
end
def lighten_color(hex, amount)
hex = adjust_hex(hex)
rgb = hex.scan(/../).map { |color| color.hex }
rgb[0] = [(rgb[0].to_i + 255 * amount).round, 255].min
rgb[1] = [(rgb[1].to_i + 255 * amount).round, 255].min
rgb[2] = [(rgb[2].to_i + 255 * amount).round, 255].min
"#%02x%02x%02x" % rgb
end
def rgba_color(hex, opacity = 1)
rgbs = hex_to_rgbs(adjust_hex(hex))
"rgba(#{rgbs.join(',')},#{opacity})"
end
private
def adjust_hex(hex)
hex = hex.gsub('#', '')
if hex.size == 3
chars = hex.scan(/\w/)
hex = chars.zip(chars).flatten.join
@ -305,13 +323,9 @@ class Report
hex = hex.ljust(6, hex.last)
end
rgbs = hex_to_rgbs(hex)
"rgba(#{rgbs.join(',')},#{opacity})"
hex
end
private
def hex_to_rgbs(hex_color)
hex_color = hex_color.gsub('#', '')
rgbs = hex_color.scan(/../)

View File

@ -14,7 +14,7 @@ Report.add_report("consolidated_page_views") do |report|
color = report.rgba_color(tertiary)
if filter == "page_view_anon"
color = report.rgba_color(tertiary, 0.5)
color = report.lighten_color(tertiary, 0.25)
end
if filter == "page_view_crawler"