<!DOCTYPE html>
<html>
<head>
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.5.3/d3.js"></script>
<style>
.node {
fill: #dddddd;
stroke: gray;
stroke-width: 4;
}
.flowline {
fill: none;
stroke: black;
opacity: 0.5;
stroke-width: 4;
stroke-dasharray: 10, 4;
}
</style>
</head>
<body>
<script>
var width = 960,
height = 500;
var svg = d3.select('body').append('svg')
.attr('width', width)
.attr('height', height);
var ex1 = svg.append('g')
.attr('transform', 'translate(50 50)');
ex1.append('path')
.attr('class', 'flowline')
.attr('d', 'M100 100 L300 100');
ex1.append('path')
.attr('class', 'flowline')
.attr('d', 'M200 300 L300 100');
ex1.append('path')
.attr('class', 'flowline')
.attr('d', 'M200 300 L300 250');
ex1.append('path')
.attr('class', 'flowline')
.attr('d', 'M300 250 L100 100');
ex1.append('circle')
.attr('class', 'node')
.attr('cx', 100)
.attr('cy', 100)
.attr('r', 20);
ex1.append('circle')
.attr('class', 'node')
.attr('cx', 300)
.attr('cy', 100)
.attr('r', 20);
ex1.append('circle')
.attr('class', 'node')
.attr('cx', 200)
.attr('cy', 300)
.attr('r', 20);
ex1.append('circle')
.attr('class', 'node')
.attr('cx', 300)
.attr('cy', 250)
.attr('r', 20);
var ex2 = svg.append('g')
.attr('transform', 'translate(450 50)');
ex2.append('path')
.attr('class', 'flowline')
.attr('d', 'M100 100 S200 0 300 100');
ex2.append('path')
.attr('class', 'flowline')
.attr('d', 'M200 300 S200 200 300 100');
ex2.append('path')
.attr('class', 'flowline')
.attr('d', 'M200 300 S300 350 300 250');
ex2.append('path')
.attr('class', 'flowline')
.attr('d', 'M300 250 L100 100');
ex2.append('circle')
.attr('class', 'node')
.attr('cx', 100)
.attr('cy', 100)
.attr('r', 20);
ex2.append('circle')
.attr('class', 'node')
.attr('cx', 300)
.attr('cy', 100)
.attr('r', 20);
ex2.append('circle')
.attr('class', 'node')
.attr('cx', 200)
.attr('cy', 300)
.attr('r', 20);
ex2.append('circle')
.attr('class', 'node')
.attr('cx', 300)
.attr('cy', 250)
.attr('r', 20);
function animate(){
d3.select(this)
.transition()
.ease('linear')
.duration(1000)
.styleTween("stroke-dashoffset", function() {
return d3.interpolate(0, 14);
})
.each("end", animate);
}
d3.selectAll(".flowline")
.each(animate);
</script>
</body>
</html>
간단한을? IE9 사용자에게 애니메이션 GIF를 보여줍니다. – Mottie
재사용 가능한 것을 찾고 있습니다. 또한 차트는 다른 매개 변수로 동적으로 생성되므로 1-off 애니메이션 GIF가이 기능을 수행하지 않습니다. js 솔루션을 사용하여 선을 애니메이션화하는 방법에 대해 생각해보십시오. 가장 간단한 솔루션이 될 수있는 것 같습니다 – user6867266
이 하나의 https://maxwellito.github.io/vivus/와 같은 몇 가지 고급 svg 애니메이션을 할 여러 js 라이브러리가있는 것처럼 보입니다. 그러나, 내 시나리오는 매우 기본적인 것입니다 - 직선 점선은 다양한 속도로 흐르는 애니메이션. 그래서 나는 간단한 함수 나 소수의 js 함수를 사용하여 내가 수행 할 작업을 수행 할 수 있다고 생각한다. – user6867266