52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
# File 'lib/charty/backends/jfreechart.rb', line 52
def plot(plot, context, subplot: false)
case context.method
when :bar
dataset = DefaultCategoryDataset.new
context.series.each do |data|
data.ys.to_a.zip(Array.new(data.xs.size, data.label.to_s), data.xs.to_a.map(&:to_s)).each do |d|
dataset.addValue(*d)
end
end
title = context.title || ""
xlabel = context.xlabel || ""
ylabel = context.ylabel || ""
plot.createBarChart(
title,
xlabel,
ylabel,
dataset,
PlotOrientation::VERTICAL,
true,
false,
false
)
when :barh
dataset = DefaultCategoryDataset.new
context.series.each do |data|
data.ys.to_a.zip(Array.new(data.xs.size, data.label.to_s), data.xs.to_a.map(&:to_s)).each do |d|
dataset.addValue(*d)
end
end
title = context.title || ""
xlabel = context.xlabel || ""
ylabel = context.ylabel || ""
plot.createBarChart(
title,
xlabel,
ylabel,
dataset,
PlotOrientation::HORIZONTAL,
true,
false,
false
)
when :box_plot
raise NotImplementedError
when :bubble
dataset = MatrixSeriesCollection.new
context.series.each do |data|
series = MatrixSeries.new(data.label.to_s, 1000, 1000)
data.xs.to_a.zip(data.ys.to_a, data.zs.to_a).each do |series_param|
series.update(*series_param)
end
dataset.addSeries(series)
end
title = context.title || ""
xlabel = context.xlabel || ""
ylabel = context.ylabel || ""
plot.createBubbleChart(
title,
xlabel,
ylabel,
dataset,
PlotOrientation::VERTICAL,
true,
false,
false
)
when :curve
dataset = DefaultCategoryDataset.new
context.series.each do |data|
data.xs.to_a.zip(data.ys.to_a).each do |a|
dataset.addValue(a[1], data.label.to_s, a[0])
end
end
title = context.title || ""
xlabel = context.xlabel || ""
ylabel = context.ylabel || ""
plot.createLineChart(
title,
xlabel,
ylabel,
dataset,
PlotOrientation::VERTICAL,
true,
false,
false
)
when :scatter
dataset = XYSeriesCollection.new
context.series.each do |data|
series = XYSeries.new(data.label.to_s)
data.xs.to_a.zip(data.ys.to_a).each do |series_param|
series.add(*series_param)
end
dataset.addSeries(series)
end
title = context.title || ""
xlabel = context.xlabel || ""
ylabel = context.ylabel || ""
plot.createScatterPlot(
title,
xlabel,
ylabel,
dataset,
PlotOrientation::VERTICAL,
true,
false,
false
)
when :error_bar
raise NotImplementedError
when :hist
raise NotImplementedError
end
end
|