ruby-gr 0.73.6.0 → 0.73.19.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c49cfd6712b94567eebb2ae2b4e2f67c227acc0bce428c15d777419d4b6ba31b
4
- data.tar.gz: ecd7816d1e8f9784169ee9b917189361b18f6424958c70498279731c42c985c0
3
+ metadata.gz: af97f95dda8fbb4c36e6ea785aff4a2e84ff94999b9e231d1915ebe66faa2a9e
4
+ data.tar.gz: 44b3bb5edd034a4e6fc0763890be330b175c3241ffe460853ae22bd42ac2a053
5
5
  SHA512:
6
- metadata.gz: 63bcc49377529b51fbf7d8005ee75c6b3af6961fd96ffd5ae769dbf495b75fbe064f6c50a3e180e1e8030dfa97297abdd4442c89e17b0fea49865e045dbfb464
7
- data.tar.gz: 40024235f7e6599a5a9555dacac610a74e4abf1ee07332c7a82a834e3b070d9096d79408e453078014f7f59bdc58182f29a39e8e2afbf5d8b8536a3a6b86eabf
6
+ metadata.gz: 71043c094117d2876355d3a6cda779ba4eedde5a59049796c7ad987d9ba52545fcdf6806cb1f708d5b878d79c8d21e95b557bc3ebfeeeecbffb3939c2bae0ffe
7
+ data.tar.gz: 5bb3bbd6baed3c1026ed0e4f89adb3acd15d25455b20e5814f2819fcc11d4f60bc7c41cbddf8a99f5bdd5b6b20e03e66f800432faec559b2a8e8389fe149c787
data/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  [![Gem Version](https://img.shields.io/gem/v/ruby-gr?color=brightgreen)](https://rubygems.org/gems/ruby-gr)
4
4
  [![CI](https://github.com/red-data-tools/GR.rb/workflows/CI/badge.svg)](https://github.com/red-data-tools/GR.rb/actions)
5
- [![Gitter Chat](https://badges.gitter.im/red-data-tools/en.svg)](https://gitter.im/red-data-tools/en)
6
5
  [![Docs Latest](https://img.shields.io/badge/docs-latest-blue.svg)](https://red-data-tools.github.io/GR.rb/)
6
+ [![Lines of Code](https://img.shields.io/endpoint?url=https%3A%2F%2Ftokei.kojix2.net%2Fbadge%2Fgithub%2Fred-data-tools%2FGR.rb%2Flines)](https://tokei.kojix2.net/github/red-data-tools/GR.rb)
7
7
 
8
8
  [![rdatasets-1](https://i.imgur.com/XEQ6wKs.png)](examples/rdatasets.rb)
9
9
  [![stem](https://i.imgur.com/3w0Ejrm.png)](examples/fast_plots.rb)
@@ -21,7 +21,7 @@
21
21
  [![face](https://i.imgur.com/uLCKi2r.png)](examples/face.rb)
22
22
  [![shade](https://i.imgur.com/VJmS3EQ.png)](examples/shade_ex.rb)
23
23
 
24
- :bar_chart: [GR framework](https://github.com/sciapp/gr) - powerful visualization library - for Ruby
24
+ :bar_chart: [GR framework](https://github.com/sciapp/gr) - powerful visualization library - for Ruby
25
25
 
26
26
  ## Installation
27
27
 
@@ -31,7 +31,7 @@ First, [install GR](#gr-installation). Then install [`gr-plot`](https://github.c
31
31
  gem install gr-plot
32
32
  ```
33
33
 
34
- [pkg-config](https://github.com/ruby-gnome/pkg-config) will detect the location of the shared library. Otherwise, you need to specify the environment variable.
34
+ [pkg-config](https://github.com/ruby-gnome/pkg-config) will detect the location of the shared library. Otherwise, you need to specify the environment variable.
35
35
 
36
36
  ```sh
37
37
  export GRDIR="/your/path/to/gr"
@@ -69,7 +69,7 @@ require 'gr/plot'
69
69
  GR.plot(x, y)
70
70
  ```
71
71
 
72
- List of available functions.
72
+ List of available functions.
73
73
 
74
74
  [`plot`](../../wiki/Plotting-functions#plot)
75
75
  [`step`](../../wiki/Plotting-functions#step)
@@ -151,7 +151,7 @@ macOS : See ["How to open apps from un-notarized or unidentified developers"](ht
151
151
 
152
152
  ### Using package managers
153
153
 
154
- The third party GR packages for Mac, Linux and Windows are available for advanced users. However, these packages are provided by OSS volunteers and may not be the latest version or support some features (such as video output). If you find any problem, please report the issue [here](https://github.com/red-data-tools/GR.rb/issues).
154
+ The third party GR packages for Mac, Linux and Windows are available for advanced users. However, these packages are provided by OSS volunteers and may not be the latest version or support some features (such as video output). If you find any problem, please report the issue [here](https://github.com/red-data-tools/GR.rb/issues).
155
155
 
156
156
  #### Mac - Homebrew
157
157
 
@@ -183,12 +183,12 @@ If you are using Rubyinstaller, pacman will automatically install [mingw-w64-gr]
183
183
  GR.rb is a library under development, so even small improvements like fixing typos are welcome!
184
184
  Please feel free to send us your PR.
185
185
 
186
- * [Report bugs](https://github.com/red-data-tools/GR.rb/issues)
187
- * Fix bugs and [submit pull requests](https://github.com/red-data-tools/GR.rb/pulls)
188
- * Write, clarify, or fix documentation
189
- * Suggest or add new features
190
- * Update GR packages ( Homebrew, MinGW, red-data-tools )
191
- * Create visualization tools based on GR.rb
186
+ - [Report bugs](https://github.com/red-data-tools/GR.rb/issues)
187
+ - Fix bugs and [submit pull requests](https://github.com/red-data-tools/GR.rb/pulls)
188
+ - Write, clarify, or fix documentation
189
+ - Suggest or add new features
190
+ - Update GR packages ( Homebrew, MinGW, red-data-tools )
191
+ - Create visualization tools based on GR.rb
192
192
 
193
193
  If you are not familiar with Ruby gem development, please see
194
194
  [I'm new to Ruby](https://github.com/red-data-tools/GR.rb/wiki/I%27m-new-to-Ruby)
data/lib/gr/ffi.rb CHANGED
@@ -65,6 +65,39 @@ module GR
65
65
  'hexbin_2pass_priv_t *priv'
66
66
  ]
67
67
 
68
+ Tick = struct [
69
+ 'double value',
70
+ 'int is_major'
71
+ ]
72
+
73
+ TickLabel = struct [
74
+ 'double tick',
75
+ 'char *label',
76
+ 'double width'
77
+ ]
78
+
79
+ Axis = struct [
80
+ 'double min',
81
+ 'double max',
82
+ 'double tick',
83
+ 'double org',
84
+ 'double position',
85
+ 'int major_count',
86
+ 'int num_ticks',
87
+ 'void *ticks',
88
+ 'double tick_size',
89
+ 'int num_tick_labels',
90
+ 'void *tick_labels',
91
+ 'double label_position',
92
+ 'int draw_axis_line',
93
+ 'int label_orientation'
94
+ ]
95
+
96
+ FormatReference = struct [
97
+ 'char *format',
98
+ 'int length'
99
+ ]
100
+
68
101
  try_extern 'void gr_initgr(void)'
69
102
  try_extern 'int gr_debug(void)'
70
103
  try_extern 'void gr_opengks(void)'
@@ -125,8 +158,8 @@ module GR
125
158
  try_extern 'void gr_inqfillstyle(int *)'
126
159
  try_extern 'void gr_setfillcolorind(int)'
127
160
  try_extern 'void gr_inqfillcolorind(int *)'
128
- try_extern 'void gr_setresizebehaviour(int)'
129
- try_extern 'void gr_inqresizebehaviour(int *)'
161
+ try_extern 'void gr_setnominalsize(double)'
162
+ try_extern 'void gr_inqnominalsize(double *)'
130
163
  try_extern 'void gr_setcolorrep(int, double, double, double)'
131
164
  try_extern 'void gr_setwindow(double, double, double, double)'
132
165
  try_extern 'void gr_inqwindow(double *, double *, double *, double *)'
@@ -212,6 +245,8 @@ module GR
212
245
  try_extern 'char *gr_getgraphics(void)'
213
246
  try_extern 'int gr_drawgraphics(char *)'
214
247
  try_extern 'int gr_startlistener(void)'
248
+ try_extern 'int gr_inqgrplotport(void)'
249
+ try_extern 'int gr_setgrplotport(int)'
215
250
  try_extern 'void gr_mathtex(double, double, char *)'
216
251
  try_extern 'void gr_inqmathtex(double, double, char *, double *, double *)'
217
252
  try_extern 'void gr_mathtex3d(double, double, double, char *, int)'
@@ -223,6 +258,8 @@ module GR
223
258
  try_extern 'void gr_moveselection(double, double)'
224
259
  try_extern 'void gr_resizeselection(int, double, double)'
225
260
  try_extern 'void gr_inqbbox(double *, double *, double *, double *)'
261
+ try_extern 'void gr_setbackground(void)'
262
+ try_extern 'void gr_clearbackground(void)'
226
263
  try_extern 'double gr_precision(void)'
227
264
  try_extern 'int gr_text_maxsize(void)'
228
265
  try_extern 'void gr_setregenflags(int)'
@@ -239,6 +276,7 @@ module GR
239
276
  try_extern 'void gr_trisurface(int, double *, double *, double *)'
240
277
  try_extern 'void gr_gradient(int, int, double *, double *, double *, double *, double *)'
241
278
  try_extern 'void gr_quiver(int, int, double *, double *, double *, double *, int)'
279
+ typealias 'interp2_method_t', 'int'
242
280
  try_extern 'void gr_interp2(int nx, int ny, const double *x, const double *y, const double *z,' \
243
281
  ' int nxq, int nyq, const double *xq, const double *yq, double *zq,' \
244
282
  ' interp2_method_t method, double extrapval)'
@@ -257,6 +295,7 @@ module GR
257
295
  try_extern 'void gr_inqbordercolorind(int *)'
258
296
  try_extern 'void gr_selectclipxform(int)'
259
297
  try_extern 'void gr_inqclipxform(int *)'
298
+ try_extern 'void gr_inqclip(int *, double *)'
260
299
  try_extern 'void gr_setprojectiontype(int)'
261
300
  try_extern 'void gr_inqprojectiontype(int *)'
262
301
  try_extern 'void gr_setperspectiveprojection(double, double, double)'
@@ -303,6 +342,8 @@ module GR
303
342
  try_extern 'void gr_inqmathfont(int *font)'
304
343
  try_extern 'void gr_setclipregion(int region)'
305
344
  try_extern 'void gr_inqclipregion(int *region)'
345
+ try_extern 'void gr_setclipsector(double start_angle, double end_angle)'
346
+ try_extern 'void gr_inqclipsector(double *start_angle, double *end_angle)'
306
347
  try_extern 'void gr_settextoffset(double xoff, double yoff)'
307
348
  try_extern 'char *gr_ftoa(char *string, double value, format_reference_t *reference)'
308
349
  try_extern 'void gr_getformat(format_reference_t *result, double origin, double min, double max, double tick_width, int major)'
data/lib/gr.rb CHANGED
@@ -137,7 +137,7 @@ module GR
137
137
  # * 371 : Gtk
138
138
  # * 380 : wxWidgets
139
139
  # * 381 : Qt4
140
- # * 382 : Scaleable Vector Graphics (SVG)
140
+ # * 382 : Scalable Vector Graphics (SVG)
141
141
  # * 390 : Windows Metafile
142
142
  # * 400 : Quartz
143
143
  # * 410 : Socket driver
@@ -519,7 +519,7 @@ module GR
519
519
  inquiry_int { |pt| super(pt) }
520
520
  end
521
521
 
522
- # Specifiy the marker type for polymarkers.
522
+ # Specify the marker type for polymarkers.
523
523
  #
524
524
  # @param style [Integer] The polymarker marker type
525
525
  # * 1 : MARKERTYPE_DOT - Smallest displayable dot
@@ -732,7 +732,7 @@ module GR
732
732
  # * 3 : TEXT_HALIGN_RIGHT - Right justify
733
733
  #
734
734
  # @param vertical [Integer] Vertical text alignment
735
- # * 0 : TEXT_VALIGN_NORMAL  
735
+ # * 0 : TEXT_VALIGN_NORMAL
736
736
  # * 1 : TEXT_VALIGN_TOP - Align with the top of the characters
737
737
  # * 2 : TEXT_VALIGN_CAP - Aligned with the cap of the characters
738
738
  # * 3 : TEXT_VALIGN_HALF - Aligned with the half line of the characters
@@ -1116,6 +1116,52 @@ module GR
1116
1116
 
1117
1117
  alias axes2d axes
1118
1118
 
1119
+ def axis(option, min: Float::NAN, max: Float::NAN, tick: Float::NAN, org: Float::NAN, position: Float::NAN, major_count: 1,
1120
+ tick_size: Float::NAN, label_position: Float::NAN, draw_axis_line: 1, label_orientation: 0)
1121
+ ax = FFI::Axis.malloc
1122
+ ax.min = min
1123
+ ax.max = max
1124
+ ax.tick = tick
1125
+ ax.org = org
1126
+ ax.position = position
1127
+ ax.major_count = major_count
1128
+ ax.tick_size = tick_size
1129
+ ax.label_position = label_position
1130
+ ax.draw_axis_line = draw_axis_line
1131
+ ax.label_orientation = label_orientation
1132
+ ax.ticks = FFI::Pointer::NULL
1133
+ ax.num_ticks = 0
1134
+ ax.tick_labels = FFI::Pointer::NULL
1135
+ ax.num_tick_labels = 0
1136
+ super(option, ax)
1137
+ ax
1138
+ end
1139
+
1140
+ def drawaxis(option, min: Float::NAN, max: Float::NAN, tick: Float::NAN, org: Float::NAN, position: Float::NAN,
1141
+ major_count: 1, tick_size: Float::NAN, label_position: Float::NAN, draw_axis_line: 1, label_orientation: 0)
1142
+ ax = FFI::Axis.malloc
1143
+ ax.min = min
1144
+ ax.max = max
1145
+ ax.tick = tick
1146
+ ax.org = org
1147
+ ax.position = position
1148
+ ax.major_count = major_count
1149
+ ax.tick_size = tick_size
1150
+ ax.label_position = label_position
1151
+ ax.draw_axis_line = draw_axis_line
1152
+ ax.label_orientation = label_orientation
1153
+ ax.ticks = FFI::Pointer::NULL
1154
+ ax.num_ticks = 0
1155
+ ax.tick_labels = FFI::Pointer::NULL
1156
+ ax.num_tick_labels = 0
1157
+ super(option, ax)
1158
+ ax
1159
+ end
1160
+
1161
+ def drawaxes(x_axis, y_axis, option = 1)
1162
+ super(x_axis, y_axis, option)
1163
+ end
1164
+
1119
1165
  # Create axes in the current workspace and supply a custom function for
1120
1166
  # changing the behaviour of the tick labels.
1121
1167
  #
@@ -1348,9 +1394,10 @@ module GR
1348
1394
  # * 6 SHADED_MESH - Applies light source shading to the 3-D surface
1349
1395
  #
1350
1396
  def surface(x, y, z, option)
1351
- # TODO: check: Arrays have incorrect length or dimension.
1352
1397
  nx = x.length
1353
1398
  ny = y.length
1399
+ raise ArgumentError, "z must have length nx * ny (expected #{nx * ny}, got #{z.length})" if z.length != nx * ny
1400
+
1354
1401
  super(nx, ny, x, y, z, option)
1355
1402
  end
1356
1403
 
@@ -1376,10 +1423,11 @@ module GR
1376
1423
  # of 1000 to `major_h`.
1377
1424
  #
1378
1425
  def contour(x, y, h, z, major_h)
1379
- # TODO: check: Arrays have incorrect length or dimension.
1380
1426
  nx = x.length
1381
1427
  ny = y.length
1382
1428
  nh = h.length
1429
+ raise ArgumentError, "z must have length nx * ny (expected #{nx * ny}, got #{z.length})" if z.length != nx * ny
1430
+
1383
1431
  super(nx, ny, nh, x, y, h, z, major_h)
1384
1432
  end
1385
1433
 
@@ -1401,10 +1449,11 @@ module GR
1401
1449
  # array containing the Z coordinates
1402
1450
  #
1403
1451
  def contourf(x, y, h, z, major_h)
1404
- # TODO: check: Arrays have incorrect length or dimension.
1405
1452
  nx = x.length
1406
1453
  ny = y.length
1407
1454
  nh = h.length
1455
+ raise ArgumentError, "z must have length nx * ny (expected #{nx * ny}, got #{z.length})" if z.length != nx * ny
1456
+
1408
1457
  super(nx, ny, nh, x, y, h, z, major_h)
1409
1458
  end
1410
1459
 
@@ -1416,7 +1465,7 @@ module GR
1416
1465
  # @param levels [Array, NArray] A list of contour levels
1417
1466
  #
1418
1467
  def tricontour(x, y, z, levels)
1419
- npoints = x.length # equal_length ?
1468
+ npoints = equal_length(x, y, z)
1420
1469
  nlevels = levels.length
1421
1470
  super(npoints, x, y, z, nlevels, levels)
1422
1471
  end
@@ -1919,9 +1968,10 @@ module GR
1919
1968
 
1920
1969
  # @deprecated
1921
1970
  def gradient(x, y, z)
1922
- # TODO: check: Arrays have incorrect length or dimension.
1923
1971
  nx = x.length
1924
1972
  ny = y.length
1973
+ raise ArgumentError, "z must have length nx * ny (expected #{nx * ny}, got #{z.length})" if z.length != nx * ny
1974
+
1925
1975
  inquiry [{ double: nx * ny }, { double: nx * ny }] do |pu, pv|
1926
1976
  super(nx, ny, x, y, z, pu, pv)
1927
1977
  end
@@ -1942,9 +1992,12 @@ module GR
1942
1992
  # The values for `x` and `y` are in world coordinates.
1943
1993
  #
1944
1994
  def quiver(x, y, u, v, color)
1945
- # TODO: check: Arrays have incorrect length or dimension.
1946
1995
  nx = x.length
1947
1996
  ny = y.length
1997
+ if u.length != nx * ny || v.length != nx * ny
1998
+ raise ArgumentError, "u and v must have length nx * ny (expected #{nx * ny}, got u: #{u.length}, v: #{v.length})"
1999
+ end
2000
+
1948
2001
  super(nx, ny, x, y, u, v, (color ? 1 : 0))
1949
2002
  end
1950
2003
 
@@ -2419,6 +2472,45 @@ module GR
2419
2472
  n_connections = colors.length
2420
2473
  super(n_points, px, py, pz, n_connections, int(connections), int(colors))
2421
2474
  end
2475
+
2476
+ # @return [Integer]
2477
+ def startlistener
2478
+ inquiry_int do |ret|
2479
+ super(ret)
2480
+ end
2481
+ end
2482
+
2483
+ # @!method setmathfont
2484
+
2485
+ def inqmathfont
2486
+ inquiry_int { |pt| super(pt) }
2487
+ end
2488
+
2489
+ # @!method setclipregion
2490
+
2491
+ def inqclipregion
2492
+ inquiry_int { |pt| super(pt) }
2493
+ end
2494
+
2495
+ # @!method setclipsector
2496
+
2497
+ def inqclipsector
2498
+ inquiry %i[double double] do |*pts|
2499
+ super(*pts)
2500
+ end
2501
+ end
2502
+
2503
+ def getformat(origin, min, max, tick_width, major)
2504
+ ref = FFI::FormatReference.malloc
2505
+ super(ref, origin, min, max, tick_width, major)
2506
+ ref
2507
+ end
2508
+
2509
+ def ftoa(value, format_ref)
2510
+ string = Fiddle::Pointer.malloc(256)
2511
+ super(string, value, format_ref)
2512
+ string.to_s
2513
+ end
2422
2514
  end
2423
2515
 
2424
2516
  ASF_BUNDLED = 0
@@ -2506,12 +2598,29 @@ module GR
2506
2598
  MARKERTYPE_HLINE = -31
2507
2599
  MARKERTYPE_OMARK = -32
2508
2600
 
2601
+ AXES_SIMPLE_AXES = 1
2602
+ AXES_TWIN_AXES = 2
2603
+ AXES_WITH_GRID = 4
2604
+
2605
+ REGION_RECTANGLE = 0
2606
+ REGION_ELLIPSE = 1
2607
+
2509
2608
  OPTION_X_LOG = 1
2510
2609
  OPTION_Y_LOG = 2
2511
2610
  OPTION_Z_LOG = 4
2512
2611
  OPTION_FLIP_X = 8
2513
2612
  OPTION_FLIP_Y = 16
2514
2613
  OPTION_FLIP_Z = 32
2614
+ OPTION_X_LOG2 = 64
2615
+ OPTION_Y_LOG2 = 128
2616
+ OPTION_Z_LOG2 = 256
2617
+ OPTION_X_LN = 512
2618
+ OPTION_Y_LN = 1024
2619
+ OPTION_Z_LN = 2048
2620
+
2621
+ SPEC_LINE = 1
2622
+ SPEC_MARKER = 2
2623
+ SPEC_COLOR = 4
2515
2624
 
2516
2625
  OPTION_LINES = 0
2517
2626
  OPTION_MESH = 1
@@ -2520,6 +2629,7 @@ module GR
2520
2629
  OPTION_COLORED_MESH = 4
2521
2630
  OPTION_CELL_ARRAY = 5
2522
2631
  OPTION_SHADED_MESH = 6
2632
+ OPTION_3D_MESH = 7
2523
2633
 
2524
2634
  MODEL_RGB = 0
2525
2635
  MODEL_HSV = 1
data/lib/gr3.rb CHANGED
@@ -288,7 +288,7 @@ module GR3
288
288
  #
289
289
  # This function does not return an error code, because of its asynchronous
290
290
  # nature. If gr3_getpixmap_() returns a GR3_ERROR_OPENGL_ERR, this might be
291
- # caused by this function saving unuseable data into the draw list.
291
+ # caused by this function saving unusable data into the draw list.
292
292
  #
293
293
  # @param mesh [Integer] The mesh to be drawn
294
294
  # @param n [Integer] The number of meshes to be drawn
@@ -593,6 +593,70 @@ module GR3
593
593
  drawspins(positions, spins, colors)
594
594
  end
595
595
 
596
+ # @!method setalphamode
597
+
598
+ # @return [Integer]
599
+ def getalphamode
600
+ inquiry_int do |mode|
601
+ super(mode)
602
+ end
603
+ end
604
+
605
+ # @!method setlightsources
606
+
607
+ # @return [Integer]
608
+ def getlightsources(max_num_lights = 16)
609
+ positions = GRCommons::Fiddley::MemoryPointer.new(:float, max_num_lights * 3)
610
+ colors = GRCommons::Fiddley::MemoryPointer.new(:float, max_num_lights * 3)
611
+ num_lights = super(max_num_lights, positions, colors)
612
+ # TODO: Return arrays instead of pointers?
613
+ # For now, returning pointers as they might be large?
614
+ # But usually we want ruby objects.
615
+ # Let's convert them to arrays if num_lights > 0
616
+ pos_arr = positions.read_array_of_float(num_lights * 3).each_slice(3).to_a
617
+ col_arr = colors.read_array_of_float(num_lights * 3).each_slice(3).to_a
618
+ [num_lights, pos_arr, col_arr]
619
+ end
620
+
621
+ # @!method setlightparameters
622
+
623
+ # @return [Array<Float>]
624
+ def getlightparameters
625
+ inquiry %i[float float float float] do |ambient, diffuse, specular, specular_power|
626
+ super(ambient, diffuse, specular, specular_power)
627
+ end
628
+ end
629
+
630
+ # @!method setdefaultlightparameters
631
+
632
+ # @!method setclipping
633
+
634
+ # @return [Array<Float>]
635
+ def getclipping
636
+ inquiry %i[float float float float float float] do |xmin, xmax, ymin, ymax, zmin, zmax|
637
+ super(xmin, xmax, ymin, ymax, zmin, zmax)
638
+ end
639
+ end
640
+
641
+ # @!method setsurfaceoption
642
+
643
+ # @return [Integer]
644
+ def getsurfaceoption
645
+ super
646
+ end
647
+
648
+ # @param data [NArray] 3D narray array containing the voxel data
649
+ # @param isovalue [Float] isovalue at which the surface will be created
650
+ # @param color [Array, NArray] the color of the surface
651
+ # @param strides [Array, NArray] the strides in each direction
652
+ def isosurface(data, isovalue = 0.5, color = nil, strides = nil)
653
+ nx, ny, nz = data.shape
654
+ color ||= [1.0, 1.0, 1.0]
655
+ strides ||= [1, 1, 1]
656
+ strides = GRCommons::GRCommonUtils.int(strides)
657
+ super(nx, ny, nz, data, isovalue, color, strides)
658
+ end
659
+
596
660
  # Creates meshes for slices through the given data, using the current GR
597
661
  # colormap. Use the parameters x, y or z to specify what slices should be
598
662
  # drawn and at which positions they should go through the data. If neither
@@ -34,7 +34,7 @@ module GRCommons
34
34
  #
35
35
  # @note Mainly used by developers for debugging.
36
36
  #
37
- # = How it works 
37
+ # = How it works
38
38
  # It prepend a module named Inspector to the singular class of the FFI module.
39
39
  # It will inspects the GR function call of the FFI module
40
40
  #
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GRCommons
4
- VERSION = '0.73.6.0'
4
+ VERSION = '0.73.19.0'
5
5
  end
data/lib/grm/ffi.rb CHANGED
@@ -21,7 +21,7 @@ module GRM
21
21
  # header files.
22
22
 
23
23
  # https://github.com/sciapp/gr/blob/master/lib/grm/include/grm/args.h
24
- try_extern 'grm_args_value_iterator_t *grm_arg_value_iter(const arg_t *arg)'
24
+ try_extern 'grm_args_value_iterator_t *grm_arg_value_iter(const grm_arg_t *arg)'
25
25
  try_extern 'grm_args_t *grm_args_new(void)'
26
26
  try_extern 'void grm_args_delete(grm_args_t *args)'
27
27
  try_extern 'int grm_args_push(grm_args_t *args, const char *key, const char *value_format, ...)'
@@ -39,6 +39,9 @@ module GRM
39
39
  try_extern 'void grm_dump(const grm_args_t *args, FILE *f)'
40
40
  try_extern 'void grm_dump_json(const grm_args_t *args, FILE *f)'
41
41
  try_extern 'char *grm_dump_json_str(void)'
42
+ try_extern 'char *grm_dump_html(char *plot_id)'
43
+ try_extern 'char *grm_dump_html_args(char *plot_id, grm_args_t *args)'
44
+ try_extern 'void grm_dump_bson(const grm_args_t *args, FILE *f)'
42
45
 
43
46
  # https://github.com/sciapp/gr/blob/master/lib/grm/include/grm/event.h
44
47
  typealias 'grm_event_type_t', 'int' # enum
@@ -71,7 +74,7 @@ module GRM
71
74
  try_extern 'int grm_clear(void)'
72
75
  try_extern 'void grm_dump_graphics_tree(FILE *f)'
73
76
  try_extern 'char *grm_dump_graphics_tree_str(void)'
74
- try_extern 'unsigned int grm_max_plotid(void)'
77
+ try_extern 'unsigned int grm_max_plot_id(void)'
75
78
  try_extern 'int grm_merge(const grm_args_t *args)'
76
79
  try_extern 'int grm_merge_extended(const grm_args_t *args, int hold, const char *identificator)'
77
80
  try_extern 'int grm_merge_hold(const grm_args_t *args)'
@@ -81,6 +84,19 @@ module GRM
81
84
  try_extern 'int grm_process_tree(void)'
82
85
  try_extern 'int grm_export(const char *file_path)'
83
86
  try_extern 'int grm_switch(unsigned int id)'
87
+ try_extern 'int grm_get_error_code()'
84
88
  try_extern 'int grm_load_graphics_tree(FILE *file)'
89
+ try_extern 'int grm_validate(void)'
90
+ # The following functions use C++ types that cannot be parsed by Fiddle
91
+ # try_extern 'std::shared_ptr<GRM::Element> grm_get_document_root(void)'
92
+ # try_extern 'std::shared_ptr<GRM::Render> grm_get_render(void)'
93
+ # try_extern 'int grm_iterate_grid(GRM::Grid *grid, const std::shared_ptr<GRM::Element> &parent_dom_element, int plot_id)'
94
+ # try_extern 'int grm_plot_helper(GRM::GridElement *grid_element, GRM::Slice *slice, const std::shared_ptr<GRM::Element> &parent_dom_element, int plot_id)'
95
+ # try_extern 'std::shared_ptr<GRM::Element> grm_get_subplot_from_ndc_point_using_dom(double x, double y)'
96
+ # try_extern 'std::shared_ptr<GRM::Element> grm_get_subplot_from_ndc_points_using_dom(unsigned int n, const double *x, const double *y)'
97
+ # try_extern 'void grm_set_attribute_on_all_subplots(std::string attribute, int value)'
98
+ # try_extern 'int grm_get_focus_and_factor_from_dom(const int x1, const int y1, const int x2, const int y2, const int keep_aspect_ratio, double *factor_x, double *factor_y, double *focus_x, double *focus_y, std::shared_ptr<GRM::Element> &subplot_element)'
99
+ # try_extern 'std::map<std::string, std::list<std::string>> grm_get_context_data()'
100
+ # try_extern 'std::shared_ptr<GRM::Document> grm_load_graphics_tree_schema(bool with_private_attributes = false)'
85
101
  end
86
102
  end
data/lib/grm.rb CHANGED
@@ -67,15 +67,13 @@ module GRM
67
67
  case value
68
68
  when Hash
69
69
  new(**value)
70
- else
71
- nil
72
70
  end
73
71
  end
74
72
  end
75
73
 
76
74
  def initialize(**args)
77
75
  @args = GRM.args_new
78
- @args.free = FFI["grm_args_delete"]
76
+ @args.free = FFI['grm_args_delete']
79
77
  @references = []
80
78
  args.each do |key, value|
81
79
  push(key, value)
@@ -84,44 +82,86 @@ module GRM
84
82
 
85
83
  def push(key, value)
86
84
  key = key.to_s if key.is_a?(Symbol)
85
+
86
+ # Support Numo::NArray transparently when available
87
+ if defined?(Numo::NArray) && value.is_a?(Numo::NArray)
88
+ shape = value.shape
89
+ case shape.length
90
+ when 1
91
+ # 1D NArray: delegate to existing Array handling
92
+ return push(key, value.to_a)
93
+ when 2
94
+ # 2D NArray: convert to nested Array and reuse 2D Array path
95
+ rows, cols = shape
96
+ nested = Array.new(rows) do |r|
97
+ Array.new(cols) do |c|
98
+ value[r, c]
99
+ end
100
+ end
101
+ return push(key, nested)
102
+ else
103
+ raise ArgumentError, "Numo::NArray with dimension > 2 is not supported for key '#{key}'"
104
+ end
105
+ end
106
+
87
107
  case value
88
108
  when String
89
- GRM.args_push(@args, key, "s", :const_string, value)
109
+ GRM.args_push(@args, key, 's', :const_string, value)
90
110
  when Integer
91
- GRM.args_push(@args, key, "i", :int, value)
111
+ GRM.args_push(@args, key, 'i', :int, value)
92
112
  when Float
93
- GRM.args_push(@args, key, "d", :double, value)
113
+ GRM.args_push(@args, key, 'd', :double, value)
94
114
  when Args
95
- GRM.args_push(@args, key, "a", :voidp, value.address)
115
+ GRM.args_push(@args, key, 'a', :voidp, value.address)
96
116
  value.to_gr.free = nil
97
117
  when Array
118
+ raise ArgumentError, "Array value for key '#{key}' cannot be empty" if value.empty?
119
+
120
+ # Handle 2D Array (Matrix): flatten and add dimensions
121
+ if value[0].is_a?(Array)
122
+ rows = value.size
123
+ cols = value[0].size
124
+ # Validate that all rows have the same length
125
+ unless value.all? { |row| row.size == cols }
126
+ raise ArgumentError, "All rows in 2D array for key '#{key}' must have the same length"
127
+ end
128
+
129
+ # Flatten in row-major order
130
+ flattened = value.flatten
131
+
132
+ push(key, flattened)
133
+ # GRM expects dims in [width, height] order (columns, rows)
134
+ push("#{key}_dims", [cols, rows])
135
+ return
136
+ end
137
+
98
138
  case value[0]
99
139
  when String
100
- addresses = value.collect {|v| Fiddle::Pointer[v].to_i}
101
- GRM.args_push(@args, key, "nS",
140
+ addresses = value.collect { |v| Fiddle::Pointer[v].to_i }
141
+ GRM.args_push(@args, key, 'nS',
102
142
  :int, value.size,
103
- :voidp, addresses.pack("J*"))
143
+ :voidp, addresses.pack('J*'))
104
144
  when Integer
105
- GRM.args_push(@args, key, "nI",
145
+ GRM.args_push(@args, key, 'nI',
106
146
  :int, value.size,
107
- :voidp, value.pack("i*"))
147
+ :voidp, value.pack('i*'))
108
148
  when Float
109
- GRM.args_push(@args, key, "nD",
149
+ GRM.args_push(@args, key, 'nD',
110
150
  :int, value.size,
111
- :voidp, value.pack("d*"))
151
+ :voidp, value.pack('d*'))
112
152
  when Args
113
- GRM.args_push(@args, key, "nA",
153
+ GRM.args_push(@args, key, 'nA',
114
154
  :int, value.size,
115
- :voidp, value.collect(&:address).pack("J*"))
155
+ :voidp, value.collect(&:address).pack('J*'))
116
156
  value.each do |v|
117
157
  v.to_gr.free = nil
118
158
  end
119
159
  else
120
- vs = value.collect {|v| Args.new(**v)}
160
+ vs = value.collect { |v| Args.new(**v) }
121
161
  @references.concat(vs)
122
- GRM.args_push(@args, key, "nA",
162
+ GRM.args_push(@args, key, 'nA',
123
163
  :int, value.size,
124
- :voidp, vs.collect(&:address).pack("J*"))
164
+ :voidp, vs.collect(&:address).pack('J*'))
125
165
  vs.each do |v|
126
166
  v.to_gr.free = nil
127
167
  end
@@ -129,7 +169,7 @@ module GRM
129
169
  else
130
170
  v = Args.new(**value)
131
171
  @references << v
132
- GRM.args_push(@args, key, "a", :voidp, v.address)
172
+ GRM.args_push(@args, key, 'a', :voidp, v.address)
133
173
  v.to_gr.free = nil
134
174
  end
135
175
  end
@@ -149,24 +189,29 @@ module GRM
149
189
  end
150
190
 
151
191
  class << self
152
- def merge(args=nil)
153
- super(Args.try_convert(args) || args)
192
+ def merge(args = nil)
193
+ args = Args.try_convert(args) || args
194
+ super(args)
154
195
  end
155
196
 
156
- def merge_extended(args=nil, hold=0, identifiator=nil)
157
- super(Args.try_convert(args) || args, hold, identificator)
197
+ def merge_extended(args = nil, hold = 0, identificator = nil)
198
+ args = Args.try_convert(args) || args
199
+ super(args, hold, identificator)
158
200
  end
159
201
 
160
- def merge_hold(args=nil)
161
- super(Args.try_convert(args) || args)
202
+ def merge_hold(args = nil)
203
+ args = Args.try_convert(args) || args
204
+ super(args)
162
205
  end
163
206
 
164
- def merge_named(args=nil, identifiator=nil)
165
- super(Args.try_convert(args) || args, identificator)
207
+ def merge_named(args = nil, identificator = nil)
208
+ args = Args.try_convert(args) || args
209
+ super(args, identificator)
166
210
  end
167
211
 
168
- def plot(args=nil)
169
- super(Args.try_convert(args) || args)
212
+ def plot(args = nil)
213
+ args = Args.try_convert(args) || args
214
+ super(args)
170
215
  end
171
216
  end
172
217
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-gr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.73.6.0
4
+ version: 0.73.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2024-08-06 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: fiddle
@@ -24,7 +24,7 @@ dependencies:
24
24
  - !ruby/object:Gem::Version
25
25
  version: 1.1.0
26
26
  - !ruby/object:Gem::Dependency
27
- name: numo-narray
27
+ name: numo-narray-alt
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - ">="
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  - !ruby/object:Gem::Version
100
100
  version: '0'
101
101
  requirements: []
102
- rubygems_version: 3.6.0.dev
102
+ rubygems_version: 3.7.2
103
103
  specification_version: 4
104
104
  summary: GR for Ruby
105
105
  test_files: []