Module: Analytica::Visualization::Representation
- Included in:
- DataSet, DataSystem
- Defined in:
- lib/visualization.rb
Instance Method Summary collapse
- #add_custom(item) ⇒ Object
- #bar_settings(bar_settings) ⇒ Object
- #common_options ⇒ Object
- #generate_custom ⇒ Object
- #generate_labels ⇒ Object
- #generate_title ⇒ Object
- #set_labels(params = {}) ⇒ Object
- #set_title(params) ⇒ Object
Instance Method Details
#add_custom(item) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/visualization.rb', line 67 def add_custom(item) enforce!(:string, item) @custom_set = true @custom += "&" if @custom.size > 0 @custom += item end |
#bar_settings(bar_settings) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/visualization.rb', line 59 def () enforce_map_optional!({ :width => :natural_number, :spacing => :natural_number, :group_spacing => :natural_number}, ) end |
#common_options ⇒ Object
160 161 162 163 164 165 166 |
# File 'lib/visualization.rb', line 160 def = {} .merge!(generate_labels) .merge!(generate_title) .merge!(generate_custom) end |
#generate_custom ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/visualization.rb', line 152 def generate_custom = { :custom => @custom } @custom = "" end |
#generate_labels ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/visualization.rb', line 83 def generate_labels = {} if @labels_set if @labels[:data] add_custom("chm=N#{@labels[:data][:prefix]}*f#{@labels[:data][:decimal]}*#{@labels[:data][:postfix]},#{@labels[:data][:color]},0,-1,#{@labels[:data][:size]}&chds=0,#{datamax}") end if @labels[:axis] axis_labels = { :axis_with_labels => ['x', 'y'], :axis_labels => [@labels[:axis][:data], ["#{0}", "#{(datamax*0.5).to_i}", "#{datamax.to_i}"]] } axis_style = case @labels[:axis][:style] when :axis_tick "lt" when :axis_only "l" when :tick_only "t" when :none "_" end add_custom("chxs=0N#{@labels[:axis][:prefix]}*f#{@labels[:axis][:decimal]}*#{@labels[:axis][:postfix]},#{@labels[:axis][:color]},#{@labels[:axis][:size]},#{axis_style},#{@labels[:axis][:tick_color]}|1N#{@labels[:axis][:prefix]}*f#{@labels[:axis][:decimal]}*#{@labels[:axis][:postfix]},#{@labels[:axis][:color]},#{@labels[:axis][:size]},#{axis_style},#{@labels[:axis][:tick_color]}") #http://code.google.com/apis/chart/docs/chart_params.html .merge!(axis_labels) elsif @labels[:x_axis] x_axis_label = { :axis_with_labels => ['x'], :axis_labels => @labels[:x_axis][:data].size == 0 ? self.map{|n|"#{n}"} : @labels[:x_axis][:data] } axis_style = case @labels[:x_axis][:style] when :axis_tick "lt" when :axis_only "l" when :tick_only "t" when :none "_" end add_custom("chxs=0N#{@labels[:x_axis][:prefix]}*f#{@labels[:x_axis][:decimal]}*#{@labels[:x_axis][:postfix]},#{@labels[:x_axis][:color]},#{@labels[:x_axis][:size]},#{axis_style},#{@labels[:x_axis][:tick_color]}") #http://code.google.com/apis/chart/docs/chart_params.html .merge!(x_axis_label) elsif @labels[:y_axis] y_axis_label = { :axis_with_labels => ['y'], :axis_labels => @labels[:y_axis][:data].size == 0 ? ["#{0}", "#{(datamax*0.5).to_i}", "#{datamax.to_i}"] : @labels[:y_axis][:data] } axis_style = case @labels[:y_axis][:style] when :axis_tick "lt" when :axis_only "l" when :tick_only "t" when :none "_" end add_custom("chxs=0N#{@labels[:y_axis][:prefix]}*f#{@labels[:y_axis][:decimal]}*#{@labels[:y_axis][:postfix]},#{@labels[:y_axis][:color]},#{@labels[:y_axis][:size]},#{axis_style},#{@labels[:y_axis][:tick_color]}") #http://code.google.com/apis/chart/docs/chart_params.html .merge!(y_axis_label) end end end |
#generate_title ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/visualization.rb', line 75 def generate_title = {} if @title_set .merge!({:title => @title[:text], :title_size => @title[:size], :title_color => @title[:color]}) end end |
#set_labels(params = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/visualization.rb', line 8 def set_labels(params={}) enforce_map_defaults!({ :data => [], :type => :axis, :style => :axis_tick, :prefix => ' ', :postfix => ' ', :decimal => 0, :color => '000000', :tick_color => "333333", :size => 10}, params) enforce_primitive!(Array, params[:data]) enforce_map!({ :type => [:axis, :x_axis, :y_axis, :data], :prefix => :string, :decimal => :integer, :color => :hex_color, :tick_color => :hex_color, :style => [:axis_tick, :axis_only, :tick_only, :none], :size => :natural_number}, params) @labels_set = true @labels = {} if @labels.nil? @labels[params[:type]] = {} @labels[params[:type]][:prefix] = params[:prefix] == ' ' ? '' : params[:prefix] @labels[params[:type]][:postfix] = params[:postfix] == ' ' ? '' : params[:postfix] @labels[params[:type]][:decimal] = params[:decimal] @labels[params[:type]][:color] = params[:color] @labels[params[:type]][:size] = params[:size] @labels[params[:type]][:style] = params[:style] @labels[params[:type]][:tick_color] = params[:tick_color] @labels[params[:type]][:data] = params[:data] end |
#set_title(params) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/visualization.rb', line 45 def set_title(params) enforce_map_defaults!({ :text => ' ', :size => 11, :color => "000000"}, params) enforce_map!({ :text => :string, :size => :natural_number, :color => :hex_color}, params) @title = params @title_set = true end |