ruby-gr 0.0.5 → 0.0.6
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/LICENSE.txt +1 -0
- data/README.md +12 -10
- data/lib/gr.rb +339 -292
- data/lib/gr/ffi.rb +188 -180
- data/lib/gr/grbase.rb +1 -0
- data/lib/gr/plot.rb +1344 -0
- data/lib/gr/plot.rb.md +207 -0
- data/lib/gr3.rb +99 -81
- data/lib/gr3/ffi.rb +114 -78
- data/lib/gr3/gr3base.rb +5 -0
- data/lib/gr_commons.rb +1 -1
- data/lib/gr_commons/define_methods.rb +3 -1
- data/lib/gr_commons/extern.rb +16 -0
- data/lib/gr_commons/fiddley.rb +419 -0
- data/lib/gr_commons/gr_common_utils.rb +19 -48
- data/lib/gr_commons/jupyter_support.rb +5 -2
- data/lib/gr_commons/version.rb +1 -1
- metadata +37 -20
- data/lib/gr_commons/attach_function.rb +0 -15
data/lib/gr/plot.rb.md
ADDED
@@ -0,0 +1,207 @@
|
|
1
|
+
This is a memo to think about the structure of Plot/Figure.
|
2
|
+
|
3
|
+
````ruby
|
4
|
+
|
5
|
+
module GR
|
6
|
+
# object oriented way
|
7
|
+
class PlotBase
|
8
|
+
end
|
9
|
+
|
10
|
+
class Line < PlotBase
|
11
|
+
end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def set_viewport; end
|
15
|
+
|
16
|
+
def minmax; end
|
17
|
+
|
18
|
+
def set_window; end
|
19
|
+
|
20
|
+
def draw_axes; end
|
21
|
+
|
22
|
+
def draw_polar_axes; end
|
23
|
+
|
24
|
+
def _inqtext; end
|
25
|
+
|
26
|
+
def _text; end
|
27
|
+
|
28
|
+
def draw_legend; end
|
29
|
+
|
30
|
+
def draw_colorbar; end
|
31
|
+
|
32
|
+
def colormap; end
|
33
|
+
|
34
|
+
def to_rgba; end
|
35
|
+
|
36
|
+
# Ruby is object-oriented language.
|
37
|
+
# Julia is more functional...
|
38
|
+
# def create_context
|
39
|
+
# end
|
40
|
+
# def restore_context
|
41
|
+
# end
|
42
|
+
# def figure
|
43
|
+
# end
|
44
|
+
|
45
|
+
# def hold
|
46
|
+
# end
|
47
|
+
# def usecolorscheme
|
48
|
+
# end
|
49
|
+
|
50
|
+
# Set current subplot index.
|
51
|
+
def subplot; end
|
52
|
+
|
53
|
+
# draw_grid
|
54
|
+
|
55
|
+
# xticks
|
56
|
+
# yticks
|
57
|
+
# zticks
|
58
|
+
|
59
|
+
# xticklabels
|
60
|
+
# yticklabels
|
61
|
+
|
62
|
+
def plot_img; end # should be private?
|
63
|
+
|
64
|
+
def plot_iso; end # should be private?
|
65
|
+
|
66
|
+
def plot_polar; end # should be private?
|
67
|
+
|
68
|
+
# send_meta
|
69
|
+
|
70
|
+
def plot_data; end # should be private?
|
71
|
+
|
72
|
+
def plot_args; end # should be private?
|
73
|
+
|
74
|
+
# Draw one or more line plots.
|
75
|
+
def plot_line; end
|
76
|
+
alias lineplot plot_line
|
77
|
+
|
78
|
+
# def plot_line_over oplot_line ?
|
79
|
+
|
80
|
+
# Draw one or more step or staircase plots.
|
81
|
+
def plot_step; end
|
82
|
+
alias stepplot plot_step
|
83
|
+
alias step plot_step
|
84
|
+
|
85
|
+
# Draw one or more scatter plots.
|
86
|
+
def plot_scatter; end
|
87
|
+
alias scatterplot plot_scatter
|
88
|
+
alias scatter plot_scatter
|
89
|
+
|
90
|
+
# Draw a stem plot.
|
91
|
+
def plot_stem; end
|
92
|
+
alias stemplot plot_stem
|
93
|
+
alias stem plot_stem
|
94
|
+
|
95
|
+
# Draw a bar plot.
|
96
|
+
def plot_bar; end
|
97
|
+
alias barplot plot_bar
|
98
|
+
alias bar plot_bar
|
99
|
+
|
100
|
+
def hist; end # should be private?
|
101
|
+
|
102
|
+
# Draw a histogram.
|
103
|
+
def plot_histgram; end
|
104
|
+
alias histogram plot_histgram
|
105
|
+
|
106
|
+
# Draw a polar histogram.
|
107
|
+
def plot_polarhistogram; end
|
108
|
+
alias polarhistogram plot_polarhistogram
|
109
|
+
|
110
|
+
# Draw a contour plot.
|
111
|
+
def plot_contour; end
|
112
|
+
alias contourplot plot_contour
|
113
|
+
# GR.contour is already defined in GR::FFI class.
|
114
|
+
|
115
|
+
# Draw a filled contour plot.
|
116
|
+
def plot_contourf; end
|
117
|
+
alias contourfplot plot_contour # change name?
|
118
|
+
# GR.contourf is already defined in GR::FFI class.
|
119
|
+
|
120
|
+
# Draw a hexagon binning plot.
|
121
|
+
def plot_hexbin; end
|
122
|
+
alias hexbinplot plot_hexbin
|
123
|
+
# GR.hexbin is already defined in GR::FFI class.
|
124
|
+
alias jointplot plot_hexbin
|
125
|
+
|
126
|
+
# Draw a heatmap.
|
127
|
+
def plot_heatmap; end
|
128
|
+
alias heatmap plot_heatmap
|
129
|
+
|
130
|
+
def plot_polarheatmap; end
|
131
|
+
alias polarheatmap plot_polarheatmap
|
132
|
+
|
133
|
+
# Draw a three-dimensional wireframe plot.
|
134
|
+
def plot_wireframe; end
|
135
|
+
alias wireframe plot_wireframe
|
136
|
+
|
137
|
+
# Draw a three-dimensional surface plot.
|
138
|
+
def plot_surface; end
|
139
|
+
alias surfaceplot plot_surface
|
140
|
+
|
141
|
+
def plot_volume; end
|
142
|
+
alias volumeplot plot_volume
|
143
|
+
|
144
|
+
# Draw one or more three-dimensional line plots.
|
145
|
+
def plot_line3; end
|
146
|
+
alias lineplot3 plot_line3
|
147
|
+
|
148
|
+
# Draw one or more three-dimensional scatter plots.
|
149
|
+
def plot_scatter3; end
|
150
|
+
alias scatterplot3 plot_scatter3
|
151
|
+
|
152
|
+
def redraw; end
|
153
|
+
|
154
|
+
def title; end
|
155
|
+
|
156
|
+
def xlabel; end
|
157
|
+
|
158
|
+
def ylabel; end
|
159
|
+
|
160
|
+
def legend; end
|
161
|
+
|
162
|
+
def xlim; end
|
163
|
+
|
164
|
+
def ylim; end
|
165
|
+
|
166
|
+
def savefig; end
|
167
|
+
|
168
|
+
def meshgrid; end # should be private ?
|
169
|
+
|
170
|
+
def peaks; end # should be private ?
|
171
|
+
|
172
|
+
def imshow; end
|
173
|
+
|
174
|
+
# Draw an isosurface.
|
175
|
+
def plot_isosurface; end
|
176
|
+
|
177
|
+
# Draw one or more polar plots.
|
178
|
+
def plot_polar; end
|
179
|
+
|
180
|
+
# Draw a triangular surface plot.
|
181
|
+
def plot_trisurf; end
|
182
|
+
|
183
|
+
# Draw a triangular contour plot.
|
184
|
+
def plot_tricont; end
|
185
|
+
|
186
|
+
def plot_shade; end
|
187
|
+
|
188
|
+
# def set_panzoom ?
|
189
|
+
|
190
|
+
# mainloop
|
191
|
+
|
192
|
+
# GR.plot do
|
193
|
+
#
|
194
|
+
# end
|
195
|
+
#
|
196
|
+
# GR.plot(:scatter, * * *)
|
197
|
+
def plot; end
|
198
|
+
|
199
|
+
# Object ?
|
200
|
+
|
201
|
+
# a = GR::Bar.new()
|
202
|
+
# a.draw ?
|
203
|
+
# a = GR::Bar.plot() ?
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
```
|
data/lib/gr3.rb
CHANGED
@@ -2,38 +2,52 @@
|
|
2
2
|
|
3
3
|
# OverView of GR.rb
|
4
4
|
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
+
# +------------------+
|
37
|
+
#
|
38
|
+
# Why not GR::GR3?
|
39
|
+
# * kojix2 did not want to force gr3 to be loaded when gr is loaded.
|
40
|
+
# * kojix2 did not want to write `GR3 = GR::GR3` or something.
|
41
|
+
# * This is a opinion of kojix2 and may be changed in the future.
|
42
|
+
#
|
43
|
+
# GR3 uses Numo::Narrray.
|
44
|
+
# * It is difficult to write GR3 modules with only Ruby arrays.
|
45
|
+
# * Numo::Narray has better performance and is easier to read.
|
46
|
+
# * Numo::Narray does not work with JRuby.
|
47
|
+
# * https://github.com/ruby-numo/numo-narray/issues/147
|
48
|
+
#
|
49
|
+
# This is a procedural interface to the GR3 in GR plotting library,
|
50
|
+
# https://github.com/sciapp/gr
|
37
51
|
module GR3
|
38
52
|
class Error < StandardError; end
|
39
53
|
|
@@ -42,19 +56,18 @@ module GR3
|
|
42
56
|
end
|
43
57
|
|
44
58
|
# Platforms | path
|
45
|
-
# Windows | bin/
|
59
|
+
# Windows | bin/libGR3.dll
|
46
60
|
# MacOSX | lib/libGR3.so (NOT .dylib)
|
47
61
|
# Ubuntu | lib/libGR3.so
|
48
62
|
raise Error, 'Please set env variable GRDIR' unless ENV['GRDIR']
|
49
63
|
|
50
64
|
ENV['GKS_FONTPATH'] ||= ENV['GRDIR']
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
65
|
+
if Object.const_defined?(:RubyInstaller)
|
66
|
+
@ffi_lib = File.expand_path('bin/libGR3.dll', ENV['GRDIR'])
|
67
|
+
RubyInstaller::Runtime.add_dll_directory(File.dirname(@ffi_lib))
|
68
|
+
else
|
69
|
+
@ffi_lib = File.expand_path('lib/libGR3.so', ENV['GRDIR'])
|
70
|
+
end
|
58
71
|
|
59
72
|
require_relative 'gr_commons'
|
60
73
|
require_relative 'gr3/version'
|
@@ -69,13 +82,14 @@ module GR3
|
|
69
82
|
# This module is for adding error checking to all methods in GR3
|
70
83
|
module CheckError
|
71
84
|
def geterror
|
72
|
-
line = ::
|
73
|
-
file = ::
|
85
|
+
line = GRCommons::Fiddley::MemoryPointer.new(:int)
|
86
|
+
file = GRCommons::Fiddley::MemoryPointer.new(:pointer)
|
74
87
|
e = super(1, line, file)
|
75
88
|
return [0, nil, nil] if e == 0
|
76
89
|
|
77
90
|
line = line.read_int
|
78
|
-
|
91
|
+
# to_ptr: Fiddley::MemoryPointer -> Fiddle::Pointer
|
92
|
+
file = file.to_ptr.ptr.to_s
|
79
93
|
[e, line, file]
|
80
94
|
end
|
81
95
|
|
@@ -90,11 +104,15 @@ module GR3
|
|
90
104
|
mesg = FFI.gr3_geterrorstring(e)
|
91
105
|
raise "GR3 error #{file} #{line} #{mesg}"
|
92
106
|
end
|
107
|
+
values
|
93
108
|
end
|
94
109
|
end
|
95
110
|
end
|
96
111
|
extend CheckError
|
97
112
|
|
113
|
+
# Now you can see a lot of methods just calling super here.
|
114
|
+
# Why? Do they really need?
|
115
|
+
# Yes. They are written to help the yard generate the documentation.
|
98
116
|
class << self
|
99
117
|
# This method initializes the gr3 context.
|
100
118
|
# @return [Integer]
|
@@ -124,13 +142,13 @@ module GR3
|
|
124
142
|
# If gr3 is not initialized `"Not initialized"` is returned.
|
125
143
|
# @return [String]
|
126
144
|
def getrenderpathstring(*)
|
127
|
-
super
|
145
|
+
super.to_s
|
128
146
|
end
|
129
147
|
|
130
148
|
# This function returns a string representation of a given error code.
|
131
149
|
# @return [String]
|
132
150
|
def geterrorstring(*)
|
133
|
-
super
|
151
|
+
super.to_s
|
134
152
|
end
|
135
153
|
|
136
154
|
# This function clears the draw list.
|
@@ -366,9 +384,9 @@ module GR3
|
|
366
384
|
# a new mesh has to be created.
|
367
385
|
# @param nx [Integer] number of points in x-direction
|
368
386
|
# @param ny [Integer] number of points in y-direction
|
369
|
-
# @param
|
370
|
-
# @param
|
371
|
-
# @param
|
387
|
+
# @param x [Array, NArray] an array containing the x-coordinates
|
388
|
+
# @param y [Array, NArray] an array containing the y-coordinates
|
389
|
+
# @param z [Array, NArray] an array of length nx * ny containing the z-coordinates
|
372
390
|
# @param option [Integer] option for the surface mesh; the GR3_SURFACE constants can be combined with bitwise or. See the table below.
|
373
391
|
# * 0 : GR3_SURFACE_DEFAULT
|
374
392
|
# * default behavior
|
@@ -383,9 +401,9 @@ module GR3
|
|
383
401
|
# * 16 : GR3_SURFACE_GRZSHADED
|
384
402
|
# * like GR3_SURFACE_GRCOLOR, but use the z-value directly as color index
|
385
403
|
# @return [Integer]
|
386
|
-
def createsurfacemesh(nx, ny,
|
404
|
+
def createsurfacemesh(nx, ny, x, y, z, option = 0)
|
387
405
|
inquiry_int do |mesh|
|
388
|
-
super(mesh, nx, ny,
|
406
|
+
super(mesh, nx, ny, x, y, z, option)
|
389
407
|
end
|
390
408
|
end
|
391
409
|
|
@@ -413,16 +431,16 @@ module GR3
|
|
413
431
|
end
|
414
432
|
|
415
433
|
# Create a surface plot with gr3 and draw it with gks as cellarray.
|
416
|
-
# @param
|
417
|
-
# @param
|
418
|
-
# @param
|
434
|
+
# @param x [Array, NArray] an array containing the x-coordinates
|
435
|
+
# @param y [Array, NArray] an array containing the y-coordinates
|
436
|
+
# @param z [Array, NArray] an array of length nx * ny containing the z-coordinates
|
419
437
|
# @param option [Integer] see the option parameter of gr_surface.
|
420
438
|
# OPTION_COLORED_MESH and OPTION_Z_SHADED_MESH are supported.
|
421
|
-
def surface(
|
422
|
-
nx =
|
423
|
-
ny =
|
439
|
+
def surface(x, y, z, option)
|
440
|
+
nx = x.length
|
441
|
+
ny = y.length
|
424
442
|
# TODO: Check out_of_bounds
|
425
|
-
super(nx, ny,
|
443
|
+
super(nx, ny, x, y, z, option)
|
426
444
|
end
|
427
445
|
|
428
446
|
# drawtubemesh
|
@@ -675,10 +693,10 @@ module GR3
|
|
675
693
|
|
676
694
|
def volume(data, algorithm)
|
677
695
|
inquiry %i[double double] do |dmin, dmax|
|
678
|
-
|
696
|
+
dmin.write_double(-1)
|
679
697
|
dmax.write_double(-1)
|
680
698
|
# TODO: raise error when no NArray
|
681
|
-
data = Numo::DFloat.cast(data) if data.is_a Array
|
699
|
+
data = Numo::DFloat.cast(data) if data.is_a? Array
|
682
700
|
nx, ny, nz = data.shape
|
683
701
|
super(nx, ny, nz, data, algorithm, dmin, dmax)
|
684
702
|
end
|
@@ -731,38 +749,38 @@ module GR3
|
|
731
749
|
end
|
732
750
|
|
733
751
|
# InitAttribute
|
734
|
-
IA_END_OF_LIST
|
735
|
-
IA_FRAMEBUFFER_WIDTH
|
752
|
+
IA_END_OF_LIST = 0
|
753
|
+
IA_FRAMEBUFFER_WIDTH = 1
|
736
754
|
IA_FRAMEBUFFER_HEIGHT = 2
|
737
755
|
|
738
756
|
# Error
|
739
|
-
ERROR_NONE
|
740
|
-
ERROR_INVALID_VALUE
|
741
|
-
ERROR_INVALID_ATTRIBUTE
|
742
|
-
ERROR_INIT_FAILED
|
743
|
-
ERROR_OPENGL_ERR
|
744
|
-
ERROR_OUT_OF_MEM
|
745
|
-
ERROR_NOT_INITIALIZED
|
746
|
-
ERROR_CAMERA_NOT_INITIALIZED =
|
747
|
-
ERROR_UNKNOWN_FILE_EXTENSION =
|
748
|
-
ERROR_CANNOT_OPEN_FILE
|
749
|
-
ERROR_EXPORT
|
757
|
+
ERROR_NONE = 0
|
758
|
+
ERROR_INVALID_VALUE = 1
|
759
|
+
ERROR_INVALID_ATTRIBUTE = 2
|
760
|
+
ERROR_INIT_FAILED = 3
|
761
|
+
ERROR_OPENGL_ERR = 4
|
762
|
+
ERROR_OUT_OF_MEM = 5
|
763
|
+
ERROR_NOT_INITIALIZED = 6
|
764
|
+
ERROR_CAMERA_NOT_INITIALIZED = 7
|
765
|
+
ERROR_UNKNOWN_FILE_EXTENSION = 8
|
766
|
+
ERROR_CANNOT_OPEN_FILE = 9
|
767
|
+
ERROR_EXPORT = 10
|
750
768
|
|
751
769
|
# Quality
|
752
|
-
QUALITY_OPENGL_NO_SSAA =
|
753
|
-
QUALITY_OPENGL_2X_SSAA =
|
754
|
-
QUALITY_OPENGL_4X_SSAA =
|
755
|
-
QUALITY_OPENGL_8X_SSAA =
|
770
|
+
QUALITY_OPENGL_NO_SSAA = 0
|
771
|
+
QUALITY_OPENGL_2X_SSAA = 2
|
772
|
+
QUALITY_OPENGL_4X_SSAA = 4
|
773
|
+
QUALITY_OPENGL_8X_SSAA = 8
|
756
774
|
QUALITY_OPENGL_16X_SSAA = 16
|
757
|
-
QUALITY_POVRAY_NO_SSAA =
|
758
|
-
QUALITY_POVRAY_2X_SSAA =
|
759
|
-
QUALITY_POVRAY_4X_SSAA =
|
760
|
-
QUALITY_POVRAY_8X_SSAA =
|
775
|
+
QUALITY_POVRAY_NO_SSAA = 0 + 1
|
776
|
+
QUALITY_POVRAY_2X_SSAA = 2 + 1
|
777
|
+
QUALITY_POVRAY_4X_SSAA = 4 + 1
|
778
|
+
QUALITY_POVRAY_8X_SSAA = 8 + 1
|
761
779
|
QUALITY_POVRAY_16X_SSAA = 16 + 1
|
762
780
|
|
763
781
|
# Drawable
|
764
782
|
DRAWABLE_OPENGL = 1
|
765
|
-
DRAWABLE_GKS
|
783
|
+
DRAWABLE_GKS = 2
|
766
784
|
|
767
785
|
# SurfaceOption
|
768
786
|
SURFACE_DEFAULT = 0
|