About MP8: An Extra Credit MP

As announced in lecture, CS 105 is offering an MP8 that can replace any single MP score. Specifically:

Since MP8 is purely extra credit, MP8 is not required. Not completing MP8 will not impact your grade in any way. Since CS 105 uses an absolute grading scale, not getting these extra credit points will not hurt you compared to everyone else (that is, getting to 900 points gets you an A-, no matter how you get there).

This is a solo assignment

As with all MPs in CS 105, this MP is a solo assignment. You should review the academic integrity policy on the course syllabus to understand acceptable ways to get help and help others on this assignment while ensuring that solo work is done. Even though this MP is worth only extra credit, cheating on this MP holds the same penalty of a full letter grade deduction as other MPs.

Introduction

After the 2012 Summer Olympics, The New York Times created a visualization of the gold medal performance of the Men's 100-Meter Sprint that shows how significantly faster athletes have gotten since the first modern Olympic Games. You will be creating a visualization inspired by The Times visualization using the exact same tool as they used, d3.js.

In this MP, you will create the following visualization (though with different data), showing the gold, silver, and bronze medals for at least the most recent ten Olympic games:

Olympic Medal Winners in Men's 100-Meter Sprint

Time (seconds)
20122008200420001996199219881984198019769.79.89.910.010.110.210.3

From this visualization, you can quickly see that any runner winning gold in 1992 or earlier would not have even placed in 2008 or 2012. In this MP, you will gather data about your own sport and plot those medals onto the grid.

The Files

To complete this MP, we have already given you a base setup to work with. You can download the ZIP of these files here. As with all ZIP files in CS 105, you must extract the files into their own directory before working with them.

In completing this MP, you will only need to edit mp8.html. The two JavaScript libraries (d3.js and underscore.js) and CSS file are used by the HTML file and need to stay in the same directory.

Coding the MP: Part 1, The Data

In this MP, you will be working with a sport that is uniquely yours. You must go here to find out your sport (login required). Your data will be different than the sample data we use here.

Within mp8.html, Lines 17-19 contain an empty array that you need to populate with data. The data must be populated to conform to a very specific format:

As an example, the following code shows the first two years of data for the Men's 100-Meter Sprint:

var scores =
[
	[
		{ score: 9.63, medal: "Gold", year: 2012 },
		{ score: 9.75, medal: "Silver", year: 2012 },
		{ score: 9.79, medal: "Bronze", year: 2012 }
	],
	[
		{ score: 9.69, medal: "Gold", year: 2008 },
		{ score: 9.89, medal: "Silver", year: 2008 },
		{ score: 9.91, medal: "Bronze", year: 2008 }
	]
];

Your data must contain at least ten Olympic years worth of Olympic data starting with the most recent Olympics. You can add more than ten years, but at least ten years is required.

Coding the MP: Part 2, The Plot

After filling in the array with the data, when you open mp8.html within a web browser you will see a grid has already been created for you by the code we have provided. You are responsible for plotting the data onto that grid.

20122008200420001996199219881984198019769.79.89.910.010.110.210.3

Approximately 100 lines further down in the file, you will find a block of code similar to what you saw in lecture on Wednesday, Dec. 3rd, and includes a "PART 2" comment block:

// Draw the data!
svg.selectAll("circle")
   .data(scores)
   .enter()
   .append("g")
   .selectAll("circle")
   .data(function (d, i) { return d; })
   .enter()
   // ==[ PART 2 ]==
   


   // ==[ END of PART 2 ]==

Inside of the "PART 2" block, you must fill in a series of chaining functions that will draw circles for each piece of data. Since we have used the .enter() command, d3.js will run your code once for every single piece of data you entered. That means we will only append a circle once, as that action of appending a circle is going to be repeated for every data point.

Since we want to draw a circle for each data point, you must use a .append("circle") as your first chained function. In d3, a circle is defined by three key attributes:

Additionally, there are three other attributes you will set for each circle:

It is up to you to determine the cx, cy, fill, and stroke attributes based on the values of the data. However, to make your points fit nicely on the grid that was provided for you, you should use a radius of 5 and a stroke-width of 2.

In order to tell d3.js the values of cx and others, you must use the attr()-chaining function. This function takes a function as its parameter and lets you write JavaScript that must return the value you want for the given attribute. An example attr() function call is as follows:

.attr("cy", function (d, i) {
   return 30;
})

In the code above, the code always returns 30. You will need to modify this function to return the correct values, though both r and stroke-width do return static values so they should be really easy!

The values that should be returned, and things to consider as you come up with the formulas, are:

You should complete Part 2 of your MP, which requires filling in several attr() functions inside of the "PART 2" area. The following shows a bit of how to get started:

// Draw the data!
svg.selectAll("circle")
   .data(scores)
   .enter()
   .append("g")
   .selectAll("circle")
   .data(function (d, i) { return d; })
   .enter()
   // ==[ PART 2 ]==
   .append("circle")
   .attr("r", function (d, i) {
      return 5;
   })
   ... more attr() functions ...
   // ==[ END of PART 2 ]==

Explore!

Once you have finished Part 2, feel free to explore d3 and make the visualization even better! So long as each medal is shown in the right color in a way that shows how the scores compare, you will earn full credit. Doing more won't get you extra, extra credit, but if you do make your visualization even more awesome than what is required let me know (waf@) so I can check it out! (If you add more js/css, just keep it all within the HTML file as you can only submit one file.)

A few ideas:

Grading

There is no partial credit on this assignment. To earn full credit, you must have at least ten years of data plotted on the SVG in the correct location with the correct medal color for the sport that was assigned to you.

Submission

Upload your submission here.