function update(nBin) {

    // set the parameters for the histogram
    const histogram = d3.histogram()
        .value(function(d) { return d.minutes; })   // I need to give the vector of value
        .domain(x_hist.domain())  // then the domain of the graphic
        .thresholds(x_hist.ticks(nBin)); // then the numbers of bins

    // And apply this function to data to get the bins
    const bins = histogram(data_hist);

    // Y axis: update now that we know the domain
    y_hist.domain([0, d3.max(bins, function(d) { return d.length; })]);   // d3.hist has to be called before the Y axis obviously
    yAxis_hist
        .transition()
        .duration(1000)
        .call(d3.axisLeft(y_hist));

    // Join the rect with the bins data
    const u = svg_hist.selectAll("rect")
        .data(bins);

    // Manage the existing bars and eventually the new ones:
    u
        .join("rect") // Add a new rect for each new elements
        .transition() // and apply changes to all of them
        .duration(1000)
          .attr("x", 1)
          .attr("transform", function(d) { return `translate(${x_hist(d.x0)}, ${y_hist(d.length)})`})
          .attr("width", function(d) { return x_hist(d.x1) - x_hist(d.x0) -1 ; })
          .attr("height", function(d) { return height_hist - y_hist(d.length); })
          .style("fill", "#69b3a2");

    }
// A function that builds the graph for a specific value of bin
A function that builds the graph for a specific value of bin
A function that builds the graph for a specific value of bin
function update(nBin) {
    const histogram = d3.histogram()
        .value(function(d) { return d.minutes; })   
        .domain(x_hist.domain())  
        .thresholds(x_hist.ticks(nBin)); 
    const bins = histogram(data_hist);
    y_hist.domain([0, d3.max(bins, function(d) { return d.length; })]);   
    yAxis_hist
        .transition()
        .duration(1000)
        .call(d3.axisLeft(y_hist));
    const u = svg_hist.selectAll("rect")
        .data(bins);
    u
        .join("rect") 
        .transition() 
        .duration(1000)
          .attr("x", 1)
          .attr("transform", function(d) { return `translate(${x_hist(d.x0)}, ${y_hist(d.length)})`})
          .attr("width", function(d) { return x_hist(d.x1) - x_hist(d.x0) -1 ; })
          .attr("height", function(d) { return height_hist - y_hist(d.length); })
          .style("fill", "#69b3a2");
    }
function update ( nBin ) { const histogram = d3 . histogram ( ) . value ( function ( d ) { return d . minutes ; } ) . domain ( x_hist . domain ( ) ) . thresholds ( x_hist . ticks ( nBin ) ) ; const bins = histogram ( data_hist ) ; y_hist . domain ( [ 0 , d3 . max ( bins , function ( d ) { return d . length ; } ) ] ) ; yAxis_hist . transition ( ) . duration ( 1000 ) . call ( d3 . axisLeft ( y_hist ) ) ; const u = svg_hist . selectAll ( "rect" ) . data ( bins ) ; u . join ( "rect" ) . transition ( ) . duration ( 1000 ) . attr ( "x" , 1 ) . attr ( "transform" , function ( d ) { return ` ${ x_hist ( d . x0 ) } ${ y_hist ( d . length ) } ` } ) . attr ( "width" , function ( d ) { return x_hist ( d . x1 ) - x_hist ( d . x0 ) - 1 ; } ) . attr ( "height" , function ( d ) { return height_hist - y_hist ( d . length ) ; } ) . style ( "fill" , "#69b3a2" ) ; }
A function that builds the graph for a specific value of bin
A function that builds the graph for a specific value of bin
// set the parameters for the histogram // I need to give the vector of value // then the domain of the graphic // then the numbers of bins // And apply this function to data to get the bins // Y axis: update now that we know the domain // d3.hist has to be called before the Y axis obviously // Join the rect with the bins data // Manage the existing bars and eventually the new ones: // Add a new rect for each new elements // and apply changes to all of them