D3.js time.copy() Function
Last Updated :
23 Aug, 2020
The time.copy() function in D3.js is used to construct and return the copy of the original scale. Changes done to the original scale will not affect the copy scale and vice-versa.
Syntax:
time.copy()
Parameters: This function does not accept any parameter.
Return Values: This function returns the copy of the original scale.
Below programs illustrate the time.copy() function in D3.js:
Example 1:
HTML
<!DOCTYPE html>
< html >
< head >
</ script >
</ script >
< script src =
</ script >
< script src =
</ script >
</ head >
< body >
< h1 style = "color: green;" >GeeksforGeeks</ h1 >
< p >time.copy() Function </ p >
< script >
var time = d3.scaleTime()
// Setting domain and range
// for the scale
.domain([1, 100])
.range([1, 10]);
// Creating a copy of the scale
var copy = time.copy();
document.write("< h3 >time(1): " +
time(1) + "</ h3 >");
document.write("< h3 >time(100): " +
time(100) + "</ h3 >");
document.write("< p > copy scale: </ p >");
document.write("< h3 >copy(100): " +
copy(100) + "</ h3 >");
document.write("< h3 >copy(1): " +
copy(1) + "</ h3 >");
</ script >
</ body >
</ html >
|
Output:
Example 2:
HTML
<!DOCTYPE html>
< html >
< head >
</ script >
</ script >
< script src =
</ script >
< script src =
</ script >
</ head >
< body >
< h1 style = "color: green;" >GeeksforGeeks</ h1 >
< p >time.copy() Function </ p >
< script >
var time = d3.scaleTime()
// Setting domain and range
// for the scale.
.domain([1, 100])
.range([1, 10]);
// Creating a copy of the scale
var copy = time.copy();
document.write("< h3 >time(1000): " +
time(1000) + "</ h3 >");
document.write("< h3 >time(100000): " +
time(10000) + "</ h3 >");
// Using clamp on the copy of the scale
document.write(
"< p > copy scale with clamp function.</ p >");
copy.clamp(true);
document.write("< h3 >copy(1000): " +
copy(1000) + "</ h3 >");
document.write("< h3 >copy(10000): " +
copy(10000) + "</ h3 >");
</ script >
</ body >
</ html >
|
Output:
Share your thoughts in the comments
Please Login to comment...