<commit_before>/*
 * Author <NAME> <<EMAIL>>
 * Based on http://bost.ocks.org/mike/miserables/
 */

// initialize
var dataset = "substance_of_adaptation.json";
var orderby = "count"; // count or alphabet
var filter = ""; // only for adaptation_projects.json
d3.selectAll('.radio').on('change', function(){
    orderby = this.value;
});
var whichdata = 'all';
d3.selectAll('.radiowhichdata').on('change', function(){
    whichdata = this.value;
});
d3.select("#select1").style("display","none");
d3.select("#select2").style("display","none");

// here the possible selections are defined
d3.select("#dataset").on("change",function(){
    if(this.value == "substance_of_adaptation") {
        dataset = "substance_of_adaptation.json";
        d3.select("#select1").style("display","none");
        d3.select("#select2").style("display","none"); 
    } else {
        //console.log(this.value);
        var fields = [],
        fieldNames = "";
        if(this.value == "undp") {
            dataset = "adaptation_projects.json"; 
            fields = ["themes","countries","climate-hazards","key-collaborators"];
            fieldNames = ["sectors","countries","climate hazards","key collaborators"];
            fillOptions("#field1",fields,fieldNames,0);
            fillOptions("#field2",fields,fieldNames,1);
            filter = "undp";
        } else if(this.value == "psi") {
            dataset = "adaptation_projects.json"; 
            fields = ["themes","countries","climate-hazards","key-collaborators"];
            fieldNames = ["sectors","countries","climate hazards","key collaborators"];
            fillOptions("#field1",fields,fieldNames,0);
            fillOptions("#field2",fields,fieldNames,1);
            filter = "psi";
        } else if(this.value == "climatewise") {
            dataset = "adaptation_projects.json"; 
            fields = ["themes","countries","climate-hazards","key-collaborators"];
            fieldNames = ["sectors","countries","climate hazards","key collaborators"];
            fillOptions("#field1",fields,fieldNames,0);
            fillOptions("#field2",fields,fieldNames,1);
            filter = "climatewise";
        } else if(this.value == "cigrasp") {
            dataset = "cigrasp.json";
            fields = ["overview.sector","country","types","scale","overview.stimuli","overview.impacts","project_classification.project_type","project_classification.project_status","project_classification.running_time","project_classification.spatial_scale","project_classification.effect_emergence","project_classification.effect_persistence","problem_solving_capacity_an_reversibility.problem_solving_coverage","problem_solving_capacity_an_reversibility.reversibility","responsibilities.initiating_agent","responsibilities.executing_agent","responsibilities.funding_source"];
            fieldNames = ["sectors","countries","types","scale","stimuli","impacts","project type","project status","running time","spatial scale","effect emergence","effect persistence","problem solving coverage","reversibility","initiating agent","executing agent","funding source"];
            fillOptions("#field1",fields,fieldNames,0);
            fillOptions("#field2",fields,fieldNames,1);
        } else if(this.value == "oecd") {
            dataset = "oecd.json";
            fields = ["SectorNameE", "sector_mapped","recipientnameE","donornameE", "agencynameE", "purposename_e", "RegionNameE", "IncomeGroupNameE"];
            fieldNames = ["sectors","sectors in undp alm scheme","recipient countries","donor countries","agency","purposes","regions","income Groups"];
            fillOptions("#field1",fields,fieldNames,0);
            fillOptions("#field2",fields,fieldNames,1);
        } else if(this.value == "climatefundsupdate") {
            dataset = "climatefundsupdate.json";
            fields = ["sector","sector_mapped","recipient","recipient_income_level", "region", "donor", "implementor"];
            fieldNames = ["sectors","sectors in undp alm scheme","recipient countries", "Recipient Income Level", "Region", "Funder", "Implementor"];
            fillOptions("#field1",fields,fieldNames,0);
            fillOptions("#field2",fields,fieldNames,1);
        } else if(this.value == "napa") {
            dataset = "napa.json";
            fields = ["sector","sector_mapped","recipient"];
            fieldNames = ["sectors","sectors in undp alm scheme","recipient"];
            fillOptions("#field1",fields,fieldNames,0);
            fillOptions("#field2",fields,fieldNames,1);
        }
        
        d3.select("#select1").style("display","block");
        d3.select("#select2").style("display","block");
    }    
});
d3.select("#form").on('submit',function() {
    d3.event.preventDefault();
    d3.event.stopPropagation();
    updateChart();
});

updateChart();

function updateChart() {
    
    var source = "",
    target = "";
    
    if(dataset == "substance_of_adaptation.json") {
        source = "source"; // @todo, can also be something else
        target = "recipient_mapped";
    } else {
        source = d3.select('#field1').node().value;
        target = d3.select('#field2').node().value;
    }
    
    drawChart(orderby,dataset,source,target,filter);
}

function fillOptions(fieldid, fields, fieldNames,index) {
    d3.select(fieldid).selectAll("option").remove();
    
    d3.select(fieldid).selectAll("option")
    .data(d3.values(fields))
    .enter()
    .append("option")
    .attr("value", function(d,i){
        return d;
    })
    .text(function(d,i){
        return fieldNames[i];
    });
}

function drawChart(orderby,dataset,source,target,filter) {
    //console.log(orderby + " " + dataset + " " + source + " " + target);
    d3.select("svg").remove();
    var margin = {
        top: 140, 
        right: 140, 
        bottom: 10, <commit_msg>added other fields from combined data set as well<commit_after>/*
 * Author <NAME> <<EMAIL>>
 * Based on http://bost.ocks.org/mike/miserables/
 */

// initialize
var dataset = "substance_of_adaptation.json";
var orderby = "count"; // count or alphabet
var filter = ""; // only for adaptation_projects.json
d3.selectAll('.radio').on('change', function(){
    orderby = this.value;
});
var whichdata = 'all';
d3.selectAll('.radiowhichdata').on('change', function(){
    whichdata = this.value;
});
d3.select("#select1").style("display","block");
d3.select("#select2").style("display","block");

// init
dataset = "substance_of_adaptation.json";
fields = ["source","recipient_mapped","year","donor","purpose","sector","sector_mapped"];
fieldNames = ["source","country","year","donor","purpose","sector","sectors in undp alm scheme"];
fillOptions("#field1",fields,fieldNames,0);
fillOptions("#field2",fields,fieldNames,1);

// here the possible selections are defined
d3.select("#dataset").on("change",function(){
    var fields = [],
    fieldNames = "";
    if(this.value == "substance_of_adaptation") {
        dataset = "substance_of_adaptation.json";
        fields = ["source","recipient_mapped","year","donor","purpose","sector","sector_mapped"];
        fieldNames = ["source","country","year","donor","purpose","sector","sectors in undp alm scheme"];
        fillOptions("#field1",fields,fieldNames,0);
        fillOptions("#field2",fields,fieldNames,1);
    } else if(this.value == "undp") {
        dataset = "adaptation_projects.json"; 
        fields = ["themes","countries","climate-hazards","key-collaborators"];
        fieldNames = ["sectors","countries","climate hazards","key collaborators"];
        fillOptions("#field1",fields,fieldNames,0);
        fillOptions("#field2",fields,fieldNames,1);
        filter = "undp";
    } else if(this.value == "psi") {
        dataset = "adaptation_projects.json"; 
        fields = ["themes","countries","climate-hazards","key-collaborators"];
        fieldNames = ["sectors","countries","climate hazards","key collaborators"];
        fillOptions("#field1",fields,fieldNames,0);
        fillOptions("#field2",fields,fieldNames,1);
        filter = "psi";
    } else if(this.value == "climatewise") {
        dataset = "adaptation_projects.json"; 
        fields = ["themes","countries","climate-hazards","key-collaborators"];
        fieldNames = ["sectors","countries","climate hazards","key collaborators"];
        fillOptions("#field1",fields,fieldNames,0);
        fillOptions("#field2",fields,fieldNames,1);
        filter = "climatewise";
    } else if(this.value == "cigrasp") {
        dataset = "cigrasp.json";
        fields = ["overview.sector","country","types","scale","overview.stimuli","overview.impacts","project_classification.project_type","project_classification.project_status","project_classification.running_time","project_classification.spatial_scale","project_classification.effect_emergence","project_classification.effect_persistence","problem_solving_capacity_an_reversibility.problem_solving_coverage","problem_solving_capacity_an_reversibility.reversibility","responsibilities.initiating_agent","responsibilities.executing_agent","responsibilities.funding_source"];
        fieldNames = ["sectors","countries","types","scale","stimuli","impacts","project type","project status","running time","spatial scale","effect emergence","effect persistence","problem solving coverage","reversibility","initiating agent","executing agent","funding source"];
        fillOptions("#field1",fields,fieldNames,0);
        fillOptions("#field2",fields,fieldNames,1);
    } else if(this.value == "oecd") {
        dataset = "oecd.json";
        fields = ["SectorNameE", "sector_mapped","recipientnameE","donornameE", "agencynameE", "purposename_e", "RegionNameE", "IncomeGroupNameE"];
        fieldNames = ["sectors","sectors in undp alm scheme","recipient countries","donor countries","agency","purposes","regions","income Groups"];
        fillOptions("#field1",fields,fieldNames,0);
        fillOptions("#field2",fields,fieldNames,1);
    } else if(this.value == "climatefundsupdate") {
        dataset = "climatefundsupdate.json";
        fields = ["sector","sector_mapped","recipient","recipient_income_level", "region", "donor", "implementor"];
        fieldNames = ["sectors","sectors in undp alm scheme","recipient countries", "Recipient Income Level", "Region", "Funder", "Implementor"];
        fillOptions("#field1",fields,fieldNames,0);
        fillOptions("#field2",fields,fieldNames,1);
    } else if(this.value == "napa") {
        dataset = "napa.json";
        fields = ["sector","sector_mapped","recipient"];
        fieldNames = ["sectors","sectors in undp alm scheme","recipient"];
        fillOptions("#field1",fields,fieldNames,0);
        fillOptions("#field2",fields,fieldNames,1);
    }
        
//d3.select("#select1").style("display","block");
//d3.select("#select2").style("display","block");
  
});
d3.select("#form").on('submit',function() {
    d3.event.preventDefault();
    d3.event.stopPropagation();
    updateChart();
});

updateChart();

function updateChart() {
    
    var source = "",
    target = "";
    
    source = d3.select('#field1').node().value;
    target = d3.select('#field2').node().value;
    
    drawChart(orderby,dataset,source,target,filter);
}

function fillOptions(fieldid, fields, fieldNames,index) {
    d3.select(fieldid).selectAll("option").remove();
    
    d3.select(fieldid).selectAll("option")
    .data(d3.values(fields))
    .enter()
    .append("option")
    .attr("value", function(d,i){
        return d;
    })
    .text(function(d,i){
        return fieldNames[i];
    });
}

function drawChart(orderby,dataset,source,target,filter) {
    //console.log(orderby + " " + dataset + " " + source + " " + target);
    d3.select("svg").remove();
    var margin = {
        top: 140, 
        right: 140, 
        bottom: 10, 
{'fraction_non_alphanumeric': 0.17849881396136902, 'fraction_numerical': 0.010843781768891902, 'mean_word_length': 4.11703511053316, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2965252', 'n_tokens_mistral': 3558, 'n_tokens_neox': 3405, 'n_words': 501}