module DYI::Shape::Markable

This module defines the method to attach a marker symbol to the lines, the polylines, the polygons or the paths. @since 1.2.0

Public Instance Methods

has_marker?(position) click to toggle source

Returns whether this shape has a marker symbol. @param [Symbol] position the position where a marker symbol is drawn.

Specifies the following values: +:start+, +:mid+, +:end+

@return [Boolean] true if the shape has a marker at the cpecified point,

false otherwise
# File lib/dyi/shape/base.rb, line 110
def has_marker?(position)
  !@marker[position].nil?
end
marker(position) click to toggle source

Returns a marker symbol at the specified position. @param [Symbol] position the position where a marker symbol is drawn.

Specifies the following values: +:start+, +:mid+, +:end+

@return [Marker] a marker symbol at the specified position

# File lib/dyi/shape/base.rb, line 35
def marker(position)
  @marker[position]
end
set_marker(position, *args) click to toggle source

Attaches a marker symbol to the shape. @overload set_marker(position, marker)

Attaches the specified marker symbol at the specified position.
@param [Symbol] position the position where a marker symbol is drawn.
  Specifies the following values: +:start+, +:mid+, +:end+,
  +:start_end+, +:start_mid+, +:mid_end+, +:all+
@param [Marker] marker the marker symbol that is attached

@overload set_marker(position, marker_type, options = {})

Attaches a pre-defined marker symbol at the specified position.
@param [Symbol] position the position where a marker symbol is drawn.
  Specifies the following values: +:start+, +:mid+, +:end+,
  +:start_end+, +:start_mid+, +:mid_end+, +:all+
@param [Symbol] marker_type the type of pre-defined marker symbol that
  +:square+ is attached. Specifies the following values: +:circle+,
  +:triangle+, +:rhombus+, +:pentagon+, +:hexagon+
@param [Hash] options a customizable set of options
@option options [Number] :size size of the marker symbol. Specifies
  the relative size to line width
@option options [Painting] :painting painting of the marker symbol
@option options [Number, "auto"] :orient how the marker is rotated.
  Specifies a rotated angle or <tt>"auto"</tt>. <tt>"auto"</tt> means
  the marker symbol rotate the orientation of the line
# File lib/dyi/shape/base.rb, line 61
def set_marker(position, *args)
  pos = case position
          when :start then 0x1
          when :mid then 0x2
          when :end then 0x4
          when :start_mid then 0x3
          when :start_end then 0x5
          when :mid_end then 0x6
          when :all then 0x7
          else raise ArgumentError, "illegal argument: #{position.inspect}"
        end
  case args.first
  when Symbol
    opts = args[1].clone || {}
    opts[:painting] ||= Painting.new(:fill => painting.stroke,
                                     :fill_opacity => painting.stroke_opacity,
                                     :opacity => painting.opacity)
    if opts[:orient] == 'auto'
      opts[:direction] = position == :end ? :to_end : :to_start
    end
    marker = Marker.new(args.first, opts)
  when Marker
    marker = args.first
  else
    raise TypeError, "illegal argument: #{value}"
  end
  marker.set_canvas(canvas)
  @marker[:start] = marker if pos & 0x01 != 0
  @marker[:mid] = marker if pos & 0x02 != 0
  if pos & 0x04 != 0
    if pos & 0x01 != 0 && args.first.is_a?(Symbol) && opts[:orient] == 'auto'
      opts[:painting] ||= Painting.new(:fill => painting.stroke,
                                       :fill_opacity => painting.stroke_opacity,
                                       :opacity => painting.opacity)
      opts[:direction] = :to_end
      marker = Marker.new(args.first, opts)
      marker.set_canvas(canvas)
      @marker[:end] = marker
    else
      @marker[:end] = marker
    end
  end
end