Skip to content

alexmacy/d3-shape-tween

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

d3-shape-tween

An add-on for helping with smooth transitions between shapes using d3.js. This is particularly effective when transitioning from a complex shape to one with less detail.

*** Requires d3.js version 4 ***

Reference

There are two options for tweening shapes:

shapeTweenSides(shape1, shape2[, findStart])

Plots the number of points in the longer of the two arrays of points, divided by how many sides the new shape has.

shapeTweenLength(shape1, shape2[, findStart])

Plots each of the points from the first shape along the second shape, proportionally to where it was along the outside of the first shape. Note: this method often provides a smoother transition, but at the cost of some accuracy because it plots the points based on length along a line and may skip some of the destination shape's original points.

Both tweening functions take the same arguments:

shape1 & shape2: (arrays of coordinates)

Arrays of points that can be used for rendering SVG polygons.

findStart: (boolean)

Default is false if unspecified. If specified true, triggers a function that loops through shape2's points to adjust so that the shape's first point is the one closest to the start of shape1. This is good when transitioning between shapes that are in the same location, but not when the transition moves the shape to another part of the screen.

About

add-on for d3.js that provides smoother transitions between SVG shapes.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published