Open In App

D3.js easePolyIn() Function

The d3.easePolyIn() function in d3.js is used for polynomial exponential easing transition effect to a particular element. This exponential easing function raises time to the power of the given exponent.

Syntax:



d3.easePolyIn 

// Or 

d3.easePolyIn.exponent(t);

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

Return Value: This function has no return value.



Approach: D3.js transition function will be used for applying different easing effects on a particular element. First, create an SVG element and append it to the body of the HTML page, then create a rectangle or any other shape and append it to the SVG. Set some attributes of the rectangle to give it nice color and size and apply d3.transition function followed by ease() function and give the d3.easePolyIn or d3.easePolyIn.exponent(t) as a parameter to ease function.

Example 1:




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
  
    <script src
        "https://d3js.org/d3.v4.min.js">
    </script>
</head>
    
<body>
    <h1 style="color:green">GeeksforGeeks</h1>
  
    <svg width="500px" height="500px"></svg>
    <script>
        var svg = d3.select("svg")
            .attr("transform","translate(0,-50)");
  
        svg.append("rect")
            .attr("x", 10)
            .attr("y",50)
            .attr("width",150)
            .attr("height",50)
            .attr("fill", "green")
            .transition()
              
            // Use of d3.easePolyIn
            .ease(d3.easePolyIn)
            .attr("x", 100)
            .attr("y",100)
            .attr("width",150)
            .attr("height",200)
            .duration(2000);
  
    </script>
</body>
  
</html>

Output:

Example 2:




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
  
    <script src
        "https://d3js.org/d3.v4.min.js">
    </script>
</head>
    
<body>
    <h1 style="color:green">GeeksforGeeks</h1>
  
    <svg width="500px" height="500px"></svg>
    <script>
        var svg = d3.select("svg")
            .attr("transform","translate(0,-50)");
  
        svg.append("rect")
            .attr("x", 10)
            .attr("y",50)
            .attr("width",150)
            .attr("height",50)
            .attr("fill", "green")
            .transition()
              
            // Use of d3.easePolyIn
            .ease(d3.easePolyIn.exponent(50))
            .attr("x", 100)
            .attr("y",100)
            .attr("width",150)
            .attr("height",200)
            .duration(2000);
  
    </script>
</body>
  
</html>

Output:


Article Tags :