Initial commit
This commit is contained in:
commit
47b708f720
5 changed files with 905 additions and 0 deletions
53
src/Table.pde
Executable file
53
src/Table.pde
Executable file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
Adapted from: http://benfry.com/writing/map/Table.pde
|
||||
See also Visualizing Data, Ben Fry, O'Reilly, 2008 (p32)
|
||||
*/
|
||||
|
||||
// Customised Table class to allow processing of data (csv format)
|
||||
class Table {
|
||||
String[][] data; // set up 2 dimensional array for data
|
||||
int rowCount; // number of rows in table
|
||||
|
||||
// constructor method taking filename (of data file) as param
|
||||
Table(String filename) {
|
||||
String[] rows = loadStrings(filename); // load in data as array of Strings
|
||||
data = new String[rows.length][]; // set number of rows for data array
|
||||
char separator = ','; // set commas as default separator
|
||||
|
||||
// loop through each line of data
|
||||
for (int i = 0; i < rows.length; i++) {
|
||||
if (trim(rows[i]).length() == 0)
|
||||
continue; // skip empty rows
|
||||
if (rows[i].startsWith("#"))
|
||||
continue; // skip comment lines
|
||||
|
||||
// split the text at every separator character
|
||||
String[] pieces = split(rows[i], separator);
|
||||
data[rowCount] = pieces; // add data to the data array
|
||||
rowCount++;
|
||||
}
|
||||
// resize data array in case rows remain unused
|
||||
data = (String[][]) subset(data, 0, rowCount);
|
||||
}
|
||||
|
||||
// return the row count (number of rows of data)
|
||||
int getRowCount() {
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
// return the String from the given row/column, minus any double quotes
|
||||
String getString(int row, int column) {
|
||||
return data[row][column].replace("\"", ""); // remove double quotes
|
||||
}
|
||||
|
||||
// if expecting an int, return String from row/column as int
|
||||
int getInt(int row, int column) {
|
||||
return parseInt(getString(row, column));
|
||||
}
|
||||
|
||||
// if expecting a float, return String from row/column as float
|
||||
float getFloat(int row, int column) {
|
||||
return parseFloat(getString(row, column));
|
||||
}
|
||||
|
||||
}
|
96
src/WarsVisualisation.pde
Executable file
96
src/WarsVisualisation.pde
Executable file
|
@ -0,0 +1,96 @@
|
|||
// WarsVisualisation.pde - plots wars sized by casualties along a timeline 1800--2000
|
||||
|
||||
String data_src = "wars.csv"; // the data file to be used
|
||||
Table warTable; // declare table object to hold data (see class Table)
|
||||
int rowCount; // to store how many rows there are in the table
|
||||
|
||||
color col1 = #0000ff; // use blue as start of range for lerpColor function
|
||||
color col2 = #ff0000; // use green as end of range for lerpColor function
|
||||
int dataMin = MAX_INT; // for holding the max and min death counts
|
||||
int dataMax = MIN_INT;
|
||||
float ratio; // for holding the ratio between max and min
|
||||
|
||||
void setup() {
|
||||
size(1840, 600); // set up sketch display window
|
||||
background(#000000); // set background to black
|
||||
|
||||
warTable = new Table(data_src); // create new table from data file
|
||||
rowCount = warTable.getRowCount();
|
||||
|
||||
PFont font;
|
||||
font = createFont("Arial",16,true);
|
||||
textFont(font, 32);
|
||||
fill(#ffffff);
|
||||
|
||||
// draws the two horizontal lines
|
||||
stroke(#ffffff);
|
||||
line(20,200,1820,200);
|
||||
line(20,400,1820,400);
|
||||
int labelY1 = 190;
|
||||
int labelY2 = 390;
|
||||
// draws the vertical incremental lines
|
||||
for(int div = 20, year = 1800; div <= 1823; div = div + 9, year++) {
|
||||
textAlign(CENTER);
|
||||
textSize(8);
|
||||
line(div,197,div,203);
|
||||
line(div,397,div,403);
|
||||
if (year % 2 == 0) {
|
||||
text(year,div,labelY1);
|
||||
if (labelY1 == 190) labelY1 = 215;
|
||||
else labelY1 = 190;
|
||||
text(year,div,labelY2);
|
||||
if (labelY2 == 390) labelY2 = 415;
|
||||
else labelY2 = 390;
|
||||
}
|
||||
textAlign(LEFT) ;
|
||||
textSize(14);
|
||||
text("Wars 1800--2000, sized by # of deaths", 20, 160);
|
||||
text("Wars 1800--2000, coloured by # of deaths", 20, 360);
|
||||
}
|
||||
|
||||
// loop through each row of data
|
||||
// ignoring row 0, the 'header'
|
||||
for(int row = 1; row < rowCount; row++) {
|
||||
int deaths = warTable.getInt(row, 15);
|
||||
|
||||
if (deaths > dataMax)
|
||||
dataMax = deaths;
|
||||
if (deaths < dataMin)
|
||||
dataMin = deaths;
|
||||
ratio = dataMax/dataMin;
|
||||
}
|
||||
|
||||
int yrBeg, yrEnd, deaths;
|
||||
int offset = 0;
|
||||
|
||||
// populates the values for the wars
|
||||
for(int row = 1; row < rowCount; row++) {
|
||||
yrBeg = warTable.getInt(row, 2);
|
||||
yrEnd = warTable.getInt(row, 5);
|
||||
deaths = warTable.getInt(row, 15);
|
||||
float percent = norm(deaths, dataMin, dataMax);
|
||||
float newPercent = lerp(0,500,percent);
|
||||
// draws the sized top line values
|
||||
stroke(200,50);
|
||||
strokeWeight(newPercent);
|
||||
line(yearToLine(yrBeg), 200, yearToLine(yrEnd), 200);
|
||||
|
||||
// colours the bottom line values
|
||||
stroke(lerpColor(#61e2f0, #296f34, percent, HSB));
|
||||
strokeWeight(5);
|
||||
line(yearToLine(yrBeg), 400, yearToLine(yrEnd), 400);
|
||||
|
||||
// adds a label for the war, with an offset
|
||||
// that means no labels overlap
|
||||
textSize(9);
|
||||
text(warTable.getString(row, 1), yearToLine(yrBeg), 440+offset);
|
||||
offset = offset + 10;
|
||||
if (offset == 100) offset = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// converts a year to an x-coord
|
||||
int yearToLine(int year) {
|
||||
return (year - 1800)*9;
|
||||
}
|
2
src/data/LICENSE
Executable file
2
src/data/LICENSE
Executable file
|
@ -0,0 +1,2 @@
|
|||
The dataset is from the Correlates of War project (Sarkees, Reid & Wayman) and
|
||||
can be found at <https://correlatesofwar.org/data-sets/COW-war>.
|
80
src/data/wars.csv
Executable file
80
src/data/wars.csv
Executable file
|
@ -0,0 +1,80 @@
|
|||
WarNo,WarName,YrBeg1,MonBeg1,DayBeg1,YrEnd1,MonEnd1,DayEnd1,YrBeg2,MonBeg2,DayBeg2,YrEnd2,MonEnd2,DayEnd2,Duration,Deaths,CenSubSy,SubSysEa,MajPowIn,MajPowEa,WestHem,Europe,Africa,MidEast,Asia,Oceania,Edition,Version
|
||||
1,Franco-Spanish,1823,4,7,1823,11,13,-999,-999,-999,-999,-999,-999,221,1000,1,1,1,0,0,1,0,0,0,0,0,3
|
||||
4,Russo-Turkish,1828,4,26,1829,9,14,-999,-999,-999,-999,-999,-999,507,130000,1,1,1,0,0,1,0,1,0,0,0,3
|
||||
7,Mexican-American,1846,5,12,1848,2,2,-999,-999,-999,-999,-999,-999,632,19283,0,0,0,0,1,0,0,0,0,0,0,3
|
||||
10,Austro-Sardinian,1848,3,24,1848,8,9,1849,3,20,1849,3,23,143,7527,1,1,1,0,0,1,0,0,0,0,0,3
|
||||
13,First Schleswig-Holstein,1848,4,10,1848,8,26,1849,3,25,1849,7,10,247,6000,1,1,1,0,0,1,0,0,0,0,0,3
|
||||
16,Roman Republic,1849,5,8,1849,7,1,-999,-999,-999,-999,-999,-999,55,2600,1,0,1,0,0,1,0,0,0,0,0,3
|
||||
19,La Plata,1851,7,19,1852,2,3,-999,-999,-999,-999,-999,-999,200,1300,0,0,0,0,1,0,0,0,0,0,0,3
|
||||
22,Crimean,1853,10,23,1856,3,1,-999,-999,-999,-999,-999,-999,861,264200,1,1,1,1,0,1,0,0,0,0,0,3
|
||||
25,Anglo-Persian,1856,10,25,1857,3,14,-999,-999,-999,-999,-999,-999,141,2000,1,0,1,0,0,0,0,1,0,0,0,3
|
||||
28,Italian Unification,1859,4,29,1859,7,12,-999,-999,-999,-999,-999,-999,75,22500,1,1,1,1,0,1,0,0,0,0,0,3
|
||||
31,Spanish-Moroccan,1859,10,22,1860,3,25,-999,-999,-999,-999,-999,-999,156,10000,1,0,0,0,0,0,0,1,0,0,0,3
|
||||
34,Italo-Roman,1860,9,11,1860,9,29,-999,-999,-999,-999,-999,-999,19,1000,1,0,1,0,0,1,0,0,0,0,0,3
|
||||
37,Italo-Sicilian,1860,10,15,1861,1,19,-999,-999,-999,-999,-999,-999,97,1000,1,0,1,0,0,1,0,0,0,0,0,3
|
||||
40,Franco-Mexican,1862,4,16,1867,2,5,-999,-999,-999,-999,-999,-999,1757,20000,1,0,1,0,1,0,0,0,0,0,0,3
|
||||
43,Ecuadorian-Columbian,1863,11,22,1863,12,6,-999,-999,-999,-999,-999,-999,15,1000,0,0,0,0,1,0,0,0,0,0,0,3
|
||||
46,Second Schleswig-Holstein,1864,2,1,1864,4,25,1864,6,25,1864,7,20,111,4500,1,1,1,0,0,1,0,0,0,0,0,3
|
||||
49,Lopez,1864,11,12,1870,3,1,-999,-999,-999,-999,-999,-999,1936,310000,0,0,0,0,1,0,0,0,0,0,0,3
|
||||
52,Spanish-Chilean,1865,10,25,1866,5,9,-999,-999,-999,-999,-999,-999,197,1000,1,0,0,0,1,0,0,0,0,0,0,3
|
||||
55,Seven Weeks,1866,6,15,1866,7,26,-999,-999,-999,-999,-999,-999,42,44100,1,1,1,1,0,1,0,0,0,0,0,3
|
||||
58,Franco-Prussian,1870,7,19,1871,2,26,-999,-999,-999,-999,-999,-999,223,204313,1,1,1,1,0,1,0,0,0,0,0,3
|
||||
60,First Central American,1876,3,27,1876,4,25,-999,-999,-999,-999,-999,-999,30,4000,0,0,0,0,1,0,0,0,0,0,4,3
|
||||
61,Russo-Turkish,1877,4,12,1878,1,3,-999,-999,-999,-999,-999,-999,267,285000,1,1,1,0,0,1,0,1,0,0,0,3
|
||||
64,Pacific,1879,2,14,1883,12,11,-999,-999,-999,-999,-999,-999,1762,14000,0,0,0,0,1,0,0,0,0,0,0,3
|
||||
65,Anglo-Egyptian,1882,7,11,1882,9,15,-999,-999,-999,-999,-999,-999,67,2232,1,0,1,0,0,0,0,1,0,0,4,3
|
||||
67,Sino-French,1884,8,23,1885,6,9,-999,-999,-999,-999,-999,-999,291,12100,1,0,1,0,0,0,0,0,1,0,0,3
|
||||
70,Second Central American,1885,3,28,1885,4,15,-999,-999,-999,-999,-999,-999,19,1000,0,0,0,0,1,0,0,0,0,0,0,3
|
||||
72,Franco-Thai,1893,7,13,1893,8,3,-999,-999,-999,-999,-999,-999,22,1000,1,0,1,0,0,0,0,0,1,0,3,3
|
||||
73,First Sino-Japanese,1894,8,1,1895,3,30,-999,-999,-999,-999,-999,-999,242,15000,0,0,0,0,0,0,0,0,1,0,0,3
|
||||
76,Greco-Turkish,1897,2,15,1897,5,19,-999,-999,-999,-999,-999,-999,94,2000,1,1,0,0,0,1,0,0,0,0,0,3
|
||||
79,Spanish-American,1898,4,21,1898,8,12,-999,-999,-999,-999,-999,-999,114,3685,1,0,0,0,1,0,0,0,0,0,0,3
|
||||
82,Boxer Rebellion,1900,6,17,1900,8,14,-999,-999,-999,-999,-999,-999,59,3003,1,1,1,0,0,0,0,0,1,0,1,3
|
||||
83,Sino-Russian,1900,8,17,1900,10,10,-999,-999,-999,-999,-999,-999,55,4000,1,1,1,0,0,0,0,0,1,0,4,3
|
||||
85,Russo-Japanese,1904,2,8,1905,9,15,-999,-999,-999,-999,-999,-999,586,151831,1,1,1,1,0,0,0,0,1,0,0,3
|
||||
88,Third Central American,1906,5,27,1906,7,20,-999,-999,-999,-999,-999,-999,55,1000,0,0,0,0,1,0,0,0,0,0,0,3
|
||||
91,Fourth Central American,1907,2,19,1907,4,23,-999,-999,-999,-999,-999,-999,64,1000,0,0,0,0,1,0,0,0,0,0,0,3
|
||||
94,Second Spanish-Moroccan,1909,7,7,1910,3,23,-999,-999,-999,-999,-999,-999,260,10000,1,0,0,0,0,0,0,1,0,0,0,3
|
||||
97,Italo-Turkish,1911,9,29,1912,10,18,-999,-999,-999,-999,-999,-999,386,20000,1,1,1,0,0,0,0,1,0,0,0,3
|
||||
100,First Balkan,1912,10,17,1913,4,19,-999,-999,-999,-999,-999,-999,185,82000,1,1,0,0,0,1,0,1,0,0,0,3
|
||||
103,Second Balkan,1913,6,30,1913,7,30,-999,-999,-999,-999,-999,-999,31,60500,1,1,0,0,0,1,0,0,0,0,0,3
|
||||
106,World War I,1914,7,29,1918,11,11,-999,-999,-999,-999,-999,-999,1567,8578031,1,1,1,1,0,1,1,1,1,0,0,3
|
||||
109,Russo-Polish,1919,2,14,1920,10,18,-999,-999,-999,-999,-999,-999,613,100000,1,1,0,0,0,1,0,0,0,0,1,3
|
||||
112,Hungarian-Allies,1919,4,16,1919,8,4,-999,-999,-999,-999,-999,-999,111,11000,1,1,0,0,0,1,0,0,0,0,0,3
|
||||
115,Greco-Turkish,1919,5,5,1922,10,11,-999,-999,-999,-999,-999,-999,1256,50000,1,1,0,0,0,1,0,1,0,0,0,3
|
||||
116,Franco-Turkish,1919,11,1,1921,10,20,-999,-999,-999,-999,-999,-999,720,40000,1,1,1,0,0,0,0,1,0,0,3,3
|
||||
117,Lithuanian-Polish,1920,7,15,1920,12,1,-999,-999,-999,-999,-999,-999,140,1000,1,1,0,0,0,1,0,0,0,0,3,3
|
||||
118,Sino-Soviet,1929,8,17,1929,12,3,-999,-999,-999,-999,-999,-999,109,3200,0,0,1,0,0,0,0,0,1,0,1,3
|
||||
121,Second Sino-Japanese,1931,12,19,1933,5,6,-999,-999,-999,-999,-999,-999,505,60000,0,0,1,0,0,0,0,0,1,0,0,3
|
||||
124,Chaco,1932,6,15,1935,6,12,-999,-999,-999,-999,-999,-999,1093,92661,0,0,0,0,1,0,0,0,0,0,0,3
|
||||
125,Saudi-Yemeni,1934,3,20,1934,5,13,-999,-999,-999,-999,-999,-999,55,2100,0,0,0,0,0,0,0,1,0,0,4,3
|
||||
127,Italo-Ethiopian,1935,10,3,1936,5,9,-999,-999,-999,-999,-999,-999,220,20000,0,0,1,0,0,0,1,0,0,0,0,3
|
||||
130,Third Sino-Japanese,1937,7,7,1941,12,7,-999,-999,-999,-999,-999,-999,1615,1000000,0,0,1,0,0,0,0,0,1,0,0,3
|
||||
133,Changkufeng,1938,7,29,1938,8,11,-999,-999,-999,-999,-999,-999,14,1726,0,0,1,1,0,0,0,0,1,0,1,3
|
||||
136,Nomonhan,1939,5,11,1939,9,16,-999,-999,-999,-999,-999,-999,129,28000,0,0,1,1,0,0,0,0,1,0,0,3
|
||||
139,World War II,1939,9,1,1945,8,14,-999,-999,-999,-999,-999,-999,2175,16634907,0,0,1,1,0,1,1,1,1,1,0,3
|
||||
142,Russo-Finnish,1939,11,30,1940,3,12,-999,-999,-999,-999,-999,-999,104,74900,0,0,1,0,0,1,0,0,0,0,0,3
|
||||
145,Franco-Thai,1940,12,1,1941,1,22,-999,-999,-999,-999,-999,-999,53,1400,0,0,1,0,0,0,0,0,1,0,1,3
|
||||
147,First Kashmir,1948,7,17,1949,1,1,-999,-999,-999,-999,-999,-999,169,2000,0,0,0,0,0,0,0,0,1,0,4,3
|
||||
148,Palestine,1948,5,15,1948,7,18,1948,10,22,1949,1,7,143,8000,0,0,0,0,0,0,0,1,0,0,0,3
|
||||
151,Korean,1950,6,24,1953,7,27,-999,-999,-999,-999,-999,-999,1130,909833,0,0,1,1,0,0,0,0,1,0,0,3
|
||||
154,Russo-Hungarian,1956,10,23,1956,11,14,-999,-999,-999,-999,-999,-999,23,4002,0,0,1,0,0,1,0,0,0,0,0,3
|
||||
157,Sinai,1956,10,29,1956,11,6,-999,-999,-999,-999,-999,-999,9,3221,0,0,1,0,0,0,0,1,0,0,0,3
|
||||
160,Assam,1962,10,20,1962,11,22,-999,-999,-999,-999,-999,-999,34,1853,0,0,1,0,0,0,0,0,1,0,0,3
|
||||
163,Vietnamese,1965,2,7,1975,4,30,-999,-999,-999,-999,-999,-999,3735,1021442,0,0,1,0,0,0,0,0,1,0,1,3
|
||||
166,Second Kashmir,1965,8,5,1965,9,23,-999,-999,-999,-999,-999,-999,50,7061,0,0,0,0,0,0,0,0,1,0,0,3
|
||||
169,Six Day,1967,6,5,1967,6,10,-999,-999,-999,-999,-999,-999,6,19600,0,0,0,0,0,0,0,1,0,0,1,3
|
||||
172,Israeli-Egyptian,1969,3,6,1970,8,7,-999,-999,-999,-999,-999,-999,520,5368,0,0,0,0,0,0,0,1,0,0,1,3
|
||||
175,Football,1969,7,14,1969,7,18,-999,-999,-999,-999,-999,-999,5,1900,0,0,0,0,1,0,0,0,0,0,1,3
|
||||
178,Bangladesh,1971,12,3,1971,12,17,-999,-999,-999,-999,-999,-999,15,11000,0,0,0,0,0,0,0,0,1,0,1,3
|
||||
181,Yom Kippur,1973,10,6,1973,10,24,-999,-999,-999,-999,-999,-999,19,16401,0,0,0,0,0,0,0,1,0,0,1,3
|
||||
184,Turco-Cypriot,1974,7,20,1974,7,29,1974,8,14,1974,8,16,13,1500,0,0,0,0,0,1,0,0,0,0,1,3
|
||||
187,Vietnamese-Cambodian,1975,5,1,1979,1,7,-999,-999,-999,-999,-999,-999,1348,8000,0,0,0,0,0,0,0,0,1,0,3,3
|
||||
189,Ethiopian-Somalian,1977,8,1,1978,3,14,-999,-999,-999,-999,-999,-999,226,6000,0,0,0,0,0,0,1,0,0,0,2,3
|
||||
190,Ugandan-Tanzanian,1978,10,30,1979,4,12,-999,-999,-999,-999,-999,-999,165,3000,0,0,0,0,0,0,1,0,0,0,1,3
|
||||
193,Sino-Vietnamese,1979,2,17,1979,3,10,-999,-999,-999,-999,-999,-999,22,21000,0,0,1,0,0,0,0,0,1,0,1,3
|
||||
199,Iran-Iraq,1980,9,22,1988,8,20,-999,-999,-999,-999,-999,-999,2890,1250000,0,0,0,0,0,0,0,1,0,0,1,3
|
||||
202,Falklands,1982,3,25,1982,6,20,-999,-999,-999,-999,-999,-999,88,910,0,0,1,0,1,0,0,0,0,0,2,3
|
||||
205,Israel-Syria (Lebanon),1982,4,21,1982,9,5,-999,-999,-999,-999,-999,-999,138,1235,0,0,0,0,0,0,0,1,0,0,2,3
|
||||
208,Sino-Vietnamese,1987,1,5,1987,2,6,-999,-999,-999,-999,-999,-999,33,4000,0,0,1,0,0,0,0,0,1,0,2,3
|
||||
211,Gulf War,1990,8,2,1991,4,11,-999,-999,-999,-999,-999,-999,253,26343,0,0,1,0,0,0,0,1,0,0,3,3
|
|
Reference in a new issue