gnutemplate 0.1.8.2 → 0.1.9
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/gnutemplate/version.rb +1 -1
- data/lib/gnutemplate.rb +112 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fef32d38de9aac460a3999b100fedb69ffa1a95a72589fc196b4dc34385e1bf
|
4
|
+
data.tar.gz: 3ff03c9032f496344d52b28f99e25e6f7440e31b8a617e292871123d0fced7c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6af589bee0cd490502d19f180a5929af1633bd6aae0441856fb8ad7cf3e5de945ecaac27171f31c6e29ba18a668f5784b0036a091a45e6826ca6d2da828fc34
|
7
|
+
data.tar.gz: 466d9643c0fdb0e0697a4afc445da81c1d450dbde07550a62d19ce22e0ac398ac4a3c725454a4a7bd09502f01f980bc963fdcae59c8d404be34d49e055c26a46
|
data/lib/gnutemplate/version.rb
CHANGED
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,18 @@ module Gnutemplate
|
|
112
135
|
end
|
113
136
|
end
|
114
137
|
|
115
|
-
|
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
|
144
|
+
file: nil)
|
145
|
+
|
146
|
+
if !file.nil?
|
147
|
+
set terminal: "gif"
|
148
|
+
set output: file
|
149
|
+
end
|
120
150
|
|
121
151
|
data = [data] if data[0].kind_of?(Numeric) || data[0].nil?
|
122
152
|
|
@@ -128,8 +158,86 @@ module Gnutemplate
|
|
128
158
|
freqs = data.map {|d| d.to_a.compact.histogram(bins, min: xmin, max: xmax) }
|
129
159
|
ymax ||= freqs.map{ _1[1] }.flatten.max * 1.1
|
130
160
|
|
161
|
+
if pileup
|
162
|
+
###########
|
163
|
+
###
|
164
|
+
###########
|
165
|
+
|
166
|
+
set size: "#{figsize},#{figsize}"
|
167
|
+
set style: "fill solid" if fill
|
168
|
+
|
169
|
+
xticinterval = (xmax-xmin).to_f / bins
|
170
|
+
set xtics: "#{xmin-xticinterval}, #{xticinterval}, #{xmax+xticinterval}"
|
171
|
+
set(:xtics, "rotate by #{rotate_xtics}") if rotate_xtics
|
172
|
+
|
173
|
+
set xrange: (xmin-xticinterval)..(xmax+xticinterval)
|
174
|
+
set yrange: ymin..ymax
|
175
|
+
|
176
|
+
args = background ? ["[#{xmin}:#{xmax}] #{ymax} with filledc above y=#{ymin} fc \"##{background}\" notitle", {}] : []
|
177
|
+
|
178
|
+
freqs.each_with_index do |f, i|
|
179
|
+
args.push f[0], f[1]
|
180
|
+
|
181
|
+
if labels
|
182
|
+
args.push({:with => :boxes, :title => labels[i], :fillcolor => "rgb \"#{colors[i % 4]}\""})
|
183
|
+
else
|
184
|
+
args.push({:with => :boxes, :fillcolor => "rgb \"#{colors[i % 4]}\""})
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
plot *args
|
189
|
+
|
190
|
+
else
|
191
|
+
|
192
|
+
###########
|
193
|
+
###
|
194
|
+
###########
|
195
|
+
# set title:"Temperature"
|
196
|
+
set auto:"x"
|
197
|
+
set :style, :data, :histogram
|
198
|
+
set :style, :histogram, :cluster, gap:1
|
199
|
+
set :style, :fill, solid: 1.0 - (alpha/100.0), border:-1
|
200
|
+
set boxwidth:0.9
|
201
|
+
set :xtic, :rotate, by: rotate_xtics, scale: 0
|
202
|
+
|
203
|
+
xticinterval = (xmax-xmin).to_f / bins
|
204
|
+
set xrange: 0..((xmax-xmin) / xticinterval).to_i
|
205
|
+
|
206
|
+
xtics = freqs[0][0]
|
207
|
+
.each.with_index
|
208
|
+
.inject("(") { |result, (x, i)| result += "'#{x-xticinterval/2}-#{x+xticinterval/2}' #{i}," }
|
209
|
+
.gsub(/,$/, ")")
|
210
|
+
set xtics: xtics
|
211
|
+
|
212
|
+
labels ||= (0...(freqs.length)).map(&:to_s)
|
213
|
+
|
214
|
+
args = freqs.zip(labels).each_with_index.map do |(f, l), i|
|
215
|
+
[*f, using: 2, w: :histogram, t: labels[i], fillcolor: "rgb \"#{colors[i % 4]}\""]
|
216
|
+
end
|
217
|
+
|
218
|
+
plot *args
|
219
|
+
|
220
|
+
end # Of if pileup..else
|
221
|
+
end
|
222
|
+
|
223
|
+
def note_histogram(data, labels: nil, pileup: true,
|
224
|
+
xmin: nil, xmax: nil, ymin: 0, ymax: nil, bins: 10,
|
225
|
+
figsize: 1.0, rotate_xtics: 45,
|
226
|
+
fill: true, alpha: 33, background: nil,
|
227
|
+
file: nil)
|
228
|
+
|
131
229
|
Numo.noteplot do
|
132
230
|
|
231
|
+
data = [data] if data[0].kind_of?(Numeric) || data[0].nil?
|
232
|
+
|
233
|
+
alpha_hex = (alpha * 256 / 100).to_s(16).upcase
|
234
|
+
colors = ["##{alpha_hex}CC0000", "##{alpha_hex}00CC00", "##{alpha_hex}0000CC", "##{alpha_hex}888800"]
|
235
|
+
|
236
|
+
xmax ||= data.map(&:to_a).flatten.compact.max
|
237
|
+
xmin ||= data.map(&:to_a).flatten.compact.min
|
238
|
+
freqs = data.map {|d| d.to_a.compact.histogram(bins, min: xmin, max: xmax) }
|
239
|
+
ymax ||= freqs.map{ _1[1] }.flatten.max * 1.1
|
240
|
+
|
133
241
|
if !file.nil?
|
134
242
|
set terminal: "gif"
|
135
243
|
set output: file
|
@@ -193,9 +301,6 @@ module Gnutemplate
|
|
193
301
|
end
|
194
302
|
|
195
303
|
plot *args
|
196
|
-
#plot [*freqs[0], using: 2, w: :histogram, t: labels[0], fillcolor: "rgb \"#{colors[0 % 4]}\""],
|
197
|
-
#[*freqs[1], using: 2, w: :histogram, t: labels[1], fillcolor: "rgb \"#{colors[1 % 4]}\""],
|
198
|
-
#[*freqs[2], using: 2, w: :histogram, t: labels[2], fillcolor: "rgb \"#{colors[2 % 4]}\""]
|
199
304
|
|
200
305
|
end # Of if pileup..else
|
201
306
|
end # Of Numo.noteplot do
|
@@ -206,7 +311,7 @@ module Gnutemplate
|
|
206
311
|
xmin: nil, xmax: nil, ymin: 0, ymax: nil, bins: 10,
|
207
312
|
figsize: 1.0, rotate_xtics: 45,
|
208
313
|
fill: true, alpha: 33, background: nil,
|
209
|
-
file: nil
|
314
|
+
file: nil)
|
210
315
|
|
211
316
|
data = [data] if data[0].kind_of?(Numeric) || data[0].nil?
|
212
317
|
|
@@ -282,10 +387,6 @@ module Gnutemplate
|
|
282
387
|
end
|
283
388
|
|
284
389
|
plot *args
|
285
|
-
,
|
286
|
-
#[*freqs[1], using: 2, w: :histogram, t: labels[1], fillcolor: "rgb \"#{colors[1 % 4]}\""],
|
287
|
-
#[*freqs[2], using: 2, w: :histogram, t: labels[2], fillcolor: "rgb \"#{colors[2 % 4]}\""]
|
288
|
-
#plot [*freqs[0], using: 2, w: :histogram, t: labels[0], fillcolor: "rgb \"#{colors[0 % 4]}\""]
|
289
390
|
|
290
391
|
end # Of if pileup..else
|
291
392
|
end # Of Numo.noteplot do
|
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.
|
4
|
+
version: 0.1.9
|
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-
|
11
|
+
date: 2023-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: numo-gnuplot
|