Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptD3.js diverging.copy() Function

D3.js diverging.copy() Function

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"> neveropen </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"> neveropen </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:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments