D3.js中的time.clamp()函數用於啟用或禁用鉗位。如果禁用鉗位,則返回值的範圍可能超出給定範圍。
用法:
time.clamp( clamp )
參數:此函數僅接受上麵給出的和下麵描述的一個參數:
- clamp:它是一個布爾值,定義了啟用還是禁用鉗位。
返回值:此函數不返回任何內容。
以下示例程序旨在說明D3.js中的time.clamp()函數:
範例1:當鉗位設置為假時。
HTML
<!DOCTYPE html>
<html>
<head>
<script src="https://d3js.org/d3.v4.min.js">
</script>
<script src=
"https://d3js.org/d3-color.v1.min.js">
</script>
<script src=
"https://d3js.org/d3-interpolate.v1.min.js">
</script>
<script src=
"https://d3js.org/d3-scale-chromatic.v1.min.js">
</script>
</head>
<body>
<h1 style="color:green">GeeksforGeeks</h1>
<p>time.clamp() Function </p>
<script>
var time = d3.scaleTime()
// Setting domain for the scale.
.domain([1, 100])
.range([1, 10])
.clamp(false);
document.write("<h3>time(900):" +
time(900) + "</h3>");
document.write("<h3>time(100.5):" +
time(100.5) + "</h3>");
document.write("<h3>time(888):" +
time(888) + "</h3>");
document.write("<h3>time(150):" +
time(150) + "</h3>");
</script>
</body>
</html>
輸出:
範例2:鉗位設置為true時。
HTML
<!DOCTYPE html>
<html>
<head>
<script src="https://d3js.org/d3.v4.min.js">
</script>
<script src=
"https://d3js.org/d3-color.v1.min.js">
</script>
<script src=
"https://d3js.org/d3-interpolate.v1.min.js">
</script>
<script src=
"https://d3js.org/d3-scale-chromatic.v1.min.js">
</script>
</head>
<body>
<h1 style="color:green">GeeksforGeeks</h1>
<p>time.clamp() Function </p>
<script>
var time = d3.scaleTime()
// Setting domain for the scale.
.domain([1, 100])
.range([1, 10])
.clamp(true);
document.write("<h3>time(900):"
+ time(900) + "</h3>");
document.write("<h3>time(100.5):"
+ time(100.5) + "</h3>");
document.write("<h3>time(888):"
+ time(888) + "</h3>");
document.write("<h3>time(150):"
+ time(150) + "</h3>");
</script>
</body>
</html>
輸出:
相關用法
- PHP Ds\Set add()用法及代碼示例
- PHP each()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- PHP Ds\Set first()用法及代碼示例
- PHP Ds\Set last()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- p5.js pan()用法及代碼示例
- p5.js value()用法及代碼示例
- PHP Ds\Map xor()用法及代碼示例
- PHP Ds\Set contains()用法及代碼示例
- PHP Ds\Set xor()用法及代碼示例
- d3.js lch()用法及代碼示例
- d3.js d3.max()用法及代碼示例
- p5.js hue()用法及代碼示例
- p5.js min()用法及代碼示例
- p5.js red()用法及代碼示例
注:本文由純淨天空篩選整理自tarun007大神的英文原創作品 D3.js time.clamp() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。