Class: D3::Axis

Inherits:
Object
  • Object
show all
Includes:
Native
Defined in:
lib/opal/d3/axis.rb

Overview

It might be better to rewrap the Scale every time, as we’re duplicating it

Instance Method Summary collapse

Methods included from Native

included

Constructor Details

#initialize(native, scale_obj) ⇒ Axis

Returns a new instance of Axis.



6
7
8
9
10
11
# File 'lib/opal/d3/axis.rb', line 6

def initialize(native, scale_obj)
  raise unless native
  raise unless scale_obj
  @scale_obj = scale_obj
  @native = native
end

Instance Method Details

#call(context) ⇒ Object



20
21
22
23
# File 'lib/opal/d3/axis.rb', line 20

def call(context)
  @native.call(context.to_n)
  self
end

#scale(v = `undefined`) ⇒ Object Also known as: scale=



25
26
27
28
29
30
31
32
33
# File 'lib/opal/d3/axis.rb', line 25

def scale(v=`undefined`)
  if `v === undefined`
    @scale_obj
  else
    @scale_obj = v
    @native.JS.scale(v.to_n)
    self
  end
end

#tick_format(v = `undefined`, &block) ⇒ Object Also known as: tick_format=



47
48
49
50
51
52
53
54
55
56
# File 'lib/opal/d3/axis.rb', line 47

def tick_format(v=`undefined`, &block)
  v = block if block_given?
  if `v === undefined`
    result = @native.JS.tickFormat
    `result === null ? nil : result`
  else
    @native.JS.tickFormat(v == nil ? `null` : v)
    self
  end
end

#tick_values(v = `undefined`) ⇒ Object Also known as: tick_values=



36
37
38
39
40
41
42
43
44
# File 'lib/opal/d3/axis.rb', line 36

def tick_values(v=`undefined`)
  if `v === undefined`
    result = @native.JS.tickValues
    `result === null ? nil : result`
  else
    @native.JS.tickValues(v == nil ? `null` : v)
    self
  end
end