grada 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/grada/gnuplot.rb +40 -37
- data/lib/grada.rb +12 -2
- metadata +1 -1
data/lib/grada/gnuplot.rb
CHANGED
@@ -49,7 +49,7 @@ class Gnuplot
|
|
49
49
|
end
|
50
50
|
|
51
51
|
class Plot
|
52
|
-
attr_accessor :cmd, :data, :settings, :arbitrary_lines
|
52
|
+
attr_accessor :cmd, :data, :settings, :styles, :arbitrary_lines
|
53
53
|
|
54
54
|
QUOTED_METHODS = [ "title", "output", "xlabel", "x2label", "ylabel", "y2label", "clabel", "cblabel", "zlabel" ]
|
55
55
|
|
@@ -96,49 +96,52 @@ class Plot
|
|
96
96
|
|
97
97
|
io
|
98
98
|
end
|
99
|
+
end
|
99
100
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
101
|
+
class Style
|
102
|
+
attr_accessor :linestyle, :linetype, :linewidth, :linecolor, :pointtype, :pointsize, :fill, :index
|
103
|
+
|
104
|
+
alias :ls :linestyle
|
105
|
+
alias :lt :linetype
|
106
|
+
alias :lw :linewidth
|
107
|
+
alias :lc :linecolor
|
108
|
+
alias :pt :pointtype
|
109
|
+
alias :ps :pointsize
|
110
|
+
alias :fs :fill
|
111
|
+
|
112
|
+
alias :ls= :linestyle=
|
113
|
+
alias :lt= :linetype=
|
114
|
+
alias :lw= :linewidth=
|
115
|
+
alias :lc= :linecolor=
|
116
|
+
alias :pt= :pointtype=
|
117
|
+
alias :ps= :pointsize=
|
118
|
+
alias :fs= :fill=
|
119
|
+
|
120
|
+
STYLES = [:ls, :lt, :lw, :lc, :pt, :ps, :fs]
|
114
121
|
|
115
|
-
|
122
|
+
def self.increment_index
|
123
|
+
@index ||= 0
|
124
|
+
@index += 1
|
125
|
+
end
|
116
126
|
|
117
|
-
|
118
|
-
|
119
|
-
|
127
|
+
def initialize
|
128
|
+
STYLES.each do |style|
|
129
|
+
send("#{style}=", nil)
|
120
130
|
end
|
121
131
|
|
122
|
-
|
123
|
-
STYLES.each do |style|
|
124
|
-
send("#{style}=", nil)
|
125
|
-
end
|
132
|
+
yield self if block_given?
|
126
133
|
|
127
|
-
|
134
|
+
end
|
128
135
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
def to_s
|
133
|
-
str = "set style line #{@index}"
|
134
|
-
|
135
|
-
STYLES.each do |style|
|
136
|
-
str += " #{send(style)} #{style}" if send(style)
|
137
|
-
end
|
136
|
+
def to_s
|
137
|
+
str = ' '
|
138
138
|
|
139
|
-
|
139
|
+
STYLES.each do |style|
|
140
|
+
str += " #{style} #{send(style)}" if send(style)
|
140
141
|
end
|
141
|
-
|
142
|
+
|
143
|
+
str == ' ' ? '' : str
|
144
|
+
end
|
142
145
|
end
|
143
146
|
|
144
147
|
class DataSet
|
@@ -168,7 +171,7 @@ class DataSet
|
|
168
171
|
|
169
172
|
def plot_args(io = '')
|
170
173
|
io += @data.is_a?(String) ? @data : "'-'"
|
171
|
-
io += " index #{@index}" if @index
|
174
|
+
#io += " index #{@index}" if @index
|
172
175
|
io += " using #{@using}" if @using
|
173
176
|
io += " axes #{@axes}" if @axes
|
174
177
|
io += " title #{@title ? "\"#{@title}\"" : notitle}"
|
@@ -176,7 +179,7 @@ class DataSet
|
|
176
179
|
io += " smooth #{@smooth}" if @smooth
|
177
180
|
io += " with #{@with}" if @with
|
178
181
|
io += " linecolor #{@linecolor}" if @linecolor
|
179
|
-
io += " linewidth #{@linewidth}" if @linewidth
|
182
|
+
io += " line #{@index} linewidth #{@linewidth}" if @linewidth
|
180
183
|
io += " linestyle #{@linestyle.index}" if @linestyle
|
181
184
|
|
182
185
|
io
|
data/lib/grada.rb
CHANGED
@@ -23,6 +23,8 @@ class Grada
|
|
23
23
|
y_label: "Y",
|
24
24
|
with: 'lines',
|
25
25
|
graph_type: :default}
|
26
|
+
|
27
|
+
STYLES = [:linestyle, :linetype, :linewidth, :linecolor, :pointtype, :pointsize, :fill]
|
26
28
|
|
27
29
|
# Hello GraDA
|
28
30
|
#
|
@@ -174,13 +176,21 @@ class Grada
|
|
174
176
|
plot.ylabel @opts[:y_label]
|
175
177
|
|
176
178
|
if multiple_data?(@y)
|
177
|
-
@y.
|
179
|
+
@y.each_with_index do |dic, index|
|
178
180
|
dic.each do |k, v|
|
179
|
-
if k.to_sym != :with
|
181
|
+
if ! STYLES.include?(k.to_sym) && k.to_sym != :with
|
180
182
|
raise NoPlotDataError if ! v.nil? && @x.size != v.size
|
181
183
|
|
184
|
+
style = Gnuplot::Style.new do |ds|
|
185
|
+
ds.index = index
|
186
|
+
STYLES.each do |style|
|
187
|
+
ds.send("#{style}=", dic[style]) if dic[style]
|
188
|
+
end
|
189
|
+
end.to_s
|
190
|
+
|
182
191
|
plot.data << Gnuplot::DataSet.new([@x,v]) do |ds|
|
183
192
|
ds.with = dic[:with] || @opts[:with]
|
193
|
+
ds.with += style
|
184
194
|
ds.title = "#{k}"
|
185
195
|
end
|
186
196
|
end
|