Skip to content
Related Articles

Related Articles

Improve Article
D3.js easePolyIn() Function
  • Last Updated : 09 Sep, 2020

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:

  • t: It is the time that is to be raised to the power of the exponent.

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:

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
  
    <script src
    </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:

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
  
    <script src
    </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:




My Personal Notes arrow_drop_up
Recommended Articles
Page :