Skip to content

Instantly share code, notes, and snippets.

@abdullin
Created May 5, 2014 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdullin/74b9b5179b87bbd178d2 to your computer and use it in GitHub Desktop.
Save abdullin/74b9b5179b87bbd178d2 to your computer and use it in GitHub Desktop.
<!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>
Display the source blob
Display the rendered blob
Raw
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="157px" height="177px" viewBox="0 0 157 177" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
<!-- Generator: Sketch 3.0.1 (7597) - http://www.bohemiancoding.com/sketch -->
<title>u1</title>
<description>Created with Sketch.</description>
<defs></defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
<rect id="Rectangle-1" stroke="#28AD0C" stroke-width="3" fill-opacity="0.644248188" fill="#B8E986" sketch:type="MSShapeGroup" x="9" y="11" width="140" height="40" rx="10"></rect>
<rect id="Rectangle-2" stroke="#28AD0C" stroke-width="2" fill-opacity="0.644248188" fill="#B8E986" sketch:type="MSShapeGroup" x="9" y="131" width="60" height="40" rx="10"></rect>
<rect id="Rectangle-3" stroke="#28AD0C" stroke-width="2" fill-opacity="0.644248188" fill="#B8E986" sketch:type="MSShapeGroup" x="89" y="131" width="60" height="40" rx="10"></rect>
<circle id="circle_1" stroke="#979797" stroke-width="2" fill="#D8D8D8" sketch:type="MSShapeGroup" cx="79" cy="50" r="10"></circle>
<circle id="circle_2" stroke="#979797" stroke-width="2" fill="#D8D8D8" sketch:type="MSShapeGroup" cx="79" cy="50" r="10"></circle>
<text id="Write" sketch:type="MSTextLayer" font-family="Helvetica" font-size="11" font-weight="normal" sketch:alignment="middle" fill="#000000">
<tspan x="25.9711914" y="149">Write</tspan>
<tspan x="23.7260742" y="162">model</tspan>
</text>
<text id="Read" sketch:type="MSTextLayer" font-family="Helvetica" font-size="12" font-weight="normal" sketch:alignment="middle" fill="#081D03">
<tspan x="104.15625" y="150">Read</tspan>
<tspan x="102.158203" y="164">model</tspan>
</text>
<g id="animate" sketch:type="MSLayerGroup" transform="translate(39.000000, 51.000000)" stroke="#979797" stroke-linecap="square">
<path d="M40,0.5 L0.5,79.5123457" id="path_write" sketch:type="MSShapeGroup"></path>
<path d="M40.5,0.5 L80.30201,80.10402" id="path_read" sketch:type="MSShapeGroup"></path>
</g>
<text id="Component" sketch:type="MSTextLayer" font-family="Helvetica" font-size="12" font-weight="normal" sketch:alignment="middle" fill="#081D03">
<tspan x="47.4804688" y="35">Component</tspan>
</text>
</g>
</svg>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment