class SVGPlot::Path

SVG Path element, with ruby methods to describe the path

Public Class Methods

new(img, attributes = {}) click to toggle source
Calls superclass method
# File lib/svgplot/path.rb, line 5
def initialize(img, attributes = {})
  attributes[:d] ||= ''
  super(img, 'path', attributes)
end

Public Instance Methods

arc_to(dx, dy, rx, ry, axis_rot, large_arc_flag, sweep_flag) click to toggle source

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
arc_to_a(dx, dy, rx, ry, axis_rot, large_arc_flag, sweep_flag) click to toggle source
# 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() click to toggle source

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
curve_to(dx, dy, x1, y1, x2, y2) click to toggle source

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
curve_to_a(dx, dy, x1, y1, x2, y2) click to toggle source
# 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) click to toggle source

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
hline_to_a(x) click to toggle source
# File lib/svgplot/path.rb, line 36
def hline_to_a(x)
  add_d("H#{x}")
end
line_to(x, y) click to toggle source

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
line_to_a(x, y) click to toggle source
# File lib/svgplot/path.rb, line 26
def line_to_a(x, y)
  add_d("L#{x},#{y}")
end
move_to(x, y) click to toggle source

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
move_to_a(x, y) click to toggle source
# 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) click to toggle source

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
qcurve_to_a(dx, dy, x1, y1) click to toggle source
# 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) click to toggle source

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
scurve_to_a(dx, dy, x2, y2) click to toggle source
# 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) click to toggle source

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
sqcurve_to_a(dx, dy) click to toggle source
# File lib/svgplot/path.rb, line 92
def sqcurve_to_a(dx, dy)
  add_d("T#{dx},#{dy}")
end
vline_to(y) click to toggle source

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
vline_to_a(y) click to toggle source
# File lib/svgplot/path.rb, line 46
def vline_to_a(y)
  add_d("V#{y}")
end

Private Instance Methods

add_d(op) click to toggle source
# File lib/svgplot/path.rb, line 128
def add_d(op)
  @attributes[:d] << " #{op}"
end