middleman-gnuplot 0.2.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d296d148bd098ee2ea558b7d38d9c42206e63ad989b4c62d9c97a726757e1ec9
4
- data.tar.gz: b9729966785e245cf29abc49f2bfe7cc09af349775417ae489c81276cf653b3e
3
+ metadata.gz: 76c651dec2492e3bb75494cb89e3e31478fd7676d3a56964afef202716e7e233
4
+ data.tar.gz: 77ff5468d77b178341d2981ffb1bc7fc810440423835173a8d6af5fa24d567b0
5
5
  SHA512:
6
- metadata.gz: b2505a038f28b98afa3d9fce1827e5f7e03242bf97e447f206e5217815db9eb2f2ab1f7f28d9f6870416bd0d40932292af179d828bb012d8d98fd0ea5efcc832
7
- data.tar.gz: 07dfffddc1fbfd0cb585d07013506857894e68734e5781c7b5dde29b28848f7c81e737b11cfa988306dd2db979273e30e0c1102811d2528703d769af3dc99036
6
+ metadata.gz: cba0f5baeb6e693bdda4d44cd3686a2e6cc79372cf4fc8e687cf86aa139f7d2acf1606b0c02cbe98cdc12a559c801276977c416acc99d04e274635e4e2ce7952
7
+ data.tar.gz: e135f54970b188f1c0b97bcafc90a8b03df34414042c65c78ab0a3731116a661f5f8352cd0fb89badb91f784329393cc707db3237db1711f5ce055519c79c497
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
- <Copyright (C) 2018 Hermann Detz>
1
+ <!--- Copyright (C) 2018 Hermann Detz --->
2
2
 
3
- <This software may be modified and distributed under the terms>
4
- <of the MIT license. See the LICENSE file for details.>
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
@@ -79,7 +79,8 @@ module Middleman
79
79
  # Generates a random filename, if the given paramter is nil or empty
80
80
  # Returns filename (given or random)
81
81
  # @param [String] filename input filename
82
- def random_filename_if_nil filename=nil
82
+ # @param [Int] length length of random filename
83
+ def random_filename_if_nil filename=nil, length=6
83
84
  # stub method to enable documentation in yard
84
85
  end
85
86
 
@@ -168,9 +169,9 @@ module Middleman
168
169
  gp_command << "\"-\" u #{ser[:x]}:#{ser[:y]}"
169
170
 
170
171
  if ser[:style].nil? == false
171
- gp_command << {w:ser[:style]}
172
+ gp_command << "w #{ser[:style]}"
172
173
  else
173
- gp_command << {w:'lines'}
174
+ gp_command << "w lines"
174
175
  end
175
176
 
176
177
  if ser[:color].nil? == false
@@ -178,9 +179,9 @@ module Middleman
178
179
  end
179
180
 
180
181
  if ser[:title].nil? == false
181
- gp_command << {t:"#{ser[:title]}"}
182
+ gp_command << "t \"#{ser[:title]}\""
182
183
  else
183
- gp_command << {t:''}
184
+ gp_command << "notitle"
184
185
  end
185
186
 
186
187
  gp_command << ", "
@@ -203,6 +204,8 @@ module Middleman
203
204
  gp_command << "e\n"
204
205
  end
205
206
 
207
+ gp_command = gp_command.join(" ")
208
+
206
209
  puts "GP cmd: #{gp_command}"
207
210
 
208
211
  @@gp.plot gp_command
@@ -217,14 +220,23 @@ module Middleman
217
220
 
218
221
  private
219
222
 
220
- # Generates a random filename, if the given paramter is nil or empty
223
+ # Generates a random filename, if the given paramter is nil or empty.
224
+ # The length of the random string can be overridden by setting
225
+ # app.config[:gp_rndfilelength] in config.rb of the middleman project.
226
+ #
221
227
  # Returns filename (given or random)
222
228
  # Params.
223
229
  # +filename+:: input filename
224
- def random_filename_if_nil filename=nil
230
+ # +length+:: length of random filename
231
+ def random_filename_if_nil filename=nil, length=6
225
232
  if filename.nil? or filename == ""
233
+
234
+ length = app.config[:gp_rndfilelength] unless app.config[:gp_rndfilelength].nil?
235
+
236
+ puts "Length of random filename: #{length}"
237
+
226
238
  loop do
227
- filename = ([*('A'..'Z'),*('0'..'9')]).sample(app.config[:gp_rndfilelength]).join
239
+ filename = ([*('A'..'Z'),*('0'..'9')]).sample(length).join
228
240
 
229
241
  break if @@plot_names.include?(filename) == false
230
242
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  module Middleman
7
7
  module Gnuplot
8
- VERSION = "0.2.0"
8
+ VERSION = "0.2.1"
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.2.0
4
+ version: 0.2.1
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-05-12 00:00:00.000000000 Z
11
+ date: 2018-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: numo-gnuplot