-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7814fce
commit efddae7
Showing
5 changed files
with
153 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
|
||
<html> | ||
<head> | ||
<link rel="stylesheet" type="text/css" href="honeytree.css" /> | ||
<script src="http://d3js.org/d3.v2.js"></script> | ||
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script> | ||
<title>Honey!</title> | ||
</head> | ||
<body> | ||
<script> | ||
function codeAddress() { | ||
var address = document.getElementById("address").value; | ||
var geocoder = new google.maps.Geocoder(); | ||
geocoder.geocode( { 'address': address}, function(results, status) { | ||
if (status == google.maps.GeocoderStatus.OK) { | ||
console.log(results[0]['geometry']['location']['$a']); | ||
console.log(results[0]['geometry']['location']['ab']); | ||
} else { | ||
alert("Geocode was not successful for the following reason: " + status); | ||
} | ||
}); | ||
} | ||
|
||
function inputFocus(i){ | ||
if(i.value=="enter your hive's NYC street address"){ i.value="";} | ||
} | ||
</script> | ||
<div id="banner"> | ||
<a href="http://daniellesucher.com"><img src="banner.png" /></a> | ||
</div> | ||
<div> | ||
<input id="address" type="textbox" value="enter your hive's NYC street address" onFocus="inputFocus(this)"> | ||
<input type="button" value="Geocode" onclick="codeAddress()"> | ||
</div> | ||
<div id="chart"></div> | ||
<script> | ||
var data = [ | ||
{name: "Norway Maple", val: 23.6}, | ||
{name: "Callery Pear", val: 6.39}, | ||
{name: "Ginkgo", val: 2.72}, | ||
{name: "London Planetree", val: 17.84}, | ||
{name: "American Linden", val: 2.14}, | ||
{name: "Zelkova", val: 4.4}, | ||
{name: "Red Maple", val: 1.81}, | ||
{name: "Littleleaf Linden", val: 6.31}, | ||
{name: "Silver Maple", val: 2.66}, | ||
{name: "Green Ash", val: 3.05}, | ||
{name: "Honeylocust", val: 6.3}, | ||
{name: "Pin Oak", val: 6.16}, | ||
{name: "Flowering Cherry", val: 1.67}, | ||
{name: "Northern Red Oak", val: 1.37}, | ||
{name: "Japanese Pagoda Tree", val: 1.46}, | ||
{name: "Silver Linden", val: 1.6}, | ||
{name: "other", val: 10.52} | ||
]; | ||
|
||
var w = 400, | ||
h = 400, | ||
r = Math.min(w, h) / 2, | ||
labelr = r + 30, // radius for label anchor | ||
color = d3.scale.category20c(), | ||
donut = d3.layout.pie(), | ||
arc = d3.svg.arc().innerRadius(r * 0.6).outerRadius(r), | ||
pos = d3.svg.arc().innerRadius(r + 38).outerRadius(r + 38); | ||
|
||
var vis = d3.select("#chart") | ||
.append("svg:svg") | ||
.data([data]) | ||
.attr("width", w + 300) | ||
.attr("height", h + 50); | ||
|
||
var arcs = vis.selectAll("g.arc") | ||
.data(donut.value(function(d) { return d.val })) | ||
.enter().append("svg:g") | ||
.attr("class", "arc") | ||
.attr("transform", "translate(" + (r + 150) + "," + r + ")"); | ||
|
||
arcs.append("svg:path") | ||
.attr("fill", function(d, i) { return color(i); }) | ||
.attr("d", arc); | ||
|
||
arcs.append("text") | ||
.attr("transform", function(d) { return "translate(" + pos.centroid(d) + ")"; }) | ||
.attr("dy", ".35em") | ||
.attr("text-anchor", "middle") | ||
.attr("display", function(d) { return d.value > 3.0 ? null : "none"; }) | ||
.text(function(d, i) { | ||
return d.data.name; | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
$:.unshift File.expand_path('.') | ||
require 'honeytree-lib' | ||
|
||
def depth(tree) | ||
if tree.class == Array | ||
tree.map! do |node| | ||
depth(node) | ||
end | ||
return 1 + tree.max | ||
else | ||
return -1 | ||
end | ||
end | ||
|
||
describe "Huffman encode trees" do | ||
before :each do | ||
@ht = Honeytree.new | ||
@ht.find_nearby_trees "40.6223262 -73.955483", "1" # EMJC, of course | ||
@ht.find_tree_percentages | ||
@ht.huffman_encode_trees | ||
end | ||
|
||
it "should be 6 levels deep" do | ||
depth(@ht.encoded).should == 6 | ||
end | ||
|
||
it "should account for 100% of the trees at its root" do | ||
@ht.encoded[-1].should == 100.0 | ||
end | ||
end |