mirror of
https://github.com/discourse/discourse.git
synced 2025-03-20 08:17:49 +08:00
FIX: lighten instead of adding transparency to consolidated pageviews (#7495)
This commit is contained in:
parent
2570311718
commit
626534ad94
@ -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(/../)
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user