Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
Detail page updates
Browse files Browse the repository at this point in the history
- [x] Add an ‘All Years’ option to the year filter
- [x] in blue box below, 'How the data is calculated' box lists dates as 2015. Update the text to current year.
- [x] Carry the filter over when a user clicks on the ‘Projects’, ‘total budget’, or ‘total expenditure’ box.
- [x] Increase size of font of ‘About this data’ and ‘About data quality’
  • Loading branch information
bezunakarmi committed May 11, 2018
1 parent 49a2a55 commit bb9cf39
Show file tree
Hide file tree
Showing 15 changed files with 169 additions and 124 deletions.
4 changes: 2 additions & 2 deletions ctrack/art/original/ctrack.css
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ option {color:#000;}
============================================= */
.about_more_info {float: left; font-size: 12px; color: #666;}
a.more_info {color:#015CA8;}
a.about_data {background: url("/art/ic_about_data.png") no-repeat center left; display:inline-block; vertical-align:bottom; padding-left:20px; text-align:center; color:#666666; font-size:12px; line-height: 18px; margin-right: 30px; height:17px;}
a.about_data {background: url("/art/ic_about_data.png") no-repeat center left; display:inline-block; vertical-align:bottom; padding-left:20px; text-align:center; color:#666666; font-size:16px; line-height: 18px; margin-right: 30px; height:17px;}
a.about_data:hover {color:#666;}
a.about_data.quality {background: url("/art/ic_about_quality.png") no-repeat center left; text-align:right; margin-right: 0; padding-left: 23px;}

Expand Down Expand Up @@ -326,7 +326,7 @@ table.country td.name {font-size:32px; line-height:38px; color:#333333; vertica
table.country td.name.publisher {width:960px; max-width:960px; padding-right: 30px; padding-bottom: 10px; vertical-align: bottom;}
table.country td.name.publisher + td {vertical-align: bottom; padding-bottom: 15px;}
table.country td.flag {text-align:right; vertical-align: bottom; padding-bottom: 12px;}
table.country td.flag img {max-height:60px; border: 1px solid #f1f1f1;}
table.country td.flag img {max-height:90px; border: 1px solid #f1f1f1;}
table.country.min {padding:10px 0;}
table.country.min td.name {width:860px; max-width:860px; padding-right:20px; font-size:2.0em; line-height:1.1em; color:#2D2D2D;}
table.country.min td.flag img {max-height: 50px;}
Expand Down
5 changes: 3 additions & 2 deletions ctrack/js/ctrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ ctrack.setup = function (args) {
head.load(args.css);
}
let currentYear = new Date().getFullYear();
ctrack.year = parseInt(args.year || ctrack.q.year || currentYear);


ctrack.year = (args.year || ctrack.q.year || currentYear); //removed parseInt to handle all year
ctrack.year = (ctrack.year === 'all')? 'all years': ctrack.year;
ctrack.year_chunks = function (y) {
ctrack.chunk("year", y);
ctrack.chunk("year1", y - 1);
Expand Down
21 changes: 14 additions & 7 deletions ctrack/js/view_donors_top.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,21 @@ view_donors_top.ajax = function (args) {

var year = args.year || parseInt(ctrack.hash.year) || ctrack.year;
ctrack.year_chunks(year);

var dat = {
"from": "act,trans,country",
"limit": -1,
"select": "funder_ref," + ctrack.convert_str("sum_of_percent_of_trans"),
"funder_ref_not_null": "",
"groupby": "funder_ref",
"trans_code": "D|E",
"trans_day_gteq": year + "-" + ctrack.args.newyear, "trans_day_lt": (parseInt(year) + 1) + "-" + ctrack.args.newyear,
"trans_code": "D|E"
};

if(year !== 'all years'){
dat.trans_day_gteq = year + "-" + ctrack.args.newyear;
dat.trans_day_lt = (parseInt(year) + 1) + "-" + ctrack.args.newyear;
}

fetch.ajax_dat_fix(dat, args);
if (!dat.reporting_ref) {
dat.flags = 0;
Expand Down Expand Up @@ -67,6 +72,7 @@ view_donors_top.ajax = function (args) {
var top = list[0] && list[0].usd || 0;
var dd = [];
var secondTotal = 0;

list.forEach(function (v) {
var d = {};
d.num = v.usd;
Expand All @@ -83,15 +89,16 @@ view_donors_top.ajax = function (args) {
d.num = -d.num;
}
var regExp = /\(([^)]+)\)/;

try {
d.str_lab = iati_codes.funder_names[v.funder] || (regExp.exec(iati_codes.un_publisher_names[v.funder]))[1];

d.str_lab = iati_codes.funder_names[v.funder] || iati_codes.rev_crs_funders[v.funder] || (regExp.exec(iati_codes.un_publisher_names[v.funder]))[1] ;
} catch (err) {
// console.log(v.funder, err);
console.log(v.funder, err);
}
dd.push(d);
});

ctrack.chunk("data_chart_donors", dd);
ctrack.display();

Expand Down
6 changes: 5 additions & 1 deletion ctrack/js/view_list_activities.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ view_list_activities.ajax = function(args) {
if (args.output == "count") {
// just count please
let y = ctrack.args.selected_year; //Date.UTC(ctrack.args.selected_year, 1, 1) / (1000 * 60 * 60 * 24);

dat.select = "count_aid";
(dat.between = [y, "day_start", "day_end"]), delete dat.limit;
if(y !== 'all'){
dat.between = [y, "day_start", "day_end"];
}
delete dat.limit;
delete dat.orderby;
delete dat.groupby;
}
Expand Down
10 changes: 7 additions & 3 deletions ctrack/js/view_publisher_countries_top.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ view_publisher_countries_top.ajax = function (args) {
"limit": -1,
"select": "country_code," + ctrack.convert_str("sum_of_percent_of_trans"),
"groupby": "country_code",
"trans_code": "D|E",
"trans_day_gteq": year + "-" + ctrack.args.newyear,
"trans_day_lt": (parseInt(year) + 1) + "-" + ctrack.args.newyear,
"trans_code": "D|E"
};

if(year !== 'all years'){
dat.trans_day_gteq = year + "-" + ctrack.args.newyear;
dat.trans_day_lt = (parseInt(year) + 1) + "-" + ctrack.args.newyear;
}

fetch.ajax_dat_fix(dat, args);
if (!dat.reporting_ref) {
dat.flags = 0;
Expand Down
9 changes: 7 additions & 2 deletions ctrack/js/view_publisher_sectors_top.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,18 @@ view_publisher_sectors_top.ajax=function(args)
"limit":-1,
"select":"sector_code,sum_of_percent_of_trans_usd",
"groupby":"sector_code",
"trans_code":"D|E",
"trans_day_gteq":year+"-"+ctrack.args.newyear,"trans_day_lt":(parseInt(year)+1)+"-"+ctrack.args.newyear,
"trans_code":"D|E"
};

if(year !== 'all years'){
dat.trans_day_gteq = year + "-" + ctrack.args.newyear;
dat.trans_day_lt = (parseInt(year) + 1) + "-" + ctrack.args.newyear;
}
fetch.ajax_dat_fix(dat,args);

if(!dat.reporting_ref){dat.flags=0;}
fetch.ajax(dat,function(data){

for(var i=0;i<data.rows.length;i++)
{
var v=data.rows[i];
Expand Down
9 changes: 7 additions & 2 deletions ctrack/js/view_sector_category.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ view_sector_category.ajax = function(args){
"funder_ref_not_null":"",
"sector_code":ctrack.args.sector,
"groupby":"sector_code",
"trans_code":"D|E",
"trans_day_gteq":year+"-"+ctrack.args.newyear,"trans_day_lt":(parseInt(year)+1)+"-"+ctrack.args.newyear,
"trans_code":"D|E"
};

if(year !== 'all years'){
dat.trans_day_gteq = year + "-" + ctrack.args.newyear;
dat.trans_day_lt = (parseInt(year) + 1) + "-" + ctrack.args.newyear;
}

fetch.ajax_dat_fix(dat,args);
if(!dat.sector_ref){dat.flags = 0;}
fetch.ajax(dat,function(data){
Expand Down
12 changes: 8 additions & 4 deletions ctrack/js/view_sector_publisher_top.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ view_sector_publisher_top.ajax = function (args) {
"funder_ref_not_null": "",
"sector_code": ctrack.args.sector,
"groupby": "funder_ref",
"trans_code": "D|E",
"trans_day_gteq": year + "-" + ctrack.args.newyear,
"trans_day_lt": (parseInt(year) + 1) + "-" + ctrack.args.newyear,
"trans_code": "D|E"
};

if(year !== 'all years'){
dat.trans_day_gteq = year + "-" + ctrack.args.newyear;
dat.trans_day_lt = (parseInt(year) + 1) + "-" + ctrack.args.newyear;
}

fetch.ajax_dat_fix(dat, args);
if (!dat.sector_ref) {
dat.flags = 0;
Expand Down Expand Up @@ -88,7 +92,7 @@ view_sector_publisher_top.ajax = function (args) {
var regExp = /\(([^)]+)\)/;

try {
d.str_lab = iati_codes.funder_names[v.funder] || (regExp.exec(iati_codes.un_publisher_names[v.funder]))[1];
d.str_lab = iati_codes.funder_names[v.funder] || iati_codes.rev_crs_funders[v.funder] || (regExp.exec(iati_codes.un_publisher_names[v.funder]))[1];
} catch (err) {
console.log(v.funder, err);
}
Expand Down
164 changes: 84 additions & 80 deletions ctrack/js/view_sectors_top.js
Original file line number Diff line number Diff line change
@@ -1,97 +1,101 @@
// Copyright (c) 2014 International Aid Transparency Initiative (IATI)
// Licensed under the MIT license whose full text can be found at http://opensource.org/licenses/MIT

var view_sectors_top = exports;
exports.name = "view_sectors_top";

var view_sectors_top=exports;
exports.name="view_sectors_top";
var ctrack = require("./ctrack.js");
var plate = require("./plate.js");
var iati = require("./iati.js");
var fetch = require("./fetch.js");

var ctrack=require("./ctrack.js")
var plate=require("./plate.js")
var iati=require("./iati.js")
var fetch=require("./fetch.js")
var refry = require("../../dstore/js/refry.js");
var iati_codes = require("../../dstore/json/iati_codes.json");
var crs_year_sectors = require("../../dstore/json/crs_2013_sectors.json");

var refry=require("../../dstore/js/refry.js")
var iati_codes=require("../../dstore/json/iati_codes.json")
var crs_year_sectors=require("../../dstore/json/crs_2013_sectors.json")

var commafy=function(s) { return (""+s).replace(/(^|[^\w.])(\d{4,})/g, function($0, $1, $2) {
return $1 + $2.replace(/\d(?=(?:\d\d\d)+(?!\d))/g, "$&,"); }) };
var commafy = function(s) {
return ("" + s).replace(/(^|[^\w.])(\d{4,})/g, function($0, $1, $2) {
return $1 + $2.replace(/\d(?=(?:\d\d\d)+(?!\d))/g, "$&,");
});
};

// the chunk names this view will fill with new data
view_sectors_top.chunks=[
];

view_sectors_top.chunks = [];

//
// Perform fake ajax call to get data
//
view_sectors_top.ajax=function(args)
{
args=args || {};
var limit=args.limit || 5;
var year=args.year || parseInt(ctrack.hash.year) || ctrack.year;
ctrack.year_chunks(year);

var list=[];
view_sectors_top.ajax = function(args) {
args = args || {};
var limit = args.limit || 5;
var year = args.year || parseInt(ctrack.hash.year) || ctrack.year;
ctrack.year_chunks(year);

var list = [];

var dat={
"from":"act,trans,country,sector",
"limit":-1,
"select":"sector_group,sector_code,"+ctrack.convert_str("sum_of_percent_of_trans"),
"sector_group_not_null":1,
"groupby":"sector_group",
"trans_code":"D|E",
"trans_day_gteq":year+"-"+ctrack.args.newyear,"trans_day_lt":(parseInt(year)+1)+"-"+ctrack.args.newyear,
};
fetch.ajax_dat_fix(dat,args);
var dat = {
from: "act,trans,country,sector",
limit: -1,
select:
"sector_group,sector_code," +
ctrack.convert_str("sum_of_percent_of_trans"),
sector_group_not_null: 1,
groupby: "sector_group",
trans_code: "D|E"
};

if(!dat.reporting_ref){dat.flags=0;}
var callback=function(data){
for(var i=0;i<data.rows.length;i++)
{
var v=data.rows[i];
if(iati_codes.sector[v.sector_code]){
var d = {};
d.sector_group = iati_codes.sector_names[v.sector_group];
d.sector_name = iati_codes.sector[v.sector_code];
d.usd = Math.floor(ctrack.convert_num("sum_of_percent_of_trans", v));
list.push(d);
}
}
list.sort(function(a,b){
return ( (b.usd||0)-(a.usd||0) );
});
if (year !== "all years") {
dat.trans_day_gteq = year + "-" + ctrack.args.newyear;
dat.trans_day_lt = parseInt(year) + 1 + "-" + ctrack.args.newyear;
}

var total=0; list.forEach(function(it){
if(it.usd>0)
{
total+=it.usd;
}
else
{
total-=it.usd;
}
});
var shown=0;
var dd=[];
list.forEach(function(v){
var d = {};
d.num = v.usd;
var initialPct = 100*d.num/total;
if(initialPct < 1){
d.pct = "<1";
}
else{
d.pct=Math.round(initialPct);
}
if(d.num < 0){d.num = -d.num; }
d.str_lab = v.sector_name;
dd.push(d);
});
ctrack.chunk("data_chart_sectors",dd);
ctrack.display();
fetch.ajax_dat_fix(dat, args);

};
fetch.ajax(dat,callback);
if (!dat.reporting_ref) {
dat.flags = 0;
}
var callback = function(data) {
for (var i = 0; i < data.rows.length; i++) {
var v = data.rows[i];
if (iati_codes.sector[v.sector_code]) {
var d = {};
d.sector_group = iati_codes.sector_names[v.sector_group];
d.sector_name = iati_codes.sector[v.sector_code];
d.usd = Math.floor(ctrack.convert_num("sum_of_percent_of_trans", v));
list.push(d);
}
}
list.sort(function(a, b) {
return (b.usd || 0) - (a.usd || 0);
});

}
var total = 0;
list.forEach(function(it) {
if (it.usd > 0) {
total += it.usd;
} else {
total -= it.usd;
}
});
var shown = 0;
var dd = [];
list.forEach(function(v) {
var d = {};
d.num = v.usd;
var initialPct = 100 * d.num / total;
if (initialPct < 1) {
d.pct = "<1";
} else {
d.pct = Math.round(initialPct);
}
if (d.num < 0) {
d.num = -d.num;
}
d.str_lab = v.sector_name;
dd.push(d);
});
ctrack.chunk("data_chart_sectors", dd);
ctrack.display();
};
fetch.ajax(dat, callback);
};
Loading

0 comments on commit bb9cf39

Please sign in to comment.