axlsx 2.1.0.pre → 3.0.0.pre

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 (80) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/README.md +17 -20
  4. data/Rakefile +0 -1
  5. data/examples/conditional_formatting/example_conditional_formatting.rb +15 -0
  6. data/examples/example.rb +31 -1
  7. data/lib/axlsx.rb +9 -4
  8. data/lib/axlsx/drawing/area_chart.rb +99 -0
  9. data/lib/axlsx/drawing/area_series.rb +110 -0
  10. data/lib/axlsx/drawing/bar_chart.rb +143 -0
  11. data/lib/axlsx/drawing/chart.rb +8 -1
  12. data/lib/axlsx/drawing/d_lbls.rb +3 -3
  13. data/lib/axlsx/drawing/drawing.rb +3 -0
  14. data/lib/axlsx/drawing/line_series.rb +18 -1
  15. data/lib/axlsx/drawing/num_val.rb +3 -1
  16. data/lib/axlsx/drawing/one_cell_anchor.rb +2 -1
  17. data/lib/axlsx/drawing/pic.rb +24 -17
  18. data/lib/axlsx/drawing/scaling.rb +2 -2
  19. data/lib/axlsx/drawing/scatter_series.rb +16 -2
  20. data/lib/axlsx/drawing/str_val.rb +3 -1
  21. data/lib/axlsx/drawing/title.rb +19 -1
  22. data/lib/axlsx/drawing/two_cell_anchor.rb +6 -1
  23. data/lib/axlsx/drawing/view_3D.rb +2 -2
  24. data/lib/axlsx/package.rb +7 -16
  25. data/lib/axlsx/rels/relationships.rb +5 -2
  26. data/lib/axlsx/stylesheet/num_fmt.rb +9 -0
  27. data/lib/axlsx/stylesheet/styles.rb +1 -1
  28. data/lib/axlsx/util/constants.rb +8 -5
  29. data/lib/axlsx/util/mime_type_utils.rb +11 -0
  30. data/lib/axlsx/util/simple_typed_list.rb +1 -1
  31. data/lib/axlsx/util/validators.rb +14 -9
  32. data/lib/axlsx/version.rb +1 -1
  33. data/lib/axlsx/workbook/workbook.rb +19 -1
  34. data/lib/axlsx/workbook/workbook_view.rb +5 -3
  35. data/lib/axlsx/workbook/worksheet/cell.rb +26 -19
  36. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +15 -5
  37. data/lib/axlsx/workbook/worksheet/cfvos.rb +3 -0
  38. data/lib/axlsx/workbook/worksheet/cols.rb +5 -2
  39. data/lib/axlsx/workbook/worksheet/merged_cells.rb +2 -0
  40. data/lib/axlsx/workbook/worksheet/outline_pr.rb +33 -0
  41. data/lib/axlsx/workbook/worksheet/pivot_table.rb +36 -13
  42. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +4 -1
  43. data/lib/axlsx/workbook/worksheet/rich_text.rb +23 -3
  44. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +28 -32
  45. data/lib/axlsx/workbook/worksheet/row.rb +7 -0
  46. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +21 -3
  47. data/lib/axlsx/workbook/worksheet/tables.rb +3 -0
  48. data/lib/axlsx/workbook/worksheet/worksheet.rb +8 -51
  49. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +10 -10
  50. data/test/axlsx.qcachegrind +2226 -0
  51. data/test/drawing/tc_area_chart.rb +39 -0
  52. data/test/drawing/tc_area_series.rb +71 -0
  53. data/test/drawing/tc_bar_chart.rb +71 -0
  54. data/test/drawing/tc_chart.rb +23 -10
  55. data/test/drawing/tc_drawing.rb +2 -2
  56. data/test/drawing/tc_line_series.rb +38 -5
  57. data/test/drawing/tc_pic.rb +11 -19
  58. data/test/drawing/tc_scatter_series.rb +16 -5
  59. data/test/drawing/tc_str_val.rb +9 -0
  60. data/test/drawing/tc_title.rb +5 -0
  61. data/test/stylesheet/tc_styles.rb +2 -2
  62. data/test/tc_axlsx.rb +31 -0
  63. data/test/tc_helper.rb +3 -1
  64. data/test/tc_package.rb +12 -0
  65. data/test/util/tc_mime_type_utils.rb +13 -0
  66. data/test/util/tc_simple_typed_list.rb +1 -1
  67. data/test/util/tc_validators.rb +34 -10
  68. data/test/workbook/tc_shared_strings_table.rb +16 -1
  69. data/test/workbook/tc_workbook.rb +22 -1
  70. data/test/workbook/worksheet/tc_cell.rb +53 -11
  71. data/test/workbook/worksheet/tc_outline_pr.rb +19 -0
  72. data/test/workbook/worksheet/tc_pivot_table.rb +21 -6
  73. data/test/workbook/worksheet/tc_rich_text_run.rb +11 -11
  74. data/test/workbook/worksheet/tc_row.rb +5 -0
  75. data/test/workbook/worksheet/tc_sheet_pr.rb +26 -4
  76. data/test/workbook/worksheet/tc_table.rb +2 -3
  77. data/test/workbook/worksheet/tc_worksheet.rb +53 -38
  78. metadata +72 -20
  79. data/examples/IMAGE1UP.JPEG +0 -0
  80. data/lib/axlsx/util/string.rb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bbd74d60d15e7375b31b29eb04943c5014519d0a
4
- data.tar.gz: 13a7cdaf65bd1da6d7b780b9c8217cf544141679
3
+ metadata.gz: 0ace95e053d44bf7ebbd97250359660526f4672d
4
+ data.tar.gz: fbbcb63a35a7c7b39a15895e6c7d6478ea32a5a6
5
5
  SHA512:
6
- metadata.gz: 92fdb46000096174c14f32b6783e8758b39535ceb2bc193cfb0f45723c98babe7abfdab3e1ae2af76c999f414e67bf47afe93e46827571db5aa0b3bb97f79492
7
- data.tar.gz: 2b7e3f18fa42835e8ca6e48a40b8641cb0d799f898124e827c7993adb097216df788bef033dde4d1a5525338d4d24a28112092f42ce9684f61ad74daf2b09df1
6
+ metadata.gz: cce5eb9c776949ceb488f48d6014eeff6090203b90ca80dc43a553c5439f847a4885f698772eed72096a82049048ba9a26e7013a5e0de5a984fe7c7f6afe6cac
7
+ data.tar.gz: 2a882ec60dd5ddf6e96f662c69f00db4ce0516e1063797f3341e630549f17813796f868e00b8c7548531cf48c3f804c84759f5367e548ac466857273a9745702
@@ -1,5 +1,10 @@
1
1
  CHANGELOG
2
2
  ---------
3
+ - **April.1.17**:3.0.0-pre
4
+ - Support for ruby versions limited to officially supported version
5
+ - Updates to dependency gems, especially nokogiri and ruby-zip
6
+ - Patch options parsing for two cell anchor
7
+ - Remove support for depreciated worksheet members
3
8
  - **November.25.12**:1.3.4
4
9
  - Support for headers and footers for worksheets
5
10
  - bug fix: Properly escape hyperlink urls
data/README.md CHANGED
@@ -1,12 +1,10 @@
1
1
  Axlsx: Office Open XML Spreadsheet Generation
2
2
  ====================================
3
- [![Build Status](https://secure.travis-ci.org/randym/axlsx.png?branch=master)](http://travis-ci.org/randym/axlsx/)
3
+ [![Build Status](https://secure.travis-ci.org/randym/axlsx.svg?branch=master)](http://travis-ci.org/randym/axlsx/)
4
4
 
5
- If you are using axlsx for comercial purposes, or just want to show your
5
+ If you are using axlsx for commercial purposes, or just want to show your
6
6
  appreciation for the gem, please don't hesitate to make a donation.
7
7
 
8
- [![Click here to lend your support to: axlsx and make a donation at www.pledgie.com !](http://www.pledgie.com/campaigns/17814.png?skin_name=chrome)](http://www.pledgie.com/campaigns/17814)
9
-
10
8
  **IRC**:[irc.freenode.net / #axlsx](irc://irc.freenode.net/axlsx)
11
9
 
12
10
  **Git**:[http://github.com/randym/axlsx](http://github.com/randym/axlsx)
@@ -17,17 +15,17 @@ appreciation for the gem, please don't hesitate to make a donation.
17
15
 
18
16
  **Author**: Randy Morgan
19
17
 
20
- **Copyright**: 2011 - 2013
18
+ **Copyright**: 2011 - 2017
21
19
 
22
20
  **License**: MIT License
23
21
 
24
- **Latest Version**: 2.0.1
22
+ **Latest Version**: 3.0.0
25
23
 
26
- **Ruby Version**: 1.9.2, 1.9.3, 2.0.0
24
+ **Ruby Version**: 2.2.7, 2.3.4, 2.4.1
27
25
 
28
26
  **JRuby Version**: 1.9 modes
29
27
 
30
- **Rubinius Version**: rubinius 2.0.0dev * lower versions may run, this gem always tests against head.
28
+ **Rubinius Version**: rubinius 3 * lower versions may run, this gem always tests against head.
31
29
 
32
30
  **Release Date**: September 12th 2013
33
31
 
@@ -52,7 +50,7 @@ If you are working with ActiveAdmin see:
52
50
 
53
51
  [activeadmin-axlsx](http://github.com/randym/activeadmin-axlsx)
54
52
 
55
- It provies a plugin and dsl for generating downloadable reports.
53
+ It provides a plugin and dsl for generating downloadable reports.
56
54
 
57
55
  The examples directory contains a number of more specific examples as
58
56
  well.
@@ -153,7 +151,7 @@ There is much, much more you can do with this gem. If you get stuck, grab me on
153
151
 
154
152
  This gem is 100% documented with YARD, an exceptional documentation library. To see documentation for this, and all the gems installed on your system use:
155
153
 
156
- gem install yard
154
+ gem install yard kramdown
157
155
 
158
156
  yard server -g
159
157
 
@@ -231,16 +229,15 @@ related to themes, which axlsx does not implement at this time.
231
229
  - you must set 'use_shared_strings' to true. This is most
232
230
  conveniently done just before rendering by calling Package.use_shared_strings = true prior to serialization.
233
231
 
234
- ```ruby
235
- p = Axlsx::Package.new
236
- p.workbook.add_worksheet(:name => "Basic Worksheet") do |sheet|
237
- sheet.add_row ["First Column", "Second", "Third"]
238
- sheet.add_row [1, 2, 3]
239
- end
240
- p.use_shared_strings = true
241
- p.serialize('simple.xlsx')
242
- ```
243
-
232
+ ```ruby
233
+ p = Axlsx::Package.new
234
+ p.workbook.add_worksheet(:name => "Basic Worksheet") do |sheet|
235
+ sheet.add_row ["First Column", "Second", "Third"]
236
+ sheet.add_row [1, 2, 3]
237
+ end
238
+ p.use_shared_strings = true
239
+ p.serialize('simple.xlsx')
240
+ ```
244
241
  - charts do not render
245
242
 
246
243
 
data/Rakefile CHANGED
@@ -9,7 +9,6 @@ task :benchmark do
9
9
  end
10
10
 
11
11
  task :gendoc do
12
- #puts 'yard doc generation disabled until JRuby build native extensions for redcarpet or yard removes the dependency.'
13
12
  system "yardoc"
14
13
  system "yard stats --list-undoc"
15
14
  end
@@ -9,6 +9,7 @@ book = p.workbook
9
9
  # define your regular styles
10
10
  percent = book.styles.add_style(:format_code => "0.00%", :border => Axlsx::STYLE_THIN_BORDER)
11
11
  money = book.styles.add_style(:format_code => '0,000', :border => Axlsx::STYLE_THIN_BORDER)
12
+ status = book.styles.add_style(:border => Axlsx::STYLE_THIN_BORDER)
12
13
 
13
14
  # define the style for conditional formatting
14
15
  profitable = book.styles.add_style( :fg_color => "428751", :type => :dxf )
@@ -71,4 +72,18 @@ book.add_worksheet(:name => "Icon Set") do |ws|
71
72
  ws.add_conditional_formatting("B3:B100", { :type => :iconSet, :dxfId => profitable, :priority => 1, :icon_set => icon_set })
72
73
  end
73
74
 
75
+ book.add_worksheet(:name => "Contains Text") do |ws|
76
+ ws.add_row ["Previous Year Quarterly Profits (JPY)"]
77
+ ws.add_row ["Quarter", "Profit", "% of Total", "Status"]
78
+ offset = 3
79
+ rows = 20
80
+ offset.upto(rows + offset) do |i|
81
+ ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})", (10000*((rows/2-i) * (rows/2-i))) > 100000 ? "PROFIT" : "LOSS"], :style=>[nil, money, percent, status]
82
+ end
83
+
84
+ # Apply conditional formatting to range D3:D100 in the worksheet
85
+ ws.add_conditional_formatting("D3:D100", { :type => :containsText, :operator => :equal, :text => "PROFIT", :dxfId => profitable, :priority => 1 })
86
+ ws.add_conditional_formatting("D3:D100", { :type => :containsText, :operator => :equal, :text => "LOSS", :dxfId => unprofitable, :priority => 1 })
87
+ end
88
+
74
89
  p.serialize('example_conditional_formatting.xlsx')
@@ -51,6 +51,7 @@ examples << :no_autowidth
51
51
  examples << :cached_formula
52
52
  examples << :page_breaks
53
53
  examples << :rich_text
54
+ examples << :tab_color
54
55
 
55
56
  p = Axlsx::Package.new
56
57
  wb = p.workbook
@@ -676,7 +677,7 @@ end
676
677
 
677
678
  ## Book Views
678
679
  #
679
- ## Book views let you specify which sheet the show as active when the user opens the work book as well as a bunch of other
680
+ ## Book views let you specify which sheet the show as active when the user opens the work book as well as a bunch of other
680
681
  ## tuning values for the UI @see Axlsx::WorkbookView
681
682
  ## ```ruby
682
683
  if examples.include? :book_view
@@ -700,6 +701,7 @@ end
700
701
  if examples.include? :conditional_formatting
701
702
  percent = wb.styles.add_style(:format_code => "0.00%", :border => Axlsx::STYLE_THIN_BORDER)
702
703
  money = wb.styles.add_style(:format_code => '0,000', :border => Axlsx::STYLE_THIN_BORDER)
704
+ status = wb.styles.add_style(:border => Axlsx::STYLE_THIN_BORDER)
703
705
 
704
706
  # define the style for conditional formatting
705
707
  profitable = wb.styles.add_style( :fg_color => "FF428751", :type => :dxf )
@@ -763,6 +765,19 @@ if examples.include? :conditional_formatting
763
765
  icon_set = Axlsx::IconSet.new
764
766
  sheet.add_conditional_formatting("B3:B100", { :type => :iconSet, :dxfId => profitable, :priority => 1, :icon_set => icon_set })
765
767
  end
768
+
769
+ wb.add_worksheet(:name => "Contains Text") do |sheet|
770
+ sheet.add_row ["Previous Year Quarterly Profits (JPY)"]
771
+ sheet.add_row ["Quarter", "Profit", "% of Total", "Status"]
772
+ offset = 3
773
+ rows = 20
774
+ offset.upto(rows + offset) do |i|
775
+ sheet.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})", (10000*((rows/2-i) * (rows/2-i))) > 100000 ? "PROFIT" : "LOSS"], :style=>[nil, money, percent, status]
776
+ end
777
+ # Apply conditional formatting to range D3:D100 in the worksheet to match words.
778
+ sheet.add_conditional_formatting("D3:D100", { :type => :containsText, :operator => :equal, :text => "PROFIT", :dxfId => profitable, :priority => 1 })
779
+ sheet.add_conditional_formatting("D3:D100", { :type => :containsText, :operator => :equal, :text => "LOSS", :dxfId => unprofitable, :priority => 1 })
780
+ end
766
781
  end
767
782
 
768
783
  # Page Breaks
@@ -843,3 +858,18 @@ if examples.include? :rich_text
843
858
  p.serialize 'rich_text.xlsx'
844
859
  end
845
860
  #```
861
+
862
+ ##Change tab color of sheet
863
+
864
+ #```ruby
865
+ if examples.include? :tab_color
866
+ p = Axlsx::Package.new
867
+ p.use_shared_strings = true
868
+ wb = p.workbook
869
+ wb.add_worksheet(:name => "Change Tab Color") do |sheet|
870
+ sheet.add_row ["Check", "out", "the", "Tab Color", "below!"]
871
+ sheet.sheet_pr.tab_color = "FFFF6666"
872
+ end
873
+ p.serialize 'tab_color.xlsx'
874
+ end
875
+ ##```
@@ -1,6 +1,7 @@
1
1
  # encoding: UTF-8
2
2
  require 'htmlentities'
3
3
  require 'axlsx/version.rb'
4
+ require 'mimemagic'
4
5
 
5
6
  require 'axlsx/util/simple_typed_list.rb'
6
7
  require 'axlsx/util/constants.rb'
@@ -10,7 +11,7 @@ require 'axlsx/util/serialized_attributes'
10
11
  require 'axlsx/util/options_parser'
11
12
  # to be included with parsable intitites.
12
13
  #require 'axlsx/util/parser.rb'
13
- require 'axlsx/util/string'
14
+ require 'axlsx/util/mime_type_utils'
14
15
 
15
16
  require 'axlsx/stylesheet/styles.rb'
16
17
 
@@ -134,10 +135,14 @@ module Axlsx
134
135
  # @param [String] str The string to process
135
136
  # @return [String]
136
137
  def self.sanitize(str)
137
- str.delete!(CONTROL_CHARS)
138
- str
138
+ if str.frozen?
139
+ str.delete(CONTROL_CHARS)
140
+ else
141
+ str.delete!(CONTROL_CHARS)
142
+ str
143
+ end
139
144
  end
140
-
145
+
141
146
  # If value is boolean return 1 or 0
142
147
  # else return the value
143
148
  # @param [Object] value The value to process
@@ -0,0 +1,99 @@
1
+ # encoding: UTF-8
2
+ module Axlsx
3
+
4
+ # The AreaChart 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::AreaChart, :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 AreaChart < 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 = AreaSeries
53
+ @d_lbls = nil
54
+ end
55
+
56
+ # @see grouping
57
+ def grouping=(v)
58
+ RestrictionValidator.validate "AreaChart.grouping", [:percentStacked, :standard, :stacked], v
59
+ @grouping = v
60
+ end
61
+
62
+ # The node name to use in serialization. As AreaChart 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
80
+ str << ("<c:" << node_name << ">")
81
+ str << ('<c:grouping val="' << grouping.to_s << '"/>')
82
+ str << ('<c:varyColors val="' << vary_colors.to_s << '"/>')
83
+ @series.each { |ser| ser.to_xml_string(str) }
84
+ @d_lbls.to_xml_string(str) if @d_lbls
85
+ yield if block_given?
86
+ axes.to_xml_string(str, :ids => true)
87
+ str << ("</c:" << node_name << ">")
88
+ axes.to_xml_string(str)
89
+ end
90
+ end
91
+
92
+ # The axes for this chart. AreaCharts 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
@@ -0,0 +1,110 @@
1
+ # encoding: UTF-8
2
+ module Axlsx
3
+ # A AreaSeries defines the title, data and labels for line charts
4
+ # @note The recommended way to manage series is to use Chart#add_series
5
+ # @see Worksheet#add_chart
6
+ # @see Chart#add_series
7
+ class AreaSeries < Series
8
+
9
+ # The data for this series.
10
+ # @return [ValAxisData]
11
+ attr_reader :data
12
+
13
+ # The labels for this series.
14
+ # @return [CatAxisData]
15
+ attr_reader :labels
16
+
17
+ # The fill color for this series.
18
+ # Red, green, and blue is expressed as sequence of hex digits, RRGGBB. A perceptual gamma of 2.2 is used.
19
+ # @return [String]
20
+ attr_reader :color
21
+
22
+ # show markers on values
23
+ # @return [Boolean]
24
+ attr_reader :show_marker
25
+
26
+ # custom marker symbol
27
+ # @return [String]
28
+ attr_reader :marker_symbol
29
+
30
+ # line smoothing on values
31
+ # @return [Boolean]
32
+ attr_reader :smooth
33
+
34
+ # Creates a new series
35
+ # @option options [Array, SimpleTypedList] data
36
+ # @option options [Array, SimpleTypedList] labels
37
+ # @param [Chart] chart
38
+ def initialize(chart, options={})
39
+ @show_marker = false
40
+ @marker_symbol = options[:marker_symbol] ? options[:marker_symbol] : :default
41
+ @smooth = false
42
+ @labels, @data = nil, nil
43
+ super(chart, options)
44
+ @labels = AxDataSource.new(:data => options[:labels]) unless options[:labels].nil?
45
+ @data = NumDataSource.new(options) unless options[:data].nil?
46
+ end
47
+
48
+ # @see color
49
+ def color=(v)
50
+ @color = v
51
+ end
52
+
53
+ # @see show_marker
54
+ def show_marker=(v)
55
+ Axlsx::validate_boolean(v)
56
+ @show_marker = v
57
+ end
58
+
59
+ # @see marker_symbol
60
+ def marker_symbol=(v)
61
+ Axlsx::validate_marker_symbol(v)
62
+ @marker_symbol = v
63
+ end
64
+
65
+ # @see smooth
66
+ def smooth=(v)
67
+ Axlsx::validate_boolean(v)
68
+ @smooth = v
69
+ end
70
+
71
+ # Serializes the object
72
+ # @param [String] str
73
+ # @return [String]
74
+ def to_xml_string(str = '')
75
+ super(str) do
76
+ if color
77
+ str << '<c:spPr><a:solidFill>'
78
+ str << ('<a:srgbClr val="' << color << '"/>')
79
+ str << '</a:solidFill>'
80
+ str << '<a:ln w="28800">'
81
+ str << '<a:solidFill>'
82
+ str << ('<a:srgbClr val="' << color << '"/>')
83
+ str << '</a:solidFill>'
84
+ str << '</a:ln>'
85
+ str << '<a:round/>'
86
+ str << '</c:spPr>'
87
+ end
88
+
89
+ if !@show_marker
90
+ str << '<c:marker><c:symbol val="none"/></c:marker>'
91
+ elsif @marker_symbol != :default
92
+ str << '<c:marker><c:symbol val="' + @marker_symbol.to_s + '"/></c:marker>'
93
+ end
94
+
95
+ @labels.to_xml_string(str) unless @labels.nil?
96
+ @data.to_xml_string(str) unless @data.nil?
97
+ str << ('<c:smooth val="' << ((smooth) ? '1' : '0') << '"/>')
98
+ end
99
+ end
100
+
101
+ private
102
+
103
+ # assigns the data for this series
104
+ def data=(v) DataTypeValidator.validate "Series.data", [NumDataSource], v; @data = v; end
105
+
106
+ # assigns the labels for this series
107
+ def labels=(v) DataTypeValidator.validate "Series.labels", [AxDataSource], v; @labels = v; end
108
+
109
+ end
110
+ end
@@ -0,0 +1,143 @@
1
+ # encoding: UTF-8
2
+ module Axlsx
3
+
4
+ # The BarChart is a three dimentional barchart (who would have guessed?) that you can add to your worksheet.
5
+ # @see Worksheet#add_chart
6
+ # @see Chart#add_series
7
+ # @see Package#serialize
8
+ # @see README for an example
9
+ class BarChart < Chart
10
+
11
+ # the category axis
12
+ # @return [CatAxis]
13
+ def cat_axis
14
+ axes[:cat_axis]
15
+ end
16
+ alias :catAxis :cat_axis
17
+
18
+ # the value axis
19
+ # @return [ValAxis]
20
+ def val_axis
21
+ axes[:val_axis]
22
+ end
23
+ alias :valAxis :val_axis
24
+
25
+ # The direction of the bars in the chart
26
+ # must be one of [:bar, :col]
27
+ # @return [Symbol]
28
+ def bar_dir
29
+ @bar_dir ||= :bar
30
+ end
31
+ alias :barDir :bar_dir
32
+
33
+ # space between bar or column clusters, as a percentage of the bar or column width.
34
+ # @return [String]
35
+ attr_reader :gap_depth
36
+ alias :gapDepth :gap_depth
37
+
38
+ # space between bar or column clusters, as a percentage of the bar or column width.
39
+ # @return [String]
40
+ def gap_width
41
+ @gap_width ||= 150
42
+ end
43
+ alias :gapWidth :gap_width
44
+
45
+ #grouping for a column, line, or area chart.
46
+ # must be one of [:percentStacked, :clustered, :standard, :stacked]
47
+ # @return [Symbol]
48
+ def grouping
49
+ @grouping ||= :clustered
50
+ end
51
+
52
+ # The shabe of the bars or columns
53
+ # must be one of [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax]
54
+ # @return [Symbol]
55
+ def shape
56
+ @shape ||= :box
57
+ end
58
+
59
+ # validation regex for gap amount percent
60
+ GAP_AMOUNT_PERCENT = /0*(([0-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)%/
61
+
62
+ # Creates a new bar chart object
63
+ # @param [GraphicFrame] frame The workbook that owns this chart.
64
+ # @option options [Cell, String] title
65
+ # @option options [Boolean] show_legend
66
+ # @option options [Symbol] bar_dir
67
+ # @option options [Symbol] grouping
68
+ # @option options [String] gap_width
69
+ # @option options [String] gap_depth
70
+ # @option options [Symbol] shape
71
+ # @see Chart
72
+ def initialize(frame, options={})
73
+ @vary_colors = true
74
+ @gap_width, @gap_depth, @shape = nil, nil, nil
75
+ super(frame, options)
76
+ @series_type = BarSeries
77
+ @d_lbls = nil
78
+ end
79
+
80
+ # The direction of the bars in the chart
81
+ # must be one of [:bar, :col]
82
+ def bar_dir=(v)
83
+ RestrictionValidator.validate "BarChart.bar_dir", [:bar, :col], v
84
+ @bar_dir = v
85
+ end
86
+ alias :barDir= :bar_dir=
87
+
88
+ #grouping for a column, line, or area chart.
89
+ # must be one of [:percentStacked, :clustered, :standard, :stacked]
90
+ def grouping=(v)
91
+ RestrictionValidator.validate "BarChart.grouping", [:percentStacked, :clustered, :standard, :stacked], v
92
+ @grouping = v
93
+ end
94
+
95
+ # space between bar or column clusters, as a percentage of the bar or column width.
96
+ def gap_width=(v)
97
+ RegexValidator.validate "BarChart.gap_width", GAP_AMOUNT_PERCENT, v
98
+ @gap_width=(v)
99
+ end
100
+ alias :gapWidth= :gap_width=
101
+
102
+ # space between bar or column clusters, as a percentage of the bar or column width.
103
+ def gap_depth=(v)
104
+ RegexValidator.validate "BarChart.gap_didth", GAP_AMOUNT_PERCENT, v
105
+ @gap_depth=(v)
106
+ end
107
+ alias :gapDepth= :gap_depth=
108
+
109
+ # The shabe of the bars or columns
110
+ # must be one of [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax]
111
+ def shape=(v)
112
+ RestrictionValidator.validate "BarChart.shape", [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax], v
113
+ @shape = v
114
+ end
115
+
116
+ # Serializes the object
117
+ # @param [String] str
118
+ # @return [String]
119
+ def to_xml_string(str = '')
120
+ super(str) do
121
+ str << '<c:barChart>'
122
+ str << ('<c:barDir val="' << bar_dir.to_s << '"/>')
123
+ str << ('<c:grouping val="' << grouping.to_s << '"/>')
124
+ str << ('<c:varyColors val="' << vary_colors.to_s << '"/>')
125
+ @series.each { |ser| ser.to_xml_string(str) }
126
+ @d_lbls.to_xml_string(str) if @d_lbls
127
+ str << ('<c:gapWidth val="' << @gap_width.to_s << '"/>') unless @gap_width.nil?
128
+ str << ('<c:gapDepth val="' << @gap_depth.to_s << '"/>') unless @gap_depth.nil?
129
+ str << ('<c:shape val="' << @shape.to_s << '"/>') unless @shape.nil?
130
+ axes.to_xml_string(str, :ids => true)
131
+ str << '</c:barChart>'
132
+ axes.to_xml_string(str)
133
+ end
134
+ end
135
+
136
+ # A hash of axes used by this chart. Bar charts have a value and
137
+ # category axes specified via axes[:val_axes] and axes[:cat_axis]
138
+ # @return [Axes]
139
+ def axes
140
+ @axes ||= Axes.new(:cat_axis => CatAxis, :val_axis => ValAxis)
141
+ end
142
+ end
143
+ end