Class: ChartHelpers::GanttChart
- Inherits:
-
Object
- Object
- ChartHelpers::GanttChart
- Defined in:
- lib/chart_helpers/gantt_chart.rb
Constant Summary collapse
- DEFAULT =
{ font_size: 12, font_family: 'arial', font_weight: 'regular', title_font_weight: 'bold', font_color: '#000', row_color: '#9370DB', row_height: 30 }.freeze
- TITLE_TOP_PADDING =
20
- GRID_TOP_PADDING =
TITLE_TOP_PADDING + 80
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#scale ⇒ Object
readonly
Returns the value of attribute scale.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #build(output) ⇒ Object
-
#initialize(title:, data:, scale:, width: 2000, height: nil, date_format: nil, number_format: nil, options: {}) ⇒ GanttChart
constructor
A new instance of GanttChart.
Constructor Details
#initialize(title:, data:, scale:, width: 2000, height: nil, date_format: nil, number_format: nil, options: {}) ⇒ GanttChart
Returns a new instance of GanttChart.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/chart_helpers/gantt_chart.rb', line 20 def initialize(title:, data:, scale:, width: 2000, height: nil, date_format: nil, number_format: nil, options: {}) @title = title @data = data @scale = scale @date_format = date_format @number_format = number_format @options = @max_value = @data.collect { |v| v[:end] }.max @max_value = @max_value.to_time if @max_value.is_a?(DateTime) @max_value = @max_value.to_f @min_value = @data.collect { |v| v[:start] }.min @min_value = @min_value.to_time if @min_value.is_a?(DateTime) @min_value = @min_value.to_f # We aren't guaranteed for our min_value to be 0, so base everything off of the difference @diff_value = @max_value - @min_value @row_height = setting(:row_height) @width = width # Height should be one "row_height"" for each row + one for the axis + title @height = height || @row_height * (data.size + 1) + 100 # Cache for text sizes to avoid duplicating work @text_sizes = {} end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
18 19 20 |
# File 'lib/chart_helpers/gantt_chart.rb', line 18 def data @data end |
#scale ⇒ Object (readonly)
Returns the value of attribute scale.
18 19 20 |
# File 'lib/chart_helpers/gantt_chart.rb', line 18 def scale @scale end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
18 19 20 |
# File 'lib/chart_helpers/gantt_chart.rb', line 18 def title @title end |
Instance Method Details
#build(output) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/chart_helpers/gantt_chart.rb', line 47 def build(output) svg = Victor::SVG.new(width: @width, height: @height) render_title(svg) render_grid(svg) svg.g(transform: "translate(0, #{TITLE_TOP_PADDING})") do @data.each_with_index { |row, i| render_row(svg, row, i + 1) } end svg.save(output) end |