nyaplot 0.1.0 → 0.1.1
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 +4 -4
- data/README.md +33 -6
- data/examples/rb/3d.rb +73 -0
- data/examples/rb/basic.rb +74 -0
- data/examples/rb/bio.rb +59 -0
- data/examples/rb/maps.rb +29 -0
- data/examples/rb/multiple.rb +29 -0
- data/examples/rb/scatter.rb +26 -0
- data/examples/rb/wind.rb +20 -0
- data/lib/nyaplot/core.rb +8 -2
- data/lib/nyaplot/data.rb +7 -3
- data/lib/nyaplot/frame.rb +23 -10
- data/lib/nyaplot/plot.rb +8 -0
- data/lib/nyaplot/templates/static_html.erb +3 -9
- data/lib/nyaplot/version.rb +1 -1
- data/lib/nyaplot3d/plot3d.rb +13 -3
- data/nyaplot.gemspec +1 -1
- metadata +11 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4ec246bfaa5e6bde74849d22e8679d3ca33fd778
|
|
4
|
+
data.tar.gz: c9bc0d66313a907e09047c1632f44a9f31686eb5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fe34206cc16465d00132765ce99746c7a16e926f1d002de928089705dd256e8c7efe2d61e742a797ff38518103be1f09af5f12ca34f6e19b4c0e908818dce846
|
|
7
|
+
data.tar.gz: 5501a06381d18f375d12a077b04d7e6266af263bc64b95c3c48c9b22d25671666296071ec0931dbec9f07e88def3c135d3f35223a36a97dae5a1f7e8903c954c
|
data/README.md
CHANGED
|
@@ -52,6 +52,8 @@ Mapnya is an extension library for map visualization.
|
|
|
52
52
|
See [this notebook](http://nbviewer.ipython.org/github/domitry/nyaplot/blob/master/examples/notebook/Mapnya.ipynb) to learn more.
|
|
53
53
|
|
|
54
54
|
## Installation
|
|
55
|
+
### Install nyaplot
|
|
56
|
+
<!--
|
|
55
57
|
### Build and install nyaplot
|
|
56
58
|
This gem is still under development and is not registered to RubyGems.org. Therefore clone this repository and build gem by yourself to try it.
|
|
57
59
|
|
|
@@ -64,9 +66,8 @@ And then build and install using gem command:
|
|
|
64
66
|
cd nyaplot
|
|
65
67
|
gem build nyaplot.gemspec
|
|
66
68
|
gem install nyaplot-0.0.1.gem
|
|
69
|
+
-->
|
|
67
70
|
|
|
68
|
-
|
|
69
|
-
<!--
|
|
70
71
|
Add this line to your application's Gemfile:
|
|
71
72
|
|
|
72
73
|
gem 'nyaplot'
|
|
@@ -78,16 +79,31 @@ And then execute:
|
|
|
78
79
|
Or install it yourself as:
|
|
79
80
|
|
|
80
81
|
$ gem install nyaplot
|
|
81
|
-
|
|
82
|
+
|
|
82
83
|
|
|
83
84
|
### Install IRuby notebook
|
|
84
85
|
Nyaplot do not have any dependency, but we strongly recommend to install [IRuby](https://github.com/minad/iruby) by @minad at the same time.
|
|
85
86
|
IRuby is a web-based interactive Ruby environment and Nyaplot is totally designed to work with it.
|
|
86
87
|
You can install the gem itself by running `gem install` command, but it has some dependent libraries outside of Ruby-ecosystem.
|
|
87
88
|
|
|
88
|
-
#### Ubuntu 14.
|
|
89
|
+
#### Ubuntu 14.10
|
|
90
|
+
|
|
91
|
+
There are various ways to install Python and IPython notebook, but [Anaconda](https://store.continuum.io/cshop/anaconda/) is highly recommended.
|
|
92
|
+
|
|
93
|
+
IRuby requires IPython >= 1.1 and libzmq >= 3.2, so update IPython and install libzmq3 before installing IRuby.
|
|
89
94
|
|
|
90
|
-
|
|
95
|
+
```shell
|
|
96
|
+
conda update ipython
|
|
97
|
+
sudo apt-get install libzmq3-dev
|
|
98
|
+
```
|
|
99
|
+
And then try to run `gem install iruby`.
|
|
100
|
+
|
|
101
|
+
If the code above does not work, try below.
|
|
102
|
+
|
|
103
|
+
```shell
|
|
104
|
+
conda update zeromq
|
|
105
|
+
conda update pyzmq
|
|
106
|
+
```
|
|
91
107
|
|
|
92
108
|
#### Mac OS X
|
|
93
109
|
|
|
@@ -102,7 +118,18 @@ brew install zeromq
|
|
|
102
118
|
|
|
103
119
|
#### Windows
|
|
104
120
|
|
|
105
|
-
|
|
121
|
+
First, install IPython and its dependencies using [Enthought Canopy](https://www.enthought.com/). There are various ways to install IPython, but Canopy may be the most useful to Windows users.
|
|
122
|
+
|
|
123
|
+
Then install IRuby by running `gem install iruby`.
|
|
124
|
+
|
|
125
|
+
After that, install ZeroMQ from [here](http://zeromq.org/area:download). Be sure to install stable release of the version **3.2.?**.
|
|
126
|
+
**Attention: install 32bit version of Zeromq even if your Windows is built for 64-bit.**
|
|
127
|
+
|
|
128
|
+
Add the path to the directory of ZeroMQ binaries (Maybe the path is `Program Files (x86)/ZeroMQ 3.2.4/bin`) to environment variables `PATH`.
|
|
129
|
+
|
|
130
|
+
Then rename `libzmq-v100-mt-3_2_4.dll` to `libzmq.dll`. It maybe in `Program Files (x86)/ZeroMQ 3.2.4/bin`.
|
|
131
|
+
|
|
132
|
+
At last, pure IRuby do not work on Windows, so please apply [patches I sent before](https://github.com/minad/iruby/pull/30) to IRuby.
|
|
106
133
|
|
|
107
134
|
## Acknowledgments
|
|
108
135
|
|
data/examples/rb/3d.rb
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
require 'nyaplot'
|
|
2
|
+
require 'nyaplot3d'
|
|
3
|
+
|
|
4
|
+
# Wireframe
|
|
5
|
+
x=[];y=[];z=[]
|
|
6
|
+
-10.step(10, 0.5) do |i|
|
|
7
|
+
-10.step(10, 0.5) do |j|
|
|
8
|
+
x.push(i)
|
|
9
|
+
y.push(j)
|
|
10
|
+
z.push(Math.sin(Math.sqrt(i*i+j*j))/Math.sqrt(i*i+j*j))
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
z.map!{|val| next (val.nan? ? 0 : val)} #(0,0) will be -inf
|
|
14
|
+
|
|
15
|
+
plot = Nyaplot::Plot3D.new
|
|
16
|
+
plot.add(:wireframe, x, y, z)
|
|
17
|
+
plot.export_html("wireframe.html")
|
|
18
|
+
|
|
19
|
+
# Surface
|
|
20
|
+
plot = Nyaplot::Plot3D.new
|
|
21
|
+
plot.add(:surface, x, y, z)
|
|
22
|
+
plot.export_html("surface.html")
|
|
23
|
+
|
|
24
|
+
# Line
|
|
25
|
+
step_num = 10000;
|
|
26
|
+
p = 10; r = 28; b = 8/3; dt = 0.01
|
|
27
|
+
|
|
28
|
+
fx = Proc.new{|x,y,z| ((-1)*p*x + p*y)};
|
|
29
|
+
fy = Proc.new{|x,y,z| ((-1)*x*z + r*x - y)};
|
|
30
|
+
fz = Proc.new{|x,y,z| (x*y - b*z)};
|
|
31
|
+
|
|
32
|
+
x_arr=[]; y_arr=[]; z_arr=[]
|
|
33
|
+
x = 1; y = 1; z = 1
|
|
34
|
+
step_num.times do |i|
|
|
35
|
+
x += dt * fx.call(x,y,z);
|
|
36
|
+
y += dt * fy.call(x,y,z);
|
|
37
|
+
z += dt * fz.call(x,y,z);
|
|
38
|
+
x_arr.push(x);
|
|
39
|
+
y_arr.push(y);
|
|
40
|
+
z_arr.push(z);
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
plot = Nyaplot::Plot3D.new
|
|
44
|
+
plot.add(:line, x_arr, y_arr, z_arr)
|
|
45
|
+
plot.export_html("3dline.html")
|
|
46
|
+
|
|
47
|
+
# Scatter
|
|
48
|
+
plot = Nyaplot::Plot3D.new
|
|
49
|
+
colors = ['#8dd3c7', '#ffffb3', '#bebada', '#fb8072']
|
|
50
|
+
['circle', 'rect', 'rect', 'diamond'].each do |shape|
|
|
51
|
+
x, y, z = [0,0,0].map{|d| next Array.new(20, rand*5).map{|v| next v+rand}}
|
|
52
|
+
sc = plot.add(:scatter, x, y, z)
|
|
53
|
+
sc.shape(shape)
|
|
54
|
+
sc.fill_color(colors.pop)
|
|
55
|
+
end
|
|
56
|
+
plot.export_html("3dscatter.html")
|
|
57
|
+
|
|
58
|
+
# Particles
|
|
59
|
+
plot = Nyaplot::Plot3D.new
|
|
60
|
+
['#ff7f00','#1f78b4','#a6cee3'].each_with_index do |color, index|
|
|
61
|
+
x=[];y=[];z=[];dz = 5*rand
|
|
62
|
+
0.step(1, 0.2) do |i|
|
|
63
|
+
0.step(1, 0.2) do |j|
|
|
64
|
+
x.push(i+rand)
|
|
65
|
+
y.push(j+rand)
|
|
66
|
+
z.push(Math.sin(i)*Math.sin(j)+dz+rand)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
p = plot.add(:particles, x, y, z)
|
|
70
|
+
p.color(color)
|
|
71
|
+
p.name('molecules')
|
|
72
|
+
end
|
|
73
|
+
plot.export_html("particles.html")
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
require 'nyaplot'
|
|
2
|
+
|
|
3
|
+
# Bar chart
|
|
4
|
+
plot = Nyaplot::Plot.new
|
|
5
|
+
plot.add(:bar, ['Persian', 'Maine Coon', 'American Shorthair'], [10,20,30])
|
|
6
|
+
plot.x_label("Species")
|
|
7
|
+
plot.y_label("Number")
|
|
8
|
+
plot.export_html("bar.html")
|
|
9
|
+
|
|
10
|
+
# Line chart
|
|
11
|
+
x = []; y = []; theta = 0.6; a=1
|
|
12
|
+
while theta < 14*Math::PI do
|
|
13
|
+
x.push(a*Math::cos(theta)/theta)
|
|
14
|
+
y.push(a*Math::sin(theta)/theta)
|
|
15
|
+
theta += 0.1
|
|
16
|
+
end
|
|
17
|
+
plot1 = Nyaplot::Plot.new
|
|
18
|
+
plot1.add(:line, x, y)
|
|
19
|
+
plot1.export_html("line.html")
|
|
20
|
+
|
|
21
|
+
# Scatter + Line
|
|
22
|
+
sc_y=[]; line_x=sc_x=[]; line_y=[]; a=0.5; b=3; noise=1.5; x=0
|
|
23
|
+
rnd = Random.new
|
|
24
|
+
while x<10
|
|
25
|
+
line_x.push(x)
|
|
26
|
+
line_y.push(a*x+b)
|
|
27
|
+
sc_y.push(a*x+b+noise*(rnd.rand-0.5))
|
|
28
|
+
x=(x+0.5).round(1)
|
|
29
|
+
end
|
|
30
|
+
plot2 = Nyaplot::Plot.new
|
|
31
|
+
sc = plot2.add(:scatter, sc_x, sc_y)
|
|
32
|
+
line = plot2.add(:line, line_x, line_y)
|
|
33
|
+
sc.color('#000')
|
|
34
|
+
sc.title('point')
|
|
35
|
+
line.title('line')
|
|
36
|
+
plot2.legend(true)
|
|
37
|
+
plot2.export_html("scatter_line.html")
|
|
38
|
+
|
|
39
|
+
# Histogram
|
|
40
|
+
arr=[]
|
|
41
|
+
1000.times {|i| arr.push((Float(i-500)/1000)**2)}
|
|
42
|
+
print arr.to_s
|
|
43
|
+
plot3 = Nyaplot::Plot.new
|
|
44
|
+
plot3.add(:histogram, arr)
|
|
45
|
+
plot3.yrange([0,250])
|
|
46
|
+
plot3.export_html("histogram.html")
|
|
47
|
+
|
|
48
|
+
# Box plot
|
|
49
|
+
arr2 = arr.map{|val| val/0.8-2}
|
|
50
|
+
arr3 = arr.map{|val| val*1.1+0.3}
|
|
51
|
+
arr4 = arr.map{|val| val*1.3+0.3}
|
|
52
|
+
plot4 = Nyaplot::Plot.new
|
|
53
|
+
plot4.add(:box, arr, arr2, arr3, arr4)
|
|
54
|
+
plot4.export_html("box.html")
|
|
55
|
+
|
|
56
|
+
# 2D- Histogram
|
|
57
|
+
x=[]; y=[]; fill=[]
|
|
58
|
+
-5.step(5, 0.2) do |i|
|
|
59
|
+
-5.step(5, 0.2) do |j|
|
|
60
|
+
x.push(i)
|
|
61
|
+
y.push(j)
|
|
62
|
+
val = Math.sin(Math.sqrt(i*i+j*j))/Math.sqrt(i*i+j*j)
|
|
63
|
+
fill.push((val.nan? ? 0 : val))
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
plot5 = Nyaplot::Plot.new
|
|
68
|
+
hm = plot5.add(:heatmap, x, y, fill)
|
|
69
|
+
hm.stroke_color("#fff")
|
|
70
|
+
hm.stroke_width("0")
|
|
71
|
+
hm.width(0.2)
|
|
72
|
+
hm.height(0.2)
|
|
73
|
+
plot5.legend(true)
|
|
74
|
+
plot5.export_html("heatmap.html")
|
data/examples/rb/bio.rb
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require 'nyaplot'
|
|
2
|
+
require 'bionya'
|
|
3
|
+
|
|
4
|
+
arr = []
|
|
5
|
+
10.times do |i|
|
|
6
|
+
arr.push({group: 'group' + i.to_s ,df: Nyaplot::DataFrame.new({axis: ['a', 'b', 'c'], val: [2, 3, 4]})})
|
|
7
|
+
end
|
|
8
|
+
df = Nyaplot::DataFrame.new(arr)
|
|
9
|
+
|
|
10
|
+
plot = Nyaplot::CircularPlot.new(df, :group, :df)
|
|
11
|
+
plot.add(1, :arc, :axis, :val)
|
|
12
|
+
plot.export_html("example_bionya.html")
|
|
13
|
+
|
|
14
|
+
df = Nyaplot::DataFrame.from_csv(File.expand_path('../../notebook/data/circular/category.csv',__FILE__))
|
|
15
|
+
df2 = Nyaplot::DataFrame.from_csv(File.expand_path('../../notebook/data/circular/hgmd.tsv', __FILE__), {col_sep: "\t"})
|
|
16
|
+
df3 = Nyaplot::DataFrame.from_csv(File.expand_path('../../notebook/data/circular/genes_hgmd.tsv', __FILE__), {col_sep: "\t"})
|
|
17
|
+
|
|
18
|
+
hash2 = {}
|
|
19
|
+
df3.each_row do |row|
|
|
20
|
+
chr_name = "chr" + row[:gene_name].match(/hs(.+)/)[1]
|
|
21
|
+
hash2[chr_name] ||= []
|
|
22
|
+
hash2[chr_name].push({locale: row[:start], name: row[:name]})
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
hash = {}
|
|
26
|
+
df2.each_row do |row|
|
|
27
|
+
chr_name = "chr" + row[:gene_name].match(/hs(.+)/)[1]
|
|
28
|
+
hash[chr_name] ||= []
|
|
29
|
+
hash[chr_name].push({start: row[:start], val: row[:num2]})
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
bin_size = df.size.max/50
|
|
33
|
+
chr_name = df.column(:name).to_a
|
|
34
|
+
nested = df.column(:size).to_a.map.with_index do |size, i|
|
|
35
|
+
vals = hash[chr_name[i]]
|
|
36
|
+
names = hash2[chr_name[i]]
|
|
37
|
+
vals = [] if vals.nil?
|
|
38
|
+
names = [] if names.nil?
|
|
39
|
+
raw = Array.new(size/bin_size, 0).map.with_index {|val, i|
|
|
40
|
+
val = vals.reduce(0){|memo, v| next memo + v[:val] if v[:start] > i*bin_size && v[:start] < (i+1)*bin_size; memo}
|
|
41
|
+
name = names.select {|name| name[:locale] > i*bin_size && name[:locale] < (i+1)*bin_size}
|
|
42
|
+
{axis: i*bin_size, val: val, name: (name.length==0 ? '' : name[0][:name])}
|
|
43
|
+
}
|
|
44
|
+
Nyaplot::DataFrame.new(raw)
|
|
45
|
+
end
|
|
46
|
+
df.df = nested
|
|
47
|
+
|
|
48
|
+
df.name = df.column(:name).to_a.map{|name| name.match(/chr(.+)/)[1]}
|
|
49
|
+
color = Nyaplot::Colors.qual
|
|
50
|
+
|
|
51
|
+
plot2 = Nyaplot::CircularPlot.new(df, :name, :df)
|
|
52
|
+
arc = plot2.add(1, :arc, :axis, :val)
|
|
53
|
+
arc.color(["rgb(56,108,176)"])
|
|
54
|
+
labels = plot2.add(2, :labels, :axis, :name)
|
|
55
|
+
labels.text_size("0.3em")
|
|
56
|
+
plot2.color(color)
|
|
57
|
+
plot2.text_size("0.5em")
|
|
58
|
+
plot2.text_color("#000")
|
|
59
|
+
plot2.export_html("mutations.html")
|
data/examples/rb/maps.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'nyaplot'
|
|
2
|
+
require 'mapnya'
|
|
3
|
+
|
|
4
|
+
raw_df = Nyaplot::Countries.df
|
|
5
|
+
|
|
6
|
+
hash = [:name, :lat, :lng, :area, :capital].map{|label| {label => raw_df.column(label).to_a}}.reduce({}){|memo, hash| memo.merge(hash)}
|
|
7
|
+
df = Nyaplot::DataFrame.new(hash)
|
|
8
|
+
|
|
9
|
+
color = Nyaplot::Colors.Reds
|
|
10
|
+
|
|
11
|
+
plot = Nyaplot::MapPlot.new
|
|
12
|
+
sc = plot.add_with_df(df, :scatter, :lng, :lat) # x->:lng, y->lat
|
|
13
|
+
sc.configure do
|
|
14
|
+
tooltip_contents([:capital, :name, :area])
|
|
15
|
+
color(color)
|
|
16
|
+
size([10, 100000])
|
|
17
|
+
size_by(:area)
|
|
18
|
+
fill_by(:area)
|
|
19
|
+
end
|
|
20
|
+
plot.export_html("scatter_on_the_map.html")
|
|
21
|
+
|
|
22
|
+
plot = Nyaplot::MapPlot.new
|
|
23
|
+
plot.add_map("AUS")
|
|
24
|
+
plot.scale(800)
|
|
25
|
+
plot.export_html("australia.html")
|
|
26
|
+
|
|
27
|
+
plot.add_map("JPN")
|
|
28
|
+
plot.export_html("japan.html")
|
|
29
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'nyaplot'
|
|
2
|
+
|
|
3
|
+
path = File.expand_path("../../notebook/data/first.tab", __FILE__)
|
|
4
|
+
df = Nyaplot::DataFrame.from_csv(path, sep="\t")
|
|
5
|
+
df.filter! {|row| row[:set1] != 0.0}
|
|
6
|
+
|
|
7
|
+
plot4=Nyaplot::Plot.new
|
|
8
|
+
plot4.add_with_df(df, :histogram, :set1)
|
|
9
|
+
plot4.configure do
|
|
10
|
+
height(400)
|
|
11
|
+
x_label('PNR')
|
|
12
|
+
y_label('Frequency')
|
|
13
|
+
filter({target:'x'})
|
|
14
|
+
yrange([0,130])
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
plot5=Nyaplot::Plot.new
|
|
18
|
+
plot5.add_with_df(df, :bar, :mutation)
|
|
19
|
+
plot5.configure do
|
|
20
|
+
height(400)
|
|
21
|
+
x_label('Mutation types')
|
|
22
|
+
y_label('Frequency')
|
|
23
|
+
yrange([0,100])
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
frame = Nyaplot::Frame.new
|
|
27
|
+
frame.add(plot4)
|
|
28
|
+
frame.add(plot5)
|
|
29
|
+
frame.export_html("multiple_pane.html")
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'nyaplot'
|
|
2
|
+
|
|
3
|
+
samples = Array.new(10).map.with_index{|d,i| 'cat'+i.to_s}
|
|
4
|
+
address = ['London', 'Kyoto', 'Los Angeles', 'Puretoria']
|
|
5
|
+
x=[];y=[];home=[]
|
|
6
|
+
|
|
7
|
+
10.times do
|
|
8
|
+
x.push(5*rand)
|
|
9
|
+
y.push(5*rand)
|
|
10
|
+
home.push(address.clone.sample)
|
|
11
|
+
end
|
|
12
|
+
df = Nyaplot::DataFrame.new({x: x,y: y,name: samples, home: home})
|
|
13
|
+
|
|
14
|
+
plot = Nyaplot::Plot.new
|
|
15
|
+
plot.x_label("weight [kg]")
|
|
16
|
+
plot.y_label("height [m]")
|
|
17
|
+
|
|
18
|
+
color = Nyaplot::Colors.qual
|
|
19
|
+
|
|
20
|
+
sc = plot.add_with_df(df, :scatter, :x, :y)
|
|
21
|
+
sc.tooltip_contents([:name, :home])
|
|
22
|
+
sc.fill_by(:home)
|
|
23
|
+
sc.shape_by(:home)
|
|
24
|
+
sc.color(color)
|
|
25
|
+
|
|
26
|
+
plot.export_html("scatter.html")
|
data/examples/rb/wind.rb
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'nyaplot'
|
|
2
|
+
require 'mapnya'
|
|
3
|
+
|
|
4
|
+
path = File.expand_path("../../notebook/data/wind.csv", __FILE__)
|
|
5
|
+
abs = []
|
|
6
|
+
df = Nyaplot::DataFrame.from_csv(path)
|
|
7
|
+
df.filter!{|row| !(row[:lon] < 200 && row[:lon] > 175)}
|
|
8
|
+
df.each_row{|row| row[:uwnd] = row[:uwnd]/3; row[:vwnd] = row[:vwnd]/3}
|
|
9
|
+
df.each_row{|row| abs.push(Math.sqrt(row[:uwnd]*row[:uwnd]+row[:vwnd]*row[:vwnd]))}
|
|
10
|
+
df.abs = abs
|
|
11
|
+
|
|
12
|
+
plot = Nyaplot::MapPlot.new
|
|
13
|
+
vectors = plot.add_with_df(df, :vectors, :lon, :lat)
|
|
14
|
+
vectors.dx(:uwnd)
|
|
15
|
+
vectors.dy(:vwnd)
|
|
16
|
+
vectors.fill_by(:abs)
|
|
17
|
+
|
|
18
|
+
color = Nyaplot::Colors.OrRd(3)
|
|
19
|
+
vectors.color(color)
|
|
20
|
+
plot.export_html("wind_vectors.html")
|
data/lib/nyaplot/core.rb
CHANGED
|
@@ -26,13 +26,19 @@ module Nyaplot
|
|
|
26
26
|
@@additional_libraries[name]=url
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
#
|
|
30
|
-
def self.
|
|
29
|
+
# generate initializing code
|
|
30
|
+
def self.generate_init_code
|
|
31
31
|
path = File.expand_path("../templates/init.js.erb", __FILE__)
|
|
32
32
|
template = File.read(path)
|
|
33
33
|
dep_libraries = @@dep_libraries
|
|
34
34
|
additional_libraries = @@additional_libraries
|
|
35
35
|
js = ERB.new(template).result(binding)
|
|
36
|
+
js
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Enable to show plots on IRuby notebook
|
|
40
|
+
def self.init_iruby
|
|
41
|
+
js = self.generate_init_code
|
|
36
42
|
IRuby.display(IRuby.javascript(js))
|
|
37
43
|
end
|
|
38
44
|
|
data/lib/nyaplot/data.rb
CHANGED
|
@@ -135,9 +135,13 @@ module Nyaplot
|
|
|
135
135
|
end
|
|
136
136
|
|
|
137
137
|
def to_html(threshold = 15)
|
|
138
|
-
html = '<table
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
html = '<table>'
|
|
139
|
+
|
|
140
|
+
unless @rows[0].nil?
|
|
141
|
+
html += '<tr>'
|
|
142
|
+
@rows[0].each {|key, val| html.concat('<th>' + key.to_s + '</th>')}
|
|
143
|
+
html += '</tr>'
|
|
144
|
+
end
|
|
141
145
|
|
|
142
146
|
@rows.each_with_index do |row, i|
|
|
143
147
|
next if i > threshold && i < @rows.length-1
|
data/lib/nyaplot/frame.rb
CHANGED
|
@@ -26,23 +26,36 @@ module Nyaplot
|
|
|
26
26
|
panes.push(plot)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
#
|
|
29
|
+
# generate html code for <body> tag
|
|
30
|
+
def generate_body
|
|
31
|
+
path = File.expand_path("../templates/iruby.erb", __FILE__)
|
|
32
|
+
template = File.read(path)
|
|
33
|
+
id = SecureRandom.uuid()
|
|
34
|
+
model = self.to_json
|
|
35
|
+
ERB.new(template).result(binding)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# generate static html file
|
|
30
39
|
# @return [String] generated html
|
|
31
|
-
def
|
|
40
|
+
def generate_html
|
|
41
|
+
body = generate_body
|
|
42
|
+
init = Nyaplot.generate_init_code
|
|
32
43
|
path = File.expand_path("../templates/static_html.erb", __FILE__)
|
|
33
44
|
template = File.read(path)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
45
|
+
ERB.new(template).result(binding)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# export static html file
|
|
49
|
+
def export_html(path="./plot.html")
|
|
50
|
+
path = File.expand_path(path, Dir::pwd)
|
|
51
|
+
str = generate_html
|
|
52
|
+
File.write(path, str)
|
|
37
53
|
end
|
|
38
54
|
|
|
39
55
|
# show plot automatically on IRuby notebook
|
|
40
56
|
def to_iruby
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
id = SecureRandom.uuid()
|
|
44
|
-
model = self.to_json
|
|
45
|
-
['text/html', ERB.new(template).result(binding)]
|
|
57
|
+
html = generate_body
|
|
58
|
+
['text/html', html]
|
|
46
59
|
end
|
|
47
60
|
|
|
48
61
|
# show plot on IRuby notebook
|
data/lib/nyaplot/plot.rb
CHANGED
|
@@ -82,6 +82,13 @@ module Nyaplot
|
|
|
82
82
|
Frame.new.tap {|f| f.add(self) }.show
|
|
83
83
|
end
|
|
84
84
|
|
|
85
|
+
# export html file
|
|
86
|
+
def export_html(path=nil)
|
|
87
|
+
require 'securerandom'
|
|
88
|
+
path = "./plot-" + SecureRandom.uuid().to_s + ".html" if path.nil?
|
|
89
|
+
Frame.new.tap {|f| f.add(self) }.export_html(path)
|
|
90
|
+
end
|
|
91
|
+
|
|
85
92
|
# @return [Array<String>] names of dataframe used by diagrams belog to this plot
|
|
86
93
|
def df_list
|
|
87
94
|
arr=[]
|
|
@@ -92,6 +99,7 @@ module Nyaplot
|
|
|
92
99
|
|
|
93
100
|
def before_to_json
|
|
94
101
|
diagrams = get_property(:diagrams)
|
|
102
|
+
return if diagrams.length == 0
|
|
95
103
|
|
|
96
104
|
# set default values when not specified by users
|
|
97
105
|
zoom(true) if diagrams.all?{|d| d.zoom?}
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
<html lang='en'>
|
|
2
2
|
<head>
|
|
3
3
|
<title>Nyaplot</title>
|
|
4
|
-
<script src=
|
|
5
|
-
<script
|
|
4
|
+
<script src="http://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.14/require.min.js"></script>
|
|
5
|
+
<script><%= init %></script>
|
|
6
6
|
</head>
|
|
7
|
-
<body>
|
|
8
|
-
<div id='vis'></div>
|
|
9
|
-
<script>
|
|
10
|
-
model = <%= model %>
|
|
11
|
-
window.onload = function(){Nyaplot.core.parse(model, '#vis');};
|
|
12
|
-
</script>
|
|
13
|
-
</body>
|
|
7
|
+
<body><%= body %></body>
|
|
14
8
|
</html>
|
data/lib/nyaplot/version.rb
CHANGED
data/lib/nyaplot3d/plot3d.rb
CHANGED
|
@@ -43,9 +43,19 @@ module Nyaplot
|
|
|
43
43
|
|
|
44
44
|
# Show plot on IRuby notebook
|
|
45
45
|
def show
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
Frame.new.tap {|f| f.add(self) }.show
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Show plot automatically on IRuby notebook
|
|
50
|
+
def to_iruby
|
|
51
|
+
Frame.new.tap {|f| f.add(self) }.to_iruby
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# export html file
|
|
55
|
+
def export_html(path=nil)
|
|
56
|
+
require 'securerandom'
|
|
57
|
+
path = "./plot-" + SecureRandom.uuid().to_s + ".html" if path.nil?
|
|
58
|
+
Frame.new.tap {|f| f.add(self) }.export_html(path)
|
|
49
59
|
end
|
|
50
60
|
|
|
51
61
|
# @return [Array<String>] names of dataframe used by diagrams belog to this plot
|
data/nyaplot.gemspec
CHANGED
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
|
9
9
|
spec.authors = ["Naoki Nishida"]
|
|
10
10
|
spec.email = ["domitry@gmail.com"]
|
|
11
11
|
spec.summary = %q{interactive plots generator for Ruby users}
|
|
12
|
-
spec.description = %q{
|
|
12
|
+
spec.description = %q{interactive plots generator for Ruby users. Visit the GitHub repository to get more information.}
|
|
13
13
|
spec.homepage = "https://www.github.com/domitry/nyaplot"
|
|
14
14
|
spec.license = "MIT"
|
|
15
15
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: nyaplot
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Naoki Nishida
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-08-
|
|
11
|
+
date: 2014-08-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -66,8 +66,8 @@ dependencies:
|
|
|
66
66
|
- - ">="
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
68
|
version: '0'
|
|
69
|
-
description:
|
|
70
|
-
|
|
69
|
+
description: interactive plots generator for Ruby users. Visit the GitHub repository
|
|
70
|
+
to get more information.
|
|
71
71
|
email:
|
|
72
72
|
- domitry@gmail.com
|
|
73
73
|
executables: []
|
|
@@ -104,6 +104,13 @@ files:
|
|
|
104
104
|
- examples/notebook/data/operon.csv
|
|
105
105
|
- examples/notebook/data/ttest.csv
|
|
106
106
|
- examples/notebook/data/wind.csv
|
|
107
|
+
- examples/rb/3d.rb
|
|
108
|
+
- examples/rb/basic.rb
|
|
109
|
+
- examples/rb/bio.rb
|
|
110
|
+
- examples/rb/maps.rb
|
|
111
|
+
- examples/rb/multiple.rb
|
|
112
|
+
- examples/rb/scatter.rb
|
|
113
|
+
- examples/rb/wind.rb
|
|
107
114
|
- lib/bionya.rb
|
|
108
115
|
- lib/bionya/README.md
|
|
109
116
|
- lib/bionya/core.rb
|