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(adapter_name) ⇒ Plotter

Returns a new instance of Plotter


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

def initialize(adapter_name)
  @plotter_adapter =  PlotterAdapter.create(adapter_name)
end

Instance Attribute Details

#tableObject

Returns the value of attribute table


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

def table
  @table
end

Instance Method Details

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


110
111
112
113
# File 'lib/charty/plotter.rb', line 110

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

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


115
116
117
118
# File 'lib/charty/plotter.rb', line 115

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

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


120
121
122
123
# File 'lib/charty/plotter.rb', line 120

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

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


125
126
127
128
# File 'lib/charty/plotter.rb', line 125

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

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


130
131
132
133
# File 'lib/charty/plotter.rb', line 130

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

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


140
141
142
143
# File 'lib/charty/plotter.rb', line 140

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

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


145
146
147
148
# File 'lib/charty/plotter.rb', line 145

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

#layout(definition = :horizontal) ⇒ Object


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

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

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


135
136
137
138
# File 'lib/charty/plotter.rb', line 135

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

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


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

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

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


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

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

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


37
38
39
40
41
42
43
44
45
46
47
# File 'lib/charty/plotter.rb', line 37

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

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


49
50
51
52
53
54
55
56
57
58
59
# File 'lib/charty/plotter.rb', line 49

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

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


61
62
63
64
65
66
67
68
69
70
71
# File 'lib/charty/plotter.rb', line 61

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

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


85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/charty/plotter.rb', line 85

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

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


98
99
100
101
102
103
104
105
106
107
108
# File 'lib/charty/plotter.rb', line 98

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

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


73
74
75
76
77
78
79
80
81
82
83
# File 'lib/charty/plotter.rb', line 73

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