middleman-gnuplot 0.2.0 → 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/README.md +29 -3
- data/lib/middleman-gnuplot/extension.rb +249 -46
- 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
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
|
1
|
+
<!--- Copyright (C) 2018 Hermann Detz --->
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
<!--- This software may be modified and distributed under the terms
|
4
|
+
of the MIT license. See the LICENSE file for details. --->
|
5
5
|
|
6
6
|
# middleman-gnuplot
|
7
7
|
|
@@ -26,6 +26,13 @@ Modify the `config.rb` of your project as follows:
|
|
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)
|
28
28
|
end
|
29
|
+
|
30
|
+
If not specified, the plots will be generated with random filenames,
|
31
|
+
which are 6 characters long. This setting can be overridden in `config.rb`
|
32
|
+
to e.g. 8 using the following line:
|
33
|
+
|
34
|
+
set :gp_rndfilelength, 8
|
35
|
+
|
29
36
|
## Usage
|
30
37
|
|
31
38
|
All functions return the output filename of the plot, which can be used
|
@@ -60,6 +67,25 @@ The middleman-gnuplot extension provides the following helper methods:
|
|
60
67
|
image_tag plot_script("path_to_gnuplot_script", "filename", "Plot Title")
|
61
68
|
```
|
62
69
|
|
70
|
+
* `plot_data(data, series, filename, title)`: Plots data points from a given array
|
71
|
+
`data` directly. The data series can be specified as hashes within the array
|
72
|
+
`series`. Allowed fields are `:x`, `:y`, `:title` and `:style` (lines, points,
|
73
|
+
linespoints, ...). The default style is lines. `filename` defines the output
|
74
|
+
filename. If nil, a random filename is generated and returned by the function.
|
75
|
+
The `title` parameter can be used to define a plot title.
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
image_tag plot_data([[1,2,1],[2,5,3],[3,3,1],[4,1,5]],
|
79
|
+
[{:x => 1,
|
80
|
+
:y => 2,
|
81
|
+
:title => "Series 1"},
|
82
|
+
{:x => 1,
|
83
|
+
:y => 3,
|
84
|
+
:title => "Series 2",
|
85
|
+
:style => "points"}],
|
86
|
+
"filename", "Plot Title"
|
87
|
+
```
|
88
|
+
|
63
89
|
## Note
|
64
90
|
|
65
91
|
The build summary of middleman lists plot files that were generated in
|
@@ -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))
|
@@ -79,12 +83,15 @@ module Middleman
|
|
79
83
|
# Generates a random filename, if the given paramter is nil or empty
|
80
84
|
# Returns filename (given or random)
|
81
85
|
# @param [String] filename input filename
|
82
|
-
|
86
|
+
# @param [Int] length length of random filename
|
87
|
+
def random_filename_if_nil filename=nil, length=6
|
83
88
|
# stub method to enable documentation in yard
|
84
89
|
end
|
85
90
|
|
86
91
|
helpers do
|
87
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
|
+
|
88
95
|
filename = random_filename_if_nil(filename)
|
89
96
|
|
90
97
|
if title.nil?
|
@@ -129,6 +136,76 @@ module Middleman
|
|
129
136
|
return outfile
|
130
137
|
end
|
131
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
|
+
|
132
209
|
def plot_script script, filename=nil, title=nil
|
133
210
|
filename = random_filename_if_nil(filename)
|
134
211
|
|
@@ -149,85 +226,99 @@ module Middleman
|
|
149
226
|
return outfile
|
150
227
|
end
|
151
228
|
|
152
|
-
|
153
|
-
|
154
|
-
|
229
|
+
def plot_data data, series=nil, filename=nil, title=nil
|
230
|
+
unless series.nil?
|
231
|
+
filename = random_filename_if_nil(filename)
|
155
232
|
|
156
|
-
|
157
|
-
|
158
|
-
|
233
|
+
if title.nil?
|
234
|
+
title = ""
|
235
|
+
end
|
159
236
|
|
160
|
-
|
237
|
+
outfile = "#{app.config[:gp_outdir]}/#{filename}.#{app.config[:gp_format]}"
|
161
238
|
|
162
|
-
|
163
|
-
|
239
|
+
@@gp.set output:"./#{@@base_dir}/#{outfile}"
|
240
|
+
@@gp.set title:"#{title}"
|
164
241
|
|
165
|
-
|
242
|
+
gp_command = []
|
166
243
|
|
167
|
-
|
168
|
-
|
244
|
+
series.each do |ser|
|
245
|
+
gp_command << "\"-\" u #{ser[:x]}:#{ser[:y]}"
|
169
246
|
|
170
247
|
if ser[:style].nil? == false
|
171
|
-
gp_command << {
|
248
|
+
gp_command << "w #{ser[:style]}"
|
172
249
|
else
|
173
|
-
gp_command <<
|
250
|
+
gp_command << "w lines"
|
174
251
|
end
|
175
252
|
|
176
253
|
if ser[:color].nil? == false
|
177
|
-
|
254
|
+
gp_command << {lc:"rgb '#{ser[:color]}'"}
|
178
255
|
end
|
179
256
|
|
180
257
|
if ser[:title].nil? == false
|
181
|
-
|
258
|
+
gp_command << "t \"#{ser[:title]}\""
|
182
259
|
else
|
183
|
-
|
260
|
+
gp_command << "notitle"
|
184
261
|
end
|
185
262
|
|
263
|
+
if ser[:width].nil? == false
|
264
|
+
gp_command << "lw #{ser[:width]}"
|
265
|
+
end
|
266
|
+
|
186
267
|
gp_command << ", "
|
187
|
-
|
268
|
+
end
|
188
269
|
|
189
|
-
|
190
|
-
|
270
|
+
gp_command[-1] = ''
|
271
|
+
gp_command << "\n"
|
191
272
|
|
192
|
-
|
193
|
-
|
194
|
-
|
273
|
+
(1..series.size).each do
|
274
|
+
data.each do |line|
|
275
|
+
tmpstring = ""
|
195
276
|
|
196
|
-
|
197
|
-
|
198
|
-
|
277
|
+
line.each do |col|
|
278
|
+
tmpstring << "#{col}\t"
|
279
|
+
end
|
199
280
|
|
200
|
-
|
201
|
-
|
281
|
+
gp_command << "#{tmpstring}\n"
|
282
|
+
end
|
202
283
|
|
203
|
-
|
204
|
-
|
284
|
+
gp_command << "e\n"
|
285
|
+
end
|
205
286
|
|
206
|
-
|
287
|
+
gp_command = gp_command.join(" ")
|
207
288
|
|
208
|
-
|
289
|
+
puts "GP cmd: #{gp_command}"
|
209
290
|
|
291
|
+
@@gp.plot gp_command
|
210
292
|
|
211
|
-
register_filename(filename)
|
212
293
|
|
213
|
-
|
214
|
-
|
215
|
-
|
294
|
+
register_filename(filename)
|
295
|
+
|
296
|
+
return outfile
|
297
|
+
end
|
298
|
+
end
|
216
299
|
|
217
300
|
|
218
301
|
private
|
219
302
|
|
220
|
-
# Generates a random filename, if the given paramter is nil or empty
|
303
|
+
# Generates a random filename, if the given paramter is nil or empty.
|
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
|
+
#
|
221
307
|
# Returns filename (given or random)
|
222
308
|
# Params.
|
223
309
|
# +filename+:: input filename
|
224
|
-
|
310
|
+
# +length+:: length of random filename
|
311
|
+
def random_filename_if_nil filename=nil, length=6
|
225
312
|
if filename.nil? or filename == ""
|
226
|
-
|
227
|
-
filename = ([*('A'..'Z'),*('0'..'9')]).sample(app.config[:gp_rndfilelength]).join
|
313
|
+
length = app.config[:gp_rndfilelength] unless app.config[:gp_rndfilelength].nil?
|
228
314
|
|
229
|
-
|
230
|
-
|
315
|
+
puts "Length of random filename: #{length}"
|
316
|
+
|
317
|
+
loop do
|
318
|
+
filename = ([*('A'..'Z'),*('0'..'9')]).sample(length).join
|
319
|
+
|
320
|
+
break if @@plot_names.include?(filename) == false
|
321
|
+
end
|
231
322
|
end
|
232
323
|
|
233
324
|
return filename
|
@@ -241,7 +332,7 @@ module Middleman
|
|
241
332
|
# +filename+:: filename to be added to array
|
242
333
|
def register_filename filename
|
243
334
|
if @@plot_names.include?(filename)
|
244
|
-
|
335
|
+
message "Warning: Filename #{filename} for plot already in use!", :warning
|
245
336
|
end
|
246
337
|
|
247
338
|
@@plot_names.append(filename)
|
@@ -258,15 +349,127 @@ module Middleman
|
|
258
349
|
|
259
350
|
case type
|
260
351
|
when :warning
|
261
|
-
|
352
|
+
colString = "\033[1;33m"
|
262
353
|
when :error
|
263
|
-
|
354
|
+
colString = "\033[1;31m"
|
264
355
|
end
|
265
356
|
|
266
357
|
message = "#{colString}#{offset}middleman-gnuplot: #{text}#{colReset}"
|
267
358
|
|
268
359
|
puts message
|
269
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
|
270
473
|
end
|
271
474
|
end
|
272
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: []
|