rbplotly 0.1.1 → 0.1.2
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 +4 -4
- data/.travis.yml +3 -0
- data/README.md +23 -10
- data/docs/images/line_chart.png +0 -0
- data/examples/Bar Charts.ipynb +254 -0
- data/examples/Basic Usage.ipynb +227 -0
- data/examples/{basic_histogram.ipynb → Histograms.ipynb} +3 -2
- data/examples/Line charts.ipynb +88 -0
- data/examples/Pie Charts.ipynb +151 -0
- data/examples/Scatter Plots.ipynb +224 -0
- data/examples/heatmaps.ipynb +66 -5
- data/lib/plotly/axis.rb +4 -1
- data/lib/plotly/client.rb +13 -8
- data/lib/plotly/data.rb +13 -2
- data/lib/plotly/layout.rb +1 -1
- data/lib/plotly/line.rb +17 -0
- data/lib/plotly/marker.rb +23 -0
- data/lib/plotly/offline/exportable.rb +5 -0
- data/lib/plotly/plot.rb +0 -12
- data/lib/plotly/version.rb +1 -1
- data/rbplotly.gemspec +11 -7
- metadata +41 -24
- data/examples/basic_bar_chart.ipynb +0 -82
- data/examples/basic_pie_chart.ipynb +0 -84
- data/examples/grouped_bar_chart.ipynb +0 -89
- data/examples/line_and_scatter_plots.ipynb +0 -227
- data/examples/stacked_bar_chart.ipynb +0 -89
data/examples/heatmaps.ipynb
CHANGED
@@ -3,6 +3,67 @@
|
|
3
3
|
{
|
4
4
|
"cell_type": "code",
|
5
5
|
"execution_count": 1,
|
6
|
+
"metadata": {
|
7
|
+
"collapsed": false,
|
8
|
+
"scrolled": true
|
9
|
+
},
|
10
|
+
"outputs": [
|
11
|
+
{
|
12
|
+
"data": {
|
13
|
+
"text/html": [
|
14
|
+
"\n",
|
15
|
+
" <script>\n",
|
16
|
+
" requirejs.config({paths: { 'plotly': ['https://cdn.plot.ly/plotly-latest.min'] }})\n",
|
17
|
+
" </script>\n",
|
18
|
+
"\n",
|
19
|
+
"\n",
|
20
|
+
"<div id=\"538b8031-8157-4473-aaab-221d4569c87b\" style=\"height: 100%; width: 100%;\"></div>\n",
|
21
|
+
"\n",
|
22
|
+
"<script>\n",
|
23
|
+
" require(['plotly'], function(Plotly) { \n",
|
24
|
+
"Plotly.newPlot(\n",
|
25
|
+
" '538b8031-8157-4473-aaab-221d4569c87b',\n",
|
26
|
+
" [{\"z\":[[1,20,30],[20,1,60],[30,60,1]],\"type\":\"heatmap\"}],\n",
|
27
|
+
" {},\n",
|
28
|
+
" {\"linkText\":\"Export to plot.ly\",\"showLink\":true}\n",
|
29
|
+
")\n",
|
30
|
+
"\n",
|
31
|
+
"window.addEventListener('resize', function() {\n",
|
32
|
+
" Plotly.Plots.resize(document.getElementById('538b8031-8157-4473-aaab-221d4569c87b'))\n",
|
33
|
+
"})\n",
|
34
|
+
" }) \n",
|
35
|
+
"</script>"
|
36
|
+
],
|
37
|
+
"text/plain": [
|
38
|
+
"#<Plotly::Offline::HTML:0x007ff4ac144a30 @id=\"538b8031-8157-4473-aaab-221d4569c87b\", @data=[{:z=>[[1, 20, 30], [20, 1, 60], [30, 60, 1]], :type=>:heatmap}], @layout={}, @config={:linkText=>\"Export to plot.ly\", :showLink=>true}, @embedded=true>"
|
39
|
+
]
|
40
|
+
},
|
41
|
+
"metadata": {},
|
42
|
+
"output_type": "display_data"
|
43
|
+
}
|
44
|
+
],
|
45
|
+
"source": [
|
46
|
+
"# Basic Heatmap\n",
|
47
|
+
"require 'rbplotly'\n",
|
48
|
+
"\n",
|
49
|
+
"z = [\n",
|
50
|
+
" [1, 20, 30],\n",
|
51
|
+
" [20, 1, 60],\n",
|
52
|
+
" [30, 60, 1]\n",
|
53
|
+
"]\n",
|
54
|
+
"\n",
|
55
|
+
"data = [{\n",
|
56
|
+
" z: z,\n",
|
57
|
+
" type: :heatmap\n",
|
58
|
+
"}]\n",
|
59
|
+
"\n",
|
60
|
+
"plot = Plotly::Plot.new(data: data)\n",
|
61
|
+
"plot.show"
|
62
|
+
]
|
63
|
+
},
|
64
|
+
{
|
65
|
+
"cell_type": "code",
|
66
|
+
"execution_count": 2,
|
6
67
|
"metadata": {
|
7
68
|
"collapsed": false
|
8
69
|
},
|
@@ -16,25 +77,25 @@
|
|
16
77
|
" </script>\n",
|
17
78
|
"\n",
|
18
79
|
"\n",
|
19
|
-
"<div id=\"
|
80
|
+
"<div id=\"30fe907e-b3ae-4b61-ae76-e40bd75080c4\" style=\"height: 100%; width: 100%;\"></div>\n",
|
20
81
|
"\n",
|
21
82
|
"<script>\n",
|
22
83
|
" require(['plotly'], function(Plotly) { \n",
|
23
84
|
"Plotly.newPlot(\n",
|
24
|
-
" '
|
25
|
-
" [{\"
|
85
|
+
" '30fe907e-b3ae-4b61-ae76-e40bd75080c4',\n",
|
86
|
+
" [{\"z\":[[0,6,5,5,3,9,6,6,9,7],[6,3,2,5,9,1,4,6,7,4],[7,6,8,2,1,0,0,1,3,7],[6,8,8,4,3,1,0,8,5,3],[1,2,4,0,2,6,4,2,7,6],[3,2,9,6,2,7,5,6,1,5],[2,0,3,4,4,8,6,9,2,9],[3,5,0,6,7,0,8,6,6,0],[0,8,3,9,7,6,5,0,9,9],[6,4,3,5,2,8,2,8,6,8]],\"type\":\"heatmap\",\"x\":[\"x1\",\"x2\",\"x3\",\"x4\",\"x5\",\"x6\",\"x7\",\"x8\",\"x9\",\"x10\"],\"y\":[\"y1\",\"y2\",\"y3\",\"y4\",\"y5\",\"y6\",\"y7\",\"y8\",\"y9\",\"y10\"]}],\n",
|
26
87
|
" {\"width\":500,\"height\":500},\n",
|
27
88
|
" {\"linkText\":\"Export to plot.ly\",\"showLink\":true}\n",
|
28
89
|
")\n",
|
29
90
|
"\n",
|
30
91
|
"window.addEventListener('resize', function() {\n",
|
31
|
-
" Plotly.Plots.resize(document.getElementById('
|
92
|
+
" Plotly.Plots.resize(document.getElementById('30fe907e-b3ae-4b61-ae76-e40bd75080c4'))\n",
|
32
93
|
"})\n",
|
33
94
|
" }) \n",
|
34
95
|
"</script>"
|
35
96
|
],
|
36
97
|
"text/plain": [
|
37
|
-
"#<Plotly::Offline::HTML:
|
98
|
+
"#<Plotly::Offline::HTML:0x007ff4ac82e0d0 @id=\"30fe907e-b3ae-4b61-ae76-e40bd75080c4\", @data=[{:z=>[[0, 6, 5, 5, 3, 9, 6, 6, 9, 7], [6, 3, 2, 5, 9, 1, 4, 6, 7, 4], [7, 6, 8, 2, 1, 0, 0, 1, 3, 7], [6, 8, 8, 4, 3, 1, 0, 8, 5, 3], [1, 2, 4, 0, 2, 6, 4, 2, 7, 6], [3, 2, 9, 6, 2, 7, 5, 6, 1, 5], [2, 0, 3, 4, 4, 8, 6, 9, 2, 9], [3, 5, 0, 6, 7, 0, 8, 6, 6, 0], [0, 8, 3, 9, 7, 6, 5, 0, 9, 9], [6, 4, 3, 5, 2, 8, 2, 8, 6, 8]], :type=>:heatmap, :x=>[\"x1\", \"x2\", \"x3\", \"x4\", \"x5\", \"x6\", \"x7\", \"x8\", \"x9\", \"x10\"], :y=>[\"y1\", \"y2\", \"y3\", \"y4\", \"y5\", \"y6\", \"y7\", \"y8\", \"y9\", \"y10\"]}], @layout={:width=>500, :height=>500}, @config={:linkText=>\"Export to plot.ly\", :showLink=>true}, @embedded=true>"
|
38
99
|
]
|
39
100
|
},
|
40
101
|
"metadata": {},
|
data/lib/plotly/axis.rb
CHANGED
@@ -4,9 +4,12 @@ module Plotly
|
|
4
4
|
class Axis
|
5
5
|
include Castable
|
6
6
|
|
7
|
-
ATTRS = %i(title range).freeze
|
7
|
+
ATTRS = %i(title range zeroline).freeze
|
8
8
|
attr_accessor(*ATTRS)
|
9
9
|
|
10
|
+
# @option opts [String] title
|
11
|
+
# @option opts [Array] range
|
12
|
+
# @option opts [Boolean] zeroline
|
10
13
|
def initialize(opts)
|
11
14
|
return unless opts.is_a?(Hash)
|
12
15
|
opts.each { |k, v| instance_variable_set("@#{k}", v) }
|
data/lib/plotly/client.rb
CHANGED
@@ -3,14 +3,6 @@ require 'base64'
|
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
module Plotly
|
6
|
-
class << self
|
7
|
-
attr_reader :client
|
8
|
-
|
9
|
-
def auth(username, api_key)
|
10
|
-
@client = Client.new(username, api_key)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
6
|
class Client
|
15
7
|
attr_reader :conn
|
16
8
|
|
@@ -37,4 +29,17 @@ module Plotly
|
|
37
29
|
}
|
38
30
|
end
|
39
31
|
end
|
32
|
+
|
33
|
+
class << self
|
34
|
+
# Set the default client which is automatically used when any clients aren't assigned.
|
35
|
+
def auth(username, api_key)
|
36
|
+
@client = Client.new(username, api_key)
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [Plotly::Client]
|
40
|
+
# @raise [RuntimeError]
|
41
|
+
def client
|
42
|
+
@client ? @client : raise('Authentication required')
|
43
|
+
end
|
44
|
+
end
|
40
45
|
end
|
data/lib/plotly/data.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'plotly/castable'
|
2
|
+
require 'plotly/marker'
|
2
3
|
|
3
4
|
module Plotly
|
4
5
|
class Data
|
5
6
|
include Castable
|
6
7
|
|
7
|
-
attr_accessor :x, :y, :z, :values, :labels, :mode, :type, :name, :colorscale
|
8
|
+
attr_accessor :x, :y, :z, :values, :labels, :mode, :type, :name, :text, :colorscale, :marker
|
8
9
|
|
9
10
|
# @option opts [Array] x
|
10
11
|
# @option opts [Array] y
|
@@ -14,9 +15,19 @@ module Plotly
|
|
14
15
|
# @option opts [String] mode
|
15
16
|
# @option opts [String] type
|
16
17
|
# @option opts [String] name
|
18
|
+
# @option opts [Array] text array of strings
|
17
19
|
# @option opts [Array] colorscale
|
20
|
+
# @option opts [Hash or Plotly::Marker] marker
|
18
21
|
def initialize(opts = {})
|
19
|
-
opts.each
|
22
|
+
opts.each do |k, v|
|
23
|
+
v.convert_to(Plotly::Marker) if k == marker
|
24
|
+
instance_variable_set("@#{k}", v)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def marker=(marker)
|
29
|
+
marker.convert_to(Plotly::Marker)
|
30
|
+
@marker = marker
|
20
31
|
end
|
21
32
|
end
|
22
33
|
end
|
data/lib/plotly/layout.rb
CHANGED
data/lib/plotly/line.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'plotly/castable'
|
2
|
+
|
3
|
+
module Plotly
|
4
|
+
class Line
|
5
|
+
include Castable
|
6
|
+
|
7
|
+
ATTRS = %i(width color).freeze
|
8
|
+
attr_accessor(*ATTRS)
|
9
|
+
|
10
|
+
# @option opts [Fixnum] width
|
11
|
+
# @option opts [String] color 'rgba(0, 0, 200, .5)'
|
12
|
+
def initialize(opts)
|
13
|
+
return unless opts.is_a?(Hash)
|
14
|
+
opts.each { |k, v| instance_variable_set("@#{k}", v) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'plotly/castable'
|
2
|
+
require 'plotly/line'
|
3
|
+
|
4
|
+
module Plotly
|
5
|
+
class Marker
|
6
|
+
include Castable
|
7
|
+
|
8
|
+
ATTRS = %i(size color opacity line).freeze
|
9
|
+
attr_accessor(*ATTRS)
|
10
|
+
|
11
|
+
# @option opts [Fixnum] size
|
12
|
+
# @option opts [String] color e.g.'rgba(0, 0, 200, .5)'
|
13
|
+
# @option opts [Hash or Plotly::Line] line
|
14
|
+
def initialize(opts)
|
15
|
+
return unless opts.is_a?(Hash)
|
16
|
+
|
17
|
+
opts.each do |k, v|
|
18
|
+
v.convert_to(Plotly::Line) if k.to_sym == :line
|
19
|
+
instance_variable_set("@#{k}", v)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/plotly/plot.rb
CHANGED
@@ -21,18 +21,6 @@ module Plotly
|
|
21
21
|
@layout = layout.convert_to(Plotly::Layout)
|
22
22
|
end
|
23
23
|
|
24
|
-
# @param data [Plotly::Data or Hash]
|
25
|
-
def add_data(data = Data.new)
|
26
|
-
@data.push begin
|
27
|
-
case data
|
28
|
-
when Data then data
|
29
|
-
when Hash then Data.new(data)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# @todo add remove_data method
|
35
|
-
|
36
24
|
# @param data [Array] list of Hash or Plotly::Data objects
|
37
25
|
def data=(data)
|
38
26
|
raise unless data.is_a?(Array)
|
data/lib/plotly/version.rb
CHANGED
data/rbplotly.gemspec
CHANGED
@@ -6,10 +6,12 @@ require 'plotly/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'rbplotly'
|
8
8
|
spec.version = Plotly::VERSION
|
9
|
-
spec.authors = ['
|
9
|
+
spec.authors = ['ash1day']
|
10
10
|
spec.email = ['y4ashida@gmail.com']
|
11
11
|
|
12
|
-
spec.summary = '
|
12
|
+
spec.summary = 'a Ruby visualization library'
|
13
|
+
spec.description = 'Rbplotly, a Ruby visualization library, ' \
|
14
|
+
'allows you to create interactive plots.'
|
13
15
|
spec.homepage = 'https://github.com/y4ashida/rbplotly'
|
14
16
|
spec.license = 'MIT'
|
15
17
|
|
@@ -18,14 +20,16 @@ Gem::Specification.new do |spec|
|
|
18
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
21
|
spec.require_paths = ['lib']
|
20
22
|
|
21
|
-
spec.add_dependency 'faraday',
|
22
|
-
spec.add_dependency 'uuidtools',
|
23
|
-
spec.add_dependency 'launchy',
|
23
|
+
spec.add_dependency 'faraday', '~> 0.9'
|
24
|
+
spec.add_dependency 'uuidtools', '~> 2.1'
|
25
|
+
spec.add_dependency 'launchy', '~> 2.4'
|
24
26
|
|
25
27
|
spec.add_development_dependency 'bundler', '~> 1.12'
|
26
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
-
spec.add_development_dependency 'rspec', '~> 3.5'
|
28
28
|
spec.add_development_dependency 'guard-rspec', '~> 4.7'
|
29
29
|
spec.add_development_dependency 'guard-rubocop', '~> 1.2'
|
30
|
+
spec.add_development_dependency 'rake', '~> 11.2'
|
31
|
+
spec.add_development_dependency 'rspec', '~> 3.5'
|
30
32
|
spec.add_development_dependency 'yard', '~> 0.9'
|
33
|
+
|
34
|
+
spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.6'
|
31
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbplotly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- ash1day
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -67,61 +67,61 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.12'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: guard-rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '4.7'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '4.7'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: guard-rubocop
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '1.2'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '1.2'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: rake
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '11.2'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '11.2'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: rspec
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '3.5'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
124
|
+
version: '3.5'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: yard
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,7 +136,22 @@ dependencies:
|
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0.9'
|
139
|
-
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: codeclimate-test-reporter
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0.6'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0.6'
|
153
|
+
description: Rbplotly, a Ruby visualization library, allows you to create interactive
|
154
|
+
plots.
|
140
155
|
email:
|
141
156
|
- y4ashida@gmail.com
|
142
157
|
executables: []
|
@@ -156,19 +171,21 @@ files:
|
|
156
171
|
- bin/console
|
157
172
|
- bin/setup
|
158
173
|
- docs/images/line_chart.png
|
159
|
-
- examples/
|
160
|
-
- examples/
|
161
|
-
- examples/
|
162
|
-
- examples/
|
174
|
+
- examples/Bar Charts.ipynb
|
175
|
+
- examples/Basic Usage.ipynb
|
176
|
+
- examples/Histograms.ipynb
|
177
|
+
- examples/Line charts.ipynb
|
178
|
+
- examples/Pie Charts.ipynb
|
179
|
+
- examples/Scatter Plots.ipynb
|
163
180
|
- examples/heatmaps.ipynb
|
164
|
-
- examples/line_and_scatter_plots.ipynb
|
165
|
-
- examples/stacked_bar_chart.ipynb
|
166
181
|
- lib/plotly/axis.rb
|
167
182
|
- lib/plotly/castable.rb
|
168
183
|
- lib/plotly/client.rb
|
169
184
|
- lib/plotly/data.rb
|
170
185
|
- lib/plotly/exportable.rb
|
171
186
|
- lib/plotly/layout.rb
|
187
|
+
- lib/plotly/line.rb
|
188
|
+
- lib/plotly/marker.rb
|
172
189
|
- lib/plotly/offline/exportable.rb
|
173
190
|
- lib/plotly/offline/html.rb
|
174
191
|
- lib/plotly/offline/plotly.min.js
|
@@ -199,8 +216,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
216
|
version: '0'
|
200
217
|
requirements: []
|
201
218
|
rubyforge_project:
|
202
|
-
rubygems_version: 2.5.
|
219
|
+
rubygems_version: 2.5.2
|
203
220
|
signing_key:
|
204
221
|
specification_version: 4
|
205
|
-
summary:
|
222
|
+
summary: a Ruby visualization library
|
206
223
|
test_files: []
|