gnutemplate 0.1.8.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '08348dfcbd8aa2c5f4d3204ba6d1cbb7215e69c5c36d3c7ed125f2947cc7b0a5'
4
- data.tar.gz: a0b2af796fd95613d344446517178c53c5ba2ca11b4b32b08ff2b836fdde7542
3
+ metadata.gz: 5faac0acbe5d64d0e9cf6aec58ffed06004f62e0c372ef4a551881de916e2c64
4
+ data.tar.gz: b2676c4052f26536e59c5e34379e67fb7f7013f3ca40479088342aa0ae71e7c6
5
5
  SHA512:
6
- metadata.gz: f5753ee46b8a405aa613df70a6f8dd771b84646da13a242cd0e77d5bbcbdbb046cf09d4d718ab561459497008d0e249bb429edca9d82c029a7d1caa81fbbc134
7
- data.tar.gz: 5d17439db11bb344a51ac20a32b7bf04fe6930f86e204546d043e043750f4d1a775b573ef48a86df53c01b01bec8e2ca74771245bffe3c1cc96403ff7884c136
6
+ metadata.gz: 28dd05eeaa1cda84b9fcca9d0eb537af4e884e103e7b2b9e80314350dbe32c97a0504902af8d9e4f3f1555579afee54947bf404955d05b62fa82b47717591bcb
7
+ data.tar.gz: a7413b695ff3273cd126c1beb0b477b4f81e53a0ad573b89008566401e2408f161bd3f62151cc8ec1037efd798ae074865e52a3e90f9958bf058472480b51114
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gnutemplate
4
- VERSION = "0.1.8.3"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/gnutemplate.rb CHANGED
@@ -4,9 +4,32 @@ require_relative "gnutemplate/version"
4
4
  require "numo/gnuplot"
5
5
  require "histogram/array"
6
6
 
7
+ module ExtendNP
8
+ def new_to_iruby
9
+ require 'tempfile'
10
+ tempfile_svg = Tempfile.open(['plot','.svg'])
11
+ # output SVG to tmpfile
12
+ gp = Numo::Gnuplot.default
13
+ gp.reset
14
+ gp.unset :multiplot # added
15
+ gp.set terminal:'svg'
16
+ gp.set output:tempfile_svg.path
17
+ gp.instance_eval(&@block)
18
+ ### gp.unset 'output' # commented out
19
+ svg = File.read(tempfile_svg.path)
20
+ tempfile_svg.close
21
+ ["image/svg+xml",svg]
22
+ end
23
+ end
24
+
25
+ class Numo::Gnuplot::NotePlot
26
+ include ExtendNP
27
+ alias_method :old_to_iruby, :to_iruby
28
+ alias_method :to_iruby, :new_to_iruby
29
+ end
30
+
7
31
  module Gnutemplate
8
32
  class Error < StandardError; end
9
-
10
33
 
11
34
  def note_line(data)
12
35
  Numo.noteplot do
@@ -112,11 +135,13 @@ module Gnutemplate
112
135
  end
113
136
  end
114
137
 
115
- def note_histogram(data, labels: nil, pileup: true,
138
+ # いずれかはここからargsを返せるようにする
139
+ # set terminal部の扱いは考えなければならない(多分、_drow, _noteにif...set...end だけ残せばいい)
140
+ def histogram(data, labels: nil, pileup: true,
116
141
  xmin: nil, xmax: nil, ymin: 0, ymax: nil, bins: 10,
117
142
  figsize: 1.0, rotate_xtics: 45,
118
143
  fill: true, alpha: 33, background: nil,
119
- file: nil, engine: :note)
144
+ file: nil)
120
145
 
121
146
  data = [data] if data[0].kind_of?(Numeric) || data[0].nil?
122
147
 
@@ -128,73 +153,160 @@ module Gnutemplate
128
153
  freqs = data.map {|d| d.to_a.compact.histogram(bins, min: xmin, max: xmax) }
129
154
  ymax ||= freqs.map{ _1[1] }.flatten.max * 1.1
130
155
 
156
+ if pileup
157
+ ###########
158
+ ###
159
+ ###########
160
+
161
+ set size: "#{figsize},#{figsize}"
162
+ set style: "fill solid" if fill
163
+
164
+ xticinterval = (xmax-xmin).to_f / bins
165
+ set xtics: "#{xmin-xticinterval}, #{xticinterval}, #{xmax+xticinterval}"
166
+ set(:xtics, "rotate by #{rotate_xtics}") if rotate_xtics
167
+
168
+ set xrange: (xmin-xticinterval)..(xmax+xticinterval)
169
+ set yrange: ymin..ymax
170
+
171
+ args = background ? ["[#{xmin}:#{xmax}] #{ymax} with filledc above y=#{ymin} fc \"##{background}\" notitle", {}] : []
172
+
173
+ freqs.each_with_index do |f, i|
174
+ args.push f[0], f[1]
175
+
176
+ if labels
177
+ args.push({:with => :boxes, :title => labels[i], :fillcolor => "rgb \"#{colors[i % 4]}\""})
178
+ else
179
+ args.push({:with => :boxes, :fillcolor => "rgb \"#{colors[i % 4]}\""})
180
+ end
181
+ end
182
+
183
+ return args
184
+
185
+ else
186
+
187
+ ###########
188
+ ###
189
+ ###########
190
+ # set title:"Temperature"
191
+ set auto:"x"
192
+ set :style, :data, :histogram
193
+ set :style, :histogram, :cluster, gap:1
194
+ set :style, :fill, solid: 1.0 - (alpha/100.0), border:-1
195
+ set boxwidth:0.9
196
+ set :xtic, :rotate, by: rotate_xtics, scale: 0
197
+
198
+ xticinterval = (xmax-xmin).to_f / bins
199
+ set xrange: 0..((xmax-xmin) / xticinterval).to_i
200
+
201
+ xtics = freqs[0][0]
202
+ .each.with_index
203
+ .inject("(") { |result, (x, i)| result += "'#{x-xticinterval/2}-#{x+xticinterval/2}' #{i}," }
204
+ .gsub(/,$/, ")")
205
+ set xtics: xtics
206
+
207
+ labels ||= (0...(freqs.length)).map(&:to_s)
208
+
209
+ args = freqs.zip(labels).each_with_index.map do |(f, l), i|
210
+ [*f, using: 2, w: :histogram, t: labels[i], fillcolor: "rgb \"#{colors[i % 4]}\""]
211
+ end
212
+
213
+ return args
214
+
215
+ end # Of if pileup..else
216
+ end
217
+
218
+ def note_histogram(data, labels: nil, pileup: true,
219
+ xmin: nil, xmax: nil, ymin: 0, ymax: nil, bins: 10,
220
+ figsize: 1.0, rotate_xtics: 45,
221
+ fill: true, alpha: 33, background: nil,
222
+ file: nil)
223
+
131
224
  Numo.noteplot do
132
225
 
133
226
  if !file.nil?
134
227
  set terminal: "gif"
135
228
  set output: file
136
229
  end
230
+
231
+ args = histogram(data, labels: labels, pileup: pileup,
232
+ xmin: xmin, xmax: xmax, ymin: ymin, ymax: ymax, bins: bins,
233
+ figsize: figsize, rotate_xtics: rotate_xtics,
234
+ fill: fill, alpha: alpha, background: background)
235
+
236
+ plot *args
137
237
 
138
- if pileup
139
- ###########
140
- ###
141
- ###########
238
+ # data = [data] if data[0].kind_of?(Numeric) || data[0].nil?
142
239
 
143
- set size: "#{figsize},#{figsize}"
144
- set style: "fill solid" if fill
240
+ # alpha_hex = (alpha * 256 / 100).to_s(16).upcase
241
+ # colors = ["##{alpha_hex}CC0000", "##{alpha_hex}00CC00", "##{alpha_hex}0000CC", "##{alpha_hex}888800"]
242
+
243
+ # xmax ||= data.map(&:to_a).flatten.compact.max
244
+ # xmin ||= data.map(&:to_a).flatten.compact.min
245
+ # freqs = data.map {|d| d.to_a.compact.histogram(bins, min: xmin, max: xmax) }
246
+ # ymax ||= freqs.map{ _1[1] }.flatten.max * 1.1
145
247
 
146
- xticinterval = (xmax-xmin).to_f / bins
147
- set xtics: "#{xmin-xticinterval}, #{xticinterval}, #{xmax+xticinterval}"
148
- set(:xtics, "rotate by #{rotate_xtics}") if rotate_xtics
149
248
 
150
- set xrange: (xmin-xticinterval)..(xmax+xticinterval)
151
- set yrange: ymin..ymax
249
+ # if pileup
250
+ # ###########
251
+ # ###
252
+ # ###########
152
253
 
153
- args = background ? ["[#{xmin}:#{xmax}] #{ymax} with filledc above y=#{ymin} fc \"##{background}\" notitle", {}] : []
254
+ # set size: "#{figsize},#{figsize}"
255
+ # set style: "fill solid" if fill
154
256
 
155
- freqs.each_with_index do |f, i|
156
- args.push f[0], f[1]
257
+ # xticinterval = (xmax-xmin).to_f / bins
258
+ # set xtics: "#{xmin-xticinterval}, #{xticinterval}, #{xmax+xticinterval}"
259
+ # set(:xtics, "rotate by #{rotate_xtics}") if rotate_xtics
157
260
 
158
- if labels
159
- args.push({:with => :boxes, :title => labels[i], :fillcolor => "rgb \"#{colors[i % 4]}\""})
160
- else
161
- args.push({:with => :boxes, :fillcolor => "rgb \"#{colors[i % 4]}\""})
162
- end
163
- end
261
+ # set xrange: (xmin-xticinterval)..(xmax+xticinterval)
262
+ # set yrange: ymin..ymax
164
263
 
165
- plot *args
264
+ # args = background ? ["[#{xmin}:#{xmax}] #{ymax} with filledc above y=#{ymin} fc \"##{background}\" notitle", {}] : []
166
265
 
167
- else
266
+ # freqs.each_with_index do |f, i|
267
+ # args.push f[0], f[1]
168
268
 
169
- ###########
170
- ###
171
- ###########
172
- # set title:"Temperature"
173
- set auto:"x"
174
- set :style, :data, :histogram
175
- set :style, :histogram, :cluster, gap:1
176
- set :style, :fill, solid: 1.0 - (alpha/100.0), border:-1
177
- set boxwidth:0.9
178
- set :xtic, :rotate, by: rotate_xtics, scale: 0
269
+ # if labels
270
+ # args.push({:with => :boxes, :title => labels[i], :fillcolor => "rgb \"#{colors[i % 4]}\""})
271
+ # else
272
+ # args.push({:with => :boxes, :fillcolor => "rgb \"#{colors[i % 4]}\""})
273
+ # end
274
+ # end
179
275
 
180
- xticinterval = (xmax-xmin).to_f / bins
181
- set xrange: 0..((xmax-xmin) / xticinterval).to_i
276
+ # plot *args
182
277
 
183
- xtics = freqs[0][0]
184
- .each.with_index
185
- .inject("(") { |result, (x, i)| result += "'#{x-xticinterval/2}-#{x+xticinterval/2}' #{i}," }
186
- .gsub(/,$/, ")")
187
- set xtics: xtics
278
+ # else
188
279
 
189
- labels ||= (0...(freqs.length)).map(&:to_s)
280
+ # ###########
281
+ # ###
282
+ # ###########
283
+ # # set title:"Temperature"
284
+ # set auto:"x"
285
+ # set :style, :data, :histogram
286
+ # set :style, :histogram, :cluster, gap:1
287
+ # set :style, :fill, solid: 1.0 - (alpha/100.0), border:-1
288
+ # set boxwidth:0.9
289
+ # set :xtic, :rotate, by: rotate_xtics, scale: 0
190
290
 
191
- args = freqs.zip(labels).each_with_index.map do |(f, l), i|
192
- [*f, using: 2, w: :histogram, t: labels[i], fillcolor: "rgb \"#{colors[i % 4]}\""]
193
- end
291
+ # xticinterval = (xmax-xmin).to_f / bins
292
+ # set xrange: 0..((xmax-xmin) / xticinterval).to_i
293
+
294
+ # xtics = freqs[0][0]
295
+ # .each.with_index
296
+ # .inject("(") { |result, (x, i)| result += "'#{x-xticinterval/2}-#{x+xticinterval/2}' #{i}," }
297
+ # .gsub(/,$/, ")")
298
+ # set xtics: xtics
194
299
 
195
- plot *args
300
+ # labels ||= (0...(freqs.length)).map(&:to_s)
301
+
302
+ # args = freqs.zip(labels).each_with_index.map do |(f, l), i|
303
+ # [*f, using: 2, w: :histogram, t: labels[i], fillcolor: "rgb \"#{colors[i % 4]}\""]
304
+ # end
305
+
306
+ # plot *args
307
+
308
+ # end # Of if pileup..else
196
309
 
197
- end # Of if pileup..else
198
310
  end # Of Numo.noteplot do
199
311
 
200
312
  end # Of def function
@@ -203,17 +315,7 @@ module Gnutemplate
203
315
  xmin: nil, xmax: nil, ymin: 0, ymax: nil, bins: 10,
204
316
  figsize: 1.0, rotate_xtics: 45,
205
317
  fill: true, alpha: 33, background: nil,
206
- file: nil, engine: :note)
207
-
208
- data = [data] if data[0].kind_of?(Numeric) || data[0].nil?
209
-
210
- alpha_hex = (alpha * 256 / 100).to_s(16).upcase
211
- colors = ["##{alpha_hex}CC0000", "##{alpha_hex}00CC00", "##{alpha_hex}0000CC", "##{alpha_hex}888800"]
212
-
213
- xmax ||= data.map(&:to_a).flatten.compact.max
214
- xmin ||= data.map(&:to_a).flatten.compact.min
215
- freqs = data.map {|d| d.to_a.compact.histogram(bins, min: xmin, max: xmax) }
216
- ymax ||= freqs.map{ _1[1] }.flatten.max * 1.1
318
+ file: nil)
217
319
 
218
320
  Numo.gnuplot do
219
321
 
@@ -221,67 +323,84 @@ module Gnutemplate
221
323
  set terminal: "gif"
222
324
  set output: file
223
325
  end
326
+
327
+ args = histogram(data, labels: labels, pileup: pileup,
328
+ xmin: xmin, xmax: xmax, ymin: ymin, ymax: ymax, bins: bins,
329
+ figsize: figsize, rotate_xtics: rotate_xtics,
330
+ fill: fill, alpha: alpha, background: background)
224
331
 
225
- if pileup
226
- ###########
227
- ###
228
- ###########
332
+ plot *args
229
333
 
230
- set size: "#{figsize},#{figsize}"
231
- set style: "fill solid" if fill
334
+ # data = [data] if data[0].kind_of?(Numeric) || data[0].nil?
232
335
 
233
- xticinterval = (xmax-xmin).to_f / bins
234
- set xtics: "#{xmin-xticinterval}, #{xticinterval}, #{xmax+xticinterval}"
235
- set(:xtics, "rotate by #{rotate_xtics}") if rotate_xtics
336
+ # alpha_hex = (alpha * 256 / 100).to_s(16).upcase
337
+ # colors = ["##{alpha_hex}CC0000", "##{alpha_hex}00CC00", "##{alpha_hex}0000CC", "##{alpha_hex}888800"]
338
+
339
+ # xmax ||= data.map(&:to_a).flatten.compact.max
340
+ # xmin ||= data.map(&:to_a).flatten.compact.min
341
+ # freqs = data.map {|d| d.to_a.compact.histogram(bins, min: xmin, max: xmax) }
342
+ # ymax ||= freqs.map{ _1[1] }.flatten.max * 1.1
236
343
 
237
- set xrange: (xmin-xticinterval)..(xmax+xticinterval)
238
- set yrange: ymin..ymax
344
+ # if pileup
345
+ # ###########
346
+ # ###
347
+ # ###########
239
348
 
240
- args = background ? ["[#{xmin}:#{xmax}] #{ymax} with filledc above y=#{ymin} fc \"##{background}\" notitle", {}] : []
349
+ # set size: "#{figsize},#{figsize}"
350
+ # set style: "fill solid" if fill
241
351
 
242
- freqs.each_with_index do |f, i|
243
- args.push f[0], f[1]
352
+ # xticinterval = (xmax-xmin).to_f / bins
353
+ # set xtics: "#{xmin-xticinterval}, #{xticinterval}, #{xmax+xticinterval}"
354
+ # set(:xtics, "rotate by #{rotate_xtics}") if rotate_xtics
244
355
 
245
- if labels
246
- args.push({:with => :boxes, :title => labels[i], :fillcolor => "rgb \"#{colors[i % 4]}\""})
247
- else
248
- args.push({:with => :boxes, :fillcolor => "rgb \"#{colors[i % 4]}\""})
249
- end
250
- end
356
+ # set xrange: (xmin-xticinterval)..(xmax+xticinterval)
357
+ # set yrange: ymin..ymax
251
358
 
252
- plot *args # ,xs, ys, { with: :lines , title: "STD"}
359
+ # args = background ? ["[#{xmin}:#{xmax}] #{ymax} with filledc above y=#{ymin} fc \"##{background}\" notitle", {}] : []
253
360
 
254
- else
361
+ # freqs.each_with_index do |f, i|
362
+ # args.push f[0], f[1]
255
363
 
256
- ###########
257
- ###
258
- ###########
259
- set auto:"x"
260
- set :style, :data, :histogram
261
- set :style, :histogram, :cluster, gap:1
262
- set :style, :fill, solid: 1.0 - (alpha/100.0), border:-1
263
- set boxwidth:0.9
264
- set :xtic, :rotate, by: rotate_xtics, scale: 0
364
+ # if labels
365
+ # args.push({:with => :boxes, :title => labels[i], :fillcolor => "rgb \"#{colors[i % 4]}\""})
366
+ # else
367
+ # args.push({:with => :boxes, :fillcolor => "rgb \"#{colors[i % 4]}\""})
368
+ # end
369
+ # end
265
370
 
266
- xticinterval = (xmax-xmin).to_f / bins
267
- set xrange: 0..((xmax-xmin) / xticinterval).to_i
371
+ # plot *args # ,xs, ys, { with: :lines , title: "STD"}
268
372
 
269
- xtics = freqs[0][0]
270
- .each.with_index
271
- .inject("(") { |result, (x, i)| result += "'#{x-xticinterval/2}-#{x+xticinterval/2}' #{i}," }
272
- .gsub(/,$/, ")")
273
- set xtics: xtics
373
+ # else
274
374
 
275
- labels ||= (0...(freqs.length)).map(&:to_s)
375
+ # ###########
376
+ # ###
377
+ # ###########
378
+ # set auto:"x"
379
+ # set :style, :data, :histogram
380
+ # set :style, :histogram, :cluster, gap:1
381
+ # set :style, :fill, solid: 1.0 - (alpha/100.0), border:-1
382
+ # set boxwidth:0.9
383
+ # set :xtic, :rotate, by: rotate_xtics, scale: 0
276
384
 
277
- args = freqs.zip(labels).each_with_index.map do |(f, l), i|
278
- [*f, using: 2, w: :histogram, t: labels[i], fillcolor: "rgb \"#{colors[i % 4]}\""]
279
- end
385
+ # xticinterval = (xmax-xmin).to_f / bins
386
+ # set xrange: 0..((xmax-xmin) / xticinterval).to_i
387
+
388
+ # xtics = freqs[0][0]
389
+ # .each.with_index
390
+ # .inject("(") { |result, (x, i)| result += "'#{x-xticinterval/2}-#{x+xticinterval/2}' #{i}," }
391
+ # .gsub(/,$/, ")")
392
+ # set xtics: xtics
280
393
 
281
- plot *args
394
+ # labels ||= (0...(freqs.length)).map(&:to_s)
395
+
396
+ # args = freqs.zip(labels).each_with_index.map do |(f, l), i|
397
+ # [*f, using: 2, w: :histogram, t: labels[i], fillcolor: "rgb \"#{colors[i % 4]}\""]
398
+ # end
399
+
400
+ # plot *args
282
401
 
283
- end # Of if pileup..else
284
- end # Of Numo.noteplot do
402
+ # end # Of if pileup..else
403
+ end # Of Numo.gnuplot do
285
404
 
286
405
  end # Of def function
287
406
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gnutemplate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - showata
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-14 00:00:00.000000000 Z
11
+ date: 2023-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: numo-gnuplot