Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add Graphene.theme and Graphene.font, which allows the user to set de…
…fault theme options
  • Loading branch information
jhollinger committed Oct 5, 2012
1 parent 831bb8d commit 9f7bcd2
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/graphene/gruff.rb
@@ -1,4 +1,12 @@
module Graphene
class << self
# The default Gruff font path
attr_accessor :font

# The default Gruff theme
attr_accessor :theme
end

# Executes the given block if Gruff is available. Raises a GrapheneException if not.
def self.gruff
if defined? Gruff
Expand All @@ -8,6 +16,14 @@ def self.gruff
end
end

private

# Apply the default theme and font to the given Gruff chart
def self.theme!(chart)
chart.font = self.font if self.font
chart.theme = self.theme if self.theme
end

# Extends calculators with one-dimensional graphs, like pie charts.
module OneDGraphs
# Returns a Gruff::Pie object with the stats set.
Expand Down Expand Up @@ -206,6 +222,7 @@ def spider_chart(path=nil, title=nil, &block)

# Builds a chart
def chart(chart, path=nil, title=nil, hack=false, &block)
Graphene.theme! chart
chart.title = title unless title.nil?
block.call(chart) if block

Expand Down Expand Up @@ -394,6 +411,7 @@ def accumulator_bar_graph(path=nil, title=nil, &block)

# Builds a graph
def graph(graph, path=nil, title=nil, &block)
Graphene.theme! graph
graph.title = title unless title.nil?

# Create an empty array for each group (e.g. {["Firefox"] => [], ["Safari"] => []}), even if it's empty.
Expand Down

0 comments on commit 9f7bcd2

Please sign in to comment.