diff options
| author | Randy Morgan <[email protected]> | 2012-05-26 14:40:24 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-05-26 14:40:24 +0900 |
| commit | ea66a00e1a6275ce263ba943c45d1e6ff844eb0c (patch) | |
| tree | 4d71435599dbc842b6ab119633d771b07a5ab3a5 /lib | |
| parent | ddb30e7e45e88082c268b902e60f62d48d855c70 (diff) | |
| download | caxlsx-ea66a00e1a6275ce263ba943c45d1e6ff844eb0c.tar.gz caxlsx-ea66a00e1a6275ce263ba943c45d1e6ff844eb0c.zip | |
add in two cell anchors for images.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/axlsx/drawing/drawing.rb | 9 | ||||
| -rw-r--r-- | lib/axlsx/drawing/pic.rb | 18 | ||||
| -rw-r--r-- | lib/axlsx/drawing/two_cell_anchor.rb | 7 |
3 files changed, 31 insertions, 3 deletions
diff --git a/lib/axlsx/drawing/drawing.rb b/lib/axlsx/drawing/drawing.rb index 943c0f2d..b06130f1 100644 --- a/lib/axlsx/drawing/drawing.rb +++ b/lib/axlsx/drawing/drawing.rb @@ -68,11 +68,16 @@ module Axlsx @anchors = SimpleTypedList.new [TwoCellAnchor, OneCellAnchor] end - # Adds an image to the chart + # Adds an image to the chart If th end_at option is specified we create a two cell anchor. By default we use a one cell anchor. # @note The recommended way to manage images is to use Worksheet.add_image. Please refer to that method for documentation. # @see Worksheet#add_image + # @return [Pic] def add_image(options={}) - OneCellAnchor.new(self, options) + if options[:end_at] + TwoCellAnchor.new(self, options).add_pic(options) + else + OneCellAnchor.new(self, options) + end @anchors.last.object end diff --git a/lib/axlsx/drawing/pic.rb b/lib/axlsx/drawing/pic.rb index e5e005fa..e7b5bbbb 100644 --- a/lib/axlsx/drawing/pic.rb +++ b/lib/axlsx/drawing/pic.rb @@ -113,23 +113,29 @@ module Axlsx # @param [Integer] v # @see OneCellAnchor.width def width + return unless @anchor.is_a?(OneCellAnchor) @anchor.width end # @see width def width=(v) + return unless @anchor.is_a?(OneCellAnchor) @anchor.width = v end # providing access to update the anchor's height attribute # @param [Integer] v # @see OneCellAnchor.width + # @note this is a noop if you are using a TwoCellAnchor def height + return unless @anchor.is_a?(OneCellAnchor) @anchor.height end # @see height + # @note This is a noop if you are using a TwoCellAnchor def height=(v) + return unless @anchor.is_a?(OneCellAnchor) @anchor.height = v end @@ -142,6 +148,18 @@ module Axlsx def start_at(x, y) @anchor.from.col = x @anchor.from.row = y + @anchor.from + end + + # noop if not using a two cell anchor + # @param [Integer] x The column + # @param [Integer] y The row + # @return [Marker] + def end_at(x, y) + return unless @anchor.is_a?(TwoCellAnchor) + @anchor.to.col = x + @anchor.to.row = y + @anchor.to end # Serializes the object diff --git a/lib/axlsx/drawing/two_cell_anchor.rb b/lib/axlsx/drawing/two_cell_anchor.rb index b496bd8a..8071515c 100644 --- a/lib/axlsx/drawing/two_cell_anchor.rb +++ b/lib/axlsx/drawing/two_cell_anchor.rb @@ -34,7 +34,7 @@ module Axlsx # @param [Drawing] drawing # @param [Class] chart_type This is passed to the graphic frame for instantiation. must be Chart or a subclass of Chart # @param object The object this anchor holds. - # @option options [Array] start_at the col, row to start at + # @option options [Array] start_at the col, row to start at THIS IS DOCUMENTED BUT NOT IMPLEMENTED HERE! # @option options [Array] end_at the col, row to end at def initialize(drawing, options={}) @drawing = drawing @@ -49,6 +49,11 @@ module Axlsx @object.chart end + # Creates an image associated with this anchor. + def add_pic(options={}) + @object = Pic.new(self, options) + end + # The index of this anchor in the drawing # @return [Integer] def index |
