gnutemplate 0.2.0.2 → 0.2.1

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: f08db55b18fe15eae25c87905d12bb1c1d1c9a35b1f59bca831431ef2c415b72
4
- data.tar.gz: 8fec75c071eabf8dc6652e2e9d953ef379bf3782e20e91c97451f3753f6d04ba
3
+ metadata.gz: b8702141a60cf55e1469b1dc3c614c61ae4e186b82528499b68539f8d26e5e99
4
+ data.tar.gz: d9e37d34538eff71b66ee6606792dc97a4a6b1af3d8f6f5c23ad156b4651a61c
5
5
  SHA512:
6
- metadata.gz: cb258e5c419d47df697b56910d8f7e6b6ab965cf7df640971e358c96e9c05c27ebc27e9ea689f3f17444c2e70f5a86a7b53d0f13809019cf0baa3c611a4ab565
7
- data.tar.gz: d79bacf208a0f08342250b9efe2770e396b5870525c787a3e6f1dfb5e49066d0d0e7ab0ee767a3c8502304d1ac2d396409f389299e54018a9688abc3151b741e
6
+ metadata.gz: ee061e613587ab79811aaf9b3aa44841c4073963b0da073791e944696d0a582cba3ff4f985a7dea3d44ddd40e274f6d7b7b87dab1839da1192ddbb11cda9f742
7
+ data.tar.gz: 4a70f90c8c570cf6ba0bcb3bae0a85701feaab3b3dc829c0edf00c5758c4c15aea55f788df0e77ba4b9caa0e89c5d7e45cf109f5ba72cc831e8098b03e079aae
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gnutemplate
4
- VERSION = "0.2.0.2"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/gnutemplate.rb CHANGED
@@ -31,6 +31,24 @@ end
31
31
  module Gnutemplate
32
32
  class Error < StandardError; end
33
33
 
34
+
35
+ # settingはむずい
36
+ # ・全体はハッシュ
37
+ # ・基本は次のような指定
38
+ # settings[:style] = "fill solid"
39
+ # ・ハッシュを使う場合も。以下は、set :xtic, :rotate, by: rotate_xtics, scale: 0の表現怜
40
+ # settings[:xtic] = {rotate: nil, by: rotate_xtics, scale: 0}
41
+ # ・同じキー(例えばxtics)に複数指定たいときはリストにして渡す
42
+ # settings[:xtics] = ["#{xmin-xticinterval}, #{xticinterval}, #{xmax+xticinterval}" ,
43
+ # "rotate by #{rotate_xtics}"]
44
+ # ・リストの中を更にハッシュにすることも可能
45
+ # settings[:style] = [{data: nil, histogram: nil}, # set :style, :data, :histogram を表現
46
+ # {histogram: nil, cluster: nil, gap: 1}, # set :histogram, :cluster, gap: 1 を表現
47
+ # {fill: nil, solid: 1.0 - (alpha/100.0), border: -1}]
48
+
49
+
50
+ SubPlot = Struct.new(:args, :settings)
51
+
34
52
  def note_line(data)
35
53
  Numo.noteplot do
36
54
  set xtics: xtics
@@ -104,42 +122,40 @@ module Gnutemplate
104
122
  # 列データをmin, maxごとに分離する
105
123
  rows_min = (0...(rows.length)).to_a.map {|i| rows[i] if i % 2 == 0}.compact
106
124
  rows_max = (0...(rows.length)).to_a.map {|i| rows[i] if i % 2 == 1}.compact
107
-
108
- Numo.gnuplot do
109
- if !file.nil?
110
- set terminal: "gif"
111
- set output: file
112
- end
113
125
 
114
- if !xtics.nil?
115
- set xtics: xtics
116
- set :xtics, "rotate by 90"
117
- end
118
-
119
- xrange ||= (rows_min.map(&:to_a).flatten.compact.min)..(rows_max.map(&:to_a).flatten.compact.max)
120
- set xrange: xrange
121
- set :grid
122
- set style: :fill_solid
123
- set title: title if title
124
-
125
- ### キャンドルスティックを応用する
126
- # X軸, 太い所の最大値, 最大値, 最小値, 太い所の最小値
127
- # 今回は細い箇所は不要
128
- # X軸はこの場合配列にしなきゃだめ(to_a) これは癖をつけたほうが安全
126
+ settings = {}
127
+ args = []
129
128
 
130
- args = rows_min.zip(rows_max, titlenames).each.with_index.inject([]) do |result, ((mi, ma, t), i)|
131
- result += [xrange.to_a, mi.to_a, mi.to_a, ma.to_a, ma.to_a, {with: "candlesticks", fc_rgb: colors[i % 4], title: t} ]
132
- end
129
+ if !xtics.nil?
130
+ set[:xtics] = [xtics]
131
+ set[:xtics].push "rotate by 90"
132
+ end
133
133
 
134
- plot *args
134
+ xrange ||= (rows_min.map(&:to_a).flatten.compact.min)..(rows_max.map(&:to_a).flatten.compact.max)
135
+
136
+ set[:xrange] = xrange
137
+ set[:grid] = nil
138
+ set[:style] = :fill_solid
139
+ set[:title] = title if title
140
+
141
+ ### キャンドルスティックを応用する
142
+ # X軸, 太い所の最大値, 最大値, 最小値, 太い所の最小値
143
+ # 今回は細い箇所は不要
144
+ # X軸はこの場合配列にしなきゃだめ(to_a) これは癖をつけたほうが安全
145
+
146
+ args = rows_min.zip(rows_max, titlenames).each.with_index.inject([]) do |result, ((mi, ma, t), i)|
147
+ result += [xrange.to_a, mi.to_a, mi.to_a, ma.to_a, ma.to_a, {with: "candlesticks", fc_rgb: colors[i % 4], title: t} ]
135
148
  end
149
+
150
+ plot *args
151
+
136
152
  end
137
153
 
138
- # いずれかはここからargsを返せるようにする
154
+ # ここからsettings, argsを返せるようにする
139
155
  # set terminal部の扱いは考えなければならない(多分、_drow, _noteにif...set...end だけ残せばいい)
140
156
  def histogram(data, labels: nil, pileup: true,
141
157
  xmin: nil, xmax: nil, ymin: 0, ymax: nil, bins: 10,
142
- figsize: 1.0, rotate_xtics: 45,
158
+ plotsize: nil, rotate_xtics: 45,
143
159
  fill: true, alpha: 33, background: nil,
144
160
  file: nil)
145
161
 
@@ -154,21 +170,24 @@ module Gnutemplate
154
170
  ymax ||= freqs.map{ _1[1] }.flatten.max * 1.1
155
171
 
156
172
  if pileup
157
- ###########
158
- ###
159
- ###########
160
-
161
- set size: "#{figsize},#{figsize}"
162
- set style: "fill solid" if fill
163
173
 
164
174
  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
175
 
168
- set xrange: (xmin-xticinterval)..(xmax+xticinterval)
169
- set yrange: ymin..ymax
176
+ settings = {}
177
+ settings[:size] = "#{plotsize[0]},#{plotsize[1]}" if plotsize
178
+ settings[:style] = "fill solid" if fill
170
179
 
171
- args = background ? ["[#{xmin}:#{xmax}] #{ymax} with filledc above y=#{ymin} fc \"##{background}\" notitle", {}] : []
180
+ settings[:xtics] = ["#{xmin-xticinterval}, #{xticinterval}, #{xmax+xticinterval}"]
181
+ settings[:xtics].push("rotate by #{rotate_xtics}") if rotate_xtics
182
+
183
+ settings[:xrange] = (xmin-xticinterval)..(xmax+xticinterval)
184
+ settings[:yrange] = ymin..ymax
185
+
186
+ args = if background
187
+ ["[#{xmin}:#{xmax}] #{ymax} with filledc above y=#{ymin} fc \"##{background}\" notitle", {}]
188
+ else
189
+ []
190
+ end
172
191
 
173
192
  freqs.each_with_index do |f, i|
174
193
  args.push f[0], f[1]
@@ -180,29 +199,27 @@ module Gnutemplate
180
199
  end
181
200
  end
182
201
 
183
- return args
202
+ return SubPlot.new(args, settings)
184
203
 
185
204
  else
186
205
 
187
- ###########
188
- ###
189
- ###########
190
206
  # 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
207
+ settings = {}
208
+ settings[:auto] = "x"
209
+ settings[:style] = [{data: nil, histogram: nil}, # set :style, :data, :histogram を表現
210
+ {histogram: nil, cluster: nil, gap: 1}, # set :histogram, :cluster, gap: 1 を表現
211
+ {fill: nil, solid: 1.0 - (alpha/100.0), border: -1}]
212
+ settings[:boxwidth] = 0.9
213
+ settings[:xtic] = {rotate: nil, by: rotate_xtics, scale: 0}
197
214
 
198
215
  xticinterval = (xmax-xmin).to_f / bins
199
- set xrange: 0..((xmax-xmin) / xticinterval).to_i
216
+ settings[:xrange] = 0..((xmax-xmin) / xticinterval).to_i
200
217
 
201
218
  xtics = freqs[0][0]
202
219
  .each.with_index
203
220
  .inject("(") { |result, (x, i)| result += "'#{x-xticinterval/2}-#{x+xticinterval/2}' #{i}," }
204
221
  .gsub(/,$/, ")")
205
- set xtics: xtics
222
+ settings[:xtics] = xtics
206
223
 
207
224
  labels ||= (0...(freqs.length)).map(&:to_s)
208
225
 
@@ -210,200 +227,197 @@ module Gnutemplate
210
227
  [*f, using: 2, w: :histogram, t: labels[i], fillcolor: "rgb \"#{colors[i % 4]}\""]
211
228
  end
212
229
 
213
- return args
230
+ return SubPlot.new(args, settings)
214
231
 
215
232
  end # Of if pileup..else
216
233
  end
217
- module_function :histogram
218
234
 
219
235
  def note_histogram(data, labels: nil, pileup: true,
220
236
  xmin: nil, xmax: nil, ymin: 0, ymax: nil, bins: 10,
221
- figsize: 1.0, rotate_xtics: 45,
237
+ plotsize: nil, rotate_xtics: 45,
222
238
  fill: true, alpha: 33, background: nil,
223
239
  file: nil)
224
240
 
225
- Numo.noteplot do
226
-
227
- if !file.nil?
228
- set terminal: "gif"
229
- set output: file
230
- end
231
-
232
- args = histogram(data, labels: labels, pileup: pileup,
233
- xmin: xmin, xmax: xmax, ymin: ymin, ymax: ymax, bins: bins,
234
- figsize: figsize, rotate_xtics: rotate_xtics,
235
- fill: fill, alpha: alpha, background: background)
236
-
237
- plot *args
238
-
239
- # data = [data] if data[0].kind_of?(Numeric) || data[0].nil?
240
-
241
- # alpha_hex = (alpha * 256 / 100).to_s(16).upcase
242
- # colors = ["##{alpha_hex}CC0000", "##{alpha_hex}00CC00", "##{alpha_hex}0000CC", "##{alpha_hex}888800"]
243
-
244
- # xmax ||= data.map(&:to_a).flatten.compact.max
245
- # xmin ||= data.map(&:to_a).flatten.compact.min
246
- # freqs = data.map {|d| d.to_a.compact.histogram(bins, min: xmin, max: xmax) }
247
- # ymax ||= freqs.map{ _1[1] }.flatten.max * 1.1
248
-
249
-
250
- # if pileup
251
- # ###########
252
- # ###
253
- # ###########
254
-
255
- # set size: "#{figsize},#{figsize}"
256
- # set style: "fill solid" if fill
257
-
258
- # xticinterval = (xmax-xmin).to_f / bins
259
- # set xtics: "#{xmin-xticinterval}, #{xticinterval}, #{xmax+xticinterval}"
260
- # set(:xtics, "rotate by #{rotate_xtics}") if rotate_xtics
261
-
262
- # set xrange: (xmin-xticinterval)..(xmax+xticinterval)
263
- # set yrange: ymin..ymax
264
-
265
- # args = background ? ["[#{xmin}:#{xmax}] #{ymax} with filledc above y=#{ymin} fc \"##{background}\" notitle", {}] : []
266
-
267
- # freqs.each_with_index do |f, i|
268
- # args.push f[0], f[1]
269
-
270
- # if labels
271
- # args.push({:with => :boxes, :title => labels[i], :fillcolor => "rgb \"#{colors[i % 4]}\""})
272
- # else
273
- # args.push({:with => :boxes, :fillcolor => "rgb \"#{colors[i % 4]}\""})
274
- # end
275
- # end
276
-
277
- # plot *args
278
-
279
- # else
280
-
281
- # ###########
282
- # ###
283
- # ###########
284
- # # set title:"Temperature"
285
- # set auto:"x"
286
- # set :style, :data, :histogram
287
- # set :style, :histogram, :cluster, gap:1
288
- # set :style, :fill, solid: 1.0 - (alpha/100.0), border:-1
289
- # set boxwidth:0.9
290
- # set :xtic, :rotate, by: rotate_xtics, scale: 0
291
-
292
- # xticinterval = (xmax-xmin).to_f / bins
293
- # set xrange: 0..((xmax-xmin) / xticinterval).to_i
294
-
295
- # xtics = freqs[0][0]
296
- # .each.with_index
297
- # .inject("(") { |result, (x, i)| result += "'#{x-xticinterval/2}-#{x+xticinterval/2}' #{i}," }
298
- # .gsub(/,$/, ")")
299
- # set xtics: xtics
300
-
301
- # labels ||= (0...(freqs.length)).map(&:to_s)
302
-
303
- # args = freqs.zip(labels).each_with_index.map do |(f, l), i|
304
- # [*f, using: 2, w: :histogram, t: labels[i], fillcolor: "rgb \"#{colors[i % 4]}\""]
305
- # end
306
-
307
- # plot *args
308
-
309
- # end # Of if pileup..else
310
-
311
- end # Of Numo.noteplot do
312
-
241
+ as = Gnutemplate.histogram(data, labels: labels, pileup: pileup,
242
+ xmin: xmin, xmax: xmax, ymin: ymin, ymax: ymax, bins: bins,
243
+ plotsize: plotsize, rotate_xtics: rotate_xtics,
244
+ fill: fill, alpha: alpha, background: background)
245
+
246
+ note as, file: file
247
+
313
248
  end # Of def function
314
249
 
315
250
  def draw_histogram(data, labels: nil, pileup: true,
316
251
  xmin: nil, xmax: nil, ymin: 0, ymax: nil, bins: 10,
317
- figsize: 1.0, rotate_xtics: 45,
252
+ plotsize: nil, rotate_xtics: 45,
318
253
  fill: true, alpha: 33, background: nil,
319
254
  file: nil)
320
255
 
321
- Numo.gnuplot do
322
-
323
- if !file.nil?
324
- set terminal: "gif"
325
- set output: file
326
- end
327
-
328
- args = histogram(data, labels: labels, pileup: pileup,
329
- xmin: xmin, xmax: xmax, ymin: ymin, ymax: ymax, bins: bins,
330
- figsize: figsize, rotate_xtics: rotate_xtics,
331
- fill: fill, alpha: alpha, background: background)
332
-
333
- plot *args
334
-
335
- # data = [data] if data[0].kind_of?(Numeric) || data[0].nil?
256
+ as = Gnutemplate.histogram(data, labels: labels, pileup: pileup,
257
+ xmin: xmin, xmax: xmax, ymin: ymin, ymax: ymax, bins: bins,
258
+ plotsize: plotsize, rotate_xtics: rotate_xtics,
259
+ fill: fill, alpha: alpha, background: background)
260
+
261
+ draw as, file: file
336
262
 
337
- # alpha_hex = (alpha * 256 / 100).to_s(16).upcase
338
- # colors = ["##{alpha_hex}CC0000", "##{alpha_hex}00CC00", "##{alpha_hex}0000CC", "##{alpha_hex}888800"]
263
+ end # Of def function
339
264
 
340
- # xmax ||= data.map(&:to_a).flatten.compact.max
341
- # xmin ||= data.map(&:to_a).flatten.compact.min
342
- # freqs = data.map {|d| d.to_a.compact.histogram(bins, min: xmin, max: xmax) }
343
- # ymax ||= freqs.map{ _1[1] }.flatten.max * 1.1
344
-
345
- # if pileup
346
- # ###########
347
- # ###
348
- # ###########
349
-
350
- # set size: "#{figsize},#{figsize}"
351
- # set style: "fill solid" if fill
352
-
353
- # xticinterval = (xmax-xmin).to_f / bins
354
- # set xtics: "#{xmin-xticinterval}, #{xticinterval}, #{xmax+xticinterval}"
355
- # set(:xtics, "rotate by #{rotate_xtics}") if rotate_xtics
356
-
357
- # set xrange: (xmin-xticinterval)..(xmax+xticinterval)
358
- # set yrange: ymin..ymax
359
-
360
- # args = background ? ["[#{xmin}:#{xmax}] #{ymax} with filledc above y=#{ymin} fc \"##{background}\" notitle", {}] : []
361
265
 
362
- # freqs.each_with_index do |f, i|
363
- # args.push f[0], f[1]
364
-
365
- # if labels
366
- # args.push({:with => :boxes, :title => labels[i], :fillcolor => "rgb \"#{colors[i % 4]}\""})
367
- # else
368
- # args.push({:with => :boxes, :fillcolor => "rgb \"#{colors[i % 4]}\""})
369
- # end
370
- # end
371
-
372
- # plot *args # ,xs, ys, { with: :lines , title: "STD"}
373
-
374
- # else
375
-
376
- # ###########
377
- # ###
378
- # ###########
379
- # set auto:"x"
380
- # set :style, :data, :histogram
381
- # set :style, :histogram, :cluster, gap:1
382
- # set :style, :fill, solid: 1.0 - (alpha/100.0), border:-1
383
- # set boxwidth:0.9
384
- # set :xtic, :rotate, by: rotate_xtics, scale: 0
385
-
386
- # xticinterval = (xmax-xmin).to_f / bins
387
- # set xrange: 0..((xmax-xmin) / xticinterval).to_i
388
-
389
- # xtics = freqs[0][0]
390
- # .each.with_index
391
- # .inject("(") { |result, (x, i)| result += "'#{x-xticinterval/2}-#{x+xticinterval/2}' #{i}," }
392
- # .gsub(/,$/, ")")
393
- # set xtics: xtics
394
-
395
- # labels ||= (0...(freqs.length)).map(&:to_s)
396
-
397
- # args = freqs.zip(labels).each_with_index.map do |(f, l), i|
398
- # [*f, using: 2, w: :histogram, t: labels[i], fillcolor: "rgb \"#{colors[i % 4]}\""]
399
- # end
400
-
401
- # plot *args
402
-
403
- # end # Of if pileup..else
404
- end # Of Numo.gnuplot do
405
-
406
- end # Of def function
266
+ def note(subplot, file: nil, campus_size: nil, multicolumn: 1) # for any plot function
267
+
268
+ subplot = [subplot] if !subplot.is_a?(Array)
269
+
270
+ Numo.noteplot do
271
+
272
+ if file
273
+ if campus_size
274
+ set termnal: "png", size: campus_size
275
+ else
276
+ set terminal: "png"
277
+ end
278
+ set output: file
279
+ end
280
+
281
+ # マルチプロット調整
282
+ multiline = (subplot.length.to_f / multicolumn).ceil
283
+ set :multiplot, layout: "#{multiline},#{multicolumn}"
284
+
285
+ # subplot一つ一つを描画
286
+ subplot.each do |sp|
287
+
288
+ # こういうのがパターンマッチでできるの?
289
+ sp.settings.each do |k, v|
290
+ if v.kind_of?(Hash)
291
+ sargs = []
292
+ skwargs = {}
293
+
294
+ v.map do |vk, vv|
295
+ if vv.nil?
296
+ sargs.push vk
297
+ else
298
+ skwargs[vk] = vv
299
+ end
300
+ end
301
+
302
+ set k, *sargs, **skwargs
303
+
304
+ elsif v.kind_of?(Array)
305
+
306
+ v.each do |vi|
307
+ if vi.kind_of?(Hash)
308
+ sargs = []
309
+ skwargs = {}
310
+ vi.map do |vk, vv|
311
+ if vv.nil?
312
+ sargs.push vk
313
+ else
314
+ skwargs[vk] = vv
315
+ end
316
+ end
317
+ set k, *sargs, **skwargs
318
+ else
319
+ set k, vi
320
+ end
321
+ end
322
+
323
+ else
324
+
325
+ if v.nil?
326
+ set k
327
+ else
328
+ set k, v
329
+ end
330
+
331
+ end
332
+ end
333
+
334
+ plot *(sp.args)
335
+ end # of subplot.each
336
+
337
+ unset :multiplot
338
+
339
+ end # of Numo.noteplot
340
+ end # of def draw
341
+
342
+ def draw(subplot, settings, campus_size: nil, file: nil, multicolumn: 1) # for any plot function
343
+
344
+ subplot = [subplot] if !subplot.is_a?(Array)
345
+
346
+ Numo.gnuplot do
347
+
348
+ if file
349
+ if campus_size
350
+ set termnal: "png", size: campus_size
351
+ else
352
+ set terminal: "png"
353
+ end
354
+ set output: file
355
+ end
356
+
357
+ multiline = (subplot.length.to_f / multicolumn).ceil
358
+ set :multiplot, layout: "#{multiline},#{multicolumn}"
359
+
360
+ subplot.each do |sp|
361
+
362
+ # こういうのがパターンマッチでできるの?
363
+ sp.settings.each do |k, v|
364
+ if v.kind_of?(Hash)
365
+ sargs = []
366
+ skwargs = {}
367
+
368
+ v.map do |vk, vv|
369
+ if vv.nil?
370
+ sargs.push vk
371
+ else
372
+ skwargs[vk] = vv
373
+ end
374
+ end
375
+
376
+ set k, *sargs, **skwargs
377
+
378
+ elsif v.kind_of?(Array)
379
+
380
+ v.each do |vi|
381
+ if vi.kind_of?(Hash)
382
+ sargs = []
383
+ skwargs = {}
384
+ vi.map do |vk, vv|
385
+ if vv.nil?
386
+ sargs.push vk
387
+ else
388
+ skwargs[vk] = vv
389
+ end
390
+ end
391
+ set k, *sargs, **skwargs
392
+ else
393
+ set k, vi
394
+ end
395
+ end
396
+
397
+ else
398
+
399
+ if v.nil?
400
+ set k
401
+ else
402
+ set k, v
403
+ end
404
+
405
+ end
406
+ end
407
+
408
+ plot *(sp.args)
409
+
410
+ end # of subplot.each
411
+
412
+ unset :multiplot
413
+
414
+ end # of Numo.gnuplot
415
+ end # of def draw
416
+
417
+ module_function :histogram
418
+ module_function :note_line, :draw_line
419
+ module_function :note_box, :draw_box
420
+ module_function :note_histogram, :draw_histogram
421
+ module_function :note, :draw
407
422
 
408
- module_function :note_line, :draw_line, :note_box, :draw_box, :note_histogram, :draw_histogram
409
423
  end # Of module
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.2.0.2
4
+ version: 0.2.1
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-24 00:00:00.000000000 Z
11
+ date: 2023-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: numo-gnuplot