Class: Charty::Plotter

Inherits:
Object
  • Object
show all
Defined in:
lib/charty/plotter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(backend_name) ⇒ Plotter

Returns a new instance of Plotter.


3
4
5
6
# File 'lib/charty/plotter.rb', line 3

def initialize(backend_name)
  backend_class = Backends.find_backend_class(backend_name)
  @backend = backend_class.new
end

Instance Attribute Details

#tableObject

Returns the value of attribute table.


12
13
14
# File 'lib/charty/plotter.rb', line 12

def table
  @table
end

Instance Method Details

#bar(**args, &block) ⇒ Object


118
119
120
121
# File 'lib/charty/plotter.rb', line 118

def bar(**args, &block)
  context = RenderContext.new :bar, **args, &block
  context.apply(@backend)
end

#barh(**args, &block) ⇒ Object


123
124
125
126
# File 'lib/charty/plotter.rb', line 123

def barh(**args, &block)
  context = RenderContext.new :barh, **args, &block
  context.apply(@backend)
end

#box_plot(**args, &block) ⇒ Object


128
129
130
131
# File 'lib/charty/plotter.rb', line 128

def box_plot(**args, &block)
  context = RenderContext.new :box_plot, **args, &block
  context.apply(@backend)
end

#bubble(**args, &block) ⇒ Object


133
134
135
136
# File 'lib/charty/plotter.rb', line 133

def bubble(**args, &block)
  context = RenderContext.new :bubble, **args, &block
  context.apply(@backend)
end

#curve(**args, &block) ⇒ Object


138
139
140
141
# File 'lib/charty/plotter.rb', line 138

def curve(**args, &block)
  context = RenderContext.new :curve, **args, &block
  context.apply(@backend)
end

#error_bar(**args, &block) ⇒ Object


148
149
150
151
# File 'lib/charty/plotter.rb', line 148

def error_bar(**args, &block)
  context = RenderContext.new :error_bar, **args, &block
  context.apply(@backend)
end

#hist(**args, &block) ⇒ Object


153
154
155
156
# File 'lib/charty/plotter.rb', line 153

def hist(**args, &block)
  context = RenderContext.new :hist, **args, &block
  context.apply(@backend)
end

#layout(definition = :horizontal) ⇒ Object


158
159
160
# File 'lib/charty/plotter.rb', line 158

def layout(definition=:horizontal)
  Layout.new(@backend, definition)
end

#scatter(**args, &block) ⇒ Object


143
144
145
146
# File 'lib/charty/plotter.rb', line 143

def scatter(**args, &block)
  context = RenderContext.new :scatter, **args, &block
  context.apply(@backend)
end

#to_bar(x, y, **args, &block) ⇒ Object


14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/charty/plotter.rb', line 14

def to_bar(x, y, **args, &block)
  seriesx = table[x]
  seriesy = table[y]
  xrange = (seriesx.min)..(seriesx.max)
  yrange = (seriesy.min)..(seriesy.max)
  bar do
    series seriesx, seriesy
    range x: xrange, y: yrange
    xlabel x
    ylabel y
  end
end

#to_barh(x, y, **args, &block) ⇒ Object


27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/charty/plotter.rb', line 27

def to_barh(x, y, **args, &block)
  seriesx = table[x]
  seriesy = table[y]
  xrange = (seriesx.min)..(seriesx.max)
  yrange = (seriesy.min)..(seriesy.max)
  barh do
    series seriesx, seriesy
    range x: xrange, y: yrange
    xlabel x
    ylabel y
  end
end

#to_box_plot(x, y, **args, &block) ⇒ Object


40
41
42
43
44
45
46
47
48
49
50
# File 'lib/charty/plotter.rb', line 40

def to_box_plot(x, y, **args, &block)
  serieses = [table[x], table[y]]
  xrange = 0..serieses.size
  yrange = (serieses.flatten.min - 1)..(serieses.flatten.max + 1)
  box_plot do
    data serieses
    range x: xrange, y: yrange
    xlabel x
    ylabel y
  end
end

#to_bubble(x, y, z, **args, &block) ⇒ Object


52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/charty/plotter.rb', line 52

def to_bubble(x, y, z, **args, &block)
  seriesx = table[x]
  seriesy = table[y]
  seriesz = table[z]
  xrange = (seriesx.min)..(seriesx.max)
  yrange = (seriesy.min)..(seriesy.max)
  bubble do
    series seriesx, seriesy, seriesz
    range x: xrange, y: yrange
    xlabel x
    ylabel y
  end
end

#to_curve(x, y, **args, &block) ⇒ Object


66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/charty/plotter.rb', line 66

def to_curve(x, y, **args, &block)
  seriesx = table[x]
  seriesy = table[y]
  xrange = (seriesx.min)..(seriesx.max)
  yrange = (seriesy.min)..(seriesy.max)
  curve do
    series seriesx, seriesy
    range x: xrange, y: yrange
    xlabel x
    ylabel y
  end
end

#to_error_bar(x, y, **args, &block) ⇒ Object


92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/charty/plotter.rb', line 92

def to_error_bar(x, y, **args, &block)
  # TODO: It is not yet decided how to include data including xerror and yerror.
  seriesx = table[x]
  seriesy = table[y]
  xrange = (seriesx.min)..(seriesx.max)
  yrange = (seriesy.min)..(seriesy.max)
  error_bar do
    series seriesx, seriesy
    range x: xrange, y: yrange
    xlabel x
    ylabel y
  end
end

#to_hst(x, y, **args, &block) ⇒ Object


106
107
108
109
110
111
112
113
114
115
116
# File 'lib/charty/plotter.rb', line 106

def to_hst(x, y, **args, &block)
  serieses = [table[x], table[y]]
  xrange = (serieses.flatten.min - 1)..(serieses.flatten.max + 1)
  yrange = 0..serieses[0].size
  hist do
    data serieses
    range x: xrange, y: yrange
    xlabel x
    ylabel y
  end
end

#to_scatter(x, y, **args, &block) ⇒ Object


79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/charty/plotter.rb', line 79

def to_scatter(x, y, **args, &block)
  seriesx = table[x]
  seriesy = table[y]
  xrange = (seriesx.min)..(seriesx.max)
  yrange = (seriesy.min)..(seriesy.max)
  scatter do
    series seriesx, seriesy
    range x: xrange, y: yrange
    xlabel x
    ylabel y
  end
end