├── .gitignore
├── .gitmodules
├── LICENSE
├── README.md
├── doc
└── index.md
├── examples
├── css
│ └── style.css
├── index.html
├── js
│ ├── contour-df-styled.js
│ ├── contour-df.js
│ ├── plot.js
│ └── scatter.js
├── simple.html
├── simple_sushi.html
└── test.html
└── src
├── soba.css
├── soba.js
├── soba_modal.css
└── soba_modal.js
/.gitignore:
--------------------------------------------------------------------------------
1 | /nbproject
2 | .project
3 | .settings
4 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "sushi"]
2 | path = sushi
3 | url = https://github.com/mil-tokyo/sushi.git
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Machine Intelligence Laboratory (The University of Tokyo)
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 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Soba Javascript Library
2 |
3 | A visualization toolkit coordinating with Sushi and Tempura
4 |
5 | Soba is a 2D plotting library integrated with Sushi (https://github.com/mil-tokyo/sushi) written in javascript. This library is easy to use, can work in web browsers and coordinate with Sushi and Tempura(https://github.com/mil-tokyo/tempura).
6 |
7 | Please visit Tempura demo page(http://mil-tokyo.github.io/tempura/demo/index.html) to see figures drawn by this library.
8 |
9 | Related papers are available ( http://mil-tokyo.github.io/miljs.html ).
10 |
11 | #Introduction
12 |
13 | Soba Javascript Library is a javascript 2D plotting library which is designed to draw high quality figures for scientific computation easily as in matplotlib (http://matplotlib.org/).
14 | Soba Javascript Library is written in javascript so that it can work on web browsers in any environment and can coordinate with Sushi (https://github.com/mil-tokyo/sushi) and Tempura (https://github.com/mil-tokyo/tempura).
15 |
16 | #How to use
17 | ## Clone the repo or download the files
18 | On a console, type
19 | ```
20 | git clone git@github.com:mil-tokyo/soba.git
21 | ```
22 | or simply download the file from
23 | https://github.com/mil-tokyo/soba/archive/master.zip
24 |
25 | src/soba.js and src/soba.css are core files.
26 |
27 | ## Include files in your HTML
28 | Soba works with HTML in web browsers and depends on d3.js (http://d3js.org/).
29 | Please include d3.js and Soba codes in your HTML file as following:
30 |
31 | ```HTML
32 |
33 |
34 |
35 | ```
36 |
37 | ## Create an instance of Soba class to draw figure in a DOM object
38 | Soba draws a figure as a SVG object in a DOM object.
39 | For example, Soba creates and initializes a SVG object in a DOM object whose id is "figure1" by the following code:
40 |
41 | ```javascript
42 | var plt = new Soba('#figure1');
43 | ```
44 |
45 | Soba uses d3.js to handle SVG objects.
46 |
47 | ## Draw graph on the figure
48 | Now, let's draw graphs!
49 | For example, plot() plots continuous points and connects those points by line if a specific option is given like this:
50 | ```javascript
51 | plt.plot(x,y,options);
52 | plt.show();
53 | ```
54 | Here, variables x and y represent the locations of the points and the styles of the points and the line can be controlled by options as a string.
55 |
56 | ## Full simple example
57 | Here, the whole code is shown to plot one sine curve.
58 |
59 | http://mil-tokyo.github.io/soba/examples/simple.html
60 | ```HTML
61 |
62 |
63 |
64 | Simple Soba sample
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
87 |
88 |
89 | ```
90 |
91 | # Integration with Sushi
92 | Soba can work with Sushi Javascript Library (https://github.com/mil-tokyo/sushi) which offers fast matrix calculation in javascript.
93 | Sushi's matrix class *Sushi.Matrix* can be passed to Soba's methods.
94 | For example, the sample code above can be written as following by using *Sushi.Matrix*:
95 |
96 | http://mil-tokyo.github.io/soba/examples/simple_sushi.html
97 |
98 | ```HTML
99 |
100 |
101 |
102 | Simple Soba sample
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
129 |
130 |
131 | ```
132 | The plotting code is unchanged while the data passed to plot() method are changed to instances of *Sushi.Matrix* (and sushi.js is included).
133 |
134 | # Learn more
135 | Please see the documents [here](https://github.com/mil-tokyo/soba/blob/master/doc/index.md). You can get more detailed information such as method references.
136 |
--------------------------------------------------------------------------------
/doc/index.md:
--------------------------------------------------------------------------------
1 | # Methods
2 |
3 | ## Constructor
4 | ### Syntax
5 | ```javascript
6 | var plt = new Soba(selector);
7 | ```
8 | * *selector* : CSS selector to specify a DOM object which contains the figure drawn by the Soba instance
9 |
10 | ### Description
11 | By constructor, Soba class creates and initializes a SVG object to draw figure in a DOM object which is specified by *selector*.
12 |
13 | ### Sample
14 | ```HTML
15 |
16 |
19 | ```
20 |
21 | ## plot()
22 | ### Syntax
23 | ```javascript
24 | plt.plot(x, y, options);
25 | ```
26 | * *x* : 1-dimentional Array or n-by-1 shaped Sushi.Matrix object which represents x-coordinates of data points
27 | * *y* : 1-dimentional Array or n-by-1 shaped Sushi.Matrix object which represents y-coordinates of data points
28 | * *options (default:"b-")* : String to specify styles of points and line. Supported styles are following. Combination of these characters represents the style.
29 |
30 | | Character | Line Style |
31 | | --------- |--------------------:|
32 | | - | solid line style |
33 | | -- | dashed line style |
34 | | -. | dash-dot line style |
35 | | : | dotted line style |
36 | | o | circle marker |
37 |
38 | | Character | Color |
39 | | --------- |--------:|
40 | | b | blue |
41 | | g | green |
42 | | r | red |
43 | | c | cyan |
44 | | m | magenta |
45 | | y | yellow |
46 | | k | black |
47 | | w | white |
48 |
49 | ### Description
50 | This method plots continuous points and connects those points by line if a specific option is given. The styles of points and line are controlled by *options* argument.
51 |
52 | ### Sample
53 | ```javascript
54 | var x=..., y=...;
55 | plt.plot(x,y,'k--');
56 | ```
57 | Please see also http://mil-tokyo.github.io/soba/examples/index.html#plot
58 |
59 | ## scatter()
60 | ### Syntax
61 | ```javascript
62 | plt.scatter(x, y, colors);
63 | ```
64 | * *x* : 1-dimentional Array or n-by-1 shaped Sushi.Matrix object which represents x-coordinates of data points
65 | * *y* : 1-dimentional Array or n-by-1 shaped Sushi.Matrix object which represents y-coordinates of data points
66 | * *colors* : n-by-1 shaped Sushi.Matrix object which represents colors of data points. The elements of this matrix are integer (1,2,3,...).
67 |
68 | ### Description
69 | This method makes a scatter plot of x vs y. Colors of those are controlled by *colors* argument.
70 |
71 | ### Sample
72 | ```javascript
73 | var x=new Sushi.Matrix(...), y=new Sushi.Matrix(...), colors=new Sushi.Matrix(...);
74 | x=...; y=...; colors=...;
75 | plt.scatter(x,y,colors);
76 | ```
77 | Please see also http://mil-tokyo.github.io/soba/examples/index.html#scatter
78 |
79 | ## contourDesicionFunction()
80 | ### Syntax
81 | ```javascript
82 | plt.contourDesicionFunction(x_min, x_max, y_min, y_max, callback);
83 | plt.contourDesicionFunction(x_min, x_max, y_min, y_max, options, callback);
84 | ```
85 | * *x_min* : x-coordinate of the left edge of the plotting area
86 | * *x_max* : x-coordinate of the right edge of the plotting area
87 | * *y_min* : y-coordinate of the bottom edge of the plotting area
88 | * *y_max* : y-coordinate of the top edge of the plotting area
89 | * *options* : Object specifying some options like {option_name1: value1, option_name2: value2, ...}. Supported options are following:
90 |
91 | | Option name | Description |
92 | | ----------- |--------|
93 | | levels | Array containing the contour levels. If not provided, the contour levels are determined automatically.|
94 | | colors | Array containing the colors of contour lines. Colors are specified by the aliases described above(plot()). If not provided, colors are determined automatically. If the length of this array is shorter than that of levels, specified colors are repeated. |
95 | | linestyles | Array containing the line styles of contour lines. Line styles are specified by strings. 'solid' and 'dashed' are supported. If not provided, all lines are solid style. If the length of this array is shorter than that of levels, specified line styles are repeated.|
96 | * *callback* : Callback function that takes 2 arguments *x* and *y* and returns function value to draw contour.
97 |
98 | ### Description
99 | This method plots contours of a function specified by *callback* function. The plotting area is specified by *x_min*, *x_max*, *y_min* and *y_max* and *callback* is called over lattice points in the plotting area to assign function values to each point.
100 |
101 | ### Sample
102 | ```javascript
103 | plt.contourDesicionFunction(-3, 3, -3, 3, {levels: [0.0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.11, 0.], colors: ['m','b'], linestyles: ['dashed', 'solid']}, function(x,y){
104 | var z = Math.exp(-(x*x+y*y)/2)/(2*Math.PI); // Gaussian distribution
105 | return z;
106 | });
107 | ```
108 | Please see also http://mil-tokyo.github.io/soba/examples/index.html#contour-df
109 |
110 | ## xlim()
111 | ### Syntax
112 | ```javascript
113 | plt.xlim([x_min, x_max]);
114 | ```
115 | * *x_min (default: null)* : A number specifying the minimum of *x* axis. If not specified, it is determined automatically.
116 | * *x_max (default: null)* : A number specifying the maximum of *x* axis. If not specified, it is determined automatically.
117 |
118 | ### Description
119 | Set the limits for *x*.
120 |
121 | ### Sample
122 | ```javascript
123 | plt.xlim([0, null]);
124 | ```
125 |
126 | ## ylim()
127 | ### Syntax
128 | ```javascript
129 | plt.ylim([y_min, y_max]);
130 | ```
131 | (Arguments are similar to xlim())
132 |
133 | ### Description
134 | Set the limits for *y*.
135 |
136 | ### Sample
137 | ```javascript
138 | plt.ylim([0, null]);
139 | ```
140 |
141 | ## legend()
142 | ### Syntax
143 | ```javascript
144 | plt.legend(labels, location);
145 | ```
146 | * *labels* : Array containing titles of figure elements
147 | * *location (default:"upper right")* : String to specify the legend location. 'right', 'left, 'upper' and 'bottom' are supported. These can be combined such as 'bottom left'.
148 |
149 | ### Description
150 | Place a legend in the figure.
151 |
152 | ### Sample
153 | ```javascript
154 | plt.legend(['label1', 'label2', ...], "bottom left");
155 | ```
156 |
157 | ## xlabel()
158 | ### Syntax
159 | ```javascript
160 | plt.xlabel(label, options);
161 | ```
162 | * *label* : String representing *x* axis label
163 | * *options* : Object specifying some options like {option_name1: value1, option_name2: value2, ...}. Supported options are following:
164 |
165 | | Option name | Description |
166 | | ----------- |--------|
167 | | fontsize | Integer specifying the font size|
168 |
169 | ### Description
170 | Set the x axis label.
171 |
172 | ### Sample
173 | ```javascript
174 | plt.xlabel('x');
175 | ```
176 |
177 | ## ylabel()
178 | ### Syntax
179 | ```javascript
180 | plt.ylabel(label, options);
181 | ```
182 | (Arguments are the same as xlabel())
183 |
184 | ### Description
185 | Set the y axis label.
186 |
187 | ### Sample
188 | ```javascript
189 | plt.ylabel('y');
190 | ```
191 |
192 | ## colorbar()
193 | ### Syntax
194 | ```javascript
195 | plt.colorbar();
196 | ```
197 |
198 | ### Description
199 | Add a colorbar to a plot corresponding to a contour.
200 |
201 | ### Sample
202 | ```javascript
203 | plt.colorbar();
204 | ```
205 |
206 | ## show()
207 | ### Syntax
208 | ```javascript
209 | plt.show();
210 | ```
211 |
212 | ### Description
213 | Display a figure. Nothing is drawn until this method is called. This method MUST be called to draw a figure.
214 |
215 | ### Sample
216 | ```javascript
217 | plt.show();
218 | ```
219 |
220 | ## clf()
221 | ### Syntax
222 | ```javascript
223 | plt.clf();
224 | ```
225 |
226 | ### Description
227 | Clear all figures before show() is called.
228 |
229 | ### Sample
230 | ```javascript
231 | plt.clf();
232 | ```
233 |
--------------------------------------------------------------------------------
/examples/css/style.css:
--------------------------------------------------------------------------------
1 | .content-wrapper{
2 | clear: both;
3 | }
4 | .content-wrapper h3 {
5 | padding: 5px;
6 | background-color: #eee;
7 | border: 1px solid #ddd;
8 | }
9 | .figure{
10 | border: solid 1px #000;
11 | width: 640px;
12 | height: 480px;
13 | float: left;
14 | }
15 | .source{
16 | float: left;
17 | }
--------------------------------------------------------------------------------
/examples/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Simple Soba sample
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |