statsailr 0.7.3 → 0.7.4

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: f43e60b39aac689fdb11d44e9210bca2dbc001c45bb2af91bfd7f4aaf030d8d2
4
- data.tar.gz: 10df046a557a751c27a1555a04366c5a8da06641b2aa6b3516b04b95ce37e81c
3
+ metadata.gz: 0f27292effff5ace93fcbae7cecd0a62615450ff496ba1c2bdc03b3824894a56
4
+ data.tar.gz: 7a13e3905398a04bde7f3dd0719576bcfc92a6b95b62e2a34071eca9db0086c0
5
5
  SHA512:
6
- metadata.gz: c58978325f14ed1d462f6647c56a1bae7d0b60103de26a65112b1050746312cb24179c8ea12568b58e7ac919682146aa753b58a8b3cb06e1a98750bf2763bb44
7
- data.tar.gz: 7180c9aee4851fd67cfbf6f4857bc2b23d821d3003d4afea715b7a620399a90e4e1d756d6937effa5f93969771c53a0bb6fecae7e6281c5f19054bc76a1ccac8
6
+ metadata.gz: 356f45dd828c22c84071879e6d0a9a16ec215adf5f3894d37b6a292a6189dde7e211a12aea4697e5695a21cc8d6848c57ae5156d263b035c5b2eed667abb7300
7
+ data.tar.gz: 1f94bb8192f0af9d20ee9a79600a8db9278d17c4a323da274e8aad6e6ad3318368d070422fd30c631da75ac845773810708999d92a066ebcff0e2dce9bb8be59
@@ -26,34 +26,54 @@ def self.initial_setting_for_r(device_info)
26
26
  RBridge.exec_function_no_return(attach_widget_func)
27
27
  @new_device_info = { "file_output" => false, "dev_off_required" => false }
28
28
 
29
- when "cairoraster" # (e.g.) ["CairoRaster", {"width" => 800, "height" => 600, "dev.copy_opt" => {"dir_path"=> dir_to_save , "prefix"=> "plot", "type" => "png"} }]
29
+ when "cairoraster" # (e.g.) ["CairoRaster", {"width" => 800, "height" => 600 }, {"file_output_opt" => {"dir_path"=> dir_to_save , "prefix"=> "plot", "type" => "png"} }]
30
30
  puts "Use Cairo function in Cairo library"
31
31
  if ! device_info[1].is_a?(Hash)
32
32
  raise "The second element of device info needs to be Hash"
33
33
  end
34
- cairo_info = device_info[1]
35
- if ! ["png", "jpeg"].include? cairo_info["dev.copy_opt"]["type"]
34
+ cairo_info = device_info[1].dup
35
+ file_output_opt = device_info[2]["file_output_opt"]
36
+ if ! ["png", "jpeg"].include? file_output_opt["type"]
36
37
  raise "only png or jpeg is supported for type"
37
38
  else
38
- case cairo_info["dev.copy_opt"]["type"]
39
+ case file_output_opt["type"]
39
40
  when "png"
40
41
  # load png library
41
42
  lib_func = RBridge.create_library_function("png")
42
43
  RBridge.exec_function_no_return(lib_func)
43
44
  when "jpeg"
44
45
  # use default jpeg device
46
+ lib_func = RBridge.create_library_function("jpeg")
47
+ RBridge.exec_function_no_return(lib_func)
45
48
  end
46
49
  end
47
50
  lib_func = RBridge.create_library_function("Cairo")
48
51
  RBridge.exec_function_no_return(lib_func)
49
- new_cairo_device_func = RBridge.create_function_call("Cairo", { "width" => RBridge.create_intvec([ cairo_info["width"] ]),
50
- "height" => RBridge.create_intvec([ cairo_info["height"] ]),
51
- "type" => RBridge.create_strvec([ "raster" ]) })
52
- RBridge.exec_function_no_return(new_cairo_device_func)
53
- @new_device_info = { "file_output" => true, "dev_off_required" => true ,
54
- "opt" => cairo_info["dev.copy_opt"].merge( {
55
- "device_func" => RBridge::SymbolR.new( cairo_info["dev.copy_opt"]["type"] ).to_r_symbol,
56
- "default_width" => cairo_info["width"], "default_height" => cairo_info["height"]})}
52
+
53
+ @new_device_info = { "file_output" => true, "dev_off_required" => true ,"file_output_opt" => file_output_opt,
54
+ "dev_control" => {
55
+ "new" => lambda {
56
+ RBridge.exec_function_no_return(
57
+ RBridge.create_function_call("Cairo",
58
+ { "width" => RBridge.create_intvec([ cairo_info["width"] ]),
59
+ "height" => RBridge.create_intvec([ cairo_info["height"] ]),
60
+ "type" => RBridge.create_strvec([ "raster" ]) }))
61
+ },
62
+ "off" => lambda {
63
+ RBridge.exec_function_no_return(
64
+ RBridge.create_function_call("dev.off", {}))
65
+ },
66
+ "get_size" => lambda {
67
+ {:width => cairo_info["width"], :height => cairo_info["height"]}
68
+ },
69
+ "set_size" => lambda {|width, height|
70
+ cairo_info["width"] = width
71
+ cairo_info["height"] = height
72
+ }
73
+ }
74
+ }
75
+ @new_device_info["dev_control"]["new"].call()
76
+
57
77
  else
58
78
  puts "Unknown device type: #{device_type}"
59
79
  end
@@ -253,17 +273,29 @@ blocks.each(){|blk|
253
273
  else
254
274
  if @new_device_info["file_output"] == true
255
275
  # The plot needs to be saved on disk.
256
- dev_info_opt = @new_device_info["opt"]
276
+ file_output_opt = @new_device_info["file_output_opt"]
257
277
  temp_path = ""
258
- temp_file = Tempfile.new( [dev_info_opt["prefix"] , "." + dev_info_opt["type"] ] , dev_info_opt["dir_path"] )
278
+ temp_file = Tempfile.new( [file_output_opt["prefix"] , "." + file_output_opt["type"] ] , file_output_opt["dir_path"] )
259
279
  temp_path = temp_file.path
260
280
  temp_file.close(true)
261
- dev_copy_func = RBridge::create_function_call("dev.copy", { "device" => dev_info_opt["device_func"], "file" => RBridge::create_strvec([temp_path]),
262
- "width" => RBridge::create_intvec( [dev_info_opt["default_width"]] ),
263
- "height" => RBridge::create_intvec( [dev_info_opt["default_height"]] ) })
264
- RBridge::exec_function_no_return(dev_copy_func)
265
- dev_off_func = RBridge::create_function_call("dev.off", {})
266
- RBridge::exec_function_no_return(dev_off_func)
281
+
282
+ if ["png", "jpeg" ].include? file_output_opt["type"]
283
+ # writePNG( image=Cairo.capture( device=dev.cur() ), target="./plot.png" )
284
+ r_func_curr_dev = RBridge::create_function_call("dev.cur", {})
285
+ r_func_cairo_capture = RBridge::create_function_call("Cairo.capture",{"device" => r_func_curr_dev})
286
+ r_str_file_path = RBridge::create_strvec([temp_path])
287
+ if file_output_opt["type"] == "png"
288
+ r_func_write_png = RBridge::create_function_call("writePNG", {"image" => r_func_cairo_capture, "target" => r_str_file_path })
289
+ RBridge::exec_function_no_return( r_func_write_png )
290
+ elsif file_output_opt["type"] == "jpeg"
291
+ r_func_write_jpeg = RBridge::create_function_call("writeJPEG", {"image" => r_func_cairo_capture, "target" => r_str_file_path })
292
+ RBridge::exec_function_no_return( r_func_write_jpeg )
293
+ end
294
+ end
295
+
296
+ @new_device_info["dev_control"]["off"].call()
297
+ @new_device_info["dev_control"]["new"].call()
298
+
267
299
  if(File.exist? temp_path)
268
300
  output_mngr.add_new_message(:plot_file).set_content( temp_path )
269
301
  end
@@ -1,3 +1,3 @@
1
1
  module StatSailr
2
- VERSION = "0.7.3"
2
+ VERSION = "0.7.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statsailr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toshihiro Umehara
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-22 00:00:00.000000000 Z
11
+ date: 2021-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: r_bridge