The continuous.copy() function is used to create and return an exact copy of the given scale. Any change in the original scale will not affect the return scale and vice-versa.
Syntax:
continuous.copy();
Parameters: This function does not accept any parameters.
Return Value: This function returns a copy of original scale.
Below examples illustrate the continuous.copy() function in D3.js:
Example 1:
HTML
<!DOCTYPE html> <html lang="en"> Â Â <head> Â Â Â Â <meta charset="UTF-8"/> Â Â Â Â <meta name="viewport" path1tent= Â Â Â Â Â Â Â Â "width=device-width, initial-scale=1.0"/> Â Â Â Â </script> Â Â Â Â <script src= Â Â Â Â </script> Â Â Â Â <script src= Â Â Â Â </script> Â Â Â Â <script src= Â Â Â Â </script> </head> Â Â <body> Â Â Â Â <h2 style="color:green;">Geeks for neveropen</h2> Â Â Â Â Â Â <p>continuous.copy() Function </p> Â Â Â Â Â Â <script> Â Â Â Â Â Â Â Â var x = d3.scaleLinear() Â Â Â Â Â Â Â Â Â Â Â Â .domain([0, 1]) Â Â Â Â Â Â Â Â Â Â Â Â .range([1, 2, 3, 4, 5, 6]) Â Â Â Â Â Â Â Â Â Â var copy = x.copy(); Â Â Â Â Â Â Â Â document.write("</br>"); Â Â Â Â Â Â Â Â document.write("<p> This is from original: "); Â Â Â Â Â Â Â Â document.write("<h3>" + x(0.5144) + "</h3>"); Â Â Â Â Â Â Â Â document.write("<p> This is a copy of original: "); Â Â Â Â Â Â Â Â document.write("<h3>" + copy(0.5144) + "</h3>"); Â Â Â Â </script> </body> Â Â </html> |
Output:
Example 2:
HTML
<!DOCTYPE html> <html lang="en">   <head>     <meta charset="UTF-8" />     <meta name="viewport" path1tent="width=device-width,         initial-scale=1.0" />     <title>Geeks for neveropen</title>     </script>     </script>     <script src=     </script>     <script src=     </script> </head>   <body>     <h2>Geeks for neveropen</h2>       <p>continuous.copy() Function </p>       <script>         var x = d3.scaleLinear()             .domain([0, 1])             .range([1, 2, 3, 4, 5, 6])           var copy = x.copy()             .interpolate(d3.interpolateRound);                       document.write("</br>");         document.write("This is from original: ");         document.write("<h3>" + x(0.5144) + "</h3>");         document.write("This is a copy of original: ");         document.write("<h3>" + copy(0.5144) + "</h3>");     </script> </body>   </html> |
Output:

