summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-07-10 21:07:25 +0900
committerRandy Morgan <[email protected]>2012-07-10 21:07:25 +0900
commitc5f62d135f786917703d3dd9a98d66918d2ad1eb (patch)
tree75c4276b2a22640ac3cf7ed9ee20d10210a26c98
parente82f217d5d94d5e07c195323b61f9e3195ac6634 (diff)
downloadcaxlsx-c5f62d135f786917703d3dd9a98d66918d2ad1eb.tar.gz
caxlsx-c5f62d135f786917703d3dd9a98d66918d2ad1eb.zip
more cleanup
-rw-r--r--lib/axlsx/drawing/cat_axis.rb80
-rw-r--r--lib/axlsx/drawing/chart.rb48
-rw-r--r--lib/axlsx/drawing/drawing.rb9
3 files changed, 71 insertions, 66 deletions
diff --git a/lib/axlsx/drawing/cat_axis.rb b/lib/axlsx/drawing/cat_axis.rb
index 2e200bda..ba392ce6 100644
--- a/lib/axlsx/drawing/cat_axis.rb
+++ b/lib/axlsx/drawing/cat_axis.rb
@@ -3,6 +3,26 @@ module Axlsx
#A CatAxis object defines a chart category axis
class CatAxis < Axis
+ # Creates a new CatAxis object
+ # @param [Integer] ax_id the id of this axis. Inherited
+ # @param [Integer] cross_ax the id of the perpendicular axis. Inherited
+ # @option options [Symbol] ax_pos. Inherited
+ # @option options [Symbol] tick_lbl_pos. Inherited
+ # @option options [Symbol] crosses. Inherited
+ # @option options [Boolean] auto
+ # @option options [Symbol] lbl_algn
+ # @option options [Integer] lbl_offset
+ # @option options [Integer] tick_lbl_skip
+ # @option options [Integer] tick_mark_skip
+ def initialize(ax_id, cross_ax, options={})
+ @tick_lbl_skip = 1
+ @tick_mark_skip = 1
+ self.auto = 1
+ self.lbl_algn = :ctr
+ self.lbl_offset = "100"
+ super(ax_id, cross_ax, options)
+ end
+
# From the docs: This element specifies that this axis is a date or text axis based on the data that is used for the axis labels, not a specific choice.
# @return [Boolean]
attr_reader :auto
@@ -10,64 +30,48 @@ module Axlsx
# specifies how the perpendicular axis is crossed
# must be one of [:ctr, :l, :r]
# @return [Symbol]
- attr_reader :lblAlgn
+ attr_reader :lbl_algn
+ alias :lblAlgn :lbl_algn
# The offset of the labels
# must be between a string between 0 and 1000
# @return [Integer]
- attr_reader :lblOffset
-
+ attr_reader :lbl_offset
+ alias :lblOffset :lbl_offset
# The number of tick lables to skip between labels
# @return [Integer]
- attr_reader :tickLblSkip
+ attr_reader :tick_lbl_skip
+ alias :tickLblSkip :tick_lbl_skip
# The number of tickmarks to be skipped before the next one is rendered.
# @return [Boolean]
- attr_reader :tickMarkSkip
-
+ attr_reader :tick_mark_skip
+ alias :tickMarkSkip :tick_mark_skip
# regex for validating label offset
LBL_OFFSET_REGEX = /0*(([0-9])|([1-9][0-9])|([1-9][0-9][0-9])|1000)/
- # Creates a new CatAxis object
- # @param [Integer] axId the id of this axis. Inherited
- # @param [Integer] crossAx the id of the perpendicular axis. Inherited
- # @option options [Symbol] axPos. Inherited
- # @option options [Symbol] tickLblPos. Inherited
- # @option options [Symbol] crosses. Inherited
- # @option options [Boolean] auto
- # @option options [Symbol] lblAlgn
- # @option options [Integer] lblOffset
- # @option options [Integer] tickLblSkip
- # @option options [Integer] tickMarkSkip
- def initialize(axId, crossAx, options={})
- @tickLblSkip = 1
- @tickMarkSkip = 1
- self.auto = 1
- self.lblAlgn = :ctr
- self.lblOffset = "100"
- super(axId, crossAx, options)
- end
-
-
- # @see tickLblSkip
- def tickLblSkip=(v) Axlsx::validate_unsigned_int(v); @tickLblSkip = v; end
-
- # @see tickMarkSkip
- def tickMarkSkip=(v) Axlsx::validate_unsigned_int(v); @tickMarkSkip = v; end
+ # @see tick_lbl_skip
+ def tick_lbl_skip=(v) Axlsx::validate_unsigned_int(v); @tick_lbl_skip = v; end
+ alias :tickLblSkip= :tick_lbl_skip=
+ # @see tick_mark_skip
+ def tick_mark_skip=(v) Axlsx::validate_unsigned_int(v); @tick_mark_skip = v; end
+ alias :tickMarkSkip= :tick_mark_skip=
# From the docs: This element specifies that this axis is a date or text axis based on the data that is used for the axis labels, not a specific choice.
def auto=(v) Axlsx::validate_boolean(v); @auto = v; end
# specifies how the perpendicular axis is crossed
# must be one of [:ctr, :l, :r]
- def lblAlgn=(v) RestrictionValidator.validate "#{self.class}.lblAlgn", [:ctr, :l, :r], v; @lblAlgn = v; end
+ def lbl_algn=(v) RestrictionValidator.validate "#{self.class}.lbl_algn", [:ctr, :l, :r], v; @lbl_algn = v; end
+ alias :lblAlgn= :lbl_algn=
# The offset of the labels
# must be between a string between 0 and 1000
- def lblOffset=(v) RegexValidator.validate "#{self.class}.lblOffset", LBL_OFFSET_REGEX, v; @lblOffset = v; end
+ def lbl_offset=(v) RegexValidator.validate "#{self.class}.lbl_offset", LBL_OFFSET_REGEX, v; @lbl_offset = v; end
+ alias :lblOffset= :lbl_offset=
# Serializes the object
# @param [String] str
@@ -76,10 +80,10 @@ module Axlsx
str << '<c:catAx>'
super(str)
str << '<c:auto val="' << @auto.to_s << '"/>'
- str << '<c:lblAlgn val="' << @lblAlgn.to_s << '"/>'
- str << '<c:lblOffset val="' << @lblOffset.to_i.to_s << '"/>'
- str << '<c:tickLblSkip val="' << @tickLblSkip.to_s << '"/>'
- str << '<c:tickMarkSkip val="' << @tickMarkSkip.to_s << '"/>'
+ str << '<c:lblAlgn val="' << @lbl_algn.to_s << '"/>'
+ str << '<c:lblOffset val="' << @lbl_offset.to_i.to_s << '"/>'
+ str << '<c:tickLblSkip val="' << @tick_lbl_skip.to_s << '"/>'
+ str << '<c:tickMarkSkip val="' << @tick_mark_skip.to_s << '"/>'
str << '</c:catAx>'
end
diff --git a/lib/axlsx/drawing/chart.rb b/lib/axlsx/drawing/chart.rb
index 5c8f5043..1f36dfe4 100644
--- a/lib/axlsx/drawing/chart.rb
+++ b/lib/axlsx/drawing/chart.rb
@@ -1,10 +1,33 @@
# encoding: UTF-8
module Axlsx
+
# A Chart is the superclass for specific charts
# @note Worksheet#add_chart is the recommended way to create charts for your worksheets.
# @see README for examples
class Chart
+ # Creates a new chart object
+ # @param [GraphicalFrame] frame The frame that holds this chart.
+ # @option options [Cell, String] title
+ # @option options [Boolean] show_legend
+ # @option options [Array|String|Cell] start_at The X, Y coordinates defining the top left corner of the chart.
+ # @option options [Array|String|Cell] end_at The X, Y coordinates defining the bottom right corner of the chart.
+ def initialize(frame, options={})
+ @style = 18
+ @view_3D = nil
+ @graphic_frame=frame
+ @graphic_frame.anchor.drawing.worksheet.workbook.charts << self
+ @series = SimpleTypedList.new Series
+ @show_legend = true
+ @series_type = Series
+ @title = Title.new
+ options.each do |o|
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
+ end
+ start_at(*options[:start_at]) if options[:start_at]
+ end_at(*options[:end_at]) if options[:end_at]
+ yield self if block_given?
+ end
# The 3D view properties for the chart
attr_reader :view_3D
@@ -38,29 +61,6 @@ module Axlsx
# @return [Boolean]
attr_reader :show_legend
- # Creates a new chart object
- # @param [GraphicalFrame] frame The frame that holds this chart.
- # @option options [Cell, String] title
- # @option options [Boolean] show_legend
- # @option options [Array|String|Cell] start_at The X, Y coordinates defining the top left corner of the chart.
- # @option options [Array|String|Cell] end_at The X, Y coordinates defining the bottom right corner of the chart.
- def initialize(frame, options={})
- @style = 18
- @view_3D = nil
- @graphic_frame=frame
- @graphic_frame.anchor.drawing.worksheet.workbook.charts << self
- @series = SimpleTypedList.new Series
- @show_legend = true
- @series_type = Series
- @title = Title.new
- options.each do |o|
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
- end
- start_at(*options[:start_at]) if options[:start_at]
- end_at(*options[:end_at]) if options[:end_at]
- yield self if block_given?
- end
-
# The index of this chart in the workbooks charts collection
# @return [Integer]
def index
@@ -90,7 +90,6 @@ module Axlsx
# @return [Boolean]
def show_legend=(v) Axlsx::validate_boolean(v); @show_legend = v; end
-
# The style for the chart.
# see ECMA Part 1 ยง21.2.2.196
# @param [Integer] v must be between 1 and 48
@@ -198,4 +197,5 @@ module Axlsx
alias :view3D= :view_3D=
end
+
end
diff --git a/lib/axlsx/drawing/drawing.rb b/lib/axlsx/drawing/drawing.rb
index 1553809a..6dd5580e 100644
--- a/lib/axlsx/drawing/drawing.rb
+++ b/lib/axlsx/drawing/drawing.rb
@@ -42,12 +42,13 @@ module Axlsx
require 'axlsx/drawing/vml_drawing.rb'
require 'axlsx/drawing/vml_shape.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.
+ # A Drawing is a canvas for charts and images. Each worksheet has a single drawing that manages anchors.
+ # The anchors reference the charts or images 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 and Worksheet.add_image methods.
# @see Worksheet#add_chart
+ # @see Worksheet#add_image
# @see Chart
- # see README for an example of how to create a chart.
+ # see examples/example.rb for an example of how to create a chart.
class Drawing
# The worksheet that owns the drawing