Open In App

D3.js threshold.copy() Function

Last Updated : 23 Aug, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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




<!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>


Output:

Example 2:

HTML




<!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>


Output:



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads