class RedmineCrm::ColorsHelper
Constants
- NAMED_COLORS
Public Class Methods
contrasting_text_color(input_color)
click to toggle source
# File lib/redmine_crm/colors_helper.rb, line 177 def contrasting_text_color(input_color) color = hex_color(input_color).gsub('#','') convert_to_brightness_value(color) > 382.5 ? darken_color(color) : lighten_color(color) end
convert_to_brightness_value(input_color)
click to toggle source
# File lib/redmine_crm/colors_helper.rb, line 186 def convert_to_brightness_value(input_color) (hex_color(input_color).scan(/../).map {|color| color.hex}).sum end
darken_color(input_color, amount=0.4)
click to toggle source
Amount should be a decimal between 0 and 1. Lower means darker
# File lib/redmine_crm/colors_helper.rb, line 158 def darken_color(input_color, amount=0.4) hex_color = hex_color(input_color).gsub('#','') rgb = hex_color.scan(/../).map {|color| color.hex} rgb[0] = (rgb[0].to_i * amount).round rgb[1] = (rgb[1].to_i * amount).round rgb[2] = (rgb[2].to_i * amount).round "#%02x%02x%02x" % rgb end
hex_color(input_color)
click to toggle source
# File lib/redmine_crm/colors_helper.rb, line 182 def hex_color(input_color) "##{NAMED_COLORS[input_color] || input_color}" end
lighten_color(input_color, amount=0.6)
click to toggle source
Amount should be a decimal between 0 and 1. Higher lightgreen lighter
# File lib/redmine_crm/colors_helper.rb, line 168 def lighten_color(input_color, amount=0.6) hex_color = hex_color(input_color).gsub('#','') rgb = hex_color.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