D3.js | d3.continuous.clamp() Function

The d3.continuous.clamp() function in D3.js is used to enable or disable the clamp. If the clamp is disabled then the range of domain’s value might be out of range but if the clamp is enabled then the range of domain’s value will always be in range.

Syntax:

continuous.clamp( Value )

Parameters: This function accept single parameter Value which is either true or false.



Return Value: This function does not return any value.

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

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        D3.js | d3.continuous.clamp() Function
    </title>
  
    <script src=
        "https://d3js.org/d3.v4.min.js">
    </script>
</head>
  
<body>
    <script>
  
        // Calling the .scaleLinear() function
        var x = d3.scaleLinear()
            .domain([10, 100])
            .range([0, 5]);
  
        // Calling the .clamp() function          
        x.clamp(false);
  
        // Calling continuous() and .invert() function
        var A = x(6);
        var B = x.invert(10);
        console.log(A);
        console.log(B);
    </script>
</body>
  
</html>

chevron_right


Output:

-0.22222222222222224
190

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        D3.js | d3.continuous.clamp() Function
    </title>
  
    <script src=
        "https://d3js.org/d3.v4.min.js">
    </script>
</head>
  
<body>
    <script>
  
        // Calling the .scaleLinear() function
        var x = d3.scaleLinear()
            .domain([10, 100])
            .range([0, 5]);
  
        // Calling the .clamp() function          
        x.clamp(true);
  
        // Calling continuous() and .invert() function
        var A = x(6);
        var B = x.invert(10);
        console.log(A);
        console.log(B);
    </script>
</body>
  
</html>

chevron_right


Output:

0
100

Reference: https://devdocs.io/d3~5/d3-scale#continuous_clamp



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.