summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-07-14 19:01:51 +0900
committerRandy Morgan <[email protected]>2012-07-14 19:01:51 +0900
commit85cb12036c6cb8c71851b6751709d945b7da4cf9 (patch)
treebe2a1c6c17a78ef8b93eaa05d06a391d509b7a81
parent2123e0d045c04d92bba98e6feb56ac94dff7d1cd (diff)
downloadcaxlsx-85cb12036c6cb8c71851b6751709d945b7da4cf9.tar.gz
caxlsx-85cb12036c6cb8c71851b6751709d945b7da4cf9.zip
refactoring of some helper methods in chart
-rw-r--r--lib/axlsx/drawing/chart.rb48
-rw-r--r--lib/axlsx/drawing/two_cell_anchor.rb39
2 files changed, 62 insertions, 25 deletions
diff --git a/lib/axlsx/drawing/chart.rb b/lib/axlsx/drawing/chart.rb
index 1f36dfe4..3047fec2 100644
--- a/lib/axlsx/drawing/chart.rb
+++ b/lib/axlsx/drawing/chart.rb
@@ -154,16 +154,32 @@ module Axlsx
str << '</c:chartSpace>'
end
- # This is a short cut method to set the start anchor position
+ # This is a short cut method to set the anchor start marker position
# If you need finer granularity in positioning use
- # graphic_frame.anchor.from.colOff / rowOff
- # @param [Integer] x The column
+ #
+ # This helper method acceps a fairly wide range of inputs exampled
+ # below
+ #
+ # @example
+ #
+ # start_at 0, 5 # The anchor start marker is set to 6th row of
+ # the first column
+ #
+ # start_at [0, 5] # The anchor start marker is set to start on the 6th row
+ # of the first column
+ #
+ # start_at "C1" # The anchor start marker is set to start on the first row
+ # of the third column
+ #
+ # start_at sheet.rows.first.cells.last # The anchor start
+ # marker is set to the location of a specific cell.
+ #
+ # @param [Array|String|Cell] x the column, coordinates, string
+ # reference or cell to use in setting the start marker position.
# @param [Integer] y The row
# @return [Marker]
def start_at(x=0, y=0)
- x, y = *parse_coord_args(x, y)
- @graphic_frame.anchor.from.col = x
- @graphic_frame.anchor.from.row = y
+ @graphic_frame.anchor.start_at(x, y)
end
# This is a short cut method to set the end anchor position
@@ -172,25 +188,9 @@ module Axlsx
# @param [Integer] x The column - default 10
# @param [Integer] y The row - default 10
# @return [Marker]
+ # @see start_at
def end_at(x=10, y=10)
- x, y = *parse_coord_args(x, y)
- @graphic_frame.anchor.to.col = x
- @graphic_frame.anchor.to.row = y
- end
-
- private
-
- 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]
+ @graphic_frame.anchor.end_at(x, y)
end
def view_3D=(v) DataTypeValidator.validate "#{self.class}.view_3D", View3D, v; @view_3D = v; end
diff --git a/lib/axlsx/drawing/two_cell_anchor.rb b/lib/axlsx/drawing/two_cell_anchor.rb
index 73ccf2b5..e7b27408 100644
--- a/lib/axlsx/drawing/two_cell_anchor.rb
+++ b/lib/axlsx/drawing/two_cell_anchor.rb
@@ -25,7 +25,6 @@ module Axlsx
# @return [Drawing]
attr_reader :drawing
-
# Creates a new TwoCellAnchor object
# c.start_at 5, 9
# @param [Drawing] drawing
@@ -37,6 +36,22 @@ module Axlsx
@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)
@@ -70,6 +85,28 @@ module Axlsx
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