Elegans - Elegant 3D plots generator with WebGL¶
Description¶
Elegans is a 3D plotting library written in JavaScript. With Elegans, you can generate charts in JavaScript, and show them on your browser.
Contents:
Getting Started¶
Installation¶
Download the latest version of Elegans from here. Then copy and paste code below to your html file.
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/three.js/r66/three.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/d3/3.4.4/d3.min.js"></script>
<script type="text/javascript" src="your_link_to_elegans.min.js"></script>
Preparing Data¶
There are two input formats of vertexes, Matrix and Array.
Matrix¶
Matrix format is looks like return value of Numpy.meshgrid. Surface and Wireframe support this format.
var data =
{x:[
[1,1,1],
[2,2,2],
[3,3,3]
],
y:[
[1,2,3],
[1,2,3],
[1,2,3]
],
z:[
[1,2,3],
[4,5,6],
[7,8,9]
]};
Array¶
In Array format, the set of 3 values that have the same index in x,y,z array indicates 1 vertex. Line, Particles and Scatter support this format.
var data = {x:[1,2,3],y:[1,2,3],z:[1,2,3]};
Quick plotting¶
You can quickly generate plots in method-chain style, with d3.js selector.
d3.select("#vis").datum(data).call(Elegans.LinePlot.thickness(5).colors(["#dd1c77","#dd1c77"]));
Multiple plotting¶
When you need to put multiple plots in one 3-dimentional space, you can write code like below.
var stage = new Elegans.Stage(d3.select("#vis")[0][0]);
var line = new Elegans.Line(line_data, {thickness: 5, colors: ["#dd1c77","#dd1c77"]});
var particles = new Elegans.Particles(particles_data, {size: 0.8, color: "#c994c7"});
stage.add(line);
stage.add(particles);
stage.render();
Embedding Elegans into your library¶
Elegans has API to make it easier to embed it into various environments except browsers, like IPython notebook. What you need to do is only to generate simple JSON object, and embed it into static html templates like below.
var model = {
charts:[{type:"Particles",data:{x:[1,2,3],y:[1,2,3],z:[1,2,3]},options:{color:"#000000"}}],
options:{width:500, height:500}
};
Elegans.Embed.parse(model, "#vis");
Supporting Charts¶
API Reference¶
Stage¶
Methods¶
.add(chart)
Add charts to 3-dementional space.
- chart - instance of Surface, Wireframe, Line, Particles, Scatter
.render()
Start rendering charts.
Surface¶
Constructor¶
Surface(data, options)
- data - Matrix type data
- options
- fill_colors - Array of String
- has_legend - Boolean
WireFrame¶
Constructor¶
WireFrame(data, options)
- data - Matrix type data
- options
- name - String
- color - String
- thickness - Number
- has_legend - Boolean
Line¶
Constructor¶
Line(data, options)
- data - Array type data
- options
- name - String
- colors - Array of String
- thickness - Number
- has_legend - Boolean
Particles¶
Constructor¶
Particles(data, options)
- data - Array type data
- options
- name - String
- color - String
- size - Number. default value is 0.3
- has_legend - Boolean
Scatter¶
Constructor¶
Scatter(data, options)
- data - Array type data
- options
- name - String
- shape - String. One of “circle”, “cross”, “rect”, and “diamond.”
- size - Number. default value is 1.5.
- stroke_width - Number. default value is 3.
- stroke_color - String
- fill_color - String
- has_legend - Boolean
WireFramePlot¶
Properties¶
- data_name - String
- color - String
- thickness - Number
- has_legend - Boolean
LinePlot¶
Properties¶
- data_name - String
- colors - Array of String
- thickness - Number
- has_legend - Boolean
Contribution¶
How to contribute¶
- Fork it.
- Create your feauture branch.
- Commit your changes.
- Push to the branch.
- Create new Pull-request.
How to build Elegans¶
Before building Elegans, you need to install node.js and npm.
sudo apt-get install node
After installing, Pull repository from GitHub.
git pull https://github.com/domitry/elegans.git
Then, run commands below.
cd elegans
npm install
grunt release
License¶
This version of Elegans is licenced under the MIT License.
The MIT License (MIT)
Copyright (c) 2014 Naoki Nishida
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.