Saturday, November 22, 2025
HomeLanguagesJavascriptD3.js log.clamp() Function

D3.js log.clamp() Function

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:

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

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6784 POSTS0 COMMENTS
Nicole Veronica
11931 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11999 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6863 POSTS0 COMMENTS
Umr Jansen
6848 POSTS0 COMMENTS