Wednesday, July 3, 2024
HomeLanguagesJavascriptD3.js threshold.copy() Function

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




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

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!

Thapelo Manthata
I’m a desktop support specialist transitioning into a SharePoint developer role by day and Software Engineering student by night. My superpowers include customer service, coding, the Microsoft office 365 suite including SharePoint and power platform.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments