Browse files

adding readme

  • Loading branch information...
1 parent f5a578a commit 900183317cc34f834c4db415b78d8504b949d4ae @maxdemarzi committed Feb 21, 2012
Showing with 161 additions and 109 deletions.
  1. +23 −0 README
  2. +0 −3 neoflow.rb
  3. +132 −7 public/index.html
  4. +5 −0 public/neoflow.css
  5. +1 −50 public/us-state-centroids.json
  6. +0 −49 public/working.html
View
23 README
@@ -0,0 +1,23 @@
+=== Description
+
+Finding the Max Flow of a network using Gremlin and Neo4j.
+
+=== How To
+
+Follow along on {Max Flow with Gremlin and Transactions}[http://wp.me/p26jdv-7f]
+
+ git clone git@github.com:maxdemarzi/neoflow.git
+ cd neoflow
+ bundle install
+ neo4j:install
+ neo4j:start
+ neo4j:create
+ rackup
+
+Then visit http://localhost:9292/index.html to see the example.
+
+=== Links
+
+* {Neo4j Community}[http://neo4j.org]
+* {D3.js}[http://mbostock.github.com/d3/]
+* {Max De Marzi}[http://maxdemarzi.com]
View
3 neoflow.rb
@@ -3,9 +3,6 @@
require 'sinatra'
require 'uri'
-require 'net-http-spy'
-Net::HTTP.http_logger_options = {:verbose => true} # see everything
-
def create_graph
neo = Neography::Rest.new
graph_exists = neo.get_node_properties(1)
View
139 public/index.html
@@ -1,15 +1,140 @@
<!DOCTYPE html>
<html>
<head>
- <meta http-equiv="Content-type" content="text/html; charset=utf-8">
- <title>Neo4j Force Collapsible Example</title>
+ <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
+ <title>U.S. States</title>
<script type="text/javascript" src="d3.min.js"></script>
- <script type="text/javascript" src="d3.geom.min.js"></script>
- <script type="text/javascript" src="d3.layout.min.js"></script>
- <link type="text/css" rel="stylesheet" href="network.css"/>
+ <script type="text/javascript" src="d3.geo.min.js"></script>
+ <link type="text/css" rel="stylesheet" href="neoflow.css"/>
</head>
<body>
- <div id="chart"></div>
- <script type="text/javascript" src="network.js"></script>
+ <script type="text/javascript">
+
+// The radius scale for the centroids.
+var r = d3.scale.sqrt()
+ .domain([0, 1e6])
+ .range([0, 10]);
+
+// Our projection.
+var xy = d3.geo.albersUsa();
+
+var svg = d3.select("body").append("svg");
+svg.append("g").attr("id", "states");
+svg.append("g").attr("id", "state-centroids");
+
+d3.json("us-states.json", function(collection) {
+ svg.select("#states")
+ .selectAll("path")
+ .data(collection.features)
+ .enter().append("path")
+ .attr("d", d3.geo.path().projection(xy));
+});
+
+d3.json("us-state-centroids.json", function(collection) {
+ svg.select("#state-centroids")
+ .selectAll("circle")
+ .data(collection.features
+ .sort(function(a, b) { return b.properties.population - a.properties.population; }))
+ .enter().append("circle")
+ .attr("id", function(d) { return "state_" + d.id; })
+ .attr("transform", function(d) { return "translate(" + xy(d.geometry.coordinates) + ")"; })
+ .attr("r", 0)
+ .transition()
+ .duration(1000)
+ .delay(function(d, i) { return i * 50; })
+ .attr("r", 5);
+});
+
+svg.append("text")
+ .attr("transform", function() { return "translate(" + xy([-119.355165,35.458606]) + ")"; })
+ .attr("dy", ".35em")
+ .attr("dx", "-.45em")
+ .attr("text-anchor", "end")
+ .text("Source");
+
+svg.append("text")
+ .attr("transform", function() { return "translate(" + xy([-88.380238,41.278216]) + ")"; })
+ .attr("dy", ".35em")
+ .attr("dx", ".45em")
+ .attr("text-anchor", "start")
+ .text("Sink");
+
+svg.append("text")
+ .attr("transform", function() { return "translate(" + xy([ -97.388631,30.943149]) + ")"; })
+ .attr("dy", ".35em")
+ .attr("dx", ".45em")
+ .attr("text-anchor", "start")
+ .text("Node");
+
+// Source to Node
+svg.append("text")
+ .attr("transform", function() { return "translate(" + xy([-113,32]) + ")"; })
+ .attr("dy", ".35em")
+ .attr("dx", ".45em")
+ .attr("text-anchor", "start")
+ .text("Capacity: 1");
+
+// Node to Sync
+svg.append("text")
+ .attr("transform", function() { return "translate(" + xy([-93,36]) + ")"; })
+ .attr("dy", ".35em")
+ .attr("dx", ".45em")
+ .attr("text-anchor", "start")
+ .text("Capacity: 3");
+
+
+// Source to Node
+svg.append("text")
+ .attr("transform", function() { return "translate(" + xy([-113,42]) + ")"; })
+ .attr("dy", ".35em")
+ .attr("dx", ".45em")
+ .attr("text-anchor", "start")
+ .text("Capacity: 1");
+
+// Source to Node
+svg.append("text")
+ .attr("transform", function() { return "translate(" + xy([-113,37]) + ")"; })
+ .attr("dy", ".35em")
+ .attr("dx", ".45em")
+ .attr("text-anchor", "start")
+ .text("Capacity: 2");
+
+
+
+svg.append("svg:path")
+ .attr("d","M" + xy([-119.355165,35.458606]) + " L" + xy([-97.388631,30.943149]))
+ .style("stroke-width", 2)
+ .style("stroke", "steelblue")
+ .style("fill", "none");
+
+svg.append("svg:path")
+ .attr("d","M" + xy([-119.355165,35.458606]) + " L" + xy([-88.380238,41.278216]))
+ .style("stroke-width", 2)
+ .style("stroke", "steelblue")
+ .style("fill", "none");
+
+svg.append("svg:path")
+ .attr("d","M" + xy([-119.355165,35.458606]) + " S" + xy([-110,45]) + " " + xy([-88.380238,41.278216]))
+ .style("stroke-width", 2)
+ .style("stroke", "steelblue")
+ .style("fill", "none");
+
+svg.append("svg:path")
+ .attr("d","M" + xy([ -97.388631,30.943149]) + " L" + xy([-88.380238,41.278216]))
+ .style("stroke-width", 2)
+ .style("stroke", "steelblue")
+ .style("fill", "none");
+
+// Max Flow
+svg.append("text")
+ .attr("x","0")
+ .attr("y","10")
+ .attr("dy", ".35em")
+ .attr("dx", ".45em")
+ .attr("text-anchor", "start")
+ .text("Max Flow: 4");
+
+
+ </script>
</body>
</html>
View
5 public/neoflow.css
@@ -12,4 +12,9 @@ svg {
#state-centroids circle {
fill: steelblue;
fill-opacity: .8;
+}
+
+#citypath {
+ stroke: #c00;
+ stroke-width: 3px;
}
View
51 public/us-state-centroids.json
@@ -1,54 +1,5 @@
{"type":"FeatureCollection","features":[
-{"type":"Feature","id":"01","geometry":{"type":"Point","coordinates":[-86.766233,33.001471]},"properties":{"name":"Alabama","population":4447100}},
-{"type":"Feature","id":"02","geometry":{"type":"Point","coordinates":[-148.716968,61.288254]},"properties":{"name":"Alaska","population":626932}},
-{"type":"Feature","id":"04","geometry":{"type":"Point","coordinates":[-111.828711,33.373506]},"properties":{"name":"Arizona","population":5130632}},
-{"type":"Feature","id":"05","geometry":{"type":"Point","coordinates":[-92.576816,35.080251]},"properties":{"name":"Arkansas","population":2673400}},
{"type":"Feature","id":"06","geometry":{"type":"Point","coordinates":[-119.355165,35.458606]},"properties":{"name":"California","population":33871648}},
-{"type":"Feature","id":"08","geometry":{"type":"Point","coordinates":[-105.203628,39.500656]},"properties":{"name":"Colorado","population":4301261}},
-{"type":"Feature","id":"09","geometry":{"type":"Point","coordinates":[-72.874365,41.494852]},"properties":{"name":"Connecticut","population":3405565}},
-{"type":"Feature","id":"10","geometry":{"type":"Point","coordinates":[-75.561908,39.397164]},"properties":{"name":"Delaware","population":783600}},
-{"type":"Feature","id":"11","geometry":{"type":"Point","coordinates":[-77.014001,38.910092]},"properties":{"name":"District of Columbia","population":572059}},
-{"type":"Feature","id":"12","geometry":{"type":"Point","coordinates":[-81.634622,27.795850]},"properties":{"name":"Florida","population":15982378}},
-{"type":"Feature","id":"13","geometry":{"type":"Point","coordinates":[-83.868887,33.332208]},"properties":{"name":"Georgia","population":8186453}},
-{"type":"Feature","id":"15","geometry":{"type":"Point","coordinates":[-157.524452,21.146768]},"properties":{"name":"Hawaii","population":1211537}},
-{"type":"Feature","id":"16","geometry":{"type":"Point","coordinates":[-115.133222,44.242605]},"properties":{"name":"Idaho","population":1293953}},
{"type":"Feature","id":"17","geometry":{"type":"Point","coordinates":[-88.380238,41.278216]},"properties":{"name":"Illinois","population":12419293}},
-{"type":"Feature","id":"18","geometry":{"type":"Point","coordinates":[-86.261515,40.163935]},"properties":{"name":"Indiana","population":6080485}},
-{"type":"Feature","id":"19","geometry":{"type":"Point","coordinates":[-93.049161,41.960392]},"properties":{"name":"Iowa","population":2926324}},
-{"type":"Feature","id":"20","geometry":{"type":"Point","coordinates":[-96.536052,38.454303]},"properties":{"name":"Kansas","population":2688418}},
-{"type":"Feature","id":"21","geometry":{"type":"Point","coordinates":[-85.241819,37.808159]},"properties":{"name":"Kentucky","population":4041769}},
-{"type":"Feature","id":"22","geometry":{"type":"Point","coordinates":[-91.457133,30.699270]},"properties":{"name":"Louisiana","population":4468976}},
-{"type":"Feature","id":"23","geometry":{"type":"Point","coordinates":[-69.719931,44.313614]},"properties":{"name":"Maine","population":1274923}},
-{"type":"Feature","id":"24","geometry":{"type":"Point","coordinates":[-76.797396,39.145653]},"properties":{"name":"Maryland","population":5296486}},
-{"type":"Feature","id":"25","geometry":{"type":"Point","coordinates":[-71.363628,42.271831]},"properties":{"name":"Massachusetts","population":6349097}},
-{"type":"Feature","id":"26","geometry":{"type":"Point","coordinates":[-84.170753,42.866412]},"properties":{"name":"Michigan","population":9938444}},
-{"type":"Feature","id":"27","geometry":{"type":"Point","coordinates":[-93.583003,45.210782]},"properties":{"name":"Minnesota","population":4919479}},
-{"type":"Feature","id":"28","geometry":{"type":"Point","coordinates":[-89.593164,32.566420]},"properties":{"name":"Mississippi","population":2844658}},
-{"type":"Feature","id":"29","geometry":{"type":"Point","coordinates":[-92.153770,38.437715]},"properties":{"name":"Missouri","population":5595211}},
-{"type":"Feature","id":"30","geometry":{"type":"Point","coordinates":[-111.209708,46.813302]},"properties":{"name":"Montana","population":902195}},
-{"type":"Feature","id":"31","geometry":{"type":"Point","coordinates":[-97.403875,41.183753]},"properties":{"name":"Nebraska","population":1711263}},
-{"type":"Feature","id":"32","geometry":{"type":"Point","coordinates":[-116.304648,37.165965]},"properties":{"name":"Nevada","population":1998257}},
-{"type":"Feature","id":"33","geometry":{"type":"Point","coordinates":[-71.463342,43.153046]},"properties":{"name":"New Hampshire","population":1235786}},
-{"type":"Feature","id":"34","geometry":{"type":"Point","coordinates":[-74.428055,40.438458]},"properties":{"name":"New Jersey","population":8414350}},
-{"type":"Feature","id":"35","geometry":{"type":"Point","coordinates":[-106.342108,34.623012]},"properties":{"name":"New Mexico","population":1819046}},
-{"type":"Feature","id":"36","geometry":{"type":"Point","coordinates":[-74.645228,41.507548]},"properties":{"name":"New York","population":18976457}},
-{"type":"Feature","id":"37","geometry":{"type":"Point","coordinates":[-79.667654,35.553334]},"properties":{"name":"North Carolina","population":8049313}},
-{"type":"Feature","id":"38","geometry":{"type":"Point","coordinates":[-99.334736,47.375168]},"properties":{"name":"North Dakota","population":642200}},
-{"type":"Feature","id":"39","geometry":{"type":"Point","coordinates":[-82.749366,40.480854]},"properties":{"name":"Ohio","population":11353140}},
-{"type":"Feature","id":"40","geometry":{"type":"Point","coordinates":[-96.834653,35.597940]},"properties":{"name":"Oklahoma","population":3450654}},
-{"type":"Feature","id":"41","geometry":{"type":"Point","coordinates":[-122.579524,44.732273]},"properties":{"name":"Oregon","population":3421399}},
-{"type":"Feature","id":"42","geometry":{"type":"Point","coordinates":[-77.075925,40.463528]},"properties":{"name":"Pennsylvania","population":12281054}},
-{"type":"Feature","id":"44","geometry":{"type":"Point","coordinates":[-71.448902,41.753318]},"properties":{"name":"Rhode Island","population":1048319}},
-{"type":"Feature","id":"45","geometry":{"type":"Point","coordinates":[-81.032387,34.034551]},"properties":{"name":"South Carolina","population":4012012}},
-{"type":"Feature","id":"46","geometry":{"type":"Point","coordinates":[-99.043799,44.047502]},"properties":{"name":"South Dakota","population":754844}},
-{"type":"Feature","id":"47","geometry":{"type":"Point","coordinates":[-86.397772,35.795862]},"properties":{"name":"Tennessee","population":5689283}},
-{"type":"Feature","id":"48","geometry":{"type":"Point","coordinates":[-97.388631,30.943149]},"properties":{"name":"Texas","population":20851820}},
-{"type":"Feature","id":"49","geometry":{"type":"Point","coordinates":[-111.900160,40.438987]},"properties":{"name":"Utah","population":2233169}},
-{"type":"Feature","id":"50","geometry":{"type":"Point","coordinates":[-72.814309,44.081127]},"properties":{"name":"Vermont","population":608827}},
-{"type":"Feature","id":"51","geometry":{"type":"Point","coordinates":[-77.835857,37.750345]},"properties":{"name":"Virginia","population":7078515}},
-{"type":"Feature","id":"53","geometry":{"type":"Point","coordinates":[-121.624501,47.341728]},"properties":{"name":"Washington","population":5894121}},
-{"type":"Feature","id":"54","geometry":{"type":"Point","coordinates":[-80.820221,38.767195]},"properties":{"name":"West Virginia","population":1808344}},
-{"type":"Feature","id":"55","geometry":{"type":"Point","coordinates":[-89.001006,43.728544]},"properties":{"name":"Wisconsin","population":5363675}},
-{"type":"Feature","id":"56","geometry":{"type":"Point","coordinates":[-107.008835,42.675762]},"properties":{"name":"Wyoming","population":493782}},
-{"type":"Feature","id":"72","geometry":{"type":"Point","coordinates":[-66.58765,18.19958]},"properties":{"code":"PR","name":"Puerto Rico","population":3808610}}
+{"type":"Feature","id":"48","geometry":{"type":"Point","coordinates":[-97.388631,30.943149]},"properties":{"name":"Texas","population":20851820}}
]}
View
49 public/working.html
@@ -1,49 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
- <title>U.S. States</title>
- <script type="text/javascript" src="d3.min.js"></script>
- <script type="text/javascript" src="d3.geo.min.js"></script>
- <link type="text/css" rel="stylesheet" href="neoflow.css"/>
- </head>
- <body>
- <script type="text/javascript">
-
-// The radius scale for the centroids.
-var r = d3.scale.sqrt()
- .domain([0, 1e6])
- .range([0, 10]);
-
-// Our projection.
-var xy = d3.geo.albersUsa();
-
-var svg = d3.select("body").append("svg");
-svg.append("g").attr("id", "states");
-svg.append("g").attr("id", "state-centroids");
-
-d3.json("us-states.json", function(collection) {
- svg.select("#states")
- .selectAll("path")
- .data(collection.features)
- .enter().append("path")
- .attr("d", d3.geo.path().projection(xy));
-});
-
-d3.json("us-state-centroids.json", function(collection) {
- svg.select("#state-centroids")
- .selectAll("circle")
- .data(collection.features
- .sort(function(a, b) { return b.properties.population - a.properties.population; }))
- .enter().append("circle")
- .attr("transform", function(d) { return "translate(" + xy(d.geometry.coordinates) + ")"; })
- .attr("r", 0)
- .transition()
- .duration(1000)
- .delay(function(d, i) { return i * 50; })
- .attr("r", function(d) { return r(d.properties.population); });
-});
-
- </script>
- </body>
-</html>

0 comments on commit 9001833

Please sign in to comment.