Sunday, November 17, 2024
Google search engine
HomeLanguagesJavascriptD3.js band.copy() Function

D3.js band.copy() Function

The band.copy() function is used to construct and return the copy of the current scale with the same domain and range. Any changes made to any scale are independent of each other i.e change in original scale will not affect the copy scale and vice-versa.

Syntax:

band.copy();

Parameters: This function does not accept any parameter.

Return Values: This function returns a copy of the current scale. The return type is a function.

Below given are a few examples of the function given above.

Example 1:




<!DOCTYPE html> 
<html lang = "en"
<head
    <meta charset = "UTF-8" /> 
    <meta name = "viewport"
        path1tent = "width=device-width, 
        initial-scale = 1.0"/> 
    <script src =
    </script>
      
</head
<body
    <script
    // Creating the band scale 
    //with specified domain and range.
        var band = d3.scaleBand()
                    .domain([10, 20, 30, 40, 50])
                    .range([10, 100]);
    // Discrete values are automatically created 
    // By the band function
    // Band of the range is [10, 100]
        console.log("band(10): ", band(10));
        console.log("band(50): ", band(50));
  
        var bandCopy = band.copy();
        console.log("bandCopy(10): ", bandCopy(10));
        console.log("bandCopy(50): ", bandCopy(50));
    </script
</body
</html>


Output:

Example 2:




<!DOCTYPE html> 
<html lang = "en"
<head
    <meta charset = "UTF-8" /> 
    <meta name = "viewport"
        path1tent = "width=device-width, 
        initial-scale = 1.0"/> 
    <title>GeekforGeeks</title
    <script src =
    </script>
      
</head
<body
    <script
    // Creating the band scale
  // with specified domain and range.
        var band = d3.scaleBand()
                .domain([10, 20, 30, 40, 50])
                .range([1, 10]);
// Discrete values are automatically created 
    // By the band function
    // Band of the range is [1, 10]
        console.log(
"Before any type of change in original scale:");
        console.log("band(10): ", band(10));
        console.log("band(50): ", band(50));
        // Making copy of the original scale
        var bandCopy = band.copy();
        console.log(
"When the range of the original "+
"scale is changed to rangeRound:");
        // Making changes to the original scale
        band.rangeRound([1, 10]);
        console.log("band(10): ", band(10));
        console.log("band(50): ", band(50));
        console.log("Output of the copy scale:");
        console.log("bandCopy(10): ", bandCopy(10));
        console.log("bandCopy(50): ", bandCopy(50));
    </script
</body
</html>


Output:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments