Skip to content

Instantly share code, notes, and snippets.

@claudialexa
Created February 29, 2016 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save claudialexa/5ec7dbd0ee9065ab0f30 to your computer and use it in GitHub Desktop.
Save claudialexa/5ec7dbd0ee9065ab0f30 to your computer and use it in GitHub Desktop.
Understanding Hitler's Rise to Power: The German Elections of 1919-1933
Date Party Votes Seats
January 19 1919 National Socialist German Workers Party (Nazi Party) 0 0
January 19 1919 Independent Social Democratic Party of Germany 0 0
January 19 1919 Social Democratic Party of Germany 11509048 163
January 19 1919 Communist Party of Germany 0 0
January 19 1919 Centre Party 5980216 91
January 19 1919 German National People's Party 3121479 44
January 19 1919 Bavarian People's Party 0 0
January 19 1919 German People's Party 1345338 19
January 19 1919 Christian Social People's Service 664 0
January 19 1919 German State Party 0 0
January 19 1919 German Farmers' Party 0 0
January 19 1919 Agricultural League 0 0
January 19 1919 Reich Party of the German Middle Class 0 0
January 19 1919 German-Hanoverian Party 77226 1
January 19 1919 Radical Middle Class 0 0
January 19 1919 Christian-National Peasants' and Farmers' Party 0 0
January 19 1919 People's Justice Party 0 0
January 19 1919 Socialist Workers' Party of Germany 0 0
January 19 1920 National Socialist German Workers Party (Nazi Party) 0 0
January 19 1920 Independent Social Democratic Party of Germany 5046813 84
January 19 1920 Social Democratic Party of Germany 6104398 102
January 19 1920 Communist Party of Germany 589545 4
January 19 1920 Centre Party 3845001 64
January 19 1920 German National People's Party 4249100 84
January 19 1920 Bavarian People's Party 1173344 20
January 19 1920 German People's Party 3919446 65
January 19 1920 Christian Social People's Service 0 0
January 19 1920 German State Party 0 0
January 19 1920 German Farmers' Party 0 0
January 19 1920 Agricultural League 0 0
January 19 1920 Reich Party of the German Middle Class 0 0
January 19 1920 German-Hanoverian Party 319108 5
January 19 1920 Radical Middle Class 0 0
January 19 1920 Christian-National Peasants' and Farmers' Party 0 0
January 19 1920 People's Justice Party 0 0
January 19 1920 Socialist Workers' Party of Germany 0 0
May 4 1924 National Socialist German Workers Party (Nazi Party) 36291 0
May 4 1924 Independent Social Democratic Party of Germany 235 0
May 4 1924 Social Democratic Party of Germany 6008905 100
May 4 1924 Communist Party of Germany 3693280 62
May 4 1924 Centre Party 3914379 65
May 4 1924 German National People's Party 5696475 95
May 4 1924 Bavarian People's Party 3693280 62
May 4 1924 German People's Party 2694381 45
May 4 1924 Christian Social People's Service 0 0
May 4 1924 German State Party 0 0
May 4 1924 German Farmers' Party 0 0
May 4 1924 Agricultural League 574939 10
May 4 1924 Reich Party of the German Middle Class 0 0
May 4 1924 German-Hanoverian Party 319792 5
May 4 1924 Radical Middle Class 0 0
May 4 1924 Christian-National Peasants' and Farmers' Party 0 0
May 4 1924 People's Justice Party 0 0
May 4 1924 Socialist Workers' Party of Germany 0 0
December 7 1924 National Socialist German Workers Party (Nazi Party) 0 0
December 7 1924 Independent Social Democratic Party of Germany 98842 0
December 7 1924 Social Democratic Party of Germany 7881041 131
December 7 1924 Communist Party of Germany 2709086 45
December 7 1924 Centre Party 4118849 69
December 7 1924 German National People's Party 6205802 103
December 7 1924 Bavarian People's Party 1134035 19
December 7 1924 German People's Party 3049064 51
December 7 1924 Christian Social People's Service 0 0
December 7 1924 German State Party 0 0
December 7 1924 German Farmers' Party 0 0
December 7 1924 Agricultural League 500525 8
December 7 1924 Reich Party of the German Middle Class 0 0
December 7 1924 German-Hanoverian Party 261549 4
December 7 1924 Radical Middle Class 0 0
December 7 1924 Christian-National Peasants' and Farmers' Party 0 0
December 7 1924 People's Justice Party 0 0
December 7 1924 Socialist Workers' Party of Germany 0 0
September 14 1930 National Socialist German Workers Party (Nazi Party) 6379672 107
September 14 1930 Independent Social Democratic Party of Germany 11690 0
September 14 1930 Social Democratic Party of Germany 8575244 143
September 14 1930 Communist Party of Germany 4590160 77
September 14 1930 Centre Party 4127000 68
September 14 1930 German National People's Party 2457686 41
September 14 1930 Bavarian People's Party 1058637 19
September 14 1930 German People's Party 1577365 30
September 14 1930 Christian Social People's Service 868269 14
September 14 1930 German State Party 1322034 20
September 14 1930 German Farmers' Party 339434 6
September 14 1930 Agricultural League 193926 3
September 14 1930 Reich Party of the German Middle Class 1361762 23
September 14 1930 German-Hanoverian Party 144286 3
September 14 1930 Radical Middle Class 0 0
September 14 1930 Christian-National Peasants' and Farmers' Party 1108043 19
September 14 1930 People's Justice Party 0 0
September 14 1930 Socialist Workers' Party of Germany 0 0
November 6 1932 National Socialist German Workers Party (Nazi Party) 11737021 196
November 6 1932 Independent Social Democratic Party of Germany 0 0
November 6 1932 Social Democratic Party of Germany 7247901 121
November 6 1932 Communist Party of Germany 5980239 100
November 6 1932 Centre Party 423545 70
November 6 1932 German National People's Party 2959053 51
November 6 1932 Bavarian People's Party 1094597 20
November 6 1932 German People's Party 660889 11
November 6 1932 Christian Social People's Service 403666 5
November 6 1932 German State Party 336778 2
November 6 1932 German Farmers' Party 149026 3
November 6 1932 Agricultural League 105220 2
November 6 1932 Reich Party of the German Middle Class 110309 1
November 6 1932 German-Hanoverian Party 63966 1
November 6 1932 Radical Middle Class 60246 0
November 6 1932 Christian-National Peasants' and Farmers' Party 46382 0
November 6 1932 People's Justice Party 46202 0
November 6 1932 Socialist Workers' Party of Germany 45201 0
March 3 1933 National Socialist German Workers Party (Nazi Party) 17277180 288
March 3 1933 Independent Social Democratic Party of Germany 0 0
March 3 1933 Social Democratic Party of Germany 7181629 120
March 3 1933 Communist Party of Germany 4848058 81
March 3 1933 Centre Party 4424905 73
March 3 1933 German National People's Party 0 0
March 3 1933 Bavarian People's Party 1073552 19
March 3 1933 German People's Party 432312 2
March 3 1933 Christian Social People's Service 383999 2
March 3 1933 German State Party 334242 5
March 3 1933 German Farmers' Party 114048 2
March 3 1933 Agricultural League 83839 1
March 3 1933 Reich Party of the German Middle Class 0 0
March 3 1933 German-Hanoverian Party 47743 0
March 3 1933 Radical Middle Class 0 0
March 3 1933 Christian-National Peasants' and Farmers' Party 0 0
March 3 1933 People's Justice Party 0 0
March 3 1933 Socialist Workers' Party of Germany 0 0
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>How Hitler Came to Power: Understanding the German Elections 1919-1933</title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script>
<style type="text/css">
body {
background-color: #ffffff;
font-family: sans-serif;
}
h2 {
margin-left: 30px;
}
p {
margin-left: 30px;
font-size: 11pt;
color: gray;
}
svg {
background-color: white;
}
path {
fill:none;
/* stroke: black;
*/ stroke-width: 2px;
}
.axis path,
.axis line {
fill: none;
stroke: black;
stroke-width: 1px;
shape-rendering: crispEdges;
}
.line {
fill: none;
stroke-opacity: 60%;
stroke-width: 2px;
}
.line.unfocused{
stroke-opacity: 60%;
}
.line.focused {
stroke-width: 4px;
stroke-opacity: 100%;
/* stroke: red;
*/ }
.axis text {
font-family: sans-serif;
font-size: 11px;
}
.tooltip {
position: absolute;
z-index: 10;
}
.tooltip p {
background-color: white;
border: gray 1px solid;
padding: 2px;
min-width: 220px;
}
.xlabel {
font-famile: sans-serif;
font-size: 11px;
color: gray;
}
</style>
</head>
<body>
<h2>How Hitler Came to Power: Understanding the German Elections of 1919-1933</h2>
<p><b>Data Vis</b> by Claudia Aguirre. <b>Data Source:</b> <i>The Weimar Republic</i>, Eberhard Kolb</p>
<p> By the time World War I ended, the Germans had lost millions of lives and were in a deep economic depression. The unrest that followed the end of the war resulted in the overthrow of the empire and the formation of a new government, the Weimar Republic. </p>
<p>This time in German history is remembered by the cultural renaissance of German society; the emergence of cabaret, Bauhaus and the arts. At the same time, it also saw some of the biggest political and economic failures, most highlighted by rampant hyperinflation and ultimately, the government's inability to stop Adolf Hitler from coming to power in 1935. </p>
<p>Leading to that fateful day in 1935, there were more elections and political parties around the country than Germans could count. Many (like the Nazi Party, once named the National Socialist German Workers' Party) appeared one day, died the next and revived in a few months. In following these patterns, historians have been able to understand the state of the German mindset and how the Nazi Party was actually able to get to power.</p>
<script type="text/javascript">
var fullwidth = 1000;
fullheight = 500;
var dateFormat = d3.time.format("%B %d %Y");
var margin = {top: 20, right: 25, bottom: 20, left: 100};
var width = fullwidth- margin.left - margin.right,
height = fullheight - margin.top - margin.bottom;
// How can I access d.Party outside of nest?
// var politicalParties = d3.nest()
// .key(function (d){
// return d.Party;
// })
var xScale = d3.time.scale().range([0, width]);
var yScale = d3.scale.linear().range([0, height]);
var xAxis = d3.svg.axis()
.scale(xScale)
.orient("bottom")
.ticks(13)
.innerTickSize([0]);
var yAxis = d3.svg.axis()
.scale(yScale)
.orient("left")
.innerTickSize([0]);
// Building Lines
var line = d3.svg.line()
.x(function (d) {
return xScale(dateFormat.parse(d.Date));
})
.y(function (d) {
return yScale(+d.Votes);
});
//Create the empty SVG image
var svg = d3.select("body")
.append("svg")
.attr("width", fullwidth)
.attr("height", fullheight)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var tooltip = d3.select("body")
.append("div")
.attr("class", "tooltip");
d3.csv("german_elections_final.csv", function (error,data) {
if (error) {
console.log("error reading file");
}
var dataset = d3.nest()
.key(function (d) {
return d.Party;
})
.sortValues(function (a, b) {
return dateFormat.parse(a.Date) - dateFormat.parse(b.Date)
})
.entries(data);
xScale.domain(
d3.extent(data, function(d) {
return dateFormat.parse(d.Date);
}));
yScale.domain([
d3.max(data, function(d) {
return +d.Votes;
}),
0
]);
var color = d3.scale.category10();
var groups = svg.selectAll("g.lines")
.data(dataset)
.enter()
.append("g")
.attr("class", "lines");
groups.selectAll("path")
.data(function(d) {
return [ d.values ];
})
.enter()
.append("path")
.attr("class", "line")
.style("stroke", function(d) {
return color(d[0].Party); })
.attr("d", line);
var circles = groups.selectAll("circle")
.data(function(d) {
return d.values;
})
.enter()
.append("circle");
circles.attr("cx", function(d) {
return xScale(dateFormat.parse(d.Date));
})
.attr("cy", function(d) {
return yScale(d.Votes);
})
.attr("r", 4)
.style("opacity", 1)
.style("fill", "gray");
circles
.on("mouseover", mouseoverFunc)
.on("mousemove", mousemoveFunc)
.on("mouseout", mouseoutFunc);
// Still need to fix line label ugh
// groups.append("text")
// .attr("x", function(d) {
// if (d.values.length != 0) {
// var lastYear = d.values[d.values.length-1].date;
// return xScale(dateFormat.parse(lastYear));
// }
// })
// .attr("y", function(d) {
// if (Votes.length != 0) {
// var lastAmount = d.Votes[d.Votes.length-1].amount;
// return yScale(+lastAmount);
// }
// })
// .attr("dx", "3px")
// .attr("dy", "3px")
// .text(function(d) {
// if (d.values.length != 0) {
// var lastAmount = d.values[d.values.length-1].amount;
// if (+lastAmount > 700000) {
// return d.Party;
// }
// }
// })
// .attr("class", "linelabel");
//Axes
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.call(yAxis);
svg.append("text")
.attr("class", "ylabel")
.attr("transform","rotate(-90) translate(" + (-height/2) + ",0)")
.style("text-anchor", "middle")
.attr("dy", -80)
.text("Votes");
function mouseoverFunc(d) {
d3.select(this)
.transition()
.style("opacity", 1)
.attr("r", 10);
tooltip
.style("display", null) // this removes the display none setting from it
.html("<p>Party: " + d.Party +
"<br>Year: " + d.Date +
"<br>Votes: " + d.Votes + "</p>");
}
function mousemoveFunc(d) {
tooltip
.style("top", (d3.event.pageY - 10) + "px" )
.style("left", (d3.event.pageX + 10) + "px");
}
function mouseoutFunc(d) {
d3.select(this)
.transition()
.style("opacity", 1)
.attr("r", 4);
tooltip.style("display", "none"); // this sets it to invisible!
}
}); // end of data csv
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment