middleman-gnuplot 0.1.1 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 15fda679ea252f213b2952d616710ff9e8967f93
4
- data.tar.gz: bb5c0a442a12bda847cd88406b7ff5b65855a487
2
+ SHA256:
3
+ metadata.gz: d296d148bd098ee2ea558b7d38d9c42206e63ad989b4c62d9c97a726757e1ec9
4
+ data.tar.gz: b9729966785e245cf29abc49f2bfe7cc09af349775417ae489c81276cf653b3e
5
5
  SHA512:
6
- metadata.gz: fd2373b58e1837f009f77c8399eeaec32d85f7d7419f4e37ace228cdeab6c5531c0e082055a74c7993abcbfb0c0fcc6fe8500bf44291e2427bddbdd8f264e69c
7
- data.tar.gz: f725dd22211886fa0accd53bac00c9d5f8076167697e735e7ce4dd96f02a09a7b3cff10251f3415ba967f7dd9011bc622db2d879e9c305233d8abad20e0345d4
6
+ metadata.gz: b2505a038f28b98afa3d9fce1827e5f7e03242bf97e447f206e5217815db9eb2f2ab1f7f28d9f6870416bd0d40932292af179d828bb012d8d98fd0ea5efcc832
7
+ data.tar.gz: 07dfffddc1fbfd0cb585d07013506857894e68734e5781c7b5dde29b28848f7c81e737b11cfa988306dd2db979273e30e0c1102811d2528703d769af3dc99036
data/README.md CHANGED
@@ -21,7 +21,7 @@ Update your gem list:
21
21
 
22
22
  Modify the `config.rb` of your project as follows:
23
23
 
24
- activate :gnulot do |opts|
24
+ activate :gnuplot do |opts|
25
25
  opts.gp_tmpdir = 'tmp' # path, where plots are stored before copied to build dir
26
26
  opts.gp_outdir = 'img' # directory holding plot files with build dir
27
27
  opts.gp_format = 'png' # determines output format (currently supports png and pdf)
@@ -16,7 +16,7 @@ module Middleman
16
16
  @@plot_names = []
17
17
 
18
18
  # Initializes the middleman-gnuplot extension.
19
- def initialize(app, options_hash={}, &block)
19
+ def initialize app, options_hash={}, &block
20
20
  super
21
21
  app.config[:gp_outdir] = options.gp_outdir
22
22
  app.config[:gp_tmpdir] = options.gp_tmpdir
@@ -43,11 +43,11 @@ module Middleman
43
43
  # @param [Array<Hash>] functions function definition hash
44
44
  # @option functions [String] expression expression hat can be processed by gnuplot (e.g. sin(x))
45
45
  # @option functions [String] style _lines_ or _points_
46
- # @option functions [String] color RGB colro definition in hex format
46
+ # @option functions [String] color RGB color definition in hex format
47
47
  # @option functions [String] title name of trace
48
48
  # @param [String] filename base filename for output file
49
49
  # @param [String] title plot title
50
- def plot_functions (functions=[], filename=nil, title=nil)
50
+ def plot_functions functions=[], filename=nil, title=nil
51
51
  # stub method to enable documentation in yard
52
52
  end
53
53
 
@@ -56,20 +56,35 @@ module Middleman
56
56
  # @param [String] script path to the gnuplot script
57
57
  # @param [String] filename for output file (can be overridden in script)
58
58
  # @param [String] title plot title (can be overridden in script)
59
- def plot_script (script, filename=nil, title=nil)
59
+ def plot_script script, filename=nil, title=nil
60
60
  # stub method to enable documentation in yard
61
61
  end
62
62
 
63
+ # Generates a plot via gnuplot using the given data array
64
+ # The data array should be an array of rows that contains arrays of cols.
65
+ # e.g. [[x1, y1, z1], [x2, y2, z2], [x3, y3, z3]]
66
+ # @param [Array] data see format above
67
+ # @param [Array<Hash>] series function definition hash
68
+ # @option series [Int] x Index of x-column in array (1, 2, ...)
69
+ # @option series [Int] y Index of y-column in array (1, 2, ...)
70
+ # @option series [String] style _lines_ or _points_
71
+ # @option series [String] color RGB color definition in hex format
72
+ # @option series [String] title name of trace
73
+ # @param [String] filename base filename for output file
74
+ # @param [String] title plot title
75
+ def plot_data data, series=nil, filename=nil, title=nil
76
+ # stub method to enable documentation in yard
77
+ end
78
+
63
79
  # Generates a random filename, if the given paramter is nil or empty
64
80
  # Returns filename (given or random)
65
- # Params.
66
- # +filename+:: input filename
67
- def random_filename_if_nil (filename=nil)
81
+ # @param [String] filename input filename
82
+ def random_filename_if_nil filename=nil
68
83
  # stub method to enable documentation in yard
69
84
  end
70
85
 
71
86
  helpers do
72
- def plot_functions (functions=[], filename=nil, title=nil)
87
+ def plot_functions functions=[], filename=nil, title=nil
73
88
  filename = random_filename_if_nil(filename)
74
89
 
75
90
  if title.nil?
@@ -114,7 +129,7 @@ module Middleman
114
129
  return outfile
115
130
  end
116
131
 
117
- def plot_script (script, filename=nil, title=nil)
132
+ def plot_script script, filename=nil, title=nil
118
133
  filename = random_filename_if_nil(filename)
119
134
 
120
135
  outfile = "#{app.config[:gp_outdir]}/#{filename}.#{app.config[:gp_format]}"
@@ -134,6 +149,71 @@ module Middleman
134
149
  return outfile
135
150
  end
136
151
 
152
+ def plot_data data, series=nil, filename=nil, title=nil
153
+ unless series.nil?
154
+ filename = random_filename_if_nil(filename)
155
+
156
+ if title.nil?
157
+ title = ""
158
+ end
159
+
160
+ outfile = "#{app.config[:gp_outdir]}/#{filename}.#{app.config[:gp_format]}"
161
+
162
+ @@gp.set output:"./#{@@base_dir}/#{outfile}"
163
+ @@gp.set title:"#{title}"
164
+
165
+ gp_command = []
166
+
167
+ series.each do |ser|
168
+ gp_command << "\"-\" u #{ser[:x]}:#{ser[:y]}"
169
+
170
+ if ser[:style].nil? == false
171
+ gp_command << {w:ser[:style]}
172
+ else
173
+ gp_command << {w:'lines'}
174
+ end
175
+
176
+ if ser[:color].nil? == false
177
+ gp_command << {lc:"rgb '#{ser[:color]}'"}
178
+ end
179
+
180
+ if ser[:title].nil? == false
181
+ gp_command << {t:"#{ser[:title]}"}
182
+ else
183
+ gp_command << {t:''}
184
+ end
185
+
186
+ gp_command << ", "
187
+ end
188
+
189
+ gp_command[-1] = ''
190
+ gp_command << "\n"
191
+
192
+ (1..series.size).each do
193
+ data.each do |line|
194
+ tmpstring = ""
195
+
196
+ line.each do |col|
197
+ tmpstring << "#{col}\t"
198
+ end
199
+
200
+ gp_command << "#{tmpstring}\n"
201
+ end
202
+
203
+ gp_command << "e\n"
204
+ end
205
+
206
+ puts "GP cmd: #{gp_command}"
207
+
208
+ @@gp.plot gp_command
209
+
210
+
211
+ register_filename(filename)
212
+
213
+ return outfile
214
+ end
215
+ end
216
+
137
217
 
138
218
  private
139
219
 
@@ -141,7 +221,7 @@ module Middleman
141
221
  # Returns filename (given or random)
142
222
  # Params.
143
223
  # +filename+:: input filename
144
- def random_filename_if_nil (filename=nil)
224
+ def random_filename_if_nil filename=nil
145
225
  if filename.nil? or filename == ""
146
226
  loop do
147
227
  filename = ([*('A'..'Z'),*('0'..'9')]).sample(app.config[:gp_rndfilelength]).join
@@ -159,7 +239,7 @@ module Middleman
159
239
  # user adds the same filename twice - a warning is issued.
160
240
  # Params.
161
241
  # +filename+:: filename to be added to array
162
- def register_filename (filename)
242
+ def register_filename filename
163
243
  if @@plot_names.include?(filename)
164
244
  message "Warning: Filename #{filename} for plot already in use!", :warning
165
245
  end
@@ -171,7 +251,7 @@ module Middleman
171
251
  # Params.
172
252
  # +text+:: the message body to be printed
173
253
  # +type+:: :warning (yellow) or :error (red)
174
- def message (text, type=:warning)
254
+ def message text, type=:warning
175
255
  colString = ''
176
256
  colReset = "\033[0m"
177
257
  offset = "\033[14C"
@@ -5,7 +5,7 @@
5
5
 
6
6
  module Middleman
7
7
  module Gnuplot
8
- VERSION = "0.1.1"
8
+ VERSION = "0.2.0"
9
9
  end
10
10
  end
11
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-gnuplot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hermann Detz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-05 00:00:00.000000000 Z
11
+ date: 2018-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: numo-gnuplot
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  version: '0'
80
80
  requirements: []
81
81
  rubyforge_project:
82
- rubygems_version: 2.6.10
82
+ rubygems_version: 2.7.6
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: Middleman extension for gnuplot