Class: DYI::Shape::ReusedShape

Inherits:
Base show all
Defined in:
lib/dyi/shape/reused_shape.rb

Overview

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.3.0

Constant Summary

Constants inherited from GraphicalElement

GraphicalElement::CLASS_REGEXP

Constants inherited from Element

Element::ID_REGEXP

Instance Attribute Summary collapse

Attributes inherited from Base

#anchor_href, #anchor_target, #attributes, #clipping, #parent

Attributes inherited from GraphicalElement

#css_class

Attributes inherited from Element

#description, #title

Instance Method Summary collapse

Methods inherited from Base

#add_animation, #add_painting_animation, #add_transform_animation, #animate?, #animations, #clear_clipping, #draw_on, #has_marker?, #root_element?, #root_node?, #rotate, #scale, #set_clipping, #set_clipping_shapes, #set_event, #skew_x, #skew_y, #transform, #translate

Methods inherited from GraphicalElement

#add_css_class, #add_event_listener, #css_classes, #event_listeners, #event_target?, #remove_css_class, #remove_event_listener, #set_event, #to_reused_source

Methods inherited from Element

#canvas, #id, #id=, #include_external_file?, #inner_id

Constructor Details

#initialize(source_element, left_top, options = {}) ⇒ ReusedShape

Returns a new instance of ReusedShape.

Since:

  • 1.3.0



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/dyi/shape/reused_shape.rb', line 39

def initialize(source_element, left_top, options={})
  @source_element = source_element.to_reused_source
  width = Length.new_or_nil(options.delete(:width))
  height = Length.new_or_nil(options.delete(:height))
  @lt_pt = Coordinate.new(left_top)
  @lt_pt += Coordinate.new(width, 0) if width && width < Length::ZERO
  @lt_pt += Coordinate.new(0, height) if height && height < Length::ZERO
  @width = width && width.abs
  @height = height && height.abs
  @attributes = init_attributes(options)
  source_element.publish_id
end

Instance Attribute Details

#source_elementObject (readonly)

Since:

  • 1.3.0



31
32
33
# File 'lib/dyi/shape/reused_shape.rb', line 31

def source_element
  @source_element
end

Instance Method Details

#bottomLength

Returns a y-axis coordinate of the bottom of the re-used shape.

Returns:

  • (Length)

    a y-axis coordinate of the bottom

Since:

  • 1.3.0



72
73
74
# File 'lib/dyi/shape/reused_shape.rb', line 72

def bottom
  height && (@lt_pt.y + height)
end

#centerCoordinate

Returns a coordinate of the center of the re-used shape.

Returns:

Since:

  • 1.3.0



78
79
80
# File 'lib/dyi/shape/reused_shape.rb', line 78

def center
  width && height && (@lt_pt + Coordinate.new(width.quo(2), height.quo(2)))
end

#child_elementsObject

Since:

  • 1.3.0



82
83
84
# File 'lib/dyi/shape/reused_shape.rb', line 82

def child_elements
  source_element.child_elements
end

#has_uri_reference?Boolean

Returns whether the element has a URI reference.

Returns:

  • (Boolean)

    whether the element has a URI reference

Since:

  • 1.3.0



87
88
89
# File 'lib/dyi/shape/reused_shape.rb', line 87

def has_uri_reference?
  true
end

#leftLength

Returns a x-axis coordinate of the left side of the re-used shape.

Returns:

  • (Length)

    the x-axis coordinate of the left side

Since:

  • 1.3.0



54
55
56
# File 'lib/dyi/shape/reused_shape.rb', line 54

def left
  @lt_pt.x
end

#rightLength

Returns a x-axis coordinate of the right side of the re-used shape.

Returns:

  • (Length)

    the x-axis coordinate of the right side

Since:

  • 1.3.0



60
61
62
# File 'lib/dyi/shape/reused_shape.rb', line 60

def right
  width && (@lt_pt.x + width)
end

#topLength

Returns a y-axis coordinate of the top of the re-used shape.

Returns:

  • (Length)

    a y-axis coordinate of the top

Since:

  • 1.3.0



66
67
68
# File 'lib/dyi/shape/reused_shape.rb', line 66

def top
  @lt_pt.y
end

#write_as(formatter, io = $>) ⇒ Object

Writes image on io object.

Parameters:

  • formatter (Formatter::Base)

    an object that defines the image format

  • io (IO) (defaults to: $>)

    an io to be written

Since:

  • 1.3.0



94
95
96
# File 'lib/dyi/shape/reused_shape.rb', line 94

def write_as(formatter, io=$>)
  formatter.write_reused_shape(self, io)
end