Skip to content

Instantly share code, notes, and snippets.

@claudialexa
Last active February 23, 2016 03:42
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/1d4ab6becaf9278f4c0a to your computer and use it in GitHub Desktop.
Save claudialexa/1d4ab6becaf9278f4c0a to your computer and use it in GitHub Desktop.
A sooon to be Line Chart: Elections in the Weimar Republic
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Crazy Elections: Weimar Germany</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;
}
h1 {
margin-left: 30px;
}
p {
margin-left: 30px;
font-size: 11pt;
color: gray;
}
svg {
background-color: white;
}
.axis path,
.axis line {
fill: none;
stroke: black;
stroke-width: 1px;
}
.line {
fill: none;
stroke: gray;
stroke-width: 1px;
stroke-opacity: 80%;
}
.axis text {
font-family: sans-serif;
font-size: 11px;
}
.xlabel {
font-famile: sans-serif;
font-size: 11px;
color: gray;
}
</style>
</head>
<body>
<h1>Crazy Elections: Weimar Germany</h3>
<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 ulatimately, 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 margin = {top: 20, right: 25, bottom: 20, left: 80};
var width = fullwidth- margin.left - margin.right;
var height = fullheight - margin.top - margin.bottom;
var dateFormat = d3.time.format("%m/%d/%Y");
var xScale = d3.time.scale().range([0, width]);
var yScale = d3.scale.linear().range([0, height]);
// var widthScale = d3.scale.linear().range ([0, width]);
// var heightScale = d3.scale.ordinal().rangeRoundBands([margin.top, height], 0.2);
var xAxis = d3.svg.axis()
.scale(xScale)
.orient("bottom")
.ticks(15)
.tickFormat(function(d)
{
return dateFormat(d);
})
.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);
})
.interpolate("basis");
//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 + ")");
d3.csv("weimar_elections.csv", function(data) {
var years = ["December 7 1924", "January 19 1919", "January 19 1920", "January 19 1921", "January 19 1922", "January 19 1923", "January 19 1924", "July 31 1932", "June 6 1920", "March 3 1933", "May 20 1928", "May 4 1924", "November 6 1932", "September 14 1930"];
var dataset = [];
data.forEach(function (d, i) {
var myVotes = [];
years.forEach(function (y) {
if (d[y]){
myVotes.push({
year: y,
amount: d[y]
});
}
});
dataset.push({
party: d.Party, votes: myVotes
});
});
xScale.domain(
d3.extent(years, function(d) {
return dateFormat.parse(d);
}));
yScale.domain([
d3.max(dataset, function(d) {
return d3.max(d.votes, function(d) {
return +d.amount;
});
}),
0
]);
var groups = svg.selectAll("g")
.data(dataset)
.enter()
.append("g");
groups.append("title")
.text(function(d) {
return d.Party;
});
groups.selectAll("path")
.data(function(d) { //
return [ d.votes ];
})
.enter()
.append("path")
.attr("class", "line")
.attr("d", line);
//Axes
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.call(yAxis);
});
</script>
</body>
</html>
Party December 7 1924 January 19 1919 January 19 1920 January 19 1921 January 19 1922 January 19 1923 January 19 1924 July 31 1932 June 6 1920 March 3 1933 May 20 1928 May 4 1924 November 6 1932 September 14 1930
Agricultural League 500525 0 0 0 0 0 0 96851 0 83839 0 574939 105220 193926
Bavarian Peasants' League 0 0 0 0 0 0 275125 0 218596 0 0 0 0 0
Bavarian People's Party 1134035 0 0 0 0 0 0 1192684 1173344 1073552 945644 946648 1094597 1058637
Black-White-Red Struggle Front (DNVP)[a] 0 0 0 0 0 0 0 0 0 3136760 0 0 0 0
Centre Party 4118849 0 5980216 0 0 0 0 4589430 3845001 4424905 3712152 3914379 4230545 4127000
Christian Social People's Service 0 0 0 0 0 0 0 364543 0 383999 0 0 403666 868269
Christian-National Peasants' and Farmers' Party 0 0 0 0 0 0 0 0 0 0 571891 0 46382 1108043
Communist Party of Germany 2709086 0 0 0 0 0 0 5282636 589454 4848058 3264793 3693280 5980239 4590160
Economic Party of the German Middle Class 692963 0 0 0 0 0 0 0 0 0 0 500820 0 0
For Hindenberg and Pope 0 0 0 0 0 0 0 0 0 0 0 0 27752 0
German Country People 0 0 0 0 0 0 0 90554 0 0 0 0 0 0
German Democratic Party 1919829 0 0 5641825 0 0 0 0 2333741 0 1479374 1655129 0 0
German Farmers' Party 0 0 0 0 0 0 0 137133 0 114048 481254 0 149026 339434
German National People's Party 6205802 0 0 0 3121479 0 0 2178024 4249100 0 4381563 5696475 2959053 2457686
German People's Party 3049064 0 0 0 0 1345638 0 436002 3919446 432312 2679703 2694381 660889 1577365
German Reform Party 0 0 0 0 0 0 0 59 0 0 0 0 352 0
German Social Monarchist Party 0 0 0 0 0 0 0 0 0 0 0 0 355 0
German State Party 0 0 0 0 0 0 0 371800 0 334242 0 0 336447 1322034
German Workers Party 0 0 0 0 0 0 0 257 0 0 0 0 308 0
German-Hanoverian Party 261549 0 0 0 0 0 0 0 319108 47743 0 319792 63966 144286
Haus- und Landwirtepartei 0 0 0 0 0 0 0 0 0 0 0 0 461 0
Independent Social Democratic Party of Germany 0 0 0 0 0 0 0 0 5046813 0 0 0 0 0
National Socialist Freedom Movement 907242 0 0 0 0 0 0 0 0 0 0 1918329 0 0
National Socialist German Workers Party 0 0 0 0 0 0 0 13745680 0 17277180 810127 0 11737021 6379672
Nationalist Party 0 0 0 0 0 0 0 0 0 0 0 0 588 0
Party against Alcohol 0 0 0 0 0 0 0 0 0 0 0 0 0 1171
People's Justice Party 0 0 0 0 0 0 0 0 0 0 0 0 46202 0
People's Socialists 0 0 0 0 0 0 0 0 0 0 0 0 518 0
Radical Middle Class 0 0 0 0 0 0 0 0 0 0 0 0 60246 0
Reich Party for Civil Rights and Deflation/Christian Social Reich Party 0 0 0 0 0 0 0 0 0 0 0 0 0 271291
Reich Party of the German Middle Class 0 0 0 0 0 0 0 146876 0 0 1387602 0 110309 1361762
Social Democratic Party 7881041 11509048 0 0 0 0 0 0 6104398 0 9152979 6008905 0 8575244
Social Democratic Party of Germany 0 0 0 0 0 0 0 7959712 0 7181629 0 0 7247901 0
Socialist Struggle Community 0 0 0 0 0 0 0 0 0 3954 0 0 0 0
Socialist Workers' Party of Germany 0 0 0 0 0 0 0 72630 0 0 0 0 45201 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment