Class: D3::Nest
- Inherits:
-
Object
- Object
- D3::Nest
- Defined in:
- lib/opal/d3/nest.rb
Instance Method Summary collapse
- #entries(array) ⇒ Object
-
#initialize ⇒ Nest
constructor
A new instance of Nest.
- #key(&block) ⇒ Object
-
#map(array) ⇒ Object
This is really attrocious, why don’t we just return nested hash?.
- #object(array) ⇒ Object
- #rollup(&block) ⇒ Object
- #sort_keys(key = nil, &block) ⇒ Object
- #sort_values(key = nil, &block) ⇒ Object
Constructor Details
#initialize ⇒ Nest
Returns a new instance of Nest.
3 4 5 6 7 |
# File 'lib/opal/d3/nest.rb', line 3 def initialize @native = `window.d3`.JS.nest @depth = 0 @rollup = false end |
Instance Method Details
#entries(array) ⇒ Object
53 54 55 56 |
# File 'lib/opal/d3/nest.rb', line 53 def entries(array) result = @native.JS.entries(array) map_entries(result, @depth) end |
#key(&block) ⇒ Object
9 10 11 12 13 |
# File 'lib/opal/d3/nest.rb', line 9 def key(&block) @native.JS.key(block) @depth += 1 self end |
#map(array) ⇒ Object
This is really attrocious, why don’t we just return nested hash?
48 49 50 51 |
# File 'lib/opal/d3/nest.rb', line 48 def map(array) result = @native.JS.map(array) map_map(result, @depth) end |
#object(array) ⇒ Object
58 59 60 |
# File 'lib/opal/d3/nest.rb', line 58 def object(array) @native.JS.object(array) end |
#rollup(&block) ⇒ Object
62 63 64 65 66 |
# File 'lib/opal/d3/nest.rb', line 62 def rollup(&block) @native.JS.rollup(block) @rollup = true self end |
#sort_keys(key = nil, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/opal/d3/nest.rb', line 15 def sort_keys(key=nil,&block) if block raise ArgumentError, "Pass block or :ascending/:descending" else if key == :ascending block = `window.d3.ascending` elsif key == :descending block = `window.d3.descending` else raise ArgumentError, "Pass block or :ascending/:descending" end end @native.JS.sortKeys(block) self end |
#sort_values(key = nil, &block) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/opal/d3/nest.rb', line 31 def sort_values(key=nil,&block) if block raise ArgumentError, "Pass block or :ascending/:descending" else if key == :ascending block = `window.d3.ascending` elsif key == :descending block = `window.d3.descending` else raise ArgumentError, "Pass block or :ascending/:descending" end end @native.JS.sortValues(block) self end |