ruby-gr 0.0.7 → 0.0.8
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 +2 -4
- data/lib/gr.rb +1 -1
- data/lib/gr/plot.rb +30 -4
- data/lib/gr_commons/gr_common_utils.rb +23 -3
- data/lib/gr_commons/jupyter_support.rb +10 -8
- data/lib/gr_commons/version.rb +1 -1
- 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: 898535fe254b0d6a4a457f6583e6d969cf10598f040bc64464f4e5458a151e57
|
4
|
+
data.tar.gz: a8d0a53dee6d84f52f73c9e014a38ce9def381492abf55b88867a6fe1e6c639f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f66234f7d19386f36d3106ec6f7e6e529ca5b0f85f6ea1e0bbd13686b3d5d41d2073f3530436dde1a89d1d0c11cfb6fa5f30839d0022e6e67670f33ea91a8aa4
|
7
|
+
data.tar.gz: 36ca2dca1f723a51d066d063b12601574cf2fb643d4a2221a481642d20f8097982e0fc9500488a2e79b09a01aa8169de7b32237dee75ece63aef39000be5f7a3
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# GR
|
1
|
+
# GR.rb
|
2
2
|
|
3
3
|
[](LICENSE.txt)
|
4
4
|
[](https://travis-ci.org/red-data-tools/GR.rb)
|
@@ -6,9 +6,7 @@
|
|
6
6
|
[](https://gitter.im/red-data-tools/en)
|
7
7
|
[](https://rubydoc.info/gems/ruby-gr)
|
8
8
|
|
9
|
-
[GR framework](https://github.com/sciapp/gr) - the graphics library for visualisation - for Ruby
|
10
|
-
|
11
|
-
:construction: Under construction.
|
9
|
+
:bar_chart: [GR framework](https://github.com/sciapp/gr) - the graphics library for visualisation - for Ruby
|
12
10
|
|
13
11
|
## Installation
|
14
12
|
Install [GR](https://github.com/sciapp/gr/releases).
|
data/lib/gr.rb
CHANGED
data/lib/gr/plot.rb
CHANGED
@@ -40,6 +40,11 @@ module GR
|
|
40
40
|
xlog yflip ylabel ylim ylog zflip zlabel zlim zlog clim
|
41
41
|
subplot].freeze
|
42
42
|
|
43
|
+
@@last_plot
|
44
|
+
def self.last_plot
|
45
|
+
@@last_plot
|
46
|
+
end
|
47
|
+
|
43
48
|
def initialize(*args)
|
44
49
|
@kvs = if args[-1].is_a? Hash
|
45
50
|
args.pop
|
@@ -55,6 +60,7 @@ module GR
|
|
55
60
|
@scheme = 0
|
56
61
|
@background = 0xffffff
|
57
62
|
@handle = nil
|
63
|
+
@@last_plot = self
|
58
64
|
end
|
59
65
|
attr_accessor :args, :kvs, :scheme
|
60
66
|
|
@@ -893,6 +899,11 @@ module GR
|
|
893
899
|
end
|
894
900
|
end
|
895
901
|
|
902
|
+
def to_svg
|
903
|
+
## Need IRuby improvemend.
|
904
|
+
GR.show(false) if ENV['GKSwstype'] == 'svg'
|
905
|
+
end
|
906
|
+
|
896
907
|
private
|
897
908
|
|
898
909
|
def hasline(mask)
|
@@ -1165,7 +1176,8 @@ module GR
|
|
1165
1176
|
|
1166
1177
|
alias _tricontour_ tricontour
|
1167
1178
|
def tricontour(*args)
|
1168
|
-
|
1179
|
+
x, y, z, kv = parse_args(*args)
|
1180
|
+
create_plot(:tricont, x, y, z, kv)
|
1169
1181
|
end
|
1170
1182
|
|
1171
1183
|
alias _surface_ surface
|
@@ -1180,11 +1192,13 @@ module GR
|
|
1180
1192
|
|
1181
1193
|
alias _trisurface_ trisurface
|
1182
1194
|
def trisurface(*args)
|
1183
|
-
|
1195
|
+
x, y, z, kv = parse_args(*args)
|
1196
|
+
create_plot(:trisurf, x, y, z, kv)
|
1184
1197
|
end
|
1185
1198
|
|
1186
1199
|
def wireframe(*args)
|
1187
|
-
|
1200
|
+
x, y, z, kv = parse_args(*args)
|
1201
|
+
create_plot(:wireframe, x, y, z, kv)
|
1188
1202
|
end
|
1189
1203
|
|
1190
1204
|
def plot3(*args)
|
@@ -1233,6 +1247,12 @@ module GR
|
|
1233
1247
|
end
|
1234
1248
|
end
|
1235
1249
|
|
1250
|
+
def savefig(filename)
|
1251
|
+
GR.beginprint(filename)
|
1252
|
+
GR::Plot.last_plot.plot_data(false)
|
1253
|
+
GR.endprint
|
1254
|
+
end
|
1255
|
+
|
1236
1256
|
private
|
1237
1257
|
|
1238
1258
|
def create_plot(type, *args, &block)
|
@@ -1240,6 +1260,7 @@ module GR
|
|
1240
1260
|
plt.kvs[:kind] = type
|
1241
1261
|
block.call(plt) if block_given?
|
1242
1262
|
plt.plot_data
|
1263
|
+
plt
|
1243
1264
|
end
|
1244
1265
|
|
1245
1266
|
def parse_args(*args)
|
@@ -1272,7 +1293,12 @@ module GR
|
|
1272
1293
|
|
1273
1294
|
def hist(x, nbins = 0)
|
1274
1295
|
nbins = (3.3 * Math.log10(x.length)).round + 1 if nbins <= 1
|
1275
|
-
|
1296
|
+
begin
|
1297
|
+
require 'histogram/array'
|
1298
|
+
rescue LoadError => e
|
1299
|
+
e.message << " Please add gem 'histogram' to your project's Gemfile."
|
1300
|
+
raise e
|
1301
|
+
end
|
1276
1302
|
x = x.to_a if narray?(x)
|
1277
1303
|
x, y = x.histogram(nbins, bin_boundary: :min)
|
1278
1304
|
x.push(x[-1] + x[1] - x[0])
|
@@ -22,9 +22,29 @@ module GRCommons
|
|
22
22
|
# NOTE: The following method converts Ruby Array or NArray into packed string.
|
23
23
|
SUPPORTED_TYPES.each do |type|
|
24
24
|
define_method(type) do |data|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
case data
|
26
|
+
when Array
|
27
|
+
data = data.flatten
|
28
|
+
Fiddley::Utils.array2str(type, data)
|
29
|
+
when ->(x) { narray?(x) }
|
30
|
+
case type
|
31
|
+
when :uint8
|
32
|
+
Numo::UInt8.cast(data).to_binary
|
33
|
+
when :uint16
|
34
|
+
Numo::UInt16.cast(data).to_binary
|
35
|
+
when :int
|
36
|
+
Numo::Int32.cast(data).to_binary
|
37
|
+
when :uint
|
38
|
+
Numo::UInt32.cast(data).to_binary
|
39
|
+
when :double
|
40
|
+
Numo::DFloat.cast(data).to_binary
|
41
|
+
when :float
|
42
|
+
Numo::SFloat.cast(data).to_binary
|
43
|
+
end
|
44
|
+
else
|
45
|
+
data = data.to_a.flatten
|
46
|
+
Fiddley::Utils.array2str(type, data)
|
47
|
+
end
|
28
48
|
end
|
29
49
|
end
|
30
50
|
|
@@ -13,24 +13,26 @@ module GRCommons
|
|
13
13
|
end
|
14
14
|
|
15
15
|
# Display your plot in Jupyter Notebook / Lab
|
16
|
-
def show
|
16
|
+
def show(display = true)
|
17
17
|
emergencyclosegks
|
18
18
|
sleep 0.5
|
19
19
|
type = ENV['GKSwstype']
|
20
20
|
case type
|
21
21
|
when 'svg'
|
22
22
|
data = File.read(ENV['GKS_FILEPATH'] + '.svg')
|
23
|
-
IRuby.display(data, mime: 'image/svg+xml')
|
23
|
+
IRuby.display(data, mime: 'image/svg+xml') if display
|
24
24
|
when 'webm', 'ogg', 'mp4', 'mov'
|
25
25
|
require 'base64'
|
26
26
|
data = File.binread(ENV['GKS_FILEPATH'] + '.' + type)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
if display
|
28
|
+
IRuby.display(
|
29
|
+
"<video controls autoplay type=\"video/#{type}\" " \
|
30
|
+
"src=\"data:video/#{type};base64,#{Base64.encode64(data)}\">",
|
31
|
+
mime: 'text/html'
|
32
|
+
)
|
33
|
+
end
|
32
34
|
end
|
33
|
-
|
35
|
+
data unless display
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
data/lib/gr_commons/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-gr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kojix2
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|