├── .circleci
└── config.yml
├── .gitignore
├── Dockerfile
├── Gemfile
├── Gemfile.lock
├── LICENSE
├── README.md
├── Rakefile
├── _config.yml
├── appveyor.yml
├── bin
├── console
└── setup
├── docs
├── _config.yml
├── bio.html
├── charty.html
├── graph.html
├── index.html
├── rbplotly-bar.html
├── rbplotly-basic.html
├── rbplotly-boxplot.html
├── rbplotly-heatmap.html
├── rbplotly-hist.html
├── rbplotly-line.html
├── rbplotly-pie.html
├── rbplotly-scatter.html
├── rumale-kmeans.html
├── rumale.html
└── table.html
├── examples
├── bio.md
├── charty.md
├── graph.md
├── index.md
├── numo-gnuplot.ipynb
├── rbplotly-bar.md
├── rbplotly-basic.md
├── rbplotly-boxplot.md
├── rbplotly-heatmap.md
├── rbplotly-hist.md
├── rbplotly-line.md
├── rbplotly-pie.md
├── rbplotly-scatter.md
├── rumale-kmeans.md
├── rumale.md
└── table.md
├── exe
└── rubydown
├── lib
├── rubydown.rb
└── rubydown
│ └── version.rb
├── rubydown.gemspec
├── templates
└── template.html.erb
└── test
└── test-table.rb
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | # Ruby CircleCI 2.0 configuration file
2 | #
3 | # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4 | #
5 | version: 2
6 | jobs:
7 | build:
8 | docker:
9 | - image: ruby
10 |
11 | working_directory: ~/repo
12 |
13 | steps:
14 | - checkout
15 |
16 | - run:
17 | name: install rubydown
18 | command: |
19 | apt-get update
20 | apt-get install -y gnuplot
21 | gem build rubydown.gemspec
22 | gem install rubydown-0.2.0.gem
23 | gem install bio
24 |
25 | # run tests!
26 | - run:
27 | name: run tests
28 | command: |
29 | rubydown -i examples/bio.md -e templates/template.html.erb -o /tmp/bio.html
30 | rubydown -i examples/table.md -e templates/template.html.erb -o /tmp/table.html
31 | rubydown -i examples/graph.md -e templates/template.html.erb -o /tmp/graph.html
32 |
33 | # collect reports
34 | - store_artifacts:
35 | path: /tmp
36 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | vendor/
2 | pkg/
3 | .bundle/
4 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM ruby
2 |
3 | USER root
4 |
5 | RUN apt-get update && apt-get install -y emacs25-nox vim-nox mlocate locales-all tmux gnuplot && gem install numo-gnuplot\
6 | git config --global alias.co checkout && \
7 | git config --global alias.br branch && \
8 | git config --global alias.ci commit && \
9 | git config --global alias.st status
10 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source "https://rubygems.org"
2 |
3 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4 |
5 | # Specify your gem's dependencies in rubydown.gemspec
6 | gemspec
7 |
8 | gem "test-unit", "~> 3.2"
9 |
--------------------------------------------------------------------------------
/Gemfile.lock:
--------------------------------------------------------------------------------
1 | PATH
2 | remote: .
3 | specs:
4 | rubydown (0.1.0)
5 | daru
6 | kramdown
7 | numo-gnuplot
8 | numo-narray
9 | pry
10 |
11 | GEM
12 | remote: https://rubygems.org/
13 | specs:
14 | backports (3.11.4)
15 | coderay (1.1.2)
16 | daru (0.2.1)
17 | backports
18 | packable (~> 1.3.9)
19 | kramdown (1.17.0)
20 | method_source (0.9.2)
21 | numo-gnuplot (0.2.4)
22 | numo-narray (0.9.1.3)
23 | packable (1.3.10)
24 | backports
25 | power_assert (1.1.3)
26 | pry (0.12.2)
27 | coderay (~> 1.1.0)
28 | method_source (~> 0.9.0)
29 | rake (10.5.0)
30 | test-unit (3.2.9)
31 | power_assert
32 |
33 | PLATFORMS
34 | ruby
35 |
36 | DEPENDENCIES
37 | bundler (~> 1.17)
38 | rake (~> 10.0)
39 | rubydown!
40 | test-unit
41 |
42 | BUNDLED WITH
43 | 1.17.3
44 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Yusuke Sangenya
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # rubydown
2 |
3 | [](https://circleci.com/gh/RubyData/rubydown/tree/master)
4 | [](https://ci.appveyor.com/project/kozo2/rubydown)
5 |
6 | *rubydown* is pure-Ruby [R Markdown](https://rmarkdown.rstudio.com/) clone.
7 | It takes a markdown source file, executes the code chunks, captures the output, and stitches the output into the destination file.
8 |
9 | Python also has R Markdown like packages.
10 | If you have interest about making reproducible reports, please also refer to the following projects.
11 |
12 | https://github.com/jankatins/knitpy
13 | https://github.com/pystitch/stitch
14 | https://github.com/danijar/handout
15 |
16 |
17 | ## Install
18 |
19 | ```
20 | sudo apt install gnuplot # When you use numo-gnuplot with rubydown
21 |
22 | sudo apt install python3-pip # When you use charty with rubydown
23 | sudo python3 -m pip install -U pip matplotlib # When you use charty with rubydown
24 |
25 | gem install rubydown
26 | ```
27 |
28 | ## Usage (example with [rumale](https://github.com/yoshoku/rumale) and [rdatasets](https://github.com/kojix2/rdatasets))
29 |
30 | ```
31 | gem install rumale rdatasets
32 | git clone git://github.com/RubyData/rubydown
33 | cd rubydown/examples
34 | rubydown -i rumale.md
35 | ```
36 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | require "bundler/gem_tasks"
2 | task :default => :spec
3 |
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-cayman
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | # appveyor.yml
2 | install:
3 | - set PATH=C:\Ruby25-x64\bin;%PATH%
4 | - gem build rubydown.gemspec
5 | - gem install rubydown-0.2.0.gem
6 |
7 | build: off
8 |
9 | before_test:
10 | - ruby -v
11 | - gem -v
12 | - bundle -v
13 | - rubydown --version
14 | - gem install bio
15 |
16 | test_script:
17 | - choco install gnuplot
18 | - set PATH=C:\Program Files\gnuplot\bin;%PATH%
19 | - gnuplot --version
20 | - rubydown -i examples\bio.md -e templates\template.html.erb -o bio.html
21 | - rubydown -i examples\graph.md -e templates\template.html.erb -o graph.html
22 | - rubydown -i examples\table.md -e templates\template.html.erb -o table.html
23 |
24 | artifacts:
25 | - path: '*.html'
26 |
--------------------------------------------------------------------------------
/bin/console:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | require "bundler/setup"
4 | require "rubydown"
5 |
6 | # You can add fixtures and/or initialization code here to make experimenting
7 | # with your gem easier. You can also use a different console, if you like.
8 |
9 | # (If you use this, don't forget to add pry to your Gemfile!)
10 | # require "pry"
11 | # Pry.start
12 |
13 | require "irb"
14 | IRB.start(__FILE__)
15 |
--------------------------------------------------------------------------------
/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -euo pipefail
3 | IFS=$'\n\t'
4 | set -vx
5 |
6 | bundle install
7 |
8 | # Do any other automated setup that you need to do here
9 |
--------------------------------------------------------------------------------
/docs/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-cayman
--------------------------------------------------------------------------------
/docs/bio.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
19 |
20 |
21 |
22 |
23 | BioRuby Tutorial
24 |
25 | Trying Bioruby
26 |
27 | Now test the following:
28 |
29 | require 'bio'
30 | seq = Bio::Sequence::NA.new("atgcatgcaaaa")
31 |
32 |
=> atgcatgcaaaa
33 |
34 |
35 |
36 | seq.complement
37 |
38 |
=> ttttgcatgcat
39 |
40 |
41 |
42 | Working with nucleic / amino acid sequences (Bio::Sequence class)
43 |
44 | The Bio::Sequence
class allows the usual sequence transformations and translations.
45 |
46 | In the example below the DNA sequence atgcatgcaaaa
is converted into the complemental strand and spliced into a subsequence; next, the nucleic acid composition is calculated and the sequence is translated into the amino acid sequence, the molecular weight calculated, and so on. When translating into amino acid sequences, the frame can be specified and optionally the codon table selected (as defined in codontable.rb ).
47 |
48 | seq = Bio::Sequence::NA.new("atgcatgcaaaa")
49 |
50 |
=> atgcatgcaaaa
51 |
52 |
53 |
54 | # complemental sequence (Bio::Sequence::NA object)
55 | seq.complement
56 |
57 |
=> ttttgcatgcat
58 |
59 |
60 |
61 | seq.subseq(3,8) # gets subsequence of positions 3 to 8 (starting from 1)
62 |
63 |
=> gcatgc
64 |
65 |
66 |
67 | seq.gc_percent
68 |
69 |
=> 33
70 |
71 |
72 |
73 | seq.composition
74 |
75 |
=> {"a"=>6, "t"=>2, "g"=>2, "c"=>2}
76 |
77 |
78 |
79 | seq.translate
80 |
81 |
=> MHAK
82 |
83 |
84 |
85 | seq.translate(2)
86 |
87 |
=> CMQ
88 |
89 |
90 |
91 | seq.translate(1,11)
92 |
93 |
=> MHAK
94 |
95 |
96 |
97 | seq.translate.codes
98 |
99 |
=> ["Met", "His", "Ala", "Lys"]
100 |
101 |
102 |
103 | seq.translate.names
104 |
105 |
=> ["methionine", "histidine", "alanine", "lysine"]
106 |
107 |
108 |
109 | seq.translate.composition
110 |
111 |
=> {"M"=>1, "H"=>1, "A"=>1, "K"=>1}
112 |
113 |
114 |
115 | seq.translate.molecular_weight
116 |
117 |
=> 485.6050000000001
118 |
119 |
120 |
121 | seq.complement.translate
122 |
123 |
=> FCMH
124 |
125 |
126 |
127 |
128 |
129 |
130 |
--------------------------------------------------------------------------------
/docs/charty.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
19 |
20 |
21 |
22 |
23 |
24 | Charty Usage
25 |
26 | You can write Markdown!
27 |
28 |
29 | item1
30 | item2
31 |
32 |
33 |
34 | require 'charty'
35 | charty = Charty::Plotter.new(:pyplot)
36 |
37 | bar = charty.bar do
38 | series [0,1,2,3,4], [10,40,20,90,70]
39 | series [0,1,2,3,4], [90,80,70,60,50]
40 | series [0,1,2,3,4,5,6,7,8], [50,60,20,30,10, 90, 0, 100, 50]
41 | range x: 0..10, y: 1..100
42 | xlabel 'foo'
43 | ylabel 'bar'
44 | title 'bar plot'
45 | end
46 | bar.render("bar_matplot.png")
47 |
48 |
290 |
291 |
292 |
293 |
294 |
--------------------------------------------------------------------------------
/docs/graph.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
19 |
20 |
21 |
22 |
23 | Graph generation example
24 |
25 |
26 |
27 | Rubydown::RbMarkPlot
is extended class of Numo::Gnuplot
28 |
29 | rp = Rubydown::RbMarkPlot.new
30 | rp.set title: "Example Plot"
31 | rp.plot "sin(x)", w:"lines"
32 |
33 |
158 |
159 |
160 |
161 |
--------------------------------------------------------------------------------
/docs/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
19 |
20 |
21 |
22 |
23 | テスト
24 |
25 | コードを書く
26 |
27 | ~~~ruby と ~~~ でコードを囲むと、そのブロックが評価される。
28 |
29 | array = [1,2,3,4]
30 | converted = array.map { |e| e * 100 }
31 |
32 | converted # 最後の行が出力される
33 |
34 |
=> [100, 200, 300, 400]
35 |
36 |
37 |
38 | 標準出力も表示される
39 |
40 | puts :hoge
41 |
42 | "fuga\npiyo".inspect
43 |
44 |
hoge
45 |
46 | => "fuga\npiyo"
47 |
48 |
49 |
50 | ブロックは全部同じスコープ
51 |
52 | 先程定義した変数converted
が以下でも使える。
53 |
54 | converted.map { |e| e / 100 }
55 |
56 |
=> [1, 2, 3, 4]
57 |
58 |
59 |
60 | ライブラリを使う
61 |
62 | もちろん外部のライブラリをロードすることもできる。
63 |
64 | require 'matrix'
65 |
66 | Matrix.identity(10)
67 |
68 |
=> Matrix[[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]
69 |
70 |
71 |
72 | to_htmlを実装する
73 |
74 | to_html
メソッドを実装すると、その結果が出力される。
75 |
76 | class Matrix # オープンクラス
77 | def to_html
78 | rows = self.to_a.map do |row|
79 | elems = row.map do |elem|
80 | "<td>#{elem}</td>"
81 | end
82 | "<tr>#{elems}</tr>"
83 | end
84 | "<table>#{rows.join}</table>"
85 | end
86 | end
87 |
88 | Matrix.identity(10)
89 |
90 |
91 |
92 |
93 | 1
94 | 0
95 | 0
96 | 0
97 | 0
98 | 0
99 | 0
100 | 0
101 | 0
102 | 0
103 |
104 |
105 | 0
106 | 1
107 | 0
108 | 0
109 | 0
110 | 0
111 | 0
112 | 0
113 | 0
114 | 0
115 |
116 |
117 | 0
118 | 0
119 | 1
120 | 0
121 | 0
122 | 0
123 | 0
124 | 0
125 | 0
126 | 0
127 |
128 |
129 | 0
130 | 0
131 | 0
132 | 1
133 | 0
134 | 0
135 | 0
136 | 0
137 | 0
138 | 0
139 |
140 |
141 | 0
142 | 0
143 | 0
144 | 0
145 | 1
146 | 0
147 | 0
148 | 0
149 | 0
150 | 0
151 |
152 |
153 | 0
154 | 0
155 | 0
156 | 0
157 | 0
158 | 1
159 | 0
160 | 0
161 | 0
162 | 0
163 |
164 |
165 | 0
166 | 0
167 | 0
168 | 0
169 | 0
170 | 0
171 | 1
172 | 0
173 | 0
174 | 0
175 |
176 |
177 | 0
178 | 0
179 | 0
180 | 0
181 | 0
182 | 0
183 | 0
184 | 1
185 | 0
186 | 0
187 |
188 |
189 | 0
190 | 0
191 | 0
192 | 0
193 | 0
194 | 0
195 | 0
196 | 0
197 | 1
198 | 0
199 |
200 |
201 | 0
202 | 0
203 | 0
204 | 0
205 | 0
206 | 0
207 | 0
208 | 0
209 | 0
210 | 1
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
--------------------------------------------------------------------------------
/docs/rbplotly-bar.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
19 |
20 |
21 |
22 |
23 | rbplotly bar chart usage
24 |
25 | require 'rbplotly'
26 |
27 | trace = {
28 | x: %w(giraffes orangutans monkeys),
29 | y: [20, 14, 23],
30 | type: :bar
31 | }
32 |
33 | plot = Plotly::Plot.new(data: [trace])
34 |
35 |
38 |
39 |
53 |
54 | trace1 = {
55 | x: %w(giraffes orangutans monkeys),
56 | y: [20, 14, 23],
57 | type: :bar,
58 | name: 'SF Zoo'
59 | }
60 | trace2 = {
61 | x: %w(giraffes orangutans monkeys),
62 | y: [12, 18, 29],
63 | type: :bar,
64 | name: 'LA Zoo'
65 | }
66 |
67 | plot = Plotly::Plot.new(data: [trace1, trace2])
68 |
69 |
72 |
73 |
87 |
88 | plot.layout.barmode = :stack
89 | plot
90 |
91 |
94 |
95 |
109 |
110 | trace1 = {
111 | x: %w(giraffes orangutans monkeys),
112 | y: [20, 14, 23],
113 | type: :bar,
114 | name: 'SF Zoo'
115 | }
116 | trace2 = {
117 | x: %w(giraffes orangutans monkeys),
118 | y: [12, 18, 29],
119 | type: :bar,
120 | name: 'LA Zoo'
121 | }
122 |
123 | plot = Plotly::Plot.new(data: [trace1, trace2], layout: { barmode: :stack } )
124 |
125 |
128 |
129 |
143 |
144 |
145 |
146 |
147 |
--------------------------------------------------------------------------------
/docs/rbplotly-basic.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
19 |
20 |
21 |
22 |
23 | rbplotly basic usage
24 |
25 | require 'rbplotly'
26 |
27 | n = 100
28 |
29 | x = n.times.map { |i| i.to_f / (n - 1) }
30 | y0 = n.times.map { rand(-2.0..2.0) + 5 }
31 | y1 = n.times.map { rand(-2.0..2.0) }
32 |
33 | trace0 = { x: x, y: y0, type: :scatter, mode: :markers }
34 | trace1 = trace0.merge(y: y1, mode: :'markers+lines')
35 |
36 | plot = Plotly::Plot.new(data: [trace0, trace1])
37 |
38 |
41 |
42 |
56 |
57 | Here we replace the last trace range from -0.5 to 0.5
58 |
59 | plot.data.last.y = n.times.map { rand(-0.5..0.5) }
60 | plot
61 |
62 |
65 |
66 |
80 |
81 | Next we add a line trace with the center -5 and the range from -2.0 to 2.0.
82 |
83 | new_trace = { x: x, y: n.times.map { rand(-2.0..2.0) - 5 }, type: :scatter, mode: :lines }
84 | plot.data.push(new_trace)
85 | plot
86 |
87 |
90 |
91 |
105 |
106 | Last of all we add the x,y titles.
107 |
108 | plot.layout.xaxis = { title: 'x title' }
109 | plot.layout.yaxis = { title: 'y title' }
110 | plot
111 |
112 |
115 |
116 |
130 |
131 |
132 |
133 |
134 |
135 |
--------------------------------------------------------------------------------
/docs/rbplotly-boxplot.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
19 |
20 |
21 |
22 |
23 | rbplotly boxplot usage
24 |
25 | require 'rbplotly'
26 |
27 | n = 50
28 | y0 = n.times.map { rand(-1.0..0.0) }
29 | y1 = n.times.map { rand(0.0..1.0) }
30 |
31 | trace0 = {
32 | y: y0,
33 | type: :box
34 | }
35 |
36 | trace1 = {
37 | y: y1,
38 | type: :box
39 | }
40 |
41 | data = [trace0, trace1]
42 |
43 | plot = Plotly::Plot.new(data: data)
44 |
45 |
48 |
49 |
63 |
64 | Horizontal boxplot
65 |
66 | n = 50
67 | x0 = n.times.map { rand(-1.0..0.0) }
68 | x1 = n.times.map { rand(0.0..1.0) }
69 |
70 | trace0 = {
71 | x: x0,
72 | type: :box
73 | }
74 |
75 | trace1 = {
76 | x: x1,
77 | type: :box
78 | }
79 |
80 | data = [trace0, trace1]
81 |
82 | plot = Plotly::Plot.new(data: data)
83 |
84 |
87 |
88 |
102 |
103 | boxplot with the points
104 |
105 | trace = {
106 | y: [0, 1, 1, 2, 3, 5, 8, 13, 21],
107 | boxpoints: :all,
108 | jitter: 0.3,
109 | pointpos: -1.8,
110 | type: :box
111 | }
112 |
113 | plot = Plotly::Plot.new(data: [trace])
114 |
115 |
118 |
119 |
133 |
134 |
135 |
136 |
137 |
--------------------------------------------------------------------------------
/docs/rbplotly-heatmap.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
19 |
20 |
21 |
22 |
23 | rbplotly heatmap usage
24 |
25 | require 'rbplotly'
26 |
27 | z = [
28 | [1, 20, 30],
29 | [20, 1, 60],
30 | [30, 60, 1]
31 | ]
32 |
33 | data = [{
34 | z: z,
35 | type: :heatmap
36 | }]
37 |
38 | plot = Plotly::Plot.new(data: data)
39 |
40 |
43 |
44 |
58 |
59 | n = 10
60 | data = {
61 | x: (1..n).map { |i| "x#{i}" },
62 | y: (1..n).map { |i| "y#{i}" },
63 | z: (1..n).map { (1..n).map { rand(10) } },
64 | type: :heatmap
65 | }
66 |
67 | layout = {
68 | width: 500,
69 | height: 500
70 | }
71 |
72 | plot = Plotly::Plot.new(data: [data], layout: layout)
73 |
74 |
77 |
78 |
92 |
93 |
94 |
95 |
96 |
--------------------------------------------------------------------------------
/docs/rbplotly-hist.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
19 |
20 |
21 |
22 |
23 | rbplotly histogram usage
24 |
25 | require 'rbplotly'
26 |
27 | data = [{ x: (1..500).map { rand }, type: :histogram }]
28 |
29 | plot = Plotly::Plot.new(data: data)
30 |
31 |
34 |
35 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/docs/rbplotly-line.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
19 |
20 |
21 |
22 |
23 | rbplotly line plot usage
24 |
25 | require 'rbplotly'
26 |
27 | plot = Plotly::Plot.new
28 | flip = -1
29 | x = (0...100).map { |i| i.to_f / 10 }
30 | (0..5).each do |i|
31 | trace = {
32 | x: x,
33 | y: (1...100).map { |j| Math.sin(j.to_f / 10 + i) },
34 | line: { shape: :spline },
35 | mode: :lines
36 | }
37 | plot.data.push(trace)
38 | end
39 | plot
40 |
41 |
44 |
45 |
59 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/docs/rbplotly-pie.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
19 |
20 |
21 |
22 |
23 | rbplotly pie chart usage
24 |
25 | Basic pie chart
26 |
27 | require 'rbplotly'
28 |
29 | data = [{
30 | labels: %w(Residential Non-Residential Utility),
31 | values: [19, 26, 55],
32 | type: :pie
33 | }]
34 |
35 | layout = { title: 'Forcasted 2014 U.S. PV Installations by Market Segment' }
36 |
37 | plot = Plotly::Plot.new(data: data, layout: layout )
38 |
39 |
42 |
43 |
57 |
58 | Donut chart
59 |
60 | trace1 = {
61 | name: 'GHG Emissions',
62 | values: [16, 15, 12, 6, 5, 4, 42],
63 | domain: { x: [0, 0.5] },
64 |
65 | labels: %w(US China European Union Russian Federation Brazil India Rest\ of\ World),
66 | hoverinfo: :'label+percent+name',
67 | hole: 0.4,
68 | type: :pie,
69 | }
70 |
71 | trace2 = trace1.merge({
72 | name: 'CO2 Emissions',
73 | values: [27, 11, 25, 8, 1, 3, 25],
74 | domain: { x: [0.5, 1] }
75 | })
76 |
77 | plot = Plotly::Plot.new(data: [trace1, trace2])
78 |
79 |
82 |
83 |
97 |
98 |
99 |
100 |
101 |
--------------------------------------------------------------------------------
/docs/rbplotly-scatter.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
19 |
20 |
21 |
22 |
23 | rbplotly scatter plot usage
24 |
25 | Simple scatter Plot
26 |
27 | require 'rbplotly'
28 |
29 | n = 100
30 | x = n.times.map { rand(-2.0..2.0) }
31 | y = n.times.map { rand(-1.0..1.0) }
32 | trace = { x: x, y: y, mode: :markers }
33 |
34 | plot = Plotly::Plot.new(data: [trace])
35 | plot.layout.title = 'Simple Scatter Plot'
36 | plot
37 |
38 |
41 |
42 |
56 |
57 | Line and scatter plots
58 |
59 | n = 100
60 |
61 | x = n.times.map { |i| i.to_f / (n - 1) }
62 | y0 = n.times.map { rand(-2.0..2.0) + 5 }
63 | y1 = n.times.map { rand(-2.0..2.0) }
64 | y2 = n.times.map { rand(-2.0..2.0) - 5 }
65 |
66 | trace0 = { x: x, y: y0, type: :scatter, mode: :markers }
67 | trace1 = { x: x, y: y1, type: :scatter, mode: :'markers+lines' }
68 | trace2 = { x: x, y: y2, type: :scatter, mode: :lines }
69 |
70 | plot = Plotly::Plot.new(data: [trace0, trace1, trace2])
71 | plot.layout.title = 'Line and Scatter Plots'
72 | plot
73 |
74 |
77 |
78 |
92 |
93 | Style scatter plots
94 |
95 | n = 100
96 | trace0 = {
97 | x: n.times.map { rand(-2.0..2.0) },
98 | y: n.times.map { rand(-1.0..1.0) },
99 | name: 'Red',
100 | mode: :markers,
101 | marker: {
102 | size: 15,
103 | color: 'rgba(200, 0, 0, .5)',
104 | line: { width: 2, color: 'rgb(0, 0, 0, .5)' }
105 | }
106 | }
107 | trace1 = {
108 | x: n.times.map { rand(-2.0..2.0) },
109 | y: n.times.map { rand(-1.0..1.0) },
110 | name: 'Blue',
111 | mode: :markers,
112 | marker: {
113 | size: 10,
114 | color: 'rgba(0, 0, 200, .5)',
115 | line: { width: 1, color: 'rgb(0, 0, 0, .5)' }
116 | }
117 | }
118 |
119 | layout = {
120 | title: 'Styled Scatter',
121 | xaxis: { zeroline: false },
122 | yaxis: { zeroline: false }
123 | }
124 |
125 | plot = Plotly::Plot.new(data: [trace0, trace1], layout: layout)
126 |
127 |
130 |
131 |
145 |
146 |
147 |
148 |
149 |
--------------------------------------------------------------------------------
/docs/rumale-kmeans.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
19 |
20 |
21 |
22 |
23 |
24 | k-means clustering with rumale
25 |
26 | super simple k-means clustering demo
27 |
28 | require "numo/narray"
29 | require "rumale"
30 | samples = Numo::DFloat[[1, 2], [1, 4], [1, 0],[10, 2], [10, 4], [10, 0]]
31 | analyzer = Rumale::Clustering::KMeans.new(n_clusters: 2, max_iter: 50)
32 | cluster_labels = analyzer.fit_predict(samples)
33 |
34 | [1, 1, 1, 0, 0, 0]
35 |
36 | We can see that the rumale analyzer
separately labeled the first 3points and the last 3points.
37 |
38 | Visualizing clusters with rbplotly
39 |
40 | Next we visualize the cluster with rbplotly
41 |
42 | cluster0 = samples[0..2,0..1]
43 | cluster1 = samples[3..5,0..1]
44 | x0 = cluster0[0..-1,0].to_a
45 | y0 = cluster0[0..-1,1].to_a
46 | x1 = cluster1[0..-1,0].to_a
47 | y1 = cluster1[0..-1,1].to_a
48 | trace0 = {x:x0, y:y0, type: :scatter, mode: :markers}
49 | trace1 = {x:x1, y:y1, type: :scatter, mode: :markers}
50 | plot = Plotly::Plot.new(data: [trace0, trace1])
51 |
52 |
55 |
56 |
70 |
71 | The end
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/docs/rumale.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
19 |
20 |
21 |
22 |
23 | Rumale machine learning examples
24 |
25 | require 'rumale'
26 | require 'rdatasets'
27 |
28 | iris = RDatasets.load(:datasets, :iris)
29 |
30 | iris_labels = iris['Species'].to_a
31 | encoder = Rumale::Preprocessing::LabelEncoder.new
32 | labels = encoder.fit_transform(iris_labels)
33 | p "hoge"
34 |
35 |
"hoge"
36 |
37 | => hoge
38 |
39 |
40 |
41 | samples = Numo::DFloat[*iris[0..3].to_matrix.to_a]
42 |
43 |
44 |
45 |
46 | 5.1
47 | 3.5
48 | 1.4
49 | 0.2
50 |
51 |
52 | 4.9
53 | 3.0
54 | 1.4
55 | 0.2
56 |
57 |
58 | 4.7
59 | 3.2
60 | 1.3
61 | 0.2
62 |
63 |
64 | 4.6
65 | 3.1
66 | 1.5
67 | 0.2
68 |
69 |
70 | 5.0
71 | 3.6
72 | 1.4
73 | 0.2
74 |
75 |
76 | 5.4
77 | 3.9
78 | 1.7
79 | 0.4
80 |
81 |
82 | 4.6
83 | 3.4
84 | 1.4
85 | 0.3
86 |
87 |
88 | 5.0
89 | 3.4
90 | 1.5
91 | 0.2
92 |
93 |
94 | 4.4
95 | 2.9
96 | 1.4
97 | 0.2
98 |
99 |
100 | 4.9
101 | 3.1
102 | 1.5
103 | 0.1
104 |
105 |
106 | 5.4
107 | 3.7
108 | 1.5
109 | 0.2
110 |
111 |
112 | 4.8
113 | 3.4
114 | 1.6
115 | 0.2
116 |
117 |
118 | 4.8
119 | 3.0
120 | 1.4
121 | 0.1
122 |
123 |
124 | 4.3
125 | 3.0
126 | 1.1
127 | 0.1
128 |
129 |
130 | 5.8
131 | 4.0
132 | 1.2
133 | 0.2
134 |
135 |
136 | 5.7
137 | 4.4
138 | 1.5
139 | 0.4
140 |
141 |
142 | 5.4
143 | 3.9
144 | 1.3
145 | 0.4
146 |
147 |
148 | 5.1
149 | 3.5
150 | 1.4
151 | 0.3
152 |
153 |
154 | 5.7
155 | 3.8
156 | 1.7
157 | 0.3
158 |
159 |
160 | 5.1
161 | 3.8
162 | 1.5
163 | 0.3
164 |
165 |
166 | 5.4
167 | 3.4
168 | 1.7
169 | 0.2
170 |
171 |
172 | 5.1
173 | 3.7
174 | 1.5
175 | 0.4
176 |
177 |
178 | 4.6
179 | 3.6
180 | 1.0
181 | 0.2
182 |
183 |
184 | 5.1
185 | 3.3
186 | 1.7
187 | 0.5
188 |
189 |
190 | 4.8
191 | 3.4
192 | 1.9
193 | 0.2
194 |
195 |
196 | 5.0
197 | 3.0
198 | 1.6
199 | 0.2
200 |
201 |
202 | 5.0
203 | 3.4
204 | 1.6
205 | 0.4
206 |
207 |
208 | 5.2
209 | 3.5
210 | 1.5
211 | 0.2
212 |
213 |
214 | 5.2
215 | 3.4
216 | 1.4
217 | 0.2
218 |
219 |
220 | 4.7
221 | 3.2
222 | 1.6
223 | 0.2
224 |
225 |
226 | 4.8
227 | 3.1
228 | 1.6
229 | 0.2
230 |
231 |
232 | 5.4
233 | 3.4
234 | 1.5
235 | 0.4
236 |
237 |
238 | 5.2
239 | 4.1
240 | 1.5
241 | 0.1
242 |
243 |
244 | 5.5
245 | 4.2
246 | 1.4
247 | 0.2
248 |
249 |
250 | 4.9
251 | 3.1
252 | 1.5
253 | 0.2
254 |
255 |
256 | 5.0
257 | 3.2
258 | 1.2
259 | 0.2
260 |
261 |
262 | 5.5
263 | 3.5
264 | 1.3
265 | 0.2
266 |
267 |
268 | 4.9
269 | 3.6
270 | 1.4
271 | 0.1
272 |
273 |
274 | 4.4
275 | 3.0
276 | 1.3
277 | 0.2
278 |
279 |
280 | 5.1
281 | 3.4
282 | 1.5
283 | 0.2
284 |
285 |
286 | 5.0
287 | 3.5
288 | 1.3
289 | 0.3
290 |
291 |
292 | 4.5
293 | 2.3
294 | 1.3
295 | 0.3
296 |
297 |
298 | 4.4
299 | 3.2
300 | 1.3
301 | 0.2
302 |
303 |
304 | 5.0
305 | 3.5
306 | 1.6
307 | 0.6
308 |
309 |
310 | 5.1
311 | 3.8
312 | 1.9
313 | 0.4
314 |
315 |
316 | 4.8
317 | 3.0
318 | 1.4
319 | 0.3
320 |
321 |
322 | 5.1
323 | 3.8
324 | 1.6
325 | 0.2
326 |
327 |
328 | 4.6
329 | 3.2
330 | 1.4
331 | 0.2
332 |
333 |
334 | 5.3
335 | 3.7
336 | 1.5
337 | 0.2
338 |
339 |
340 | 5.0
341 | 3.3
342 | 1.4
343 | 0.2
344 |
345 |
346 | 7.0
347 | 3.2
348 | 4.7
349 | 1.4
350 |
351 |
352 | 6.4
353 | 3.2
354 | 4.5
355 | 1.5
356 |
357 |
358 | 6.9
359 | 3.1
360 | 4.9
361 | 1.5
362 |
363 |
364 | 5.5
365 | 2.3
366 | 4.0
367 | 1.3
368 |
369 |
370 | 6.5
371 | 2.8
372 | 4.6
373 | 1.5
374 |
375 |
376 | 5.7
377 | 2.8
378 | 4.5
379 | 1.3
380 |
381 |
382 | 6.3
383 | 3.3
384 | 4.7
385 | 1.6
386 |
387 |
388 | 4.9
389 | 2.4
390 | 3.3
391 | 1.0
392 |
393 |
394 | 6.6
395 | 2.9
396 | 4.6
397 | 1.3
398 |
399 |
400 | 5.2
401 | 2.7
402 | 3.9
403 | 1.4
404 |
405 |
406 | 5.0
407 | 2.0
408 | 3.5
409 | 1.0
410 |
411 |
412 | 5.9
413 | 3.0
414 | 4.2
415 | 1.5
416 |
417 |
418 | 6.0
419 | 2.2
420 | 4.0
421 | 1.0
422 |
423 |
424 | 6.1
425 | 2.9
426 | 4.7
427 | 1.4
428 |
429 |
430 | 5.6
431 | 2.9
432 | 3.6
433 | 1.3
434 |
435 |
436 | 6.7
437 | 3.1
438 | 4.4
439 | 1.4
440 |
441 |
442 | 5.6
443 | 3.0
444 | 4.5
445 | 1.5
446 |
447 |
448 | 5.8
449 | 2.7
450 | 4.1
451 | 1.0
452 |
453 |
454 | 6.2
455 | 2.2
456 | 4.5
457 | 1.5
458 |
459 |
460 | 5.6
461 | 2.5
462 | 3.9
463 | 1.1
464 |
465 |
466 | 5.9
467 | 3.2
468 | 4.8
469 | 1.8
470 |
471 |
472 | 6.1
473 | 2.8
474 | 4.0
475 | 1.3
476 |
477 |
478 | 6.3
479 | 2.5
480 | 4.9
481 | 1.5
482 |
483 |
484 | 6.1
485 | 2.8
486 | 4.7
487 | 1.2
488 |
489 |
490 | 6.4
491 | 2.9
492 | 4.3
493 | 1.3
494 |
495 |
496 | 6.6
497 | 3.0
498 | 4.4
499 | 1.4
500 |
501 |
502 | 6.8
503 | 2.8
504 | 4.8
505 | 1.4
506 |
507 |
508 | 6.7
509 | 3.0
510 | 5.0
511 | 1.7
512 |
513 |
514 | 6.0
515 | 2.9
516 | 4.5
517 | 1.5
518 |
519 |
520 | 5.7
521 | 2.6
522 | 3.5
523 | 1.0
524 |
525 |
526 | 5.5
527 | 2.4
528 | 3.8
529 | 1.1
530 |
531 |
532 | 5.5
533 | 2.4
534 | 3.7
535 | 1.0
536 |
537 |
538 | 5.8
539 | 2.7
540 | 3.9
541 | 1.2
542 |
543 |
544 | 6.0
545 | 2.7
546 | 5.1
547 | 1.6
548 |
549 |
550 | 5.4
551 | 3.0
552 | 4.5
553 | 1.5
554 |
555 |
556 | 6.0
557 | 3.4
558 | 4.5
559 | 1.6
560 |
561 |
562 | 6.7
563 | 3.1
564 | 4.7
565 | 1.5
566 |
567 |
568 | 6.3
569 | 2.3
570 | 4.4
571 | 1.3
572 |
573 |
574 | 5.6
575 | 3.0
576 | 4.1
577 | 1.3
578 |
579 |
580 | 5.5
581 | 2.5
582 | 4.0
583 | 1.3
584 |
585 |
586 | 5.5
587 | 2.6
588 | 4.4
589 | 1.2
590 |
591 |
592 | 6.1
593 | 3.0
594 | 4.6
595 | 1.4
596 |
597 |
598 | 5.8
599 | 2.6
600 | 4.0
601 | 1.2
602 |
603 |
604 | 5.0
605 | 2.3
606 | 3.3
607 | 1.0
608 |
609 |
610 | 5.6
611 | 2.7
612 | 4.2
613 | 1.3
614 |
615 |
616 | 5.7
617 | 3.0
618 | 4.2
619 | 1.2
620 |
621 |
622 | 5.7
623 | 2.9
624 | 4.2
625 | 1.3
626 |
627 |
628 | 6.2
629 | 2.9
630 | 4.3
631 | 1.3
632 |
633 |
634 | 5.1
635 | 2.5
636 | 3.0
637 | 1.1
638 |
639 |
640 | 5.7
641 | 2.8
642 | 4.1
643 | 1.3
644 |
645 |
646 | 6.3
647 | 3.3
648 | 6.0
649 | 2.5
650 |
651 |
652 | 5.8
653 | 2.7
654 | 5.1
655 | 1.9
656 |
657 |
658 | 7.1
659 | 3.0
660 | 5.9
661 | 2.1
662 |
663 |
664 | 6.3
665 | 2.9
666 | 5.6
667 | 1.8
668 |
669 |
670 | 6.5
671 | 3.0
672 | 5.8
673 | 2.2
674 |
675 |
676 | 7.6
677 | 3.0
678 | 6.6
679 | 2.1
680 |
681 |
682 | 4.9
683 | 2.5
684 | 4.5
685 | 1.7
686 |
687 |
688 | 7.3
689 | 2.9
690 | 6.3
691 | 1.8
692 |
693 |
694 | 6.7
695 | 2.5
696 | 5.8
697 | 1.8
698 |
699 |
700 | 7.2
701 | 3.6
702 | 6.1
703 | 2.5
704 |
705 |
706 | 6.5
707 | 3.2
708 | 5.1
709 | 2.0
710 |
711 |
712 | 6.4
713 | 2.7
714 | 5.3
715 | 1.9
716 |
717 |
718 | 6.8
719 | 3.0
720 | 5.5
721 | 2.1
722 |
723 |
724 | 5.7
725 | 2.5
726 | 5.0
727 | 2.0
728 |
729 |
730 | 5.8
731 | 2.8
732 | 5.1
733 | 2.4
734 |
735 |
736 | 6.4
737 | 3.2
738 | 5.3
739 | 2.3
740 |
741 |
742 | 6.5
743 | 3.0
744 | 5.5
745 | 1.8
746 |
747 |
748 | 7.7
749 | 3.8
750 | 6.7
751 | 2.2
752 |
753 |
754 | 7.7
755 | 2.6
756 | 6.9
757 | 2.3
758 |
759 |
760 | 6.0
761 | 2.2
762 | 5.0
763 | 1.5
764 |
765 |
766 | 6.9
767 | 3.2
768 | 5.7
769 | 2.3
770 |
771 |
772 | 5.6
773 | 2.8
774 | 4.9
775 | 2.0
776 |
777 |
778 | 7.7
779 | 2.8
780 | 6.7
781 | 2.0
782 |
783 |
784 | 6.3
785 | 2.7
786 | 4.9
787 | 1.8
788 |
789 |
790 | 6.7
791 | 3.3
792 | 5.7
793 | 2.1
794 |
795 |
796 | 7.2
797 | 3.2
798 | 6.0
799 | 1.8
800 |
801 |
802 | 6.2
803 | 2.8
804 | 4.8
805 | 1.8
806 |
807 |
808 | 6.1
809 | 3.0
810 | 4.9
811 | 1.8
812 |
813 |
814 | 6.4
815 | 2.8
816 | 5.6
817 | 2.1
818 |
819 |
820 | 7.2
821 | 3.0
822 | 5.8
823 | 1.6
824 |
825 |
826 | 7.4
827 | 2.8
828 | 6.1
829 | 1.9
830 |
831 |
832 | 7.9
833 | 3.8
834 | 6.4
835 | 2.0
836 |
837 |
838 | 6.4
839 | 2.8
840 | 5.6
841 | 2.2
842 |
843 |
844 | 6.3
845 | 2.8
846 | 5.1
847 | 1.5
848 |
849 |
850 | 6.1
851 | 2.6
852 | 5.6
853 | 1.4
854 |
855 |
856 | 7.7
857 | 3.0
858 | 6.1
859 | 2.3
860 |
861 |
862 | 6.3
863 | 3.4
864 | 5.6
865 | 2.4
866 |
867 |
868 | 6.4
869 | 3.1
870 | 5.5
871 | 1.8
872 |
873 |
874 | 6.0
875 | 3.0
876 | 4.8
877 | 1.8
878 |
879 |
880 | 6.9
881 | 3.1
882 | 5.4
883 | 2.1
884 |
885 |
886 | 6.7
887 | 3.1
888 | 5.6
889 | 2.4
890 |
891 |
892 | 6.9
893 | 3.1
894 | 5.1
895 | 2.3
896 |
897 |
898 | 5.8
899 | 2.7
900 | 5.1
901 | 1.9
902 |
903 |
904 | 6.8
905 | 3.2
906 | 5.9
907 | 2.3
908 |
909 |
910 | 6.7
911 | 3.3
912 | 5.7
913 | 2.5
914 |
915 |
916 | 6.7
917 | 3.0
918 | 5.2
919 | 2.3
920 |
921 |
922 | 6.3
923 | 2.5
924 | 5.0
925 | 1.9
926 |
927 |
928 | 6.5
929 | 3.0
930 | 5.2
931 | 2.0
932 |
933 |
934 | 6.2
935 | 3.4
936 | 5.4
937 | 2.3
938 |
939 |
940 | 5.9
941 | 3.0
942 | 5.1
943 | 1.8
944 |
945 |
946 |
947 |
948 | model = Rumale::LinearModel::SVC.new(
949 | reg_param: 0.0001,
950 | fit_bias: true,
951 | max_iter: 3000,
952 | random_seed: 1
953 | )
954 |
955 | model.fit(samples, labels)
956 |
957 | p model.predict(samples).to_a
958 |
959 |
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
960 |
961 | => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
962 |
963 |
964 |
965 |
966 |
967 |
968 |
--------------------------------------------------------------------------------
/docs/table.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
19 |
20 |
21 |
22 |
23 | Table generation example
24 |
25 |
26 |
27 | a = Numo::DFloat.new(3, 5).seq
28 |
29 |
30 |
31 |
32 | 0.0
33 | 1.0
34 | 2.0
35 | 3.0
36 | 4.0
37 |
38 |
39 | 5.0
40 | 6.0
41 | 7.0
42 | 8.0
43 | 9.0
44 |
45 |
46 | 10.0
47 | 11.0
48 | 12.0
49 | 13.0
50 | 14.0
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/examples/bio.md:
--------------------------------------------------------------------------------
1 | # BioRuby Tutorial
2 |
3 | ## Trying Bioruby
4 |
5 | Now test the following:
6 |
7 | ~~~ruby
8 | require 'bio'
9 | seq = Bio::Sequence::NA.new("atgcatgcaaaa")
10 | ~~~
11 |
12 | ~~~ruby
13 | seq.complement
14 | ~~~
15 |
16 | ## Working with nucleic / amino acid sequences (Bio::Sequence class)
17 |
18 | The `Bio::Sequence` class allows the usual sequence transformations and translations.
19 |
20 | In the example below the DNA sequence `atgcatgcaaaa` is converted into the complemental strand and spliced into a subsequence; next, the nucleic acid composition is calculated and the sequence is translated into the amino acid sequence, the molecular weight calculated, and so on. When translating into amino acid sequences, the frame can be specified and optionally the codon table selected (as defined in [codontable.rb](https://github.com/bioruby/bioruby/blob/master/lib/bio/data/codontable.rb)).
21 |
22 | ~~~ruby
23 | seq = Bio::Sequence::NA.new("atgcatgcaaaa")
24 | ~~~
25 |
26 | ~~~ruby
27 | # complemental sequence (Bio::Sequence::NA object)
28 | seq.complement
29 | ~~~
30 |
31 | ~~~ruby
32 | seq.subseq(3,8) # gets subsequence of positions 3 to 8 (starting from 1)
33 | ~~~
34 |
35 | ~~~ruby
36 | seq.gc_percent
37 | ~~~
38 |
39 | ~~~ruby
40 | seq.composition
41 | ~~~
42 |
43 | ~~~ruby
44 | seq.translate
45 | ~~~
46 |
47 | ~~~ruby
48 | seq.translate(2)
49 | ~~~
50 |
51 | ~~~ruby
52 | seq.translate(1,11)
53 | ~~~
54 |
55 | ~~~ruby
56 | seq.translate.codes
57 | ~~~
58 |
59 | ~~~ruby
60 | seq.translate.names
61 | ~~~
62 |
63 | ~~~ruby
64 | seq.translate.composition
65 | ~~~
66 |
67 | ~~~ruby
68 | seq.translate.molecular_weight
69 | ~~~
70 |
71 | ~~~ruby
72 | seq.complement.translate
73 | ~~~
74 |
--------------------------------------------------------------------------------
/examples/charty.md:
--------------------------------------------------------------------------------
1 |
2 | # Charty Usage
3 |
4 | ## You can write Markdown!
5 |
6 | - item1
7 | - item2
8 |
9 | ~~~ruby
10 |
11 | require 'charty'
12 | charty = Charty::Plotter.new(:pyplot)
13 |
14 | bar = charty.bar do
15 | series [0,1,2,3,4], [10,40,20,90,70]
16 | series [0,1,2,3,4], [90,80,70,60,50]
17 | series [0,1,2,3,4,5,6,7,8], [50,60,20,30,10, 90, 0, 100, 50]
18 | range x: 0..10, y: 1..100
19 | xlabel 'foo'
20 | ylabel 'bar'
21 | title 'bar plot'
22 | end
23 | bar.render("bar_matplot.png")
24 | ~~~
25 |
26 |
--------------------------------------------------------------------------------
/examples/graph.md:
--------------------------------------------------------------------------------
1 | # Graph generation example
2 |
3 | ## With [Numo::Gnuplot](https://github.com/ruby-numo/numo-gnuplot)
4 |
5 | `Rubydown::RbMarkPlot` is extended class of `Numo::Gnuplot`
6 |
7 | ~~~ruby
8 | rp = Rubydown::RbMarkPlot.new
9 | rp.set title: "Example Plot"
10 | rp.plot "sin(x)", w:"lines"
11 | ~~~
12 |
--------------------------------------------------------------------------------
/examples/index.md:
--------------------------------------------------------------------------------
1 | ## テスト
2 |
3 | ### コードを書く
4 |
5 | *~~~ruby* と *~~~* でコードを囲むと、そのブロックが評価される。
6 |
7 | ~~~ruby
8 | array = [1,2,3,4]
9 | converted = array.map { |e| e * 100 }
10 |
11 | converted # 最後の行が出力される
12 | ~~~
13 |
14 | 標準出力も表示される
15 |
16 | ~~~ruby
17 | puts :hoge
18 |
19 | "fuga\npiyo".inspect
20 | ~~~
21 |
22 | ### ブロックは全部同じスコープ
23 |
24 | 先程定義した変数`converted`が以下でも使える。
25 |
26 | ~~~ruby
27 | converted.map { |e| e / 100 }
28 | ~~~
29 |
30 | ### ライブラリを使う
31 |
32 | もちろん外部のライブラリをロードすることもできる。
33 |
34 | ~~~ruby
35 | require 'matrix'
36 |
37 | Matrix.identity(10)
38 | ~~~
39 |
40 | ### to_htmlを実装する
41 |
42 | `to_html` メソッドを実装すると、その結果が出力される。
43 |
44 | ~~~ruby
45 | class Matrix # オープンクラス
46 | def to_html
47 | rows = self.to_a.map do |row|
48 | elems = row.map do |elem|
49 | "#{elem} "
50 | end
51 | "#{elems} "
52 | end
53 | ""
54 | end
55 | end
56 |
57 | Matrix.identity(10)
58 | ~~~
59 |
--------------------------------------------------------------------------------
/examples/rbplotly-bar.md:
--------------------------------------------------------------------------------
1 | # rbplotly bar chart usage
2 |
3 |
4 | ~~~ruby
5 | require 'rbplotly'
6 |
7 | trace = {
8 | x: %w(giraffes orangutans monkeys),
9 | y: [20, 14, 23],
10 | type: :bar
11 | }
12 |
13 | plot = Plotly::Plot.new(data: [trace])
14 | ~~~
15 |
16 |
17 | ~~~ruby
18 | trace1 = {
19 | x: %w(giraffes orangutans monkeys),
20 | y: [20, 14, 23],
21 | type: :bar,
22 | name: 'SF Zoo'
23 | }
24 | trace2 = {
25 | x: %w(giraffes orangutans monkeys),
26 | y: [12, 18, 29],
27 | type: :bar,
28 | name: 'LA Zoo'
29 | }
30 |
31 | plot = Plotly::Plot.new(data: [trace1, trace2])
32 | ~~~
33 |
34 | ~~~ruby
35 | plot.layout.barmode = :stack
36 | plot
37 | ~~~
38 |
39 | ~~~ruby
40 | trace1 = {
41 | x: %w(giraffes orangutans monkeys),
42 | y: [20, 14, 23],
43 | type: :bar,
44 | name: 'SF Zoo'
45 | }
46 | trace2 = {
47 | x: %w(giraffes orangutans monkeys),
48 | y: [12, 18, 29],
49 | type: :bar,
50 | name: 'LA Zoo'
51 | }
52 |
53 | plot = Plotly::Plot.new(data: [trace1, trace2], layout: { barmode: :stack } )
54 | ~~~
55 |
--------------------------------------------------------------------------------
/examples/rbplotly-basic.md:
--------------------------------------------------------------------------------
1 | # rbplotly basic usage
2 |
3 |
4 | ~~~ruby
5 | require 'rbplotly'
6 |
7 | n = 100
8 |
9 | x = n.times.map { |i| i.to_f / (n - 1) }
10 | y0 = n.times.map { rand(-2.0..2.0) + 5 }
11 | y1 = n.times.map { rand(-2.0..2.0) }
12 |
13 | trace0 = { x: x, y: y0, type: :scatter, mode: :markers }
14 | trace1 = trace0.merge(y: y1, mode: :'markers+lines')
15 |
16 | plot = Plotly::Plot.new(data: [trace0, trace1])
17 | ~~~
18 |
19 | Here we replace the last trace range from -0.5 to 0.5
20 |
21 |
22 | ~~~ruby
23 | plot.data.last.y = n.times.map { rand(-0.5..0.5) }
24 | plot
25 | ~~~
26 |
27 | Next we add a line trace with the center -5 and the range from -2.0 to 2.0.
28 |
29 | ~~~ruby
30 | new_trace = { x: x, y: n.times.map { rand(-2.0..2.0) - 5 }, type: :scatter, mode: :lines }
31 | plot.data.push(new_trace)
32 | plot
33 | ~~~
34 |
35 | Last of all we add the x,y titles.
36 |
37 |
38 | ~~~ruby
39 | plot.layout.xaxis = { title: 'x title' }
40 | plot.layout.yaxis = { title: 'y title' }
41 | plot
42 | ~~~
43 |
44 |
--------------------------------------------------------------------------------
/examples/rbplotly-boxplot.md:
--------------------------------------------------------------------------------
1 | # rbplotly boxplot usage
2 |
3 | ~~~ruby
4 | require 'rbplotly'
5 |
6 | n = 50
7 | y0 = n.times.map { rand(-1.0..0.0) }
8 | y1 = n.times.map { rand(0.0..1.0) }
9 |
10 | trace0 = {
11 | y: y0,
12 | type: :box
13 | }
14 |
15 | trace1 = {
16 | y: y1,
17 | type: :box
18 | }
19 |
20 | data = [trace0, trace1]
21 |
22 | plot = Plotly::Plot.new(data: data)
23 | ~~~
24 |
25 | ## Horizontal boxplot
26 |
27 | ~~~ruby
28 | n = 50
29 | x0 = n.times.map { rand(-1.0..0.0) }
30 | x1 = n.times.map { rand(0.0..1.0) }
31 |
32 | trace0 = {
33 | x: x0,
34 | type: :box
35 | }
36 |
37 | trace1 = {
38 | x: x1,
39 | type: :box
40 | }
41 |
42 | data = [trace0, trace1]
43 |
44 | plot = Plotly::Plot.new(data: data)
45 | ~~~
46 |
47 |
48 | ## boxplot with the points
49 |
50 | ~~~ruby
51 | trace = {
52 | y: [0, 1, 1, 2, 3, 5, 8, 13, 21],
53 | boxpoints: :all,
54 | jitter: 0.3,
55 | pointpos: -1.8,
56 | type: :box
57 | }
58 |
59 | plot = Plotly::Plot.new(data: [trace])
60 | ~~~
61 |
--------------------------------------------------------------------------------
/examples/rbplotly-heatmap.md:
--------------------------------------------------------------------------------
1 | # rbplotly heatmap usage
2 |
3 | ~~~ruby
4 | require 'rbplotly'
5 |
6 | z = [
7 | [1, 20, 30],
8 | [20, 1, 60],
9 | [30, 60, 1]
10 | ]
11 |
12 | data = [{
13 | z: z,
14 | type: :heatmap
15 | }]
16 |
17 | plot = Plotly::Plot.new(data: data)
18 | ~~~
19 |
20 | ~~~ruby
21 | n = 10
22 | data = {
23 | x: (1..n).map { |i| "x#{i}" },
24 | y: (1..n).map { |i| "y#{i}" },
25 | z: (1..n).map { (1..n).map { rand(10) } },
26 | type: :heatmap
27 | }
28 |
29 | layout = {
30 | width: 500,
31 | height: 500
32 | }
33 |
34 | plot = Plotly::Plot.new(data: [data], layout: layout)
35 | ~~~
36 |
--------------------------------------------------------------------------------
/examples/rbplotly-hist.md:
--------------------------------------------------------------------------------
1 | # rbplotly histogram usage
2 |
3 | ~~~ruby
4 | require 'rbplotly'
5 |
6 | data = [{ x: (1..500).map { rand }, type: :histogram }]
7 |
8 | plot = Plotly::Plot.new(data: data)
9 | ~~~
10 |
--------------------------------------------------------------------------------
/examples/rbplotly-line.md:
--------------------------------------------------------------------------------
1 | # rbplotly line plot usage
2 |
3 | ~~~ruby
4 | require 'rbplotly'
5 |
6 | plot = Plotly::Plot.new
7 | flip = -1
8 | x = (0...100).map { |i| i.to_f / 10 }
9 | (0..5).each do |i|
10 | trace = {
11 | x: x,
12 | y: (1...100).map { |j| Math.sin(j.to_f / 10 + i) },
13 | line: { shape: :spline },
14 | mode: :lines
15 | }
16 | plot.data.push(trace)
17 | end
18 | plot
19 | ~~~
20 |
--------------------------------------------------------------------------------
/examples/rbplotly-pie.md:
--------------------------------------------------------------------------------
1 | # rbplotly pie chart usage
2 |
3 | ## Basic pie chart
4 |
5 | ~~~ruby
6 | require 'rbplotly'
7 |
8 | data = [{
9 | labels: %w(Residential Non-Residential Utility),
10 | values: [19, 26, 55],
11 | type: :pie
12 | }]
13 |
14 | layout = { title: 'Forcasted 2014 U.S. PV Installations by Market Segment' }
15 |
16 | plot = Plotly::Plot.new(data: data, layout: layout )
17 | ~~~
18 |
19 | ## Donut chart
20 |
21 | ~~~ruby
22 | trace1 = {
23 | name: 'GHG Emissions',
24 | values: [16, 15, 12, 6, 5, 4, 42],
25 | domain: { x: [0, 0.5] },
26 |
27 | labels: %w(US China European Union Russian Federation Brazil India Rest\ of\ World),
28 | hoverinfo: :'label+percent+name',
29 | hole: 0.4,
30 | type: :pie,
31 | }
32 |
33 | trace2 = trace1.merge({
34 | name: 'CO2 Emissions',
35 | values: [27, 11, 25, 8, 1, 3, 25],
36 | domain: { x: [0.5, 1] }
37 | })
38 |
39 | plot = Plotly::Plot.new(data: [trace1, trace2])
40 | ~~~
41 |
--------------------------------------------------------------------------------
/examples/rbplotly-scatter.md:
--------------------------------------------------------------------------------
1 | # rbplotly scatter plot usage
2 |
3 | ## Simple scatter Plot
4 |
5 | ~~~ruby
6 | require 'rbplotly'
7 |
8 | n = 100
9 | x = n.times.map { rand(-2.0..2.0) }
10 | y = n.times.map { rand(-1.0..1.0) }
11 | trace = { x: x, y: y, mode: :markers }
12 |
13 | plot = Plotly::Plot.new(data: [trace])
14 | plot.layout.title = 'Simple Scatter Plot'
15 | plot
16 | ~~~
17 |
18 | ## Line and scatter plots
19 |
20 | ~~~ruby
21 | n = 100
22 |
23 | x = n.times.map { |i| i.to_f / (n - 1) }
24 | y0 = n.times.map { rand(-2.0..2.0) + 5 }
25 | y1 = n.times.map { rand(-2.0..2.0) }
26 | y2 = n.times.map { rand(-2.0..2.0) - 5 }
27 |
28 | trace0 = { x: x, y: y0, type: :scatter, mode: :markers }
29 | trace1 = { x: x, y: y1, type: :scatter, mode: :'markers+lines' }
30 | trace2 = { x: x, y: y2, type: :scatter, mode: :lines }
31 |
32 | plot = Plotly::Plot.new(data: [trace0, trace1, trace2])
33 | plot.layout.title = 'Line and Scatter Plots'
34 | plot
35 | ~~~
36 |
37 | ## Style scatter plots
38 |
39 | ~~~ruby
40 | n = 100
41 | trace0 = {
42 | x: n.times.map { rand(-2.0..2.0) },
43 | y: n.times.map { rand(-1.0..1.0) },
44 | name: 'Red',
45 | mode: :markers,
46 | marker: {
47 | size: 15,
48 | color: 'rgba(200, 0, 0, .5)',
49 | line: { width: 2, color: 'rgb(0, 0, 0, .5)' }
50 | }
51 | }
52 | trace1 = {
53 | x: n.times.map { rand(-2.0..2.0) },
54 | y: n.times.map { rand(-1.0..1.0) },
55 | name: 'Blue',
56 | mode: :markers,
57 | marker: {
58 | size: 10,
59 | color: 'rgba(0, 0, 200, .5)',
60 | line: { width: 1, color: 'rgb(0, 0, 0, .5)' }
61 | }
62 | }
63 |
64 | layout = {
65 | title: 'Styled Scatter',
66 | xaxis: { zeroline: false },
67 | yaxis: { zeroline: false }
68 | }
69 |
70 | plot = Plotly::Plot.new(data: [trace0, trace1], layout: layout)
71 | ~~~
72 |
--------------------------------------------------------------------------------
/examples/rumale-kmeans.md:
--------------------------------------------------------------------------------
1 |
2 | # k-means clustering with [rumale](https://github.com/yoshoku/rumale)
3 |
4 | ## super simple k-means clustering demo
5 |
6 | ~~~ruby
7 | require "numo/narray"
8 | require "rumale"
9 | samples = Numo::DFloat[[1, 2], [1, 4], [1, 0],[10, 2], [10, 4], [10, 0]]
10 | analyzer = Rumale::Clustering::KMeans.new(n_clusters: 2, max_iter: 50)
11 | cluster_labels = analyzer.fit_predict(samples)
12 | ~~~
13 |
14 |
15 | We can see that the rumale `analyzer` separately labeled the first 3points and the last 3points.
16 |
17 | ## Visualizing clusters with [rbplotly](https://github.com/ash1day/rbplotly)
18 |
19 | Next we visualize the cluster with rbplotly
20 |
21 | ~~~ruby
22 | cluster0 = samples[0..2,0..1]
23 | cluster1 = samples[3..5,0..1]
24 | x0 = cluster0[0..-1,0].to_a
25 | y0 = cluster0[0..-1,1].to_a
26 | x1 = cluster1[0..-1,0].to_a
27 | y1 = cluster1[0..-1,1].to_a
28 | trace0 = {x:x0, y:y0, type: :scatter, mode: :markers}
29 | trace1 = {x:x1, y:y1, type: :scatter, mode: :markers}
30 | plot = Plotly::Plot.new(data: [trace0, trace1])
31 | ~~~
32 |
33 | The end
34 |
--------------------------------------------------------------------------------
/examples/rumale.md:
--------------------------------------------------------------------------------
1 | Rumale machine learning examples
2 |
3 |
4 | ~~~ruby
5 | require 'rumale'
6 | require 'rdatasets'
7 |
8 | iris = RDatasets.load(:datasets, :iris)
9 |
10 | iris_labels = iris['Species'].to_a
11 | encoder = Rumale::Preprocessing::LabelEncoder.new
12 | labels = encoder.fit_transform(iris_labels)
13 | p "hoge"
14 | ~~~
15 |
16 | ~~~ruby
17 | samples = Numo::DFloat[*iris[0..3].to_matrix.to_a]
18 | ~~~
19 |
20 | ~~~ruby
21 | model = Rumale::LinearModel::SVC.new(
22 | reg_param: 0.0001,
23 | fit_bias: true,
24 | max_iter: 3000,
25 | random_seed: 1
26 | )
27 |
28 | model.fit(samples, labels)
29 |
30 | p model.predict(samples).to_a
31 | ~~~
32 |
--------------------------------------------------------------------------------
/examples/table.md:
--------------------------------------------------------------------------------
1 | # Table generation example
2 |
3 | ## With [Numo::Narray](https://github.com/ruby-numo/numo-narray)
4 |
5 | ~~~ruby
6 | a = Numo::DFloat.new(3, 5).seq
7 | ~~~
8 |
--------------------------------------------------------------------------------
/exe/rubydown:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby
2 |
3 | require 'kramdown'
4 | require 'erb'
5 | require 'stringio'
6 | require 'base64'
7 | require 'optparse'
8 |
9 | require 'rubydown'
10 |
11 | def get_context
12 | binding
13 | end
14 |
15 | class EvalDoc < Kramdown::Document
16 | attr_accessor :context, :stdout
17 | attr_reader :javascripts
18 |
19 | def initialize(text, *opts)
20 | super(text, *opts)
21 |
22 | @javascripts = {}
23 | self.context = get_context
24 | self.root = scan_el(self.root)
25 | end
26 |
27 | REQUIREJS_SCRIPT_TAG = ''
28 | MATHJAX_SCRIPT_TAG = ""
29 |
30 | private
31 | def scan_el(el)
32 | @javascripts[:mathjax] ||= MATHJAX_SCRIPT_TAG if el.type == :math
33 |
34 | new_children = []
35 | el.children.each do |child_el|
36 | child_el = scan_el(child_el)
37 | new_children << child_el
38 |
39 | is_code = child_el.type == :codeblock || child_el.type == :codespan
40 |
41 | if is_code && child_el.options[:lang] == 'ruby'
42 | code = child_el.value.gsub(/^ *ruby *\n/, '')
43 | new_children << eval_and_elementize(code)
44 | @javascripts[:requirejs] ||= REQUIREJS_SCRIPT_TAG
45 | end
46 | end
47 |
48 | el.children = new_children
49 |
50 | return el
51 | end
52 |
53 | def eval_and_elementize(code)
54 | stdout = StringIO.new
55 |
56 | $stdout = stdout
57 | eval_result = self.context.eval(code)
58 | $stdout = STDOUT
59 |
60 | stdout_string = stdout.string.empty? ? '' : stdout.string + "\n"
61 |
62 | case
63 | when eval_result.respond_to?(:to_html)
64 | Kramdown::Document.new(eval_result.to_html, input: :html).root
65 | when eval_result.instance_of?(File) && File.extname(eval_result.path) == ".png"
66 | img_b64 = Base64.encode64(File.binread(eval_result.path))
67 | Kramdown::Document.new(" ", input: :html).root
68 | else
69 | text_result_el(stdout_string + "=> #{eval_result}")
70 | end
71 | end
72 |
73 | def text_result_el(text)
74 | text_el = Kramdown::Element.new(:codeblock, text)
75 | p_el = Kramdown::Element.new(:p)
76 | p_el.children << text_el
77 | p_el
78 | end
79 | end
80 |
81 | def main # to separate binding
82 |
83 | options = {}
84 | options[:erb] = File.expand_path('../../templates/template.html.erb', __FILE__)
85 | option_parser = OptionParser.new do |opts|
86 | opts.on("-i INPUT", "Input form the file") do |input|
87 | options[:input] = input
88 | end
89 | opts.on("-e ERB", "Specify template file") do |erb|
90 | options[:erb] = erb
91 | end
92 | opts.on("-o OUTPUT", "Output html to OUTPUT") do |output|
93 | options[:output] = output
94 | end
95 | opts.on("-h", "--help", "Prints this help") do
96 | puts opts
97 | exit
98 | end
99 | opts.on_tail("--version", "Show version") do
100 | puts Rubydown::VERSION
101 | exit
102 | end
103 | end
104 |
105 | option_parser.parse!
106 | # puts options.inspect
107 | # puts options[:input]
108 | # puts options[:erb]
109 | # puts options[:output]
110 |
111 | case options[:input]
112 | when /\.md\z/i
113 | options[:output] ||= options[:input].sub(/\.md\z/i, '.html')
114 | when /./
115 | abort("Input file must be markdown (*.md)")
116 | else
117 | abort(option_parser.help)
118 | end
119 |
120 | doc = EvalDoc.new(File.read(options[:input], encoding: 'utf-8')) # using in ERB
121 | File.write(options[:output], ERB.new(File.read(options[:erb])).result(binding))
122 | # puts ERB.new(File.read(options[:erb])).result(binding)
123 | end
124 |
125 | main
126 |
--------------------------------------------------------------------------------
/lib/rubydown.rb:
--------------------------------------------------------------------------------
1 | require "rubydown/version"
2 |
3 | require 'numo/narray'
4 | require 'rbplotly'
5 | require 'numo/gnuplot'
6 | require 'base64'
7 | require 'tempfile'
8 | require 'charty'
9 |
10 |
11 | class Numo::NArray
12 | def to_html
13 | case ndim
14 | when 2
15 | rows = self.to_a.map do |row|
16 | elems = row.map do |elem|
17 | "#{elem} "
18 | end
19 | "#{elems.join} "
20 | end
21 | ""
22 | when 1
23 | cols = self.to_a.map do |elem|
24 | "#{elem} "
25 | end
26 | ""
27 | else
28 | inspect
29 | end
30 | end
31 | end
32 |
33 | Charty::RenderContext.prepend Module.new {
34 | def render(filename=nil)
35 | super
36 | if filename.nil?
37 | p "The image could not be rendered. In the environment without IRuby, the file name for the charty render method is required."
38 | else
39 | File.open(filename)
40 | end
41 | end
42 | }
43 |
44 | module Rubydown
45 | class RbMarkPlot < Numo::Gnuplot
46 | def plot(*args)
47 | super(*args)
48 | self
49 | end
50 |
51 | def splot(*args)
52 | super(*args)
53 | self
54 | end
55 |
56 | def _plot_splot(*args)
57 | @tempfile = Tempfile.open(['plot', '.png'])
58 | set terminal: 'png'
59 | set output: @tempfile.path
60 | super(*args)
61 | end
62 |
63 | def to_html
64 | img_b64 = Base64.encode64(File.binread(@tempfile))
65 | <<-HTML
66 |
67 | HTML
68 | end
69 | end
70 |
71 | class Error < StandardError; end
72 | # Your code goes here...
73 | end
74 |
--------------------------------------------------------------------------------
/lib/rubydown/version.rb:
--------------------------------------------------------------------------------
1 | module Rubydown
2 | VERSION = "0.2.0"
3 | end
4 |
--------------------------------------------------------------------------------
/rubydown.gemspec:
--------------------------------------------------------------------------------
1 |
2 | lib = File.expand_path("../lib", __FILE__)
3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4 | require "rubydown/version"
5 |
6 | Gem::Specification.new do |spec|
7 | spec.name = "rubydown"
8 | spec.version = Rubydown::VERSION
9 | spec.authors = ["Yusuke Sangenya", "Kozo Nishida", "Kazuhiro Nishiyama"]
10 | spec.email = ["kozo.nishida@gmail.com"]
11 | spec.license = 'MIT'
12 | spec.summary = "Pure Ruby R Markdown clone."
13 | spec.description = "rubydown is R Markdown clone for Rubyists."
14 | spec.homepage = "https://github.com/sciruby-jp/rubydown"
15 |
16 | # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17 | # to allow pushing to a single host or delete this section to allow pushing to any host.
18 | if spec.respond_to?(:metadata)
19 | # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20 |
21 | spec.metadata["homepage_uri"] = spec.homepage
22 | spec.metadata["source_code_uri"] = "https://github.com/sciruby-jp/rubydown"
23 | # spec.metadata["changelog_uri"] = "https//github.com/sciruby-jp/rubydown/blob/master/CHANGELOG.md"
24 | else
25 | raise "RubyGems 2.0 or newer is required to protect against " \
26 | "public gem pushes."
27 | end
28 |
29 | # Specify which files should be added to the gem when it is released.
30 | # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31 | spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32 | `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33 | end
34 | spec.bindir = "exe"
35 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36 | spec.require_paths = ["lib"]
37 |
38 | spec.add_dependency "kramdown", "~> 2.1"
39 | spec.add_dependency "daru", "~> 0.2"
40 | spec.add_dependency "numo-narray", "~> 0.9.1"
41 | spec.add_dependency "numo-gnuplot", "~> 0.2.4"
42 | spec.add_dependency "rbplotly", "~> 0.1.2"
43 | spec.add_dependency "charty", "~> 0.2.0"
44 | spec.add_dependency "matplotlib", "~> 1.0.0"
45 |
46 | spec.add_development_dependency "bundler", "~> 1.17"
47 | spec.add_development_dependency "rake", "~> 10.0"
48 | spec.add_development_dependency "test-unit", "~> 3.3"
49 | end
50 |
--------------------------------------------------------------------------------
/templates/template.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
19 | <%= doc.javascripts.values.join('') %>
20 |
21 |
22 |
23 | <%= doc.to_html %>
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/test/test-table.rb:
--------------------------------------------------------------------------------
1 | require 'test/unit'
2 | require 'numo/narray'
3 | require 'rubydown'
4 |
5 | class TableTest < Test::Unit::TestCase
6 | def setup
7 | @table = Numo::DFloat.new(3, 5).seq.to_html
8 | end
9 |
10 | def test_to_html
11 | assert_equal(
12 | "0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0
",
13 | @table
14 | )
15 | end
16 | end
--------------------------------------------------------------------------------