Class: Graph::Horizon

Inherits:
Graph
  • Object
show all
Defined in:
lib/graph/horizon.rb

Overview

Horizon extension of Graph

Constant Summary collapse

GRAPH_COLOUR =

Default: Anchor blue

Settings.horizon_color || "#006d2c"

Class Method Summary collapse

Class Method Details

.complement(base) ⇒ Object

Uses the 'color' library


38
39
40
41
42
# File 'lib/graph/horizon.rb', line 38

def self.complement base  
  hsl = (Color::RGB.from_html base).to_hsl
  hsl.hue = (hsl.hue + 180) % 360
  hsl.to_rgb.html
end

.get_coloursObject

Given the base graph colour, create a range of hues from the inverse to the colour itself in a range.


10
11
12
# File 'lib/graph/horizon.rb', line 10

def self.get_colours
  tint_range(complement GRAPH_COLOUR) + tint_range(GRAPH_COLOUR, reverse: true)
end

.tint_range(base, opts = {}) ⇒ Object

Cubism colour range. By default: 8 colour, representing -4, -3, -2, -1, 1, 2, 3, 4; cubism defaults: #08519c -4; #006d2c +4 Method gives a tinting of color, dark to light. Reverse for positive side (light to dark)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/graph/horizon.rb', line 17

def self.tint_range base, opts={}
  rgb = base[1..-1].scan(/.{1,2}/).map{|a| a.to_i(16)}

  arr = [rgb]
  int = rgb

  i = opts[:iterations] || 4     # Denotes amount of overlapping layers
  f = opts[:factor]     || (1.0 / i) # Denotes tint factor

  (i-1).times do 
    int = int.map{|b| ((255 - b)*f).to_i + b}
    arr << int
  end

  arr = arr.reverse if opts[:reverse]

  arr.map{|b| "#"+b.map{|a| a.to_s(16).rjust(2,"0")}.join("")}
end