js/table.js
/* Redraws the table when it has been sorted by weight. */
Redraws the table when it has been sorted by weight.
Redraws the table when it has been sorted by weight .
redrawWeights(that) {
        function weightMap(weight) {
            if (weight == "N/A" && that.weightSortDown) {
                return Infinity;
            }
            else if (weight == "N/A" && !that.weightSortDown) {
                return -Infinity; 
            }
            else {
                return +weight;
            }
        }
        that.deleteTable();
        let sortedByWeight = that.latestWeights.sort(function (a, b) {
            let returnValue = 0;
            if (that.weightSortDown) {
                returnValue = weightMap(a[0]) - weightMap(b[0]);
            }
            else {
                returnValue = weightMap(b[0]) - weightMap(a[0]);
            }
            return returnValue;
        });
        let countryRow = d3.select("#tableBody")
            .selectAll("tr")
            .data(sortedByWeight)
            .enter()
            .append("tr")
            .classed("tableRow", true);
        countryRow.append("td")
            .text(function (d, i) {
                return d[1];
            })
            .on("click", d => that.selectCountryFromTuple(d, that))
            .classed("countryNameTd", true);
        countryRow.append("td").text(function (d, i) {
            return d[0];
        });
    }
redrawWeights ( that ) { function weightMap ( weight ) { if ( weight == "N/A" && that . weightSortDown ) { return Infinity ; } else if ( weight == "N/A" && ! that . weightSortDown ) { return - Infinity ; } else { return + weight ; } } that . deleteTable ( ) ; let sortedByWeight = that . latestWeights . sort ( function ( a , b ) { let returnValue = 0 ; if ( that . weightSortDown ) { returnValue = weightMap ( a [ 0 ] ) - weightMap ( b [ 0 ] ) ; } else { returnValue = weightMap ( b [ 0 ] ) - weightMap ( a [ 0 ] ) ; } return returnValue ; } ) ; let countryRow = d3 . select ( "#tableBody" ) . selectAll ( "tr" ) . data ( sortedByWeight ) . enter ( ) . append ( "tr" ) . classed ( "tableRow" , true ) ; countryRow . append ( "td" ) . text ( function ( d , i ) { return d [ 1 ] ; } ) . on ( "click" , d => that . selectCountryFromTuple ( d , that ) ) . classed ( "countryNameTd" , true ) ; countryRow . append ( "td" ) . text ( function ( d , i ) { return d [ 0 ] ; } ) ; }
Redraws the table when it has been sorted by weight.
Redraws the table when it has been sorted by weight .
/* Maps all possible weight values (not just numbers) to appropriate 
        values that can be numerically sorted. */ //Put N/As at the bottom in either case