StarterCode/assets/js/app.js
// Function used for updating circles group with new tooltip.
Function used for updating circles group with new tooltip.
Function used for updating circles group with new tooltip .
function updateToolTip(chosenXAxis, chosenYAxis, circlesGroup) {
    var xLabel;
    var yLabel;
    if (chosenXAxis === "poverty") {
        xLabel = "Poverty: ";
    }
    else if (chosenXAxis === "income") {
        xLabel = "Median Income: "
    }
    else {
        xLabel = "Age: "
    }
    if (chosenYAxis === "healthcare") {
        yLabel = "Lacks Healthcare: ";
    }
    else if (chosenYAxis === "smokes") {
        yLabel = "Smokers: "
    }
    else {
        yLabel = "Obesity: "
    }
    var toolTip = d3.tip()
        .attr("class", "tooltip")
        .style("background", "white")
        .offset([80, -60])
        .html(function(d) {
            return (`${d.state}<br>${xLabel}: ${yLabel}`);     
        });
    circlesGroup.call(toolTip);
    circlesGroup
        .on("mouseover", function(data) {
            toolTip.show(data);
        })
        .on("mouseout", function(data, index) {
             toolTip.hide(data)
        });
        return circlesGroup;
    }
function updateToolTip ( chosenXAxis , chosenYAxis , circlesGroup ) { var xLabel ; var yLabel ; if ( chosenXAxis === "poverty" ) { xLabel = "Poverty: " ; } else if ( chosenXAxis === "income" ) { xLabel = "Median Income: " } else { xLabel = "Age: " } if ( chosenYAxis === "healthcare" ) { yLabel = "Lacks Healthcare: " ; } else if ( chosenYAxis === "smokes" ) { yLabel = "Smokers: " } else { yLabel = "Obesity: " } var toolTip = d3 . tip ( ) . attr ( "class" , "tooltip" ) . style ( "background" , "white" ) . offset ( [ 80 , - 60 ] ) . html ( function ( d ) { return ( ` ${ d . state } ${ xLabel } ${ yLabel } ` ) ; } ) ; circlesGroup . call ( toolTip ) ; circlesGroup . on ( "mouseover" , function ( data ) { toolTip . show ( data ) ; } ) . on ( "mouseout" , function ( data , index ) { toolTip . hide ( data ) } ) ; return circlesGroup ; }
Function used for updating circles group with new tooltip.
Function used for updating circles group with new tooltip .
// Conditional for X Axis. // Conditional for Y Axis. // Step 6: Initialize tool tip // Create "mouseover"/"mouseout" event listeners for tool tip.