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, specifying the chart class, start and end marker locations.
A Drawing is a canvas for charts. Each worksheet has a single drawing that can specify multiple anchors which reference charts.
Instance Attribute Summary collapse
-
#anchors ⇒ SimpleTypedList
readonly
A collection of anchors for this drawing.
-
#charts ⇒ Array
readonly
An array of charts 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.
-
#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
63 64 65 66 67 68 |
# File 'lib/axlsx/drawing/drawing.rb', line 63 def initialize(worksheet) DataTypeValidator.validate "Drawing.worksheet", Worksheet, worksheet @worksheet = worksheet @worksheet.workbook.drawings << self @anchors = SimpleTypedList.new TwoCellAnchor end |
Instance Attribute Details
#anchors ⇒ SimpleTypedList (readonly)
A collection of anchors for this drawing
35 36 37 |
# File 'lib/axlsx/drawing/drawing.rb', line 35 def anchors @anchors end |
#charts ⇒ Array (readonly)
An array of charts that are associated with this drawing’s anchors
39 40 41 |
# File 'lib/axlsx/drawing/drawing.rb', line 39 def charts @charts end |
#index ⇒ Integer (readonly)
The index of this drawing in the owning workbooks’s drawings collection.
43 44 45 |
# File 'lib/axlsx/drawing/drawing.rb', line 43 def index @index end |
#pn ⇒ String (readonly)
The part name for this drawing
51 52 53 |
# File 'lib/axlsx/drawing/drawing.rb', line 51 def pn @pn end |
#relationships ⇒ Relationships (readonly)
The drawing’s relationships.
59 60 61 |
# File 'lib/axlsx/drawing/drawing.rb', line 59 def relationships @relationships end |
#rels_pn ⇒ String (readonly)
The relational part name for this drawing
55 56 57 |
# File 'lib/axlsx/drawing/drawing.rb', line 55 def rels_pn @rels_pn end |
#rId ⇒ String (readonly)
The relation reference id for this drawing
47 48 49 |
# File 'lib/axlsx/drawing/drawing.rb', line 47 def rId @rId end |
#worksheet ⇒ Worksheet (readonly)
The worksheet that owns the drawing
30 31 32 |
# File 'lib/axlsx/drawing/drawing.rb', line 30 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.
Adds a chart to the drawing.
75 76 77 78 79 |
# File 'lib/axlsx/drawing/drawing.rb', line 75 def add_chart(chart_type, ={}) DataTypeValidator.validate "Drawing.chart_type", Chart, chart_type TwoCellAnchor.new(self, chart_type, ) @anchors.last.graphic_frame.chart end |
#to_xml ⇒ String
Serializes the drawing
112 113 114 115 116 117 118 119 |
# File 'lib/axlsx/drawing/drawing.rb', line 112 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 |