class MyChart::XY
Public Class Methods
new(objs_hash)
click to toggle source
# File lib/my_chart/xy.rb, line 5 def initialize objs_hash @objs_hash = objs_hash end
Public Instance Methods
==(obj)
click to toggle source
# File lib/my_chart/xy.rb, line 29 def == obj obj.kind_of? XY and value == obj.value end
complete_keys(range=nil)
click to toggle source
# File lib/my_chart/xy.rb, line 33 def complete_keys range=nil return self unless range new_hash = value.dup range.each do |key| new_hash[key] = [] unless new_hash[key] end XY.new new_hash end
datasets()
click to toggle source
# File lib/my_chart/xy.rb, line 25 def datasets [{label: 'xy', data: value.values.map{|objs| objs.count}}] end
group_by(&blk)
click to toggle source
# File lib/my_chart/xy.rb, line 13 def group_by &blk XYZ.new Hash[value.map{ |group_name, objs| [group_name, objs.group_by(&blk)] }] end
labels()
click to toggle source
# File lib/my_chart/xy.rb, line 21 def labels value.keys end
limit(config)
click to toggle source
# File lib/my_chart/xy.rb, line 57 def limit config limit_method, num = config.first ? [:first, config.first] : [:last, config.last] limited = value.to_a.send limit_method, num new_hash = Hash[limited] XY.new new_hash end
select(&blk)
click to toggle source
# File lib/my_chart/xy.rb, line 9 def select &blk XY.new value.select(&blk) end
sort(order)
click to toggle source
# File lib/my_chart/xy.rb, line 42 def sort order compare = if :key === order.asc -> a, b { a[0] <=> b[0] } elsif :key === order.desc -> a, b { b[0] <=> a[0] } elsif :count === order.asc -> a, b { a[1].size <=> b[1].size } else -> a, b { b[1].size <=> a[1].size } end sorted = value.to_a.sort &compare new_hash = Hash[sorted] XY.new new_hash end
value()
click to toggle source
# File lib/my_chart/xy.rb, line 17 def value @objs_hash end