D3.js time.copy() Function

The time.copy() function in D3.js is used to construct and return the copy of the original scale. Changes done to the original scale will not affect the copy scale and vice-versa.

Syntax:

time.copy()

Parameters: This function does not accept any parameter.

Return Values: This function returns the copy of the original scale.

Below programs illustrate the time.copy() function in D3.js:



Example 1:

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <script src="https://d3js.org/d3.v4.min.js">
    </script>
    <script src="https://d3js.org/d3-color.v1.min.js">
    </script>
    <script src=
    </script>
    <script src=
    </script>
</head>
  
<body>
    <h1 style="color: green;">GeeksforGeeks</h1>
  
    <p>time.copy() Function </p>
  
    <script>
  
        var time = d3.scaleTime()
  
            // Setting domain and range
            // for the scale
            .domain([1, 100])
            .range([1, 10]);
  
        // Creating a copy of the scale
        var copy = time.copy();
  
        document.write("<h3>time(1): " +
            time(1) + "</h3>");
        document.write("<h3>time(100): " +
            time(100) + "</h3>");
        document.write("<p> copy scale: </p>");
          
    document.write("<h3>copy(100): " +
            copy(100) + "</h3>");
        document.write("<h3>copy(1): " +
            copy(1) + "</h3>");
    </script>
</body>
  
</html>

chevron_right


Output:

Example 2:

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <script src="https://d3js.org/d3.v4.min.js">
    </script>
    <script src="https://d3js.org/d3-color.v1.min.js">
    </script>
    <script src=
    </script>
    <script src=
    </script>
</head>
  
<body>
    <h1 style="color: green;">GeeksforGeeks</h1>
  
    <p>time.copy() Function </p>
  
    <script>
  
        var time = d3.scaleTime()
  
            // Setting domain and range
            // for the scale.
            .domain([1, 100])
            .range([1, 10]);
  
        // Creating a copy of the scale
        var copy = time.copy();
  
        document.write("<h3>time(1000): " +
            time(1000) + "</h3>");
        document.write("<h3>time(100000): " +
            time(10000) + "</h3>");
  
        // Using clamp on the copy of the scale
        document.write(
    "<p> copy scale with clamp function.</p>");
      
        copy.clamp(true);
        document.write("<h3>copy(1000): " +
            copy(1000) + "</h3>");
        document.write("<h3>copy(10000): " +
            copy(10000) + "</h3>");
    </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.