Innovation Session: The History of NFL Win Percentages – Part 3
Two charts that I’ve drawn inspiration from as I’ve been working on this are the New York Times housing prices graphic and the Feathersquare chart of Oxford Summer Eight” bump race results. The first is beautiful and second is fairly contextually similar. Hopefully this NFL graphic can hold a candle to them when it is all done.
One idea I had was to have the color of each team’s line be one of the team’s official colors. I was hoping to be able to pull this in from a centralized source so I could change colors if the graph was too noisy. This is important enough that I figured I should make sure it would work before getting too far down any path. I had gotten the Falcons & Sains colors to work last week by using a CSS color name, but didn’t really want to have to do that for every team – I was hoping I could use the hex color code instead.
It turns out that is really easy. The line can be defined by a hex, color name or RGB numbers. Knowing that, all I would have to do is build out a CSV with each team name a color code. I could then reference this CSV later.
Getting the colors would be another story, I thought I would have to go to each team’s site & either look for it in a press kit section – or download their logo and use photoshop to get the color. Turns out someone else already did this. I love the internet. Someone built a handy website that has all of the NFL team colors hex codes. Piece of cake. Because I’m only planning on using one color for each team, I went through and picked the most distinguishable one for each team.
Today’s sessions could best be described as three hours of trying to get something to work only to realize that it would never work that way and then a few minutes of clarity in which a lot got done. Programming seems to go like that a lot & the pacing is always discomforting to me.
After finishing that I set out to get a simplified function to show each team’s line. D3 makes it really easy to make a graph using a CSV using the d3.csv() functionality. If each row of the CSV is a unique object, you can quickly create a scatter plot, bar graph, etc, using information in the columns to visualize the object.
It turns out that isn’t as easy to do when each row is part of a series that is grouped by one of the columns. I figured I would have to refactor the code to get something to work. My initial idea was to load the data using d3.csv() then outside of that function, do the charting by calling back into it for each team.
I eventually realized that d3.csv() is asynchronous and can not be used to define a global variable. I have to everything inside of that function. So I got rid of everything I had been trying and started back where I was last week.
I got things working by charting off of a new array I call AllTeamData which holds an array for each teams data. I am still manually adding each team to it right now – figuring out how to automatically do that is the next challenge.
More Team Data
It is also fairly interesting to look back that far and realize how different football was. I had to make a few decisions about what to include. Teams changed names, moved and there were some years where teams combined because neither had enough players due to the great war.
Finally, thanks to the way I’ve grouped and charted the lines I was able to add some interaction to the chart finally. I lost the team colors in the process, but hopefully I can get those back next week.
If you look now you’ll be able to see a bunch of grey lines, each of which turns blue when you hover on it.
See it yourself here: NFL Win Percentages
Check out the code on Github: NFL Win Percentages
Can you guess what the four teams currently charted are based on the data? (Note to self – add labels)