Monday, September 23, 2024
Google search engine
HomeLanguagesJavascriptD3.js time.copy() Function

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




<!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;">neveropen</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>


Output:

Example 2:

HTML




<!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;">neveropen</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>


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