middleman-gnuplot 0.2.1 → 0.2.2
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 +4 -4
- data/lib/middleman-gnuplot/extension.rb +240 -49
- data/lib/middleman-gnuplot/gp_helpers.rb +2 -0
- data/lib/middleman-gnuplot/version.rb +1 -1
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c17a392a4f1cc289766f0b40a56555db9f5db6da02f1a14a32cbf9034c28a47
|
4
|
+
data.tar.gz: 9ed89c1e1414bbf4a65b22b4c5cc85fcc44464dd964cada51ab9c882b7848eb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f4532fd93a3c31c0173726e2dc38c0cb1eeece4d32671768916ed696841857e78e36fe473a9a69a8e123d12d13b41cd395f0b4ba484f7c1f5606b58ec2e1130
|
7
|
+
data.tar.gz: 03f440a898cb902302433edfa303736cc38769eece7d228cc159ae3494b3757989cccaddc9e198a1e3efc52124dff7c0b707ea9af97788ac31eeafd51b98e088
|
@@ -3,6 +3,7 @@ require "middleman-gnuplot/gp_helpers"
|
|
3
3
|
require "middleman-core"
|
4
4
|
require "numo/gnuplot"
|
5
5
|
require "fileutils"
|
6
|
+
require "time"
|
6
7
|
|
7
8
|
module Middleman
|
8
9
|
class GnuplotExtension < Middleman::Extension
|
@@ -39,6 +40,9 @@ module Middleman
|
|
39
40
|
end
|
40
41
|
|
41
42
|
# Generates a plot via gnuplot using a given expression.
|
43
|
+
#
|
44
|
+
# @deprecated Will be deprecated in the next version in favor of {#plot}.
|
45
|
+
#
|
42
46
|
# The function must be provided as hash using the following fields:
|
43
47
|
# @param [Array<Hash>] functions function definition hash
|
44
48
|
# @option functions [String] expression expression hat can be processed by gnuplot (e.g. sin(x))
|
@@ -86,6 +90,8 @@ module Middleman
|
|
86
90
|
|
87
91
|
helpers do
|
88
92
|
def plot_functions functions=[], filename=nil, title=nil
|
93
|
+
warn "plot_functions will be deprecated in the next version in favor of the new function plot"
|
94
|
+
|
89
95
|
filename = random_filename_if_nil(filename)
|
90
96
|
|
91
97
|
if title.nil?
|
@@ -130,6 +136,76 @@ module Middleman
|
|
130
136
|
return outfile
|
131
137
|
end
|
132
138
|
|
139
|
+
def plot functions=[], filename=nil, title=nil, options={}
|
140
|
+
filename = random_filename_if_nil(filename)
|
141
|
+
|
142
|
+
if title.nil?
|
143
|
+
title = ""
|
144
|
+
end
|
145
|
+
|
146
|
+
outfile = "#{app.config[:gp_outdir]}/#{filename}.#{app.config[:gp_format]}"
|
147
|
+
|
148
|
+
@@gp.set output:"./#{@@base_dir}/#{outfile}"
|
149
|
+
@@gp.set title:"#{title}"
|
150
|
+
|
151
|
+
if options.nil? == false
|
152
|
+
process_options options
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
gp_command = []
|
157
|
+
|
158
|
+
functions.each_with_index do |function,i|
|
159
|
+
if function[:expression].nil? == false
|
160
|
+
gp_command << function[:expression]
|
161
|
+
else
|
162
|
+
if function[:file].nil? == false and
|
163
|
+
function[:colx].nil? == false and
|
164
|
+
function[:coly].nil? == false
|
165
|
+
gp_command << "'#{function[:file]}' using #{function[:colx]}:#{function[:coly]} "
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
if function[:style].nil? == false
|
170
|
+
gp_command << {w:function[:style]}
|
171
|
+
else
|
172
|
+
gp_command << {w:'lines'}
|
173
|
+
end
|
174
|
+
|
175
|
+
if function[:dashtype].nil? == false
|
176
|
+
gp_command << "dt #{function[:dashtype]}"
|
177
|
+
end
|
178
|
+
|
179
|
+
if function[:width].nil? == false
|
180
|
+
gp_command << "lw #{function[:width]}"
|
181
|
+
end
|
182
|
+
|
183
|
+
if function[:color].nil? == false
|
184
|
+
gp_command << {lc:"rgb '#{function[:color]}'"}
|
185
|
+
end
|
186
|
+
|
187
|
+
if function[:title].nil? == false
|
188
|
+
gp_command << {t:"#{function[:title]}"}
|
189
|
+
else
|
190
|
+
gp_command << {t:''}
|
191
|
+
end
|
192
|
+
|
193
|
+
if function[:ymin].nil? == false
|
194
|
+
gp_command << "y1=#{function[:ymin]}"
|
195
|
+
end
|
196
|
+
|
197
|
+
gp_command << ", "
|
198
|
+
end
|
199
|
+
|
200
|
+
gp_command[-1] = ''
|
201
|
+
|
202
|
+
@@gp.plot gp_command
|
203
|
+
|
204
|
+
register_filename(filename)
|
205
|
+
|
206
|
+
return outfile
|
207
|
+
end
|
208
|
+
|
133
209
|
def plot_script script, filename=nil, title=nil
|
134
210
|
filename = random_filename_if_nil(filename)
|
135
211
|
|
@@ -150,23 +226,23 @@ module Middleman
|
|
150
226
|
return outfile
|
151
227
|
end
|
152
228
|
|
153
|
-
|
154
|
-
|
155
|
-
|
229
|
+
def plot_data data, series=nil, filename=nil, title=nil
|
230
|
+
unless series.nil?
|
231
|
+
filename = random_filename_if_nil(filename)
|
156
232
|
|
157
|
-
|
158
|
-
|
159
|
-
|
233
|
+
if title.nil?
|
234
|
+
title = ""
|
235
|
+
end
|
160
236
|
|
161
|
-
|
237
|
+
outfile = "#{app.config[:gp_outdir]}/#{filename}.#{app.config[:gp_format]}"
|
162
238
|
|
163
|
-
|
164
|
-
|
239
|
+
@@gp.set output:"./#{@@base_dir}/#{outfile}"
|
240
|
+
@@gp.set title:"#{title}"
|
165
241
|
|
166
|
-
|
242
|
+
gp_command = []
|
167
243
|
|
168
|
-
|
169
|
-
|
244
|
+
series.each do |ser|
|
245
|
+
gp_command << "\"-\" u #{ser[:x]}:#{ser[:y]}"
|
170
246
|
|
171
247
|
if ser[:style].nil? == false
|
172
248
|
gp_command << "w #{ser[:style]}"
|
@@ -175,71 +251,74 @@ module Middleman
|
|
175
251
|
end
|
176
252
|
|
177
253
|
if ser[:color].nil? == false
|
178
|
-
|
254
|
+
gp_command << {lc:"rgb '#{ser[:color]}'"}
|
179
255
|
end
|
180
256
|
|
181
257
|
if ser[:title].nil? == false
|
182
|
-
|
258
|
+
gp_command << "t \"#{ser[:title]}\""
|
183
259
|
else
|
184
|
-
|
260
|
+
gp_command << "notitle"
|
185
261
|
end
|
186
262
|
|
263
|
+
if ser[:width].nil? == false
|
264
|
+
gp_command << "lw #{ser[:width]}"
|
265
|
+
end
|
266
|
+
|
187
267
|
gp_command << ", "
|
188
|
-
|
268
|
+
end
|
189
269
|
|
190
|
-
|
191
|
-
|
270
|
+
gp_command[-1] = ''
|
271
|
+
gp_command << "\n"
|
192
272
|
|
193
|
-
|
194
|
-
|
195
|
-
|
273
|
+
(1..series.size).each do
|
274
|
+
data.each do |line|
|
275
|
+
tmpstring = ""
|
196
276
|
|
197
|
-
|
198
|
-
|
199
|
-
|
277
|
+
line.each do |col|
|
278
|
+
tmpstring << "#{col}\t"
|
279
|
+
end
|
200
280
|
|
201
|
-
|
202
|
-
|
281
|
+
gp_command << "#{tmpstring}\n"
|
282
|
+
end
|
203
283
|
|
204
|
-
|
205
|
-
|
284
|
+
gp_command << "e\n"
|
285
|
+
end
|
206
286
|
|
207
|
-
|
287
|
+
gp_command = gp_command.join(" ")
|
208
288
|
|
209
|
-
|
289
|
+
puts "GP cmd: #{gp_command}"
|
210
290
|
|
211
|
-
|
291
|
+
@@gp.plot gp_command
|
212
292
|
|
213
293
|
|
214
|
-
|
294
|
+
register_filename(filename)
|
215
295
|
|
216
|
-
|
217
|
-
|
218
|
-
|
296
|
+
return outfile
|
297
|
+
end
|
298
|
+
end
|
219
299
|
|
220
300
|
|
221
301
|
private
|
222
302
|
|
223
303
|
# Generates a random filename, if the given paramter is nil or empty.
|
224
|
-
|
225
|
-
|
226
|
-
|
304
|
+
# The length of the random string can be overridden by setting
|
305
|
+
# app.config[:gp_rndfilelength] in config.rb of the middleman project.
|
306
|
+
#
|
227
307
|
# Returns filename (given or random)
|
228
308
|
# Params.
|
229
309
|
# +filename+:: input filename
|
230
|
-
|
310
|
+
# +length+:: length of random filename
|
231
311
|
def random_filename_if_nil filename=nil, length=6
|
232
312
|
if filename.nil? or filename == ""
|
313
|
+
length = app.config[:gp_rndfilelength] unless app.config[:gp_rndfilelength].nil?
|
233
314
|
|
234
|
-
|
235
|
-
|
236
|
-
puts "Length of random filename: #{length}"
|
315
|
+
puts "Length of random filename: #{length}"
|
237
316
|
|
238
|
-
|
239
|
-
|
317
|
+
loop do
|
318
|
+
filename = ([*('A'..'Z'),*('0'..'9')]).sample(length).join
|
240
319
|
|
241
|
-
|
242
|
-
|
320
|
+
break if @@plot_names.include?(filename) == false
|
321
|
+
end
|
243
322
|
end
|
244
323
|
|
245
324
|
return filename
|
@@ -253,7 +332,7 @@ module Middleman
|
|
253
332
|
# +filename+:: filename to be added to array
|
254
333
|
def register_filename filename
|
255
334
|
if @@plot_names.include?(filename)
|
256
|
-
|
335
|
+
message "Warning: Filename #{filename} for plot already in use!", :warning
|
257
336
|
end
|
258
337
|
|
259
338
|
@@plot_names.append(filename)
|
@@ -270,15 +349,127 @@ module Middleman
|
|
270
349
|
|
271
350
|
case type
|
272
351
|
when :warning
|
273
|
-
|
352
|
+
colString = "\033[1;33m"
|
274
353
|
when :error
|
275
|
-
|
354
|
+
colString = "\033[1;31m"
|
276
355
|
end
|
277
356
|
|
278
357
|
message = "#{colString}#{offset}middleman-gnuplot: #{text}#{colReset}"
|
279
358
|
|
280
359
|
puts message
|
281
360
|
end
|
361
|
+
|
362
|
+
# Processes a set of options that should be passed to gnuplot.
|
363
|
+
# Params.
|
364
|
+
# @param [array of hashes] an array of hashes that contain the options
|
365
|
+
# @option :datafilesep data file separator (e.g. '\t' or ' ')
|
366
|
+
# @option :timefmt a string indicating the time format that should be used
|
367
|
+
# @option :xtype only required if it should be set to :date
|
368
|
+
# @option :ytype only required if it should be set to :date
|
369
|
+
# @option :xrange a string indicating the x-axis range
|
370
|
+
# @option :yrange a string indicating the y-axis range
|
371
|
+
# @option :xformat a string indicating the x-axis format
|
372
|
+
# @option :yformat a string indicating the y-axis format
|
373
|
+
# @option :key a string to place or modify the key
|
374
|
+
def process_options options={}
|
375
|
+
if options[:term].nil? == false
|
376
|
+
@@gp.set term:"#{options[:term]}"
|
377
|
+
end
|
378
|
+
|
379
|
+
if options[:datafilesep].nil? == false
|
380
|
+
@@gp.set "datafile separator '#{options[:datafilesep]}'"
|
381
|
+
end
|
382
|
+
|
383
|
+
if ((options[:xtype].nil? == false and options[:xtype] == :date) or
|
384
|
+
(options[:ytype].nil? == false and options[:ytype] == :date)) and
|
385
|
+
(options[:timefmt].nil? == false)
|
386
|
+
if options[:xtype] == :date
|
387
|
+
@@gp.set "xdata time"
|
388
|
+
end
|
389
|
+
|
390
|
+
if options[:ytype] == :date
|
391
|
+
@@gp.set "ydata time"
|
392
|
+
end
|
393
|
+
|
394
|
+
@@gp.set "timefmt '#{options[:timefmt]}'"
|
395
|
+
end
|
396
|
+
|
397
|
+
if options[:xrange].nil? == false
|
398
|
+
if options[:xtype].nil? == false and options[:xtype] == :date
|
399
|
+
@@gp.set "xrange ['#{Time.at(options[:xrange].begin).strftime("%Y-%m-%d %H:%M:%S")}':'#{Time.at(options[:xrange].end).strftime("%Y-%m-%d %H:%M:%S")}']"
|
400
|
+
else
|
401
|
+
@@gp.set "xrange [#{options[:xrange].begin}:#{options[:xrange].end}]"
|
402
|
+
end
|
403
|
+
else
|
404
|
+
@@gp.unset "xrange"
|
405
|
+
end
|
406
|
+
|
407
|
+
if options[:yrange].nil? == false
|
408
|
+
if options[:ytype].nil? == false and options[:ytype] == :date
|
409
|
+
@@gp.set "yrange ['#{Time.at(options[:yrange].begin).strftime("%Y-%m-%d %H:%M:%S")}':'#{Time.at(options[:yrange].end).strftime("%Y-%m-%d %H:%M:%S")}']"
|
410
|
+
else
|
411
|
+
@@gp.set "yrange [#{options[:yrange].begin}:#{options[:yrange].end}]"
|
412
|
+
end
|
413
|
+
else
|
414
|
+
@@gp.unset "yrange"
|
415
|
+
end
|
416
|
+
|
417
|
+
if options[:xtics].nil? == false
|
418
|
+
@@gp.set "xtics #{options[:xtics]}"
|
419
|
+
end
|
420
|
+
|
421
|
+
if options[:ytics].nil? == false
|
422
|
+
@@gp.set "ytics #{options[:ytics]}"
|
423
|
+
end
|
424
|
+
|
425
|
+
if options[:mxtics].nil? == false
|
426
|
+
@@gp.set "mxtics #{options[:mxtics]}"
|
427
|
+
end
|
428
|
+
|
429
|
+
if options[:mytics].nil? == false
|
430
|
+
@@gp.set "mytics #{options[:mytics]}"
|
431
|
+
end
|
432
|
+
|
433
|
+
if options[:logx].nil? == false and options[:logx] == true
|
434
|
+
@@gp.set "log x"
|
435
|
+
else
|
436
|
+
@@gp.unset "log x"
|
437
|
+
end
|
438
|
+
|
439
|
+
if options[:logy].nil? == false and options[:logy] == true
|
440
|
+
@@gp.set "log y"
|
441
|
+
else
|
442
|
+
@@gp.unset "log y"
|
443
|
+
end
|
444
|
+
|
445
|
+
if options[:xformat].nil? == false
|
446
|
+
@@gp.set "format x '#{options[:xformat]}'"
|
447
|
+
end
|
448
|
+
|
449
|
+
if options[:yformat].nil? == false
|
450
|
+
@@gp.set "format y '#{options[:yformat]}'"
|
451
|
+
end
|
452
|
+
|
453
|
+
if options[:xlabel].nil? == false
|
454
|
+
@@gp.set "xlabel '#{options[:xlabel]}'"
|
455
|
+
else
|
456
|
+
@@gp.unset "xlabel"
|
457
|
+
end
|
458
|
+
|
459
|
+
if options[:ylabel].nil? == false
|
460
|
+
@@gp.set "ylabel '#{options[:ylabel]}'"
|
461
|
+
else
|
462
|
+
@@gp.unset "ylabel"
|
463
|
+
end
|
464
|
+
|
465
|
+
if options[:key].nil? == false
|
466
|
+
@@gp.set "key #{options[:key]}"
|
467
|
+
end
|
468
|
+
|
469
|
+
if options[:grid].nil? == false
|
470
|
+
@@gp.set "grid #{options[:grid]}"
|
471
|
+
end
|
472
|
+
end
|
282
473
|
end
|
283
474
|
end
|
284
475
|
end
|
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.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hermann Detz
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: numo-gnuplot
|
@@ -63,7 +63,7 @@ homepage: https://github.com/hermanndetz/middleman-gnuplot
|
|
63
63
|
licenses:
|
64
64
|
- MIT
|
65
65
|
metadata: {}
|
66
|
-
post_install_message:
|
66
|
+
post_install_message:
|
67
67
|
rdoc_options: []
|
68
68
|
require_paths:
|
69
69
|
- lib
|
@@ -78,9 +78,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
78
|
- !ruby/object:Gem::Version
|
79
79
|
version: '0'
|
80
80
|
requirements: []
|
81
|
-
|
82
|
-
|
83
|
-
signing_key:
|
81
|
+
rubygems_version: 3.4.1
|
82
|
+
signing_key:
|
84
83
|
specification_version: 4
|
85
84
|
summary: Middleman extension for gnuplot
|
86
85
|
test_files: []
|