This is excerpted from my work on emilio.js, a d3 plotting library, but useful enough to stand on its own.
-
Generators are constructed with
new Path()
. -
Takes two optional arguments,
xScale
andyScale
.- Methods for coordinate space translation.
- Works great with
d3.scale()
objects! xScale
andyScale
affect the x and y coordinate spaces, respectively.- If only
xScale
is supplied, y values will be in thexScale
space.
-
Chainable!
var p = new Path(); p.move(0,0).line(50,50).smoothCurve(100,50,100,0); pathEl.setAttribute('d', p.data()); // 'M0,0L50,50S100,50 100,0'
M
=move(x, y)
L
=line(x, y)
H
=horiz(x)
V
=vert(y)
C
=curve(c1x, c1y, c2x, c2y, x, y)
S
=smoothCurve(cx, cy, x, y)
Q
=quad(cx, cy, x, y)
T
=smoothQuad(x, y)
A
=arc(rx, ry, x-axis-rotation, large-arc-flag, sweep-flag, x, y)
Z
=close()
abs()
- subsequent calls will be in absolute coordinate space (default).rel()
- subsequent calls will be in relative coordinate space.data()
- returns the computedd
atrribute for the<path>
.