Skip to content
Related Articles

Related Articles

D3.js time.clamp() Function
  • Last Updated : 23 Aug, 2020

The time.clamp() function in D3.js is used to enable or disable the clamp. If the clamp is disabled then the range of the return value may be outside the given range.

Syntax:

time.clamp( clamp )

Parameters: This function accepts only one parameter as given above and described below:

  • clamp: It is a boolean value that defines if the clamp is enabled or disabled.

Return Values: This function does not return anything.

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



Example 1: When the clamp is set to false.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script src="https://d3js.org/d3.v4.min.js">
    </script>
    <script src=
    </script>
    <script src=
    </script>
    <script src=
    </script>
</head>
  
<body>
    <h1 style="color: green">GeeksforGeeks</h1>
  
    <p>time.clamp() Function </p>
  
    <script>
  
        var time = d3.scaleTime()
            // Setting domain for the scale.
            .domain([1, 100])
            .range([1, 10])
            .clamp(false);
  
        document.write("<h3>time(900): " +
            time(900) + "</h3>");
        document.write("<h3>time(100.5): " +
            time(100.5) + "</h3>");
        document.write("<h3>time(888): " +
            time(888) + "</h3>");
        document.write("<h3>time(150): " +
            time(150) + "</h3>");
    </script>
</body>
  
</html>

Output:

Example 2: When clamp is set to true.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script src="https://d3js.org/d3.v4.min.js">
    </script>
    <script src=
    </script>
    <script src=
    </script>
    <script src=
    </script>
</head>
  
<body>
    <h1 style="color: green">GeeksforGeeks</h1>
  
    <p>time.clamp() Function </p>
  
    <script>
  
        var time = d3.scaleTime()
            // Setting domain for the scale.
            .domain([1, 100])
            .range([1, 10])
            .clamp(true);
  
        document.write("<h3>time(900): "
            + time(900) + "</h3>");
        document.write("<h3>time(100.5): "
            + time(100.5) + "</h3>");
        document.write("<h3>time(888): "
            + time(888) + "</h3>");
        document.write("<h3>time(150): "
            + time(150) + "</h3>");
    </script>
</body>
  
</html>

Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :