From 4d16bfc43780e5d3f7368625700b583e3e98217a Mon Sep 17 00:00:00 2001
From: Randy Morgan The recommended way to manage drawings is to use the Worksheet.add_chart
-method.
+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
+
+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.
A collection of anchors for this drawing only TwoCellAnchors are supported -in this version.
++A collection of anchors for this drawing only TwoCellAnchors are supported +in this version. +
The worksheet that owns the drawing.
++The worksheet that owns the drawing. +
Adds a chart to the drawing.
++Adds a chart to the drawing. +
Adds an image to the chart.
++Adds an image to the chart. +
An array of charts that are associated with this drawing's anchors.
++An array of charts that are associated with this drawing’s anchors. +
An array of image objects that are associated with this drawing's anchors.
++An array of image objects that are associated with this drawing’s +anchors. +
The index of this drawing in the owning workbooks's drawings collection.
++The index of this drawing in the owning workbooks’s drawings +collection. +
Creates a new Drawing object.
++Creates a new Drawing object. +
The part name for this drawing.
++The part name for this drawing. +
The drawing's relationships.
++The drawing’s relationships. +
The relational part name for this drawing.
++The relational part name for this drawing. +
The relation reference id for this drawing.
++The relation reference id for this drawing. +
Serializes the drawing.
++Serializes the drawing. +
Creates a new Drawing object
++Creates a new Drawing object +
The worksheet that owns this drawing
++The worksheet that owns this drawing +
# File 'lib/axlsx/drawing/drawing.rb', line 52 -def initialize(worksheet) - DataTypeValidator.validate "Drawing.worksheet", Worksheet, worksheet - @worksheet = worksheet - @worksheet.workbook.drawings << self - @anchors = SimpleTypedList.new [TwoCellAnchor, OneCellAnchor] -end+def initialize(worksheet) + DataTypeValidator.validate "Drawing.worksheet", Worksheet, worksheet + @worksheet = worksheet + @worksheet.workbook.drawings << self + @anchors = SimpleTypedList.new [TwoCellAnchor, OneCellAnchor] +end +
A collection of anchors for this drawing only TwoCellAnchors are supported -in this version
++A collection of anchors for this drawing only TwoCellAnchors are supported +in this version +
# File 'lib/axlsx/drawing/drawing.rb', line 48 -def anchors - @anchors -end+def anchors + @anchors +end +
The worksheet that owns the drawing
++The worksheet that owns the drawing +
# File 'lib/axlsx/drawing/drawing.rb', line 43 -def worksheet - @worksheet -end+def worksheet + @worksheet +end +
The recommended way to manage charts is to use Worksheet.add_chart. Please -refer to that method for documentation.
++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.
++Adds a chart to the drawing. +
# File 'lib/axlsx/drawing/drawing.rb', line 70 -def add_chart(chart_type, ={}) - TwoCellAnchor.new(self, ) - @anchors.last.add_chart(chart_type, ) -end+def add_chart(chart_type, ={}) + TwoCellAnchor.new(self, ) + @anchors.last.add_chart(chart_type, ) +end +
The recommended way to manage images is to use Worksheet.add_image. Please -refer to that method for documentation.
++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
++Adds an image to the chart +
# File 'lib/axlsx/drawing/drawing.rb', line 62 -def add_image(={}) - OneCellAnchor.new(self, ) - @anchors.last.object -end+def add_image(={}) + OneCellAnchor.new(self, ) + @anchors.last.object +end +
An array of charts that are associated with this drawing's anchors
++An array of charts that are associated with this drawing’s anchors +
# File 'lib/axlsx/drawing/drawing.rb', line 77 -def charts - charts = @anchors.select { |a| a.object.is_a?(GraphicFrame) } - charts.map { |a| a.object.chart } -end+def charts + charts = @anchors.select { |a| a.object.is_a?(GraphicFrame) } + charts.map { |a| a.object.chart } +end +
An array of image objects that are associated with this drawing's anchors
++An array of image objects that are associated with this drawing’s +anchors +
# File 'lib/axlsx/drawing/drawing.rb', line 84 -def images - images = @anchors.select { |a| a.object.is_a?(Pic) } - images.map { |a| a.object } -end+def images + images = @anchors.select { |a| a.object.is_a?(Pic) } + images.map { |a| a.object } +end +
The index of this drawing in the owning workbooks's drawings collection.
++The index of this drawing in the owning workbooks’s drawings +collection. +
# File 'lib/axlsx/drawing/drawing.rb', line 91 -def index - @worksheet.workbook.drawings.index(self) -end+def index + @worksheet.workbook.drawings.index(self) +end +
The part name for this drawing
++The part name for this drawing +
# File 'lib/axlsx/drawing/drawing.rb', line 103 -def pn - "#{DRAWING_PN % (index+1)}" -end+def pn + "#{DRAWING_PN % (index+1)}" +end +
The drawing's relationships.
++The drawing’s relationships. +
# File 'lib/axlsx/drawing/drawing.rb', line 115 -def relationships - r = Relationships.new - charts.each do |chart| - r << Relationship.new(CHART_R, "../#{chart.pn}") - end - images.each do |image| - r << Relationship.new(IMAGE_R, "../#{image.pn}") - end - r -end+def relationships + r = Relationships.new + charts.each do |chart| + r << Relationship.new(CHART_R, "../#{chart.pn}") + end + images.each do |image| + r << Relationship.new(IMAGE_R, "../#{image.pn}") + end + r +end +
The relational part name for this drawing
++The relational part name for this drawing +
# File 'lib/axlsx/drawing/drawing.rb', line 109 -def rels_pn - "#{DRAWING_RELS_PN % (index+1)}" -end+def rels_pn + "#{DRAWING_RELS_PN % (index+1)}" +end +
The relation reference id for this drawing
++The relation reference id for this drawing +
# File 'lib/axlsx/drawing/drawing.rb', line 97 -def rId - "rId#{index+1}" -end+def rId + "rId#{index+1}" +end +
Serializes the drawing
++Serializes the drawing +
# File 'lib/axlsx/drawing/drawing.rb', line 128 -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+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 +