plotlyrb 0.2.0 → 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.
- checksums.yaml +7 -7
- data/README.md +24 -9
- data/lib/plotlyrb/grid.rb +3 -4
- data/lib/plotlyrb/plot.rb +16 -4
- data/lib/plotlyrb/plot_image.rb +11 -7
- data/lib/plotlyrb/version.rb +1 -1
- data/plotlyrb.gemspec +1 -1
- metadata +47 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bbae35cc7f8a221bfc10e1aa0871f4c69c67de9b
|
4
|
+
data.tar.gz: e4bc1e4abf9805be288eacc211047449460d6267
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 30250a5b1591d455506f78e5dc98e5c8f210dbc1bb4ca92d7e890727c7672155505593df790c065111f2c43531ca493e683a96d5d9da0e42f485364cd576aec1
|
7
|
+
data.tar.gz: 1cf7735bd3af867c2cc80dd2044feff6593123e258c65113b06a28e1fdcd8b449771e1b35f70bcdd441c7e2cf4180e935cf935ef401863d61596d3abc394c85e
|
data/README.md
CHANGED
@@ -31,22 +31,37 @@ Or install it yourself as:
|
|
31
31
|
```ruby
|
32
32
|
require 'plotlyrb'
|
33
33
|
|
34
|
-
data
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
# NOTE: data argument must be an array of traces
|
35
|
+
data = [
|
36
|
+
{
|
37
|
+
:x => ['2013-10-04 22:23:00', '2013-11-04 22:23:00', '2013-12-04 22:23:00'],
|
38
|
+
:y => [1, 3, 6],
|
39
|
+
:type => 'scatter',
|
40
|
+
:mode => 'markers',
|
41
|
+
:name => 'Andrew M'
|
42
|
+
},
|
43
|
+
{
|
44
|
+
:x => ['2013-10-04 22:23:00', '2013-11-04 22:23:00', '2013-12-04 22:23:00'],
|
45
|
+
:y => [3, 4, 9],
|
46
|
+
:type => 'scatter'
|
47
|
+
:name => 'Andrew N'
|
48
|
+
}
|
49
|
+
]
|
40
50
|
|
41
51
|
layout = {
|
42
52
|
:xaxis => { :title => 'times' },
|
43
|
-
:yaxis => { :title => '
|
53
|
+
:yaxis => { :title => 'pokemon caught', :range => [0, 7] },
|
54
|
+
}
|
55
|
+
|
56
|
+
plot_spec = {
|
57
|
+
:figure => {:data => data},
|
58
|
+
:layout => layout,
|
59
|
+
:format => :svg
|
44
60
|
}
|
45
61
|
|
46
62
|
plotly = Plotlyrb::ApiV2.auth_plotly('username', 'super secret API key')
|
47
63
|
|
48
|
-
|
49
|
-
plotly.plot_image([data], '/path/to/plot.svg', :svg, layout)
|
64
|
+
plotly.plot_image(plot_spec, '/path/to/plot.svg')
|
50
65
|
```
|
51
66
|
|
52
67
|
## TODO
|
data/lib/plotlyrb/grid.rb
CHANGED
@@ -9,12 +9,11 @@ module Plotlyrb
|
|
9
9
|
@https.use_ssl = true
|
10
10
|
end
|
11
11
|
|
12
|
-
# data is a hash that mirrors the format of the
|
12
|
+
# data is a hash that mirrors the format of the hash in the API
|
13
13
|
# https://api.plot.ly/v2/grids#create
|
14
|
-
def create(
|
15
|
-
payload = {:data => data}.to_json
|
14
|
+
def create(grid_spec)
|
16
15
|
request = Net::HTTP::Post.new(ApiV2::GRIDS.path, @headers)
|
17
|
-
request.body =
|
16
|
+
request.body = grid_spec.to_json
|
18
17
|
Response.from_http_response(@https.request(request))
|
19
18
|
end
|
20
19
|
end
|
data/lib/plotlyrb/plot.rb
CHANGED
@@ -14,20 +14,32 @@ module Plotlyrb
|
|
14
14
|
# column names (must appear in grid), and a layout. Extracts the column references from the
|
15
15
|
# grid response to populate the xsrc # and ysrc fields in data.
|
16
16
|
# See https://api.plot.ly/v2/plots#create
|
17
|
-
def create_from_grid(
|
17
|
+
def create_from_grid(plot_spec, grid_json)
|
18
18
|
grid_response_body = JSON.parse(grid_json)
|
19
|
+
return Response.fail('No :figure key in plot spec') unless plot_spec.has_key?(:figure)
|
20
|
+
unless plot_spec[:figure].has_key?(:data)
|
21
|
+
return Response.fail('No :data key at {:figure => {:data => ...}} in plot spec')
|
22
|
+
end
|
23
|
+
|
19
24
|
begin
|
20
|
-
payload_data = data.map { |d|
|
25
|
+
payload_data = plot_spec[:figure][:data].map { |d|
|
26
|
+
self.class.replace_column_names_with_uids(grid_response_body, d)
|
27
|
+
}
|
21
28
|
rescue => e
|
22
29
|
return Response.fail(e.to_s)
|
23
30
|
else
|
24
|
-
payload =
|
31
|
+
payload = self.class.replace_data_in_spec(plot_spec, payload_data)
|
25
32
|
request = Net::HTTP::Post.new(ApiV2::PLOTS.path, @headers)
|
26
|
-
request.body = payload
|
33
|
+
request.body = payload.to_json
|
27
34
|
Response.from_http_response(@https.request(request))
|
28
35
|
end
|
29
36
|
end
|
30
37
|
|
38
|
+
def self.replace_data_in_spec(spec, new_data)
|
39
|
+
new_figure = spec[:figure].merge({:data => new_data})
|
40
|
+
spec.merge({:figure => new_figure})
|
41
|
+
end
|
42
|
+
|
31
43
|
def self.replace_column_names_with_uids(response_body, trace_data)
|
32
44
|
raise('No :xsrc key in trace data') unless trace_data.has_key?(:xsrc)
|
33
45
|
raise('No :ysrc key in trace data') unless trace_data.has_key?(:ysrc)
|
data/lib/plotlyrb/plot_image.rb
CHANGED
@@ -12,14 +12,18 @@ module Plotlyrb
|
|
12
12
|
@https.use_ssl = true
|
13
13
|
end
|
14
14
|
|
15
|
-
def plot_image(
|
16
|
-
raise
|
17
|
-
|
15
|
+
def plot_image(plot_image_spec, image_path)
|
16
|
+
raise 'No :format key in spec' unless plot_image_spec.has_key?(:format)
|
17
|
+
raise 'No :figure key in spec' unless plot_image_spec.has_key?(:figure)
|
18
|
+
raise ':data key not found at {:figure => {:data => ...}}' unless plot_image_spec[:figure].has_key?(:data)
|
19
|
+
|
20
|
+
image_format = plot_image_spec[:format]
|
21
|
+
raise "Image format #{image_format} not supported" unless VALID_IMAGE_FORMATS.include?(image_format.to_sym)
|
22
|
+
|
18
23
|
request = Net::HTTP::Post.new(ApiV2::IMAGES.path, @headers)
|
19
|
-
request.body =
|
24
|
+
request.body = plot_image_spec.to_json
|
20
25
|
response = @https.request(request)
|
21
|
-
|
22
|
-
IO.binwrite(image_path_with_ext, response.body)
|
26
|
+
IO.binwrite(image_path, response.body)
|
23
27
|
end
|
24
28
|
end
|
25
|
-
end
|
29
|
+
end
|
data/lib/plotlyrb/version.rb
CHANGED
data/plotlyrb.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
18
|
# delete this section to allow pushing this gem to any host.
|
19
19
|
if spec.respond_to?(:metadata)
|
20
|
-
spec.metadata['allowed_push_host'] = "
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
21
|
else
|
22
22
|
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
23
|
end
|
metadata
CHANGED
@@ -1,48 +1,53 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: plotlyrb
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Veitch Lister Consulting
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2016-10-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
version: "1.11"
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
22
20
|
type: :development
|
23
|
-
version_requirements: *id001
|
24
|
-
- !ruby/object:Gem::Dependency
|
25
|
-
name: rake
|
26
21
|
prerelease: false
|
27
|
-
|
28
|
-
requirements:
|
29
|
-
- - ~>
|
30
|
-
- !ruby/object:Gem::Version
|
31
|
-
version:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
32
34
|
type: :development
|
33
|
-
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
34
41
|
description: Trying to complete a complete API based on the Python Library https://github.com/plotly/plotly.py/tree/master/plotly/plotly
|
35
|
-
email:
|
42
|
+
email:
|
36
43
|
- developers@veitchlister.com.au
|
37
44
|
executables: []
|
38
|
-
|
39
|
-
extensions:
|
45
|
+
extensions:
|
40
46
|
- ext/mkrf_conf.rb
|
41
47
|
extra_rdoc_files: []
|
42
|
-
|
43
|
-
|
44
|
-
- .
|
45
|
-
- .ruby-version
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- ".ruby-version"
|
46
51
|
- CODE_OF_CONDUCT.md
|
47
52
|
- Gemfile
|
48
53
|
- Gemfile.lock
|
@@ -62,32 +67,28 @@ files:
|
|
62
67
|
- lib/plotlyrb/version.rb
|
63
68
|
- plotlyrb.gemspec
|
64
69
|
homepage: https://github.com/vlc/plotlyrb
|
65
|
-
licenses:
|
70
|
+
licenses:
|
66
71
|
- MIT
|
67
|
-
metadata:
|
68
|
-
allowed_push_host:
|
72
|
+
metadata:
|
73
|
+
allowed_push_host: https://rubygems.org
|
69
74
|
post_install_message:
|
70
75
|
rdoc_options: []
|
71
|
-
|
72
|
-
require_paths:
|
76
|
+
require_paths:
|
73
77
|
- lib
|
74
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
-
requirements:
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
76
80
|
- - ">="
|
77
|
-
- !ruby/object:Gem::Version
|
81
|
+
- !ruby/object:Gem::Version
|
78
82
|
version: 1.8.7
|
79
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
-
requirements:
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
81
85
|
- - ">="
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version:
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
84
88
|
requirements: []
|
85
|
-
|
86
89
|
rubyforge_project:
|
87
|
-
rubygems_version: 2.
|
90
|
+
rubygems_version: 2.4.6
|
88
91
|
signing_key:
|
89
92
|
specification_version: 4
|
90
93
|
summary: A Ruby wrapper around the Plotly RESTful API.
|
91
94
|
test_files: []
|
92
|
-
|
93
|
-
has_rdoc:
|