Class: D3::Selection
- Inherits:
-
Object
- Object
- D3::Selection
- Includes:
- Native
- Defined in:
- lib/opal/d3/selection.rb
Instance Method Summary collapse
- #append(name = `undefined`, &block) ⇒ Object
-
#attr(name, value = `undefined`, &block) ⇒ Object
nil means something specific (reset value), so we need another special value.
- #classed(classes, yesno = `undefined`, &block) ⇒ Object
- #data(data = nil, key = nil, &block) ⇒ Object
- #each(other = `undefined`, &block) ⇒ Object
- #filter(other = `undefined`, &block) ⇒ Object
- #insert(name = `undefined`, before = `undefined`, &block) ⇒ Object
- #inspect ⇒ Object
- #merge(other) ⇒ Object
- #property(key, value = `undefined`) ⇒ Object
-
#style(name, value = `undefined`, priority = `undefined`, &block) ⇒ Object
Usage: style(“foo”) style(“foo”){ value } style(“foo”, value) style(“foo”, value, priority).
Methods included from Native
Instance Method Details
#append(name = `undefined`, &block) ⇒ Object
28 29 30 31 32 |
# File 'lib/opal/d3/selection.rb', line 28 def append(name=`undefined`, &block) raise if `name !== undefined` and block_given? name = block if block_given? D3::Selection.new @native.JS.append(name.to_n) end |
#attr(name, value = `undefined`, &block) ⇒ Object
nil means something specific (reset value), so we need another special value
120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/opal/d3/selection.rb', line 120 def attr(name, value=`undefined`, &block) if block @native.JS.attr(name, block) self elsif `value == undefined` @native.JS.attr(name) elsif value == nil @native.JS.attr(name, `null`) self else @native.JS.attr(name, value) self end end |
#classed(classes, yesno = `undefined`, &block) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/opal/d3/selection.rb', line 63 def classed(classes, yesno=`undefined`, &block) if block_given? @native.JS.classed(classes, block) self elsif `yesno !== undefined` @native.JS.classed(classes, yesno) self else @native.JS.classed(classes) end end |
#data(data = nil, key = nil, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/opal/d3/selection.rb', line 16 def data(data=nil,key=nil,&block) if block self.class.new @native.JS.data(block) elsif key != nil self.class.new @native.JS.data(data,key) elsif data != nil self.class.new @native.JS.data(data) else @native.JS.data end end |
#each(other = `undefined`, &block) ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/opal/d3/selection.rb', line 83 def each(other=`undefined`,&block) if block_given? @native.JS.each(block) else @native.JS.each(other) end self end |
#filter(other = `undefined`, &block) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/opal/d3/selection.rb', line 75 def filter(other=`undefined`,&block) if block_given? D3::Selection.new @native.JS.filter(block) else D3::Selection.new @native.JS.filter(other) end end |
#insert(name = `undefined`, before = `undefined`, &block) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/opal/d3/selection.rb', line 34 def insert(name=`undefined`, before=`undefined`, &block) if `name === undefined` raise unless block_given? D3::Selection.new @native.JS.insert(block.to_n) elsif `before === undefined` if block_given? D3::Selection.new @native.JS.insert(name.to_n, block.to_n) else D3::Selection.new @native.JS.insert(name.to_n) end else raise if block_given? D3::Selection.new @native.JS.insert(name.to_n, before.to_n) end end |
#inspect ⇒ Object
9 10 11 |
# File 'lib/opal/d3/selection.rb', line 9 def inspect `#@native.toString()` end |
#merge(other) ⇒ Object
59 60 61 |
# File 'lib/opal/d3/selection.rb', line 59 def merge(other) D3::Selection.new @native.JS.merge(other.to_n) end |
#property(key, value = `undefined`) ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/opal/d3/selection.rb', line 92 def property(key, value=`undefined`) if `value === undefined` @native.JS.property(key) else @native.JS.property(key, value) self end end |
#style(name, value = `undefined`, priority = `undefined`, &block) ⇒ Object
Usage: style(“foo”) style(“foo”){ value } style(“foo”, value) style(“foo”, value, priority)
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/opal/d3/selection.rb', line 106 def style(name, value=`undefined`, priority=`undefined`, &block) if block raise if `name === undefined` or `priority !== undefined` or `value !== undefined` Selection.new @native.JS.style(name, block) elsif `value === undefined` @native.JS.style(name) else value = `value === nil ? null : value` Selection.new @native.JS.style(name, value, priority) end end |