Class: SVGPlot::Path
Overview
SVG Path element, with ruby methods to describe the path
Instance Attribute Summary
Attributes inherited from ChildTag
Attributes inherited from Tag
#attributes, #children, #defaults, #tag
Instance Method Summary collapse
-
#arc_to(dx, dy, rx, ry, axis_rot, large_arc_flag, sweep_flag) ⇒ Object
Draws an elliptical arc from the current point to the point x,y.
- #arc_to_a(dx, dy, rx, ry, axis_rot, large_arc_flag, sweep_flag) ⇒ Object
-
#close ⇒ Object
close path command.
-
#curve_to(dx, dy, x1, y1, x2, y2) ⇒ Object
Draws a cubic Bezier curve from current pen point to dx,dy.
- #curve_to_a(dx, dy, x1, y1, x2, y2) ⇒ Object
-
#hline_to(x) ⇒ Object
Draws a horizontal line to the point defined by x.
- #hline_to_a(x) ⇒ Object
-
#initialize(img, attributes = {}) ⇒ Path
constructor
A new instance of Path.
-
#line_to(x, y) ⇒ Object
Draws a line from current pen location to specified point x,y.
- #line_to_a(x, y) ⇒ Object
-
#move_to(x, y) ⇒ Object
Moves pen to specified point x,y without drawing.
- #move_to_a(x, y) ⇒ Object
-
#qcurve_to(dx, dy, x1, y1) ⇒ Object
Draws a quadratic Bezier curve from current pen point to dx,dy.
- #qcurve_to_a(dx, dy, x1, y1) ⇒ Object
-
#scurve_to(dx, dy, x2, y2) ⇒ Object
Draws a cubic Bezier curve from current pen point to dx,dy.
- #scurve_to_a(dx, dy, x2, y2) ⇒ Object
-
#sqcurve_to(dx, dy) ⇒ Object
Draws a quadratic Bezier curve from current pen point to dx,dy.
- #sqcurve_to_a(dx, dy) ⇒ Object
-
#vline_to(y) ⇒ Object
Draws a vertical line to the point defined by y.
- #vline_to_a(y) ⇒ Object
Methods inherited from ChildTag
#linear_gradient, #radial_gradient
Methods inherited from Tag
#append_child, #method_missing, #path, #raw, #respond_to?, #spawn_child, #to_s, #use, #write
Methods included from Expansion
Methods included from Transform
#matrix, #rotate, #scale, #skew_x, #skew_y, #translate
Constructor Details
#initialize(img, attributes = {}) ⇒ Path
Returns a new instance of Path.
5 6 7 8 |
# File 'lib/svgplot/path.rb', line 5 def initialize(img, attributes = {}) attributes[:d] ||= '' super(img, 'path', attributes) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class SVGPlot::Tag
Instance Method Details
#arc_to(dx, dy, rx, ry, axis_rot, large_arc_flag, sweep_flag) ⇒ Object
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.
104 105 106 107 108 |
# 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 |
#arc_to_a(dx, dy, rx, ry, axis_rot, large_arc_flag, sweep_flag) ⇒ Object
110 111 112 113 114 |
# 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 ⇒ Object
close path command
Closes the path by drawing a line from current point to first point.
122 123 124 |
# File 'lib/svgplot/path.rb', line 122 def close add_d('Z') end |
#curve_to(dx, dy, x1, y1, x2, y2) ⇒ Object
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.
54 55 56 |
# 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 |
#curve_to_a(dx, dy, x1, y1, x2, y2) ⇒ Object
58 59 60 |
# 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 |
#hline_to(x) ⇒ Object
Draws a horizontal line to the point defined by x.
32 33 34 |
# File 'lib/svgplot/path.rb', line 32 def hline_to(x) add_d("h#{x}") end |
#hline_to_a(x) ⇒ Object
36 37 38 |
# File 'lib/svgplot/path.rb', line 36 def hline_to_a(x) add_d("H#{x}") end |
#line_to(x, y) ⇒ Object
Draws a line from current pen location to specified point x,y.
22 23 24 |
# File 'lib/svgplot/path.rb', line 22 def line_to(x, y) add_d("l#{x},#{y}") end |
#line_to_a(x, y) ⇒ Object
26 27 28 |
# File 'lib/svgplot/path.rb', line 26 def line_to_a(x, y) add_d("L#{x},#{y}") end |
#move_to(x, y) ⇒ Object
Moves pen to specified point x,y without drawing.
12 13 14 |
# File 'lib/svgplot/path.rb', line 12 def move_to(x, y) add_d("m#{x},#{y}") end |
#move_to_a(x, y) ⇒ Object
16 17 18 |
# File 'lib/svgplot/path.rb', line 16 def move_to_a(x, y) add_d("M#{x},#{y}") end |
#qcurve_to(dx, dy, x1, y1) ⇒ Object
Draws a quadratic Bezier curve from current pen point to dx,dy. x1,y1 is the control point controlling how the curve bends.
77 78 79 |
# File 'lib/svgplot/path.rb', line 77 def qcurve_to(dx, dy, x1, y1) add_d("q#{x1},#{y1} #{dx},#{dy}") end |
#qcurve_to_a(dx, dy, x1, y1) ⇒ Object
81 82 83 |
# File 'lib/svgplot/path.rb', line 81 def qcurve_to_a(dx, dy, x1, y1) add_d("Q#{x1},#{y1} #{dx},#{dy}") end |
#scurve_to(dx, dy, x2, y2) ⇒ Object
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.
66 67 68 |
# File 'lib/svgplot/path.rb', line 66 def scurve_to(dx, dy, x2, y2) add_d("s#{x2},#{y2} #{dx},#{dy}") end |
#scurve_to_a(dx, dy, x2, y2) ⇒ Object
70 71 72 |
# File 'lib/svgplot/path.rb', line 70 def scurve_to_a(dx, dy, x2, y2) add_d("S#{x2},#{y2} #{dx},#{dy}") end |
#sqcurve_to(dx, dy) ⇒ Object
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.
88 89 90 |
# File 'lib/svgplot/path.rb', line 88 def sqcurve_to(dx, dy) add_d("t#{dx},#{dy}") end |
#sqcurve_to_a(dx, dy) ⇒ Object
92 93 94 |
# File 'lib/svgplot/path.rb', line 92 def sqcurve_to_a(dx, dy) add_d("T#{dx},#{dy}") end |
#vline_to(y) ⇒ Object
Draws a vertical line to the point defined by y.
42 43 44 |
# File 'lib/svgplot/path.rb', line 42 def vline_to(y) add_d("v#{y}") end |
#vline_to_a(y) ⇒ Object
46 47 48 |
# File 'lib/svgplot/path.rb', line 46 def vline_to_a(y) add_d("V#{y}") end |