Class: Ccharts::Settings::StackSettings
- Inherits:
-
Object
- Object
- Ccharts::Settings::StackSettings
- Defined in:
- lib/ccharts/settings.rb
Overview
stacked bar
Instance Method Summary collapse
- #background(v) ⇒ Object
- #category_labels(v) ⇒ Object
- #colors(v) ⇒ Object
-
#counts(series_count, cats_count) ⇒ Object
inject the series/category counts known only at render time.
-
#initialize ⇒ StackSettings
constructor
A new instance of StackSettings.
- #plain(v) ⇒ Object
- #show_labels(v) ⇒ Object
- #show_prices(v) ⇒ Object
- #to_ffi ⇒ Object
Constructor Details
#initialize ⇒ StackSettings
Returns a new instance of StackSettings.
214 215 216 217 218 219 220 221 |
# File 'lib/ccharts/settings.rb', line 214 def initialize @colors = nil @bg = nil @cat_labels = nil @show_labels = false @show_prices = false @plain = false end |
Instance Method Details
#background(v) ⇒ Object
224 |
# File 'lib/ccharts/settings.rb', line 224 def background(v); @bg = v; self; end |
#category_labels(v) ⇒ Object
225 |
# File 'lib/ccharts/settings.rb', line 225 def category_labels(v); @cat_labels = v; self; end |
#colors(v) ⇒ Object
223 |
# File 'lib/ccharts/settings.rb', line 223 def colors(v); @colors = v; self; end |
#counts(series_count, cats_count) ⇒ Object
inject the series/category counts known only at render time
231 232 233 234 235 |
# File 'lib/ccharts/settings.rb', line 231 def counts(series_count, cats_count) @series_count = series_count @cats_count = cats_count self end |
#plain(v) ⇒ Object
228 |
# File 'lib/ccharts/settings.rb', line 228 def plain(v); @plain = !!v; self; end |
#show_labels(v) ⇒ Object
226 |
# File 'lib/ccharts/settings.rb', line 226 def show_labels(v); @show_labels = !!v; self; end |
#show_prices(v) ⇒ Object
227 |
# File 'lib/ccharts/settings.rb', line 227 def show_prices(v); @show_prices = !!v; self; end |
#to_ffi ⇒ Object
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/ccharts/settings.rb', line 237 def to_ffi s = FFI::StackSettings.malloc keep = [] # NULL-terminated per-series color pointer array. color_ptrs = [] if @plain @series_count.times { color_ptrs << FFI::EMPTY.to_i } elsif @colors && !@colors.empty? @colors.each do |c| p = FFI.color_ptr(c, false) keep << p color_ptrs << p.to_i end end colors_addr = if color_ptrs.empty? Fiddle::NULL else Fiddle::Pointer[(color_ptrs + [0]).pack("Q*")].to_i end bgp = FFI.color_ptr(@bg, @plain) keep << bgp cat_ptrs = [] if @cat_labels && !@cat_labels.empty? @cat_labels.each do |l| p = FFI.cstr(l) keep << p cat_ptrs << p.to_i end end cat_addr = cat_ptrs.empty? ? Fiddle::NULL : Fiddle::Pointer[cat_ptrs.pack("Q*")].to_i s.colors = colors_addr s.bg_color = bgp.to_i s.cat_labels = cat_addr s.series = @series_count s.cats = @cats_count s.show_labels = @show_labels ? 1 : 0 s.show_prices = @show_prices ? 1 : 0 [s, keep] end |