Skip to content
Related Articles

Related Articles

Improve Article
D3.js diverging.copy() Function
  • Last Updated : 07 Sep, 2020

The diverging scales are very much similar to continuous scales. The only difference is that the output range of this scale is fixed by the interpolator thus the range is not configurable.

The diverging.copy() function in d3.js is used to construct and return the exact copy of the original scale. Any change in the original scale does not affect the copy scale and vice-versa.

Syntax:

diverging.copy();

Parameters: This function does not take any parameters.

Return Values: This function return the copy of the original scale.



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
<style>
</style>
<body
    <h2 style="color:green"> GeeksforGeeks </h2>
    <h4> D3.js | diverging.copy() Function </h4>
    <script
        var diverging = 
d3.scaleDiverging(d3.interpolateSpectral);
        // Default domain is used i.e [0, 1]
        document.write(
        "<b>From original scale: </b>");
        document.write(
"<p>diverging(0.1): ", diverging(0.1) + "</p>");
        document.write(
"<p>diverging(0.2): ", diverging(0.2) + "</p>");
        document.write(
"<p>diverging(0.3): ", diverging(0.3) + "</p>");
        document.write("<b>From copy scale: </b>");
        var divergingCopy = diverging.copy();
        document.write(
"<p>divergingCopy(0.1): ", divergingCopy(0.1) + "</p>");
        document.write(
"<p>divergingCopy(0.2): ", divergingCopy(0.2) + "</p>");
        document.write(
"<p>divergingCopy(0.3): ", divergingCopy(0.3) + "</p>");
    </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=
</head
<style>
</style>
<body
    <h2 style="color:green"> GeeksforGeeks </h2>
    <h4> D3.js | diverging.copy() Function </h4>
    <script
        var diverging = 
d3.scaleDiverging(d3.interpolateSpectral);
        // Default domain is used i.e [0, 1]
        document.write(
        "<b>From original scale: </b>");
        document.write(
"<p>diverging(0.1): ", diverging(0.1) + "</p>");
        document.write(
"<p>diverging(0.2): ", diverging(0.2) + "</p>");
        document.write(
"<b>Change in copy scale does not"+
" effect original scale: </b>");
        var divergingCopy = diverging.copy();
        // Domain is changed to [10, 100]
        divergingCopy.domain([10, 100])
        document.write(
"<p>divergingCopy(0.1): ", divergingCopy(0.1) + "</p>");
        document.write(
"<p>divergingCopy(0.2): ", divergingCopy(0.2) + "</p>");
    </script
</body
</html>

Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :