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.
Files changed (3) hide show
  1. data/lib/grada/gnuplot.rb +40 -37
  2. data/lib/grada.rb +12 -2
  3. 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
- def style(&blk)
101
- @styles << Style.new(&blk)
102
- end
103
-
104
- class Style
105
- attr_accessor :linestyle, :linetype, :linewidth, :linecolor, :pointtype, :pointsize, :fill, :index
106
-
107
- alias :ls :linestyle
108
- alias :lt :linetype
109
- alias :lw :linewidth
110
- alias :lc :linecolor
111
- alias :pt :pointtype
112
- alias :ps :pointsize
113
- alias :fs :fill
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
- STYLES = [:ls, :lt, :lw, :lc, :pt, :ps, :fs]
122
+ def self.increment_index
123
+ @index ||= 0
124
+ @index += 1
125
+ end
116
126
 
117
- def self.increment_index
118
- @index ||= 0
119
- @index += 1
127
+ def initialize
128
+ STYLES.each do |style|
129
+ send("#{style}=", nil)
120
130
  end
121
131
 
122
- def initialize
123
- STYLES.each do |style|
124
- send("#{style}=", nil)
125
- end
132
+ yield self if block_given?
126
133
 
127
- yield self if block_given?
134
+ end
128
135
 
129
- self.increment_index
130
- end
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
- str
139
+ STYLES.each do |style|
140
+ str += " #{style} #{send(style)}" if send(style)
140
141
  end
141
- end
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.each do |dic|
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grada
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: