Class: ChartJS::Dataset

Inherits:
Object
  • Object
show all
Defined in:
lib/chart_js/chart/dataset.rb,
lib/chart_js/chart/bar_chart/dataset.rb,
lib/chart_js/chart/line_chart/dataset.rb,
lib/chart_js/chart/radar_chart/dataset.rb

Instance Method Summary collapse

Constructor Details

#initialize(label, &block) ⇒ Dataset

Returns a new instance of Dataset.



10
11
12
13
14
15
# File 'lib/chart_js/chart/dataset.rb', line 10

def initialize(label, &block)
  @container = Hash.new
  #fill(false)
  label(label)
  build(&block)
end

Instance Method Details

#axis_id(value, axis) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/chart_js/chart/dataset.rb', line 34

def axis_id(value, axis)
  case axis
  when :x
    @container['xAxisID'] = value
  when :y
    @container['yAxisID'] = value
  end
end

#background(&block) ⇒ Object



65
66
67
# File 'lib/chart_js/chart/dataset.rb', line 65

def background(&block)
  @container = Background.new(@container).build(&block)
end

#border(&block) ⇒ Object



69
70
71
# File 'lib/chart_js/chart/dataset.rb', line 69

def border(&block)
  @container = Border.new(@container).build(&block)
end

#build(&block) ⇒ Object



17
18
19
20
# File 'lib/chart_js/chart/dataset.rb', line 17

def build(&block)
  instance_eval(&block)
  @container 
end

#color(value = :random, type = :both) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/chart_js/chart/dataset.rb', line 43

def color(value = :random, type = :both)
  if value == :random
    c = "##{SecureRandom.hex(3)}"
    color c, :border     if type == :both || type == :border 
    color c, :background if type == :both || type == :background
    return 
  end
  case type 
  when :border
    @container['borderColor'] = value
  when :background
    @container['backgroundColor'] = value
  when :both
    color value, :border
    color value, :background
  end
end

#data(value) ⇒ Object



22
23
24
# File 'lib/chart_js/chart/dataset.rb', line 22

def data(value)
  @container['data'] = value
end

#fill(value = true) ⇒ Object



30
31
32
# File 'lib/chart_js/chart/dataset.rb', line 30

def fill(value = true)
  @container['fill'] = value
end

#label(value) ⇒ Object



26
27
28
# File 'lib/chart_js/chart/dataset.rb', line 26

def label(value)
  @container['label'] = value
end

#line(&block) ⇒ Object



77
78
79
# File 'lib/chart_js/chart/dataset.rb', line 77

def line(&block)
  @container = Line.new(@container).build(&block)
end

#point(&block) ⇒ Object



73
74
75
# File 'lib/chart_js/chart/dataset.rb', line 73

def point(&block)
  @container = Point.new(@container).build(&block)
end

#span_gaps(value = true) ⇒ Object



61
62
63
# File 'lib/chart_js/chart/dataset.rb', line 61

def span_gaps(value = true)
  @container['spanGaps'] = value
end

#to_hObject



81
82
83
# File 'lib/chart_js/chart/dataset.rb', line 81

def to_h
  @container
end