class DYI::Shape::Marker
Marker
object represents a symbol at One or more vertices of the lines.
Marker
provides some pre-defined shapes and a custom marker defined freely. @since 1.2.0
Attributes
canvas[RW]
height[RW]
marker_units[RW]
orient[RW]
ref_point[RW]
shapes[RW]
view_box[RW]
width[RW]
Public Class Methods
new(shape, options={})
click to toggle source
@overload initialize(marker_type, options = {})
Creates a new pre-defined marker. @param [Symbol] marker_type a type of the marker. Specifies the following: +:circle+, +:triangle+, +:inverted_triangle+, +:square+, +:rhombus+, +:inverted_pentagon+, +:hexagon+ @option options [Number] :size size of the marker. Specifies the relative size to line width @option options [Painting] :painting painting of the marker @option options [Number, "auto"] :orient how the marker is rotated. Specifies a rotated angle or <tt>"auto"</tt>. <tt>"auto"</tt> means the marker rotate the orientation of the line @option options [Symbol] :direction a direction of the marker. This option is valid if option +:orient+ value is <tt>"auto"</tt>. Specifies the following: +:to_start+, +:to_end+
@overload initialize(shapes, options = {})
Creates a new custom marker. @param [Shape::Base, Array<Shape::Base>] shapes a shape that represents marker @option options [String] :units a setting to define the coordinate system of the custom marker. @option options [String] :view_box @option options [Coordinate] :ref_point @option options [Length] :width @option options [Length] :height @option options [Number, nil] :orient
@raise [ArgumentError]
# File lib/dyi/shape/marker.rb, line 196 def initialize(shape, options={}) case shape when Symbol inverted = !!(shape.to_s =~ /^inverted_/) marker_source = @@predefined_markers[inverted ? $'.to_sym : shape] raise ArgumentError, "`#{shape}' is unknown marker" unless marker_source @ref_point = Coordinate::ZERO if options[:orient] == 'auto' direction = (inverted ^ (options[:direction] == :to_start)) ? :to_start : :to_end @orient = 'auto' else direction = nil @orient = (options[:orient] || 0) + (inverted ? 180 : 0) end @shapes = [marker_source[:creator].call(options[:painting] || {}, direction)] @view_box = marker_source[:view_box] @marker_units = 'strokeWidth' @width = @height = Length.new(options[:size] || 3) * marker_source[:magnify] when Shape::Base, Array @ref_point = options[:ref_point] || Coordinate::ZERO @shapes = shape.is_a?(Shape::Base) ? [shape] : shape @view_box = options[:view_box] || "0 0 3 3" @marker_units = options[:units] || 'strokeWidth' @width = Length.new(options[:width] || 3) @height = Length.new(options[:height] || 3) @orient = options[:orient] else raise ArgumentError, "argument is a wrong class" end end
Public Instance Methods
child_elements()
click to toggle source
# File lib/dyi/shape/marker.rb, line 235 def child_elements @shapes end
set_canvas(canvas)
click to toggle source
# File lib/dyi/shape/marker.rb, line 227 def set_canvas(canvas) if @canvas.nil? @canvas = canvas elsif @canvas != canvas raise Arguments, "the clipping is registered to another canvas" end end
write_as(formatter, io=$>)
click to toggle source
# File lib/dyi/shape/marker.rb, line 239 def write_as(formatter, io=$>) formatter.write_marker(self, io) end