[ruby]
[gruff]
[graph]
[ruby_library]
色を変えてみよう。と言うことでGruffの中身を見てみる。
# A color scheme plucked from the colors on the popular usability blog.
def theme_37signals
# Colors
@green = '#339933'
@purple = '#cc99cc'
@blue = '#336699'
@yellow = '#FFF804'
@red = '#ff0000'
@orange = '#cf5910'
@black = 'black'
@colors = [@yellow, @blue, @green, @red, @purple, @orange, @black]
self.theme = {
:colors => @colors,
:marker_color => 'black',
:font_color => 'black',
:background_colors => ['#d1edf5', 'white']
}
end
ここんな感じで自由に設定できるみたい。
themeパターンをメソッドとしていくつか作ってライブラリにしとくと便利かも。
module Gruff
class Base
def theme_sex_graph
# Colors
@green = '#339933'
@purple = '#cc99cc'
@blue = '#336699'
@yellow = '#FFF804'
@red = '#FF5580'
@orange = '#cf5910'
@black = 'black'
@colors = [@blue, @red, @green, @yellow, @purple, @orange, @black]
self.theme = {
:colors => @colors,
:marker_color => 'black',
:font_color => 'black',
:background_colors => ['#d1edf5', 'white']
}
end
end
end
こんな感じのファイルをつくって require してみる。
あと、0の地点を上にしたいのでグラフを回転させる。
g = Gruff::Pie.new 500
g.font = "/usr/share/fonts/ja/TrueType/kochi-gothic-subst.ttf"
g.theme_sex_graph #テーマを変更
g.title = "性別"
g.data(["男性",41])
g.data(["女性", 59])
g.zero_degree = -90 #回転
結果。
とりあえず完成。