Class: GraphColorLibrary

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/technical_graph/graph_color_library.rb

Overview

Used for auto color grabber

Constant Summary collapse

BASIC_COLORS =
[
  '#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

Constructor Details

#initializeGraphColorLibrary

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_colorObject



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_colorObject

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

#resetObject

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