Skip to content

Instantly share code, notes, and snippets.

@enjalot
Created September 9, 2013 21:31
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 enjalot/6501816 to your computer and use it in GitHub Desktop.
Save enjalot/6501816 to your computer and use it in GitHub Desktop.
stroke dash
{"description":"stroke dash","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"inline-console":true,"thumbnail":"http://i.imgur.com/CEq6f6j.png"}
var data = [
{x: 0, y:50},
{x: 25, y:0},
{x: 50, y:50}
]
var line = d3.svg.line()
.x(function(d) {
return d.x;
})
.y(function(d) {
return d.y;
});
var svg = d3.select("svg");
var group = svg.append("g")
.attr({
transform: "translate(" + [60, 150] + ")"
})
var path = group.append("path")
.attr({
d: line(data),
fill: "none",
stroke: "#000"
})
var len = path.node().getTotalLength();
console.log(len);
len = 44
var offset = 26;
p = path.attr({
"stroke-dasharray": 64 + " " + 26,
"stroke-dashoffset": offset
})
//more info on this
//http://bl.ocks.org/1313857
//http://www.carto.net/svg/samples/animated_bustrack.shtml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment