pathExample = {
const svg = d3
.create('svg')
.call(q.setSize, config.mapWidth, config.mapHeight);
const g = svg.append('g').call(q.move, () => [10, 10]);
const updatePath = node =>
node
.transition()
.duration(400)
.ease(d3.easeLinear)
.attrTween('d', function(d) {
console.log('tweening');
var previous = d3.select(this).attr('d');
if (d === 'circle') return flubber.toCircle(sampleGeoPath, 100, 50, 50);
return flubber.interpolate(previous, sampleGeoPath);
});
const enterMap = region =>
region
.append('path')
.attr('class', 'province')
.attr('data-region', getRegionName)
.attr('d', pathGen);
const updateMap = region => region.call(mapAnim);
const mapAnim = region =>
region
.transition()
.duration(500)
.attrTween('d', function(d) {
try {
const prevPath = d3.select(this).attr('d');
const regionName = getRegionName(d);
const [_y, _x] = provinceCoords[regionName];
const [x, y] = koreaProjection([_x, _y]);
const radius = scaleR(provinceData[regionName]);
if (currentPath === 'CIRCLE')
return flubber.toCircle(prevPath, x, y, radius);
const geoPath = pathGen(d);
return flubber.fromCircle(x, y, radius, geoPath);
} catch (err) {}
});
function render(pathMode) {
console.log('rerender');
const provinces = g
.selectAll('.province')
.data(geoJsonNoMultiPolygon.features, (d, i) => i)
.join(enterMap, updateMap);
}
render();
return Object.assign(svg.node(), { render });
}