D3.js threshold.copy() Function

The threshold.copy() function in d3.js is used to create and return the exact copy of the threshold scale. Any change in the original scale will not affect the copy scale.

Syntax:

threshold.copy();

Parameters: This function does not accept any parameter.

Return Value: This function returns an exact copy of the original threshold scale.

Example 1:



HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" path1tent=
        "width=device-width,initial-scale=1.0" />
  
    <script src="https://d3js.org/d3.v4.min.js">
    </script>
</head>
  
<body>
    <h2 style="color:green">GeekforGeeks</h2>
  
    <p>threshold.copy() Function </p>
  
    <script>
        var threshold = d3.scaleThreshold()
            // Domain
            .domain([1, 2, 3, 4])
            // Range for the domain
            .range([10, 20, 30, 40, 50]);
  
        document.write("<h3>threshold(1): " 
            + threshold(1) + "</h3>");
        document.write("<h3>threshold(3): " 
            + threshold(3) + "</h3>");
  
        document.write(
            "<p> This is from copy scale.</p>");
  
        var thresholdCopy = threshold.copy();
          
        document.write("<h3>thresholdCopy(1): " 
            + thresholdCopy(1) + "</h3>");
        document.write("<h3>thresholdCopy(3): " 
            + thresholdCopy(3) + "</h3>");
    </script>
</body>
  
</html>

chevron_right


Output:

Example 2:

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" path1tent=
        "width=device-width,initial-scale=1.0" />
  
    <script src="https://d3js.org/d3.v4.min.js">
    </script>
</head>
  
<body>
    <h2 style="color:green">GeekforGeeks</h2>
  
    <p>threshold.copy() Function </p>
  
    <script>
        var threshold = d3.scaleThreshold()
            // Domain
            .domain([1, 2, 3, 4])
            // Range for the domain
            .range([10, 20, 30, 40, 50]);
  
        var thresholdCopy = threshold.copy();
  
        document.write(
            "<div style=line-height:5px><h3>threshold(1): " 
            + threshold(1) + "</h3>");
  
        document.write("<h3>threshold(3): " 
                + threshold(3) + "</h3>");
  
        // Making changes on the original scale
        threshold.range([100, 200, 300, 400, 500]);
        document.write(
        "<p> After making changes in the original scale</p>");
  
        document.write("<h3>threshold(3): " 
                + threshold(3) + "</h3>");
  
        document.write("<p> This is from copy scale.</p>");
  
        document.write("<h3>thresholdCopy(1): " 
                + thresholdCopy(1) + "</h3>");
        document.write("<h3>thresholdCopy(3): " 
                + thresholdCopy(3) + "</h3></div>");
    </script>
</body>
  
</html>

chevron_right


Output:

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.