Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 6.36 KB | None | 0 0
  1. <!--
  2.     Christian Barboza  
  3.     01420751   
  4.     CIS 468 Data Visualization
  5.     Professor Koop     
  6.     Assignment #3
  7. -->
  8.  
  9. <html>
  10.  
  11.     <head>
  12.         <title> CIS 468 Homework 3 </title>
  13.     </head>
  14.  
  15.     <style>
  16.         body {
  17.           background: #fcfcfa;
  18.         }
  19.  
  20.         .stroke {
  21.           fill: none;
  22.           stroke: black;
  23.           stroke-width: 1px;
  24.         }
  25.  
  26.         .fill {
  27.           fill: #fff;
  28.         }
  29.  
  30.         .graticule {
  31.           fill: none;
  32.           stroke: black;
  33.           stroke-width: 1px;
  34.         }
  35.  
  36.         .land {
  37.           fill: black;
  38.         }
  39.        
  40.         .country {
  41.             fill: white;
  42.             stroke: black;
  43.             stroke-width: 1px;
  44.         }
  45.        
  46.         .boundary {
  47.           fill: none;
  48.           stroke: black;
  49.           stroke-width: 1px;
  50.         }
  51.     </style>
  52.  
  53.     <body>
  54.         <script src='https://cdnjs.cloudflare.com/ajax/libs/d3/4.7.3/d3.min.js'></script>
  55.         <script src='https://cdnjs.cloudflare.com/ajax/libs/topojson/2.2.0/topojson.min.js'></script>
  56.        
  57.         <h1> Homework 3 </h1>
  58.         <h2> Christian Barboza </h2>
  59.         <h2> #01420751 </h2>
  60.         <h2> CIS 468 Data Visualization </h2>
  61.         <label><em> This assignment is all my own work. I did not copy the code from any other source. </em></label>
  62.  
  63.         <h1>Women Soccer Players- Choropleth </h1>
  64.         <div id="women"></div>
  65.        
  66.         <h1>Men Soccer Players- Choropleth </h1>
  67.         <div id="men"></div>
  68.        
  69.         <h1> Force-Directed Graph </h1>
  70.         <div id="force"></div>
  71.        
  72.         <!--Women's Choropleth -->
  73.         <div id = "women">
  74.         </div>
  75.         <script>  
  76.             var width = 960, height = 580;
  77.            
  78.             var color = d3.scaleSequential(function (d) {
  79.                 return d3.interpolateReds(d/12);
  80.             });
  81.            
  82.             var projection = d3.geoMercator()
  83.                 .scale( 100 )
  84.                 .translate( [ width / 2, height / 2 ] )
  85.                 .precision( .1 );
  86.  
  87.             var path = d3.geoPath()
  88.                 .projection( projection );
  89.  
  90.             var svg = d3.select( "#women" ).append( "svg" )
  91.                 .attr( "width", width )
  92.                 .attr( "height", height );
  93.  
  94.             svg.append( "defs" ).append( "path" )
  95.                 .datum( { type: "Sphere" } )
  96.                 .attr( "id", "sphere" )
  97.                 .attr( "d", path );
  98.  
  99.             svg.append( "use" )
  100.                 .attr( "class", "stroke" )
  101.                 .attr( "xlink:href", "#sphere" );
  102.  
  103.             svg.append( "use" )
  104.                 .attr( "class", "fill" )
  105.                 .attr( "xlink:href", "#sphere" );
  106.        
  107.             d3.queue()    
  108.                     .defer(d3.json, "https://cdn.rawgit.com/johan/world.geo.json/master/countries.geo.json")
  109.                     .defer(d3.json, "http://www.cis.umassd.edu/~dkoop/cis468-2017sp/a3/fifa-17-women.json")
  110.                     .await(ready);
  111.    
  112.             function ready(error, map, data)
  113.             {  
  114.                 svg.append("g")
  115.                     .attr("class", "countries")
  116.                     .selectAll("path")
  117.                     .data(map.features)
  118.                     .enter().append("path")
  119.                         .attr("d", path)
  120.                         .attr("fill", function (d) { return color(data.filter(function (i) {return d.properties.name == i['Country'];}).length);})
  121.                         .attr("stroke","black");
  122.             }      
  123.         </script>
  124.        
  125.         <!--Men's Choropleth -->
  126.         <div id = "men">
  127.         </div>
  128.        
  129.         <script>     
  130.             var width = 960, height = 580;
  131.            
  132.             var color = d3.scaleSequential(function (d) {
  133.                 return d3.interpolateReds(d/12);
  134.             });
  135.            
  136.             var projection = d3.geoMercator()
  137.                 .scale( 100 )
  138.                 .translate( [ width / 2, height / 2 ] )
  139.                 .precision( .1 );
  140.  
  141.             var path = d3.geoPath()
  142.                 .projection( projection );
  143.  
  144.             var svg = d3.select( "#men" ).append( "svg" )
  145.                 .attr( "width", width )
  146.                 .attr( "height", height );
  147.  
  148.             svg.append( "defs" ).append( "path" )
  149.                 .datum( { type: "Sphere" } )
  150.                 .attr( "id", "sphere" )
  151.                 .attr( "d", path );
  152.  
  153.             svg.append( "use" )
  154.                 .attr( "class", "stroke" )
  155.                 .attr( "xlink:href", "#sphere" );
  156.  
  157.             svg.append( "use" )
  158.                 .attr( "class", "fill" )
  159.                 .attr( "xlink:href", "#sphere" );
  160.        
  161.             d3.queue()    
  162.                     .defer(d3.json, "https://cdn.rawgit.com/johan/world.geo.json/master/countries.geo.json")
  163.                     .defer(d3.json, "http://www.cis.umassd.edu/~dkoop/cis468-2017sp/a3/soccer-teammates-men.json")
  164.                     .await(ready);
  165.    
  166.             function ready(error, map, data)
  167.             {  
  168.                 svg.append("g")
  169.                     .attr("class", "countries")
  170.                     .selectAll("path")
  171.                     .data(map.features)
  172.                     .enter().append("path")
  173.                         .attr("d", path)
  174.                         .attr("fill", function (d) { return color(data.filter(function (i) {return d.properties.name == i['Country'];}).length);})
  175.                         .attr("stroke","black");
  176.             }      
  177.         </script>
  178.        
  179.         <!--Force-Directed Graph -->
  180.         <div id = "force">
  181.         </div>
  182.         <meta charset="utf-8">
  183.         <style>
  184.  
  185.         .links line {
  186.           stroke: #999;
  187.           stroke-opacity: 0.6;
  188.         }
  189.  
  190.         .nodes circle {
  191.           stroke: #fff;
  192.           stroke-width: 1.5px;
  193.         }
  194.  
  195.         </style>
  196.        
  197.         <!--Load the D3 library -->
  198.         <script src="https://d3js.org/d3.v4.min.js"></script>
  199.         <script>
  200.  
  201.         var svg = d3.select("svg"),
  202.             width = 960,
  203.             height = 600;
  204.  
  205.         var color = d3.scaleOrdinal(d3.schemeCategory20);
  206.  
  207.         var simulation = d3.forceSimulation()
  208.             .force("link", d3.forceLink().id(function(d) { return d.id; }))
  209.             .force("charge", d3.forceManyBody())
  210.             .force("center", d3.forceCenter(width / 2, height / 2));
  211.  
  212.         d3.json("miserables.json", function(error, graph) {
  213.           if (error) throw error;
  214.  
  215.           var link = svg.append("g")
  216.               .attr("class", "links")
  217.             .selectAll("line")
  218.             .data(graph.links)
  219.             .enter().append("line")
  220.               .attr("stroke-width", function(d) { return Math.sqrt(d.value); });
  221.  
  222.           var node = svg.append("g")
  223.               .attr("class", "nodes")
  224.             .selectAll("circle")
  225.             .data(graph.nodes)
  226.             .enter().append("circle")
  227.               .attr("r", 5)
  228.               .attr("fill", function(d) { return color(d.group); })
  229.               .call(d3.drag()
  230.                   .on("start", dragstarted)
  231.                   .on("drag", dragged)
  232.                   .on("end", dragended));
  233.  
  234.           node.append("title")
  235.               .text(function(d) { return d.id; });
  236.  
  237.           simulation
  238.               .nodes(graph.nodes)
  239.               .on("tick", ticked);
  240.  
  241.           simulation.force("link")
  242.               .links(graph.links);
  243.  
  244.           function ticked() {
  245.             link
  246.                 .attr("x1", function(d) { return d.source.x; })
  247.                 .attr("y1", function(d) { return d.source.y; })
  248.                 .attr("x2", function(d) { return d.target.x; })
  249.                 .attr("y2", function(d) { return d.target.y; });
  250.  
  251.             node
  252.                 .attr("cx", function(d) { return d.x; })
  253.                 .attr("cy", function(d) { return d.y; });
  254.           }
  255.         });
  256.  
  257.         function dragstarted(d) {
  258.           if (!d3.event.active) simulation.alphaTarget(0.3).restart();
  259.           d.fx = d.x;
  260.           d.fy = d.y;
  261.         }
  262.  
  263.         function dragged(d) {
  264.           d.fx = d3.event.x;
  265.           d.fy = d3.event.y;
  266.         }
  267.  
  268.         function dragended(d) {
  269.           if (!d3.event.active) simulation.alphaTarget(0);
  270.           d.fx = null;
  271.           d.fy = null;
  272.         }
  273.  
  274.         </script>
  275.        
  276.        
  277.     </body>
  278.    
  279. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement