diff options
| author | Randy Morgan <[email protected]> | 2011-11-23 21:45:54 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2011-11-23 21:45:54 +0900 |
| commit | c8c63518b4d58ca8875f81602792050cbec318f2 (patch) | |
| tree | 14f6e2c5286e5509879b6b664205f3ea2f38180c /lib/axlsx/drawing/drawing.rb | |
| parent | 2dea87f6f601795e32c7c14fbba5717c4b04fc1e (diff) | |
| download | caxlsx-c8c63518b4d58ca8875f81602792050cbec318f2.tar.gz caxlsx-c8c63518b4d58ca8875f81602792050cbec318f2.zip | |
Adding image support and some document clean up for .8 release
Diffstat (limited to 'lib/axlsx/drawing/drawing.rb')
| -rw-r--r-- | lib/axlsx/drawing/drawing.rb | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/lib/axlsx/drawing/drawing.rb b/lib/axlsx/drawing/drawing.rb index 385cd592..17347cd1 100644 --- a/lib/axlsx/drawing/drawing.rb +++ b/lib/axlsx/drawing/drawing.rb @@ -16,6 +16,8 @@ module Axlsx require 'axlsx/drawing/val_axis_data.rb' require 'axlsx/drawing/marker.rb' + + require 'axlsx/drawing/one_cell_anchor.rb' require 'axlsx/drawing/two_cell_anchor.rb' require 'axlsx/drawing/graphic_frame.rb' @@ -25,6 +27,9 @@ module Axlsx require 'axlsx/drawing/bar_3D_chart.rb' require 'axlsx/drawing/line_3D_chart.rb' + + require 'axlsx/drawing/pic.rb' + # 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. # @note The recommended way to manage drawings is to use the Worksheet.add_chart method. @@ -46,6 +51,10 @@ module Axlsx # @return [Array] attr_reader :charts + # An array of image objects that are associated with this drawing's anchors + # @return [Array] + attr_reader :images + # The index of this drawing in the owning workbooks's drawings collection. # @return [Integer] attr_reader :index @@ -72,20 +81,33 @@ module Axlsx DataTypeValidator.validate "Drawing.worksheet", Worksheet, worksheet @worksheet = worksheet @worksheet.workbook.drawings << self - @anchors = SimpleTypedList.new TwoCellAnchor + @anchors = SimpleTypedList.new [TwoCellAnchor, OneCellAnchor] + end + + # Adds an image to the chart + # @note The recommended way to manage images is to use Worksheet.add_image. Please refer to that method for documentation. + # @see Worksheet#add_image + def add_image(options={}) + OneCellAnchor.new(self, options) + @anchors.last.object end - # Adds a chart to the drawing. # @note The recommended way to manage charts is to use Worksheet.add_chart. Please refer to that method for documentation. # @see Worksheet#add_chart def add_chart(chart_type, options={}) - TwoCellAnchor.new(self, chart_type, options) - @anchors.last.graphic_frame.chart + TwoCellAnchor.new(self, options) + @anchors.last.add_chart(chart_type, options) end def charts - @anchors.map { |a| a.graphic_frame.chart } + charts = @anchors.select { |a| a.object.is_a?(GraphicFrame) } + charts.map { |a| a.object.chart } + end + + def images + images = @anchors.select { |a| a.object.is_a?(Pic) } + images.map { |a| a.object } end def index @@ -106,10 +128,12 @@ module Axlsx def relationships r = Relationships.new - @anchors.each do |anchor| - chart = anchor.graphic_frame.chart + 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 |
