Class: GitGraph::GitHub::GraphableData

Inherits:
Object
  • Object
show all
Defined in:
lib/gitGraph/github/graphable_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(labels: labels, datasets: datasets) ⇒ GraphableData

datasets should be an array of hashes. each has needs to contain a label => name key-value pair, which is basically the name of that dataset, and and a data => data_arr key-value pair, which is just an array of data points.



11
12
13
# File 'lib/gitGraph/github/graphable_data.rb', line 11

def initialize(labels: labels, datasets: datasets)
  @labels, @datasets = labels, datasets
end

Instance Attribute Details

#datasetsObject

Returns the value of attribute datasets.



6
7
8
# File 'lib/gitGraph/github/graphable_data.rb', line 6

def datasets
  @datasets
end

#labelsObject

Returns the value of attribute labels.



6
7
8
# File 'lib/gitGraph/github/graphable_data.rb', line 6

def labels
  @labels
end

Instance Method Details

#format_options(options) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/gitGraph/github/graphable_data.rb', line 45

def format_options(options)
  options[:fill_alpha] ||= 0.2
  options[:stroke_alpha] ||= 1.0
  options[:point_stroke_color] ||= '#fff'
  options[:point_highlight_fill] ||= '#fff'
  options
end

#map_colors_to_datasets(options) ⇒ Object



26
27
28
# File 'lib/gitGraph/github/graphable_data.rb', line 26

def map_colors_to_datasets(options)
  @datasets.map! { |dataset| dataset.merge(prettify(options)) }
end

#new_color(color, alpha) ⇒ Object



41
42
43
# File 'lib/gitGraph/github/graphable_data.rb', line 41

def new_color(color, alpha)
  "rgba(#{color[0]}, #{color[1]}, #{color[2]}, #{alpha})"
end

#prettify(options) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/gitGraph/github/graphable_data.rb', line 30

def prettify(options)
  prettified_hash = {}
  base_color = ColorGenerator.new(saturation: 1.0, value: 1.0).create_rgb

  fill_color = new_color(base_color, options[:fill_alpha])
  stroke_color = new_color(base_color, options[:stroke_alpha])
  { :fillColor => fill_color, :strokeColor => stroke_color, :pointColor => stroke_color,
    :pointStrokeColor => options[:point_stroke_color], :pointHighlightFill => options[:point_highlight_fill],
    :pointHighlightStroke => stroke_color }
end

#stringify(chart_type, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/gitGraph/github/graphable_data.rb', line 16

def stringify(chart_type, options = {})
  new_options = format_options(options)
  map_colors_to_datasets(new_options)
  if chart_type == :polar_area
    format_for_polar_area(new_options)
  else
    format_chart(new_options)
  end
end