lib/axlsx/drawing/two_cell_anchor.rb in axlsx-1.1.8 vs lib/axlsx/drawing/two_cell_anchor.rb in axlsx-1.2.0
- old
+ new
@@ -23,11 +23,10 @@
# The drawing that holds this anchor
# @return [Drawing]
attr_reader :drawing
-
# Creates a new TwoCellAnchor object
# c.start_at 5, 9
# @param [Drawing] drawing
# @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
@@ -35,10 +34,26 @@
@drawing = drawing
drawing.anchors << self
@from, @to = Marker.new, Marker.new(:col => 5, :row=>10)
end
+ # sets the col, row attributes for the from marker.
+ # @note The recommended way to set the start position for graphical
+ # objects is directly thru the object.
+ # @see Chart#start_at
+ def start_at(x, y)
+ set_marker_coords(x, y, from)
+ end
+
+ # sets the col, row attributes for the to marker
+ # @note the recommended way to set the to position for graphical
+ # objects is directly thru the object
+ # @see Char#end_at
+ def end_at(x, y)
+ set_marker_coords(x, y, to)
+ end
+
# Creates a graphic frame and chart object associated with this anchor
# @return [Chart]
def add_chart(chart_type, options)
@object = GraphicFrame.new(self, chart_type, options)
@object.chart
@@ -68,8 +83,30 @@
str << '</xdr:to>'
object.to_xml_string(str)
str << '<xdr:clientData/>'
str << '</xdr:twoCellAnchor>'
end
+ private
+
+ # parses coordinates and sets up a marker's row/col propery
+ def set_marker_coords(x, y, marker)
+ marker.col, marker.row = *parse_coord_args(x, y)
+ end
+
+ # handles multiple inputs for setting the position of a marker
+ # @see Chart#start_at
+ def parse_coord_args(x, y=0)
+ if x.is_a?(String)
+ x, y = *Axlsx::name_to_indices(x)
+ end
+ if x.is_a?(Cell)
+ x, y = *x.pos
+ end
+ if x.is_a?(Array)
+ x, y = *x
+ end
+ [x, y]
+ end
+
end
end