c2po 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ *.gem
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2012, Keming Labs, LLC (http://keminglabs.com)
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ * The name Keming Labs may not be used to endorse or promote products
15
+ derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ DISCLAIMED. IN NO EVENT SHALL KEVIN LYNAGH BE LIABLE FOR ANY DIRECT,
21
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24
+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,56 @@
1
+ C2PO Ruby language bindings
2
+ ===========================
3
+
4
+ [C2PO](http://keminglabs.com/c2po/) is a grammar of graphics implementation inspired by Hadley Wickham's ggplot2 library.
5
+ This Rubygem uses the free online C2PO compiler and is limited to 1 MB of data.
6
+ Plot specifications are compiled directly to an SVG string, which is returned:
7
+
8
+ ```ruby
9
+ require 'c2po'
10
+
11
+ #Make some random data:
12
+ data = 20.times.collect do
13
+ {:a => 10*rand, :b => 5*rand}
14
+ end
15
+
16
+ #Specify a simple scatterplot graphic:
17
+ scatterplot_spec = {
18
+ :data => data,
19
+ :geom => :point,
20
+ :mapping => {:x => :a, :y => :b}}
21
+
22
+ #Render an SVG string:
23
+ C2PO.render scatterplot_spec
24
+ #=>
25
+
26
+ ```
27
+
28
+
29
+ Install
30
+ -------
31
+
32
+ For the plain client library, run
33
+
34
+ gem install c2po
35
+
36
+ or add
37
+
38
+ c2po, "0.0.1"
39
+
40
+ to your `Gemfile`.
41
+
42
+ If you want to learn the grammar and work interactively with the examples in `/examples`, just clone this repo:
43
+
44
+ git clone https://github.com/keminglabs/c2po-ruby
45
+
46
+ install the deps:
47
+
48
+ cd examples
49
+ bundle install
50
+
51
+ then run:
52
+
53
+ bundle exec guard
54
+
55
+ to launch a live-reloading web server on `localhost:3000` for displaying graphics.
56
+ Walk through and execute the example code in `examples/1-usage.rb` to get started.
@@ -0,0 +1,19 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
+
3
+ require 'c2po/version'
4
+
5
+ spec = Gem::Specification.new do |s|
6
+ s.name = 'c2po'
7
+ s.version = C2PO::VERSION
8
+ s.summary = 'Ruby bindings for C2PO'
9
+ s.description = 'C2PO is a grammar for statistical graphics. See http://keminglabs.com/c2po.'
10
+ s.authors = ['Kevin Lynagh']
11
+ s.email = ['kevin@keminglabs.com']
12
+ s.homepage = 'http://keminglabs.com/c2po'
13
+ s.require_paths = %w{lib}
14
+
15
+ s.add_dependency('edn', '~> 1.0.0')
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.require_paths = ['lib']
19
+ end
@@ -0,0 +1 @@
1
+ index.html
@@ -0,0 +1,23 @@
1
+ #This tutorial covers basic usage and plot creation.
2
+
3
+ #First require the interactive helper functions and dependencies
4
+ require File.dirname(__FILE__) + '/interactive_helper'
5
+
6
+ #then make some random data:
7
+
8
+ data = 20.times.collect do
9
+ {:a => 10*rand, :b => 5*rand}
10
+ end
11
+
12
+ #Specify a simple scatterplot graphic:
13
+
14
+ scatterplot_spec = {
15
+ :data => data,
16
+ :geom => :point,
17
+ :mapping => {:x => :a, :y => :b}}
18
+
19
+ #then render it via the remote c2po server:
20
+
21
+ render! scatterplot_spec
22
+
23
+ #This call will save the result in `./index.html` and if your browser is pointed at `http://localhost:3000` it will automatically refresh to show this plot.
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'c2po'
4
+
5
+ gem 'guard'
6
+ gem 'rb-inotify', :require => false
7
+ gem 'rb-fsevent', :require => false
8
+ gem 'rb-fchange', :require => false
9
+
10
+ gem 'guard-livereload'
11
+ gem 'guard-webrick'
12
+
13
+
@@ -0,0 +1,49 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.2)
5
+ blankslate (2.1.2.4)
6
+ c2po (0.0.1)
7
+ edn (~> 1.0.0)
8
+ edn (1.0.0)
9
+ parslet (~> 1.4.0)
10
+ em-websocket (0.3.8)
11
+ addressable (>= 2.1.1)
12
+ eventmachine (>= 0.12.9)
13
+ eventmachine (1.0.0)
14
+ ffi (1.2.0)
15
+ guard (1.0.3)
16
+ ffi (>= 0.5.0)
17
+ thor (>= 0.14.6)
18
+ guard-livereload (0.4.2)
19
+ em-websocket (>= 0.2.0)
20
+ guard (>= 0.10.0)
21
+ multi_json (~> 1.0)
22
+ guard-webrick (0.1.2)
23
+ guard (~> 1.0.2)
24
+ launchy (~> 2.1.0)
25
+ spoon (~> 0.0.1)
26
+ launchy (2.1.2)
27
+ addressable (~> 2.3)
28
+ multi_json (1.4.0)
29
+ parslet (1.4.0)
30
+ blankslate (~> 2.0)
31
+ rb-fchange (0.0.6)
32
+ ffi
33
+ rb-fsevent (0.9.2)
34
+ rb-inotify (0.8.8)
35
+ ffi (>= 0.5.0)
36
+ spoon (0.0.1)
37
+ thor (0.16.0)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ c2po
44
+ guard
45
+ guard-livereload
46
+ guard-webrick
47
+ rb-fchange
48
+ rb-fsevent
49
+ rb-inotify
@@ -0,0 +1,6 @@
1
+ guard 'webrick' do
2
+ end
3
+
4
+ guard 'livereload' do
5
+ watch("index.html")
6
+ end
@@ -0,0 +1,11 @@
1
+ Directory for interactive development of c2po plots.
2
+ Install deps via:
3
+
4
+ bundle install
5
+
6
+ then run
7
+
8
+ bundle exec guard
9
+
10
+ execute some of the code in `scratch.rb` and view your plots at `http://localhost:3000/`.
11
+
@@ -0,0 +1,23 @@
1
+ require 'c2po'
2
+ include C2PO
3
+
4
+ OUT_FILE = File.dirname(__FILE__) + "/index.html"
5
+
6
+ def html(content)
7
+ <<-EOH
8
+ <html>
9
+ <head></head>
10
+ <body>
11
+ <div id="visualization" style="text-align: center">
12
+ #{content}
13
+ </div>
14
+ </body>
15
+ </html>
16
+ EOH
17
+ end
18
+
19
+ def render! (spec)
20
+ open(OUT_FILE, "w") do |f|
21
+ f.write html C2PO.render spec
22
+ end
23
+ end
@@ -0,0 +1,42 @@
1
+ $:.push(File.dirname(__FILE__))
2
+ require 'edn'
3
+ require 'c2po/records'
4
+ require 'c2po/geom'
5
+ require 'c2po/stat'
6
+ require 'c2po/group'
7
+ require 'c2po/scale'
8
+
9
+ require 'net/http'
10
+ require 'uri'
11
+
12
+ module C2PO
13
+ class C2POException < Exception
14
+ end
15
+
16
+ C2PO_URL = "http://c2po.keminglabs.com"
17
+
18
+ def self.motd(url=C2PO_URL)
19
+ res = Net::HTTP.get_response URI.parse url + "/motd"
20
+ res.body
21
+ end
22
+
23
+ @@motd_printed = false
24
+ def self.print_once_motd!(url=C2PO_URL)
25
+ unless @@motd_printed
26
+ puts motd url
27
+ @@motd_printed = true
28
+ end
29
+ end
30
+
31
+ def self.render(spec, url=C2PO_URL)
32
+ print_once_motd!
33
+
34
+ res = Net::HTTP.post_form(URI.parse(url),
35
+ "c2po" => spec.to_edn)
36
+ if res.code != "200"
37
+ raise C2POException.new, res.body
38
+ else
39
+ res.body
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,8 @@
1
+ module C2PO
2
+ module Geom
3
+ Point = Class.new C2PORecord
4
+ Line = Class.new C2PORecord
5
+ Bar = Class.new C2PORecord
6
+ Boxplot = Class.new C2PORecord
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module C2PO
2
+ module Group
3
+ Bin = Class.new C2PORecord
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ module C2PO
2
+ class C2PORecord < Hash
3
+ def initialize(h={})
4
+ self.merge! h
5
+ end
6
+ def to_edn
7
+ _, prefix, name = self.class.name.split("::").map(&:downcase)
8
+ EDN.tagout "com.keminglabs/c2po$#{prefix}$#{name}", {}.merge(self)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module C2PO
2
+ module Scale
3
+ Linear = Class.new C2PORecord
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module C2PO
2
+ module Stat
3
+ Sum = Class.new C2PORecord
4
+ Density = Class.new C2PORecord
5
+ Quantiles = Class.new C2PORecord
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module C2PO
2
+ VERSION = '0.0.2'
3
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: c2po
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kevin Lynagh
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: edn
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
30
+ description: C2PO is a grammar for statistical graphics. See http://keminglabs.com/c2po.
31
+ email:
32
+ - kevin@keminglabs.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - LICENSE
39
+ - README.markdown
40
+ - c2po.gemspec
41
+ - examples/.gitignore
42
+ - examples/1-usage.rb
43
+ - examples/Gemfile
44
+ - examples/Gemfile.lock
45
+ - examples/Guardfile
46
+ - examples/README.markdown
47
+ - examples/interactive_helper.rb
48
+ - lib/c2po.rb
49
+ - lib/c2po/geom.rb
50
+ - lib/c2po/group.rb
51
+ - lib/c2po/records.rb
52
+ - lib/c2po/scale.rb
53
+ - lib/c2po/stat.rb
54
+ - lib/c2po/version.rb
55
+ homepage: http://keminglabs.com/c2po
56
+ licenses: []
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 1.8.24
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Ruby bindings for C2PO
79
+ test_files: []