Skip to content
This repository
Browse code

* Merge branch 'themes'

  • Loading branch information...
commit 9c73a95d50f6eaad260e82588e7a02dac3cd1c9d 2 parents 8c35469 + 46f4e71
Uwe Kubosch authored November 09, 2012
1  lib/gruff.rb
@@ -3,6 +3,7 @@
3 3
 # Extra full path added to fix loading errors on some installations.
4 4
 
5 5
 %w(
  6
+  themes
6 7
   base
7 8
   area
8 9
   bar
112  lib/gruff/base.rb
@@ -190,7 +190,7 @@ def initialize(target_width=DEFAULT_TARGET_WIDTH)
190 190
       initialize_ivars
191 191
 
192 192
       reset_themes
193  
-      theme_keynote
  193
+      self.theme = Themes::KEYNOTE
194 194
     end
195 195
 
196 196
     # Set instance variables for this object.
@@ -316,126 +316,28 @@ def theme=(options)
316 316
       render_background
317 317
     end
318 318
 
319  
-    # A color scheme similar to the popular presentation software.
320 319
     def theme_keynote
321  
-      # Colors
322  
-      @blue = '#6886B4'
323  
-      @yellow = '#FDD84E'
324  
-      @green = '#72AE6E'
325  
-      @red = '#D1695E'
326  
-      @purple = '#8A6EAF'
327  
-      @orange = '#EFAA43'
328  
-      @white = 'white'
329  
-      @colors = [@yellow, @blue, @green, @red, @purple, @orange, @white]
330  
-
331  
-      self.theme = {
332  
-        :colors => @colors,
333  
-        :marker_color => 'white',
334  
-        :font_color => 'white',
335  
-        :background_colors => ['black', '#4a465a']
336  
-      }
  320
+      self.theme = Themes::KEYNOTE
337 321
     end
338 322
 
339  
-    # A color scheme plucked from the colors on the popular usability blog.
340 323
     def theme_37signals
341  
-      # Colors
342  
-      @green = '#339933'
343  
-      @purple = '#cc99cc'
344  
-      @blue = '#336699'
345  
-      @yellow = '#FFF804'
346  
-      @red = '#ff0000'
347  
-      @orange = '#cf5910'
348  
-      @black = 'black'
349  
-      @colors = [@yellow, @blue, @green, @red, @purple, @orange, @black]
350  
-
351  
-      self.theme = {
352  
-        :colors => @colors,
353  
-        :marker_color => 'black',
354  
-        :font_color => 'black',
355  
-        :background_colors => ['#d1edf5', 'white']
356  
-      }
  324
+      self.theme = Themes::THIRTYSEVEN_SIGNALS
357 325
     end
358 326
 
359  
-    # A color scheme from the colors used on the 2005 Rails keynote
360  
-    # presentation at RubyConf.
361 327
     def theme_rails_keynote
362  
-      # Colors
363  
-      @green = '#00ff00'
364  
-      @grey = '#333333'
365  
-      @orange = '#ff5d00'
366  
-      @red = '#f61100'
367  
-      @white = 'white'
368  
-      @light_grey = '#999999'
369  
-      @black = 'black'
370  
-      @colors = [@green, @grey, @orange, @red, @white, @light_grey, @black]
371  
-
372  
-      self.theme = {
373  
-        :colors => @colors,
374  
-        :marker_color => 'white',
375  
-        :font_color => 'white',
376  
-        :background_colors => ['#0083a3', '#0083a3']
377  
-      }
  328
+      self.theme = Themes::RAILS_KEYNOTE
378 329
     end
379 330
 
380  
-    # A color scheme similar to that used on the popular podcast site.
381 331
     def theme_odeo
382  
-      # Colors
383  
-      @grey = '#202020'
384  
-      @white = 'white'
385  
-      @dark_pink = '#a21764'
386  
-      @green = '#8ab438'
387  
-      @light_grey = '#999999'
388  
-      @dark_blue = '#3a5b87'
389  
-      @black = 'black'
390  
-      @colors = [@grey, @white, @dark_blue, @dark_pink, @green, @light_grey, @black]
391  
-
392  
-      self.theme = {
393  
-        :colors => @colors,
394  
-        :marker_color => 'white',
395  
-        :font_color => 'white',
396  
-        :background_colors => ['#ff47a4', '#ff1f81']
397  
-      }
  332
+      self.theme = Themes::ODEO
398 333
     end
399 334
 
400  
-    # A pastel theme
401 335
     def theme_pastel
402  
-      # Colors
403  
-      @colors = [
404  
-                 '#a9dada', # blue
405  
-                 '#aedaa9', # green
406  
-                 '#daaea9', # peach
407  
-                 '#dadaa9', # yellow
408  
-                 '#a9a9da', # dk purple
409  
-                 '#daaeda', # purple
410  
-                 '#dadada' # grey
411  
-                ]
412  
-
413  
-      self.theme = {
414  
-        :colors => @colors,
415  
-        :marker_color => '#aea9a9', # Grey
416  
-        :font_color => 'black',
417  
-        :background_colors => 'white'
418  
-      }
  336
+      self.theme = Themes::PASTEL
419 337
     end
420 338
 
421  
-    # A greyscale theme
422 339
     def theme_greyscale
423  
-      # Colors
424  
-      @colors = [
425  
-                 '#282828', #
426  
-                 '#383838', #
427  
-                 '#686868', #
428  
-                 '#989898', #
429  
-                 '#c8c8c8', #
430  
-                 '#e8e8e8', #
431  
-                ]
432  
-
433  
-      self.theme = {
434  
-        :colors => @colors,
435  
-        :marker_color => '#aea9a9', # Grey
436  
-        :font_color => 'black',
437  
-        :background_colors => 'white'
438  
-      }
  340
+      self.theme = Themes::GREYSCALE
439 341
     end
440 342
 
441 343
     # Parameters are an array where the first element is the name of the dataset
3  lib/gruff/bullet.rb
... ...
@@ -1,4 +1,5 @@
1 1
 require File.dirname(__FILE__) + '/base'
  2
+require 'gruff/themes'
2 3
 
3 4
 # http://en.wikipedia.org/wiki/Bullet_graph
4 5
 class Gruff::Bullet < Gruff::Base
@@ -16,7 +17,7 @@ def initialize(target_width="400x40")
16 17
     initialize_ivars
17 18
 
18 19
     reset_themes
19  
-    theme_greyscale
  20
+    self.theme = Gruff::Themes::GREYSCALE
20 21
     @title_font_size = 20
21 22
   end
22 23
 
102  lib/gruff/themes.rb
... ...
@@ -0,0 +1,102 @@
  1
+module Gruff
  2
+  module Themes
  3
+    
  4
+    # A color scheme similar to the popular presentation software.
  5
+    KEYNOTE = {
  6
+      :colors => [
  7
+        '#FDD84E',  # yellow
  8
+        '#6886B4',  # blue
  9
+        '#72AE6E',  # green
  10
+        '#D1695E',  # red
  11
+        '#8A6EAF',  # purple
  12
+        '#EFAA43',  # orange
  13
+        'white'  
  14
+      ],
  15
+      :marker_color => 'white',
  16
+      :font_color => 'white',
  17
+      :background_colors => ['black', '#4a465a']
  18
+    }
  19
+
  20
+    # A color scheme plucked from the colors on the popular usability blog.
  21
+    THIRTYSEVEN_SIGNALS = {
  22
+      :colors => [
  23
+        '#FFF804',  # yellow
  24
+        '#336699',  # blue
  25
+        '#339933',  # green
  26
+        '#ff0000',  # red
  27
+        '#cc99cc',  # purple
  28
+        '#cf5910',  # orange
  29
+        'black'
  30
+      ],
  31
+      :marker_color => 'black',
  32
+      :font_color => 'black',
  33
+      :background_colors => ['#d1edf5', 'white']
  34
+    }
  35
+
  36
+    # A color scheme from the colors used on the 2005 Rails keynote
  37
+    # presentation at RubyConf.
  38
+    RAILS_KEYNOTE = {
  39
+      :colors => [
  40
+        '#00ff00',  # green
  41
+        '#333333',  # grey
  42
+        '#ff5d00',  # orange
  43
+        '#f61100',  # red
  44
+        'white',
  45
+        '#999999',  # light grey
  46
+        'black'
  47
+      ],
  48
+      :marker_color => 'white',
  49
+      :font_color => 'white',
  50
+      :background_colors => ['#0083a3', '#0083a3']
  51
+    }
  52
+
  53
+    # A color scheme similar to that used on the popular podcast site.
  54
+    ODEO = {
  55
+      :colors => [
  56
+        '#202020',  # grey
  57
+        'white',
  58
+        '#3a5b87',  # dark blue
  59
+        '#a21764',  # dark pink
  60
+        '#8ab438',  # green
  61
+        '#999999',  # light grey
  62
+        'black'
  63
+      ],
  64
+      :marker_color => 'white',
  65
+      :font_color => 'white',
  66
+      :background_colors => ['#ff47a4', '#ff1f81']
  67
+    }
  68
+
  69
+    # A pastel theme
  70
+    PASTEL = {
  71
+      :colors => [
  72
+        '#a9dada', # blue
  73
+        '#aedaa9', # green
  74
+        '#daaea9', # peach
  75
+        '#dadaa9', # yellow
  76
+        '#a9a9da', # dk purple
  77
+        '#daaeda', # purple
  78
+        '#dadada' # grey
  79
+      ],
  80
+      :marker_color => '#aea9a9', # Grey
  81
+      :font_color => 'black',
  82
+      :background_colors => 'white'
  83
+    }
  84
+
  85
+    # A greyscale theme
  86
+    GREYSCALE = {
  87
+      :colors => [
  88
+        '#282828', #
  89
+        '#383838', #
  90
+        '#686868', #
  91
+        '#989898', #
  92
+        '#c8c8c8', #
  93
+        '#e8e8e8', #
  94
+      ],
  95
+      :marker_color => '#aea9a9', # Grey
  96
+      :font_color => 'black',
  97
+      :background_colors => 'white'
  98
+    }
  99
+    
  100
+  end
  101
+end
  102
+
4  test/test_bar.rb
@@ -25,12 +25,12 @@ def test_bar_graph
25 25
         
26 26
     g = setup_basic_graph
27 27
     g.title = "Visual Multi-Line Bar Graph Test"
28  
-    g.theme_rails_keynote
  28
+    g.theme = Gruff::Themes::RAILS_KEYNOTE
29 29
     g.write("test/output/bar_rails_keynote.png")
30 30
     
31 31
     g = setup_basic_graph
32 32
     g.title = "Visual Multi-Line Bar Graph Test"
33  
-    g.theme_odeo
  33
+    g.theme = Gruff::Themes::ODEO
34 34
     g.write("test/output/bar_odeo.png")
35 35
   end
36 36
   
6  test/test_line.rb
@@ -535,7 +535,7 @@ def line_graph_with_themes(size=nil)
535 535
     g.title = "Multi-Line Graph Test #{size}"
536 536
     g.labels = @labels
537 537
     g.baseline_value = 90
538  
-    g.theme_37signals
  538
+    g.theme = Gruff::Themes::THIRTYSEVEN_SIGNALS
539 539
     @datasets.each do |data|
540 540
       g.data(data[0], data[1])
541 541
     end
@@ -545,7 +545,7 @@ def line_graph_with_themes(size=nil)
545 545
     g.title = "Multi-Line Graph Test #{size}"
546 546
     g.labels = @labels
547 547
     g.baseline_value = 90
548  
-    g.theme_rails_keynote
  548
+    g.theme = Gruff::Themes::RAILS_KEYNOTE
549 549
     @datasets.each do |data|
550 550
       g.data(data[0], data[1])
551 551
     end
@@ -555,7 +555,7 @@ def line_graph_with_themes(size=nil)
555 555
     g.title = "Multi-Line Graph Test #{size}"
556 556
     g.labels = @labels
557 557
     g.baseline_value = 90
558  
-    g.theme_odeo
  558
+    g.theme = Gruff::Themes::ODEO
559 559
     @datasets.each do |data|
560 560
       g.data(data[0], data[1])
561 561
     end
4  test/test_pie.rb
@@ -30,7 +30,7 @@ def test_pie_graph
30 30
   def test_pie_graph_greyscale
31 31
     g = Gruff::Pie.new
32 32
     g.title = "Greyscale Pie Graph Test"
33  
-    g.theme_greyscale
  33
+    g.theme = Gruff::Themes::GREYSCALE
34 34
     @datasets.each do |data|
35 35
       g.data(data[0], data[1])
36 36
     end
@@ -41,7 +41,7 @@ def test_pie_graph_greyscale
41 41
 
42 42
   def test_pie_graph_pastel
43 43
     g = Gruff::Pie.new
44  
-    g.theme_pastel
  44
+    g.theme = Gruff::Themes::PASTEL
45 45
     g.title = "Pastel Pie Graph Test"
46 46
     @datasets.each do |data|
47 47
       g.data(data[0], data[1])
2  test/test_spider.rb
@@ -106,7 +106,7 @@ def test_theme_37signals
106 106
      g.data(data[0], data[1])
107 107
     end
108 108
 
109  
-    g.theme_37signals
  109
+    g.theme = Gruff::Themes::THIRTYSEVEN_SIGNALS
110 110
 
111 111
     # Default theme
112 112
     g.write("test/output/spider_37signals.png")

0 notes on commit 9c73a95

Please sign in to comment.
Something went wrong with that request. Please try again.