iruby-plotly 1.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.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/Readme.md +25 -0
  4. data/lib/iruby-plotly.rb +31 -0
  5. metadata +46 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 39e21b7352c532c23c7586e559e752584932b310a07bf9f62ab7cbec141af0ec
4
+ data.tar.gz: 2fea50df0c43deba80f85c1fb33fda74957cc441c2571b613eed9a9b89bc503b
5
+ SHA512:
6
+ metadata.gz: 55afce27d77044f5ccdc4eb358b485f14a90466c782edbc7ad4263071b00ab2f93d01811581367baee1e0162878c728f2c78ce99b202a9b3be69f4ba1c15b820
7
+ data.tar.gz: 980506987c4b727d395125c99cf357c87516b0402f4b493cb8aeb58556ef219d74af14831881fb26cbfee404546e4e78d855fd17c5c734d386d5118e5831e197
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Zachary Capalbo
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/Readme.md ADDED
@@ -0,0 +1,25 @@
1
+ # iruby-plotly
2
+
3
+ A shim to support using [Plotly](https://plot.ly/) in IRuby Jupyter notebooks.
4
+
5
+ Usage:
6
+
7
+ ```ruby
8
+ require 'iruby-plotly'
9
+
10
+ IRuby.plotly([{y: [1,2,5,20]}])
11
+ ```
12
+
13
+ or (convenience method)
14
+
15
+ ```ruby
16
+ IRuby.plot([1,2,5,20])
17
+ ```
18
+
19
+ or (convenience method)
20
+
21
+ ```ruby
22
+ IRuby.plot(y: [1,2, 5, 20], x: [0,1,2,3])
23
+ ```
24
+
25
+ ![Example Output](example.png)
@@ -0,0 +1,31 @@
1
+ module IRuby
2
+ DEFAULT_PLOT_HEIGHT = 800
3
+ module Display
4
+ class << self
5
+ def protect(mime, data)
6
+ return data if mime == 'application/vnd.plotly.v1+json'
7
+ MimeMagic.new(mime).text? ? data.to_s : [data.to_s].pack('m0')
8
+ end
9
+ end
10
+ end
11
+
12
+ def self.plot(data, options = {})
13
+ if data.respond_to?(:keys)
14
+ options = options.merge(data)
15
+ if data.include?(:xy) then
16
+ data = data.clone
17
+ data[:x] = data[:xy].map(&:first)
18
+ data[:y] = data[:xy].map(&:last)
19
+ data.delete(:xy)
20
+ end
21
+ data = [data]
22
+ elsif not data.first.respond_to?(:keys)
23
+ data = [{y:data, x:(1..data.size).to_a}.merge(options)]
24
+ end
25
+ IRuby.convert({data: data, layout: options.merge({height: DEFAULT_PLOT_HEIGHT})}, mime: "application/vnd.plotly.v1+json")
26
+ end
27
+
28
+ def self.plotly(data, layout = {})
29
+ IRuby.convert({data: data, layout: layout}, mime: "application/vnd.plotly.v1+json")
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iruby-plotly
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Zach Capalbo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Plot with IRuby
14
+ email: zach.geek@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - LICENSE
20
+ - Readme.md
21
+ - lib/iruby-plotly.rb
22
+ homepage: https://github.com/zach-capalbo/irub-plotly
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.7.7
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Plotting shim for IRuby & Plotly
46
+ test_files: []