summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/drawing/marker.rb
blob: 985cf321c7fad3dfa784c5780598ab02b2f352b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# encoding: UTF-8
module Axlsx
  # The Marker class defines a point in the worksheet that drawing anchors attach to.
  # @note The recommended way to manage markers is Worksheet#add_chart Markers are created for a two cell anchor based on the :start and :end options.
  # @see Worksheet#add_chart
  class Marker

    # The column this marker anchors to
    # @return [Integer]
    attr_reader :col

    # The offset distance from this marker's column
    # @return [Integer]
    attr_reader :colOff

    # The row this marker anchors to
    # @return [Integer]
    attr_reader :row

    # The offset distance from this marker's row
    # @return [Integer]
    attr_reader :rowOff

    # Creates a new Marker object
    # @option options [Integer] col
    # @option options [Integer] colOff
    # @option options [Integer] row
    # @option options [Integer] rowOff
    def initialize(options={})
      @col, @colOff, @row, @rowOff = 0, 0, 0, 0
      options.each do |o|
        self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
      end
    end

    # @see col
    def col=(v) Axlsx::validate_unsigned_int v; @col = v end
    # @see colOff
    def colOff=(v) Axlsx::validate_int v; @colOff = v end
    # @see row
    def row=(v) Axlsx::validate_unsigned_int v; @row = v end
    # @see rowOff
    def rowOff=(v) Axlsx::validate_int v; @rowOff = v end

    # shortcut to set the column, row position for this marker
    # @param col the column for the marker
    # @param row the row of the marker
    def coord(col, row)
      self.col = col
      self.row = row
    end

    def to_xml_string(str = '')
      [:col, :colOff, :row, :rowOff].each do |k|
        str << '<xdr:' << k.to_s << '>' << self.send(k).to_s << '</xdr:' << k.to_s << '>'
      end
    end

  end

end