ruby-gr 0.0.24 → 0.61.0.0

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: 54882caa13673ab79c5589d9ba8fcd02d3fef5adb0b2ad820e4aa75dc6894273
4
- data.tar.gz: 5d57cc79475d98ac75c4fef19d3af024085774ca835978b79d878fb49873e267
3
+ metadata.gz: bacbabae072c86f3b7b227a82043d4ff8e0aaad4df9da3234582270491790d4c
4
+ data.tar.gz: 033e92c26281e32cc5b4a9d42d79c56953fac00b1da5a9479b472ce94f77c995
5
5
  SHA512:
6
- metadata.gz: 5b22d5d24b5fba2fa5f806543cc513e4a4d12f7d416f7aa94b3378b7deccef5974dcaf0454afd6e0bfcb6a07322ea6fce71067c9da4eb3b7188f680e0affbf3d
7
- data.tar.gz: 4fef6ebc51e3ff253e59017c85c8d8d9ac2a56c8000a628944603c4e3645365283a403e09dbec0a7fe654353cd8f418bcfa8fbf9e5f3cd37de11eaee2b900d3a
6
+ metadata.gz: f181ff21a1254fd0791ec2e8862586be634b2ecdb4e5bec76298e22b5bf7dd59e727159cfc9c9b2fde6fc739b99cb889f25041b3592dad93ca2c1b183cb8153e
7
+ data.tar.gz: b4441cc2dbc8f2e7067d80c13407feff556f8fcb5cdb993b936df797ccfd8edd67c9db98a17fff9bf62c7a2f546877e065ba38f6bd0752e2d743473c5cbbeebd
data/LICENSE.txt CHANGED
@@ -1,7 +1,7 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019 kojix2
4
- Copyright (c) 2019 Red Data Tools
3
+ Copyright (c) 2019 - present kojix2
4
+ Copyright (c) 2019 - present Red Data Tools
5
5
 
6
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # GR.rb
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/ruby-gr.svg)](https://badge.fury.io/rb/ruby-gr)
3
+ [![Gem Version](https://img.shields.io/gem/v/ruby-gr?color=brightgreen)](https://rubygems.org/gems/ruby-gr)
4
+ [![CI](https://github.com/red-data-tools/GR.rb/workflows/CI/badge.svg)](https://github.com/red-data-tools/GR.rb/actions)
4
5
  [![Gitter Chat](https://badges.gitter.im/red-data-tools/en.svg)](https://gitter.im/red-data-tools/en)
5
6
  [![Docs Latest](https://img.shields.io/badge/docs-latest-blue.svg)](https://rubydoc.info/gems/ruby-gr)
6
7
 
@@ -31,16 +32,15 @@ First, [install GR](#gr-installation). Then install `ruby-gr` gem.
31
32
  ```sh
32
33
  gem install ruby-gr
33
34
  ```
35
+ Note: If you are using [RubyInstaller](https://rubyinstaller.org/) (Windows), pacman will automatically install [mingw-w64-gr](https://packages.msys2.org/base/mingw-w64-gr).
34
36
 
35
- Note: If you are using Rubyinstaller(Windows), pacman will automatically install [mingw-w64-gr](https://packages.msys2.org/base/mingw-w64-gr).
36
-
37
- Set environment variable `GRDIR`.
37
+ Set environment variable `GRDIR`.
38
38
 
39
39
  ```sh
40
40
  export GRDIR="/your/path/to/gr"
41
41
  ```
42
42
 
43
- If you use package managers to install GR, [pkg-config](https://github.com/ruby-gnome/pkg-config) may automatically detect the shared library location without specifying the `GRDIR` environment variable.
43
+ If you use package managers to install GR, [pkg-config](https://github.com/ruby-gnome/pkg-config) may automatically detect the shared library location without specifying the `GRDIR` environment variable.
44
44
 
45
45
  ## Quick Start
46
46
 
@@ -79,7 +79,7 @@ GR.plot(
79
79
  )
80
80
  ```
81
81
 
82
- Save in PNG format.
82
+ Save the figure in PNG format.
83
83
 
84
84
  ```ruby
85
85
  GR.savefig("figure.png")
@@ -87,17 +87,17 @@ GR.savefig("figure.png")
87
87
 
88
88
  ## API Overview
89
89
 
90
- There are two different approaches to plotting with GR.rb. One way is to call Matlab-like APIs. The other is to call GR/GR3 native functions.
90
+ There are two different approaches when plotting with GR.rb. One is to call Matlab-like APIs. The other is to call GR/GR3 native functions.
91
91
 
92
- #### GR::Plot - A simple, matlab-style API.
92
+ #### GR::Plot - A simple, matlab-style API.
93
93
 
94
94
  ```ruby
95
95
  require 'gr/plot'
96
96
  GR.plot(x, y)
97
97
  ```
98
98
 
99
- List of vailable functions. See [GR.rb Wiki](https://github.com/red-data-tools/GR.rb/wiki) for details.
100
- Some GR module methods are overridden.
99
+ Below are a list of available functions. See [GR.rb Wiki](https://github.com/red-data-tools/GR.rb/wiki) for details.
100
+ Some GR module methods are overwritten.
101
101
 
102
102
  [`plot`](../../wiki/Plotting-functions#plot)
103
103
  [`step`](../../wiki/Plotting-functions#step)
@@ -123,8 +123,6 @@ Some GR module methods are overridden.
123
123
  [`imshow`](../../wiki/Plotting-functions#imshow)
124
124
  [`isosurface`](../../wiki/Plotting-functions#isosurface)
125
125
 
126
- We are planning to prepare 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,13 +146,23 @@ 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)
154
162
  - [GR Framework](https://gr-framework.org/)
155
163
  - [GR.rb API Documentation](https://rubydoc.info/gems/ruby-gr)
156
164
 
157
- Although GR.rb adds methods dynamically, we try our best to provide a complete yard document. However, if you want to see more up-to-date information, we recommend using the official GR reference.
165
+ Although GR.rb adds methods dynamically, we try our best to provide a complete yard document. If you want to see more up-to-date information, we recommend using the official GR reference.
158
166
 
159
167
  ## GR Installation
160
168
 
@@ -168,13 +176,13 @@ Set environment variable GRDIR.
168
176
  export GRDIR="your/path/to/gr"
169
177
  ```
170
178
 
171
- * 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.
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
 
175
183
  * The third party GR packages for Mac, Linux and Windows are available (for advanced users).
176
184
  * If you find any problem, please report the issue [here](https://github.com/red-data-tools/GR.rb/issues).
177
- * Note: These packages may not have some features, for example, video output.
185
+ * Note: These packages may not have some features such as video output.
178
186
 
179
187
  #### Mac - Homebrew
180
188
 
@@ -182,20 +190,29 @@ export GRDIR="your/path/to/gr"
182
190
  brew install libgr
183
191
  ```
184
192
 
185
- #### Linux - APT Yum
193
+ Set the workstation type to gksqt.
186
194
 
187
- [packages.red-data-tools.org](https://github.com/red-data-tools/packages.red-data-tools.org) provides `libgr-dev`, `libgr3-dev` and `libgrm-dev`
195
+ ```sh
196
+ export GKS_WSTYPE=411 # gksqt (recommended)
197
+ ```
188
198
 
189
- ### Windows - MSYS2
199
+ #### Linux - openSUSE Build service
190
200
 
191
- If you are using Rubyinstaller, pacman will automatically install [mingw-w64-gr](https://packages.msys2.org/base/mingw-w64-gr) when the gem is installed.
201
+ GR releases are also available from the [openSUSE Build service](https://software.opensuse.org//download.html?project=science%3Agr-framework&package=gr) for CentOS, Debian, Fedora openSUSE and Ubuntu. Obtain a packaged release [here](https://software.opensuse.org//download.html?project=science%3Agr-framework&package=gr).
192
202
 
193
- ## Backend for Charty
203
+ ```sh
204
+ export GRDIR="/usr/gr" # Check the location with `dpkg -L gr`
205
+ ```
194
206
 
195
- GR.rb will be the default backend for [Charty](https://github.com/red-data-tools/charty).
207
+ #### Windows - MSYS2
208
+
209
+ 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.
196
210
 
197
211
  ## Contributing
198
212
 
213
+ GR.rb is a library under development, so even small improvements like fixing typos are welcome!
214
+ Please feel free to send us your PR.
215
+
199
216
  * [Report bugs](https://github.com/red-data-tools/GR.rb/issues)
200
217
  * Fix bugs and [submit pull requests](https://github.com/red-data-tools/GR.rb/pulls)
201
218
  * Write, clarify, or fix documentation
@@ -203,7 +220,22 @@ GR.rb will be the default backend for [Charty](https://github.com/red-data-tools
203
220
  * Update GR packages ( Homebrew, MinGW, red-data-tools )
204
221
  * Create visualization tools based on GR.rb
205
222
 
223
+ To get started with development:
224
+
225
+ ```sh
226
+ git clone https://github.com/red-data-tools/GR.rb
227
+ cd GR.rb
228
+ bundle install
229
+ bundle exec rake test
230
+ ```
231
+
232
+ * [I'm new to Ruby](https://github.com/red-data-tools/GR.rb/wiki/I%27m-new-to-Ruby)
233
+
234
+ ## Future plans
235
+
236
+ * Creating a backend for [Charty](https://github.com/red-data-tools/charty).
237
+ * [Object-oriented interface](https://github.com/kojix2/GRUtils.rb) based on [GRUtils.jl](https://github.com/heliosdrm/GRUtils.jl).
238
+
206
239
  ## Acknowledgements
207
240
 
208
241
  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.
209
-
data/lib/gr/ffi.rb CHANGED
@@ -15,7 +15,7 @@ module GR
15
15
  raise LoadError, 'Could not find GR Framework'
16
16
  end
17
17
 
18
- extend GRCommons::Extern
18
+ extend GRCommons::TryExtern
19
19
 
20
20
  # https://github.com/sciapp/gr/blob/master/lib/gr/gr.h
21
21
  # keep same order
@@ -41,6 +41,8 @@ module GR
41
41
  'int, int, int, int, int, int, int *)'
42
42
  try_extern 'void gr_polarcellarray(double, double, double, double, double, double, ' \
43
43
  'int, int, int, int, int, int, int *)'
44
+ try_extern 'void gr_nonuniformpolarcellarray(double, double, double *, double *, ' \
45
+ 'int, int, int, int, int, int, int *);'
44
46
  try_extern 'void gr_gdp(int, double *, double *, int, int, int *)'
45
47
  try_extern 'void gr_spline(int, double *, double *, int, int)'
46
48
  try_extern 'void gr_gridit(int, double *, double *, double *, int, int, ' \
@@ -115,6 +117,7 @@ module GR
115
117
  try_extern 'void gr_setcolormap(int)'
116
118
  try_extern 'void gr_inqcolormap(int *)'
117
119
  try_extern 'void gr_setcolormapfromrgb(int n, double *r, double *g, double *b, double *x)'
120
+ try_extern 'void gr_inqcolormapinds(int *, int *)'
118
121
  try_extern 'void gr_colorbar(void)'
119
122
  try_extern 'void gr_inqcolor(int, int *)'
120
123
  try_extern 'int gr_inqcolorfromrgb(double, double, double)'
@@ -182,6 +185,8 @@ module GR
182
185
  try_extern 'void gr_inqborderwidth(double *)'
183
186
  try_extern 'void gr_setbordercolorind(int)'
184
187
  try_extern 'void gr_inqbordercolorind(int *)'
188
+ try_extern 'void gr_selectclipxform(int)'
189
+ try_extern 'void gr_inqclipxform(int *);'
185
190
  try_extern 'void gr_setprojectiontype(int)'
186
191
  try_extern 'void gr_inqprojectiontype(int *)'
187
192
  try_extern 'void gr_setperspectiveprojection(double, double, double)'
@@ -202,6 +207,15 @@ module GR
202
207
  try_extern 'void gr_inqtext3d(double, double, double, char *, int axis, double *, double *)'
203
208
  try_extern 'void gr_settextencoding(int)'
204
209
  try_extern 'void gr_inqtextencoding(int *)'
210
+ try_extern 'void gr_loadfont(char *, int *)'
205
211
  # gr_setcallback(char *(*)(const char *));
212
+ try_extern 'void gr_setthreadnumber(int)'
213
+ try_extern 'void gr_setpicturesizeforvolume(int, int)'
214
+ try_extern 'void gr_setvolumebordercalculation(int)'
215
+ try_extern 'void gr_setapproximativecalculation(int)'
216
+ try_extern 'void gr_inqvolumeflags(int *, int *, int *, int *, int *)'
217
+ try_extern 'void gr_cpubasedvolume(int, int, int, double *, int, double *, double *, double *, double *)'
218
+ try_extern 'void gr_inqvpsize(int *, int *, double *)'
219
+ try_extern 'void gr_polygonmesh3d(int, const double *, const double *, const double *, int, const int *, const int *)'
206
220
  end
207
221
  end
data/lib/gr/plot.rb CHANGED
@@ -33,17 +33,17 @@ module GR
33
33
  # Plot kinds conform to GR.jl
34
34
  PLOT_KIND = %i[line step scatter stem hist contour contourf hexbin heatmap
35
35
  nonuniformheatmap wireframe surface plot3 scatter3 imshow
36
- isosurface polar polarhist polarheatmap trisurf tricont shade
37
- volume].freeze # the name might be changed in the future.
36
+ isosurface polar polarhist polarheatmap nonuniformpolarheatmap
37
+ trisurf tricont shade volume].freeze
38
38
 
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 nbins
43
- ratio rotation scale size spec subplot tilt title update xaxis
44
- xflip xform xlabel xlim xlog xrange xticks yaxis yflip ylabel
45
- ylim ylog zflip yrange yticks viewport vp where window zaxis
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,
@@ -78,8 +78,7 @@ module GR
78
78
  zapfchancery_mediumitalic: 130,
79
79
  zapfdingbats: 131,
80
80
  cmuserif_math: 232, # original: cmuserif-math
81
- dejavusans: 233,
82
- pingfangsc: 234
81
+ dejavusans: 233
83
82
  }.freeze
84
83
 
85
84
  @last_plot = nil
@@ -90,7 +89,8 @@ module GR
90
89
  attr_accessor :args, :kvs, :scheme
91
90
 
92
91
  def initialize(*raw_args)
93
- @kvs = raw_args.last.is_a?(Hash) ? raw_args.pop : {}
92
+ # Keywords are cloned to avoid disruptive changes
93
+ @kvs = raw_args.last.is_a?(Hash) ? raw_args.pop.clone : {}
94
94
  @args = plot_args(raw_args) # method name is the same as Julia/Python
95
95
 
96
96
  # Check keyword options.
@@ -153,15 +153,20 @@ module GR
153
153
  vp1, vp2, vp3, vp4 = vp
154
154
  end
155
155
 
156
- viewport = [vp1 + 0.125 * (vp2 - vp1),
157
- vp1 + 0.925 * (vp2 - vp1),
158
- vp3 + 0.125 * (vp4 - vp3),
159
- vp3 + 0.925 * (vp4 - vp3)]
160
-
161
- if %i[contour contourf hexbin heatmap nonuniformheatmap polarheatmap
162
- surface trisurf volume].include?(kind)
163
- viewport[1] -= 0.1
164
- end
156
+ left_margin = kvs.has_key?(:ylabel) ? 0.05 : 0
157
+ right_margin = if %i[contour contourf hexbin heatmap nonuniformheatmap polarheatmap
158
+ nonuniformpolarheatmap surface trisurf volume].include?(kind)
159
+ (vp2 - vp1) * 0.1
160
+ else
161
+ 0
162
+ end
163
+ bottom_margin = kvs.has_key?(:xlabel) ? 0.05 : 0
164
+ top_margin = kvs.has_key?(:title) ? 0.075 : 0
165
+
166
+ viewport = [vp1 + (0.075 + left_margin) * (vp2 - vp1),
167
+ vp1 + (0.95 - right_margin) * (vp2 - vp1),
168
+ vp3 + (0.075 + bottom_margin) * (vp4 - vp3),
169
+ vp3 + (0.975 - top_margin) * (vp4 - vp3)]
165
170
 
166
171
  if %i[line step scatter stem].include?(kind) && kvs[:labels]
167
172
  location = kvs[:location] || 1
@@ -193,7 +198,7 @@ module GR
193
198
  GR.restorestate
194
199
  end
195
200
 
196
- if %i[polar polarhist polarheatmap].include? kind
201
+ if %i[polar polarhist polarheatmap nonuniformpolarheatmap].include? kind
197
202
  xmin, xmax, ymin, ymax = viewport
198
203
  xcenter = 0.5 * (xmin + xmax)
199
204
  ycenter = 0.5 * (ymin + ymax)
@@ -204,7 +209,7 @@ module GR
204
209
 
205
210
  def set_window(kind)
206
211
  scale = 0
207
- unless %i[polar polarhist polarheatmap].include?(kind)
212
+ unless %i[polar polarhist polarheatmap nonuniformpolarheatmap].include?(kind)
208
213
  scale |= GR::OPTION_X_LOG if kvs[:xlog]
209
214
  scale |= GR::OPTION_Y_LOG if kvs[:ylog]
210
215
  scale |= GR::OPTION_Z_LOG if kvs[:zlog]
@@ -219,11 +224,11 @@ module GR
219
224
  kvs[:xrange] = [xmin, xmax]
220
225
  kvs[:yrange] = [ymin, ymax]
221
226
  else
222
- minmax
227
+ minmax(kind)
223
228
  end
224
229
 
225
230
  major_count = if %i[wireframe surface plot3 scatter3 polar polarhist
226
- polarheatmap trisurf volume].include?(kind)
231
+ polarheatmap nonuniformpolarheatmap trisurf volume].include?(kind)
227
232
  2
228
233
  else
229
234
  5
@@ -239,15 +244,15 @@ module GR
239
244
  xmax += 0.5
240
245
  end
241
246
  xtick, majorx = if (scale & GR::OPTION_X_LOG) == 0
242
- unless %i[heatmap polarheatmap].include?(kind)
243
- unless kvs.has_key?(:xlim)
244
- xmin, xmax = GR.adjustlimits(xmin, xmax) unless kvs[:panzoom]
245
- end
247
+ if !%i[heatmap polarheatmap].include?(kind) &&
248
+ !kvs.has_key?(:xlim) &&
249
+ !kvs[:panzoom]
250
+ xmin, xmax = GR.adjustlimits(xmin, xmax)
246
251
  end
247
252
  if kvs.has_key?(:xticks)
248
253
  kvs[:xticks]
249
254
  else
250
- [GR.tick(xmin, xmax) / major_count, major_count]
255
+ [auto_tick(xmin, xmax) / major_count, major_count]
251
256
  end
252
257
  else
253
258
  [1, 1]
@@ -268,15 +273,15 @@ module GR
268
273
  end
269
274
  end
270
275
  ytick, majory = if (scale & GR::OPTION_Y_LOG) == 0
271
- unless %i[heatmap polarheatmap].include?(kind)
272
- unless kvs.has_key?(:ylim)
273
- ymin, ymax = GR.adjustlimits(ymin, ymax) unless kvs[:panzoom]
274
- end
276
+ if !%i[heatmap polarheatmap].include?(kind) &&
277
+ !kvs.has_key?(:ylim) &&
278
+ !kvs[:panzoom]
279
+ ymin, ymax = GR.adjustlimits(ymin, ymax)
275
280
  end
276
281
  if kvs.has_key?(:yticks)
277
282
  kvs[:yticks]
278
283
  else
279
- [GR.tick(ymin, ymax) / major_count, major_count]
284
+ [auto_tick(ymin, ymax) / major_count, major_count]
280
285
  end
281
286
  else
282
287
  [1, 1]
@@ -291,7 +296,7 @@ module GR
291
296
  if kvs.has_key?(:zticks)
292
297
  kvs[:zticks]
293
298
  else
294
- [GR.tick(zmin, zmax) / major_count, major_count]
299
+ [auto_tick(zmin, zmax) / major_count, major_count]
295
300
  end
296
301
  else
297
302
  [1, 1]
@@ -301,15 +306,16 @@ module GR
301
306
  end
302
307
 
303
308
  kvs[:window] = xmin, xmax, ymin, ymax
304
- if %i[polar polarhist polarheatmap].include?(kind)
309
+ if %i[polar polarhist polarheatmap nonuniformpolarheatmap trisurf].include?(kind)
305
310
  GR.setwindow(-1, 1, -1, 1)
306
311
  else
307
312
  GR.setwindow(xmin, xmax, ymin, ymax)
308
313
  end
309
314
  if %i[wireframe surface plot3 scatter3 trisurf volume].include?(kind)
310
315
  rotation = kvs[:rotation] || 40
311
- tilt = kvs[:tilt] || 70
312
- GR.setspace(zmin, zmax, rotation, tilt)
316
+ tilt = kvs[:tilt] || 60
317
+ GR.setwindow3d(xmin, xmax, ymin, ymax, zmin, zmax)
318
+ GR.setspace3d(-rotation, tilt, 30, 0)
313
319
  end
314
320
 
315
321
  kvs[:scale] = scale
@@ -319,7 +325,7 @@ module GR
319
325
  def draw_axes(kind, pass = 1)
320
326
  viewport = kvs[:viewport]
321
327
  vp = kvs[:vp]
322
- ratio = kvs[:ratio]
328
+ _ratio = kvs[:ratio]
323
329
  xtick, xorg, majorx = kvs[:xaxis]
324
330
  ytick, yorg, majory = kvs[:yaxis]
325
331
  drawgrid = kvs.has_key?(:grid) ? kvs[:grid] : true
@@ -328,10 +334,10 @@ module GR
328
334
  GR.setlinecolorind(1)
329
335
  diag = Math.sqrt((viewport[1] - viewport[0])**2 + (viewport[3] - viewport[2])**2)
330
336
  GR.setlinewidth(1)
331
- charheight = [0.018 * diag, 0.012].max
332
- GR.setcharheight(charheight)
333
337
  ticksize = 0.0075 * diag
334
338
  if %i[wireframe surface plot3 scatter3 trisurf volume].include?(kind)
339
+ charheight = [0.024 * diag, 0.012].max
340
+ GR.setcharheight(charheight)
335
341
  ztick, zorg, majorz = kvs[:zaxis]
336
342
  if pass == 1 && drawgrid
337
343
  GR.grid3d(xtick, 0, ztick, xorg[0], yorg[1], zorg[0], 2, 0, 2)
@@ -341,6 +347,8 @@ module GR
341
347
  GR.axes3d(0, ytick, 0, xorg[1], yorg[0], zorg[0], 0, majory, 0, ticksize)
342
348
  end
343
349
  else
350
+ charheight = [0.018 * diag, 0.012].max
351
+ GR.setcharheight(charheight)
344
352
  if %i[heatmap nonuniformheatmap shade].include?(kind)
345
353
  ticksize = -ticksize
346
354
  elsif drawgrid
@@ -423,7 +431,7 @@ module GR
423
431
  GR.setcharheight(charheight)
424
432
  GR.setlinetype(GR::LINETYPE_SOLID)
425
433
 
426
- tick = 0.5 * GR.tick(rmin, rmax)
434
+ tick = auto_tick(rmin, rmax)
427
435
  n = ((rmax - rmin) / tick + 0.5).round
428
436
  (n + 1).times do |i|
429
437
  r = i.to_f / n
@@ -585,7 +593,7 @@ module GR
585
593
  charheight = [0.016 * diag, 0.012].max
586
594
  GR.setcharheight(charheight)
587
595
  if kvs[:scale] & GR::OPTION_Z_LOG == 0
588
- ztick = 0.5 * GR.tick(zmin, zmax)
596
+ ztick = auto_tick(zmin, zmax)
589
597
  GR.axes(0, ztick, 1, zmin, 0, 1, 0.005)
590
598
  else
591
599
  GR.setscale(GR::OPTION_Y_LOG)
@@ -617,12 +625,17 @@ module GR
617
625
  if kvs.has_key?(:font)
618
626
  name = kvs[:font]
619
627
  # 'Cmuserif-Math' => :cmuserif_math
620
- sym_name = name.to_s.gsub('-','_').downcase.to_sym
628
+ sym_name = name.to_s.gsub('-', '_').downcase.to_sym
621
629
  if FONTS.include?(sym_name)
622
630
  font = FONTS[sym_name]
623
631
  GR.settextfontprec(font, font > 200 ? 3 : 0)
624
632
  else
625
- warn "Unknown font name: #{name}" # should raise error?
633
+ font = GR.loadfont(name)
634
+ if font >= 0
635
+ GR.settextfontprec(font, 3)
636
+ else
637
+ warn "Unknown font name: #{name}"
638
+ end
626
639
  end
627
640
  else
628
641
  # The following fonts are the default in GR.jl
@@ -636,7 +649,7 @@ module GR
636
649
  set_window(kind)
637
650
  if %i[polar polarhist].include?(kind)
638
651
  draw_polar_axes
639
- elsif !%i[imshow isosurface polarheatmap].include?(kind)
652
+ elsif !%i[imshow isosurface polarheatmap nonuniformpolarheatmap].include?(kind)
640
653
  draw_axes(kind)
641
654
  end
642
655
  end
@@ -657,8 +670,12 @@ module GR
657
670
 
658
671
  when :line
659
672
  mask = GR.uselinespec(spec)
660
- GR.polyline(x, y) if hasline(mask)
661
- GR.polymarker(x, y) if hasmarker(mask)
673
+ linewidth = kvs[:linewidth]
674
+ # Slightly different from Julia,
675
+ # Because the implementation of polyline and polymarker is different.
676
+ z ||= linewidth # FIXME
677
+ GR.polyline(x, y, z, c) if hasline(mask)
678
+ GR.polymarker(x, y, z, c) if hasmarker(mask)
662
679
 
663
680
  when :step
664
681
  mask = GR.uselinespec(spec)
@@ -694,20 +711,9 @@ module GR
694
711
 
695
712
  when :scatter
696
713
  GR.setmarkertype(GR::MARKERTYPE_SOLID_CIRCLE)
697
- if z || c
698
- if c
699
- cmin, cmax = kvs[:crange]
700
- c = c.map { |i| normalize_color(i, cmin, cmax) }
701
- cind = c.map { |i| (1000 + i * 255).round }
702
- end
703
- x.length.times do |i|
704
- GR.setmarkersize(z[i] / 100.0) if z
705
- GR.setmarkercolorind(cind[i]) if c
706
- GR.polymarker([x[i]], [y[i]])
707
- end
708
- else
709
- GR.polymarker(x, y)
710
- end
714
+ z = z&.map { |i| i * 0.01 }
715
+ c = c&.map { |i| normalize_color(i, *kvs[:crange]) }
716
+ GR.polymarker(x, y, z, c)
711
717
 
712
718
  when :stem
713
719
  GR.setlinecolorind(1)
@@ -757,7 +763,7 @@ module GR
757
763
  GR.fillarc(-ρ[i], ρ[i], -ρ[i], ρ[i], θ[i - 1], θ[i])
758
764
  end
759
765
 
760
- when :polarheatmap
766
+ when :polarheatmap, :nonuniformpolarheatmap
761
767
  w, h = z.shape
762
768
  cmap = colormap
763
769
  cmin, cmax = kvs[:zrange]
@@ -766,7 +772,15 @@ module GR
766
772
  data.reverse(axis: 1) if kvs[:yflip]
767
773
  colors = data * 255 + 1000
768
774
  colors = colors.transpose # Julia is column major
769
- GR.polarcellarray(0, 0, 0, 360, 0, 1, w, h, colors)
775
+ case kind
776
+ when :polarheatmap
777
+ GR.polarcellarray(0, 0, 0, 360, 0, 1, w, h, colors)
778
+ when :nonuniformpolarheatmap
779
+ ymax = y.max.to_f
780
+ ρ = y.map { |i| i / ymax }
781
+ θ = x.map { |i| i * 180 / Math::PI }
782
+ GR.nonuniformpolarcellarray(θ, ρ, w, h, colors)
783
+ end
770
784
  draw_polar_axes
771
785
  kvs[:zrange] = [cmin, cmax]
772
786
  colorbar
@@ -788,7 +802,7 @@ module GR
788
802
  zmin = kvs[:zlim].first if kvs[:zlim].first
789
803
  zmax = kvs[:zlim].last if kvs[:zlim].last
790
804
  end
791
-
805
+ GR.setprojectiontype(0)
792
806
  GR.setspace(zmin, zmax, 0, 90)
793
807
  levels = kvs[:levels] || 0
794
808
  clabels = kvs[:clabels] || false
@@ -1023,7 +1037,7 @@ module GR
1023
1037
 
1024
1038
  def to_svg
1025
1039
  ## Need IRuby improvemend.
1026
- GR.show(false) if ENV['GKSwstype'] == 'svg'
1040
+ GR.show(false) if ENV['GKS_WSTYPE'] == 'svg'
1027
1041
  end
1028
1042
 
1029
1043
  private
@@ -1096,8 +1110,8 @@ module GR
1096
1110
 
1097
1111
  # Normalize a color c with the range [cmin, cmax]
1098
1112
  # 0 <= normalize_color(c, cmin, cmax) <= 1
1099
- # Note: narray.map{|i| normalize_color(i)} There's room for speedup.
1100
1113
  def normalize_color(c, cmin, cmax)
1114
+ # NOTE: narray.map{|i| normalize_color(i)} There's room for speedup.
1101
1115
  c = c.to_f # if c is Integer
1102
1116
  c = c.clamp(cmin, cmax) - cmin
1103
1117
  c /= (cmax - cmin) if cmin != cmax
@@ -1134,7 +1148,7 @@ module GR
1134
1148
  [a, b]
1135
1149
  end
1136
1150
 
1137
- def minmax
1151
+ def minmax(kind)
1138
1152
  xmin = ymin = zmin = cmin = Float::INFINITY
1139
1153
  xmax = ymax = zmax = cmax = -Float::INFINITY
1140
1154
  scale = kvs[:scale]
@@ -1147,6 +1161,9 @@ module GR
1147
1161
  x0, x1 = x.minmax
1148
1162
  xmin = [x0, xmin].min
1149
1163
  xmax = [x1, xmax].max
1164
+ elsif kind == :volume
1165
+ xmin = -1
1166
+ xmax = 1
1150
1167
  else
1151
1168
  xmin = 0
1152
1169
  xmax = 1
@@ -1158,6 +1175,9 @@ module GR
1158
1175
  y0, y1 = y.minmax
1159
1176
  ymin = [y0, ymin].min
1160
1177
  ymax = [y1, ymax].max
1178
+ elsif kind == :volume
1179
+ ymin = -1
1180
+ ymax = 1
1161
1181
  else
1162
1182
  ymin = 0
1163
1183
  ymax = 1
@@ -1199,6 +1219,21 @@ module GR
1199
1219
  end
1200
1220
  end
1201
1221
 
1222
+ def to_wc(wn)
1223
+ xmin, ymin = GR.ndctowc(wn[0], wn[2])
1224
+ xmax, ymax = GR.ndctowc(wn[1], wn[3])
1225
+ [xmin, xmax, ymin, ymax]
1226
+ end
1227
+
1228
+ def auto_tick(amin, amax)
1229
+ scale = 10.0**Math.log10(amax - amin).truncate
1230
+ tick_size = [5.0, 2.0, 1.0, 0.5, 0.2, 0.1, 0.05, 0.02, 0.01]
1231
+ i = tick_size.find_index do |tsize|
1232
+ ((amax - amin) / scale / tsize) > 7 # maximum number of tick marks
1233
+ end
1234
+ tick_size[i - 1] * scale
1235
+ end
1236
+
1202
1237
  def legend_size
1203
1238
  scale = GR.inqscale
1204
1239
  GR.selntran(0)
@@ -1285,6 +1320,20 @@ module GR
1285
1320
  end
1286
1321
  end
1287
1322
 
1323
+ # (Plot) Draw a nonuniformpolarheatmap.
1324
+ def nonuniformpolarheatmap(*args)
1325
+ # FIXME
1326
+ args, kv = format_xyzc(*args)
1327
+ _x, _y, z = args
1328
+ ysize, xsize = z.shape
1329
+ z = z.reshape(xsize, ysize)
1330
+ create_plot(:nonuniformpolarheatmap, kv) do |plt|
1331
+ plt.kvs[:xlim] ||= [0.5, xsize + 0.5]
1332
+ plt.kvs[:ylim] ||= [0.5, ysize + 0.5]
1333
+ plt.args = [[(1..xsize).to_a, (1..ysize).to_a, z, nil, '']]
1334
+ end
1335
+ end
1336
+
1288
1337
  alias _contour_ contour
1289
1338
  # (Plot) Draw a contour plot.
1290
1339
  def contour(*args)