axlsx 1.1.3 → 1.1.4

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 (79) hide show
  1. data/CHANGELOG.md +21 -0
  2. data/LICENSE +1 -1
  3. data/README.md +38 -415
  4. data/examples/#extractive.csv# +0 -0
  5. data/examples/#extractive.rb# +45 -0
  6. data/examples/chart_colors.rb +73 -0
  7. data/examples/chart_colors.rb~ +0 -0
  8. data/examples/chart_colors.xlsx +0 -0
  9. data/examples/colored_series_data.xlsx +0 -0
  10. data/examples/conditional_formatting/getting_barred.xlsx +0 -0
  11. data/examples/example.rb +174 -113
  12. data/examples/example.xlsx +0 -0
  13. data/examples/example_streamed.xlsx +0 -0
  14. data/examples/extractive.csv +1 -0
  15. data/examples/extractive.csv~ +1 -0
  16. data/examples/extractive.rb +42 -0
  17. data/examples/extractive.rb~ +3 -0
  18. data/examples/extractive.xlsx +0 -0
  19. data/examples/no-use_autowidth.xlsx +0 -0
  20. data/examples/shared_strings_example.xlsx +0 -0
  21. data/examples/stack.rb +21 -0
  22. data/examples/stack.rb~ +27 -0
  23. data/examples/stack.xlsx +0 -0
  24. data/examples/~$chart_colors.xlsx +0 -0
  25. data/examples/~$extractive.xlsx +0 -0
  26. data/lib/axlsx/drawing/ax_data_source.rb +25 -0
  27. data/lib/axlsx/drawing/ax_data_source.rb~ +55 -0
  28. data/lib/axlsx/drawing/axis.rb +12 -3
  29. data/lib/axlsx/drawing/bar_series.rb +23 -6
  30. data/lib/axlsx/drawing/cat_axis.rb +24 -0
  31. data/lib/axlsx/drawing/chart.rb +7 -5
  32. data/lib/axlsx/drawing/data_source.rb~ +51 -0
  33. data/lib/axlsx/drawing/drawing.rb +8 -4
  34. data/lib/axlsx/drawing/line_series.rb +20 -4
  35. data/lib/axlsx/drawing/num_data.rb +52 -0
  36. data/lib/axlsx/drawing/num_data.rb~ +51 -0
  37. data/lib/axlsx/drawing/num_data_source.rb +58 -0
  38. data/lib/axlsx/drawing/num_data_source.rb~ +54 -0
  39. data/lib/axlsx/drawing/num_val.rb +32 -0
  40. data/lib/axlsx/drawing/num_val.rb~ +40 -0
  41. data/lib/axlsx/drawing/pie_series.rb +18 -4
  42. data/lib/axlsx/drawing/ref.rb~ +41 -0
  43. data/lib/axlsx/drawing/scatter_series.rb +28 -2
  44. data/lib/axlsx/drawing/ser_axis.rb +1 -1
  45. data/lib/axlsx/drawing/series.rb +1 -1
  46. data/lib/axlsx/drawing/str_data.rb +42 -0
  47. data/lib/axlsx/drawing/str_data.rb~ +58 -0
  48. data/lib/axlsx/drawing/str_val.rb +33 -0
  49. data/lib/axlsx/drawing/str_val.rb~ +35 -0
  50. data/lib/axlsx/drawing/view_3D.rb +6 -3
  51. data/lib/axlsx/util/validators.rb +1 -1
  52. data/lib/axlsx/version.rb +1 -1
  53. data/lib/axlsx/workbook/worksheet/col.rb +2 -1
  54. data/lib/axlsx/workbook/worksheet/row.rb +44 -5
  55. data/lib/axlsx/workbook/worksheet/table.rb +1 -1
  56. data/test/drawing/tc_bar_series.rb +18 -13
  57. data/test/drawing/tc_cat_axis_data.rb +23 -13
  58. data/test/drawing/tc_chart.rb +0 -2
  59. data/test/drawing/tc_data_source.rb +17 -0
  60. data/test/drawing/tc_data_source.rb~ +30 -0
  61. data/test/drawing/tc_line_series.rb +3 -9
  62. data/test/drawing/tc_named_axis_data.rb +27 -0
  63. data/test/drawing/tc_num_data.rb +27 -0
  64. data/test/drawing/tc_num_data.rb~ +35 -0
  65. data/test/drawing/tc_num_val.rb +29 -0
  66. data/test/drawing/tc_num_val.rb~ +29 -0
  67. data/test/drawing/tc_pie_series.rb +4 -11
  68. data/test/drawing/tc_scatter_series.rb +6 -5
  69. data/test/drawing/tc_str_data.rb +18 -0
  70. data/test/drawing/tc_str_data.rb~ +30 -0
  71. data/test/drawing/tc_str_val.rb +21 -0
  72. data/test/drawing/tc_str_val.rb~ +26 -0
  73. data/test/drawing/tc_two_cell_anchor.rb +1 -1
  74. data/test/workbook/worksheet/tc_row.rb +6 -0
  75. metadata +65 -13
  76. data/lib/axlsx/drawing/cat_axis_data.rb +0 -34
  77. data/lib/axlsx/drawing/named_axis_data.rb +0 -36
  78. data/lib/axlsx/drawing/val_axis_data.rb +0 -27
  79. data/test/drawing/tc_val_axis_data.rb +0 -17
Binary file
@@ -0,0 +1 @@
1
+ :'oil-bbl' => 9591.411671,8860.714604,8237.936509,7700.523067,7231.831842,6819.307902,6453.297235,6126.251755,5832.182748,5566.276532,5324.618706,5103.992757,4901.730597,4715.600022,4543.718862,4384.488699,4236.543136,4098.707009,3969.963937,3849.430276,3736.33405,3629.997786,3529.824424,3435.28568,3345.912388,3261.286414,3181.033882,3104.819438,3032.341401,2963.327615,2897.531915,2834.731083,2774.722219,2717.320479,2662.357097,2609.677666,2559.140642,2510.616021,2463.984182,2419.134871,2375.966292,2334.384311,2294.301748,2255.637735,2218.317165,2182.270173,2147.431696,2113.741056,2081.141602,2049.580377,2019.007821,1989.377502,1960.645871,1932.772042,1905.71759,1879.446367,1853.924338,1829.119424,1805.001366,1781.541597,1758.713122,1736.490414,1714.849315,1693.766943,1673.22161,1653.192744,1633.660817,1614.607284,1596.014514,1577.865741,1560.145009,1542.837121,1525.927597,1509.402632,1493.249056,1477.454298,1462.006352,1446.893746,1432.105512,1417.631159,1403.460647,1389.584361,1375.993094,1362.678018,1349.630672,1336.842938,1324.307026,1312.015455,1299.961043,1288.136885,1276.536347,1265.153047,1253.980847,1243.013838,1232.246332,1221.672852,1211.288119,1201.087047,1191.064732,1181.216443,1171.537618,1162.023853,1152.670896,1143.474642,1134.431125,1125.536513,1116.787101,1108.179309,1099.709672,1091.37484,1083.171571,1075.096725,1067.147265,1059.320247,1051.612821,1044.022223,1036.545778,1029.180889,1021.92504,1014.775789
@@ -0,0 +1 @@
1
+ oil-bbl,9591.411671,8860.714604,8237.936509,7700.523067,7231.831842,6819.307902,6453.297235,6126.251755,5832.182748,5566.276532,5324.618706,5103.992757,4901.730597,4715.600022,4543.718862,4384.488699,4236.543136,4098.707009,3969.963937,3849.430276,3736.33405,3629.997786,3529.824424,3435.28568,3345.912388,3261.286414,3181.033882,3104.819438,3032.341401,2963.327615,2897.531915,2834.731083,2774.722219,2717.320479,2662.357097,2609.677666,2559.140642,2510.616021,2463.984182,2419.134871,2375.966292,2334.384311,2294.301748,2255.637735,2218.317165,2182.270173,2147.431696,2113.741056,2081.141602,2049.580377,2019.007821,1989.377502,1960.645871,1932.772042,1905.71759,1879.446367,1853.924338,1829.119424,1805.001366,1781.541597,1758.713122,1736.490414,1714.849315,1693.766943,1673.22161,1653.192744,1633.660817,1614.607284,1596.014514,1577.865741,1560.145009,1542.837121,1525.927597,1509.402632,1493.249056,1477.454298,1462.006352,1446.893746,1432.105512,1417.631159,1403.460647,1389.584361,1375.993094,1362.678018,1349.630672,1336.842938,1324.307026,1312.015455,1299.961043,1288.136885,1276.536347,1265.153047,1253.980847,1243.013838,1232.246332,1221.672852,1211.288119,1201.087047,1191.064732,1181.216443,1171.537618,1162.023853,1152.670896,1143.474642,1134.431125,1125.536513,1116.787101,1108.179309,1099.709672,1091.37484,1083.171571,1075.096725,1067.147265,1059.320247,1051.612821,1044.022223,1036.545778,1029.180889,1021.92504,1014.775789
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby -w -s
2
+ # -*- coding: utf-8 -*-
3
+
4
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
5
+ require 'axlsx'
6
+
7
+ data = [ ['oil-bbl',9591.411671,8860.714604,8237.936509,7700.523067,7231.831842,6819.307902,6453.297235,6126.251755,5832.182748,5566.276532,5324.618706,5103.992757,4901.730597,4715.600022,4543.718862,4384.488699,4236.543136,4098.707009,3969.963937,3849.430276,3736.33405,3629.997786,3529.824424,3435.28568,3345.912388,3261.286414,3181.033882,3104.819438,3032.341401,2963.327615,2897.531915,2834.731083,2774.722219,2717.320479,2662.357097,2609.677666,2559.140642,2510.616021,2463.984182,2419.134871,2375.966292,2334.384311,2294.301748,2255.637735,2218.317165,2182.270173,2147.431696,2113.741056,2081.141602,2049.580377,2019.007821,1989.377502,1960.645871,1932.772042,1905.71759,1879.446367,1853.924338,1829.119424,1805.001366,1781.541597,1758.713122,1736.490414,1714.849315,1693.766943,1673.22161,1653.192744,1633.660817,1614.607284,1596.014514,1577.865741,1560.145009,1542.837121,1525.927597,1509.402632,1493.249056,1477.454298,1462.006352,1446.893746,1432.105512,1417.631159,1403.460647,1389.584361,1375.993094,1362.678018,1349.630672,1336.842938,1324.307026,1312.015455,1299.961043,1288.136885,1276.536347,1265.153047,1253.980847,1243.013838,1232.246332,1221.672852,1211.288119,1201.087047,1191.064732,1181.216443,1171.537618,1162.023853,1152.670896,1143.474642,1134.431125,1125.536513,1116.787101,1108.179309,1099.709672,1091.37484,1083.171571,1075.096725,1067.147265,1059.320247,1051.612821,1044.022223,1036.545778,1029.180889,1021.92504,1014.775789],
8
+
9
+ ['gas-mcf', 940970.153,836556.732,748476.939,673307.64,608520.158,552204.935,502892.3,459432.263,420911.806,386596.658,355889.491,328299.357,303418.988,280907.679,260478.232,241886.857,224925.287,209414.552,195200.029,182147.455,170139.707,159074.174,148860.596,139419.282,130679.626,122578.864,115061.035,108076.1,101579.19,95529.972,89892.104,84632.762,79722.24,75133.597,70842.349,66826.213,63064.865,59539.742,56233.86,53131.662,50218.869,47482.365,44910.082,42490.907,40214.588,38071.662,36053.382,34151.656,32358.989,30668.434,29073.545,27568.334,26147.237,24805.079,23537.041,22338.633,21205.67,20134.246,19120.717,18161.677,17253.941,16394.533,15580.663,14809.724,14079.269,13387.006,12730.786,12108.59,11518.524,10958.809,10427.774,9923.847,9445.55,8991.492,8560.364,8150.934,7762.041,7392.59,7041.551,6707.951,6390.874,6089.452,5802.871,5530.358,5271.185,5024.664,4790.145,4567.013,4354.687,4152.618,3960.286,3777.198,3602.889,3436.919,3278.87,3128.347,2984.976,2848.401,2718.287,2594.316,2476.184,2363.606,2256.309,2154.037,2056.545,1963.599,1874.982,1790.482,1709.903,1633.054,1559.758,1489.844,1423.151,1359.525,1298.821,1240.899,1185.628,1132.883,1082.544,1034.499],
10
+
11
+ ['water-bbl',940.97,836.557,748.477,673.308,608.52,552.205,502.892,459.432,420.912,386.597,355.889,328.299,303.419,280.908,260.478,241.887,224.925,209.415,195.2,182.147,170.14,159.074,148.861,139.419,130.68,122.579,115.061,108.076,101.579,95.53,89.892,84.633,79.722,75.134,70.842,66.826,63.065,59.54,56.234,53.132,50.219,47.482,44.91,42.491,40.215,38.072,36.053,34.152,32.359,30.668,29.074,27.568,26.147,24.805,23.537,22.339,21.206,20.134,19.121,18.162,17.254,16.395,15.581,14.81,14.079,13.387,12.731,12.109,11.519,10.959,10.428,9.924,9.446,8.991,8.56,8.151,7.762,7.393,7.042,6.708,6.391,6.089,5.803,5.53,5.271,5.025,4.79,4.567,4.355,4.153,3.96,3.777,3.603,3.437,3.279,3.128,2.985,2.848,2.718,2.594,2.476,2.364,2.256,2.154,2.057,1.964,1.875,1.79,1.71,1.633,1.56,1.49,1.423,1.36,1.299,1.241,1.186,1.133,1.083,1.034] ]
12
+
13
+ p = Axlsx::Package.new
14
+ wb = p.workbook
15
+ wb.add_worksheet(:name => 'volumes') do |ws|
16
+ # perspective, rotX and rotY flatten the 3D chart
17
+ # hPercent sets the chart height to 100%
18
+ chart = ws.add_chart(Axlsx::Line3DChart, :perspective => 0, :hPercent => 100, :rotX => 0, :rotY => 0, :start_at => "A4", :end_at => 'M44', :title => 'Monthly forcast for Type Curve Gas secondary - gross ngl')
19
+
20
+ # Set up log based scaling and appropriate min/max values for Y axis
21
+ chart.valAxis.scaling.logBase = 10
22
+ chart.valAxis.scaling.min = 0.1
23
+ chart.valAxis.scaling.max = 10000000.0
24
+
25
+ # No poing in showing the series axis labels as the chart is flattened!
26
+ chart.serAxis.delete = true
27
+
28
+ # Knock the catAxis labels down to the forced min.
29
+ chart.catAxis.crosses = :min
30
+ # set up cat labels / markes to show every 12th item
31
+ chart.catAxis.tickLblSkip = 12
32
+ chart.catAxis.tickMarkSkip = 12
33
+
34
+ #rgb colors for our data series
35
+ colors = ['00FF00', 'FF0000', '0000FF']
36
+ data.each_with_index do |value, index|
37
+ ws.add_row value
38
+ chart.add_series :data => ws.rows.last.cells[(1..value.size-1)], :labels => (0..value.size).map{ |i| i }, :title => ws.rows.last.cells.first, :color => colors[index]
39
+ end
40
+ end
41
+
42
+ p.serialize 'extractive.xlsx'
@@ -0,0 +1,3 @@
1
+ data = {:'oil-bbl' => [9591.411671,8860.714604,8237.936509,7700.523067,7231.831842,6819.307902,6453.297235,6126.251755,5832.182748,5566.276532,5324.618706,5103.992757,4901.730597,4715.600022,4543.718862,4384.488699,4236.543136,4098.707009,3969.963937,3849.430276,3736.33405,3629.997786,3529.824424,3435.28568,3345.912388,3261.286414,3181.033882,3104.819438,3032.341401,2963.327615,2897.531915,2834.731083,2774.722219,2717.320479,2662.357097,2609.677666,2559.140642,2510.616021,2463.984182,2419.134871,2375.966292,2334.384311,2294.301748,2255.637735,2218.317165,2182.270173,2147.431696,2113.741056,2081.141602,2049.580377,2019.007821,1989.377502,1960.645871,1932.772042,1905.71759,1879.446367,1853.924338,1829.119424,1805.001366,1781.541597,1758.713122,1736.490414,1714.849315,1693.766943,1673.22161,1653.192744,1633.660817,1614.607284,1596.014514,1577.865741,1560.145009,1542.837121,1525.927597,1509.402632,1493.249056,1477.454298,1462.006352,1446.893746,1432.105512,1417.631159,1403.460647,1389.584361,1375.993094,1362.678018,1349.630672,1336.842938,1324.307026,1312.015455,1299.961043,1288.136885,1276.536347,1265.153047,1253.980847,1243.013838,1232.246332,1221.672852,1211.288119,1201.087047,1191.064732,1181.216443,1171.537618,1162.023853,1152.670896,1143.474642,1134.431125,1125.536513,1116.787101,1108.179309,1099.709672,1091.37484,1083.171571,1075.096725,1067.147265,1059.320247,1051.612821,1044.022223,1036.545778,1029.180889,1021.92504,1014.775789]
2
+ :'gas-mcf' => [940970.153,836556.732,748476.939,673307.64,608520.158,552204.935,502892.3,459432.263,420911.806,386596.658,355889.491,328299.357,303418.988,280907.679,260478.232,241886.857,224925.287,209414.552,195200.029,182147.455,170139.707,159074.174,148860.596,139419.282,130679.626,122578.864,115061.035,108076.1,101579.19,95529.972,89892.104,84632.762,79722.24,75133.597,70842.349,66826.213,63064.865,59539.742,56233.86,53131.662,50218.869,47482.365,44910.082,42490.907,40214.588,38071.662,36053.382,34151.656,32358.989,30668.434,29073.545,27568.334,26147.237,24805.079,23537.041,22338.633,21205.67,20134.246,19120.717,18161.677,17253.941,16394.533,15580.663,14809.724,14079.269,13387.006,12730.786,12108.59,11518.524,10958.809,10427.774,9923.847,9445.55,8991.492,8560.364,8150.934,7762.041,7392.59,7041.551,6707.951,6390.874,6089.452,5802.871,5530.358,5271.185,5024.664,4790.145,4567.013,4354.687,4152.618,3960.286,3777.198,3602.889,3436.919,3278.87,3128.347,2984.976,2848.401,2718.287,2594.316,2476.184,2363.606,2256.309,2154.037,2056.545,1963.599,1874.982,1790.482,1709.903,1633.054,1559.758,1489.844,1423.151,1359.525,1298.821,1240.899,1185.628,1132.883,1082.544,1034.499]
3
+ :'water-bbl' => [940.97,836.557,748.477,673.308,608.52,552.205,502.892,459.432,420.912,386.597,355.889,328.299,303.419,280.908,260.478,241.887,224.925,209.415,195.2,182.147,170.14,159.074,148.861,139.419,130.68,122.579,115.061,108.076,101.579,95.53,89.892,84.633,79.722,75.134,70.842,66.826,63.065,59.54,56.234,53.132,50.219,47.482,44.91,42.491,40.215,38.072,36.053,34.152,32.359,30.668,29.074,27.568,26.147,24.805,23.537,22.339,21.206,20.134,19.121,18.162,17.254,16.395,15.581,14.81,14.079,13.387,12.731,12.109,11.519,10.959,10.428,9.924,9.446,8.991,8.56,8.151,7.762,7.393,7.042,6.708,6.391,6.089,5.803,5.53,5.271,5.025,4.79,4.567,4.355,4.153,3.96,3.777,3.603,3.437,3.279,3.128,2.985,2.848,2.718,2.594,2.476,2.364,2.256,2.154,2.057,1.964,1.875,1.79,1.71,1.633,1.56,1.49,1.423,1.36,1.299,1.241,1.186,1.133,1.083,1.034]}
Binary file
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby -w -s
2
+ # -*- coding: utf-8 -*-
3
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
4
+ require 'axlsx'
5
+
6
+ Axlsx::Worksheet.class_eval do
7
+ def add_row_with_position(values = [], options = {})
8
+ values = Array.new(options[:start_at] || 0) + values
9
+ add_row(values, options)
10
+ end
11
+ end
12
+
13
+ p = Axlsx::Package.new
14
+ wb = p.workbook
15
+ wb.add_worksheet do |ws|
16
+ ws.add_row_with_position [1,2,3,4,5]
17
+ ws.add_row_with_position [1,2,3,4,5], :start_at => 5
18
+
19
+ end
20
+ p.validate.each { |e| puts e.message }
21
+ p.serialize("stack.xlsx")
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby -w -s
2
+ # -*- coding: utf-8 -*-
3
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
4
+ require 'axlsx'
5
+
6
+ Axlsx::Worksheet.class_eval do
7
+ def add_row_with_position(values = [], options = {})
8
+ if options.try(:[], :start_at).present?
9
+ val = []
10
+ options[:start_at].times { val.push nil}
11
+ options.delete(:start_at)
12
+ values = val + values
13
+ end
14
+ add_row_without_position(values, options)
15
+ end
16
+ alias_method_chain :add_row, :add_row_without_position
17
+ end
18
+
19
+
20
+
21
+ p = Axlsx::Package.new
22
+ wb = p.workbook
23
+ wb.add_worksheet do |ws|
24
+ ws.add_row_with_position([1,2,3,4,5], :start_at => 5)
25
+ end
26
+ p.validate.each { |e| puts e.message }
27
+ p.serialize("no-use_autowidth.xlsx")
Binary file
@@ -0,0 +1,25 @@
1
+ module Axlsx
2
+ # An axis data source that can contain referenced or literal strings or numbers
3
+ # @note only string data types are supported - mainly because we have not implemented a chart type that requires a numerical axis value
4
+ class AxDataSource < NumDataSource
5
+
6
+ # allowed element tag names
7
+ # @return [Array]
8
+ def self.allowed_tag_names
9
+ [:xVal, :cat]
10
+ end
11
+
12
+ # creates a new NumDataSource object
13
+ # @option options [Array] data An array of Cells or Numeric objects
14
+ # @option options [Symbol] tag_name see tag_name
15
+ def initialize(options={})
16
+ @tag_name = :cat
17
+ @data_type = StrData
18
+ @ref_tag_name = :strRef
19
+ super(options)
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+
@@ -0,0 +1,55 @@
1
+ module Axlsx
2
+ # An axis data source that can contain referenced or literal strings or numbers
3
+ # @note only string data types are supported - mainly because we have not implemented a chart type that requires a numerical axis value
4
+ class AxDataSource
5
+
6
+ # The tag name to use when serializing this data source.
7
+ # Only items defined in allowed_tag_names are allowed
8
+ # @return [Symbol]
9
+ attr_reader :tag_name
10
+
11
+ attr_reader :data
12
+
13
+ # allowed element tag names
14
+ # @return [Array]
15
+ def self.allowed_tag_names
16
+ [:xVal, :cat]
17
+ end
18
+
19
+ # creates a new NumDataSource object
20
+ # @option options [Array] data An array of Cells or Numeric objects
21
+ # @option options [Symbol] tag_name see tag_name
22
+ def initialize(options={})
23
+ @f = nil
24
+ @tag_name = :cat
25
+ @data = StrData.new(options)
26
+ if options[:data] && options[:data].first.is_a?(Cell)
27
+ @f = Axlsx::cell_range(options[:data])
28
+ end
29
+ options.each do |o|
30
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
31
+ end
32
+ end
33
+
34
+ # sets the tag name for this data source
35
+ # @param [Symbol] One of the allowed_tag_names
36
+ def tag_name=(v)
37
+ Axlsx::RestrictionValidator.validate "#{self.class.name}.tag_name", self.class.allowed_tag_names, v
38
+ @tag_name = v
39
+ end
40
+
41
+ def to_xml_string(str="")
42
+ str << '<c:' << tag_name.to_s << '>'
43
+ if @f
44
+ str << '<c:strRef>'
45
+ str << '<c:f>' << @f.to_s << '</c:f>'
46
+ end
47
+ @data.to_xml_string str
48
+ if @f
49
+ str << '</c:strRef>'
50
+ end
51
+ str << '</c:' << tag_name.to_s << '>'
52
+ end
53
+ end
54
+ end
55
+
@@ -44,6 +44,10 @@ module Axlsx
44
44
  # @return [Boolean]
45
45
  attr_reader :gridlines
46
46
 
47
+ # specifies if gridlines should be shown in the chart
48
+ # @return [Boolean]
49
+ attr_reader :delete
50
+
47
51
  # Creates an Axis object
48
52
  # @param [Integer] axId the id of this axis
49
53
  # @param [Integer] crossAx the id of the perpendicular axis
@@ -57,7 +61,7 @@ module Axlsx
57
61
  @axId = axId
58
62
  @crossAx = crossAx
59
63
  @format_code = "General"
60
- @label_rotation = 0
64
+ @delete = @label_rotation = 0
61
65
  @scaling = Scaling.new(:orientation=>:minMax)
62
66
  self.axPos = :b
63
67
  self.tickLblPos = :nextTo
@@ -84,6 +88,11 @@ module Axlsx
84
88
  # default true
85
89
  def gridlines=(v) Axlsx::validate_boolean(v); @gridlines = v; end
86
90
 
91
+
92
+ # Specify if axis should be removed from the chart
93
+ # default false
94
+ def delete=(v) Axlsx::validate_boolean(v); @delete = v; end
95
+
87
96
  # specifies how the perpendicular axis is crossed
88
97
  # must be one of [:autoZero, :min, :max]
89
98
  def crosses=(v) RestrictionValidator.validate "#{self.class}.crosses", [:autoZero, :min, :max], v; @crosses = v; end
@@ -104,7 +113,7 @@ module Axlsx
104
113
  def to_xml_string(str = '')
105
114
  str << '<c:axId val="' << @axId.to_s << '"/>'
106
115
  @scaling.to_xml_string str
107
- str << '<c:delete val="0"/>'
116
+ str << '<c:delete val="'<< @delete.to_s << '"/>'
108
117
  str << '<c:axPos val="' << @axPos.to_s << '"/>'
109
118
  str << '<c:majorGridlines>'
110
119
  if self.gridlines == false
@@ -120,7 +129,7 @@ module Axlsx
120
129
  str << '<c:minorTickMark val="none"/>'
121
130
  str << '<c:tickLblPos val="' << @tickLblPos.to_s << '"/>'
122
131
  # some potential value in implementing this in full. Very detailed!
123
- str << "<c:txPr><a:bodyPr rot='#{@label_rotation}'/><a:lstStyle/><a:p><a:pPr><a:defRPr/></a:pPr><a:endParaRPr/></a:p></c:txPr>"
132
+ str << '<c:txPr><a:bodyPr rot="' << @label_rotation.to_s << '"/><a:lstStyle/><a:p><a:pPr><a:defRPr/></a:pPr><a:endParaRPr/></a:p></c:txPr>'
124
133
  str << '<c:crossAx val="' << @crossAx.to_s << '"/>'
125
134
  str << '<c:crosses val="' << @crosses.to_s << '"/>'
126
135
  end
@@ -8,7 +8,7 @@ module Axlsx
8
8
 
9
9
 
10
10
  # The data for this series.
11
- # @return [Array, SimpleTypedList]
11
+ # @return [NumDataSource]
12
12
  attr_reader :data
13
13
 
14
14
  # The labels for this series.
@@ -20,19 +20,27 @@ module Axlsx
20
20
  # @return [Symbol]
21
21
  attr_reader :shape
22
22
 
23
+ # An array of rgb colors to apply to your bar chart.
24
+ attr_reader :colors
25
+
23
26
  # Creates a new series
24
27
  # @option options [Array, SimpleTypedList] data
25
28
  # @option options [Array, SimpleTypedList] labels
26
29
  # @option options [String] title
27
30
  # @option options [String] shape
31
+ # @option options [String] colors an array of colors to use when rendering each data point
28
32
  # @param [Chart] chart
29
33
  def initialize(chart, options={})
30
34
  @shape = :box
35
+ @colors = []
31
36
  super(chart, options)
32
- self.labels = CatAxisData.new(options[:labels]) unless options[:labels].nil?
33
- self.data = ValAxisData.new(options[:data]) unless options[:data].nil?
37
+ self.labels = AxDataSource.new({:data => options[:labels]}) unless options[:labels].nil?
38
+ self.data = NumDataSource.new(options) unless options[:data].nil?
34
39
  end
35
40
 
41
+ # @see colors
42
+ def colors=(v) DataTypeValidator.validate "BarSeries.colors", [Array], v; @colors = v end
43
+
36
44
  # The shabe of the bars or columns
37
45
  # must be one of [:percentStacked, :clustered, :standard, :stacked]
38
46
  def shape=(v)
@@ -45,19 +53,28 @@ module Axlsx
45
53
  # @return [String]
46
54
  def to_xml_string(str = '')
47
55
  super(str) do |str_inner|
56
+
57
+ colors.each_with_index do |c, index|
58
+ str_inner << '<c:dPt>'
59
+ str_inner << '<c:idx val="' << index.to_s << '"/>'
60
+ str_inner << '<c:spPr><a:solidFill>'
61
+ str_inner << '<a:srgbClr val="' << c << '"/>'
62
+ str_inner << '</a:solidFill></c:spPr></c:dPt>'
63
+ end
64
+
48
65
  @labels.to_xml_string(str_inner) unless @labels.nil?
49
66
  @data.to_xml_string(str_inner) unless @data.nil?
50
- str_inner << '<shape val="' << @shape.to_s << '"/>'
67
+ str_inner << '<c:shape val="' << shape.to_s << '"></c:shape>'
51
68
  end
52
69
  end
53
70
 
54
71
  private
55
72
 
56
73
  # assigns the data for this series
57
- def data=(v) DataTypeValidator.validate "Series.data", [SimpleTypedList], v; @data = v; end
74
+ def data=(v) DataTypeValidator.validate "Series.data", [NumDataSource], v; @data = v; end
58
75
 
59
76
  # assigns the labels for this series
60
- def labels=(v) DataTypeValidator.validate "Series.labels", [SimpleTypedList], v; @labels = v; end
77
+ def labels=(v) DataTypeValidator.validate "Series.labels", [AxDataSource], v; @labels = v; end
61
78
 
62
79
  end
63
80
 
@@ -17,6 +17,16 @@ module Axlsx
17
17
  # @return [Integer]
18
18
  attr_reader :lblOffset
19
19
 
20
+
21
+ # The number of tick lables to skip between labels
22
+ # @return [Integer]
23
+ attr_reader :tickLblSkip
24
+
25
+ # The number of tickmarks to be skipped before the next one is rendered.
26
+ # @return [Boolean]
27
+ attr_reader :tickMarkSkip
28
+
29
+
20
30
  # regex for validating label offset
21
31
  LBL_OFFSET_REGEX = /0*(([0-9])|([1-9][0-9])|([1-9][0-9][0-9])|1000)%/
22
32
 
@@ -29,13 +39,25 @@ module Axlsx
29
39
  # @option options [Boolean] auto
30
40
  # @option options [Symbol] lblAlgn
31
41
  # @option options [Integer] lblOffset
42
+ # @option options [Integer] tickLblSkip
43
+ # @option options [Integer] tickMarkSkip
32
44
  def initialize(axId, crossAx, options={})
45
+ @tickLblSkip = 1
46
+ @tickMarkSkip = 1
33
47
  self.auto = 1
34
48
  self.lblAlgn = :ctr
35
49
  self.lblOffset = "100%"
36
50
  super(axId, crossAx, options)
37
51
  end
38
52
 
53
+
54
+ # @see tickLblSkip
55
+ def tickLblSkip=(v) Axlsx::validate_unsigned_int(v); @tickLblSkip = v; end
56
+
57
+ # @see tickMarkSkip
58
+ def tickMarkSkip=(v) Axlsx::validate_unsigned_int(v); @tickMarkSkip = v; end
59
+
60
+
39
61
  # 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.
40
62
  def auto=(v) Axlsx::validate_boolean(v); @auto = v; end
41
63
 
@@ -56,6 +78,8 @@ module Axlsx
56
78
  str << '<c:auto val="' << @auto.to_s << '"/>'
57
79
  str << '<c:lblAlgn val="' << @lblAlgn.to_s << '"/>'
58
80
  str << '<c:lblOffset val="' << @lblOffset.to_s << '"/>'
81
+ str << '<c:tickLblSkip val="' << @tickLblSkip.to_s << '"/>'
82
+ str << '<c:tickMarkSkip val="' << @tickMarkSkip.to_s << '"/>'
59
83
  str << '</c:catAx>'
60
84
  end
61
85
 
@@ -41,6 +41,8 @@ module Axlsx
41
41
  # @param [GraphicalFrame] frame The frame that holds this chart.
42
42
  # @option options [Cell, String] title
43
43
  # @option options [Boolean] show_legend
44
+ # @option options [Array|String|Cell] start_at The X, Y coordinates defining the top left corner of the chart.
45
+ # @option options [Array|String|Cell] end_at The X, Y coordinates defining the bottom right corner of the chart.
44
46
  def initialize(frame, options={})
45
47
  @style = 2
46
48
  @view3D = nil
@@ -54,7 +56,7 @@ module Axlsx
54
56
  self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
55
57
  end
56
58
  start_at(*options[:start_at]) if options[:start_at]
57
- end_at(*options[:end_at]) if options[:start_at]
59
+ end_at(*options[:end_at]) if options[:end_at]
58
60
  yield self if block_given?
59
61
  end
60
62
 
@@ -153,7 +155,7 @@ module Axlsx
153
155
  # @param [Integer] x The column
154
156
  # @param [Integer] y The row
155
157
  # @return [Marker]
156
- def start_at(x, y=0)
158
+ def start_at(x=0, y=0)
157
159
  x, y = *parse_coord_args(x, y)
158
160
  @graphic_frame.anchor.from.col = x
159
161
  @graphic_frame.anchor.from.row = y
@@ -162,10 +164,10 @@ module Axlsx
162
164
  # This is a short cut method to set the end anchor position
163
165
  # If you need finer granularity in positioning use
164
166
  # graphic_frame.anchor.to.colOff / rowOff
165
- # @param [Integer] x The column
166
- # @param [Integer] y The row
167
+ # @param [Integer] x The column - default 10
168
+ # @param [Integer] y The row - default 10
167
169
  # @return [Marker]
168
- def end_at(x, y=0)
170
+ def end_at(x=10, y=10)
169
171
  x, y = *parse_coord_args(x, y)
170
172
  @graphic_frame.anchor.to.col = x
171
173
  @graphic_frame.anchor.to.row = y
@@ -0,0 +1,51 @@
1
+ module Axlsx
2
+
3
+ # Base class for xVal, yVal and val and cat data sources
4
+ # @note xVal and cat are AxDataSource elements while yVal and val are NumDataSource elements
5
+ # The difference being that with AxDataSource elements, the data can be numLit, numRef, strLit or strRef
6
+ # while NumDataSource elements can only be numLit or numRef
7
+ class DataSource
8
+
9
+ def self.allowed_tag_names
10
+ [:yVal, :xVal, :val, :cat]
11
+ end
12
+
13
+ def self.allowed_types
14
+ [NumData, StrData]
15
+ end
16
+
17
+ attr_reader :tag_name
18
+
19
+ attr_reader :data
20
+
21
+ def initialize(type, data=[], options={})
22
+ Axlsx::RestrictionValidator.validate "#{self.class.name}", self.class.allowed_types, type
23
+ @data = type.new(:data = data)
24
+ tag_name = :val
25
+ options.each do |o|
26
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
27
+ end
28
+ end
29
+
30
+ def tag_name=(v)
31
+ Axlsx::RestrictionValidator.validate "#{self.class.name}.tag_name", self.class.allowed_tag_names, v
32
+ @tag_name = v
33
+ end
34
+
35
+ def f
36
+ is_reference? ? Axlsx::cell_range(data) : ''
37
+ end
38
+
39
+ def is_reference?
40
+ @data.first.is_a? Cell
41
+ end
42
+
43
+ def to_xml_string(str = '')
44
+ str << '<c:' << tag_name.to_s << '>'
45
+ @data.to_xml_string str
46
+ str << '</c:' << tag_name.to_s << '>'
47
+ end
48
+
49
+ end
50
+
51
+ end