From 9f7bcd2b64095ced9efab4df44f5cdb285130e69 Mon Sep 17 00:00:00 2001 From: Jordan Hollinger Date: Fri, 5 Oct 2012 01:24:14 -0400 Subject: [PATCH] Add Graphene.theme and Graphene.font, which allows the user to set default theme options --- lib/graphene/gruff.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/graphene/gruff.rb b/lib/graphene/gruff.rb index e1f577c..06f1e17 100644 --- a/lib/graphene/gruff.rb +++ b/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 @@ -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. @@ -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 @@ -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.