ruby-gr 0.0.26 → 0.58.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -11
- data/lib/gr.rb +58 -23
- data/lib/gr/ffi.rb +1 -0
- data/lib/gr/plot.rb +65 -45
- data/lib/gr3.rb +4 -1
- data/lib/gr_commons/gr_lib.rb +43 -22
- data/lib/gr_commons/gr_logger.rb +23 -11
- data/lib/gr_commons/version.rb +1 -1
- data/lib/grm.rb +4 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f620965108eafb5f65fc8b1c946db5abea180708db175b88246a2ecd97a66b53
|
4
|
+
data.tar.gz: 8ff0c1b787c4b3e70a29ace39eb2fb39abaf60d71afc05b4b382edfcb6f570fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb816d775831c8e05f43e0ded3d15a22328ff0b7e5810c484782393b4fe06ee5aa03fbf431b3cbbe6c8bac2763b07ef377e42dd5d9024da1aec819251b264951
|
7
|
+
data.tar.gz: 9e12f1fa434d64b1f202a3198afa30be70ee1b4961493cde92d308134b146703ff21e2e1915cd01ed286f476f7e6900425aaa5ebdc8f1b33fd550a3d3567a14f
|
data/README.md
CHANGED
@@ -123,8 +123,6 @@ Some GR module methods are overwritten.
|
|
123
123
|
[`imshow`](../../wiki/Plotting-functions#imshow)
|
124
124
|
[`isosurface`](../../wiki/Plotting-functions#isosurface)
|
125
125
|
|
126
|
-
We are preparing a [more object-oriented interface](https://github.com/kojix2/GRUtils.rb) based on [GRUtils.jl](https://github.com/heliosdrm/GRUtils.jl) in the future.
|
127
|
-
|
128
126
|
#### GR - A module for calling native GR functions.
|
129
127
|
|
130
128
|
2-D Plots and common 3-D Plots.
|
@@ -148,6 +146,16 @@ require 'gr3'
|
|
148
146
|
GR3.cameralookat(-3, 2, -2, 0, 0, 0, 0, 0, -1)
|
149
147
|
```
|
150
148
|
|
149
|
+
### Using GR.rb non-interactively
|
150
|
+
|
151
|
+
Both APIs will by default start a Qt based window to show the result of the last call.
|
152
|
+
This behavior is caused by GR itself as it will [implicitly generate output to a file or application](https://gr-framework.org/workstations.html#no-output).
|
153
|
+
If you want to use GR.rb non-interactively, eg., as part of a static site build, you can do this by setting the environment variable `GKS_WSTYPE`to `100`.
|
154
|
+
|
155
|
+
```sh
|
156
|
+
export GKS_WSTYPE=100
|
157
|
+
```
|
158
|
+
|
151
159
|
## Documentation
|
152
160
|
|
153
161
|
- [GR.rb Wiki](https://github.com/red-data-tools/GR.rb/wiki)
|
@@ -168,7 +176,7 @@ Set environment variable GRDIR.
|
|
168
176
|
export GRDIR="your/path/to/gr"
|
169
177
|
```
|
170
178
|
|
171
|
-
|
179
|
+
macOS : Please the section "How to open apps from un-notarized or unidentified developers" in the Apple documentation ["Safely open apps on your Mac"](https://support.apple.com/en-us/HT202491).
|
172
180
|
|
173
181
|
### Using package managers
|
174
182
|
|
@@ -180,10 +188,9 @@ export GRDIR="your/path/to/gr"
|
|
180
188
|
|
181
189
|
```sh
|
182
190
|
brew install libgr
|
183
|
-
|
191
|
+
export GKS_WSTYPE=411 # gksqt (recommended)
|
184
192
|
```
|
185
193
|
|
186
|
-
|
187
194
|
#### Linux - APT
|
188
195
|
|
189
196
|
[packages.red-data-tools.org](https://github.com/red-data-tools/packages.red-data-tools.org) provides `libgr-dev`, `libgr3-dev` and `libgrm-dev`
|
@@ -192,7 +199,8 @@ Debian GNU/Linux and Ubuntu
|
|
192
199
|
|
193
200
|
```sh
|
194
201
|
sudo apt install -y -V ca-certificates lsb-release wget
|
195
|
-
wget https://packages.red-data-tools.org/$(lsb_release --id --short | tr 'A-Z' 'a-z'
|
202
|
+
wget https://packages.red-data-tools.org/$(lsb_release --id --short | tr 'A-Z' 'a-z'\
|
203
|
+
)/red-data-tools-apt-source-latest-$(lsb_release --codename --short).deb
|
196
204
|
sudo apt install -y -V ./red-data-tools-apt-source-latest-$(lsb_release --codename --short).deb
|
197
205
|
sudo apt update
|
198
206
|
sudo apt install libgrm-dev
|
@@ -207,14 +215,10 @@ CentOS
|
|
207
215
|
sudo dnf install -y gr-devel
|
208
216
|
```
|
209
217
|
|
210
|
-
|
218
|
+
#### Windows - MSYS2
|
211
219
|
|
212
220
|
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.
|
213
221
|
|
214
|
-
## Backend for Charty
|
215
|
-
|
216
|
-
GR.rb will be the default backend for [Charty](https://github.com/red-data-tools/charty).
|
217
|
-
|
218
222
|
## Contributing
|
219
223
|
|
220
224
|
GR.rb is a library under development, so even small improvements like fixing typos are welcome!
|
@@ -227,6 +231,22 @@ Please feel free to send us your PR.
|
|
227
231
|
* Update GR packages ( Homebrew, MinGW, red-data-tools )
|
228
232
|
* Create visualization tools based on GR.rb
|
229
233
|
|
234
|
+
To get started with development:
|
235
|
+
|
236
|
+
```sh
|
237
|
+
git clone https://github.com/red-data-tools/GR.rb
|
238
|
+
cd GR.rb
|
239
|
+
bundle install
|
240
|
+
bundle exec rake test
|
241
|
+
```
|
242
|
+
|
243
|
+
* [I'm new to Ruby](https://github.com/red-data-tools/GR.rb/wiki/I%27m-new-to-Ruby)
|
244
|
+
|
245
|
+
## Future plans
|
246
|
+
|
247
|
+
* GR.rb will be the default backend for [Charty](https://github.com/red-data-tools/charty).
|
248
|
+
* [Object-oriented interface](https://github.com/kojix2/GRUtils.rb) based on [GRUtils.jl](https://github.com/heliosdrm/GRUtils.jl).
|
249
|
+
|
230
250
|
## Acknowledgements
|
231
251
|
|
232
252
|
We would like to thank Josef Heinen, the creator of [GR](https://github.com/sciapp/gr) and [GR.jl](https://github.com/jheinen/GR.jl), Florian Rhiem, the creator of [python-gr](https://github.com/sciapp/python-gr), and all [GR](https://github.com/sciapp/gr) developers.
|
data/lib/gr.rb
CHANGED
@@ -58,7 +58,7 @@ module GR
|
|
58
58
|
|
59
59
|
# Platforms | path
|
60
60
|
# Windows | bin/libgr.dll
|
61
|
-
# MacOSX | lib/libGR.
|
61
|
+
# MacOSX | lib/libGR.dylib ( <= v0.53.0 .so)
|
62
62
|
# Ubuntu | lib/libGR.so
|
63
63
|
platform = RbConfig::CONFIG['host_os']
|
64
64
|
lib_names, pkg_name = \
|
@@ -70,6 +70,9 @@ module GR
|
|
70
70
|
else
|
71
71
|
[['libGR.so'], 'gr']
|
72
72
|
end
|
73
|
+
|
74
|
+
# On Windows + RubyInstaller,
|
75
|
+
# the environment variable GKS_FONTPATH will be set.
|
73
76
|
lib_path = GRCommons::GRLib.search(lib_names, pkg_name)
|
74
77
|
|
75
78
|
raise NotFoundError, "#{lib_names} not found" if lib_path.nil?
|
@@ -178,7 +181,7 @@ module GR
|
|
178
181
|
# @param x [Array, NArray] A list containing the X coordinates
|
179
182
|
# @param y [Array, NArray] A list containing the Y coordinates
|
180
183
|
# @param linewidth [Array, NArray, Numeric] A list containing the line widths
|
181
|
-
# @param line_z [Array, NArray]
|
184
|
+
# @param line_z [Array, NArray, Numeric] A list to be converted to colors
|
182
185
|
#
|
183
186
|
# The values for x and y are in world coordinates.
|
184
187
|
# The attributes that control the appearance of a polyline are linetype,
|
@@ -190,13 +193,24 @@ module GR
|
|
190
193
|
if linewidth.nil? && line_z.nil?
|
191
194
|
super(n, x, y)
|
192
195
|
else
|
193
|
-
linewidth
|
194
|
-
linewidth
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
196
|
+
linewidth ||= GR.inqlinewidth
|
197
|
+
linewidth = if linewidth.is_a?(Numeric)
|
198
|
+
Array.new(n, linewidth * 100)
|
199
|
+
else
|
200
|
+
raise ArgumentError if n != linewidth.length
|
201
|
+
|
202
|
+
linewidth.map { |i| (100 * i).round }
|
203
|
+
end
|
204
|
+
line_z ||= GR.inqcolor(989) # FIXME
|
205
|
+
color = if line_z.is_a?(Numeric)
|
206
|
+
Array.new(n, line_z)
|
207
|
+
else
|
208
|
+
raise ArgumentError if n != line_z.length
|
209
|
+
|
210
|
+
to_rgb_color(line_z)
|
211
|
+
end
|
212
|
+
z = linewidth.to_a.zip(color).flatten # to_a : NArray
|
213
|
+
gdp(x, y, GDP_DRAW_LINES, z)
|
200
214
|
end
|
201
215
|
end
|
202
216
|
|
@@ -205,7 +219,7 @@ module GR
|
|
205
219
|
# @param x [Array, NArray] A list containing the X coordinates
|
206
220
|
# @param y [Array, NArray] A list containing the Y coordinates
|
207
221
|
# @param markersize [Array, NArray, Numeric] A list containing the marker sizes
|
208
|
-
# @param marker_z [Array, NArray]
|
222
|
+
# @param marker_z [Array, NArray, Numeric] A list to be converted to colors
|
209
223
|
#
|
210
224
|
# The values for x and y are in world coordinates.
|
211
225
|
# The attributes that control the appearance of a polymarker are marker type,
|
@@ -217,13 +231,24 @@ module GR
|
|
217
231
|
if markersize.nil? && marker_z.nil?
|
218
232
|
super(n, x, y)
|
219
233
|
else
|
220
|
-
markersize
|
221
|
-
markersize
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
234
|
+
markersize ||= GR.inqmarkersize
|
235
|
+
markersize = if markersize.is_a?(Numeric)
|
236
|
+
Array.new(n, markersize * 100)
|
237
|
+
else
|
238
|
+
raise ArgumentError if n != markersize.length
|
239
|
+
|
240
|
+
markersize.map { |i| (100 * i).round }
|
241
|
+
end
|
242
|
+
marker_z ||= GR.inqcolor(989) # FIXME
|
243
|
+
color = if marker_z.is_a?(Numeric)
|
244
|
+
Array.new(n, marker_z)
|
245
|
+
else
|
246
|
+
raise ArgumentError if n != marker_z.length
|
247
|
+
|
248
|
+
to_rgb_color(marker_z)
|
249
|
+
end
|
250
|
+
z = markersize.to_a.zip(color).flatten # to_a : NArray
|
251
|
+
gdp(x, y, GDP_DRAW_MARKERS, z)
|
227
252
|
end
|
228
253
|
end
|
229
254
|
|
@@ -308,9 +333,9 @@ module GR
|
|
308
333
|
# raidus. The center point of the resulting disk is located at `xorg`, `yorg`
|
309
334
|
# and the radius of the disk is `rmax`.
|
310
335
|
#
|
311
|
-
# @param
|
336
|
+
# @param x_org [Numeric] X coordinate of the disk center in world
|
312
337
|
# coordinates
|
313
|
-
# @param
|
338
|
+
# @param y_org [Numeric] Y coordinate of the disk center in world
|
314
339
|
# coordinates
|
315
340
|
# @param phimin [Numeric] start angle of the disk sector in degrees
|
316
341
|
# @param phimax [Numeric] end angle of the disk sector in degrees
|
@@ -318,7 +343,7 @@ module GR
|
|
318
343
|
# coordinates
|
319
344
|
# @param rmax [Numeric] outer radius of the punctured disk in world
|
320
345
|
# coordinates
|
321
|
-
# @param
|
346
|
+
# @param dimphi [Integer] Phi (X) dimension of the color index array
|
322
347
|
# @param dimr [Integer] iR (Y) dimension of the color index array
|
323
348
|
# @param color [Array, NArray] Color index array
|
324
349
|
#
|
@@ -1355,7 +1380,7 @@ module GR
|
|
1355
1380
|
# @param x [Array, NArray] A list containing the X coordinates
|
1356
1381
|
# @param y [Array, NArray] A list containing the Y coordinates
|
1357
1382
|
# @param z [Array, NArray] A list containing the Z coordinates
|
1358
|
-
# @param
|
1383
|
+
# @param levels [Array, NArray] A list of contour levels
|
1359
1384
|
#
|
1360
1385
|
def tricontour(x, y, z, levels)
|
1361
1386
|
npoints = x.length # equal_length ?
|
@@ -1414,6 +1439,16 @@ module GR
|
|
1414
1439
|
super(n, r, g, b, positions)
|
1415
1440
|
end
|
1416
1441
|
|
1442
|
+
# Inquire the color index range of the current colormap.
|
1443
|
+
#
|
1444
|
+
# @return [Array] first_color_ind The color index of the first color,
|
1445
|
+
# last_color_ind The color index of the last color
|
1446
|
+
def inqcolormapinds
|
1447
|
+
inquiry %i[int int] do |first_color_ind, last_color_ind|
|
1448
|
+
super(first_color_ind, last_color_ind)
|
1449
|
+
end
|
1450
|
+
end
|
1451
|
+
|
1417
1452
|
# @!method colorbar
|
1418
1453
|
|
1419
1454
|
def inqcolor(color)
|
@@ -1601,14 +1636,14 @@ module GR
|
|
1601
1636
|
# curves.
|
1602
1637
|
#
|
1603
1638
|
# @param points [Array, NArray] (N, 2) array of (x, y) vertices
|
1604
|
-
# @
|
1639
|
+
# @param codes [Array, NArray] N-length array of path codes
|
1605
1640
|
# * STOP : end the entire path
|
1606
1641
|
# * MOVETO : move to the given vertex
|
1607
1642
|
# * LINETO : draw a line from the current position to the given vertex
|
1608
1643
|
# * CURVE3 : draw a quadratic Bézier curve
|
1609
1644
|
# * CURVE4 : draw a cubic Bézier curve
|
1610
1645
|
# * CLOSEPOLY : draw a line segment to the start point of the current path
|
1611
|
-
# @
|
1646
|
+
# @param fill [Integer]
|
1612
1647
|
# A flag indication whether resulting path is to be filled or not
|
1613
1648
|
#
|
1614
1649
|
def drawpath(points, codes, fill)
|
data/lib/gr/ffi.rb
CHANGED
@@ -117,6 +117,7 @@ module GR
|
|
117
117
|
try_extern 'void gr_setcolormap(int)'
|
118
118
|
try_extern 'void gr_inqcolormap(int *)'
|
119
119
|
try_extern 'void gr_setcolormapfromrgb(int n, double *r, double *g, double *b, double *x)'
|
120
|
+
try_extern 'void gr_inqcolormapinds(int *, int *)'
|
120
121
|
try_extern 'void gr_colorbar(void)'
|
121
122
|
try_extern 'void gr_inqcolor(int, int *)'
|
122
123
|
try_extern 'int gr_inqcolorfromrgb(double, double, double)'
|
data/lib/gr/plot.rb
CHANGED
@@ -39,11 +39,11 @@ module GR
|
|
39
39
|
# Keyword options conform to GR.jl.
|
40
40
|
KW_ARGS = %i[accelerate algorithm alpha ax backgroundcolor barwidth baseline
|
41
41
|
clabels clear clim color colormap crange figsize font grid
|
42
|
-
horizontal isovalue kind label labels levels location
|
43
|
-
ratio rotation scale size spec subplot tilt title update
|
44
|
-
xflip xform xlabel xlim xlog xrange xticks yaxis yflip
|
45
|
-
ylim ylog zflip yrange yticks viewport vp where window
|
46
|
-
zlabel zlim zlog zrange zticks].freeze
|
42
|
+
horizontal isovalue kind label labels levels linewidth location
|
43
|
+
nbins ratio rotation scale size spec subplot tilt title update
|
44
|
+
xaxis xflip xform xlabel xlim xlog xrange xticks yaxis yflip
|
45
|
+
ylabel ylim ylog zflip yrange yticks viewport vp where window
|
46
|
+
zaxis zlabel zlim zlog zrange zticks].freeze
|
47
47
|
|
48
48
|
FONTS = {
|
49
49
|
times_roman: 101,
|
@@ -152,15 +152,20 @@ module GR
|
|
152
152
|
vp1, vp2, vp3, vp4 = vp
|
153
153
|
end
|
154
154
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
155
|
+
left_margin = kvs.has_key?(:ylabel) ? 0.05 : 0
|
156
|
+
right_margin = if %i[contour contourf hexbin heatmap nonuniformheatmap polarheatmap
|
157
|
+
nonuniformpolarheatmap surface trisurf volume].include?(kind)
|
158
|
+
(vp2 - vp1) * 0.1
|
159
|
+
else
|
160
|
+
0
|
161
|
+
end
|
162
|
+
bottom_margin = kvs.has_key?(:xlabel) ? 0.05 : 0
|
163
|
+
top_margin = kvs.has_key?(:title) ? 0.075 : 0
|
164
|
+
|
165
|
+
viewport = [vp1 + (0.075 + left_margin) * (vp2 - vp1),
|
166
|
+
vp1 + (0.95 - right_margin) * (vp2 - vp1),
|
167
|
+
vp3 + (0.075 + bottom_margin) * (vp4 - vp3),
|
168
|
+
vp3 + (0.975 - top_margin) * (vp4 - vp3)]
|
164
169
|
|
165
170
|
if %i[line step scatter stem].include?(kind) && kvs[:labels]
|
166
171
|
location = kvs[:location] || 1
|
@@ -218,7 +223,7 @@ module GR
|
|
218
223
|
kvs[:xrange] = [xmin, xmax]
|
219
224
|
kvs[:yrange] = [ymin, ymax]
|
220
225
|
else
|
221
|
-
minmax
|
226
|
+
minmax(kind)
|
222
227
|
end
|
223
228
|
|
224
229
|
major_count = if %i[wireframe surface plot3 scatter3 polar polarhist
|
@@ -246,7 +251,7 @@ module GR
|
|
246
251
|
if kvs.has_key?(:xticks)
|
247
252
|
kvs[:xticks]
|
248
253
|
else
|
249
|
-
[
|
254
|
+
[auto_tick(xmin, xmax) / major_count, major_count]
|
250
255
|
end
|
251
256
|
else
|
252
257
|
[1, 1]
|
@@ -275,7 +280,7 @@ module GR
|
|
275
280
|
if kvs.has_key?(:yticks)
|
276
281
|
kvs[:yticks]
|
277
282
|
else
|
278
|
-
[
|
283
|
+
[auto_tick(ymin, ymax) / major_count, major_count]
|
279
284
|
end
|
280
285
|
else
|
281
286
|
[1, 1]
|
@@ -290,7 +295,7 @@ module GR
|
|
290
295
|
if kvs.has_key?(:zticks)
|
291
296
|
kvs[:zticks]
|
292
297
|
else
|
293
|
-
[
|
298
|
+
[auto_tick(zmin, zmax) / major_count, major_count]
|
294
299
|
end
|
295
300
|
else
|
296
301
|
[1, 1]
|
@@ -300,15 +305,16 @@ module GR
|
|
300
305
|
end
|
301
306
|
|
302
307
|
kvs[:window] = xmin, xmax, ymin, ymax
|
303
|
-
if %i[polar polarhist polarheatmap nonuniformpolarheatmap].include?(kind)
|
308
|
+
if %i[polar polarhist polarheatmap nonuniformpolarheatmap trisurf].include?(kind)
|
304
309
|
GR.setwindow(-1, 1, -1, 1)
|
305
310
|
else
|
306
311
|
GR.setwindow(xmin, xmax, ymin, ymax)
|
307
312
|
end
|
308
313
|
if %i[wireframe surface plot3 scatter3 trisurf volume].include?(kind)
|
309
314
|
rotation = kvs[:rotation] || 40
|
310
|
-
tilt = kvs[:tilt] ||
|
311
|
-
GR.
|
315
|
+
tilt = kvs[:tilt] || 60
|
316
|
+
GR.setwindow3d(xmin, xmax, ymin, ymax, zmin, zmax)
|
317
|
+
GR.setspace3d(-rotation, tilt, 30, 0)
|
312
318
|
end
|
313
319
|
|
314
320
|
kvs[:scale] = scale
|
@@ -327,10 +333,10 @@ module GR
|
|
327
333
|
GR.setlinecolorind(1)
|
328
334
|
diag = Math.sqrt((viewport[1] - viewport[0])**2 + (viewport[3] - viewport[2])**2)
|
329
335
|
GR.setlinewidth(1)
|
330
|
-
charheight = [0.018 * diag, 0.012].max
|
331
|
-
GR.setcharheight(charheight)
|
332
336
|
ticksize = 0.0075 * diag
|
333
337
|
if %i[wireframe surface plot3 scatter3 trisurf volume].include?(kind)
|
338
|
+
charheight = [0.024 * diag, 0.012].max
|
339
|
+
GR.setcharheight(charheight)
|
334
340
|
ztick, zorg, majorz = kvs[:zaxis]
|
335
341
|
if pass == 1 && drawgrid
|
336
342
|
GR.grid3d(xtick, 0, ztick, xorg[0], yorg[1], zorg[0], 2, 0, 2)
|
@@ -340,6 +346,8 @@ module GR
|
|
340
346
|
GR.axes3d(0, ytick, 0, xorg[1], yorg[0], zorg[0], 0, majory, 0, ticksize)
|
341
347
|
end
|
342
348
|
else
|
349
|
+
charheight = [0.018 * diag, 0.012].max
|
350
|
+
GR.setcharheight(charheight)
|
343
351
|
if %i[heatmap nonuniformheatmap shade].include?(kind)
|
344
352
|
ticksize = -ticksize
|
345
353
|
elsif drawgrid
|
@@ -422,7 +430,7 @@ module GR
|
|
422
430
|
GR.setcharheight(charheight)
|
423
431
|
GR.setlinetype(GR::LINETYPE_SOLID)
|
424
432
|
|
425
|
-
tick =
|
433
|
+
tick = auto_tick(rmin, rmax)
|
426
434
|
n = ((rmax - rmin) / tick + 0.5).round
|
427
435
|
(n + 1).times do |i|
|
428
436
|
r = i.to_f / n
|
@@ -584,7 +592,7 @@ module GR
|
|
584
592
|
charheight = [0.016 * diag, 0.012].max
|
585
593
|
GR.setcharheight(charheight)
|
586
594
|
if kvs[:scale] & GR::OPTION_Z_LOG == 0
|
587
|
-
ztick =
|
595
|
+
ztick = auto_tick(zmin, zmax)
|
588
596
|
GR.axes(0, ztick, 1, zmin, 0, 1, 0.005)
|
589
597
|
else
|
590
598
|
GR.setscale(GR::OPTION_Y_LOG)
|
@@ -661,8 +669,12 @@ module GR
|
|
661
669
|
|
662
670
|
when :line
|
663
671
|
mask = GR.uselinespec(spec)
|
664
|
-
|
665
|
-
|
672
|
+
linewidth = kvs[:linewidth]
|
673
|
+
# Slightly different from Julia,
|
674
|
+
# Because the implementation of polyline and polymarker is different.
|
675
|
+
z ||= linewidth # FIXME
|
676
|
+
GR.polyline(x, y, z, c) if hasline(mask)
|
677
|
+
GR.polymarker(x, y, z, c) if hasmarker(mask)
|
666
678
|
|
667
679
|
when :step
|
668
680
|
mask = GR.uselinespec(spec)
|
@@ -698,20 +710,9 @@ module GR
|
|
698
710
|
|
699
711
|
when :scatter
|
700
712
|
GR.setmarkertype(GR::MARKERTYPE_SOLID_CIRCLE)
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
c = c.map { |i| normalize_color(i, cmin, cmax) }
|
705
|
-
cind = c.map { |i| (1000 + i * 255).round }
|
706
|
-
end
|
707
|
-
x.length.times do |i|
|
708
|
-
GR.setmarkersize(z[i] / 100.0) if z
|
709
|
-
GR.setmarkercolorind(cind[i]) if c
|
710
|
-
GR.polymarker([x[i]], [y[i]])
|
711
|
-
end
|
712
|
-
else
|
713
|
-
GR.polymarker(x, y)
|
714
|
-
end
|
713
|
+
z = z&.map { |i| i * 0.01 }
|
714
|
+
c = c&.map { |i| normalize_color(i, *kvs[:crange]) }
|
715
|
+
GR.polymarker(x, y, z, c)
|
715
716
|
|
716
717
|
when :stem
|
717
718
|
GR.setlinecolorind(1)
|
@@ -775,7 +776,7 @@ module GR
|
|
775
776
|
GR.polarcellarray(0, 0, 0, 360, 0, 1, w, h, colors)
|
776
777
|
when :nonuniformpolarheatmap
|
777
778
|
ymax = y.max.to_f
|
778
|
-
ρ = y.map{|i| i / ymax}
|
779
|
+
ρ = y.map { |i| i / ymax }
|
779
780
|
θ = x.map { |i| i * 180 / Math::PI }
|
780
781
|
GR.nonuniformpolarcellarray(θ, ρ, w, h, colors)
|
781
782
|
end
|
@@ -800,7 +801,7 @@ module GR
|
|
800
801
|
zmin = kvs[:zlim].first if kvs[:zlim].first
|
801
802
|
zmax = kvs[:zlim].last if kvs[:zlim].last
|
802
803
|
end
|
803
|
-
|
804
|
+
GR.setprojectiontype(0)
|
804
805
|
GR.setspace(zmin, zmax, 0, 90)
|
805
806
|
levels = kvs[:levels] || 0
|
806
807
|
clabels = kvs[:clabels] || false
|
@@ -1108,8 +1109,8 @@ module GR
|
|
1108
1109
|
|
1109
1110
|
# Normalize a color c with the range [cmin, cmax]
|
1110
1111
|
# 0 <= normalize_color(c, cmin, cmax) <= 1
|
1111
|
-
# Note: narray.map{|i| normalize_color(i)} There's room for speedup.
|
1112
1112
|
def normalize_color(c, cmin, cmax)
|
1113
|
+
# NOTE: narray.map{|i| normalize_color(i)} There's room for speedup.
|
1113
1114
|
c = c.to_f # if c is Integer
|
1114
1115
|
c = c.clamp(cmin, cmax) - cmin
|
1115
1116
|
c /= (cmax - cmin) if cmin != cmax
|
@@ -1146,7 +1147,7 @@ module GR
|
|
1146
1147
|
[a, b]
|
1147
1148
|
end
|
1148
1149
|
|
1149
|
-
def minmax
|
1150
|
+
def minmax(kind)
|
1150
1151
|
xmin = ymin = zmin = cmin = Float::INFINITY
|
1151
1152
|
xmax = ymax = zmax = cmax = -Float::INFINITY
|
1152
1153
|
scale = kvs[:scale]
|
@@ -1159,6 +1160,8 @@ module GR
|
|
1159
1160
|
x0, x1 = x.minmax
|
1160
1161
|
xmin = [x0, xmin].min
|
1161
1162
|
xmax = [x1, xmax].max
|
1163
|
+
elsif kind == :volume
|
1164
|
+
xmin, xmax = -1, 1
|
1162
1165
|
else
|
1163
1166
|
xmin = 0
|
1164
1167
|
xmax = 1
|
@@ -1170,6 +1173,8 @@ module GR
|
|
1170
1173
|
y0, y1 = y.minmax
|
1171
1174
|
ymin = [y0, ymin].min
|
1172
1175
|
ymax = [y1, ymax].max
|
1176
|
+
elsif kind == :volume
|
1177
|
+
ymin, ymax = -1, 1
|
1173
1178
|
else
|
1174
1179
|
ymin = 0
|
1175
1180
|
ymax = 1
|
@@ -1211,6 +1216,21 @@ module GR
|
|
1211
1216
|
end
|
1212
1217
|
end
|
1213
1218
|
|
1219
|
+
def to_wc(wn)
|
1220
|
+
xmin, ymin = GR.ndctowc(wn[0], wn[2])
|
1221
|
+
xmax, ymax = GR.ndctowc(wn[1], wn[3])
|
1222
|
+
[xmin, xmax, ymin, ymax]
|
1223
|
+
end
|
1224
|
+
|
1225
|
+
def auto_tick(amin, amax)
|
1226
|
+
scale = 10.0**Math.log10(amax - amin).truncate
|
1227
|
+
tick_size = [5.0, 2.0, 1.0, 0.5, 0.2, 0.1, 0.05, 0.02, 0.01]
|
1228
|
+
i = tick_size.find_index do |tsize|
|
1229
|
+
((amax - amin) / scale / tsize) > 7 # maximum number of tick marks
|
1230
|
+
end
|
1231
|
+
tick = tick_size[i - 1] * scale
|
1232
|
+
end
|
1233
|
+
|
1214
1234
|
def legend_size
|
1215
1235
|
scale = GR.inqscale
|
1216
1236
|
GR.selntran(0)
|
data/lib/gr3.rb
CHANGED
@@ -68,7 +68,7 @@ module GR3
|
|
68
68
|
|
69
69
|
# Platforms | path
|
70
70
|
# Windows | bin/libGR3.dll
|
71
|
-
# MacOSX | lib/libGR3.dylib (v0.53.0 .so)
|
71
|
+
# MacOSX | lib/libGR3.dylib ( <= v0.53.0 .so)
|
72
72
|
# Ubuntu | lib/libGR3.so
|
73
73
|
platform = RbConfig::CONFIG['host_os']
|
74
74
|
lib_names, pkg_name = \
|
@@ -80,6 +80,9 @@ module GR3
|
|
80
80
|
else
|
81
81
|
[['libGR3.so'], 'gr3']
|
82
82
|
end
|
83
|
+
|
84
|
+
# On Windows + RubyInstaller,
|
85
|
+
# the environment variable GKS_FONTPATH will be set.
|
83
86
|
lib_path = GRCommons::GRLib.search(lib_names, pkg_name)
|
84
87
|
|
85
88
|
raise NotFoundError, "#{lib_names} not found" if lib_path.nil?
|
data/lib/gr_commons/gr_lib.rb
CHANGED
@@ -23,45 +23,66 @@ module GRCommons
|
|
23
23
|
# - mingw-w64-gr
|
24
24
|
module GRLib
|
25
25
|
class << self
|
26
|
+
# Check if using RubyInstaller or not.
|
27
|
+
def ruby_installer?
|
28
|
+
Object.const_defined?(:RubyInstaller)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Return the directory path from the GRDIR environment variable.
|
32
|
+
def get_grdir_from_env(lib_names)
|
33
|
+
return nil unless ENV['GRDIR']
|
34
|
+
return ENV['GRDIR'] if Dir.exist?(ENV['GRDIR'])
|
35
|
+
|
36
|
+
warn "#{lib_names} : Dir GRDIR=#{ENV['GRDIR']} not found." # return nil
|
37
|
+
end
|
38
|
+
|
26
39
|
# Search the shared library.
|
27
40
|
# @note This method does not detect the Operating System.
|
28
41
|
#
|
29
42
|
# @param lib_names [Array] The actual file name of the shared library.
|
30
43
|
# @param pkg_name [String] The package name to be used when searching with pkg-configg
|
31
44
|
def search(lib_names, pkg_name)
|
45
|
+
# FIXME: There may be a better way to do it...
|
32
46
|
def lib_names.map_find(&block)
|
33
47
|
lazy.map(&block).find { |path| path }
|
34
48
|
end
|
49
|
+
|
50
|
+
# ENV['GRDIR']
|
51
|
+
# Verify that the directory exists.
|
52
|
+
grdir = get_grdir_from_env(lib_names)
|
53
|
+
|
35
54
|
# Windows + RubyInstaller
|
36
|
-
if
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
46
|
-
# ENV['GRDIR'] (Linux, Mac, Windows)
|
47
|
-
elsif ENV['GRDIR']
|
48
|
-
# Search for XXX.dylib and then XXX.so on macOS
|
49
|
-
lib_names.map_find do |lib_name|
|
50
|
-
recursive_search(lib_name, ENV['GRDIR'])
|
51
|
-
end || lib_names.map_find do |lib_name|
|
52
|
-
pkg_config_search(lib_name, pkg_name)
|
53
|
-
end
|
54
|
-
else
|
55
|
-
lib_names.map_find do |lib_name|
|
56
|
-
pkg_config_search(lib_name, pkg_name)
|
55
|
+
if ruby_installer?
|
56
|
+
grdir ||= File.join(RubyInstaller::Runtime.msys2_installation.msys_path,
|
57
|
+
RubyInstaller::Runtime.msys2_installation.mingwarch)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Search grdir
|
61
|
+
if grdir
|
62
|
+
lib_path = lib_names.map_find do |lib_name|
|
63
|
+
recursive_search(lib_name, grdir)
|
57
64
|
end
|
58
65
|
end
|
66
|
+
|
67
|
+
# Search with pkg-config
|
68
|
+
lib_path ||= lib_names.map_find do |lib_name|
|
69
|
+
pkg_config_search(lib_name, pkg_name)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Windows + RubyInstaller
|
73
|
+
if ruby_installer?
|
74
|
+
RubyInstaller::Runtime.add_dll_directory(File.dirname(lib_path))
|
75
|
+
# FIXME: Where should I write this code?
|
76
|
+
ENV['GKS_FONTPATH'] ||= grdir
|
77
|
+
end
|
78
|
+
|
79
|
+
lib_path
|
59
80
|
end
|
60
81
|
|
61
82
|
# Recursive file search in directories
|
62
83
|
# @param name [String] File to search for
|
63
84
|
# @param base_dir [String] Directory to search
|
64
|
-
# @
|
85
|
+
# @return path [String, NilClass] Returns the first path found.
|
65
86
|
# If not found, nil is returned.
|
66
87
|
def recursive_search(name, base_dir)
|
67
88
|
Dir.chdir(base_dir) do
|
data/lib/gr_commons/gr_logger.rb
CHANGED
@@ -5,10 +5,11 @@
|
|
5
5
|
# It should not be loaded when gr_commons/gr_commons is loaded.
|
6
6
|
|
7
7
|
require 'logger'
|
8
|
-
require '
|
9
|
-
require 'awesome_print'
|
8
|
+
require 'pp'
|
10
9
|
|
11
10
|
module GRCommons
|
11
|
+
# Convenience class methods
|
12
|
+
|
12
13
|
class << self
|
13
14
|
# Create a new GRLogger
|
14
15
|
# @param out [String]
|
@@ -16,30 +17,35 @@ module GRCommons
|
|
16
17
|
# @example
|
17
18
|
# require 'gr_commons/gr_logger'
|
18
19
|
# GRCommons.gr_log("log.txt")
|
20
|
+
|
19
21
|
def gr_log(out = $stderr)
|
20
22
|
GRCommons::GRLogger.new(out)
|
21
23
|
end
|
22
24
|
|
23
25
|
# Return the last created GRLogger
|
24
26
|
# @return [GRLogger]
|
27
|
+
|
25
28
|
def gr_logger
|
26
29
|
GRCommons::GRLogger.logger
|
27
30
|
end
|
28
31
|
end
|
29
32
|
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
+
# If GR.rb call native functions of the GR framework,
|
34
|
+
# it will be recorded in the log file.
|
35
|
+
#
|
36
|
+
# @note Mainly used by developers for debugging.
|
33
37
|
#
|
34
38
|
# = How it works
|
35
|
-
# prepend a module named Inspector to the singular class
|
36
|
-
#
|
39
|
+
# It prepend a module named Inspector to the singular class of the FFI module.
|
40
|
+
# It will inspects the GR function call of the FFI module
|
37
41
|
#
|
38
42
|
# @example
|
39
43
|
# require 'gr_commons/gr_logger'
|
40
|
-
# GRCommons.
|
44
|
+
# GRCommons::GRLogger.new("log.txt")
|
45
|
+
|
41
46
|
class GRLogger < Logger
|
42
47
|
# Return the last created GRLogger
|
48
|
+
|
43
49
|
def self.logger
|
44
50
|
@@logger ||= GRCommons::GRLogger.new
|
45
51
|
end
|
@@ -51,13 +57,15 @@ module GRCommons
|
|
51
57
|
end
|
52
58
|
end
|
53
59
|
|
60
|
+
# GR
|
61
|
+
|
54
62
|
if Object.const_defined?(:GR)
|
55
63
|
module GR
|
56
64
|
module FFI
|
57
65
|
module Inspector
|
58
66
|
GR::FFI.ffi_methods.each do |s|
|
59
67
|
define_method(s) do |*args|
|
60
|
-
GRCommons.gr_logger.info "GR::FFI.#{s}\n
|
68
|
+
GRCommons.gr_logger.info "GR::FFI.#{s}\n#{args.pretty_inspect}\n"
|
61
69
|
super(*args)
|
62
70
|
end
|
63
71
|
end
|
@@ -69,13 +77,15 @@ if Object.const_defined?(:GR)
|
|
69
77
|
end
|
70
78
|
end
|
71
79
|
|
80
|
+
# GR3
|
81
|
+
|
72
82
|
if Object.const_defined?(:GR3)
|
73
83
|
module GR3
|
74
84
|
module FFI
|
75
85
|
module Inspector
|
76
86
|
GR3::FFI.ffi_methods.each do |s|
|
77
87
|
define_method(s) do |*args|
|
78
|
-
GRCommons.gr_logger.info "GR3::FFI.#{s}\n
|
88
|
+
GRCommons.gr_logger.info "GR3::FFI.#{s}\n#{args.pretty_inspect}\n"
|
79
89
|
super(*args)
|
80
90
|
end
|
81
91
|
end
|
@@ -87,13 +97,15 @@ if Object.const_defined?(:GR3)
|
|
87
97
|
end
|
88
98
|
end
|
89
99
|
|
100
|
+
# GRM
|
101
|
+
|
90
102
|
if Object.const_defined?(:GRM)
|
91
103
|
module GRM
|
92
104
|
module FFI
|
93
105
|
module Inspector
|
94
106
|
GRM::FFI.ffi_methods.each do |s|
|
95
107
|
define_method(s) do |*args|
|
96
|
-
GRCommons.gr_logger.info "GRM::FFI.#{s}\n
|
108
|
+
GRCommons.gr_logger.info "GRM::FFI.#{s}\n#{args.pretty_inspect}\n"
|
97
109
|
super(*args)
|
98
110
|
end
|
99
111
|
end
|
data/lib/gr_commons/version.rb
CHANGED
data/lib/grm.rb
CHANGED
@@ -27,7 +27,7 @@ module GRM
|
|
27
27
|
|
28
28
|
# Platforms | path
|
29
29
|
# Windows | bin/libGRM.dll
|
30
|
-
# MacOSX | lib/libGRM.dylib (v0.53.0 .so)
|
30
|
+
# MacOSX | lib/libGRM.dylib ( <= v0.53.0 .so)
|
31
31
|
# Ubuntu | lib/libGRM.so
|
32
32
|
platform = RbConfig::CONFIG['host_os']
|
33
33
|
lib_names, pkg_name = \
|
@@ -39,6 +39,9 @@ module GRM
|
|
39
39
|
else
|
40
40
|
[['libGRM.so'], 'grm']
|
41
41
|
end
|
42
|
+
|
43
|
+
# On Windows + RubyInstaller,
|
44
|
+
# the environment variable GKS_FONTPATH will be set.
|
42
45
|
lib_path = GRCommons::GRLib.search(lib_names, pkg_name)
|
43
46
|
|
44
47
|
raise NotFoundError, "#{lib_names} not found" if lib_path.nil?
|
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.58.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kojix2
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: histogram
|
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
186
|
- !ruby/object:Gem::Version
|
187
187
|
version: '0'
|
188
188
|
requirements: []
|
189
|
-
rubygems_version: 3.2.
|
189
|
+
rubygems_version: 3.2.22
|
190
190
|
signing_key:
|
191
191
|
specification_version: 4
|
192
192
|
summary: GR for Ruby
|