diff --git a/Exercise 2/exercise2_0.html b/Exercise 2/exercise2_0.html index b53c5f3..7007eb6 100644 --- a/Exercise 2/exercise2_0.html +++ b/Exercise 2/exercise2_0.html @@ -65,9 +65,15 @@ d3.json("states.json",function(json){ svg.append("g").attr("class","mapGroup"); - var states = svg.select(".mapGroup").selectAll(".stateLine").data(json.features); - states.enter().append("path").attr("class","stateLine") + var states = svg.select(".mapGroup") + .selectAll(".stateLine") + .data(json.features); + + states.enter() + .append("path") + .attr("class","stateLine") .attr("d", d3.geo.path()); + // .attr("projection", d3.geo.orthographic); function getCentroid(stateName) { var stateData; @@ -113,19 +119,28 @@ } function displayData() { - var extent = d3.extent(csv, function(d){ return parseFloat(d[dataPoint]); }); - var radius = d3.scale.sqrt() - .domain(extent) - .range([5, 50]); - - svg.select(".title").text(dataPoint); + var extent = d3.extent(csv,function(d){ + return parseFloat(d[dataPoint]); + }); + // console.log(extent); + var radiusScale = d3.scale + .sqrt() + .domain(extent) + .range([3,30]); var circlePath = d3.geo.path() - .pointRadius(function(d) { return radius(d.radius); }); + .pointRadius(function(d){ + return radiusScale(d.radius); + }) + svg.select(".dotGroup") + .selectAll("path") + .each(function(d){ + d.radius = parseFloat(d.dataset[dataPoint]) + }) + .attr("d",circlePath); + svg.select(".title") + .text(dataPoint); - svg.select(".dotGroup").selectAll("path") - .each(function(d){ d.radius = parseFloat(d.dataset[dataPoint])}) - .attr("d", circlePath); } setupData(); diff --git a/Exercise 2/exercise2_1.html b/Exercise 2/exercise2_1.html index ded10f9..a37db43 100644 --- a/Exercise 2/exercise2_1.html +++ b/Exercise 2/exercise2_1.html @@ -108,7 +108,7 @@ var extent = d3.extent(csv, function(d){ return parseFloat(d[dataPoint]); }); var radius = d3.scale.sqrt() .domain(extent) - .range([5, 50]); + .range([3, 30]); svg.select(".title").text(dataPoint); @@ -116,7 +116,7 @@ .pointRadius(function(d) { return radius(d.radius); }); svg.select(".dotGroup").selectAll("path") - .each(function(d){ d.radius = parseFloat(d.dataset[dataPoint])}) + .each(function(d){ d.radius = parseFloat(d.dataset[dataPoint]); }) .attr("d", circlePath); } diff --git a/Exercise 2/exercise2_2.html b/Exercise 2/exercise2_2.html index e610366..811ca51 100644 --- a/Exercise 2/exercise2_2.html +++ b/Exercise 2/exercise2_2.html @@ -129,7 +129,7 @@ var dotGroup = svg.select(".dotGroup"); dotGroup.selectAll("path") - .each(function(d){ d.radius = parseFloat(d.dataset[dataPoint])}) + .each(function(d){ d.radius = parseFloat(d.dataset[dataPoint]); }) .attr("d", circlePath) .attr("fill",function(d){ return colorScale(d.dataset[dataPoint]); }); diff --git a/Exercise 2/exercise2_3.html b/Exercise 2/exercise2_3.html index a6eb886..89e49d0 100644 --- a/Exercise 2/exercise2_3.html +++ b/Exercise 2/exercise2_3.html @@ -36,14 +36,20 @@ .stateName { text-anchor: end; font-size: 12px; - baseline-shift: -12px; + baseline-shift: -6px; } .label { text-anchor: middle; font-size: 12px; display: none; } - .state:hover .label { + .state:hover .label, + .state.selected .label, + .stateBar:hover .label { + display: block; + } + .stateBar:hover .stateName, + .stateBar.selected .stateName { display: block; } .state path { @@ -103,7 +109,10 @@ .text(dataPoint); var states = svg.append("g").attr("class","dotGroup") .selectAll(".state").data(csv); - var entering = states.enter().append("g").attr("class","state"); + var entering = states.enter().append("g").attr("class","state") + .attr("class",function(d){ + return "state " + getClassName(d.State); + }); var centroid; entering.append("path").datum(function(d) { @@ -149,9 +158,19 @@ var dotGroup = svg.select(".dotGroup"); dotGroup.selectAll("path") - .each(function(d){ d.radius = parseFloat(d.dataset[dataPoint])}) + .each(function(d){ d.radius = parseFloat(d.dataset[dataPoint]); }) .attr("d", circlePath) - .attr("fill",function(d){ return colorScale(d.dataset[dataPoint]); }); + .attr("fill",function(d){ return colorScale(d.dataset[dataPoint]); }) + .on("mouseover",function(d){ + d3.select(".dotGroup") + .select("."+d3.select(this).attr("class")) + .classed("selected",true); + }) + .on("mouseout",function(d){ + d3.select(".dotGroup") + .select("."+d3.select(this).attr("class")) + .classed("selected",false); + }); dotGroup.selectAll("text") .text(function(d){ return d.dataset[dataPoint]; }) @@ -174,10 +193,23 @@ svg.select(".yAxis").call(yAxis); var states = svg.select(".barGroup").selectAll(".stateBar").data(csv); - var entering = states.enter().append("g").attr("class","stateBar"); + var entering = states.enter().append("g").attr("class","stateBar") + .attr("class",function(d){ + return "state " + getClassName(d.State); + }); states.attr("transform",function(d,i){ return "translate("+xPos(i)+","+(scaleHeight(d[dataPoint])+padding)+")"; + }) + .on("mouseover",function(d){ + d3.select(".dotGroup") + .select("."+d3.select(this).attr("class")) + .classed("selected",true); + }) + .on("mouseout",function(d){ + d3.select(".dotGroup") + .select("."+d3.select(this).attr("class")) + .classed("selected",false); }); entering.append("rect").attr("width",6); @@ -206,6 +238,16 @@ }); } + // regex: + // "South Dakota " + // "south dakota " + // "south dakota" + // "south-dakota" + + function getClassName(name){ + return name.toLowerCase().replace(/^\s+|\s+$/g, '').replace(/\s+/g, '-'); + } + setupData(); displayData(); }); diff --git a/Exercise 2/exercise2_4.html b/Exercise 2/exercise2_4.html index a6aa3a5..41e3c79 100644 --- a/Exercise 2/exercise2_4.html +++ b/Exercise 2/exercise2_4.html @@ -161,7 +161,7 @@ var dotGroup = svg.select(".dotGroup"); dotGroup.selectAll("path") - .each(function(d){ d.radius = parseFloat(d.dataset[dataPoint])}) + .each(function(d){ d.radius = parseFloat(d.dataset[dataPoint]); }) .attr("d", circlePath) .attr("fill",function(d){ return colorScale(d.dataset[dataPoint]); }) .on("mouseenter",function(d){ diff --git a/Exercise 2/exercise2_5.html b/Exercise 2/exercise2_5.html index cacfe3a..330ccc0 100644 --- a/Exercise 2/exercise2_5.html +++ b/Exercise 2/exercise2_5.html @@ -163,7 +163,7 @@ var dotGroup = svg.select(".dotGroup"); dotGroup.selectAll("path") - .each(function(d){ d.radius = parseFloat(d.dataset[dataPoint])}) + .each(function(d){ d.radius = parseFloat(d.dataset[dataPoint]); }) .transition().duration(1000) .attr("d", circlePath) .attr("fill",function(d){ return colorScale(d.dataset[dataPoint]); }) diff --git a/Exercise 2/exercise2_6.html b/Exercise 2/exercise2_6.html index c4574a5..77b57c3 100644 --- a/Exercise 2/exercise2_6.html +++ b/Exercise 2/exercise2_6.html @@ -19,7 +19,7 @@ .stateName { text-anchor: end; font-size: 12px; - baseline-shift: -4px; + baseline-shift: -6px; display: none; } .label { @@ -113,7 +113,8 @@ radius: parseFloat(d[dataPoint]), dataset: d }; - }).attr("fill","#eee");; + }).attr("fill","#eee"); + entering.append("text").datum(function(d){ var stateName = d.State.replace(/^\s+|\s+$/g, ''); return { @@ -148,16 +149,20 @@ var dotGroup = svg.select(".dotGroup"); dotGroup.selectAll("path") - .each(function(d){ d.radius = parseFloat(d.dataset[dataPoint])}) + .each(function(d){ d.radius = parseFloat(d.dataset[dataPoint]); }) .transition().duration(1000) .attr("d", circlePath) .attr("fill",function(d){ return colorScale(d.dataset[dataPoint]); }) dotGroup.selectAll("path") .on("mouseenter",function(d){ + // console.log('hello'); d3.select(".barGroup").select("."+getClassName(d.dataset.State)) .classed("selected",true); - }).on("mouseleave",function(d){ + d3.select(this).call(animate); + }) + // .on("mouseenter",animate); + .on("mouseleave",function(d){ d3.select(".barGroup").select("."+getClassName(d.dataset.State)) .classed("selected",false); }); @@ -171,6 +176,22 @@ updateBarChart(); } + function animate(){ + // console.log('hello'); + d3.select(this).transition() + .ease("bounce") + .duration(1000) + .("fill",'red') + // .attr("opacity",1.0) + // .each("end",secondanimate); + } + // function secondanimate(){ + // d3.select(this).transition() + // .ease("bounce") + // .duration(1000) + // .attr("opacity",0.5); + // } + function updateBarChart() { var dataMax = d3.max(csv, function(d){ return parseFloat(d[dataPoint]); }); var scaleHeight = d3.scale.linear() @@ -188,7 +209,9 @@ return "translate("+xPos(i)+","+(scaleHeight(0)+padding)+")"; }); - states.attr("class",function(d){ return "stateBar "+getClassName(d.State); }) + states.attr("class",function(d){ + return "stateBar "+getClassName(d.State); + }) .transition().duration(1000) .attr("transform",function(d,i){ return "translate("+xPos(i)+","+(scaleHeight(d[dataPoint])+padding)+")"; diff --git a/Exercise 3/exercise3.html b/Exercise 3/exercise3.html index f239868..4734c9a 100644 --- a/Exercise 3/exercise3.html +++ b/Exercise 3/exercise3.html @@ -20,7 +20,7 @@ cursor: pointer; } .button:hover { - background-color: #ff9900; + background-color: #ff0000; } .button.selected { background-color: #ff0099; @@ -58,17 +58,33 @@ .triangle .button:nth-child(even).selected { border-left-color: #000; } + .outline .button { + background-color: white; + border: 2px solid #999; + color: #999; + font-weight: bold; + } + .outline .button:hover { + background-color: #aa6666; + /*padding: 50px;*/ + } + .outline .button.selected { + background-color: #ff0000; + color: #ffffff; + border: 50px solid #ffff00; + /*border-color: #ffff00;*/ + }
-