red-amber-view 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fb5e2459c607b9309c170cc4c430daac7ad37072cb26d847d1978d5b5e0eae79
4
+ data.tar.gz: b138596f32935e9a3260c7bd09be8ef3a9f536e9d86951d5809894ea848063e4
5
+ SHA512:
6
+ metadata.gz: 063342bee50e06fca844511043d2097e7a069325ba262fd555a94bd86efd56e00ec54c174ca83eeb59b6be18c3e34af67abd6f5c82508fda715322e1fd38dccb
7
+ data.tar.gz: eb1192290089a706c3e639d9e8cb8d2cf6d393c7999f85dae2b5cb48c1f62663424b42dde05a92517d9dca16c8b0320ce72774292d78b5db4a77965a5d58a93e
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 kojix2
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # RedAmber View
2
+
3
+ R's `View()` for [RedAmber](https://github.com/heronshoes/red_amber).
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ gem install red-amber-view
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```ruby
14
+ require 'red_amber/view'
15
+ require 'datasets-arrow'
16
+
17
+ arrow = Datasets::Penguins.new.to_arrow
18
+ penguins = RedAmber::DataFrame.new(arrow)
19
+ penguins.view
20
+ ```
21
+
22
+ ![screenshot](https://user-images.githubusercontent.com/5798442/177008662-5a3bb1c2-fbd3-48ea-8f1a-fa3164002a08.png)
23
+
24
+
25
+
26
+ ## Contributing
27
+
28
+ RedAmber View is a library under development, so even small improvements like typofix are welcome! Please feel free to send us your pull requests.
29
+
30
+ ## License
31
+
32
+ MIT
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'libui'
4
+ require 'arrow'
5
+
6
+ WINDOW_TITLE = 'RedAmber View'
7
+ WINDOW_WIDTH = 600
8
+ WINDOW_HEIGHT = 400
9
+
10
+ ARROW_PATH = ARGV[0]
11
+ rm_arrow_file = proc { File.exist?(ARROW_PATH) && File.delete(ARROW_PATH) }
12
+ at_exit(&rm_arrow_file)
13
+
14
+ LibUI.init
15
+
16
+ main_window = LibUI.new_window(WINDOW_TITLE, WINDOW_WIDTH, WINDOW_HEIGHT, 1)
17
+
18
+ hbox = LibUI.new_horizontal_box
19
+ LibUI.window_set_child(main_window, hbox)
20
+
21
+ arrow_table = Arrow::Table.load(ARROW_PATH)
22
+ ncol = arrow_table.n_columns
23
+ nrow = arrow_table.n_rows
24
+
25
+ # Protects BlockCaller objects from garbage collection.
26
+ @block_callers = []
27
+ def rbcallback(*args, &block)
28
+ args << [0] if args.size == 1 # Argument types are ommited
29
+ block_caller = Fiddle::Closure::BlockCaller.new(*args, &block)
30
+ @block_callers << block_caller
31
+ block_caller
32
+ end
33
+
34
+ model_handler = LibUI::FFI::TableModelHandler.malloc
35
+ model_handler.to_ptr.free = Fiddle::RUBY_FREE
36
+ model_handler.NumColumns = rbcallback(4) { ncol }
37
+ model_handler.ColumnType = rbcallback(4) { 0 }
38
+ model_handler.NumRows = rbcallback(4) { nrow }
39
+ model_handler.CellValue = rbcallback(1, [1, 1, 4, 4]) do |_, _, row, column|
40
+ str = arrow_table.get_column_data(column)[row].to_s
41
+ LibUI.new_table_value_string(str)
42
+ end
43
+ model_handler.SetCellValue = rbcallback(0, [0]) {}
44
+
45
+ model = LibUI.new_table_model(model_handler)
46
+
47
+ table_params = LibUI::FFI::TableParams.malloc
48
+ table_params.to_ptr.free = Fiddle::RUBY_FREE
49
+ table_params.Model = model
50
+ table_params.RowBackgroundColorModelColumn = -1
51
+
52
+ table = LibUI.new_table(table_params)
53
+ arrow_table.columns.map.with_index do |column, i|
54
+ name = column.name.to_s
55
+ LibUI.table_append_text_column(table, name, i, -1)
56
+ end
57
+
58
+ LibUI.box_append(hbox, table, 1)
59
+ LibUI.control_show(main_window)
60
+
61
+ LibUI.window_on_closing(main_window) do
62
+ rm_arrow_file.call
63
+ LibUI.control_destroy(main_window)
64
+ LibUI.free_table_model(model)
65
+ LibUI.quit
66
+ 0
67
+ end
68
+
69
+ LibUI.main
70
+ LibUI.quit
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'red_amber/view/version'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'red_amber/view'
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RedAmber
4
+ module View
5
+ VERSION = '0.0.0'
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'red_amber'
4
+ require_relative 'view/version'
5
+
6
+ module RedAmber
7
+ module View
8
+ DataFrame.include(self)
9
+
10
+ def view
11
+ require 'securerandom'
12
+ rand = SecureRandom.hex(10)
13
+ path = "/dev/shm/red-amber-view-#{rand}.arrow"
14
+ while File.exist? path
15
+ path = "/dev/shm/red-amber-view-#{rand}.arrow"
16
+ end
17
+ to_arrow.save(path)
18
+ arrow_table_viewer = File.expand_path('../../exe/arrow_table_view.rb', __dir__)
19
+ pid = spawn("ruby #{arrow_table_viewer} #{path}")
20
+ Process.detach(pid)
21
+ end
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: red-amber-view
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - kojix2
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-07-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: libui
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: red_amber
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: red-arrow
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: A Data Viewer for RedAmber. Opens a window and displays a spreadsheet-like
56
+ table.
57
+ email:
58
+ - 2xijok@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - LICENSE.txt
64
+ - README.md
65
+ - exe/arrow_table_view.rb
66
+ - lib/red-amber/view.rb
67
+ - lib/red-amber/view/version.rb
68
+ - lib/red_amber/view.rb
69
+ - lib/red_amber/view/version.rb
70
+ homepage: https://github.com/kojix2/red-amber-view
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubygems_version: 3.3.7
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: A Data Viewer for RedAmber
93
+ test_files: []