write_xlsx 0.51.0 → 0.54.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. data/.gitignore +39 -0
  2. data/Gemfile +4 -14
  3. data/LICENSE.txt +3 -1
  4. data/README.rdoc +5 -0
  5. data/Rakefile +4 -71
  6. data/examples/chart_radar.rb +127 -0
  7. data/examples/chart_secondary_axis.rb +1 -1
  8. data/lib/write_xlsx/chart/area.rb +7 -18
  9. data/lib/write_xlsx/chart/bar.rb +20 -23
  10. data/lib/write_xlsx/chart/column.rb +7 -20
  11. data/lib/write_xlsx/chart/radar.rb +94 -0
  12. data/lib/write_xlsx/chart/stock.rb +6 -0
  13. data/lib/write_xlsx/chart.rb +317 -116
  14. data/lib/write_xlsx/package/xml_writer_simple.rb +2 -2
  15. data/lib/write_xlsx/version.rb +5 -0
  16. data/test/chart/test_write_a_latin.rb +22 -0
  17. data/test/chart/test_write_auto.rb +1 -1
  18. data/test/chart/test_write_ax_id.rb +1 -1
  19. data/test/chart/test_write_ax_pos.rb +1 -1
  20. data/test/chart/test_write_cross_ax.rb +1 -1
  21. data/test/chart/test_write_crosses.rb +1 -1
  22. data/test/chart/test_write_d_lbls.rb +18 -18
  23. data/test/chart/test_write_idx.rb +1 -1
  24. data/test/chart/test_write_label_align.rb +1 -1
  25. data/test/chart/test_write_label_offset.rb +1 -1
  26. data/test/chart/test_write_lang.rb +1 -1
  27. data/test/chart/test_write_layout.rb +1 -1
  28. data/test/chart/test_write_legend.rb +1 -1
  29. data/test/chart/test_write_legend_pos.rb +1 -1
  30. data/test/chart/test_write_major_gridlines.rb +2 -2
  31. data/test/chart/test_write_marker.rb +1 -1
  32. data/test/chart/test_write_marker_size.rb +1 -1
  33. data/test/chart/test_write_marker_value.rb +1 -1
  34. data/test/chart/test_write_num_cache.rb +1 -1
  35. data/test/chart/test_write_number_format.rb +40 -2
  36. data/test/chart/test_write_order.rb +1 -1
  37. data/test/chart/test_write_orientation.rb +1 -1
  38. data/test/chart/test_write_page_margins.rb +1 -1
  39. data/test/chart/test_write_page_setup.rb +1 -1
  40. data/test/chart/test_write_plot_vis_only.rb +1 -1
  41. data/test/chart/test_write_pt_count.rb +1 -1
  42. data/test/chart/test_write_style.rb +1 -1
  43. data/test/chart/test_write_symbol.rb +1 -1
  44. data/test/chart/test_write_tick_lbl_pos.rb +1 -1
  45. data/test/drawing/test_write_a_graphic_frame_locks.rb +1 -1
  46. data/test/drawing/test_write_c_chart.rb +1 -1
  47. data/test/drawing/test_write_c_nv_graphic_frame_pr.rb +2 -2
  48. data/test/drawing/test_write_c_nv_pr.rb +1 -1
  49. data/test/drawing/test_write_ext.rb +1 -1
  50. data/test/drawing/test_write_pos.rb +1 -1
  51. data/test/drawing/test_write_xfrm_extension.rb +1 -1
  52. data/test/drawing/test_write_xfrm_offset.rb +1 -1
  53. data/test/helper.rb +1 -1
  54. data/test/package/content_types/test_write_default.rb +1 -1
  55. data/test/package/content_types/test_write_override.rb +1 -1
  56. data/test/package/table/test_write_auto_filter.rb +1 -1
  57. data/test/package/table/test_write_table_column.rb +1 -1
  58. data/test/package/table/test_write_table_style_info.rb +1 -1
  59. data/test/package/vml/test_write_fill.rb +1 -1
  60. data/test/package/vml/test_write_idmap.rb +1 -1
  61. data/test/package/vml/test_write_move_with_cells.rb +1 -1
  62. data/test/package/vml/test_write_path.rb +2 -2
  63. data/test/package/vml/test_write_shadow.rb +1 -1
  64. data/test/package/vml/test_write_shapelayout.rb +1 -1
  65. data/test/package/vml/test_write_shapetype.rb +1 -1
  66. data/test/package/vml/test_write_size_with_cells.rb +1 -1
  67. data/test/package/vml/test_write_stroke.rb +1 -1
  68. data/test/perl_output/chart_radar.xlsx +0 -0
  69. data/test/perl_output/chart_secondary_axis.xlsx +0 -0
  70. data/test/regression/test_chart_axis22.rb +45 -0
  71. data/test/regression/test_chart_axis23.rb +46 -0
  72. data/test/regression/test_chart_axis24.rb +46 -0
  73. data/test/regression/test_chart_font01.rb +54 -0
  74. data/test/regression/test_chart_font02.rb +56 -0
  75. data/test/regression/test_chart_font03.rb +59 -0
  76. data/test/regression/test_chart_font04.rb +57 -0
  77. data/test/regression/test_chart_font05.rb +54 -0
  78. data/test/regression/test_chart_font06.rb +84 -0
  79. data/test/regression/test_chart_radar01.rb +39 -0
  80. data/test/regression/test_chart_radar02.rb +43 -0
  81. data/test/regression/test_chart_radar03.rb +43 -0
  82. data/test/regression/test_escapes04.rb +30 -0
  83. data/test/regression/test_escapes05.rb +31 -0
  84. data/test/regression/test_rich_string01.rb +1 -1
  85. data/test/regression/test_rich_string02.rb +1 -1
  86. data/test/regression/test_rich_string03.rb +1 -1
  87. data/test/regression/test_rich_string04.rb +1 -1
  88. data/test/regression/test_rich_string05.rb +1 -1
  89. data/test/regression/test_rich_string06.rb +1 -1
  90. data/test/regression/test_rich_string07.rb +1 -1
  91. data/test/regression/test_rich_string08.rb +1 -1
  92. data/test/regression/test_rich_string09.rb +1 -1
  93. data/test/regression/test_rich_string10.rb +1 -1
  94. data/test/regression/test_rich_string11.rb +1 -1
  95. data/test/regression/test_shape_connect01.rb +1 -1
  96. data/test/regression/test_shape_connect02.rb +1 -1
  97. data/test/regression/test_shape_connect03.rb +1 -1
  98. data/test/regression/test_shape_connect04.rb +1 -1
  99. data/test/regression/xlsx_files/chart_axis22.xlsx +0 -0
  100. data/test/regression/xlsx_files/chart_axis23.xlsx +0 -0
  101. data/test/regression/xlsx_files/chart_axis24.xlsx +0 -0
  102. data/test/regression/xlsx_files/chart_font01.xlsx +0 -0
  103. data/test/regression/xlsx_files/chart_font02.xlsx +0 -0
  104. data/test/regression/xlsx_files/chart_font03.xlsx +0 -0
  105. data/test/regression/xlsx_files/chart_font04.xlsx +0 -0
  106. data/test/regression/xlsx_files/chart_font05.xlsx +0 -0
  107. data/test/regression/xlsx_files/chart_font06.xlsx +0 -0
  108. data/test/regression/xlsx_files/chart_radar01.xlsx +0 -0
  109. data/test/regression/xlsx_files/chart_radar02.xlsx +0 -0
  110. data/test/regression/xlsx_files/chart_radar03.xlsx +0 -0
  111. data/test/regression/xlsx_files/escapes04.xlsx +0 -0
  112. data/test/regression/xlsx_files/escapes05.xlsx +0 -0
  113. data/test/test_example_match.rb +119 -1
  114. data/test/test_xml_writer_simple.rb +4 -4
  115. data/test/worksheet/test_write_autofilter.rb +21 -21
  116. data/test/worksheet/test_write_brk.rb +1 -1
  117. data/test/worksheet/test_write_col_breaks.rb +2 -2
  118. data/test/worksheet/test_write_col_info.rb +6 -6
  119. data/test/worksheet/test_write_custom_filter.rb +1 -1
  120. data/test/worksheet/test_write_custom_filters.rb +2 -2
  121. data/test/worksheet/test_write_dimension.rb +9 -9
  122. data/test/worksheet/test_write_ext.rb +1 -1
  123. data/test/worksheet/test_write_ext_lst.rb +1 -1
  124. data/test/worksheet/test_write_filter.rb +1 -1
  125. data/test/worksheet/test_write_filter_column.rb +1 -1
  126. data/test/worksheet/test_write_filters.rb +3 -3
  127. data/test/worksheet/test_write_hyperlink.rb +4 -4
  128. data/test/worksheet/test_write_hyperlinks.rb +2 -2
  129. data/test/worksheet/test_write_legacy_drawing.rb +1 -1
  130. data/test/worksheet/test_write_merge_cell.rb +1 -1
  131. data/test/worksheet/test_write_mx_plv.rb +1 -1
  132. data/test/worksheet/test_write_page_margins.rb +11 -11
  133. data/test/worksheet/test_write_page_set_up_pr.rb +1 -1
  134. data/test/worksheet/test_write_page_setup.rb +4 -4
  135. data/test/worksheet/test_write_pane.rb +14 -14
  136. data/test/worksheet/test_write_phonetic_pr.rb +1 -1
  137. data/test/worksheet/test_write_print_options.rb +5 -5
  138. data/test/worksheet/test_write_row_breaks.rb +2 -2
  139. data/test/worksheet/test_write_row_element.rb +1 -1
  140. data/test/worksheet/test_write_selection.rb +1 -1
  141. data/test/worksheet/test_write_sheet_calc_pr.rb +1 -1
  142. data/test/worksheet/test_write_sheet_data.rb +1 -1
  143. data/test/worksheet/test_write_sheet_format_pr.rb +1 -1
  144. data/test/worksheet/test_write_sheet_pr.rb +3 -3
  145. data/test/worksheet/test_write_sheet_protection.rb +18 -18
  146. data/test/worksheet/test_write_sheet_view.rb +6 -6
  147. data/test/worksheet/test_write_sheet_view1.rb +6 -6
  148. data/test/worksheet/test_write_sheet_view2.rb +5 -5
  149. data/test/worksheet/test_write_sheet_view3.rb +8 -8
  150. data/test/worksheet/test_write_sheet_view4.rb +8 -8
  151. data/test/worksheet/test_write_sheet_view5.rb +7 -7
  152. data/test/worksheet/test_write_sheet_view6.rb +4 -4
  153. data/test/worksheet/test_write_sheet_view7.rb +6 -6
  154. data/test/worksheet/test_write_sheet_view8.rb +4 -4
  155. data/test/worksheet/test_write_sheet_view9.rb +4 -4
  156. data/test/worksheet/test_write_tab_color.rb +1 -1
  157. data/write_xlsx.gemspec +18 -935
  158. metadata +881 -32
  159. data/VERSION +0 -1
  160. data/test/chart/test_write_num_fmt.rb +0 -16
data/.gitignore ADDED
@@ -0,0 +1,39 @@
1
+ *.gem
2
+ .bundle
3
+ .config
4
+ .yardoc
5
+ Gemfile.lock
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
17
+ work
18
+
19
+ # For MacOS:
20
+ #
21
+ .DS_Store
22
+
23
+ # For TextMate
24
+ *.tmproj
25
+ tmtags
26
+
27
+ # For emacs:
28
+ *~
29
+ \#*
30
+ .\#*
31
+
32
+ # For vim:
33
+ *.swp
34
+
35
+ # For redcar:
36
+ .redcar
37
+
38
+ # For rubinius:
39
+ *.rbc
data/Gemfile CHANGED
@@ -1,14 +1,4 @@
1
- source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
- gem "rubyzip", ">= 0"
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
- group :development do
9
- gem "jeweler", "~> 1.6.4"
10
- gem "bundler"
11
- end
12
- group :test do
13
- gem "rdoc"
14
- end
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in write_xlsx.gemspec
4
+ gemspec
data/LICENSE.txt CHANGED
@@ -1,4 +1,6 @@
1
- Copyright (c) 2012 Hideo NAKAMURA
1
+ Copyright (c) 2012-2013 Hideo NAKAMURA
2
+
3
+ MIT License
2
4
 
3
5
  Permission is hereby granted, free of charge, to any person obtaining
4
6
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -60,6 +60,11 @@ the first worksheet in an Excel XML spreadsheet called ruby.xlsx:
60
60
 
61
61
  == Recent change
62
62
 
63
+ 2013-02-07 v0.54.0
64
+ Added font manipulation to Charts.
65
+ Added number formats to Chart axes.
66
+ Added Radar Charts.
67
+
63
68
  2012-11-30 v0.51.0
64
69
  Impliment Shape, Table as welll as Excel::Write::XLSX-0.51
65
70
 
data/Rakefile CHANGED
@@ -1,78 +1,11 @@
1
- # encoding: utf-8
2
-
1
+ require "bundler/gem_tasks"
3
2
  require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
-
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "write_xlsx"
18
- gem.homepage = "http://github.com/cxn03651/write_xlsx"
19
- gem.license = "MIT"
20
- gem.summary = %Q{write_xlsx is a gem to create a new file in the Excel 2007+ XLSX format.}
21
- gem.description = <<EOS
22
- write_xlsx s a gem to create a new file in the Excel 2007+ XLSX format, and you can use the same interface as writeexcel gem.
23
- The WriteXLSX supports the following features:
24
- * Multiple worksheets
25
- * Strings and numbers
26
- * Unicode text
27
- * Rich string formats
28
- * Formulas (including array formats)
29
- * cell formatting
30
- * Embedded images
31
- * Charts
32
- * Autofilters
33
- * Data validation
34
- * Hyperlinks
35
- * Defined names
36
- * Grouping/Outlines
37
- * Cell comments
38
- * Panes
39
- * Page set-up and printing options
40
-
41
- write_xlsx uses the same interface as writeexcel gem.
42
3
 
43
- documentation is not completed, but writeexcel’s documentation will help you. See http://writeexcel.web.fc2.com/
44
-
45
- And you can find many examples in this gem.
46
- EOS
47
- gem.email = "cxn03651@msj.biglobe.ne.jp"
48
- gem.authors = ["Hideo NAKAMURA"]
49
- # dependencies defined in Gemfile
50
- end
51
- Jeweler::RubygemsDotOrgTasks.new
4
+ task :default => :test
52
5
 
53
6
  require 'rake/testtask'
54
- Rake::TestTask.new(:test) do |test|
55
- test.libs << 'lib' << 'test'
7
+ Rake::TestTask.new do |test|
8
+ test.libs << 'test'
56
9
  test.pattern = 'test/**/test_*.rb'
57
10
  test.verbose = true
58
11
  end
59
-
60
- # require 'rcov/rcovtask'
61
- # Rcov::RcovTask.new do |test|
62
- # test.libs << 'test'
63
- # test.pattern = 'test/**/test_*.rb'
64
- # test.verbose = true
65
- # test.rcov_opts << '--exclude "gems/*"'
66
- # end
67
-
68
- task :default => :test
69
-
70
- require 'rdoc/task'
71
- Rake::RDocTask.new do |rdoc|
72
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
73
-
74
- rdoc.rdoc_dir = 'rdoc'
75
- rdoc.title = "write_xlsx #{version}"
76
- rdoc.rdoc_files.include('README*')
77
- rdoc.rdoc_files.include('lib/**/*.rb')
78
- end
@@ -0,0 +1,127 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ #######################################################################
5
+ #
6
+ # A demo of an Area chart in Excel::Writer::XLSX.
7
+ #
8
+ # reverse ('(c)'), October 2012, John McNamara, jmcnamara@cpan.org
9
+ # convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
10
+ #
11
+
12
+ require 'rubygems'
13
+ require 'write_xlsx'
14
+
15
+ workbook = WriteXLSX.new('chart_radar.xlsx')
16
+ worksheet = workbook.add_worksheet
17
+ bold = workbook.add_format(:bold => 1)
18
+
19
+ # Add the worksheet data that the charts will refer to.
20
+ headings = [ 'Number', 'Batch 1', 'Batch 2' ]
21
+ data = [
22
+ [ 2, 3, 4, 5, 6, 7 ],
23
+ [ 30, 60, 70, 50, 40, 30 ],
24
+ [ 25, 40, 50, 30, 50, 40 ]
25
+ ]
26
+
27
+ worksheet.write('A1', headings, bold)
28
+ worksheet.write('A2', data)
29
+
30
+ # Create a new chart object. In this case an embedded chart.
31
+ chart1 = workbook.add_chart(:type => 'radar', :embedded => 1)
32
+
33
+ # Configure the first series.
34
+ chart1.add_series(
35
+ :name => '=Sheet1!$B$1',
36
+ :categories => '=Sheet1!$A$2:$A$7',
37
+ :values => '=Sheet1!$B$2:$B$7'
38
+ )
39
+
40
+ # Configure second series. Note alternative use of array ref to define
41
+ # ranges: [ sheetname, row_start, row_end, col_start, col_end ].
42
+ chart1.add_series(
43
+ :name => '=Sheet1!$C$1',
44
+ :categories => [ 'Sheet1', 1, 6, 0, 0 ],
45
+ :values => [ 'Sheet1', 1, 6, 2, 2 ]
46
+ )
47
+
48
+ # Add a chart title and some axis labels.
49
+ chart1.set_title(:name => 'Results of sample analysis')
50
+ chart1.set_x_axis(:name => 'Test number')
51
+ chart1.set_y_axis(:name => 'Sample length (mm)')
52
+
53
+ # Set an Excel chart style. Blue colors with white outline and shadow.
54
+ chart1.set_style(11)
55
+
56
+ # Insert the chart into the worksheet (with an offset).
57
+ worksheet.insert_chart('D2', chart1, 25, 10)
58
+
59
+ #
60
+ # Create a with_markers chart sub-type
61
+ #
62
+ chart2 = workbook.add_chart(
63
+ :type => 'radar',
64
+ :embedded => 1,
65
+ :subtype => 'with_markers'
66
+ )
67
+
68
+ # Configure the first series.
69
+ chart2.add_series(
70
+ :name => '=Sheet1!$B$1',
71
+ :categories => '=Sheet1!$A$2:$A$7',
72
+ :values => '=Sheet1!$B$2:$B$7'
73
+ )
74
+
75
+ # Configure second series.
76
+ chart2.add_series(
77
+ :name => '=Sheet1!$C$1',
78
+ :categories => [ 'Sheet1', 1, 6, 0, 0 ],
79
+ :values => [ 'Sheet1', 1, 6, 2, 2 ]
80
+ )
81
+
82
+ # Add a chart title and some axis labels.
83
+ chart2.set_title(:name => 'Stacked Chart')
84
+ chart2.set_x_axis(:name => 'Test number')
85
+ chart2.set_y_axis(:name => 'Sample length (mm)')
86
+
87
+ # Set an Excel chart style. Blue colors with white outline and shadow.
88
+ chart2.set_style(12)
89
+
90
+ # Insert the chart into the worksheet (with an offset).
91
+ worksheet.insert_chart('D18', chart2, 25, 11)
92
+
93
+ #
94
+ # Create a filled chart sub-type
95
+ #
96
+ chart3 = workbook.add_chart(
97
+ :type => 'radar',
98
+ :embedded => 1,
99
+ :subtype => 'filled'
100
+ )
101
+
102
+ # Configure the first series.
103
+ chart3.add_series(
104
+ :name => '=Sheet1!$B$1',
105
+ :categories => '=Sheet1!$A$2:$A$7',
106
+ :values => '=Sheet1!$B$2:$B$7'
107
+ )
108
+
109
+ # Configure second series.
110
+ chart3.add_series(
111
+ :name => '=Sheet1!$C$1',
112
+ :categories => [ 'Sheet1', 1, 6, 0, 0 ],
113
+ :values => [ 'Sheet1', 1, 6, 2, 2 ]
114
+ )
115
+
116
+ # Add a chart title and some axis labels.
117
+ chart3.set_title(:name => 'Percent Stacked Chart')
118
+ chart3.set_x_axis(:name => 'Test number')
119
+ chart3.set_y_axis(:name => 'Sample length (mm)')
120
+
121
+ # Set an Excel chart style. Blue colors with white outline and shadow.
122
+ chart3.set_style(13)
123
+
124
+ # Insert the chart into the worksheet (with an offset).
125
+ worksheet.insert_chart('D34', chart3, 25, 11)
126
+
127
+ workbook.close
@@ -46,7 +46,7 @@ chart.set_legend(:position => 'right')
46
46
  # Add a chart title and some axis labels.
47
47
  chart.set_title(:name => 'Survey results')
48
48
  chart.set_x_axis(:name => 'Days')
49
- chart.set_y_axis(:name => 'Population', :major_gridlines => {:show => 0})
49
+ chart.set_y_axis(:name => 'Population', :major_gridlines => {:visible => 0})
50
50
  chart.set_y2_axis(:name => 'Laser wounds')
51
51
 
52
52
  # Insert the chart into the worksheet (with an offset).
@@ -25,6 +25,13 @@ module Writexlsx
25
25
  @subtype = subtype || 'standard'
26
26
  @cross_between = 'midCat'
27
27
  @show_crosses = false
28
+
29
+ # Override and reset the default axis values.
30
+ if @subtype == 'percent_stacked'
31
+ @y_axis[:_defaults][:num_format] = '0%'
32
+ end
33
+
34
+ set_y_axis
28
35
  end
29
36
 
30
37
  #
@@ -60,24 +67,6 @@ module Writexlsx
60
67
  write_axis_ids(params)
61
68
  end
62
69
  end
63
-
64
- #
65
- # Over-ridden to add % format. TODO. This will be refactored back up to the
66
- # SUPER class later.
67
- #
68
- # Write the <C:numFmt> element.
69
- #
70
- def write_number_format(format_code = nil)
71
- source_linked = 1
72
- format_code = 'General' if !format_code || format_code.empty?
73
- format_code = '0%' if @subtype == 'percent_stacked'
74
-
75
- attributes = [
76
- 'formatCode', format_code,
77
- 'sourceLinked', source_linked
78
- ]
79
- @writer.empty_tag('c:numFmt', attributes)
80
- end
81
70
  end
82
71
  end
83
72
  end
@@ -27,6 +27,25 @@ module Writexlsx
27
27
  @horiz_val_axis = 0
28
28
  @horiz_cat_axis = 1
29
29
  @show_crosses = false
30
+
31
+ # Override and reset the default axis values.
32
+ if @x_axis[:_defaults]
33
+ @x_axis[:_defaults][:major_gridlines] = { :visible => 1 }
34
+ else
35
+ @x_axis[:_defaults] = { :major_gridlines => { :visible => 1 } }
36
+ end
37
+ if @y_axis[:_defaults]
38
+ @y_axis[:_defaults][:major_gridlines] = { :visible => 0 }
39
+ else
40
+ @y_axis[:_defaults] = { :major_gridlines => { :visible => 0 } }
41
+ end
42
+
43
+ if @subtype == 'percent_stacked'
44
+ @x_axis[:_defaults][:num_format] = '0%'
45
+ end
46
+
47
+ set_x_axis
48
+ set_y_axis
30
49
  end
31
50
 
32
51
  #
@@ -34,11 +53,8 @@ module Writexlsx
34
53
  #
35
54
  def write_chart_type(params)
36
55
  if params[:primary_axes] != 0
37
- ## Reverse X and Y axes for Bar charts.
56
+ # Reverse X and Y axes for Bar charts.
38
57
  @y_axis, @x_axis = @x_axis, @y_axis
39
- if !@y_axis[:_major_gridlines]
40
- @y_axis[:_major_gridlines] = {:show => 1}
41
- end
42
58
  if @y2_axis[:_position] == 'r'
43
59
  @y2_axis[:_position] = 't'
44
60
  end
@@ -58,25 +74,6 @@ module Writexlsx
58
74
 
59
75
  @writer.empty_tag('c:barDir', attributes)
60
76
  end
61
-
62
- #
63
- # Over-ridden to add % format. TODO. This will be refactored back up to the
64
- # SUPER class later.
65
- #
66
- # Write the <c:numFmt> element.
67
- #
68
- def write_number_format(format_code = 'General')
69
- source_linked = 1
70
-
71
- format_code = '0%' if @subtype == 'percent_stacked'
72
-
73
- attributes = [
74
- 'formatCode', format_code,
75
- 'sourceLinked', source_linked
76
- ]
77
-
78
- @writer.empty_tag('c:numFmt', attributes)
79
- end
80
77
  end
81
78
  end
82
79
  end
@@ -32,6 +32,13 @@ module Writexlsx
32
32
  super(subtype)
33
33
  @subtype = subtype || 'clustered'
34
34
  @horiz_val_axis = 0
35
+
36
+ # Override and reset the default axis values.
37
+ if @subtype == 'percent_stacked'
38
+ @y_axis[:_defaults][:num_format] = '0%'
39
+ end
40
+
41
+ set_y_axis
35
42
  end
36
43
 
37
44
  #
@@ -52,26 +59,6 @@ module Writexlsx
52
59
 
53
60
  @writer.empty_tag('c:barDir', attributes)
54
61
  end
55
-
56
- #
57
- # Over-ridden to add % format. TODO. This will be refactored back up to the
58
- # SUPER class later.
59
- #
60
- # Write the <c:numFmt> element.
61
- #
62
- def write_number_format(format_code = nil)
63
- format_code ||= 'General'
64
- source_linked = 1
65
-
66
- format_code = '0%' if @subtype == 'percent_stacked'
67
-
68
- attributes = [
69
- 'formatCode', format_code,
70
- 'sourceLinked', source_linked
71
- ]
72
-
73
- @writer.empty_tag('c:numFmt', attributes)
74
- end
75
62
  end
76
63
  end
77
64
  end
@@ -0,0 +1,94 @@
1
+ # -*- coding: utf-8 -*-
2
+ ###############################################################################
3
+ #
4
+ # Radar - A class for writing Excel Radar charts.
5
+ #
6
+ # Used in conjunction with Chart.
7
+ #
8
+ # See formatting note in Chart.
9
+ #
10
+ # Copyright 2000-2012, John McNamara, jmcnamara@cpan.org
11
+ # Convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
12
+ #
13
+
14
+ require 'write_xlsx/package/xml_writer_simple'
15
+ require 'write_xlsx/utility'
16
+
17
+ module Writexlsx
18
+ class Chart
19
+ # The Column chart module also supports the following sub-types:
20
+ #
21
+ # stacked
22
+ # percent_stacked
23
+ # These can be specified at creation time via the add_chart() Worksheet
24
+ # method:
25
+ #
26
+ # chart = workbook.add_chart( :type => 'column', :subtype => 'stacked' )
27
+ #
28
+ class Radar < self
29
+ include Writexlsx::Utility
30
+
31
+ def initialize(subtype)
32
+ super(subtype)
33
+ @subtype = subtype || 'marker'
34
+ if @subtype == 'marker'
35
+ @default_marker = { :type => 'none' }
36
+ end
37
+
38
+ # Override and reset the default axis values.
39
+ @x_axis[:_defaults][:major_gridlines] = { :visible => 1 }
40
+ set_x_axis
41
+
42
+ # Hardcode major_tick_mark for now untill there is an accessor.
43
+ @y_axis[:_major_tick_mark] = 'cross'
44
+ end
45
+
46
+ #
47
+ # Override the virtual superclass method with a chart specific method.
48
+ #
49
+ def write_chart_type(params)
50
+ # Write the c:radarChart element.
51
+ write_radar_chart(params)
52
+ end
53
+
54
+ #
55
+ # Write the <c:radarChart> element.
56
+ #
57
+ def write_radar_chart(params)
58
+ if ptrue?(params[:primary_axes])
59
+ series = get_primary_axes_series
60
+ else
61
+ series = get_secondary_axes_series
62
+ end
63
+
64
+ return if series.empty?
65
+
66
+ @writer.tag_elements('c:radarChart') do
67
+ # Write the c:radarStyle element.
68
+ write_radar_style
69
+
70
+ # Write the series elements.
71
+ series.each { |s| write_series(s) }
72
+
73
+ # Write the c:axId elements
74
+ write_axis_ids(params)
75
+ end
76
+ end
77
+
78
+ #
79
+ # Write the <c:radarStyle> element.
80
+ #
81
+ def write_radar_style
82
+ val = 'marker'
83
+
84
+ if @subtype == 'filled'
85
+ val = 'filled'
86
+ end
87
+
88
+ attributes = ['val', val]
89
+
90
+ @writer.empty_tag('c:radarStyle', attributes)
91
+ end
92
+ end
93
+ end
94
+ end
@@ -27,6 +27,12 @@ module Writexlsx
27
27
  def initialize(subtype)
28
28
  super(subtype)
29
29
  @show_crosses = false
30
+
31
+ # Override and reset the default axis values.
32
+ @x_axis[:_defaults][:num_format] = 'dd/mm/yyyy'
33
+ @x2_axis[:_defaults][:num_format] = 'dd/mm/yyyy'
34
+ set_x_axis
35
+ set_x2_axis
30
36
  end
31
37
 
32
38
  #