Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
baripembo committed Dec 20, 2024
1 parent 0352810 commit 10686f3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
50 changes: 40 additions & 10 deletions js/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ $( document ).ready(function() {
d3.csv(DATA_PATH + GLOBAL_COUNTS_ID)
]).then(function(data){
globalCounts = data[2][0];

console.log('globalCounts',globalCounts)
datasetCounts = data[1];

countryNames = datasetCounts.map(row => ({
Expand All @@ -57,8 +59,7 @@ $( document ).ready(function() {
deepLinkView();

//load the subcategory view
// $('.subcategory-container div a').html('<iframe id="subcategory-view" src="https://ocha-dap.github.io/viz-datagrid-subcategories"></iframe>');
$('.subcategory-container div a').html('<iframe id="subcategory-view" src="https://baripembo.github.io/viz-datagrid-subcategories"></iframe>');
$('.subcategory-container div a').html('<iframe id="subcategory-view" src="https://ocha-dap.github.io/viz-datagrid-subcategories"></iframe>');
});
}

Expand All @@ -73,7 +74,7 @@ $( document ).ready(function() {
.key(function(d){ return d['Category']; })
.entries(data);
categoryCount = groupByCategory.length;
groupByCategory.sort(compare);
// groupByCategory.sort(compare);
groupByCategory.push({key:'TOTAL'});

//group the data by country
Expand Down Expand Up @@ -119,7 +120,7 @@ $( document ).ready(function() {

//metric
country.values.forEach(function(metric, index) {
metric.values.sort(compare);
// metric.values.sort(compare);
var values = ['data'+(index+1)];
//category
metric.values.forEach(function(category) {
Expand Down Expand Up @@ -164,11 +165,7 @@ $( document ).ready(function() {


function createOverview() {
var totals = new Object();
//donut chart
totals['Available'] = Math.round(globalCounts['Total Percentage Data Complete']*100);
totals['Not Up-to-date'] = Math.round(globalCounts['Total Percentage Data Incomplete']*100);
totals['Empty'] = Math.round(globalCounts['Total Percentage No Data']*100);
var totals = getGlobalTotals();
var metricTotals = Object.entries(totals);

var chart = c3.generate({
Expand Down Expand Up @@ -222,6 +219,37 @@ $( document ).ready(function() {
createKeyFigure('Number of Sub-categories', globalCounts['Subcategory Count']);
}


function getGlobalTotals() {
let totals = new Object();

// Convert percentages to whole numbers
let complete = Math.round(globalCounts['Total Percentage Data Complete'] * 100);
let incomplete = Math.round(globalCounts['Total Percentage Data Incomplete'] * 100);
let noData = Math.round(globalCounts['Total Percentage No Data'] * 100);

// Ensure the sum of the percentages equals 100
let totalSum = complete + incomplete + noData;
if (totalSum !== 100) {
let adjustment = 100 - totalSum;

// Adjust the largest value
if (complete >= incomplete && complete >= noData) {
complete += adjustment;
} else if (incomplete >= complete && incomplete >= noData) {
incomplete += adjustment;
} else {
noData += adjustment;
}
}

totals['Available'] = complete;
totals['Not Up-to-date'] = incomplete;
totals['Empty'] = noData;

return totals;
}


function createKeyFigure(title, value) {
return $('.stats').append("<div class='key-figure'><div class='inner'><h3>"+ title +"</h3><div class='num'>"+ value +"</div><p class='date small'>"+ date +"</p></div></div></div>");
Expand Down Expand Up @@ -272,8 +300,10 @@ $( document ).ready(function() {
},
labels: {
format: function (v) {
if (v>0)
if (v>10)
return v + '%';
else
return null;
}
},
colors: metricColors,
Expand Down
2 changes: 1 addition & 1 deletion js/bundle.min.js

Large diffs are not rendered by default.

0 comments on commit 10686f3

Please sign in to comment.