Changeset 35092
- Timestamp:
- 2021-04-22T14:49:06+12:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/model-sites-dev/eurovision-lod/collect/eurovision/js/eurovision.js
r35071 r35092 77 77 78 78 79 80 function transpose_i(i,num_cols,num_rows,num_countries) 79 function create_array2d(num_cols,num_rows) 80 { 81 var array_2d = new Array(num_rows); 82 83 for (var i = 0; i < array_2d.length; i++) { 84 array_2d[i] = new Array(num_cols); 85 } 86 87 return array_2d; 88 } 89 90 function create_i_to_yx_mapping(num_cols,num_rows,num_countries) 91 { 92 var entries_overflow = (num_countries % num_cols) 93 var num_entries_in_last_row = (entries_overflow == 0) ? num_cols : entries_overflow; 94 95 var sorted_results_mapping = create_array2d(num_cols,num_rows); 96 97 // populate the 2d-array with the suitable mapped in values 98 var i = 0; 99 for (var x=0; x<num_cols; x++) { 100 for (var y=0; y<num_rows; y++) { 101 102 var on_last_row = (y == (num_rows-1)); 103 var in_last_row_gap = (on_last_row && (x >= num_entries_in_last_row)); 104 105 if (!in_last_row_gap) { 106 sorted_results_mapping[y][x] = i; 107 i++; 108 } 109 else { 110 sorted_results_mapping[y][x] = undefined; 111 } 112 113 } 114 } 115 116 return sorted_results_mapping; 117 } 118 119 120 function transpose_iDEPRECATED(i,num_cols,num_rows,num_countries) 81 121 { 82 122 if (i >= num_countries) { … … 136 176 var collect_doc_prefix_url = library_name + "/collection/" + coll_name + "/document/"; 137 177 138 for (var i=0; i<num_cells; i++) { 139 var trans_i = transpose_i(i,num_cols, num_rows, num_countries); 140 141 // By default, they country and points are set to be empty divs 142 var $to_country_name = $('<div>').attr("class","voting voting-country").append(""); 143 var $to_country_points = $('<div>').attr("class","voting voting-points").append(""); 144 var $a_from_country = $('<span>'); 178 var sorted_results_mapping = create_i_to_yx_mapping(num_cols,num_rows,num_countries) 179 180 for (var y=0; y<num_rows; y++) { 181 for (var x=0; x<num_cols; x++) { 182 183 var i = sorted_results_mapping[y][x]; 184 185 // By default, the country and points are set to be empty divs 186 var $to_country_name = $('<div>').attr("class","voting voting-country").append(""); 187 var $to_country_points = $('<div>').attr("class","voting voting-points").append(""); 188 var $a_from_country = $('<span>'); 145 189 146 // check to see if trans_i position is within array, otherwise default to filler 147 if (trans_i < num_countries) { 148 var from_country = VotesJSON[trans_i]; 149 150 // map -C and -S to -J for now 151 from_country = from_country.replace(/-C$/,"-J"); 152 from_country = from_country.replace(/-S$/,"-J"); 190 // if 'i' explicitly undefined, we are in one of the last-row gaps => nothing to do! 191 if (typeof i !== 'undefined') { 192 var from_country = VotesJSON[i]; 193 194 // map -C and -S to -J for now 195 from_country = from_country.replace(/-C$/,"-J"); 196 from_country = from_country.replace(/-S$/,"-J"); 197 198 var from_country_points = gs.documentMetadata[from_country]; 199 var year = gs.documentMetadata["Year"]; 153 200 154 var from_country_points = gs.documentMetadata[from_country]; 155 var year = gs.documentMetadata["Year"]; 156 157 if (typeof from_country_points !== 'undefined') { 158 var from_country_base = from_country.replace(/-(T|J)$/,""); 159 160 var pp_from_country = from_country_base; 161 if (pp_country_lookup[pp_from_country]) { 162 pp_from_country = pp_country_lookup[pp_from_country]; 201 if (typeof from_country_points !== 'undefined') { 202 var from_country_base = from_country.replace(/-(T|J)$/,""); 203 204 var pp_from_country = from_country_base; 205 if (pp_country_lookup[pp_from_country]) { 206 pp_from_country = pp_country_lookup[pp_from_country]; 207 } 208 209 var hyphen_vote_type = from_country.match(/-(?:T|J)$/); 210 var from_country_id = "FromCountry-"+from_country_base + year + hyphen_vote_type; 211 var href_from_country = collect_doc_prefix_url + from_country_id; 212 213 //var $a_from_country = $('<a>').attr("href",href_from_country).append(pp_from_country); 214 var $a_from_country = $('<a>').attr("href",href_from_country); 215 216 //$from_country_name = $('<div>').attr("class","voting voting-country").append($a_from_country).append(":") 217 $from_country_name = $('<div>').attr("class","voting voting-country").append(pp_from_country).append(":"); 218 $from_country_points = $('<div>').attr("class","voting voting-points").append(from_country_points); 163 219 } 164 165 var hyphen_vote_type = from_country.match(/-(?:T|J)$/); 166 var from_country_id = "FromCountry-"+from_country_base + year + hyphen_vote_type; 167 var href_from_country = collect_doc_prefix_url + from_country_id; 168 169 //var $a_from_country = $('<a>').attr("href",href_from_country).append(pp_from_country); 170 var $a_from_country = $('<a>').attr("href",href_from_country); 171 172 //$from_country_name = $('<div>').attr("class","voting voting-country").append($a_from_country).append(":") 173 $from_country_name = $('<div>').attr("class","voting voting-country").append(pp_from_country).append(":"); 174 $from_country_points = $('<div>').attr("class","voting voting-points").append(from_country_points); 220 else { 221 console.error("Failed to find points for: " + from_country); 222 } 175 223 } 224 225 $a_from_country 226 .append($from_country_name) 227 .append($from_country_points); 228 $('#to-country-votes') 229 .append($a_from_country); 176 230 } 177 178 /*179 $('#to-country-votes')180 .append($from_country_name)181 .append($from_country_points);182 */183 $a_from_country184 .append($from_country_name)185 .append($from_country_points);186 $('#to-country-votes')187 .append($a_from_country);188 231 189 232 } … … 257 300 258 301 var year = gs.documentMetadata["FromCountryYear"]; 259 260 for (var i=0; i<num_cells; i++) { 261 262 var trans_i = transpose_i(i,num_cols, num_rows, num_countries); 263 264 var $to_country_name = $('<div>').attr("class","voting voting-country").append(""); 265 var $to_country_points = $('<div>').attr("class","voting voting-points").append(""); 266 var $a_to_country = $('<span>'); 267 268 // check to see if trans_i position is within array, otherwise default to filler 269 if (trans_i < num_countries) { 270 var pp_to_country = from_country_votes[trans_i].Country; 271 var to_country = pp_to_country.replace(/\s+/g,""); 272 273 var to_country_points = from_country_votes[trans_i].Points; 302 303 var sorted_results_mapping = create_i_to_yx_mapping(num_cols,num_rows,num_countries) 304 305 for (var y=0; y<num_rows; y++) { 306 for (var x=0; x<num_cols; x++) { 307 308 var i = sorted_results_mapping[y][x]; 274 309 275 if (typeof to_country_points !== 'undefined') { 276 277 //var doc_id = gs.cgiParams["d"]; 278 //var hyphen_vote_type = doc_id.match(/-(?:T|J)$/); 279 var to_country_id = to_country + year; 280 var href_to_country = collect_doc_prefix_url + to_country_id; 281 282 //$a_to_country = $('<a>').attr("href",href_to_country).append(pp_to_country); 283 $a_to_country = $('<a>').attr("href",href_to_country) 310 var $to_country_name = $('<div>').attr("class","voting voting-country").append(""); 311 var $to_country_points = $('<div>').attr("class","voting voting-points").append(""); 312 var $a_to_country = $('<span>'); 313 314 // if 'i' explicitly undefined, we are in one of the last-row gaps => nothing to do! 315 if (typeof i !== 'undefined') { 316 var pp_to_country = from_country_votes[i].Country; 317 var to_country = pp_to_country.replace(/\s+/g,""); 318 319 var to_country_points = from_country_votes[i].Points; 284 320 285 $to_country_name = $('<div>').attr("class","voting voting-country").append(pp_to_country).append(":"); 286 //$to_country_name = $('<div>').attr("class","voting voting-country").append($a_to_country).append(":"); 287 $to_country_points = $('<div>').attr("class","voting voting-points").append(to_country_points); 321 if (typeof to_country_points !== 'undefined') { 322 323 //var doc_id = gs.cgiParams["d"]; 324 //var hyphen_vote_type = doc_id.match(/-(?:T|J)$/); 325 var to_country_id = to_country + year; 326 var href_to_country = collect_doc_prefix_url + to_country_id; 327 328 //$a_to_country = $('<a>').attr("href",href_to_country).append(pp_to_country); 329 $a_to_country = $('<a>').attr("href",href_to_country) 330 331 $to_country_name = $('<div>').attr("class","voting voting-country").append(pp_to_country).append(":"); 332 //$to_country_name = $('<div>').attr("class","voting voting-country").append($a_to_country).append(":"); 333 $to_country_points = $('<div>').attr("class","voting voting-points").append(to_country_points); 334 } 288 335 } 289 } 290 291 //if ($a_to_country) { 336 292 337 $a_to_country 293 338 .append($to_country_name) … … 295 340 $('#from-country-votes') 296 341 .append($a_to_country); 297 ///}298 /*299 else {300 $('#from-country-votes')301 .append($to_country_name)302 .append($to_country_points);303 342 } 304 */305 343 } 306 344 }
Note:
See TracChangeset
for help on using the changeset viewer.