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 CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA1:
3
- metadata.gz: a3294977f017a389f97c281ab13cc93b95878248
4
- data.tar.gz: 60eee1cf956a7b94135cbcd5670dedb237239075
5
- SHA512:
6
- metadata.gz: c259c1f081ecad6cd832f66bf73b3745bcaeea56bab362d4af2f9b4ab5cb17399682c21b180501bda4d391ad5d0a060f16d3d7b82836819037f65ad79dd6387f
7
- data.tar.gz: b645541f67a799b2e8810a8934dc083aa352d58c50116a0a7a62854c811d8921015bbd5512cda32e4014e242b466b5fbe891de93ef49876da91749b9fe908431
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
- :x => ['2013-10-04 22:23:00', '2013-11-04 22:23:00', '2013-12-04 22:23:00'],
36
- :y => [1, 3, 6],
37
- :type => 'scatter',
38
- :mode => 'markers',
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 => 'bigfoot sightings', :range => [0, 7] },
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
- # NOTE: data argument must be an array of traces
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 data hash in the API
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(data)
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 = payload
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(data, grid_json, layout = {})
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| self.class.replace_column_names_with_uids(grid_response_body, 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 = { :figure => { :data => payload_data, :layout => layout } }.to_json
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)
@@ -12,14 +12,18 @@ module Plotlyrb
12
12
  @https.use_ssl = true
13
13
  end
14
14
 
15
- def plot_image(data, image_path, image_type, layout = {})
16
- raise "image_type #{image_type} not supported" unless VALID_IMAGE_FORMATS.include?(image_type)
17
- payload = { :figure => { :data => data, :layout => layout }, :format => image_type.to_s }.to_json
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 = payload
24
+ request.body = plot_image_spec.to_json
20
25
  response = @https.request(request)
21
- image_path_with_ext = "#{image_path}"
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
@@ -1,3 +1,3 @@
1
1
  module Plotlyrb
2
- VERSION = '0.2.0'
2
+ VERSION = '1.0.0'
3
3
  end
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'] = "TODO: Set to 'http://mygemserver.com'"
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.2.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
- date: 2016-10-27 00:00:00 Z
13
- dependencies:
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
- prerelease: false
17
- requirement: &id001 !ruby/object:Gem::Requirement
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
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
- requirement: &id002 !ruby/object:Gem::Requirement
28
- requirements:
29
- - - ~>
30
- - !ruby/object:Gem::Version
31
- version: "10.0"
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
- version_requirements: *id002
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
- files:
44
- - .gitignore
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: "TODO: Set to 'http://mygemserver.com'"
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: "0"
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
84
88
  requirements: []
85
-
86
89
  rubyforge_project:
87
- rubygems_version: 2.0.16
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: