Created
December 29, 2012 11:27
-
-
Save trtg/4406287 to your computer and use it in GitHub Desktop.
d3 tributary manually drawing paths
This file contains 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
{"description":"d3 tributary manually drawing paths","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"tab":"edit","display_percent":0.5997407087294727,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"hidepanel":false} |
This file contains 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
//http://www.w3.org/TR/SVG/paths.html#PathDataMovetoCommands | |
function move(p) { | |
return [" M", p.x, p.y].join(" "); | |
} | |
function lineSeg(p) { | |
//lower case "l" uses relative coordinates | |
//upper case is absolute | |
return [" L", p.x, p.y].join(" "); | |
} | |
function arcSeg(p) { | |
//A r r rotation large-arc sweep x y | |
return [" A", p.r, p.r,p.rot,p.c,p.d,p.x,p.y].join(" "); | |
} | |
function bezSeg(p) { | |
//x1,y1 and x2,y2 are control points | |
return [" C", p.x1, p.y1,p.x2,p.y2,p.x,p.y].join(" "); | |
} | |
function smoothSeg(p) { | |
//x2,y2 is the control point | |
return [" S",p.x2,p.y2,p.x,p.y].join(" "); | |
} | |
function qbezSeg(p) { | |
//x1 y1 x y | |
return [" Q",p.x1,p.y1,p.x,p.y].join(" "); | |
} | |
function qsmoothSeg(p) { | |
//x y | |
return [" T",p.x,p.y].join(" "); | |
} | |
var pathD = move({x: 141,y:79}) | |
+lineSeg({x:259,y:100}) | |
+lineSeg({x:279,y:236}) | |
//+arcSeg({x: 448,y: 231,r:100,rot:0,c:1,d:0}) | |
+bezSeg({x:387,y:358,x1:414,y1:98,x2:476,y2:300}) | |
+smoothSeg({x:300,y:487,x2:300,y2:404}) | |
+qbezSeg({x:91,y:465,x1:193,y1:601}) | |
+qsmoothSeg({x:300,y:327}) | |
var svg = d3.select("svg"); | |
svg.append("path") | |
.attr("d",pathD) | |
.style({ | |
fill:"none", | |
stroke:"#000000", | |
"stroke-width":12, | |
"stroke-linecap": "round", | |
"stroke-linejoin": "round" | |
}) | |
//console.log("path",pathD); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment