Open In App

D3.js sequential.interpolator() Function

Improve
Improve
Like Article
Like
Save
Share
Report

Sequential scales are very similar to continuous scale. On a continuous scale, mapping is done in a continuous way between domain and range. The only difference is that the output range of this scale is fixed by its interpolator and this range cannot be changed.

The sequential.interpolator() function in d3.js is used to configure the interpolator of the scale. If the interpolator is specified it sets the interpolator of the scale to the specified function, else returns the scale’s current interpolator.

Syntax:

sequential.interpolator([interpolator]);

Parameters: This function accepts a single parameter as mentioned above and described below:

  • interpolator: This takes the interpolator function. If interpolator is not specified it returns the current interpolator of the scale.

Return Values: This function does not return anything.

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 src="https://d3js.org/d3.v6.min.js">
    </script>
</head>
  
<body>
    <h2 style="color:green"> GeeksforGeeks </h2>
  
    <h4> D3.js | sequential.interpolator() Function</h4>
    <script>
        var sequential = d3.scaleSequential()
  
            // Setting the interpolator of the scale.
            .interpolator((t) => t * 2);
  
        document.write("<p>sequential(2): ", 
                    sequential(2) + "</p>");
  
        document.write("<p>sequential(4): ", 
                    sequential(4) + "</p>");
  
        document.write("<p>sequential(10): ", 
                    sequential(10) + "</p>");
  
        document.write("<p>sequential(20): ", 
                    sequential(20) + "</p>");
    </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"/>
  
    <script src="https://d3js.org/d3.v6.min.js">
    </script>
</head>
  
<body>
    <h2 style="color:green"> GeeksforGeeks </h2>
  
    <h4>D3.js | sequential.interpolator() Function</h4>
  
    <script>
        var sequential = d3.scaleSequential()
            // Setting the interpolator of the scale.
            .interpolator(d3.interpolateSpectral)
            // Setting the domain of the scale.
            .domain([1, 100]);
        document.write("<p>sequential(2): ", 
                    sequential(2) + "</p>");
  
        document.write("<p>sequential(4): ", 
                    sequential(4) + "</p>");
  
        document.write("<p>sequential(10): ", 
                    sequential(10) + "</p>");
  
        document.write("<p>sequential(20): ", 
                    sequential(20) + "</p>");
    </script>
</body>
  
</html>


Output:



Last Updated : 31 Aug, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads