Skip to content

Commit 16fa74f

Browse files
committed
Merge pull request #11 from SciRuby/master
Improved README. Added proposed copyright/license modifications. Added examples.
2 parents 95935ee + 0b38f3f commit 16fa74f

File tree

7 files changed

+295
-60
lines changed

7 files changed

+295
-60
lines changed

LICENSE.txt

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
1-
Copyright (c) 2013 Zuhao Wan
2-
3-
MIT License
4-
5-
Permission is hereby granted, free of charge, to any person obtaining
6-
a copy of this software and associated documentation files (the
7-
"Software"), to deal in the Software without restriction, including
8-
without limitation the rights to use, copy, modify, merge, publish,
9-
distribute, sublicense, and/or sell copies of the Software, and to
10-
permit persons to whom the Software is furnished to do so, subject to
11-
the following conditions:
12-
13-
The above copyright notice and this permission notice shall be
14-
included in all copies or substantial portions of the Software.
15-
16-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1+
This version of Plotrb is licensed under the BSD 2-clause license.
2+
3+
* http://sciruby.com
4+
* http://github.com/sciruby/sciruby/wiki/License
5+
6+
You *must* read the Contributor Agreement before contributing code to
7+
the SciRuby Project. This is available online:
8+
9+
* http://github.com/sciruby/sciruby/wiki/Contributor-Agreement
10+
11+
-----
12+
13+
Copyright (c) 2010 - 2013, Wan Zuhao and the Ruby Science Foundation
14+
All rights reserved.
15+
16+
Redistribution and use in source and binary forms, with or without
17+
modification, are permitted provided that the following conditions are
18+
met:
19+
20+
* Redistributions of source code must retain the above copyright notice,
21+
this list of conditions and the following disclaimer.
22+
23+
* Redistributions in binary form must reproduce the above copyright
24+
notice, this list of conditions and the following disclaimer in the
25+
documentation and/or other materials provided with the distribution.
26+
27+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
28+
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29+
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
30+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
33+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38+

README.md

Lines changed: 0 additions & 35 deletions
This file was deleted.

README.rdoc

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
= Plotrb
2+
3+
Vega/D3-based plotting gem for Ruby
4+
5+
* {sciruby.com}[http://sciruby.com]
6+
* {Google+}[https://plus.google.com/109304769076178160953/posts]
7+
* {Wan Zuhao}[http://www.wanzuhao.com]
8+
9+
{<img src=https://travis-ci.org/zuhao/plotrb.png>}[https://travis-ci.org/zuhao/plotrb]
10+
11+
== Description
12+
13+
Plotrb is an experimental plotting library for the Ruby language. It
14+
brings {the simplicity of Vega}[http://trifacta.github.io/vega/] and
15+
{the power of D3}[http://d3js.org/] to the Ruby science community, to
16+
allow for {fast, customizable design; reusability and shareability; programmatic generation of visualizations; and improved performance and platform flexibility}[https://github.com/trifacta/vega/wiki/Vega-and-D3].
17+
18+
Plotrb is in many ways the child of
19+
{Rubyvis}[http://github.com/SciRuby/rubyvis] (the Ruby port of
20+
Protovis). However, it improves upon Rubyvis in that it uses a DSL that
21+
will be much more familiar and natural to Ruby coders.
22+
23+
Plotrb was created by Wan Zuhao as part of Google's Summer of Code 2013.
24+
It is part of {SciRuby}[http://sciruby.com].
25+
26+
== Installation
27+
28+
Add this line to your application's Gemfile:
29+
30+
gem 'plotrb'
31+
32+
And then execute:
33+
34+
bundle
35+
36+
Or install it yourself as:
37+
38+
gem install plotrb
39+
40+
== Usage
41+
42+
Note that Plotrb is a work in progress, so we can't guarantee that every
43+
example will work exactly.
44+
45+
* {Bar}[http://wanzuhao.com/posts/plotrb-example-bar/]
46+
* {Area}[http://wanzuhao.com/posts/plotrb-example-area/]
47+
* {Lifelines}[http://wanzuhao.com/posts/plotrb-exampe-lifelines/]
48+
49+
Examples may also be found in the `examples/` directory.
50+
51+
== Contributing
52+
53+
1. Fork it
54+
2. Create your feature branch (`git checkout -b my-new-feature`)
55+
3. Commit your changes (`git commit -am 'Add some feature'`)
56+
4. Push to the branch (`git push origin my-new-feature`)
57+
5. Create new Pull Request
58+
59+
== License
60+
61+
Copyright (c) 2013, Wan Zuhao and the Ruby Science Foundation.
62+
63+
All rights reserved.
64+
65+
Plotrb, along with SciRuby, is licensed under the BSD 2-clause license. See
66+
{LICENSE.txt}[https://github.com/SciRuby/sciruby/wiki/License] for details.
67+
68+
== Donations
69+
70+
Support a SciRuby Fellow:
71+
72+
{<img src=http://pledgie.com/campaigns/15783.png?skin_name=chrome>}[http://www.pledgie.com/campaigns/15783]

examples/arc.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require 'plotrb'
2+
3+
data = pdata.name('table').values([12,23,47,6,52,19]).transform(pie_transform)
4+
5+
scale = sqrt_scale.name('r').from(data).to([20,100])
6+
7+
mark = arc_mark.from(data) do
8+
enter do
9+
x_start { group(:width).times(0.5) }
10+
y_start { group(:height).times(0.5) }
11+
start_angle { from :start_angle }
12+
end_angle { from :end_angle }
13+
inner_radius 20
14+
outer_radius { scale(scale) }
15+
stroke '#fff'
16+
end
17+
update do
18+
fill '#ccc'
19+
end
20+
hover do
21+
fill 'pink'
22+
end
23+
end
24+
25+
vis = visualization.name('arc').width(400).height(400) do
26+
data data
27+
scales scale
28+
marks mark
29+
end
30+
31+
puts vis.generate_spec(:pretty)

examples/bar.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
require 'plotrb'
2+
3+
data = pdata.name('table').values(
4+
[
5+
{x: 1, y: 28}, {x: 2, y: 55},
6+
{x: 3, y: 43}, {x: 4, y: 91},
7+
{x: 5, y: 81}, {x: 6, y: 53},
8+
{x: 7, y: 19}, {x: 8, y: 87},
9+
{x: 9, y: 52}, {x: 10, y: 48},
10+
{x: 11, y: 24}, {x: 12, y: 49},
11+
{x: 13, y: 87}, {x: 14, y: 66},
12+
{x: 15, y: 17}, {x: 16, y: 27},
13+
{x: 17, y: 68}, {x: 18, y: 16},
14+
{x: 19, y: 49}, {x: 20, y: 15}
15+
]
16+
)
17+
18+
xs = ordinal_scale.name('x').from('table.x').to_width
19+
ys = linear_scale.name('y').from('table.y').nicely.to_height
20+
21+
mark = rect_mark.from(data) do
22+
enter do
23+
x_start { scale(xs).from('x') }
24+
width { scale(xs).offset(-1).use_band }
25+
y_start { scale(ys).from('y') }
26+
y_end { scale(ys).value(0) }
27+
end
28+
update do
29+
fill 'steelblue'
30+
end
31+
hover do
32+
fill 'red'
33+
end
34+
end
35+
36+
vis = visualization.width(400).height(200) do
37+
padding top: 10, left: 30, bottom: 30, right: 10
38+
data data
39+
scales xs, ys
40+
marks mark
41+
axes x_axis.scale(xs), y_axis.scale(ys)
42+
end
43+
44+
puts vis.generate_spec(:pretty)

examples/lifelines.rb

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
require './lib/plotrb.rb'
2+
3+
people = pdata.name('people').values(
4+
[
5+
{"label" => "Washington",
6+
"born" => -7506057600000,
7+
"died" => -5366196000000,
8+
"enter" => -5701424400000,
9+
"leave" => -5453884800000},
10+
{"label" => "Adams",
11+
"born" => -7389766800000,
12+
"died" => -4528285200000,
13+
"enter" => -5453884800000,
14+
"leave" => -5327740800000},
15+
{"label" => "Jefferson",
16+
"born" => -7154586000000,
17+
"died" => -4528285200000,
18+
"enter" => -5327740800000,
19+
"leave" => -5075280000000},
20+
{"label" => "Madison",
21+
"born" => -6904544400000,
22+
"died" => -4213184400000,
23+
"enter" => -5075280000000,
24+
"leave" => -4822819200000},
25+
{"label" => "Monroe",
26+
"born" => -6679904400000,
27+
"died" => -4370518800000,
28+
"enter" => -4822819200000,
29+
"leave" => -4570358400000}
30+
]
31+
)
32+
33+
events = pdata.name('events') do
34+
format(:json) { parse 'when' => :date }
35+
values [
36+
{"name" => "Decl. of Independence", "when" => "July 4, 1776"},
37+
{"name" => "U.S. Constitution", "when" => "3/4/1789"},
38+
{"name" => "Louisiana Purchase", "when" => "April 30, 1803"},
39+
{"name" => "Monroe Doctrine", "when" => "Dec 2, 1823"}
40+
]
41+
end
42+
43+
y_scale = ordinal_scale.name('y').from('people.label').to_height
44+
x_scale = time_scale.name('x').from(['people.born', 'people.died']).to_width.round.in_years
45+
46+
events_mark_t = text_mark.from(events) do
47+
enter do
48+
x_start { scale(x_scale).from('when') }
49+
y_start -10
50+
angle -25
51+
fill '#000'
52+
text { from 'name' }
53+
font 'Helvetica Neue'
54+
font_size 10
55+
end
56+
end
57+
58+
events_mark_r = rect_mark.from(events) do
59+
enter do
60+
x_start { scale(x_scale).from('when') }
61+
y_start -8
62+
width 1
63+
height { group(:height).offset(8) }
64+
fill '#888'
65+
end
66+
end
67+
68+
people_mark_t = text_mark.from(people) do
69+
enter do
70+
x_start { scale(x_scale).from('born') }
71+
y_start { scale(y_scale).from('label').offset(-3) }
72+
fill '#000'
73+
text { from('label') }
74+
font 'Helvetica Neue'
75+
font_size 10
76+
end
77+
end
78+
79+
people_mark_r = rect_mark.from(people) do
80+
enter do
81+
x_start { scale(x_scale).from('born') }
82+
x_end { scale(x_scale).from('died') }
83+
y_start { scale(y_scale).from('label') }
84+
height 2
85+
fill '#557'
86+
end
87+
end
88+
89+
people_mark_r2 = rect_mark.from(people) do
90+
enter do
91+
x_start { scale(x_scale).from('enter') }
92+
x_end { scale(x_scale).from('leave') }
93+
y_start { scale(y_scale).from('label').offset(-1) }
94+
height 4
95+
fill '#e44'
96+
end
97+
end
98+
99+
vis = visualization.name('lifelines').width(400).height(100) do
100+
data people, events
101+
scales x_scale, y_scale
102+
axes x_axis.scale('x')
103+
marks events_mark_t, events_mark_r, people_mark_t, people_mark_r, people_mark_r2
104+
end
105+
106+
puts vis.generate_spec(:pretty)

plotrb.gemspec

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ Gem::Specification.new do |spec|
88
spec.authors = ['Zuhao Wan']
99
spec.email = 'wanzuhao@gmail.com'
1010
spec.description = %q{Plotrb is a plotting tool in Ruby.}
11-
spec.summary = %q{Plotrb is a plotting tool in Ruby, built on D3.}
12-
spec.homepage = 'https://github.com/zuhao/plotrb'
13-
spec.license = 'MIT'
11+
spec.summary = %q{Plotrb is a plotting tool in Ruby, built on Vega and D3, and is part of the SciRuby Project.}
12+
spec.homepage = 'https://github.com/sciruby/plotrb'
13+
spec.license = 'BSD 2-clause'
1414

1515
spec.files = `git ls-files`.split($/)
1616
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -24,3 +24,4 @@ Gem::Specification.new do |spec|
2424
spec.add_dependency 'yajl-ruby'
2525
spec.add_dependency 'activemodel'
2626
end
27+

0 commit comments

Comments
 (0)