ruby-gr 0.0.13 → 0.0.18

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: 0b2f6f44a5b2198487a5b2735ab2dcd33f1b7ce0176a2763ee50a2866273021a
4
- data.tar.gz: 0073dd18c710ad1107e73b5a365f55f03f746398f33a0cd59211194d940ddee2
3
+ metadata.gz: 46a782911565b4128622399489e47d79e7ced0d3880d9c5c5adacdae7fa24709
4
+ data.tar.gz: e89d9c7e5a5ae0bf53352f3afb71fd1206c9a0e7aa5a3ba83504457fa5689b7d
5
5
  SHA512:
6
- metadata.gz: 205f75736354151eda828e200ff746e8bd69a8825476f9e7da02aafef6baf360904a8097edf27b12579b4e956821e142b83da9603d3d150b5b32b5f3e08e4214
7
- data.tar.gz: c7ddc7fd1949b22008f030ace9d3299ce38d6fa80553a27b5c3a3b74441d3376d1a15abc21b9753c5f38296f71981cd019373a2ab09fce5ab43eb413cb58107a
6
+ metadata.gz: 21a8aeb6c49da80f87bb764ba149ffa8c7e7bffa3ed171002d1c6963537b9f0b500a96f77eac6876c8c3a8af9601aad6c8a79dfd4e0aea6d7d356adfc59b04db
7
+ data.tar.gz: 99a2e4204e8eef936979895183d86003860e2b9b356a24bc0f132793177459fa8fc782cf8bdd4ac4c2a29fca6e77aff41d7501123e84917172009bc5b5907547
@@ -20,3 +20,27 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
20
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
21
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
22
  THE SOFTWARE.
23
+
24
+ The Fiddley module is:
25
+
26
+ Copyright (c) 2017 NAKAMURA Usaku usa@garbagecollect.jp
27
+
28
+ Redistribution and use in source and binary forms, with or without
29
+ modification, are permitted provided that the following conditions are met:
30
+
31
+ 1. Redistributions of source code must retain the above copyright notice, this
32
+ list of conditions and the following disclaimer.
33
+ 2. Redistributions in binary form must reproduce the above copyright notice,
34
+ this list of conditions and the following disclaimer in the documentation
35
+ and/or other materials provided with the distribution.
36
+
37
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
38
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
39
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
41
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
42
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
45
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
46
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md CHANGED
@@ -50,9 +50,51 @@ GR.plot(x, y)
50
50
  ## Examples
51
51
 
52
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)
54
+
55
+ ## Features
56
+
57
+ #### GR::Plot
58
+
59
+ A simple, matlab-style API.
60
+
61
+ ```ruby
62
+ require 'gr/plot'
63
+ ```
64
+
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
68
+
69
+ ```ruby
70
+ require 'gr'
71
+ ```
72
+
73
+ #### GR3
74
+
75
+ ```ruby
76
+ require 'gr3'
77
+ ```
78
+
79
+ ## Documentation
80
+
81
+ - [GR Framework](https://gr-framework.org/)
82
+ - [GR.rb API Documentation](https://rubydoc.info/gems/ruby-gr)
53
83
 
54
84
  ## GR Installation
55
85
 
86
+ ### Official binary release
87
+
88
+ Download the [latest release](https://github.com/sciapp/gr/releases).
89
+
90
+ Set environment variable GRDIR.
91
+
92
+ ```sh
93
+ export GRDIR="your/path/to/gr"
94
+ ```
95
+
96
+ * 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
+
56
98
  ### Homebrew
57
99
 
58
100
  ```sh
@@ -65,16 +107,25 @@ Set environment variable GRDIR.
65
107
  export GRDIR=$(brew --prefix libgr)
66
108
  ```
67
109
 
68
- ### Mac Linux Windows
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).
69
111
 
70
- Download the [latest release](https://github.com/sciapp/gr/releases).
112
+ ### Red data tools repository
71
113
 
72
- Set environment variable GRDIR.
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.
73
115
 
74
- ```sh
75
- export GRDIR="your/path/to/gr"
76
- ```
116
+ ## Backend for Charty
117
+
118
+ GR.rb will be the default backend for [Charty](https://github.com/red-data-tools/charty).
77
119
 
78
120
  ## Contributing
79
121
 
80
- Bug reports and pull requests are welcome on GitHub at https://github.com/red-data-tools/GR.rb.
122
+ * Report bugs
123
+ * Fix bugs and submit pull requests
124
+ * Write, clarify, or fix documentation
125
+ * Suggest or add new features
126
+ * Create visualization library based on GR.rb
127
+
128
+ ## Acknowledgements
129
+
130
+ We would like to thank Josef Heinen, the creator of [GR.jl](https://github.com/jheinen/GR.jl), Florian Rhiem, the creator of [python-gr](https://github.com/sciapp/python-gr), and [GR](https://github.com/sciapp/gr) developers.
131
+
data/lib/gr.rb CHANGED
@@ -2,41 +2,47 @@
2
2
 
3
3
  # OverView of GR.rb
4
4
  #
5
- # +--------------------+
6
- # +-------------------+ | GR3 module |
7
- # | GR module | | +----------------+ |
8
- # | +---------------+ | | | GR3::FFI | |
9
- # | | GR::FFI | | | | + libGR3.so | |
10
- # | | + libGR.so | | | +----------------+ |
11
- # | +---------------+ | | | define_method |
12
- # | | define_method | | +----------------+ |
13
- # | +---------------+ | | | | GR3::GR3Base | |
14
- # | | | GR::GRBase | | | | v (Private) | |
15
- # | | v (Private) | | | +++--------------+ |
16
- # | +++-------------+ | | | Extend |
17
- # | | Extend | | v +------+ |
18
- # | v | | |Check | |
19
- # | | | <--+Error | |
20
- # +-------+-----------+ | +------+ |
21
- # ^ +---------+----------+
22
- # | +------------------+ ^
23
- # Extend | | GRCommons module | | Extend
24
- # | | +--------------+ | |
25
- # | | | Fiddley | | |
26
- # | | +--------------+ | |
27
- # | | +--------------+ | |
28
- # +----+ CommonUtils +----+
29
- # | | +--------------+ | |
30
- # | | +--------------+ | |
31
- # +----+ Version +----+
32
- # | | +--------------+ |
33
- # | | +--------------+ |
34
- # +----+JupyterSupport| |
35
- # | +--------------+ |
36
- # +------------------+
5
+ # +--------------------+ +--------------------+
6
+ # | GR module | | GR3 module |
7
+ # | +----------------+ | | +----------------+ |
8
+ # | | GR::FFI | | | | GR3::FFI | |
9
+ # | | + libGR.so | | | | + libGR3.so | |
10
+ # | +----------------+ | | +----------------+ |
11
+ # | | define_method | | | define_method |
12
+ # | +----------------+ | | +----------------+ |
13
+ # | | | GR::GRBase | | | | | GR3::GR3Base | |
14
+ # | | v (Pri^ate) | | | | v (Pri^ate) | |
15
+ # | +++--------------+ | | +++--------------+ |
16
+ # | | Extend | | | Extend |
17
+ # | v | | v +-------+ |
18
+ # | +-----------+ | | | Check | |
19
+ # | | GR::Plot | | | <--+ Error | |
20
+ # | +-----------+ | | +-------+ |
21
+ # +--------------------+ +----------+---------+
22
+ # ^ ^
23
+ # | +------------------+ |
24
+ # Extend | | GRCommons module | | Extend
25
+ # | | +--------------+ | |
26
+ # | | | Fiddley | | |
27
+ # | | +--------------+ | |
28
+ # | | +--------------+ | |
29
+ # +----+ CommonUtils +----+
30
+ # | | +--------------+ | |
31
+ # | | +--------------+ | |
32
+ # +----+ Version +----+
33
+ # | | +--------------+ |
34
+ # | | +--------------+ |
35
+ # +----+JupyterSupport| |
36
+ # | +--------------+ |
37
+ # +------------------+
38
+ #
39
+ # (You can edit the above AA diagram with http://asciiflow.com/))
40
+ #
41
+ # Fiddley is Ruby-FFI compatible API layer for Fiddle.
37
42
  #
38
43
  # The GR module works without Numo::Narrray.
39
-
44
+ # GR3 and GR::Plot depends on numo-narray.
45
+ #
40
46
  # This is a procedural interface to the GR plotting library,
41
47
  # https://github.com/sciapp/gr
42
48
  module GR
@@ -46,20 +52,24 @@ module GR
46
52
  attr_accessor :ffi_lib
47
53
  end
48
54
 
49
- raise Error, 'Please set env variable GRDIR' unless ENV['GRDIR']
50
-
51
55
  # Platforms | path
52
56
  # Windows | bin/libgr.dll
53
57
  # MacOSX | lib/libGR.so (NOT .dylib)
54
58
  # Ubuntu | lib/libGR.so
55
59
  if Object.const_defined?(:RubyInstaller)
60
+ ENV['GRDIR'] ||= [
61
+ RubyInstaller::Runtime.msys2_installation.msys_path,
62
+ RubyInstaller::Runtime.msys2_installation.mingwarch
63
+ ].join(File::ALT_SEPARATOR)
56
64
  self.ffi_lib = File.expand_path('bin/libgr.dll', ENV['GRDIR'])
57
65
  RubyInstaller::Runtime.add_dll_directory(File.dirname(ffi_lib))
58
66
  else
67
+ raise Error, 'Please set env variable GRDIR' unless ENV['GRDIR']
68
+
59
69
  self.ffi_lib = File.expand_path('lib/libGR.so', ENV['GRDIR'])
60
70
  end
61
71
 
62
- # Change the default encoding to UTF-8
72
+ # Change the default encoding to UTF-8.
63
73
  ENV['GKS_ENCODING'] ||= 'utf8'
64
74
 
65
75
  require_relative 'gr_commons/gr_commons'
@@ -67,16 +77,19 @@ module GR
67
77
  require_relative 'gr/ffi'
68
78
  require_relative 'gr/grbase'
69
79
 
80
+ # `inquiry` methods etc. are defined here.
81
+ extend GRCommons::GRCommonUtils
82
+
83
+ # Support for Jupyter Notebook / Lab.
70
84
  extend GRCommons::JupyterSupport
71
85
 
72
- # `double` is the default type in GR
86
+ # `double` is the default type in GR.
73
87
  # A Ruby array or NArray passed to GR method is automatically converted to
74
- # a FFI::MemoryPointer in the GRBase class.
88
+ # a Fiddley::MemoryPointer in the GRBase class.
75
89
  extend GRBase
76
90
 
77
91
  # Now you can see a lot of methods just calling super here.
78
- # Why? Do they really need?
79
- # Yes. They are written to help the yard generate the documentation.
92
+ # They are written to help the yard generate the documentation.
80
93
  class << self
81
94
  def initgr(*)
82
95
  super
@@ -230,6 +243,9 @@ module GR
230
243
  # @param dimx [Integer] X dimension of the color index array
231
244
  # @param dimy [Integer] Y dimension of the color index array
232
245
  # @param color [Array, NArray] Color index array
246
+ # The values for `x` and `y` are in world coordinates. `x` must contain
247
+ # `dimx` + 1 elements and `y` must contain `dimy` + 1 elements. The elements
248
+ # i and i+1 are respectively the edges of the i-th cell in X and Y direction.
233
249
  def nonuniformcellarray(x, y, dimx, dimy, color)
234
250
  raise ArgumentError unless x.length == dimx + 1 && y.length == dimy + 1
235
251
 
@@ -529,6 +545,13 @@ module GR
529
545
  super
530
546
  end
531
547
 
548
+ # Gets the current text color index.
549
+ # This function gets the color of text output primitives.
550
+ # @return [Integer] color The text color index (COLOR < 1256)
551
+ def inqtextcolorind
552
+ inquiry_int { |pt| super(pt) }
553
+ end
554
+
532
555
  # Set the current character height.
533
556
  # @param height [Numeric] Text height value
534
557
  # `setcharheight` defines the height of subsequent text output primitives. Text height
@@ -1399,12 +1422,14 @@ module GR
1399
1422
 
1400
1423
  # @return [Integer]
1401
1424
  def readimage(path)
1425
+ # Feel free to make a pull request if you catch a mistake
1426
+ # or you have an idea to improve it.
1402
1427
  data = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INTPTR_T)
1403
1428
  w, h = inquiry [:int, :int] do |width, height|
1404
1429
  # data is a pointer of a pointer
1405
1430
  super(path, width, height, data.ref)
1406
1431
  end
1407
- d = data.to_str(w * h * 4).unpack('L*') # UINT8
1432
+ d = data.to_str(w * h * Fiddle::SIZEOF_INT).unpack('L*') # UInt32
1408
1433
  [w, h, d]
1409
1434
  end
1410
1435
 
@@ -1560,6 +1585,26 @@ module GR
1560
1585
  super
1561
1586
  end
1562
1587
 
1588
+ def delaunay(x, y)
1589
+ # Feel free to make a pull request if you catch a mistake
1590
+ # or you have an idea to improve it.
1591
+ npoints = equal_length(x, y)
1592
+ triangles = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INTPTR_T)
1593
+ dim = 3
1594
+ n_tri = inquiry_int do |ntri|
1595
+ super(npoints, x, y, ntri, triangles.ref)
1596
+ end
1597
+ if n_tri > 0
1598
+ tri = triangles.to_str(3 * n_tri * Fiddle::SIZEOF_INT).unpack('l*') # Int32
1599
+ # Ruby : 0-based indexing
1600
+ # Julia : 1-based indexing
1601
+ tri = tri.each_slice(3).to_a
1602
+ [n_tri, tri]
1603
+ else
1604
+ 0
1605
+ end
1606
+ end
1607
+
1563
1608
  # Reduces the number of points of the x and y array.
1564
1609
  def reducepoints(xd, yd, n)
1565
1610
  nd = equal_length(xd, yd)
@@ -1760,31 +1805,32 @@ module GR
1760
1805
  end
1761
1806
  end
1762
1807
 
1763
- # Draw paths using given vertices and path codes.
1808
+ # Draw paths using the given vertices and path codes.
1764
1809
  # @param x [Array, NArray] A list containing the X coordinates
1765
1810
  # @param y [Array, NArray] A list containing the Y coordinates
1766
- # @param codes [String] Path codes
1811
+ # @param codes [String] A list containing the path codes
1767
1812
  # The following path codes are recognized:
1768
1813
  # * M, m
1769
- # * moveto x, y
1814
+ # * moveto x, y
1770
1815
  # * L, l
1771
- # * lineto x, y
1816
+ # * lineto x, y
1772
1817
  # * Q, q
1773
- # * quadratic Bézier x1, y1 x2, y2
1818
+ # * quadratic Bézier x1, x2 y1, y2
1774
1819
  # * C, c
1775
- # * cubic Bézier x1, y1 x2, y2 x3, y3
1776
- # * R, r
1777
- # * rectangle w, h
1820
+ # * cubic Bézier x1, x2, x3 y1, y2, y3
1778
1821
  # * A, a
1779
- # * arc w, h a1, a2
1822
+ # * arc rx, a1, reserved ry, a2, reserved
1780
1823
  # * Z
1781
- # * closepath -
1824
+ # * close path -
1825
+ # * s
1826
+ # * stroke -
1782
1827
  # * s
1783
- # * stroke -
1828
+ # * close path and stroke -
1784
1829
  # * f
1785
- # * fill -
1786
- # The values for `x` and `y` are in normalized device coordinates.
1787
- # The `codes` describe several patch primitives that can be used to create compound paths.
1830
+ # * close path and fill -
1831
+ # * F
1832
+ # * close path, fill and stroke -
1833
+ # See https://gr-framework.org/python-gr.html#gr.path for more details.
1788
1834
  def path(x, y, codes)
1789
1835
  n = equal_length(x, y)
1790
1836
  super(n, x, y, codes)
@@ -1850,7 +1896,7 @@ module GR
1850
1896
  end
1851
1897
  end
1852
1898
 
1853
- # Set the far and near clipping plane for perspective projection and the
1899
+ # Set the far and near clipping plane for perspective projection and the
1854
1900
  # vertical field ov view.
1855
1901
  # Switches projection type to perspective.
1856
1902
  # @param near_plane [Numeric] distance to near clipping plane
@@ -1886,7 +1932,7 @@ module GR
1886
1932
  end
1887
1933
  end
1888
1934
 
1889
- # Interface for interaction with the rotation of the model.
1935
+ # Interface for interaction with the rotation of the model.
1890
1936
  # For this a virtual Arcball is used.
1891
1937
  # @param start_mouse_pos_x [Numeric] x component of the start mouse position
1892
1938
  # @param start_mouse_pos_y [Numeric] y component of the start mouse position
@@ -1913,6 +1959,58 @@ module GR
1913
1959
  super(*pts)
1914
1960
  end
1915
1961
  end
1962
+
1963
+ # Set the scale factor for each axis. A one means no scale.
1964
+ # All factor have to be != 0.
1965
+ # @param x_axis_scale [Numeric] factor for scaling the x-axis
1966
+ # @param y_axis_scale [Numeric] factor for scaling the y-axis
1967
+ # @param z_axis_scale [Numeric] factor for scaling the z-axis
1968
+ def setscalefactors3d(*)
1969
+ super
1970
+ end
1971
+
1972
+ # Returns the scale factors for each axis.
1973
+ def inqscalefactors3d
1974
+ inquiry %i[double double double] do |*opts|
1975
+ super(*opts)
1976
+ end
1977
+ end
1978
+
1979
+ # Set the camera for orthographic or perspective projection.
1980
+ # The center of the 3d window is used as the focus point and the camera is
1981
+ # positioned relative to it, using camera distance, rotation and tilt similar
1982
+ # to gr_setspace. This function can be used if the user prefers spherical
1983
+ # coordinates to setting the camera position directly, but has reduced
1984
+ # functionality in comparison to GR.settransformationparameters,
1985
+ # GR.setperspectiveprojection and GR.setorthographicprojection.
1986
+ # @param phi [Numeric] azimuthal angle of the spherical coordinates
1987
+ # @param theta [Numeric] polar angle of the spherical coordinates
1988
+ # @param fov [Numeric] vertical field of view (0 or NaN for orthographic projection)
1989
+ # @param camera_distance [Numeric] distance between the camera and the focus point
1990
+ # (0 or NaN for the radius of the object's smallest bounding sphere)
1991
+ def setspace3d(*)
1992
+ super
1993
+ end
1994
+
1995
+ def text3d(*)
1996
+ super
1997
+ end
1998
+
1999
+ def inqtext3d(x, y, z, string, axis)
2000
+ inquiry [{ double: 16 }, { double: 16 }] do |tbx, tby|
2001
+ super(x, y, z, string, axis, tbx, tby)
2002
+ end
2003
+ end
2004
+
2005
+ def settextencoding(*)
2006
+ super
2007
+ end
2008
+
2009
+ def inqtextencoding
2010
+ inquiry_int do |encoding|
2011
+ super(encoding)
2012
+ end
2013
+ end
1916
2014
  end
1917
2015
 
1918
2016
  ASF_BUNDLED = 0
@@ -2131,6 +2229,9 @@ module GR
2131
2229
  XFORM_CUBIC = 4
2132
2230
  XFORM_EQUALIZED = 5
2133
2231
 
2232
+ ENCODING_LATIN1 = 300
2233
+ ENCODING_UTF8 = 301
2234
+
2134
2235
  UPSAMPLE_VERTICAL_DEFAULT = 0x00000000
2135
2236
  UPSAMPLE_HORIZONTAL_DEFAULT = 0x00000000
2136
2237
  DOWNSAMPLE_VERTICAL_DEFAULT = 0x00000000
@@ -2147,4 +2248,21 @@ module GR
2147
2248
  UPSAMPLE_HORIZONTAL_LANCZOS = 0x00000300
2148
2249
  DOWNSAMPLE_VERTICAL_LANCZOS = 0x00030000
2149
2250
  DOWNSAMPLE_HORIZONTAL_LANCZOS = 0x03000000
2251
+
2252
+ RESAMPLE_DEFAULT =
2253
+ (UPSAMPLE_VERTICAL_DEFAULT | UPSAMPLE_HORIZONTAL_DEFAULT |
2254
+ DOWNSAMPLE_VERTICAL_DEFAULT | DOWNSAMPLE_HORIZONTAL_DEFAULT)
2255
+ RESAMPLE_NEAREST =
2256
+ (UPSAMPLE_VERTICAL_NEAREST | UPSAMPLE_HORIZONTAL_NEAREST |
2257
+ DOWNSAMPLE_VERTICAL_NEAREST | DOWNSAMPLE_HORIZONTAL_NEAREST)
2258
+ RESAMPLE_LINEAR =
2259
+ (UPSAMPLE_VERTICAL_LINEAR | UPSAMPLE_HORIZONTAL_LINEAR |
2260
+ DOWNSAMPLE_VERTICAL_LINEAR | DOWNSAMPLE_HORIZONTAL_LINEAR)
2261
+ RESAMPLE_LANCZOS =
2262
+ (UPSAMPLE_VERTICAL_LANCZOS | UPSAMPLE_HORIZONTAL_LANCZOS |
2263
+ DOWNSAMPLE_VERTICAL_LANCZOS | DOWNSAMPLE_HORIZONTAL_LANCZOS)
2264
+
2265
+ PROJECTION_DEFAULT = 0
2266
+ PROJECTION_ORTHOGRAPHIC = 1
2267
+ PROJECTION_PERSPECTIVE = 2
2150
2268
  end