class SVGPlot::Path
SVG Path
element, with ruby methods to describe the path
Public Class Methods
# File lib/svgplot/path.rb, line 5 def initialize(img, attributes = {}) attributes[:d] ||= '' super(img, 'path', attributes) end
Public Instance Methods
Draws an elliptical arc from the current point to the point x,y. rx and ry are the elliptical radius in x and y direction. The x-rotation determines how much the arc is to be rotated around the x-axis. It only has an effect when rx and ry have different values. The large-arc-flag doesn't seem to be used (can be either 0 or 1). Neither value (0 or 1) changes the arc. The sweep-flag determines the direction to draw the arc in.
# File lib/svgplot/path.rb, line 104 def arc_to(dx, dy, rx, ry, axis_rot, large_arc_flag, sweep_flag) add_d( "a#{rx},#{ry} #{axis_rot} #{large_arc_flag},#{sweep_flag} #{dx},#{dy}" ) end
# File lib/svgplot/path.rb, line 110 def arc_to_a(dx, dy, rx, ry, axis_rot, large_arc_flag, sweep_flag) add_d( "A#{rx},#{ry} #{axis_rot} #{large_arc_flag},#{sweep_flag} #{dx},#{dy}" ) end
close path command
Closes the path by drawing a line from current point to first point.
# File lib/svgplot/path.rb, line 122 def close add_d('Z') end
Draws a cubic Bezier curve from current pen point to dx,dy. x1,y1 and x2,y2 are start and end control points of the curve, controlling how it bends.
# File lib/svgplot/path.rb, line 54 def curve_to(dx, dy, x1, y1, x2, y2) add_d("c#{x1},#{y1} #{x2},#{y2} #{dx},#{dy}") end
# File lib/svgplot/path.rb, line 58 def curve_to_a(dx, dy, x1, y1, x2, y2) add_d("C#{x1},#{y1} #{x2},#{y2} #{dx},#{dy}") end
Draws a horizontal line to the point defined by x.
# File lib/svgplot/path.rb, line 32 def hline_to(x) add_d("h#{x}") end
# File lib/svgplot/path.rb, line 36 def hline_to_a(x) add_d("H#{x}") end
Draws a line from current pen location to specified point x,y.
# File lib/svgplot/path.rb, line 22 def line_to(x, y) add_d("l#{x},#{y}") end
# File lib/svgplot/path.rb, line 26 def line_to_a(x, y) add_d("L#{x},#{y}") end
Moves pen to specified point x,y without drawing.
# File lib/svgplot/path.rb, line 12 def move_to(x, y) add_d("m#{x},#{y}") end
# File lib/svgplot/path.rb, line 16 def move_to_a(x, y) add_d("M#{x},#{y}") end
Draws a quadratic Bezier curve from current pen point to dx,dy. x1,y1 is the control point controlling how the curve bends.
# File lib/svgplot/path.rb, line 77 def qcurve_to(dx, dy, x1, y1) add_d("q#{x1},#{y1} #{dx},#{dy}") end
# File lib/svgplot/path.rb, line 81 def qcurve_to_a(dx, dy, x1, y1) add_d("Q#{x1},#{y1} #{dx},#{dy}") end
Draws a cubic Bezier curve from current pen point to dx,dy. x2,y2 is the end control point. The start control point is is assumed to be the same as the end control point of the previous curve.
# File lib/svgplot/path.rb, line 66 def scurve_to(dx, dy, x2, y2) add_d("s#{x2},#{y2} #{dx},#{dy}") end
# File lib/svgplot/path.rb, line 70 def scurve_to_a(dx, dy, x2, y2) add_d("S#{x2},#{y2} #{dx},#{dy}") end
Draws a quadratic Bezier curve from current pen point to dx,dy. The control point is assumed to be the same as the last control point used.
# File lib/svgplot/path.rb, line 88 def sqcurve_to(dx, dy) add_d("t#{dx},#{dy}") end
# File lib/svgplot/path.rb, line 92 def sqcurve_to_a(dx, dy) add_d("T#{dx},#{dy}") end
Draws a vertical line to the point defined by y.
# File lib/svgplot/path.rb, line 42 def vline_to(y) add_d("v#{y}") end
# File lib/svgplot/path.rb, line 46 def vline_to_a(y) add_d("V#{y}") end
Private Instance Methods
# File lib/svgplot/path.rb, line 128 def add_d(op) @attributes[:d] << " #{op}" end