Class: Vis::DataSet
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from DataCommon
#[], #get, #get_ids, #off, #on, #options_to_native
#off, #on
Methods included from Utilities
#hash_array_to_native, included, #lower_camelize, #lower_camelize_hash, #native_to_hash_array
Constructor Details
#initialize(*args) ⇒ DataSet
Returns a new instance of DataSet.
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/vis/data_set.rb', line 20
def initialize(*args)
if args[0] && `Opal.is_a(args[0], Opal.Hash)`
hash_array = []
options = args[0]
elsif args[0] && `Opal.is_a(args[0], Opal.Array)`
hash_array = args[0]
options = args[1] ? args[1] : {}
else
hash_array = []
options = {}
end
native_data = hash_array_to_native(hash_array)
native_options = options_to_native(options)
@event_handlers = {}
@native = `new vis.DataSet(native_data, native_options)`
end
|
Instance Attribute Details
#event_handlers ⇒ Object
Returns the value of attribute event_handlers.
12
13
14
|
# File 'lib/vis/data_set.rb', line 12
def event_handlers
@event_handlers
end
|
Class Method Details
.wrap(native) ⇒ Object
14
15
16
17
18
|
# File 'lib/vis/data_set.rb', line 14
def self.wrap(native)
instance = allocate
instance.instance_variable_set(:@native, native)
instance
end
|
Instance Method Details
#[]=(id, hash) ⇒ Object
37
38
39
40
41
42
43
|
# File 'lib/vis/data_set.rb', line 37
def []=(id, hash)
if get(id)
update(hash[:id] = id)
else
add(hash[:id] = id)
end
end
|
#add(*args) ⇒ Object
45
46
47
48
49
50
51
52
|
# File 'lib/vis/data_set.rb', line 45
def add(*args)
if args[0] && `Opal.is_a(args[0], Opal.Hash)`
args[0] = args[0].to_n
elsif args[0] && `Opal.is_a(args[0], Opal.Array)`
args[0] = hash_array_to_native(args[0])
end
`self["native"].add.apply(self["native"], Opal.to_a(args))`
end
|
#each(options = nil, &block) ⇒ Object
54
55
56
57
|
# File 'lib/vis/data_set.rb', line 54
def each(options = nil, &block)
native_options = options_to_native(options)
`return self["native"].forEach(function(item) { return block.$call(Opal.Hash.$new(item)); }, native_options)`
end
|
#get_data_set ⇒ Object
59
60
61
|
# File 'lib/vis/data_set.rb', line 59
def get_data_set
self
end
|
#map(options = nil, &block) ⇒ Object
63
64
65
66
|
# File 'lib/vis/data_set.rb', line 63
def map(options = nil, &block)
native_options = options_to_native(options)
`return self["native"].map(function(item) { return #{block.call(`Opal.Hash.$new(item)`)}; }, native_options)`
end
|
#max(field) ⇒ Object
68
69
70
71
|
# File 'lib/vis/data_set.rb', line 68
def max(field)
res = @native.JS.max(field)
`res !== null ? Opal.Hash.$new(res) : #{nil}`
end
|
#min(field) ⇒ Object
73
74
75
76
|
# File 'lib/vis/data_set.rb', line 73
def min(field)
res = @native.JS.min(field)
`res !== null ? Opal.Hash.$new(res) : #{nil}`
end
|
#remove(*args) ⇒ Object
78
79
80
81
82
83
84
85
|
# File 'lib/vis/data_set.rb', line 78
def remove(*args)
if `Opal.is_a(args[0], Opal.Array)`
args[0] = hash_array_to_native(args[0])
elsif `Opal.is_a(args[0], Opal.Hash)`
args[0] = args[0].to_n
end
`self["native"].remove.apply(self["native"], Opal.to_a(args))`
end
|
#update(*args) ⇒ Object
87
88
89
90
91
92
93
94
|
# File 'lib/vis/data_set.rb', line 87
def update(*args)
if args[0] && `Opal.is_a(args[0], Opal.Hash)`
args[0] = args[0].to_n
elsif args[0] && `Opal.is_a(args[0], Opal.Array)`
args[0] = hash_array_to_native(args[0])
end
`self["native"].update.apply(self["native"], Opal.to_a(args))`
end
|