animated color cycle style progress bar
Created
July 27, 2016 12:09
-
-
Save k0emt/05030c35610bbc0db1620590bdca59ba to your computer and use it in GitHub Desktop.
color cycle progress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var plotDimensionWidth = 400; | |
var plotDimensionHeight = 200; | |
var delay = 200; | |
var duration = 600; | |
var smallRadius = 10; | |
var svg = d3.select("body").append("svg") | |
.attr("width", plotDimensionWidth) | |
.attr("height", plotDimensionHeight); | |
var graphData = [ | |
{x: 50, y: 100 }, | |
{x: 100, y: 100 }, | |
{x: 150, y: 100 }, | |
{x: 200, y: 100 }, | |
{x: 250, y: 100 }, | |
{x: 300, y: 100 }, | |
{x: 350, y: 100 } | |
]; | |
function render(data){ | |
var circles = svg.selectAll("circle").data(data); | |
circles.enter().append("circle") | |
.attr("r", smallRadius) | |
.attr("stroke", "#000" ) | |
.attr("fill", "#000" ) | |
.attr("cx", function (d){ return d.x; }) | |
.attr("cy", function (d){ return d.y; }); | |
circles.exit().remove(); | |
} | |
function cycle(data) { | |
d3.select("svg") | |
.selectAll("circle") | |
.transition() | |
.delay(function(d, i) { return delay * i; }) | |
.duration( duration ) | |
.attr("fill", "#f00") | |
.transition() | |
.duration( duration ) | |
.attr("fill", "#000" ); | |
} | |
render(graphData); | |
for(repeat = 0; repeat < 3; repeat++) { | |
setTimeout(function(){cycle(graphData)},repeat * 2600); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.min.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
background-color: #4f4f4f; | |
} | |
svg { | |
background-color: white; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment