function updateLC(data, condition) {

    d3.select('#lcYlabel').selectAll('text').remove()

    if (condition == 'precip') {
        varName = 'Precipitation (cm)'
    } else if (condition == 'soilm') {
        varName = 'Soil Moisture (water / soil ratio)'
    } else if (condition == 'discharge') {
        varName = 'River Discharge (ft^3 / s)'
    }

    // y-axis label
    lcYlabel.append("text")
        .attr("transform", "rotate(-90)")
        .attr("y", 0 - margin.left)
        .attr("x", 0 - (height / 2))
        .attr("dy", "1em")
        .style("text-anchor", "middle")
        .text("Avg MRB " + varName);

    // set x-axis domain and transition
    x.domain([d3.min(data, function (d) { return d.date }), d3.max(data, function (d) { return d.date })]);
    svg.selectAll(".myXaxis").transition()
        .duration(1000)
        .call(xAxis);

    // create the Y axis
    y.domain([d3.min(data, function (d) { return d.var }), d3.max(data, function (d) { return d.var })]);
    svg.selectAll(".myYaxis")
        .transition()
        .duration(1000)
        .call(yAxis);


    // Create a update selection: bind to the new data
    var u = svg.selectAll(".lineTest")
        .data([data], function (d) { return d.date });

    // Update the line
    u.enter()
        .append("path")
        .attr("class", "lineTest")
        .merge(u)
        .transition()
        .duration(1000)
        .attr("d", d3.line()
            .x(function (d) { return x(d.date); })
            .y(function (d) { return y(d.var); }))
        .attr("fill", "none")
        .attr("stroke", "steelblue")
        .attr("stroke-width", 2.5)

    //defines the points
    let p = svg.selectAll("circle")
        .data(data);

    // create tooltip div
    let div = d3.select("body").append("div")
        .attr("class", "tooltip")
        .style("opacity", 0)
        .style("border-width", "5px")
        .style("border-radius", "7px")

    //months to use in tool tip
    var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

    //updates the points when new graph is shown 
    p.enter()
        .append("circle")
        .merge(p)
        .transition()
        .duration(1000)
        .attr("fill", "black")
        .attr("stroke", "none")
        .attr("cx", function (d) { return x(Date.parse(d.date)) })
        .attr("cy", function (d) { return y(parseFloat(d.var)) })
        .attr("r", 3.5)
    p.on("click", function (event, d) {
        div.transition()
            .duration(200)
            .style("opacity", .9);
        if (condition != "discharge") {
            tooltipNum = parseFloat(d.var).toFixed(3);
        }
        else {
            tooltipNum = parseFloat(d.var);
        }
        div.html(months[new Date(d.date).getMonth()] + " "
            + new Date(d.date).getUTCFullYear() + "<br/>" + condition + ": " +
            tooltipNum)
            .style("left", (event.pageX) + "px")
            .style("top", (event.pageY - 20) + "px");
    }).on("mouseout", function (d) {
        div.transition()
            .duration(4000)
            .style("opacity", 0);
    });
}
// Create a function that takes a dataset as input and update the plot:
Create a function that takes a dataset as input and update the plot.
Create a function that takes a dataset as input and update the plot .
function updateLC(data, condition) {
    d3.select('#lcYlabel').selectAll('text').remove()
    if (condition == 'precip') {
        varName = 'Precipitation (cm)'
    } else if (condition == 'soilm') {
        varName = 'Soil Moisture (water / soil ratio)'
    } else if (condition == 'discharge') {
        varName = 'River Discharge (ft^3 / s)'
    }
    lcYlabel.append("text")
        .attr("transform", "rotate(-90)")
        .attr("y", 0 - margin.left)
        .attr("x", 0 - (height / 2))
        .attr("dy", "1em")
        .style("text-anchor", "middle")
        .text("Avg MRB " + varName);
    x.domain([d3.min(data, function (d) { return d.date }), d3.max(data, function (d) { return d.date })]);
    svg.selectAll(".myXaxis").transition()
        .duration(1000)
        .call(xAxis);
    y.domain([d3.min(data, function (d) { return d.var }), d3.max(data, function (d) { return d.var })]);
    svg.selectAll(".myYaxis")
        .transition()
        .duration(1000)
        .call(yAxis);
    var u = svg.selectAll(".lineTest")
        .data([data], function (d) { return d.date });
    u.enter()
        .append("path")
        .attr("class", "lineTest")
        .merge(u)
        .transition()
        .duration(1000)
        .attr("d", d3.line()
            .x(function (d) { return x(d.date); })
            .y(function (d) { return y(d.var); }))
        .attr("fill", "none")
        .attr("stroke", "steelblue")
        .attr("stroke-width", 2.5)
    let p = svg.selectAll("circle")
        .data(data);
    let div = d3.select("body").append("div")
        .attr("class", "tooltip")
        .style("opacity", 0)
        .style("border-width", "5px")
        .style("border-radius", "7px")
    var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
    p.enter()
        .append("circle")
        .merge(p)
        .transition()
        .duration(1000)
        .attr("fill", "black")
        .attr("stroke", "none")
        .attr("cx", function (d) { return x(Date.parse(d.date)) })
        .attr("cy", function (d) { return y(parseFloat(d.var)) })
        .attr("r", 3.5)
    p.on("click", function (event, d) {
        div.transition()
            .duration(200)
            .style("opacity", .9);
        if (condition != "discharge") {
            tooltipNum = parseFloat(d.var).toFixed(3);
        }
        else {
            tooltipNum = parseFloat(d.var);
        }
        div.html(months[new Date(d.date).getMonth()] + " "
            + new Date(d.date).getUTCFullYear() + "<br/>" + condition + ": " +
            tooltipNum)
            .style("left", (event.pageX) + "px")
            .style("top", (event.pageY - 20) + "px");
    }).on("mouseout", function (d) {
        div.transition()
            .duration(4000)
            .style("opacity", 0);
    });
}
function updateLC ( data , condition ) { d3 . select ( '#lcYlabel' ) . selectAll ( 'text' ) . remove ( ) if ( condition == 'precip' ) { varName = 'Precipitation (cm)' } else if ( condition == 'soilm' ) { varName = 'Soil Moisture (water / soil ratio)' } else if ( condition == 'discharge' ) { varName = 'River Discharge (ft^3 / s)' } lcYlabel . append ( "text" ) . attr ( "transform" , "rotate(-90)" ) . attr ( "y" , 0 - margin . left ) . attr ( "x" , 0 - ( height / 2 ) ) . attr ( "dy" , "1em" ) . style ( "text-anchor" , "middle" ) . text ( "Avg MRB " + varName ) ; x . domain ( [ d3 . min ( data , function ( d ) { return d . date } ) , d3 . max ( data , function ( d ) { return d . date } ) ] ) ; svg . selectAll ( ".myXaxis" ) . transition ( ) . duration ( 1000 ) . call ( xAxis ) ; y . domain ( [ d3 . min ( data , function ( d ) { return d . var } ) , d3 . max ( data , function ( d ) { return d . var } ) ] ) ; svg . selectAll ( ".myYaxis" ) . transition ( ) . duration ( 1000 ) . call ( yAxis ) ; var u = svg . selectAll ( ".lineTest" ) . data ( [ data ] , function ( d ) { return d . date } ) ; u . enter ( ) . append ( "path" ) . attr ( "class" , "lineTest" ) . merge ( u ) . transition ( ) . duration ( 1000 ) . attr ( "d" , d3 . line ( ) . x ( function ( d ) { return x ( d . date ) ; } ) . y ( function ( d ) { return y ( d . var ) ; } ) ) . attr ( "fill" , "none" ) . attr ( "stroke" , "steelblue" ) . attr ( "stroke-width" , 2.5 ) let p = svg . selectAll ( "circle" ) . data ( data ) ; let div = d3 . select ( "body" ) . append ( "div" ) . attr ( "class" , "tooltip" ) . style ( "opacity" , 0 ) . style ( "border-width" , "5px" ) . style ( "border-radius" , "7px" ) var months = [ "January" , "February" , "March" , "April" , "May" , "June" , "July" , "August" , "September" , "October" , "November" , "December" ] ; p . enter ( ) . append ( "circle" ) . merge ( p ) . transition ( ) . duration ( 1000 ) . attr ( "fill" , "black" ) . attr ( "stroke" , "none" ) . attr ( "cx" , function ( d ) { return x ( Date . parse ( d . date ) ) } ) . attr ( "cy" , function ( d ) { return y ( parseFloat ( d . var ) ) } ) . attr ( "r" , 3.5 ) p . on ( "click" , function ( event , d ) { div . transition ( ) . duration ( 200 ) . style ( "opacity" , .9 ) ; if ( condition != "discharge" ) { tooltipNum = parseFloat ( d . var ) . toFixed ( 3 ) ; } else { tooltipNum = parseFloat ( d . var ) ; } div . html ( months [ new Date ( d . date ) . getMonth ( ) ] + " " + new Date ( d . date ) . getUTCFullYear ( ) + "<br/>" + condition + ": " + tooltipNum ) . style ( "left" , ( event . pageX ) + "px" ) . style ( "top" , ( event . pageY - 20 ) + "px" ) ; } ) . on ( "mouseout" , function ( d ) { div . transition ( ) . duration ( 4000 ) . style ( "opacity" , 0 ) ; } ) ; }
Create a function that takes a dataset as input and update the plot:
Create a function that takes a dataset as input and update the plot :
// y-axis label // set x-axis domain and transition // create the Y axis // Create a update selection: bind to the new data // Update the line //defines the points // create tooltip div //months to use in tool tip //updates the points when new graph is shown 