Class: GitGraph::GitHub::GraphableData
- Inherits:
-
Object
- Object
- GitGraph::GitHub::GraphableData
- Defined in:
- lib/gitGraph/github/graphable_data.rb
Instance Attribute Summary collapse
-
#datasets ⇒ Object
Returns the value of attribute datasets.
-
#labels ⇒ Object
Returns the value of attribute labels.
Instance Method Summary collapse
- #format_options(options) ⇒ Object
-
#initialize(labels: labels, datasets: datasets) ⇒ GraphableData
constructor
datasets should be an array of hashes.
- #map_colors_to_datasets(options) ⇒ Object
- #new_color(color, alpha) ⇒ Object
- #prettify(options) ⇒ Object
- #stringify(chart_type, options = {}) ⇒ Object
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
#datasets ⇒ Object
Returns the value of attribute datasets.
6 7 8 |
# File 'lib/gitGraph/github/graphable_data.rb', line 6 def datasets @datasets end |
#labels ⇒ Object
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 () [:fill_alpha] ||= 0.2 [:stroke_alpha] ||= 1.0 [:point_stroke_color] ||= '#fff' [:point_highlight_fill] ||= '#fff' end |
#map_colors_to_datasets(options) ⇒ Object
26 27 28 |
# File 'lib/gitGraph/github/graphable_data.rb', line 26 def map_colors_to_datasets() @datasets.map! { |dataset| dataset.merge(prettify()) } 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() prettified_hash = {} base_color = ColorGenerator.new(saturation: 1.0, value: 1.0).create_rgb fill_color = new_color(base_color, [:fill_alpha]) stroke_color = new_color(base_color, [:stroke_alpha]) { :fillColor => fill_color, :strokeColor => stroke_color, :pointColor => stroke_color, :pointStrokeColor => [:point_stroke_color], :pointHighlightFill => [: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, = {}) = () map_colors_to_datasets() if chart_type == :polar_area format_for_polar_area() else format_chart() end end |