* is Unix
Jacob Kaplan-Moss
October 7, 2009
I'm working on a project that uses data in JSON format (www.json.org). It took me a while to get it going in processing, so I thought I'd post what I did here. If there's a better way (which undoubtedly there is!), please let me know.
Andrew Odewahn
--
Here are the steps I took (on Windows):
1. Download http://www.json.org/java/json.zip from json.org. Save it in a some directory, which I'll call %DOWNLOAD_HOME%.
2. Unzip it. Be sure you preserve the archive's directory structure (/org/json/) when you unzip the file.
3. Change directory into %DOWNLOAD_HOME%orgjson
Features: * Multiple Data Representations: Treemaps, Radial Layouts, HyperTrees/Graphs, SpaceTree-like Layouts, and more... * Major Browsers Support: IE6+, Firefox2+, Safari3+, Opera9.5+ * Open Source: Licensed under the BSD License * Library Agnostic: You may use the JIT with your favorite DOM manipulation framework * Extensible: All visualization classes are mutable, so you can easily add/override any method you want. * Composable: Visualizations can be combined in order to create new visualization methods.
<script type="text/javascript" src="http://willarson.com/code/sparklines/processing.js"></script>
<script type="text/javascript" src="http://willarson.com/code/sparklines/sparklines.js"></script>
<script>
var setup_sparklines = function() {
var opts = {};
var data = [100,500,300,200,400,500,400,400,100,200];
new Sparkline('simple1', data).draw();
};
</script>
<p> A simple sparkline. </p>
<pre><code>var data = [100,500,300,200,400,500,400,400,100,200];
new Sparkline('simple1', data).draw();</code></pre>
<canvas width="300" height="50" id="simple1" ></canvas>
<script>
setup_sparklines();
</script>
http://willarson.com/code/sparklines/sparklines.html
A simple sparkline.
var data = [100,500,300,200,400,500,400,400,100,200];
new Sparkline('simple1', data).draw();
void branch(float h) {
h *= (float) $('#val_size_1').val();
// All recursive functions must have an exit condition!!!!
// Here, ours is when the length of the branch is 2 pixels or less
if (h > 5) {
pushMatrix(); // Save the current state of transformation (i.e. where are we now)
rotate(theta); // Rotate by theta
line(0,0,0,-h); // Draw the branch
translate(0,-h); // Move to the end of the branch
//ellipse(0, 0, 40, 40);
branch(h); // Ok, now call myself to draw two new branches!!
popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state
// Repeat the same thing, only branch off to the "left" this time!
pushMatrix();
rotate(-theta);
line(0,0,0,-h);
translate(0,-h);
branch(h);
popMatrix();
}
}
// just type here
// and click "submit" when done
void setup(){
size(301,301);
}
void draw() {
background(290, mouseX, 50);
noStroke();
fill(mouseX, 139, mouseY);
rect(45, 45, 45, 45);
fill(20, mouseY, mouseX);
rect(50, 50, 35, 35);
fill(mouseX, 139, mouseY);
rect(100, 100, 100, 100);
fill(mouseX, 20, mouseY);
rect(50, 50, 35, 35);
fill(mouseX, mouseY, 139);
rect(200, 200, 200, 200);
fill(20, mouseY, mouseX);
rect(50, 50, 35, 35);
fill(mouseX, mouseY, mouseY);
rect(100, 100, 100, 100);
fill(20, mouseY, mouseX);
rect(50, 50, 35, 35);
}