Module: Graphene::OneDGraphs
- Included in:
- ResultSet
- Defined in:
- lib/graphene/gruff.rb
Overview
Extends calculators with one-dimensional graphs, like pie charts.
Instance Method Summary collapse
-
#bar_chart(path = nil, title = nil, &block) ⇒ Object
(also: #bar_graph)
Returns a Gruff::Bar object with the stats set.
-
#pie_chart(path = nil, title = nil, &block) ⇒ Object
(also: #pie_graph)
Returns a Gruff::Pie object with the stats set.
-
#side_bar_chart(path = nil, title = nil, &block) ⇒ Object
(also: #side_bar_graph)
Returns a Gruff::SideBar object with the stats set.
-
#side_stacked_bar_chart(path = nil, title = nil, &block) ⇒ Object
(also: #side_stacked_bar_graph)
Returns a Gruff::StackedSideBar object with the stats set.
-
#spider_chart(path = nil, title = nil, &block) ⇒ Object
(also: #spider_graph)
Returns a Gruff::Spider object with the stats set.
-
#stacked_bar_chart(path = nil, title = nil, &block) ⇒ Object
(also: #stacked_bar_graph)
Returns a Gruff::StackedBar object with the stats set.
Instance Method Details
#bar_chart(path = nil, title = nil, &block) ⇒ Object Also known as: bar_graph
Returns a Gruff::Bar object with the stats set.
Optionally you may pass a file path and chart title. If you pass a file path, the chart will be written to file automatically. Otherwise, you would call “write(‘/path/to/graph.png’)” on the returned chart object.
If you pass a block, it will be called, giving you access to the Gruff::Bar object before it is written to file (that is, if you also passed a file path).
Example 1:
Graphene.percentages(logs, :browser).('/path/to/browser-share.png', 'Browser Share')
Example 2:
Graphene.percentages(logs, :browser).('/path/to/browser-share.png') do |chart|
chart.title = 'Browser Share'
chart.font = '/path/to/font.ttf'
chart.theme = chart.theme_37signals
end
Example 3:
blog = Graphene.subtotals(logs, :browser)..to_blob
86 87 88 89 90 |
# File 'lib/graphene/gruff.rb', line 86 def (path=nil, title=nil, &block) Graphene.gruff do chart(Gruff::Bar.new, path, title, false, &block) end end |
#pie_chart(path = nil, title = nil, &block) ⇒ Object Also known as: pie_graph
Returns a Gruff::Pie object with the stats set.
Optionally you may pass a file path and graph title. If you pass a file path, the graph will be written to file automatically. Otherwise, you would call “write(‘/path/to/graph.png’)” on the returned graph object.
If you pass a block, it will be called, giving you access to the Gruff::Pie object before it is written to file (that is, if you also passed a file path).
Example 1:
Graphene.percentages(logs, :browser).pie_chart('/path/to/browser-share.png', 'Browser Share')
Example 2:
Graphene.percentages(logs, :browser).pie_chart('/path/to/browser-share.png') do |pie|
pie.title = 'Browser Share'
pie.font = '/path/to/font.ttf'
pie.theme = pie.theme_37signals
end
Example 3:
blog = Graphene.percentages(logs, :browser).pie_chart.to_blob
54 55 56 57 58 |
# File 'lib/graphene/gruff.rb', line 54 def pie_chart(path=nil, title=nil, &block) Graphene.gruff do chart(Gruff::Pie.new, path, title, &block) end end |
#side_bar_chart(path = nil, title = nil, &block) ⇒ Object Also known as: side_bar_graph
Returns a Gruff::SideBar object with the stats set.
Optionally you may pass a file path and chart title. If you pass a file path, the chart will be written to file automatically. Otherwise, you would call “write(‘/path/to/graph.png’)” on the returned chart object.
If you pass a block, it will be called, giving you access to the Gruff::SideBar object before it is written to file (that is, if you also passed a file path).
Example 1:
Graphene.percentages(logs, :browser).('/path/to/browser-share.png', 'Browser Share')
Example 2:
Graphene.percentages(logs, :browser).('/path/to/browser-share.png') do |chart|
chart.title = 'Browser Share'
chart.font = '/path/to/font.ttf'
chart.theme = chart.theme_37signals
end
Example 3:
blog = Graphene.subtotals(logs, :browser)..to_blob
150 151 152 153 154 |
# File 'lib/graphene/gruff.rb', line 150 def (path=nil, title=nil, &block) Graphene.gruff do chart(Gruff::SideBar.new, path, title, true, &block) end end |
#side_stacked_bar_chart(path = nil, title = nil, &block) ⇒ Object Also known as: side_stacked_bar_graph
Returns a Gruff::StackedSideBar object with the stats set.
Optionally you may pass a file path and chart title. If you pass a file path, the chart will be written to file automatically. Otherwise, you would call “write(‘/path/to/graph.png’)” on the returned chart object.
If you pass a block, it will be called, giving you access to the Gruff::StackedSideBar object before it is written to file (that is, if you also passed a file path).
Example 1:
Graphene.percentages(logs, :browser).('/path/to/browser-share.png', 'Browser Share')
Example 2:
Graphene.percentages(logs, :browser).('/path/to/browser-share.png') do |chart|
chart.title = 'Browser Share'
chart.font = '/path/to/font.ttf'
chart.theme = chart.theme_37signals
end
Example 3:
blog = Graphene.subtotals(logs, :browser)..to_blob
182 183 184 185 186 |
# File 'lib/graphene/gruff.rb', line 182 def (path=nil, title=nil, &block) Graphene.gruff do chart(Gruff::SideStackedBar.new, path, title, true, &block) end end |
#spider_chart(path = nil, title = nil, &block) ⇒ Object Also known as: spider_graph
Returns a Gruff::Spider object with the stats set.
Optionally you may pass a file path and chart title. If you pass a file path, the chart will be written to file automatically. Otherwise, you would call “write(‘/path/to/graph.png’)” on the returned chart object.
If you pass a block, it will be called, giving you access to the Gruff::Spider object before it is written to file (that is, if you also passed a file path).
Example 1:
Graphene.percentages(logs, :browser).spider_chart('/path/to/browser-share.png', 'Browser Share')
Example 2:
Graphene.percentages(logs, :browser).spider_chart('/path/to/browser-share.png') do |chart|
chart.title = 'Browser Share'
chart.font = '/path/to/font.ttf'
chart.theme = chart.theme_37signals
end
Example 3:
blog = Graphene.subtotals(logs, :browser).spider_chart.to_blob
214 215 216 217 218 |
# File 'lib/graphene/gruff.rb', line 214 def spider_chart(path=nil, title=nil, &block) Graphene.gruff do chart(Gruff::Spider.new(max_result), path, title, false, &block) end end |
#stacked_bar_chart(path = nil, title = nil, &block) ⇒ Object Also known as: stacked_bar_graph
Returns a Gruff::StackedBar object with the stats set.
Optionally you may pass a file path and chart title. If you pass a file path, the chart will be written to file automatically. Otherwise, you would call “write(‘/path/to/graph.png’)” on the returned chart object.
If you pass a block, it will be called, giving you access to the Gruff::StackedBar object before it is written to file (that is, if you also passed a file path).
Example 1:
Graphene.percentages(logs, :browser).('/path/to/browser-share.png', 'Browser Share')
Example 2:
Graphene.percentages(logs, :browser).('/path/to/browser-share.png') do |chart|
chart.title = 'Browser Share'
chart.font = '/path/to/font.ttf'
chart.theme = chart.theme_37signals
end
Example 3:
blog = Graphene.subtotals(logs, :browser)..to_blob
118 119 120 121 122 |
# File 'lib/graphene/gruff.rb', line 118 def (path=nil, title=nil, &block) Graphene.gruff do chart(Gruff::StackedBar.new, path, title, true, &block) end end |