ruby-gr 0.0.7 → 0.0.8

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: 55e5471b8532f7e180f80572158336cecc130575626a2b3361bd7ce6b0454bef
4
- data.tar.gz: d7387d744d28cb389a44769df8b9d477adc2a1320f73f8d02c55ffc17d1b1a02
3
+ metadata.gz: 898535fe254b0d6a4a457f6583e6d969cf10598f040bc64464f4e5458a151e57
4
+ data.tar.gz: a8d0a53dee6d84f52f73c9e014a38ce9def381492abf55b88867a6fe1e6c639f
5
5
  SHA512:
6
- metadata.gz: 1d13f13cb5e85843ab006b0ea1ce8a6d400edceb0b5f69ac8bf86eb5a756ce8c2dfed5ebbf7c0ecddc07ef48fba948528c53df77bf6899664098f76c8fbdb282
7
- data.tar.gz: 7f1d0091163902cb52acd7f3e0fab91cc15e178a0c39be8476e05397a8f9b6de9aad25211f4e9cb2e04ee199ebf51a6a78d8d3afbc89781743c616c74fa6a8fb
6
+ metadata.gz: f66234f7d19386f36d3106ec6f7e6e529ca5b0f85f6ea1e0bbd13686b3d5d41d2073f3530436dde1a89d1d0c11cfb6fa5f30839d0022e6e67670f33ea91a8aa4
7
+ data.tar.gz: 36ca2dca1f723a51d066d063b12601574cf2fb643d4a2221a481642d20f8097982e0fc9500488a2e79b09a01aa8169de7b32237dee75ece63aef39000be5f7a3
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # GR module for Ruby
1
+ # GR.rb
2
2
 
3
3
  [![The MIT License](https://img.shields.io/badge/license-MIT-orange.svg)](LICENSE.txt)
4
4
  [![Build Status](https://travis-ci.org/red-data-tools/GR.rb.svg?branch=master)](https://travis-ci.org/red-data-tools/GR.rb)
@@ -6,9 +6,7 @@
6
6
  [![Gitter Chat](https://badges.gitter.im/red-data-tools/en.svg)](https://gitter.im/red-data-tools/en)
7
7
  [![Docs Latest](https://img.shields.io/badge/docs-latest-blue.svg)](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
@@ -1402,7 +1402,7 @@ module GR
1402
1402
  # data is a pointer of a pointer
1403
1403
  super(path, width, height, data.ref)
1404
1404
  end
1405
- d = data.to_str(w * h * 8).unpack('L*') # UINT8
1405
+ d = data.to_str(w * h * 4).unpack('L*') # UINT8
1406
1406
  [w, h, d]
1407
1407
  end
1408
1408
 
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
- create_plot(:tricont, *args)
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
- create_plot(:trisurf, *args)
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
- create_plot(:wireframe, *args)
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
- require 'histogram/array' # dependency
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
- # FIXME: Use NArray#to_string
26
- data = data.to_a.flatten
27
- Fiddley::Utils.array2str(type, data)
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
- IRuby.display(
28
- "<video controls autoplay type=\"video/#{type}\" " \
29
- "src=\"data:video/#{type};base64,#{Base64.encode64(data)}\">",
30
- mime: 'text/html'
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
- nil
35
+ data unless display
34
36
  end
35
37
  end
36
38
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GRCommons
4
- VERSION = '0.0.7'
4
+ VERSION = '0.0.8'
5
5
  end
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.7
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-07 00:00:00.000000000 Z
11
+ date: 2019-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler