I am trying to transition between two SVG views with d3.js
. The aim is to be able to alternate between displays:
- a classical choropleth map (map where color represents a measurement)
- a bubble chart where the radius is proportionate to the population of the region
See here for a demo.
However, transitioning from arbitrary SVG path to an (approximated) circle is not straightforward. I have the following issues:
- regions of the map may contain islands or enclaves ; more generally, a SVG
path
may contain independent rings. (I would have thoughtd3
would have rendered multi-polygons as severalpath
s but no!) On the other hand, a circle is made of only one ring. How do you smooth the smaller polygons out during the transition? (I think merging the rings together is too complicated to be worth it.) I thought about fading or shrinking the polygones, but how can I implement that in practice? 'Cause I am not sure whether it is possible to single out one ring inside thed
attribute of apath
. - small regions are represented by few points and transitioning those few points onto a circle produces a polygon with too few vertices to look like an actual circle (see image under) ; What is a good strategy for smoothly adding points in the
d
attribute of apath
? ; - alternatively, instead of adding points to the broken line, one could also transition straight lines to Bézier curves (4 points and adequate anchors already produce a very good approximation of a circle). Since my own attempt is not convincing, here is the third question: How do you transition between straight lines and Bézier curves?
- lastly, at the beginning of the transition in both direction, I get spikes / stripes in some (but not all) of the shapes; any idea where that could come from?