D3.js中的d3.continuous.clamp()函數用於啟用或禁用鉗位。如果禁用鉗位,則域值的範圍可能超出範圍,但是如果啟用鉗位,則域值的範圍將始終在範圍之內。
用法:
continuous.clamp( Value )
參數:該函數接受單個參數值,該值可以為true或false。
返回值:該函數不返回任何值。
以下程序說明了D3.js中的d3.continuous.clamp()函數:
範例1:
<!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>輸出:
-0.22222222222222224 190
範例2:
<!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>輸出:
0 100
參考: https://devdocs.io/d3~5/d3-scale#continuous_clamp
相關用法
- p5.js tan()用法及代碼示例
 - p5.js second()用法及代碼示例
 - p5.js sin()用法及代碼示例
 - PHP cos( )用法及代碼示例
 - CSS var()用法及代碼示例
 - p5.js day()用法及代碼示例
 - PHP sin( )用法及代碼示例
 - PHP pos()用法及代碼示例
 - PHP key()用法及代碼示例
 - PHP abs()用法及代碼示例
 - PHP Ds\Map put()用法及代碼示例
 - d3.js d3.sum()用法及代碼示例
 
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 D3.js | d3.continuous.clamp() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
