Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created December 5, 2012 15:33
Show Gist options
  • Save zeffii/4216593 to your computer and use it in GitHub Desktop.
Save zeffii/4216593 to your computer and use it in GitHub Desktop.
olympic data_bar
{"description":"olympic data_bar","endpoint":"","display":"svg","public":true,"require":[],"tab":"edit","display_percent":0.49083150531848846,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01}
var svg = d3.select("svg");
var data = tributary.olympics;
// console.log(data);
var rects = svg.selectAll("rect")
.data(data)
/*
2010_population: 1224615000
2011_GDP: 1847980000000
*/
// population log(n) 2010
rects.enter().append("rect")
.attr("width", 14)
.attr("height", function(d,i){
console.log(d);
return Math.log(d['2010_population'])*12;
})
.attr("x", function(d,i){
return 20 + 20*i;
})
.attr("y", 316)
.attr("transform", "scale("+[1, -1]+") translate("+[24, -662]+")")
.style("fill", "#726E8D")
.style("fill-opacity", 0.22)
.style("stroke", "#858585")
.style("stroke-width", 1);
// GDP 2011
rects.enter().append("rect")
.attr("width", 14)
.attr("height", function(d,i){
console.log(d);
return Math.log(d['2011_GDP'])*7;
})
.attr("x", function(d,i){
return 20 + 20*i;
})
.attr("y", 316)
.attr("transform", "translate("+[24,30]+")")
.style("fill", "#11AAC7")
.style("fill-opacity", 0.22)
.style("stroke", "#858585")
.style("stroke-width", 1);
/*
Bronze_medals: 4
Country_name: "India"
Gold_medals: 0
ISO_country_code: "IND"
Silver_medals: 2
*/
// Female_count
var person_lambda = 37
rects.enter().append("rect")
.attr("width", 7)
.attr("height", function(d,i){
console.log(d);
return Math.log(d['Female_count'])*person_lambda;
})
.attr("x", function(d,i){
return 20 + 20*i;
})
.attr("y", 316)
.attr("transform", "scale("+[1, -1]+") translate("+[24, -662]+")")
.style("fill", "#FA0DD4")
.style("fill-opacity", 0.4928)
.style("stroke", "#858585")
.style("stroke-width", 1);
// Male_count
rects.enter().append("rect")
.attr("width", 7)
.attr("height", function(d,i){
console.log(d);
return Math.log(d['Male_count'])*person_lambda;
})
.attr("x", function(d,i){
return 27 + 20*i;
})
.attr("y", 316)
.attr("transform", "scale("+[1, -1]+") translate("+[24, -662]+")")
.style("fill", "#0027F7")
.style("fill-opacity", 0.7216)
.style("stroke", "#858585")
.style("stroke-width", 1);
[{"ISO_country_code": "USA","Country_name": "US","2011_GDP": 15094000000000.00,"2010_population": 309349000,"Female_count": 271,"Male_count": 260,"Gold_medals": 46,"Silver_medals": 29,"Bronze_medals": 29},
{"ISO_country_code": "CHN","Country_name": "China","2011_GDP": 7298100000000.00,"2010_population": 1338300000,"Female_count": 208,"Male_count": 163,"Gold_medals": 38,"Silver_medals": 27,"Bronze_medals": 23},
{"ISO_country_code": "JPN","Country_name": "Japan","2011_GDP": 5867150000000.00,"2010_population": 127451000,"Female_count": 162,"Male_count": 141,"Gold_medals": 7,"Silver_medals": 14,"Bronze_medals": 17},
{"ISO_country_code": "DEU","Country_name": "Germany","2011_GDP": 3570560000000.00,"2010_population": 81777000,"Female_count": 176,"Male_count": 219,"Gold_medals": 11,"Silver_medals": 19,"Bronze_medals": 14},
{"ISO_country_code": "FRA","Country_name": "France","2011_GDP": 2773030000000.00,"2010_population": 64895000,"Female_count": 148,"Male_count": 187,"Gold_medals": 11,"Silver_medals": 11,"Bronze_medals": 12},
{"ISO_country_code": "BRA","Country_name": "Brazil","2011_GDP": 2476650000000.00,"2010_population": 194946000,"Female_count": 128,"Male_count": 138,"Gold_medals": 3,"Silver_medals": 5,"Bronze_medals": 9},
{"ISO_country_code": "GBR","Country_name": "UK","2011_GDP": 2431590000000.00,"2010_population": 62232000,"Female_count": 269,"Male_count": 287,"Gold_medals": 29,"Silver_medals": 17,"Bronze_medals": 19},
{"ISO_country_code": "ITA","Country_name": "Italy","2011_GDP": 2194750000000.00,"2010_population": 60483000,"Female_count": 122,"Male_count": 159,"Gold_medals": 8,"Silver_medals": 9,"Bronze_medals": 11},
{"ISO_country_code": "RUS","Country_name": "Russia","2011_GDP": 1857770000000.00,"2010_population": 141750000,"Female_count": 227,"Male_count": 208,"Gold_medals": 24,"Silver_medals": 26,"Bronze_medals": 32},
{"ISO_country_code": "IND","Country_name": "India","2011_GDP": 1847980000000.00,"2010_population": 1224615000,"Female_count": 23,"Male_count": 60,"Gold_medals": 0,"Silver_medals": 2,"Bronze_medals": 4},
{"ISO_country_code": "JAM","Country_name": "Jamaica","2011_GDP": 15069767442.00,"2010_population": 2702000,"Female_count": 25,"Male_count": 25,"Gold_medals": 4,"Silver_medals": 4,"Bronze_medals": 4},
{"ISO_country_code": "GEO","Country_name": "Georgia","2011_GDP": 14366566609.00,"2010_population": 4452000,"Female_count": 6,"Male_count": 29,"Gold_medals": 1,"Silver_medals": 3,"Bronze_medals": 3},
{"ISO_country_code": "PRK","Country_name": "North Korea","2011_GDP": 12280000000.00,"2010_population": 24589122,"Female_count": 40,"Male_count": 15,"Gold_medals": 4,"Silver_medals": 0,"Bronze_medals": 2},
{"ISO_country_code": "ARM","Country_name": "Armenia","2011_GDP": 10247788877.00,"2010_population": 3092000,"Female_count": 4,"Male_count": 21,"Gold_medals": 0,"Silver_medals": 1,"Bronze_medals": 2},
{"ISO_country_code": "MNG","Country_name": "Mongolia","2011_GDP": 8557529910.00,"2010_population": 2756000,"Female_count": 13,"Male_count": 16,"Gold_medals": 0,"Silver_medals": 2,"Bronze_medals": 3},
{"ISO_country_code": "BHS","Country_name": "Bahamas","2011_GDP": 7787514000.00,"2010_population": 343000,"Female_count": 11,"Male_count": 15,"Gold_medals": 1,"Silver_medals": 0,"Bronze_medals": 0},
{"ISO_country_code": "MDA","Country_name": "Moldova","2011_GDP": 7000318677.00,"2010_population": 3562000,"Female_count": 10,"Male_count": 12,"Gold_medals": 0,"Silver_medals": 0,"Bronze_medals": 2},
{"ISO_country_code": "TJK","Country_name": "Tajikistan","2011_GDP": 6522200291.00,"2010_population": 6879000,"Female_count": 3,"Male_count": 13,"Gold_medals": 0,"Silver_medals": 0,"Bronze_medals": 1},
{"ISO_country_code": "MNE","Country_name": "Montenegro","2011_GDP": 4550463278.00,"2010_population": 632000,"Female_count": 16,"Male_count": 18,"Gold_medals": 0,"Silver_medals": 1,"Bronze_medals": 0},
{"ISO_country_code": "GRD","Country_name": "Grenada","2011_GDP": 816054092.20,"2010_population": 104000,"Female_count": 4,"Male_count": 6,"Gold_medals": 1,"Silver_medals": 0,"Bronze_medals": 0}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment