Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

D3.js log.clamp() Function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The log.clamp() function is used to enable the clamp or disable the clamp. If the clamp is disabled then the range of the return value may be outside the given range through extrapolation.

Syntax:

log.clamp(clamp);

Parameters: This function accepts single parameter as mentioned above and described below.

  • clamp: A boolean value.

Return Value: This function does not return any value.

Example 1: When the clamp is false.

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>log.clamp() Function</p>
  
    <script>
        // Calling the .scaleLog() function 
        var log = d3.scaleLog()
            .domain([1, 100])
            .range([0, 960])
            .clamp(false);
  
        // Calling log() and .invert() function 
        var a = log(10);
        var b = log.invert(1000);
        document.write("<h3>" + a + "</h3>");
        document.write("<h3>" + b + "</h3>");
    </script>
</body>
  
</html>

Output: 

Example 2: When the clamp is true.

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>log.clamp() Function</p>
  
    <script>
        // Calling the .scaleLog() function 
        var log = d3.scaleLog()
            .domain([1, 100])
            .range([0, 960])
            .clamp(true);
  
        // Calling log() and .invert() function 
        var a = log(10);
        var b = log.invert(1000);
        document.write("<h3>" + a + "</h3>");
        document.write("<h3>" + b + "</h3>");
    </script>
</body>
  
</html>

Output:


My Personal Notes arrow_drop_up
Last Updated : 23 Aug, 2020
Like Article
Save Article
Similar Reads
Related Tutorials