Skip to content

Instantly share code, notes, and snippets.

@abdullin

abdullin/index.html

Created May 5, 2014
Embed
What would you like to do?
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
body {
width: 960px;
padding-top: 40px;
margin: auto;
position: relative;
}
svg {
width: 100%;
max-height: 250px;
}
</style>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script type="text/javascript">
function translateCircleAlongPath(path, offset) {
var l = path.getTotalLength();
var tx = offset[0],
ty = offset[1];
return function() {
return function(t) {
var p = path.getPointAtLength(t * l);
d3.select(this)
.attr('cx', p.x + tx)
.attr('cy', p.y + ty);
};
};
}
function restart(){
var svg = d3.select('svg');
var circles = svg.selectAll("circle")
circles
.transition()
.duration(1000)
.style("opacity", 0)
.each('end', function(){
animation = svg.select('#animate')
var offset = d3.transform(animation.attr('transform')).translate;
// Get the path along which to move the circle
var path = svg.select('#path_read');
var tx = offset[0],
ty = offset[1];
var p = path.node().getPointAtLength(0);
circles.attr('cx',p.x+tx).attr('cy', p.y+ty)
show()
})
}
function show(){
d3.select('svg')
.selectAll("circle")
.transition()
.duration(1000)
.style("opacity", 1)
.each('end', run)
}
function run(){
var svg = d3.select('svg');
var offset = d3.transform(animation.attr('transform')).translate;
// Get the path along which to move the circle
var motionPath = svg.select('#path_read');
svg
.select('#circle_1')
.transition()
.duration(2500)
.tween('motion', translateCircleAlongPath(motionPath.node(), offset))
.each('end', restart);
var motionPath = svg.select('#path_write');
svg
.select('#circle_2')
.transition()
.duration(2500)
.tween('motion', translateCircleAlongPath(motionPath.node(), offset));
}
(function () {
window.addEventListener('load', function() {
d3.xml('u1.svg', 'image/svg+xml', function (error, data) {
d3.select('body').node().appendChild(data.documentElement);
svg = d3.select('svg');
animation = svg.select('#animate')
animation.style('display', 'none');
svg.selectAll("circle").style("opacity",0)
show()
})
})
})()
</script>
</head>
<body>
<h1>CQRS</h1>
</body>
</html>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment