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.



431
432
433
434
# File 'lib/svgplot/plot.rb', line 431

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.



581
582
583
# File 'lib/svgplot/plot.rb', line 581

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



586
587
588
# File 'lib/svgplot/plot.rb', line 586

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.



597
598
599
# File 'lib/svgplot/plot.rb', line 597

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.



507
508
509
# File 'lib/svgplot/plot.rb', line 507

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



512
513
514
# File 'lib/svgplot/plot.rb', line 512

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.



474
475
476
# File 'lib/svgplot/plot.rb', line 474

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

#hlineToA(x) ⇒ Object



479
480
481
# File 'lib/svgplot/plot.rb', line 479

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.



458
459
460
# File 'lib/svgplot/plot.rb', line 458

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

#lineToA(x, y) ⇒ Object



463
464
465
# File 'lib/svgplot/plot.rb', line 463

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.



442
443
444
# File 'lib/svgplot/plot.rb', line 442

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

#moveToA(x, y) ⇒ Object



447
448
449
# File 'lib/svgplot/plot.rb', line 447

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.



542
543
544
# File 'lib/svgplot/plot.rb', line 542

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

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



547
548
549
# File 'lib/svgplot/plot.rb', line 547

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.



525
526
527
# File 'lib/svgplot/plot.rb', line 525

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

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



530
531
532
# File 'lib/svgplot/plot.rb', line 530

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.



559
560
561
# File 'lib/svgplot/plot.rb', line 559

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

#sqcurveToA(dx, dy) ⇒ Object



564
565
566
# File 'lib/svgplot/plot.rb', line 564

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.



490
491
492
# File 'lib/svgplot/plot.rb', line 490

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

#vlineToA(y) ⇒ Object



495
496
497
# File 'lib/svgplot/plot.rb', line 495

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