Class: Axlsx::TwoCellAnchor

Inherits:
Object
  • Object
show all
Defined in:
lib/axlsx/drawing/two_cell_anchor.rb

Overview

Note:

The recommended way to manage drawings and charts is Worksheet#add_chart. Anchors are specified by the :start_at and :end_at options to that method.

This class details the anchor points for drawings.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(drawing, options = {}) ⇒ TwoCellAnchor

Note:

the chart_type parameter will be replaced with object in v. 2.0.0

Creates a new TwoCellAnchor object and sets up a reference to the from and to markers in the graphic_frame’s chart. That means that you can do stuff like c = worksheet.add_chart Axlsx::Chart c.start_at 5, 9

Parameters:

  • drawing (Drawing)
  • chart_type (Class)

    This is passed to the graphic frame for instantiation. must be Chart or a subclass of Chart

  • object

    The object this anchor holds.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • start_at (Array)

    the col, row to start at

  • end_at (Array)

    the col, row to end at



39
40
41
42
43
# File 'lib/axlsx/drawing/two_cell_anchor.rb', line 39

def initialize(drawing, options={})
  @drawing = drawing
  drawing.anchors << self
  @from, @to =  Marker.new, Marker.new(:col => 5, :row=>10)
end

Instance Attribute Details

#drawingDrawing (readonly)

The drawing that holds this anchor

Returns:



26
27
28
# File 'lib/axlsx/drawing/two_cell_anchor.rb', line 26

def drawing
  @drawing
end

#fromMarker (readonly)

A marker that defines the from cell anchor. The default from column and row are 0 and 0 respectively

Returns:



10
11
12
# File 'lib/axlsx/drawing/two_cell_anchor.rb', line 10

def from
  @from
end

#objectPic, GraphicFrame (readonly)

The object this anchor hosts

Returns:



22
23
24
# File 'lib/axlsx/drawing/two_cell_anchor.rb', line 22

def object
  @object
end

#toMarker (readonly)

A marker that returns the to cell anchor. The default to column and row are 5 and 10 respectively

Returns:



13
14
15
# File 'lib/axlsx/drawing/two_cell_anchor.rb', line 13

def to
  @to
end

Instance Method Details

#add_chart(chart_type, options) ⇒ Chart

Creates a graphic frame and chart object associated with this anchor

Returns:



47
48
49
50
# File 'lib/axlsx/drawing/two_cell_anchor.rb', line 47

def add_chart(chart_type, options)
  @object = GraphicFrame.new(self, chart_type, options)
  @object.chart
end

#indexInteger

The index of this anchor in the drawing

Returns:

  • (Integer)


54
55
56
# File 'lib/axlsx/drawing/two_cell_anchor.rb', line 54

def index
  @drawing.anchors.index(self)
end

#to_xml_string(str = '') ⇒ String

Serializes the object

Parameters:

  • str (String) (defaults to: '')

Returns:

  • (String)


61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/axlsx/drawing/two_cell_anchor.rb', line 61

def to_xml_string(str = '')
  str << '<xdr:twoCellAnchor>'
  str << '<xdr:from>'
  from.to_xml_string str
  str << '</xdr:from>'
  str << '<xdr:to>'
  to.to_xml_string str
  str << '</xdr:to>'
  object.to_xml_string(str)
  str << '<xdr:clientData/>'
  str << '</xdr:twoCellAnchor>'
end