The d3.easePolyInOut() function in d3.js is used to as an alias for d3.easePoly function. This function is used to give symmetrical easing transition effect to a particular element. This function returns a polynomial function.
Approach: D3.js transition function will be used for applying different easing effects on a particular element. First of all, create an SVG element and append it to the body of the HTML page, then create a circle or rectangle or any other shape and append it to the SVG. Set some attributes of the particular shape to give it nice color and size and apply the d3.transition function followed by ease() function and give the d3.easePolyInOut as a parameter to this function.
Syntax:
svg.append().attr().ease(d3.easePolyInOut).attr();
Parameter: This function does not accept any parameters.
Return Value: This method returns a function.
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" content=" width = device -width, initial-scale = 1 .0"> < script type = "text/javascript" </ script > </ head > < body > < h1 style = "color:green" >neveropen</ h1 > < svg width = "600px" height = "600px" ></ svg > < script > var svg = d3.select("svg") svg.append("rect") .attr("x", 50) .attr("width", 10) .attr("height", 10) .attr("fill", "green") .transition() .ease(d3.easePolyInOut) .attr("width", 100) .attr("height", 100) .attr("fill", "red") .duration(1000); </ script > </ body > </ html > |
Output:
Example 2:
<!DOCTYPE html> < html lang = "en" > < head > < meta charset = "UTF-8" > < meta name = "viewport" content=" width = device -width, initial-scale = 1 .0"> < script type = "text/javascript" </ script > </ head > < body > < h1 style = "color:green" >neveropen</ h1 > < svg width = "600px" height = "600px" ></ svg > < script > var svg = d3.select("svg") svg.append("circle") .attr("r", 0) .attr("cx", 100) .attr("cy", 50) .attr("fill", "green") .transition() .delay(8000) .ease(d3.easePolyInOut) .attr("r", 50) .duration(1000); </ script > </ body > </ html > |
Output: