<!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>
einfachste? Zeigen IE9 Benutzer ein animiertes Gif. – Mottie
auf der Suche nach etwas wiederverwendbar. Außerdem wird das Diagramm dynamisch mit verschiedenen Parametern generiert, sodass ein 1-aus-animiertes GIF nicht funktioniert. darüber nachdenken, eine js-Lösung zu verwenden, um die Linien zu animieren. scheint wie es könnte die einfachste Lösung sein – user6867266
sieht aus wie es gibt mehrere js Bibliotheken, die einige fortgeschrittene Svg-Animation wie diese https://maxwellito.github.io/vivus/ tun wird. Allerdings ist mein Szenario sehr einfach - gerade gepunktete Linien, die animiert werden, um mit variablen Geschwindigkeiten zu fließen. also denke ich, dass eine einfache Funktion oder eine Handvoll von js-Funktionen verwendet werden kann, um das zu erreichen, was ich tun muss – user6867266