Skip to content
Related Articles

Related Articles

Improve Article
D3.js point.copy() Function
  • Last Updated : 24 Aug, 2020

The point.copy() function is used to construct and return the copy of the current scale. Any changes made to either scale is independent of each other i.e change in copy scale will not affect the original scale and vice-versa.

Syntax:

point.copy();

Parameters: This function does not accept any parameter.

Return Values: This function returns a copy of the current scale. The return type is a function.

Below given are a few examples of the function given above.



Example 1:




<!DOCTYPE html> 
<html lang = "en"
<head
    <meta charset = "UTF-8" /> 
    <meta name = "viewport"
        path1tent = "width=device-width, 
        initial-scale = 1.0"/> 
    <title>GeekforGeeks</title
    <script src =
    </script>
      
</head
<body
    <script
// Creating the point scale with specified domain and range.
        var point = d3.scalePoint()
                    .domain([1, 2, 3, 4])
                    .range([1, 5]);
        var copyScale = point.copy();
        console.log("From original scale: ");
        console.log("point(1): ", point(1));
        console.log("point(2): ", point(2));
        console.log("From copy scale: ");
        console.log("copyScale(1): ", copyScale(1));
        console.log("copyScale(2): ", copyScale(2));
          
    </script
</body
</html>

Output:

Example 2:




<!DOCTYPE html> 
<html lang = "en"
<head
    <meta charset = "UTF-8" /> 
    <meta name = "viewport"
        path1tent = "width=device-width, 
        initial-scale = 1.0"/> 
    <title>GeekforGeeks</title
    <script src =
    </script>
      
</head
<body
    <script
// Creating the point scale with specified domain and range.
        var point = d3.scalePoint()
                    .domain([1, 2, 3, 4])
                    .range([1, 5]);
  
        console.log("From original scale befire making changes: ");
        console.log("point(1): ", point(1));
        console.log("point(2): ", point(2));
        // Making copy of the original scale
        var copyScale = point.copy();
        point.round([1, 5]);
        console.log("From original scale after making changes: ");
        console.log("point(1): ", point(1));
        console.log("point(2): ", point(2));
  
        console.log("From copy scale: ");
        // Changes in original scale does not
        // Affect copy scale
        console.log("copyScale(1): ", copyScale(1));
        console.log("copyScale(2): ", copyScale(2));
          
    </script
</body
</html>

Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :