This repository has been archived by the owner on Jan 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Visualisation for weighted historical exports per gdp
Visualisation for issue #66 use Barchart for this one
- Loading branch information
1 parent
3fedf37
commit 6d81bcc
Showing
3 changed files
with
46 additions
and
101 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
source/data/security/armsexports/weighted_exports_historical.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Country,WeightedExports | ||
Australia,-0.002 | ||
Austria,-0.070 | ||
Belgium,-0.292 | ||
Canada,-0.017 | ||
Czech Republic,-0.441 | ||
Denmark,-0.033 | ||
Finland,-0.054 | ||
France,-0.695 | ||
Germany,-0.312 | ||
Greece,-0.046 | ||
Hungary,-0.023 | ||
Ireland,-0.005 | ||
Italy,-0.179 | ||
Japan,0.000 | ||
Luxembourg,-0.002 | ||
Netherlands,-0.395 | ||
New Zealand,-0.000 | ||
Norway,-0.055 | ||
Poland,-0.164 | ||
Portugal,-0.041 | ||
Slovakia,-0.084 | ||
South Korea,0.000 | ||
Spain,-0.251 | ||
Sweden,-0.800 | ||
Switzerland,-0.133 | ||
United Kingdom,-0.320 | ||
United States,-0.352 | ||
EU,-0.339 | ||
Europe,-0.328 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,11 @@ | ||
formatCurrency = d3.numberFormat("$,.2f") | ||
|
||
@formatCountry = (countryString) -> | ||
countryString.replace(" ","") | ||
|
||
changeDiffClass = (value) -> | ||
if value != 0 | ||
if value > 0 then "positive" else "negative" | ||
$ -> | ||
if $('#ruestung').length > 0 | ||
export2012_13Path = rootPath+"/data/exporte_2012_2013.csv" | ||
gesamt2013Path = rootPath+"/data/gesamt_exporte_2013.csv" | ||
queue() | ||
.defer(d3.csv, export2012_13Path) | ||
.defer(d3.csv, gesamt2013Path) | ||
.await (error, @data, gesamt) -> | ||
ruestung2013 = _.filter(@data,(num) -> num.ruestung > 0) | ||
ruestung2013 = _.sortBy(ruestung2013, (num) -> -num.ruestung) | ||
gesamtRuestung2013 = _.reduce(ruestung2013,((sum, d) -> return sum + parseInt(d.ruestung)), 0) | ||
gesamt2013 = _.reduce(gesamt,((sum, d) -> return sum + parseInt(d.ruestung)), 0) | ||
ruestung2012 = _.filter(@data, (num) -> num.Country in (ruestung2013.map((d) -> d.Country))) | ||
ruestung2012 = _.sortBy(ruestung2012, (num) -> -num.ruestung) | ||
|
||
d3.select('#ruestung .gesamt-ruestung').html(formatCurrency(gesamtRuestung2013)) | ||
d3.select('#ruestung .gesamt').html(formatCurrency(gesamt2013)) | ||
|
||
width = parseInt(d3.select('.ruestung-2013-chart').style('width')) | ||
margin = {top: 10, right: 30, bottom: 120, left: 40} | ||
options = { height: 300, width: width - 20 , margin: margin } | ||
|
||
exporte = new Exporte(ruestung2013, options) | ||
exporte.setYDomain([0, d3.max(ruestung2013, (d) -> parseInt(d.ruestung) )]) | ||
exporte.setXDomain(ruestung2013.map((d) -> d.Country)) | ||
exporte.setDataKey() | ||
exporte.render('.ruestung-2013-chart .chart') | ||
$('.ruestung-2013-chart form input').change (e) -> | ||
if(this.value == '2012') | ||
exporte.setDataKey('Ruestung_2012') | ||
exporte.setYDomain([0, d3.max(ruestung2012, (d) -> parseInt(d.Ruestung_2012) )]) | ||
exporte.update(ruestung2012) | ||
else | ||
exporte.setDataKey('ruestung') | ||
exporte.setYDomain([0, d3.max(ruestung2013, (d) -> parseInt(d.ruestung) )]) | ||
exporte.update(ruestung2013) | ||
|
||
ruestungExporte2013 = d3.select('#exporte-2013').append('table') | ||
ruestungExporte2013.attr('class','table-borders') | ||
tHeadTr = ruestungExporte2013.append('thead').append('tr') | ||
tHeadTr.append('th').text('Land') | ||
tHeadTr.append('th').text('2013') | ||
tHeadTr.append('th').text('Differenz zu 2012') | ||
tBody = ruestungExporte2013.append('tbody') | ||
trs = tBody.selectAll('tr').data(ruestung2013) | ||
trs.enter().append('tr').attr('class', (d) -> formatCountry(d.Country)) | ||
trs.append('td').text((d) -> d.Country) | ||
trs.append('td').text((d) -> formatCurrency(d.ruestung)) | ||
trs.append('td').text((d) -> formatCurrency(d.ruestung - d.Ruestung_2012)).attr('class', (d) -> changeDiffClass(d.ruestung - d.Ruestung_2012)) | ||
|
||
notFreeTable = d3.select('#all-exports').append('table') | ||
notFreeTable.attr('class','table-borders') | ||
tHeadTr = notFreeTable.append('thead').append('tr') | ||
tHeadTr.append('th').text('Land') | ||
tHeadTr.append('th').text('Exporte 2013') | ||
tHeadTr.append('th').text('Rüstungsexporte 2013') | ||
tHeadTr.append('th').text('Differenz Gesamtexporte zu 2012') | ||
tHeadTr.append('th').text('Differenz Rüstungsexporte zu 2012') | ||
tBody = notFreeTable.append('tbody') | ||
trs = tBody.selectAll('tr').data(@data) | ||
trs.enter().append('tr') | ||
|
||
trs.append('td').text((d) -> d.Country) | ||
trs.append('td').text((d) -> formatCurrency(d.gesamt)) | ||
trs.append('td').text((d) -> formatCurrency(d.ruestung)) | ||
trs.append('td').text((d) -> formatCurrency(d.gesamt - d.Gesamt_2012)).attr('class', (d) -> changeDiffClass(d.gesamt - d.Gesamt_2012)) | ||
trs.append('td').text((d) -> formatCurrency(d.ruestung - d.Ruestung_2012)).attr('class', (d) -> changeDiffClass(d.ruestung - d.Ruestung_2012)) | ||
exportPath = "#{rootPath}/data/security/armsexports/weighted_exports_historical.csv" | ||
d3.csv exportPath, (data) -> | ||
exportChart = new @Barchart(data) | ||
_.map(data, (d) -> d.WeightedExports = parseFloat(d.WeightedExports)*(-1)) | ||
exportChart.setXDomain(data.map((d) -> d.Country)) | ||
exportChart.setYDomain(d3.extent(data, (d) -> parseFloat(d.WeightedExports))) | ||
exportChart.setValueKey('WeightedExports') | ||
exportChart.setGroupKey('Country') | ||
exportChart.render('.exports-percent-gdp') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters