D3.js | d3.continuous.clamp() Function
Last Updated :
31 Jul, 2019
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:
<!DOCTYPE html>
<html>
<head>
<title>
D3.js | d3.continuous.clamp() Function
</title>
<script src=
</script>
</head>
<body>
<script>
var x = d3.scaleLinear()
.domain([10, 100])
.range([0, 5]);
x.clamp( false );
var A = x(6);
var B = x.invert(10);
console.log(A);
console.log(B);
</script>
</body>
</html>
|
Output:
-0.22222222222222224
190
Example 2:
<!DOCTYPE html>
<html>
<head>
<title>
D3.js | d3.continuous.clamp() Function
</title>
<script src=
</script>
</head>
<body>
<script>
var x = d3.scaleLinear()
.domain([10, 100])
.range([0, 5]);
x.clamp( true );
var A = x(6);
var B = x.invert(10);
console.log(A);
console.log(B);
</script>
</body>
</html>
|
Output:
0
100
Reference: https://devdocs.io/d3~5/d3-scale#continuous_clamp
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...