ruby-gr 0.0.18 → 0.0.19

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: 46a782911565b4128622399489e47d79e7ced0d3880d9c5c5adacdae7fa24709
4
- data.tar.gz: e89d9c7e5a5ae0bf53352f3afb71fd1206c9a0e7aa5a3ba83504457fa5689b7d
3
+ metadata.gz: 07da9fb7d76476cb7598eac022e5a1b5e4004af6e0bdd0e87d1acd817f36abc7
4
+ data.tar.gz: 87961c4df97b188a7c5fbd77a9e0ac993a6190ddc9e3fc2f9c30b2c7e88c19cb
5
5
  SHA512:
6
- metadata.gz: 21a8aeb6c49da80f87bb764ba149ffa8c7e7bffa3ed171002d1c6963537b9f0b500a96f77eac6876c8c3a8af9601aad6c8a79dfd4e0aea6d7d356adfc59b04db
7
- data.tar.gz: 99a2e4204e8eef936979895183d86003860e2b9b356a24bc0f132793177459fa8fc782cf8bdd4ac4c2a29fca6e77aff41d7501123e84917172009bc5b5907547
6
+ metadata.gz: bb5d8869e80d488a5b2076eb80125136f27f18b4e352066ba1c5260b343440b7474ace25d708464c827954c1f02f47c682e83eff0b3e0a47d0374b58bc74ad09
7
+ data.tar.gz: 677a4c8839974102a3d4ac618f41cd06b23e4c7d7d68f70110efb7f838c1689588fc00f8c462eabfe724c7fe7a639319bd83728d047901ddd9013bba3c3db029
data/README.md CHANGED
@@ -6,9 +6,21 @@
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
- <p align="center">
10
- <img src="https://user-images.githubusercontent.com/5798442/70857099-13d57600-1f2c-11ea-8f3c-7d81065f13a5.png">
11
- </p>
9
+ ![rdatasets-1](https://i.imgur.com/XEQ6wKs.png)
10
+ ![stem](https://i.imgur.com/3w0Ejrm.png)
11
+ ![histogram](https://i.imgur.com/xUdoA2s.png)
12
+ ![barplot](https://i.imgur.com/52bOFKE.png)
13
+ ![scatter3](https://i.imgur.com/yTTVetQ.png)
14
+ ![volume](https://i.imgur.com/CuRN6oC.png)
15
+ ![griddata](https://i.imgur.com/58HdYDo.png)
16
+ ![2darray](https://i.imgur.com/aKR2FJG.png)
17
+ ![2dpolararray](https://i.imgur.com/cmSrxvS.png)
18
+ ![hexbin](https://i.imgur.com/unWhQHr.png)
19
+ ![rdatasets-2](https://i.imgur.com/ZPit2F5.png)
20
+ ![rdatasets-3](https://i.imgur.com/TbNoxwy.png)
21
+ ![surface](https://i.imgur.com/sWdaHme.png)
22
+ ![face](https://i.imgur.com/uLCKi2r.png)
23
+ ![shade](https://i.imgur.com/VJmS3EQ.png)
12
24
 
13
25
  :bar_chart: [GR framework](https://github.com/sciapp/gr) - the graphics library for visualization - for Ruby
14
26
 
@@ -47,43 +59,101 @@ y = [0.3, 0.5, 0.4, 0.2, 0.6, 0.7]
47
59
  GR.plot(x, y)
48
60
  ```
49
61
 
50
- ## Examples
62
+ <p align="center">
63
+ <img src="https://user-images.githubusercontent.com/5798442/84570709-242ab880-adca-11ea-9099-3a6b3418bf19.png">
64
+ </p>
65
+
66
+ ```ruby
67
+ require 'gr/plot'
68
+
69
+ x = Numo::DFloat.linspace(0, 10, 101)
70
+ y1 = Numo::NMath.sin(x)
71
+ y2 = Numo::NMath.cos(x)
72
+
73
+ GR.plot(
74
+ [x, y1, 'bo'], [x, y2, 'g*'],
75
+ title: "Multiple plot example",
76
+ xlabel: "x",
77
+ ylabel: "y",
78
+ ylim: [-1.2, 1.2],
79
+ labels: ["sin(x)", "cos(x)"],
80
+ location: 11
81
+ )
82
+ ```
83
+
84
+ Save to PNG file.
51
85
 
52
- Have a look in the [`examples`](https://github.com/red-data-tools/GR.rb/tree/master/examples) directory.
53
- * [Example Gallery](https://github.com/red-data-tools/GR.rb/wiki/1.-Example-gallery)
86
+ ```ruby
87
+ GR.savefig("figure.png")
88
+ ```
54
89
 
55
90
  ## Features
56
91
 
57
- #### GR::Plot
92
+ There are two layers to the GR.rb API.
58
93
 
59
- A simple, matlab-style API.
94
+ #### GR::Plot - A simple, matlab-style API.
60
95
 
61
96
  ```ruby
62
97
  require 'gr/plot'
98
+ GR.plot(x, y)
63
99
  ```
64
100
 
65
- `plot` `step` `scatter` `stem` `histogram` `contour` `contourf` `hexbin` `heatmap` `wireframe` `surface` `plot3` `scatter3` `imshow` `isosurface` `polar` `polarhist` `polarheatmap` `trisurf` `tricont` `shade` `volume`
66
-
67
- #### GR
101
+ List of vailable functions. See [GR.rb Wiki](https://github.com/red-data-tools/GR.rb/wiki) for details.
102
+
103
+ [`plot`](../../wiki/Plotting-functions#plot)
104
+ [`step`](../../wiki/Plotting-functions#step)
105
+ [`plot3`](../../wiki/Plotting-functions#plot3)
106
+ [`polar`](../../wiki/Plotting-functions#polar)
107
+ [`scatter`](../../wiki/Plotting-functions#scatter)
108
+ [`scatter3`](../../wiki/Plotting-functions#scatter3)
109
+ [`stem`](../../wiki/Plotting-functions#stem)
110
+ [`barplot`](../../wiki/Plotting-functions#barplot)
111
+ [`histogram`](../../wiki/Plotting-functions#histogram)
112
+ [`polarhistogram`](../../wiki/Plotting-functions#polarhistogram)
113
+ [`hexbin`](../../wiki/Plotting-functions#hexbin)
114
+ [`contour`](../../wiki/Plotting-functions#contour)
115
+ [`contourf`](../../wiki/Plotting-functions#contourf)
116
+ [`tricont`](../../wiki/Plotting-functions#tricont)
117
+ [`surface`](../../wiki/Plotting-functions#surface)
118
+ [`trisurf`](../../wiki/Plotting-functions#trisurf)
119
+ [`wireframe`](../../wiki/Plotting-functions#wireframe)
120
+ [`volume`](../../wiki/Plotting-functions#volume)
121
+ [`heatmap`](../../wiki/Plotting-functions#heatmap)
122
+ [`polarheatmap`](../../wiki/Plotting-functions#polarheatmap)
123
+ [`shade`](../../wiki/Plotting-functions#shade)
124
+ [`imshow`](../../wiki/Plotting-functions#imshow)
125
+ [`isosurface`](../../wiki/Plotting-functions#isosurface)
126
+
127
+ #### GR - A module for calling native GR functions.
68
128
 
69
129
  ```ruby
70
130
  require 'gr'
131
+
132
+ # For example
133
+ GR.setviewport(0.1, 0.9, 0.1, 0.9)
134
+ GR.setwindow(0.0, 20.0, 0.0, 20.0)
71
135
  ```
72
136
 
73
- #### GR3
137
+ #### GR3 - A module for calling native GR3 functions.
74
138
 
75
139
  ```ruby
76
140
  require 'gr3'
141
+
142
+ # For example
143
+ GR3.cameralookat(-3, 2, -2, 0, 0, 0, 0, 0, -1)
77
144
  ```
78
145
 
146
+ * GR.rb can be used in Jupyter Notebook.
147
+
79
148
  ## Documentation
80
149
 
150
+ - [GR.rb Wiki](https://github.com/red-data-tools/GR.rb/wiki)
81
151
  - [GR Framework](https://gr-framework.org/)
82
152
  - [GR.rb API Documentation](https://rubydoc.info/gems/ruby-gr)
83
153
 
84
154
  ## GR Installation
85
155
 
86
- ### Official binary release
156
+ ### Installing an official release (recommended)
87
157
 
88
158
  Download the [latest release](https://github.com/sciapp/gr/releases).
89
159
 
@@ -95,7 +165,12 @@ export GRDIR="your/path/to/gr"
95
165
 
96
166
  * macOS Catalina and macOS Mojave: See the "How to open an app that hasn’t been notarized or is from an unidentified developer" section of [Safely open apps on your Mac](https://support.apple.com/en-us/HT202491) in the Apple documentation.
97
167
 
98
- ### Homebrew
168
+ ### Using your package manager
169
+
170
+ * The third party GR packages for Mac, Linux and Windows (for advanced users) are available.
171
+ * If you find problems, please report to the [issue](https://github.com/red-data-tools/GR.rb/issues).
172
+
173
+ #### Mac: Homebrew
99
174
 
100
175
  ```sh
101
176
  brew install libgr
@@ -107,11 +182,13 @@ Set environment variable GRDIR.
107
182
  export GRDIR=$(brew --prefix libgr)
108
183
  ```
109
184
 
110
- If you fail to build libgr using homebrew, Please feel free to [send us your feedback](https://github.com/red-data-tools/GR.rb/issues).
185
+ #### Linux: APT Yum
186
+
187
+ [packages.red-data-tools.org](https://github.com/red-data-tools/packages.red-data-tools.org) provides `libgr-dev` and `libgr3-dev`.
111
188
 
112
- ### Red data tools repository
189
+ #### Windows: MSYS2
113
190
 
114
- Red data tools provides [packages](https://github.com/red-data-tools/packages.red-data-tools.org ) related to our project including `libgr-dev` and `libgr3-dev` for advanced users.
191
+ If you are using Rubyinstaller, pacman will automatically install [mingw-w64-gr](https://packages.msys2.org/base/mingw-w64-gr) when the gem is installed.
115
192
 
116
193
  ## Backend for Charty
117
194
 
data/lib/gr.rb CHANGED
@@ -1595,10 +1595,10 @@ module GR
1595
1595
  super(npoints, x, y, ntri, triangles.ref)
1596
1596
  end
1597
1597
  if n_tri > 0
1598
- tri = triangles.to_str(3 * n_tri * Fiddle::SIZEOF_INT).unpack('l*') # Int32
1598
+ tri = triangles.to_str(dim * n_tri * Fiddle::SIZEOF_INT).unpack('l*') # Int32
1599
1599
  # Ruby : 0-based indexing
1600
1600
  # Julia : 1-based indexing
1601
- tri = tri.each_slice(3).to_a
1601
+ tri = tri.each_slice(dim).to_a
1602
1602
  [n_tri, tri]
1603
1603
  else
1604
1604
  0
@@ -37,11 +37,12 @@ module GR
37
37
  volume].freeze # the name might be changed in the future.
38
38
 
39
39
  # Keyword options conform to GR.jl.
40
- KW_ARGS = %i[accelerate algorithm alpha backgroundcolor barwidth baseline
41
- clabels color colormap figsize horizontal isovalue label labels
42
- levels location nbins rotation size tilt title where xflip
43
- xform xlabel xlim xlog yflip ylabel ylim ylog zflip zlabel zlim
44
- zlog clim subplot].freeze
40
+ KW_ARGS = %i[accelerate algorithm alpha ax backgroundcolor barwidth baseline
41
+ clabels clear clim color colormap crange figsize horizontal
42
+ isovalue kind label labels levels location nbins ratio rotation
43
+ scale size spec subplot tilt title update xaxis xflip xform
44
+ xlabel xlim xlog xrange yaxis yflip ylabel ylim ylog zflip
45
+ yrange viewport vp where window zaxis zlabel zlim zlog zrange].freeze
45
46
 
46
47
  @last_plot = nil
47
48
  class << self
@@ -181,12 +182,8 @@ module GR
181
182
  minmax
182
183
  end
183
184
 
184
- major_count = if %i[wireframe surface plot3 scatter3 polar polarhist
185
- polarheatmap trisurf volume].include?(kind)
186
- 2
187
- else
188
- 5
189
- end
185
+ major_count = %i[wireframe surface plot3 scatter3 polar polarhist
186
+ polarheatmap trisurf volume].include?(kind) ? 2 : 5
190
187
 
191
188
  xmin, xmax = kvs[:xrange]
192
189
  if (scale & GR::OPTION_X_LOG) == 0
@@ -272,7 +269,7 @@ module GR
272
269
  ratio = kvs[:ratio]
273
270
  xtick, xorg, majorx = kvs[:xaxis]
274
271
  ytick, yorg, majory = kvs[:yaxis]
275
- drawgrid = kvs[:grid] || true
272
+ drawgrid = kvs.has_key?(:grid) ? kvs[:grid] : true
276
273
  xtick = 10 if kvs[:scale] & GR::OPTION_X_LOG != 0
277
274
  ytick = 10 if kvs[:scale] & GR::OPTION_Y_LOG != 0
278
275
  GR.setlinecolorind(1)
@@ -293,8 +290,8 @@ module GR
293
290
  else
294
291
  if %i[heatmap nonuniformheatmap shade].include?(kind)
295
292
  ticksize = -ticksize
296
- else
297
- drawgrid && GR.grid(xtick, ytick, 0, 0, majorx, majory)
293
+ elsif drawgrid
294
+ GR.grid(xtick, ytick, 0, 0, majorx, majory)
298
295
  end
299
296
  if kvs.has_key?(:xticklabels) || kvs.has_key?(:yticklabels)
300
297
  fx = if kvs.has_key?(:xticklabels)
@@ -686,9 +683,10 @@ module GR
686
683
  cmap = colormap
687
684
  cmin, cmax = kvs[:zrange]
688
685
  data = z.map { |i| normalize_color(i, cmin, cmax) }
689
- colors = data.map { |i| 1000 + i * 255 }
690
- # if kvs[:xflip]
691
- # if kvs[;yflip]
686
+ data.reverse(axis: 0) if kvs[:xflip]
687
+ data.reverse(axis: 1) if kvs[:yflip]
688
+ colors = data * 255 + 1000
689
+ colors = colors.transpose # Julia is column major
692
690
  GR.polarcellarray(0, 0, 0, 360, 0, 1, w, h, colors)
693
691
  draw_polar_axes
694
692
  kvs[:zrange] = [cmin, cmax]
@@ -1281,9 +1279,8 @@ module GR
1281
1279
  def barplot(labels, heights, kv = {})
1282
1280
  labels = labels.map(&:to_s)
1283
1281
  wc, hc = barcoordinates(heights)
1284
- horizontal = kv[:horizontal] || false
1285
1282
  create_plot(:bar, labels, heights, kv) do |plt|
1286
- if horizontal
1283
+ if kv[:horizontal]
1287
1284
  plt.args = [[hc, wc, nil, nil, '']]
1288
1285
  plt.kvs[:yticks] = [1, 1]
1289
1286
  plt.kvs[:yticklabels] = labels
@@ -1342,6 +1339,7 @@ module GR
1342
1339
  end
1343
1340
  {
1344
1341
  subplot: [xmin, xmax, ymin, ymax],
1342
+ # The policy of clearing when p[0]==1 is controversial
1345
1343
  clear: p[0] == 1,
1346
1344
  update: p[-1] == nr * nc
1347
1345
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GRCommons
4
- VERSION = '0.0.18'
4
+ VERSION = '0.0.19'
5
5
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GRM
4
+ class Error < StandardError; end
5
+
6
+ class << self
7
+ attr_accessor :ffi_lib
8
+ end
9
+
10
+ # Platforms | path
11
+ # Windows | bin/libGRM.dll
12
+ # MacOSX | lib/libGRM.so (NOT .dylib)
13
+ # Ubuntu | lib/libGRM.so
14
+ if Object.const_defined?(:RubyInstaller)
15
+ ENV['GRDIR'] ||= [
16
+ RubyInstaller::Runtime.msys2_installation.msys_path,
17
+ RubyInstaller::Runtime.msys2_installation.mingwarch
18
+ ].join(File::ALT_SEPARATOR)
19
+ self.ffi_lib = File.expand_path('bin/libGRM.dll', ENV['GRDIR'])
20
+ RubyInstaller::Runtime.add_dll_directory(File.dirname(ffi_lib))
21
+ else
22
+ raise Error, 'Please set env variable GRDIR' unless ENV['GRDIR']
23
+
24
+ self.ffi_lib = File.expand_path('lib/libGRM.so', ENV['GRDIR'])
25
+ end
26
+
27
+ # change the default encoding to UTF-8.
28
+ ENV['GKS_ENCODING'] ||= 'utf8'
29
+
30
+ require_relative 'gr_commons/gr_commons'
31
+ require_relative 'grm/version'
32
+ require_relative 'grm/ffi'
33
+ require_relative 'grm/grmbase'
34
+
35
+ # `inquiry` methods etc. are defined here.
36
+ extend GRCommons::GRCommonUtils
37
+
38
+ # `XXX` is the default type in GR.
39
+ # A Ruby array or NArray passed to GR method is automatically converted to
40
+ # a Fiddley::MemoryPointer in the GRBase class.
41
+ extend GRMBase
42
+
43
+ class << self
44
+ end
45
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fiddle/import'
4
+
5
+ module GRM
6
+ # FFI Wrapper module for GRM.
7
+ # The functions for GRM are listed here.
8
+ # Add functions here when a new version of GR is released.
9
+ module FFI
10
+ extend Fiddle::Importer
11
+
12
+ begin
13
+ dlload GRM.ffi_lib
14
+ rescue LoadError
15
+ raise LoadError, 'Could not find GR Framework'
16
+ end
17
+
18
+ extend GRCommons::Extern
19
+
20
+ # Currently, the declarations of GRM functions are distributed in several
21
+ # header files.
22
+
23
+ # https://github.com/sciapp/gr/blob/master/lib/grm/args.h
24
+
25
+ try_extern 'grm_args_t *grm_args_new(void)'
26
+ try_extern 'void grm_args_delete(grm_args_t *args)'
27
+ # Fiddle does not currently support variable-length arguments in C.
28
+ try_extern 'int grm_args_push(grm_args_t *args, const char *key, const char *value_format, ...)'
29
+ try_extern 'int grm_args_push_buf(grm_args_t *args, const char *key, const char *value_format, const void *buffer, int apply_padding)'
30
+ try_extern 'int grm_args_contains(const grm_args_t *args, const char *keyword)'
31
+ try_extern 'void grm_args_clear(grm_args_t *args)'
32
+ try_extern 'void grm_args_remove(grm_args_t *args, const char *key)'
33
+
34
+ # https://github.com/sciapp/gr/blob/master/lib/grm/dump.h
35
+ try_extern 'void grm_dump(const grm_args_t *args, FILE *f)'
36
+ try_extern 'void grm_dump_json(const grm_args_t *args, FILE *f)'
37
+ try_extern 'char *grm_dump_json_str(void)'
38
+
39
+ # https://github.com/sciapp/gr/blob/master/lib/grm/event.h
40
+ # grm_event_type_t is an enum.
41
+ # In the original fiddley, there is code for an enum.
42
+ # But GR's fiddley doesn't have it.
43
+ # try_extern 'int grm_register(grm_event_type_t type, grm_event_callback_t callback)'
44
+ # try_extern 'int grm_unregister(grm_event_type_t type)'
45
+
46
+ # https://github.com/sciapp/gr/blob/master/lib/grm/interaction.h
47
+ try_extern 'int grm_input(const grm_args_t *input_args)'
48
+ # try_extern 'int grm_get_box(const int x1, const int y1, const int x2, const int y2, const int keep_aspect_ratio, int *x, int *y, int *w, int *h)'
49
+ # try_extern 'grm_tooltip_info_t *grm_get_tooltip(const int, const int)'
50
+
51
+ # https://github.com/sciapp/gr/blob/master/lib/grm/net.h
52
+ # try_extern 'void *grm_open(int is_receiver, const char *name, unsigned int id,
53
+ # const char *(*custom_recv)(const char *, unsigned int),
54
+ # int (*custom_send)(const char *, unsigned int, const char *))
55
+ try_extern 'grm_args_t *grm_recv(const void *p, grm_args_t *args)'
56
+ # Fiddle does not currently support variable-length arguments in C.
57
+ try_extern 'int grm_send(const void *p, const char *data_desc, ...)'
58
+ try_extern 'int grm_send_buf(const void *p, const char *data_desc, const void *buffer, int apply_padding)'
59
+ try_extern 'int grm_send_ref(const void *p, const char *key, char format, const void *ref, int len)'
60
+ try_extern 'int grm_send_args(const void *p, const grm_args_t *args)'
61
+ try_extern 'void grm_close(const void *p)'
62
+ end
63
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GRM
4
+ # This module automatically converts Ruby arrays and Numo::Narray into
5
+ # Fiddley::MemoryPointer.
6
+ module GRMBase
7
+ extend GRCommons::DefineMethods
8
+ define_ffi_methods(FFI,
9
+ prefix: 'grm_',
10
+ default_type: :float) # FIXME!
11
+ end
12
+ private_constant :GRMBase
13
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GRM
4
+ VERSION = GRCommons::VERSION
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.18
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-08 00:00:00.000000000 Z
11
+ date: 2020-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -147,6 +147,10 @@ files:
147
147
  - lib/gr_commons/gr_commons.rb
148
148
  - lib/gr_commons/jupyter_support.rb
149
149
  - lib/gr_commons/version.rb
150
+ - lib/grm.rb
151
+ - lib/grm/ffi.rb
152
+ - lib/grm/grmbase.rb
153
+ - lib/grm/version.rb
150
154
  homepage: https://github.com/red-data-tools/GR.rb
151
155
  licenses:
152
156
  - MIT