axlsx 1.3.5 → 1.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +9 -1
  3. data/README.md +26 -17
  4. data/examples/conditional_formatting/example_conditional_formatting.rb +4 -2
  5. data/examples/example.rb +22 -9
  6. data/examples/pivot_table.rb +0 -2
  7. data/lib/axlsx/drawing/axes.rb +57 -0
  8. data/lib/axlsx/drawing/axis.rb +16 -13
  9. data/lib/axlsx/drawing/bar_3D_chart.rb +16 -12
  10. data/lib/axlsx/drawing/cat_axis.rb +2 -10
  11. data/lib/axlsx/drawing/d_lbls.rb +1 -1
  12. data/lib/axlsx/drawing/drawing.rb +2 -0
  13. data/lib/axlsx/drawing/line_3D_chart.rb +27 -70
  14. data/lib/axlsx/drawing/line_chart.rb +99 -0
  15. data/lib/axlsx/drawing/line_series.rb +20 -2
  16. data/lib/axlsx/drawing/scatter_chart.rb +27 -17
  17. data/lib/axlsx/drawing/ser_axis.rb +15 -16
  18. data/lib/axlsx/drawing/val_axis.rb +14 -13
  19. data/lib/axlsx/drawing/vml_shape.rb +18 -77
  20. data/lib/axlsx/util/serialized_attributes.rb +0 -1
  21. data/lib/axlsx/version.rb +1 -1
  22. data/lib/axlsx/workbook/worksheet/comment.rb +10 -23
  23. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +5 -3
  24. data/test/benchmark.rb +0 -1
  25. data/test/drawing/tc_axis.rb +15 -17
  26. data/test/drawing/tc_cat_axis.rb +9 -9
  27. data/test/drawing/tc_line_chart.rb +39 -0
  28. data/test/drawing/tc_line_series.rb +8 -2
  29. data/test/drawing/tc_ser_axis.rb +13 -12
  30. data/test/drawing/tc_val_axis.rb +6 -6
  31. data/test/drawing/tc_vml_shape.rb +9 -3
  32. data/test/profile.rb +5 -11
  33. data/test/tc_helper.rb +1 -0
  34. data/test/util/tc_validators.rb +5 -1
  35. data/test/workbook/worksheet/tc_comment.rb +5 -1
  36. data/test/workbook/worksheet/tc_comments.rb +2 -2
  37. data/test/workbook/worksheet/tc_conditional_formatting.rb +7 -0
  38. metadata +21 -55
@@ -10,7 +10,7 @@ module Axlsx
10
10
  include Axlsx::OptionsParser
11
11
  # creates a new DLbls object
12
12
  def initialize(chart_type, options={})
13
- raise ArgumentError, 'chart_type must inherit from Chart' unless chart_type.superclass == Chart
13
+ raise ArgumentError, 'chart_type must inherit from Chart' unless [Chart, LineChart].include?(chart_type.superclass)
14
14
  @chart_type = chart_type
15
15
  initialize_defaults
16
16
  parse_options options
@@ -22,6 +22,7 @@ module Axlsx
22
22
  require 'axlsx/drawing/ser_axis.rb'
23
23
  require 'axlsx/drawing/cat_axis.rb'
24
24
  require 'axlsx/drawing/val_axis.rb'
25
+ require 'axlsx/drawing/axes.rb'
25
26
 
26
27
  require 'axlsx/drawing/marker.rb'
27
28
 
@@ -33,6 +34,7 @@ module Axlsx
33
34
  require 'axlsx/drawing/chart.rb'
34
35
  require 'axlsx/drawing/pie_3D_chart.rb'
35
36
  require 'axlsx/drawing/bar_3D_chart.rb'
37
+ require 'axlsx/drawing/line_chart.rb'
36
38
  require 'axlsx/drawing/line_3D_chart.rb'
37
39
  require 'axlsx/drawing/scatter_chart.rb'
38
40
 
@@ -11,7 +11,7 @@ module Axlsx
11
11
  # ws = p.workbook.add_worksheet
12
12
  # ws.add_row ["This is a chart with no data in the sheet"]
13
13
  #
14
- # chart = ws.add_chart(Axlsx::Line3DChart, :start_at=> [0,1], :end_at=>[0,6], :title=>"Most Popular Pets")
14
+ # chart = ws.add_chart(Axlsx::Line3DChart, :start_at=> [0,1], :end_at=>[0,6], :t#itle=>"Most Popular Pets")
15
15
  # chart.add_series :data => [1, 9, 10], :labels => ["Slimy Reptiles", "Fuzzy Bunnies", "Rottweiler"]
16
16
  #
17
17
  # @see Worksheet#add_chart
@@ -19,93 +19,50 @@ module Axlsx
19
19
  # @see Chart#add_series
20
20
  # @see Series
21
21
  # @see Package#serialize
22
- class Line3DChart < Chart
23
-
24
- # the category axis
25
- # @return [CatAxis]
26
- attr_reader :catAxis
27
-
28
- # the category axis
29
- # @return [ValAxis]
30
- attr_reader :valAxis
31
-
32
- # the category axis
33
- # @return [Axis]
34
- attr_reader :serAxis
22
+ class Line3DChart < Axlsx::LineChart
35
23
 
36
24
  # space between bar or column clusters, as a percentage of the bar or column width.
37
25
  # @return [String]
38
- attr_reader :gapDepth
39
-
40
- #grouping for a column, line, or area chart.
41
- # must be one of [:percentStacked, :clustered, :standard, :stacked]
42
- # @return [Symbol]
43
- attr_reader :grouping
26
+ attr_reader :gap_depth
27
+ alias :gapDepth :gap_depth
44
28
 
45
29
  # validation regex for gap amount percent
46
30
  GAP_AMOUNT_PERCENT = /0*(([0-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)%/
47
31
 
32
+ # the category axis
33
+ # @return [Axis]
34
+ def ser_axis
35
+ axes[:ser_axis]
36
+ end
37
+ alias :serAxis :ser_axis
38
+
48
39
  # Creates a new line chart object
49
- # @param [GraphicFrame] frame The workbook that owns this chart.
50
- # @option options [Cell, String] title
51
- # @option options [Boolean] show_legend
52
- # @option options [Symbol] grouping
53
- # @option options [String] gapDepth
54
- # @option options [Integer] rotX
55
- # @option options [String] hPercent
56
- # @option options [Integer] rotY
57
- # @option options [String] depthPercent
58
- # @option options [Boolean] rAngAx
59
- # @option options [Integer] perspective
40
+ # @option options [String] gap_depth
60
41
  # @see Chart
42
+ # @see lineChart
61
43
  # @see View3D
62
44
  def initialize(frame, options={})
63
- @vary_colors = false
64
- @gapDepth = nil
65
- @grouping = :standard
66
- @catAxId = rand(8 ** 8)
67
- @valAxId = rand(8 ** 8)
68
- @serAxId = rand(8 ** 8)
69
- @catAxis = CatAxis.new(@catAxId, @valAxId)
70
- @valAxis = ValAxis.new(@valAxId, @catAxId)
71
- @serAxis = SerAxis.new(@serAxId, @valAxId)
45
+ @gap_depth = nil
46
+ @view_3D = View3D.new({:r_ang_ax=>1}.merge(options))
72
47
  super(frame, options)
73
- @series_type = LineSeries
74
- @view_3D = View3D.new({:perspective=>30}.merge(options))
75
- @d_lbls = nil
48
+ axes.add_axis :ser_axis, SerAxis
76
49
  end
77
50
 
78
- # @see grouping
79
- def grouping=(v)
80
- RestrictionValidator.validate "Bar3DChart.grouping", [:percentStacked, :standard, :stacked], v
81
- @grouping = v
82
- end
83
51
 
84
52
  # @see gapDepth
85
- def gapDepth=(v)
86
- RegexValidator.validate "Bar3DChart.gapWidth", GAP_AMOUNT_PERCENT, v
87
- @gapDepth=(v)
53
+ def gap_depth=(v)
54
+ RegexValidator.validate "Line3DChart.gapWidth", GAP_AMOUNT_PERCENT, v
55
+ @gap_depth=(v)
88
56
  end
57
+ alias :gapDepth= :gap_depth=
89
58
 
90
- # Serializes the object
91
- # @param [String] str
92
- # @return [String]
93
- def to_xml_string(str = '')
94
- super(str) do |str_inner|
95
- str_inner << '<c:line3DChart>'
96
- str_inner << '<c:grouping val="' << grouping.to_s << '"/>'
97
- str_inner << '<c:varyColors val="' << vary_colors.to_s << '"/>'
98
- @series.each { |ser| ser.to_xml_string(str_inner) }
99
- @d_lbls.to_xml_string(str) if @d_lbls
100
- str_inner << '<c:gapDepth val="' << @gapDepth.to_s << '"/>' unless @gapDepth.nil?
101
- str_inner << '<c:axId val="' << @catAxId.to_s << '"/>'
102
- str_inner << '<c:axId val="' << @valAxId.to_s << '"/>'
103
- str_inner << '<c:axId val="' << @serAxId.to_s << '"/>'
104
- str_inner << '</c:line3DChart>'
105
- @catAxis.to_xml_string str_inner
106
- @valAxis.to_xml_string str_inner
107
- @serAxis.to_xml_string str_inner
59
+ # Serializes the object
60
+ # @param [String] str
61
+ # @return [String]
62
+ def to_xml_string(str = '')
63
+ super(str) do |str_inner|
64
+ str_inner << '<c:gapDepth val="' << @gap_depth.to_s << '"/>' unless @gap_depth.nil?
65
+ end
108
66
  end
109
- end
110
67
  end
111
68
  end
@@ -0,0 +1,99 @@
1
+ # encoding: UTF-8
2
+ module Axlsx
3
+
4
+ # The LineChart is a two dimentional line chart (who would have guessed?) that you can add to your worksheet.
5
+ # @example Creating a chart
6
+ # # This example creates a line in a single sheet.
7
+ # require "rubygems" # if that is your preferred way to manage gems!
8
+ # require "axlsx"
9
+ #
10
+ # p = Axlsx::Package.new
11
+ # ws = p.workbook.add_worksheet
12
+ # ws.add_row ["This is a chart with no data in the sheet"]
13
+ #
14
+ # chart = ws.add_chart(Axlsx::LineChart, :start_at=> [0,1], :end_at=>[0,6], :title=>"Most Popular Pets")
15
+ # chart.add_series :data => [1, 9, 10], :labels => ["Slimy Reptiles", "Fuzzy Bunnies", "Rottweiler"]
16
+ #
17
+ # @see Worksheet#add_chart
18
+ # @see Worksheet#add_row
19
+ # @see Chart#add_series
20
+ # @see Series
21
+ # @see Package#serialize
22
+ class LineChart < Chart
23
+
24
+ # the category axis
25
+ # @return [CatAxis]
26
+ def cat_axis
27
+ axes[:cat_axis]
28
+ end
29
+ alias :catAxis :cat_axis
30
+
31
+ # the category axis
32
+ # @return [ValAxis]
33
+ def val_axis
34
+ axes[:val_axis]
35
+ end
36
+ alias :valAxis :val_axis
37
+
38
+ # must be one of [:percentStacked, :clustered, :standard, :stacked]
39
+ # @return [Symbol]
40
+ attr_reader :grouping
41
+
42
+ # Creates a new line chart object
43
+ # @param [GraphicFrame] frame The workbook that owns this chart.
44
+ # @option options [Cell, String] title
45
+ # @option options [Boolean] show_legend
46
+ # @option options [Symbol] grouping
47
+ # @see Chart
48
+ def initialize(frame, options={})
49
+ @vary_colors = false
50
+ @grouping = :standard
51
+ super(frame, options)
52
+ @series_type = LineSeries
53
+ @d_lbls = nil
54
+ end
55
+
56
+ # @see grouping
57
+ def grouping=(v)
58
+ RestrictionValidator.validate "LineChart.grouping", [:percentStacked, :standard, :stacked], v
59
+ @grouping = v
60
+ end
61
+
62
+ # The node name to use in serialization. As LineChart is used as the
63
+ # base class for Liine3DChart we need to be sure to serialize the
64
+ # chart based on the actual class type and not a fixed node name.
65
+ # @return [String]
66
+ def node_name
67
+ path = self.class.to_s
68
+ if i = path.rindex('::')
69
+ path = path[(i+2)..-1]
70
+ end
71
+ path[0] = path[0].chr.downcase
72
+ path
73
+ end
74
+
75
+ # Serializes the object
76
+ # @param [String] str
77
+ # @return [String]
78
+ def to_xml_string(str = '')
79
+ super(str) do |str_inner|
80
+ str_inner << "<c:" << node_name << ">"
81
+ str_inner << '<c:grouping val="' << grouping.to_s << '"/>'
82
+ str_inner << '<c:varyColors val="' << vary_colors.to_s << '"/>'
83
+ @series.each { |ser| ser.to_xml_string(str_inner) }
84
+ @d_lbls.to_xml_string(str_inner) if @d_lbls
85
+ yield str_inner if block_given?
86
+ axes.to_xml_string(str_inner, :ids => true)
87
+ str_inner << "</c:" << node_name << ">"
88
+ axes.to_xml_string(str_inner)
89
+ end
90
+ end
91
+
92
+ # The axes for this chart. LineCharts have a category and value
93
+ # axis.
94
+ # @return [Axes]
95
+ def axes
96
+ @axes ||= Axes.new(:cat_axis => CatAxis, :val_axis => ValAxis)
97
+ end
98
+ end
99
+ end
@@ -19,11 +19,16 @@ module Axlsx
19
19
  # @return [String]
20
20
  attr_reader :color
21
21
 
22
+ # show markers on values
23
+ # @return [Boolean]
24
+ attr_reader :show_marker
25
+
22
26
  # Creates a new series
23
27
  # @option options [Array, SimpleTypedList] data
24
28
  # @option options [Array, SimpleTypedList] labels
25
29
  # @param [Chart] chart
26
30
  def initialize(chart, options={})
31
+ @show_marker = false
27
32
  @labels, @data = nil, nil
28
33
  super(chart, options)
29
34
  @labels = AxDataSource.new(:data => options[:labels]) unless options[:labels].nil?
@@ -35,6 +40,12 @@ module Axlsx
35
40
  @color = v
36
41
  end
37
42
 
43
+ # @see show_marker
44
+ def show_marker=(v)
45
+ Axlsx::validate_boolean(v)
46
+ @show_marker = v
47
+ end
48
+
38
49
  # Serializes the object
39
50
  # @param [String] str
40
51
  # @return [String]
@@ -43,9 +54,16 @@ module Axlsx
43
54
  if color
44
55
  str << '<c:spPr><a:solidFill>'
45
56
  str << '<a:srgbClr val="' << color << '"/>'
46
- str << '</a:solidFill></c:spPr>'
57
+ str << '</a:solidFill>'
58
+ str << '<a:ln w="28800">'
59
+ str << '<a:solidFill>'
60
+ str << '<a:srgbClr val="' << color << '"/>'
61
+ str << '</a:solidFill>'
62
+ str << '</a:ln>'
63
+ str << '<a:round/>'
64
+ str << '</c:spPr>'
47
65
  end
48
-
66
+ str << '<c:marker><c:symbol val="none"/></c:marker>' unless @show_marker
49
67
  @labels.to_xml_string(str) unless @labels.nil?
50
68
  @data.to_xml_string(str) unless @data.nil?
51
69
  end
@@ -12,35 +12,40 @@ module Axlsx
12
12
  # The Style for the scatter chart
13
13
  # must be one of :none | :line | :lineMarker | :marker | :smooth | :smoothMarker
14
14
  # return [Symbol]
15
- attr_reader :scatterStyle
15
+ attr_reader :scatter_style
16
+ alias :scatterStyle :scatter_style
16
17
 
17
18
  # the x value axis
18
19
  # @return [ValAxis]
19
- attr_reader :xValAxis
20
+ def x_val_axis
21
+ axes[:x_val_axis]
22
+ end
23
+ alias :xValAxis :x_val_axis
20
24
 
21
25
  # the y value axis
22
26
  # @return [ValAxis]
23
- attr_reader :yValAxis
27
+ def y_val_axis
28
+ axes[:x_val_axis]
29
+ end
30
+ alias :yValAxis :y_val_axis
24
31
 
25
32
  # Creates a new scatter chart
26
33
  def initialize(frame, options={})
27
34
  @vary_colors = 0
28
- @scatterStyle = :lineMarker
29
- @xValAxId = rand(8 ** 8)
30
- @yValAxId = rand(8 ** 8)
31
- @xValAxis = ValAxis.new(@xValAxId, @yValAxId)
32
- @yValAxis = ValAxis.new(@yValAxId, @xValAxId)
33
- super(frame, options)
35
+ @scatter_style = :lineMarker
36
+
37
+ super(frame, options)
34
38
  @series_type = ScatterSeries
35
39
  @d_lbls = nil
36
40
  parse_options options
37
41
  end
38
42
 
39
43
  # see #scatterStyle
40
- def scatterStyle=(v)
44
+ def scatter_style=(v)
41
45
  Axlsx.validate_scatter_style(v)
42
- @scatterStyle = v
46
+ @scatter_style = v
43
47
  end
48
+ alias :scatterStyle= :scatter_style=
44
49
 
45
50
  # Serializes the object
46
51
  # @param [String] str
@@ -48,17 +53,22 @@ module Axlsx
48
53
  def to_xml_string(str = '')
49
54
  super(str) do |str_inner|
50
55
  str_inner << '<c:scatterChart>'
51
- str_inner << '<c:scatterStyle val="' << scatterStyle.to_s << '"/>'
56
+ str_inner << '<c:scatterStyle val="' << scatter_style.to_s << '"/>'
52
57
  str_inner << '<c:varyColors val="' << vary_colors.to_s << '"/>'
53
58
  @series.each { |ser| ser.to_xml_string(str_inner) }
54
- d_lbls.to_xml_string(str) if @d_lbls
55
- str_inner << '<c:axId val="' << @xValAxId.to_s << '"/>'
56
- str_inner << '<c:axId val="' << @yValAxId.to_s << '"/>'
59
+ d_lbls.to_xml_string(str_inner) if @d_lbls
60
+ axes.to_xml_string(str_inner, :ids => true)
57
61
  str_inner << '</c:scatterChart>'
58
- @xValAxis.to_xml_string str_inner
59
- @yValAxis.to_xml_string str_inner
62
+ axes.to_xml_string(str_inner)
60
63
  end
61
64
  str
62
65
  end
66
+
67
+ # The axes for the scatter chart. ScatterChart has an x_val_axis and
68
+ # a y_val_axis
69
+ # @return [Axes]
70
+ def axes
71
+ @axes ||= Axes.new(:x_val_axis => ValAxis, :y_val_axis => ValAxis)
72
+ end
63
73
  end
64
74
  end
@@ -5,30 +5,29 @@ module Axlsx
5
5
 
6
6
  # The number of tick lables to skip between labels
7
7
  # @return [Integer]
8
- attr_reader :tickLblSkip
8
+ attr_reader :tick_lbl_skip
9
+ alias :tickLblSkip :tick_lbl_skip
9
10
 
10
11
  # The number of tickmarks to be skipped before the next one is rendered.
11
12
  # @return [Boolean]
12
- attr_reader :tickMarkSkip
13
+ attr_reader :tick_mark_skip
14
+ alias :tickMarkSkip :tick_mark_skip
13
15
 
14
16
  # Creates a new SerAxis object
15
- # @param [Integer] axId the id of this axis. Inherited
16
- # @param [Integer] crossAx the id of the perpendicular axis. Inherited
17
- # @option options [Symbol] axPos. Inherited
18
- # @option options [Symbol] tickLblPos. Inherited
19
- # @option options [Symbol] crosses. Inherited
20
- # @option options [Integer] tickLblSkip
21
- # @option options [Integer] tickMarkSkip
22
- def initialize(axId, crossAx, options={})
23
- @tickLblSkip, @tickMarkSkip = 1, 1
24
- super(axId, crossAx, options)
17
+ # @option options [Integer] tick_lbl_skip
18
+ # @option options [Integer] tick_mark_skip
19
+ def initialize(options={})
20
+ @tick_lbl_skip, @tick_mark_skip = 1, 1
21
+ super(options)
25
22
  end
26
23
 
27
24
  # @see tickLblSkip
28
- def tickLblSkip=(v) Axlsx::validate_unsigned_int(v); @tickLblSkip = v; end
25
+ def tick_lbl_skip=(v) Axlsx::validate_unsigned_int(v); @tick_lbl_skip = v; end
26
+ alias :tickLblSkip= :tick_lbl_skip=
29
27
 
30
28
  # @see tickMarkSkip
31
- def tickMarkSkip=(v) Axlsx::validate_unsigned_int(v); @tickMarkSkip = v; end
29
+ def tick_mark_skip=(v) Axlsx::validate_unsigned_int(v); @tick_mark_skip = v; end
30
+ alias :tickMarkSkip= :tick_mark_skip=
32
31
 
33
32
  # Serializes the object
34
33
  # @param [String] str
@@ -36,8 +35,8 @@ module Axlsx
36
35
  def to_xml_string(str = '')
37
36
  str << '<c:serAx>'
38
37
  super(str)
39
- str << '<c:tickLblSkip val="' << @tickLblSkip.to_s << '"/>' unless @tickLblSkip.nil?
40
- str << '<c:tickMarkSkip val="' << @tickMarkSkip.to_s << '"/>' unless @tickMarkSkip.nil?
38
+ str << '<c:tickLblSkip val="' << @tick_lbl_skip.to_s << '"/>' unless @tick_lbl_skip.nil?
39
+ str << '<c:tickMarkSkip val="' << @tick_mark_skip.to_s << '"/>' unless @tick_mark_skip.nil?
41
40
  str << '</c:serAx>'
42
41
  end
43
42
  end
@@ -6,21 +6,22 @@ module Axlsx
6
6
  # This element specifies how the value axis crosses the category axis.
7
7
  # must be one of [:between, :midCat]
8
8
  # @return [Symbol]
9
- attr_reader :crossBetween
9
+ attr_reader :cross_between
10
+ alias :crossBetween :cross_between
10
11
 
11
12
  # Creates a new ValAxis object
12
- # @param [Integer] axId the id of this axis
13
- # @param [Integer] crossAx the id of the perpendicular axis
14
- # @option options [Symbol] axPos
15
- # @option options [Symbol] tickLblPos
16
- # @option options [Symbol] crosses
17
- # @option options [Symbol] crossesBetween
18
- def initialize(axId, crossAx, options={})
19
- self.crossBetween = :between
20
- super(axId, crossAx, options)
13
+ # @option options [Symbol] crosses_between
14
+ def initialize(options={})
15
+ self.cross_between = :between
16
+ super(options)
21
17
  end
22
- # @see crossBetween
23
- def crossBetween=(v) RestrictionValidator.validate "ValAxis.crossBetween", [:between, :midCat], v; @crossBetween = v; end
18
+
19
+ # @see cross_between
20
+ def cross_between=(v)
21
+ RestrictionValidator.validate "ValAxis.cross_between", [:between, :midCat], v
22
+ @cross_between = v
23
+ end
24
+ alias :crossBetween= :cross_between=
24
25
 
25
26
  # Serializes the object
26
27
  # @param [String] str
@@ -28,7 +29,7 @@ module Axlsx
28
29
  def to_xml_string(str = '')
29
30
  str << '<c:valAx>'
30
31
  super(str)
31
- str << '<c:crossBetween val="' << @crossBetween.to_s << '"/>'
32
+ str << '<c:crossBetween val="' << @cross_between.to_s << '"/>'
32
33
  str << '</c:valAx>'
33
34
  end
34
35