Class: GraphColorLibrary
- Inherits:
-
Object
- Object
- GraphColorLibrary
- Includes:
- Singleton
- Defined in:
- lib/technical_graph/graph_color_library.rb
Overview
Used for auto color grabber
Constant Summary collapse
- BASIC_COLORS =
rock solid colors www.imagemagick.org/script/color.php
[ '#0000FF', #'blue', '#FF0000', #'red', '#00FF00', #'green', '#FF00FF', #'purple' ]
- ADDITIONAL_COLORS =
other random picked up, SVG need #RGB and I’m too lazy :]
[ '#8B3626', #'tomato', '#FF8247', #'sienna1', #'chocolate2', #'DarkGoldenrod4', #'OliveDrab4', #'ForestGreen', #'turquoise', #'DarkCyan', #'CadetBlue4', #'DeepSkyBlue4', #'DodgerBlue2', #'CornflowerBlue', #'MidnightBlue', #'MediumPurple3', #'magenta4', #'orchid4', #'DeepPink3', #'PaleVioletRed4', #'firebrick3' ]
- FAIL_COLOR =
‘black’
'#000000'
- MAX_INTENSITY =
not too bright
0xbb
Instance Method Summary collapse
- #get_color ⇒ Object
-
#initialize ⇒ GraphColorLibrary
constructor
A new instance of GraphColorLibrary.
-
#random_color ⇒ Object
Best solution, create random color JIT.
-
#reset ⇒ Object
Reset color bank.
Constructor Details
#initialize ⇒ GraphColorLibrary
Returns a new instance of GraphColorLibrary.
44 45 46 |
# File 'lib/technical_graph/graph_color_library.rb', line 44 def initialize reset end |
Instance Method Details
#get_color ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/technical_graph/graph_color_library.rb', line 65 def get_color color = @colors.shift #return FAIL_COLOR if color.nil? # better, create random colors just in time return random_color if color.nil? return color end |
#random_color ⇒ Object
Best solution, create random color JIT
57 58 59 60 61 62 63 |
# File 'lib/technical_graph/graph_color_library.rb', line 57 def random_color str = "#" 3.times do str += colour = "%02x" % (rand * MAX_INTENSITY) end return str end |
#reset ⇒ Object
Reset color bank
49 50 51 |
# File 'lib/technical_graph/graph_color_library.rb', line 49 def reset @colors = BASIC_COLORS + ADDITIONAL_COLORS.sort { rand } end |