plotlyrb 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -4
- data/lib/plotlyrb/api_v2.rb +11 -7
- data/lib/plotlyrb/plot_image.rb +4 -5
- data/lib/plotlyrb/plotly.rb +12 -0
- data/lib/plotlyrb/version.rb +1 -1
- data/lib/plotlyrb.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA512:
|
3
|
-
|
4
|
-
|
3
|
+
metadata.gz: c414fe15b1fdae4c2ecfb7bae766660b30f16510cc4b01ea8e0cf564a0febe49ca6730ba8e0d9f0a4e252ab47890a6b3222404976e6966072fbbcef7c35488e2
|
4
|
+
data.tar.gz: 1821bcfae3d5c79b8391a130e6ff8d734deb25b68a34815555b84a4a58b48656d640767dd7845c495f8780d23a2e9290f71e8f79929763b56cf8e7a2f3ddc494
|
5
5
|
SHA1:
|
6
|
-
|
7
|
-
|
6
|
+
metadata.gz: 1e749d6b08a9882ed571ec50eef29344863cc832
|
7
|
+
data.tar.gz: 180ac6344d89b87b7b63c81cd51cfdb655157bfd
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Plotlyrb
|
2
2
|
|
3
|
-
|
3
|
+
Use [plotly](https://plot.ly) to graph your data.
|
4
4
|
|
5
|
-
|
5
|
+
Currently only supports `plot_image`, which uses the REST API to generate an image for your plot. See [the python reference](https://plot.ly/python/reference/) for details on what you can plot.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -22,7 +22,25 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
```ruby
|
26
|
+
data = {
|
27
|
+
:x => ['2013-10-04 22:23:00', '2013-11-04 22:23:00', '2013-12-04 22:23:00'],
|
28
|
+
:y => [1, 3, 6],
|
29
|
+
:type => 'scatter'
|
30
|
+
}
|
31
|
+
|
32
|
+
layout = { :xaxis => { :title => 'times' },
|
33
|
+
:yaxis => { :title => 'bigfoot sightings', :range => [0, 7] },
|
34
|
+
}
|
35
|
+
|
36
|
+
plotly = Plotlyrb::PlotImage.new('my-plotly-username', 'my-plotly-api-key')
|
37
|
+
plotly.plot_image(data, 'plot.png', :png, layout)
|
38
|
+
```
|
39
|
+
|
40
|
+
## TODO
|
41
|
+
- [ ] Support height and width
|
42
|
+
- [ ] Test more plot types
|
43
|
+
- [ ] Use data structures/abstractions for plot types, data, etc. ?
|
26
44
|
|
27
45
|
## Development
|
28
46
|
|
@@ -34,7 +52,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
34
52
|
|
35
53
|
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/plotlyrb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
54
|
|
37
|
-
|
38
55
|
## License
|
39
56
|
|
40
57
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/plotlyrb/api_v2.rb
CHANGED
@@ -8,16 +8,20 @@ module Plotlyrb
|
|
8
8
|
HOSTNAME = 'api.plot.ly'
|
9
9
|
BASE_PATH = 'v2'
|
10
10
|
BASE_URI = "#{PROTOCOL}://#{HOSTNAME}/#{BASE_PATH}"
|
11
|
-
|
12
11
|
IMAGES = URI.parse("#{BASE_URI}/images")
|
12
|
+
COMMON_HEADERS = {
|
13
|
+
'plotly-client-platform' => "Ruby #{Plotlyrb::VERSION}",
|
14
|
+
'content-type' => 'application/json'
|
15
|
+
}
|
16
|
+
|
17
|
+
def self.plotly
|
18
|
+
Plotly.new(COMMON_HEADERS)
|
19
|
+
end
|
13
20
|
|
14
|
-
def self.
|
21
|
+
def self.auth_plotly(username, api_key)
|
15
22
|
encoded_auth = Base64.encode64("#{username}:#{api_key}")
|
16
|
-
{
|
17
|
-
|
18
|
-
'authorization' => "Basic #{encoded_auth}",
|
19
|
-
'content-type' => 'application/json'
|
20
|
-
}
|
23
|
+
headers_hash = COMMON_HEADERS.merge({ 'authorization' => "Basic #{encoded_auth}" })
|
24
|
+
Plotly.new(headers_hash)
|
21
25
|
end
|
22
26
|
end
|
23
27
|
end
|
data/lib/plotlyrb/plot_image.rb
CHANGED
@@ -6,17 +6,16 @@ module Plotlyrb
|
|
6
6
|
|
7
7
|
VALID_IMAGE_FORMATS = [:png, :svg, :pdf, :eps]
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@https = Net::HTTP.new(url.host, url.port)
|
9
|
+
def initialize(plotly)
|
10
|
+
@plotly = plotly
|
11
|
+
@https = Net::HTTP.new(ApiV2::IMAGES.host, ApiV2::IMAGES.port)
|
13
12
|
@https.use_ssl = true
|
14
13
|
end
|
15
14
|
|
16
15
|
def plot_image(data, image_path, image_type, layout = {})
|
17
16
|
raise "image_type #{image_type} not supported" unless VALID_IMAGE_FORMATS.include?(image_type)
|
18
17
|
payload = { :figure => { :data => data, :layout => layout }, :format => image_type.to_s }.to_json
|
19
|
-
request = Net::HTTP::Post.new(
|
18
|
+
request = Net::HTTP::Post.new(ApiV2::IMAGES.path, @plotly)
|
20
19
|
request.body = payload
|
21
20
|
response = @https.request(request)
|
22
21
|
image_path_with_ext = "#{image_path}"
|
data/lib/plotlyrb/version.rb
CHANGED
data/lib/plotlyrb.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plotlyrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Veitchlister Consulting
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2016-01-
|
12
|
+
date: 2016-01-25 00:00:00 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: backports
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- lib/plotlyrb.rb
|
68
68
|
- lib/plotlyrb/api_v2.rb
|
69
69
|
- lib/plotlyrb/plot_image.rb
|
70
|
+
- lib/plotlyrb/plotly.rb
|
70
71
|
- lib/plotlyrb/version.rb
|
71
72
|
- plotlyrb.gemspec
|
72
73
|
homepage: https://github.com/vlc/plotlyrb
|