Changeset 35063 for main


Ignore:
Timestamp:
2021-04-12T17:30:09+12:00 (3 years ago)
Author:
davidb
Message:

Fixed bug in transpose_i() -- how to transpose a ragged-ended array is tricker than first appears\!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/model-sites-dev/eurovision-lod/collect/eurovision/js/eurovision.js

    r35048 r35063  
    66var glob_voting_country_and_points_width = (180+35);
    77
    8 function transpose_i(i,num_cols, num_rows)
    9 {
     8
     9var pp_country_lookup = {
     10    "BosniaandHerzegovina":        "Bosnia and Herzegovina",
     11    "CzechRepublic":               "Czech Republic",
     12    "FederalRepublicofYugoslavia": "Federal Republic of Yugoslavia",
     13    "NorthMacedonia":              "North Macedonia",
     14    "RepublicofMacedonia":         "Republic of Macedonia",
     15    "SanMarino":                   "San Marino",
     16    "SerbiaandMontenegro":         "Serbia and Montenegro",
     17    "UnitedKingdom":               "United Kingdom",
     18};
     19
     20function transpose_i(i,num_cols,num_rows,num_countries)
     21{
     22    if (i >= num_countries) {
     23    // out of range to tanspose, just return original value
     24    return i;
     25    }
     26   
     27    var num_filler_gaps = (num_cols * num_rows) - num_countries;
     28    var full_cols_until = num_cols - num_filler_gaps;
     29    //console.log("full cols until = " + full_cols_until);
     30   
    1031    // Map 'i' to (x,y) position in grid layout
    1132    var x = (i % num_cols);
    12     var y = Math.floor(i / num_cols); // affect int division
    13    
     33    var y = Math.floor(i / num_cols); // effectively int division
     34
    1435    // Transpose, and then reverse engineer what value of 'i' the transposed position needs to be
    1536    var trans_x = y;
     
    1839    var trans_i = trans_y * num_rows + trans_x;
    1940
     41    // Filler correction
     42    //if ((x > full_cols_until) && (trans_y < (num_cols-1))) {
     43    if (x > full_cols_until) {
     44    trans_i = trans_i - (num_cols - x)
     45    }
     46   
    2047    return trans_i;
    2148}
     
    5077
    5178    for (var i=0; i<num_cells; i++) {
    52         var trans_i = transpose_i(i,num_cols, num_rows);
     79        var trans_i = transpose_i(i,num_cols, num_rows, num_countries);
    5380
    5481        // By default, they country and points are set to be empty divs
     
    7097        if (typeof from_country_points !== 'undefined') {
    7198            var from_country_base = from_country.replace(/-(T|J)$/,"");
    72             var pp_from_country = from_country_base; // in future look to putting spacing back in for countries like United Kingdom
     99
     100            var pp_from_country = from_country_base;
     101            if (pp_country_lookup[pp_from_country]) {
     102            pp_from_country = pp_country_lookup[pp_from_country];
     103            }
    73104
    74105            var hyphen_vote_type = from_country.match(/-(?:T|J)$/);
     
    160191    for (var i=0; i<num_cells; i++) {
    161192
    162         var trans_i = transpose_i(i,num_cols, num_rows);
     193        var trans_i = transpose_i(i,num_cols, num_rows, num_countries);
    163194
    164195        var $to_country_name = $('<div>').attr("class","voting voting-country").append("");
Note: See TracChangeset for help on using the changeset viewer.