Class: Axlsx::Drawing
- Inherits:
-
Object
- Object
- Axlsx::Drawing
- Defined in:
- lib/axlsx/drawing/drawing.rb
Overview
The recommended way to manage drawings is to use the Worksheet.add_chart method.
A Drawing is a canvas for charts. Each worksheet has a single drawing that manages anchors. The anchors reference the charts via graphical frames. This is not a trivial relationship so please do follow the advice in the note. see README for an example of how to create a chart.
Instance Attribute Summary collapse
-
#anchors ⇒ SimpleTypedList
readonly
A collection of anchors for this drawing only TwoCellAnchors are supported in this version.
-
#charts ⇒ Array
readonly
An array of charts that are associated with this drawing’s anchors.
-
#images ⇒ Array
readonly
An array of image objects that are associated with this drawing’s anchors.
-
#index ⇒ Integer
readonly
The index of this drawing in the owning workbooks’s drawings collection.
-
#pn ⇒ String
readonly
The part name for this drawing.
-
#relationships ⇒ Relationships
readonly
The drawing’s relationships.
-
#rels_pn ⇒ String
readonly
The relational part name for this drawing.
-
#rId ⇒ String
readonly
The relation reference id for this drawing.
-
#worksheet ⇒ Worksheet
readonly
The worksheet that owns the drawing.
Instance Method Summary collapse
-
#add_chart(chart_type, options = {}) ⇒ Object
Adds a chart to the drawing.
-
#add_image(options = {}) ⇒ Object
Adds an image to the chart.
-
#initialize(worksheet) ⇒ Drawing
constructor
Creates a new Drawing object.
-
#to_xml ⇒ String
Serializes the drawing.
Constructor Details
#initialize(worksheet) ⇒ Drawing
Creates a new Drawing object
80 81 82 83 84 85 |
# File 'lib/axlsx/drawing/drawing.rb', line 80 def initialize(worksheet) DataTypeValidator.validate "Drawing.worksheet", Worksheet, worksheet @worksheet = worksheet @worksheet.workbook.drawings << self @anchors = SimpleTypedList.new [TwoCellAnchor, OneCellAnchor] end |
Instance Attribute Details
#anchors ⇒ SimpleTypedList (readonly)
A collection of anchors for this drawing only TwoCellAnchors are supported in this version
48 49 50 |
# File 'lib/axlsx/drawing/drawing.rb', line 48 def anchors @anchors end |
#charts ⇒ Array (readonly)
An array of charts that are associated with this drawing’s anchors
52 53 54 |
# File 'lib/axlsx/drawing/drawing.rb', line 52 def charts @charts end |
#images ⇒ Array (readonly)
An array of image objects that are associated with this drawing’s anchors
56 57 58 |
# File 'lib/axlsx/drawing/drawing.rb', line 56 def images @images end |
#index ⇒ Integer (readonly)
The index of this drawing in the owning workbooks’s drawings collection.
60 61 62 |
# File 'lib/axlsx/drawing/drawing.rb', line 60 def index @index end |
#pn ⇒ String (readonly)
The part name for this drawing
68 69 70 |
# File 'lib/axlsx/drawing/drawing.rb', line 68 def pn @pn end |
#relationships ⇒ Relationships (readonly)
The drawing’s relationships.
76 77 78 |
# File 'lib/axlsx/drawing/drawing.rb', line 76 def relationships @relationships end |
#rels_pn ⇒ String (readonly)
The relational part name for this drawing
72 73 74 |
# File 'lib/axlsx/drawing/drawing.rb', line 72 def rels_pn @rels_pn end |
#rId ⇒ String (readonly)
The relation reference id for this drawing
64 65 66 |
# File 'lib/axlsx/drawing/drawing.rb', line 64 def rId @rId end |
#worksheet ⇒ Worksheet (readonly)
The worksheet that owns the drawing
43 44 45 |
# File 'lib/axlsx/drawing/drawing.rb', line 43 def worksheet @worksheet end |
Instance Method Details
#add_chart(chart_type, options = {}) ⇒ Object
The recommended way to manage charts is to use Worksheet.add_chart. Please refer to that method for documentation.
Adds a chart to the drawing.
98 99 100 101 |
# File 'lib/axlsx/drawing/drawing.rb', line 98 def add_chart(chart_type, ={}) TwoCellAnchor.new(self, ) @anchors.last.add_chart(chart_type, ) end |
#add_image(options = {}) ⇒ Object
The recommended way to manage images is to use Worksheet.add_image. Please refer to that method for documentation.
Adds an image to the chart
90 91 92 93 |
# File 'lib/axlsx/drawing/drawing.rb', line 90 def add_image(={}) OneCellAnchor.new(self, ) @anchors.last.object end |
#to_xml ⇒ String
Serializes the drawing
142 143 144 145 146 147 148 149 |
# File 'lib/axlsx/drawing/drawing.rb', line 142 def to_xml builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml| xml.send('xdr:wsDr', :'xmlns:xdr'=>XML_NS_XDR, :'xmlns:a'=>XML_NS_A) { anchors.each {|anchor| anchor.to_xml(xml) } } end builder.to_xml end |