Class: SVGPlot::SVGPath

Inherits:
SVGTagWithParent show all
Defined in:
lib/svgplot/plot.rb

Overview

SVG Path element, with ruby methods to describe the path

Instance Attribute Summary

Attributes inherited from SVGTagWithParent

#img

Attributes inherited from SVGTag

#attributes, #children, #tag

Instance Method Summary collapse

Methods inherited from SVGTag

#append_child, #linearGradient, #matrix, #merge_defaults, #method_missing, #path, #pop_defaults, #push_defaults, #radialGradient, #raw, #rotate, #scale, #skewX, #skewY, #spawn_child, #to_s, #translate, #use, #validate_attribute, #validate_attributes, #validate_child_name, #validate_tag, #with_style, #write, #write_points, #write_styles, #write_transforms

Constructor Details

#initialize(img = nil, attributes = {}, &block) ⇒ SVGPath

Returns a new instance of SVGPath.



429
430
431
432
# File 'lib/svgplot/plot.rb', line 429

def initialize(img = nil, attributes={}, &block)
  attributes.merge!(:d => "") unless attributes.has_key? :d
  super(img, "path", attributes)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class SVGPlot::SVGTag

Instance Method Details

#arcTo(dx, dy, rx, ry, axis_rotation, large_arc_flag, sweep_flag) ⇒ Object

elliptical arc commands

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 seems to have 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.



579
580
581
# File 'lib/svgplot/plot.rb', line 579

def arcTo(dx, dy, rx, ry, axis_rotation, large_arc_flag, sweep_flag)
  add_d("a#{rx},#{ry} #{axis_rotation} #{large_arc_flag},#{sweep_flag} #{dx},#{dy}")
end

#arcToA(dx, dy, rx, ry, axis_rotation, large_arc_flag, sweep_flag) ⇒ Object



584
585
586
# File 'lib/svgplot/plot.rb', line 584

def arcToA(dx, dy, rx, ry, axis_rotation, large_arc_flag, sweep_flag)
  add_d("A#{rx},#{ry} #{axis_rotation} #{large_arc_flag},#{sweep_flag} #{dx},#{dy}")
end

#closeObject

close path command

Closes the path by drawing a line from current point to first point.



595
596
597
# File 'lib/svgplot/plot.rb', line 595

def close
  add_d("Z")
end

#curveTo(dx, dy, x1, y1, x2, y2) ⇒ Object

curveTo commands

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.



505
506
507
# File 'lib/svgplot/plot.rb', line 505

def curveTo(dx, dy, x1, y1, x2, y2)
  add_d("c#{x1},#{y1} #{x2},#{y2} #{dx},#{dy}")
end

#curveToA(dx, dy, x1, y1, x2, y2) ⇒ Object



510
511
512
# File 'lib/svgplot/plot.rb', line 510

def curveToA(dx, dy, x1, y1, x2, y2)
  add_d("C#{x1},#{y1} #{x2},#{y2} #{dx},#{dy}")
end

#hlineTo(x) ⇒ Object

horizontal lineTo commands

Draws a horizontal line to the point defined by x.



472
473
474
# File 'lib/svgplot/plot.rb', line 472

def hlineTo(x)
  add_d("h#{x}")
end

#hlineToA(x) ⇒ Object



477
478
479
# File 'lib/svgplot/plot.rb', line 477

def hlineToA(x)
  add_d("H#{x}")
end

#lineTo(x, y) ⇒ Object

lineTo commands

Draws a line from current pen location to specified point x,y.



456
457
458
# File 'lib/svgplot/plot.rb', line 456

def lineTo(x, y)
  add_d("l#{x},#{y}")
end

#lineToA(x, y) ⇒ Object



461
462
463
# File 'lib/svgplot/plot.rb', line 461

def lineToA(x, y)
  add_d("L#{x},#{y}")
end

#moveTo(x, y) ⇒ Object

moveTo commands

Moves pen to specified point x,y without drawing.



440
441
442
# File 'lib/svgplot/plot.rb', line 440

def moveTo(x, y)
  add_d("m#{x},#{y}")
end

#moveToA(x, y) ⇒ Object



445
446
447
# File 'lib/svgplot/plot.rb', line 445

def moveToA(x, y)
  add_d("M#{x},#{y}")
end

#qcurveTo(dx, dy, x1, y1) ⇒ Object

quadratic Bezier curveTo commands

Draws a quadratic Bezier curve from current pen point to dx,dy. x1,y1 is the control point controlling how the curve bends.



540
541
542
# File 'lib/svgplot/plot.rb', line 540

def qcurveTo(dx, dy, x1, y1)
  add_d("q#{x1},#{y1} #{dx},#{dy}")
end

#qcurveToA(dx, dy, x1, y1) ⇒ Object



545
546
547
# File 'lib/svgplot/plot.rb', line 545

def qcurveToA(dx, dy, x1, y1)
  add_d("Q#{x1},#{y1} #{dx},#{dy}")
end

#scurveTo(dx, dy, x2, y2) ⇒ Object

smooth curveTo commands

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.



523
524
525
# File 'lib/svgplot/plot.rb', line 523

def scurveTo(dx, dy, x2, y2)
  add_d("s#{x2},#{y2} #{dx},#{dy}")
end

#scurveToA(dx, dy, x2, y2) ⇒ Object



528
529
530
# File 'lib/svgplot/plot.rb', line 528

def scurveToA(dx, dy, x2, y2)
  add_d("S#{x2},#{y2} #{dx},#{dy}")
end

#sqcurveTo(dx, dy) ⇒ Object

smooth quadratic Bezier curveTo commands

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.



557
558
559
# File 'lib/svgplot/plot.rb', line 557

def sqcurveTo(dx, dy)
  add_d("t#{dx},#{dy}")
end

#sqcurveToA(dx, dy) ⇒ Object



562
563
564
# File 'lib/svgplot/plot.rb', line 562

def sqcurveToA(dx, dy)
  add_d("T#{dx},#{dy}")
end

#vlineTo(y) ⇒ Object

vertical lineTo commands

Draws a vertical line to the point defined by y.



488
489
490
# File 'lib/svgplot/plot.rb', line 488

def vlineTo(y)
  add_d("v#{y}")
end

#vlineToA(y) ⇒ Object



493
494
495
# File 'lib/svgplot/plot.rb', line 493

def vlineToA(y)
  add_d("V#{y}")
end