write_xlsx 0.81.1 → 0.83.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +8 -0
- data/Changes +20 -0
- data/README.md +3 -2
- data/examples/chart_combined.rb +107 -0
- data/examples/chart_data_table.rb +1 -1
- data/examples/chart_pareto.rb +82 -0
- data/lib/write_xlsx/chart.rb +115 -42
- data/lib/write_xlsx/chart/axis.rb +5 -1
- data/lib/write_xlsx/chart/bar.rb +13 -0
- data/lib/write_xlsx/chart/pie.rb +7 -0
- data/lib/write_xlsx/chart/scatter.rb +25 -57
- data/lib/write_xlsx/format.rb +40 -0
- data/lib/write_xlsx/package/app.rb +39 -1
- data/lib/write_xlsx/package/comments.rb +1 -5
- data/lib/write_xlsx/package/content_types.rb +48 -13
- data/lib/write_xlsx/package/core.rb +14 -12
- data/lib/write_xlsx/package/packager.rb +17 -41
- data/lib/write_xlsx/package/styles.rb +215 -256
- data/lib/write_xlsx/package/table.rb +5 -7
- data/lib/write_xlsx/package/xml_writer_simple.rb +2 -0
- data/lib/write_xlsx/sheets.rb +2 -2
- data/lib/write_xlsx/utility.rb +17 -2
- data/lib/write_xlsx/version.rb +1 -1
- data/lib/write_xlsx/workbook.rb +44 -2
- data/lib/write_xlsx/worksheet.rb +26 -17
- data/lib/write_xlsx/worksheet/page_setup.rb +12 -6
- data/test/chart/test_write_style.rb +2 -2
- data/test/helper.rb +3 -0
- data/test/package/app/test_app01.rb +1 -1
- data/test/package/app/test_app02.rb +1 -1
- data/test/package/app/test_app03.rb +1 -1
- data/test/package/content_types/test_content_types.rb +1 -1
- data/test/package/content_types/test_write_default.rb +1 -1
- data/test/package/content_types/test_write_override.rb +1 -1
- data/test/perl_output/chart_combined.xlsx +0 -0
- data/test/perl_output/chart_pareto.xlsx +0 -0
- data/test/regression/test_button07.rb +5 -2
- data/test/regression/test_button13.rb +34 -0
- data/test/regression/test_button14.rb +31 -0
- data/test/regression/test_chart_column11.rb +45 -0
- data/test/regression/test_chart_column12.rb +45 -0
- data/test/regression/test_chart_combined01.rb +37 -0
- data/test/regression/test_chart_combined02.rb +43 -0
- data/test/regression/test_chart_combined03.rb +45 -0
- data/test/regression/test_chart_combined04.rb +47 -0
- data/test/regression/test_chart_combined05.rb +49 -0
- data/test/regression/test_chart_combined06.rb +49 -0
- data/test/regression/test_chart_combined07.rb +53 -0
- data/test/regression/test_chart_combined08.rb +65 -0
- data/test/regression/test_chart_data_labels24.rb +50 -0
- data/test/regression/test_chart_date05.rb +57 -0
- data/test/regression/test_chart_format20.rb +55 -0
- data/test/regression/test_format11.rb +28 -0
- data/test/regression/test_format12.rb +41 -0
- data/test/regression/test_landscape01.rb +27 -0
- data/test/regression/test_quote_name04.rb +40 -0
- data/test/regression/test_set_start_page01.rb +4 -7
- data/test/regression/test_set_start_page02.rb +33 -0
- data/test/regression/test_set_start_page03.rb +33 -0
- data/test/regression/test_table17.rb +70 -0
- data/test/regression/xlsx_files/chart_column11.xlsx +0 -0
- data/test/regression/xlsx_files/chart_column12.xlsx +0 -0
- data/test/regression/xlsx_files/chart_combined01.xlsx +0 -0
- data/test/regression/xlsx_files/chart_combined02.xlsx +0 -0
- data/test/regression/xlsx_files/chart_combined03.xlsx +0 -0
- data/test/regression/xlsx_files/chart_combined04.xlsx +0 -0
- data/test/regression/xlsx_files/chart_combined05.xlsx +0 -0
- data/test/regression/xlsx_files/chart_combined06.xlsx +0 -0
- data/test/regression/xlsx_files/chart_combined07.xlsx +0 -0
- data/test/regression/xlsx_files/chart_combined08.xlsx +0 -0
- data/test/regression/xlsx_files/chart_date05.xlsx +0 -0
- data/test/regression/xlsx_files/chart_format20.xlsx +0 -0
- data/test/regression/xlsx_files/format11.xlsx +0 -0
- data/test/regression/xlsx_files/format12.xlsx +0 -0
- data/test/regression/xlsx_files/landscape01.xlsx +0 -0
- data/test/regression/xlsx_files/quote_name04.xlsx +0 -0
- data/test/regression/xlsx_files/set_start_page01.xlsx +0 -0
- data/test/regression/xlsx_files/set_start_page02.xlsx +0 -0
- data/test/regression/xlsx_files/set_start_page03.xlsx +0 -0
- data/test/regression/xlsx_files/table17.xlsx +0 -0
- data/test/test_example_match.rb +172 -0
- data/write_xlsx.gemspec +1 -0
- metadata +106 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 055ac6da5fa4ffabd709a61116271eb670a1a946
|
4
|
+
data.tar.gz: da5f1f06369023fec4603457d29cd60b1638e317
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b09a5444cce89ac0b182f9a82d37ade0e41e5a081cd0c885dcb288e8b6c67a6424ce44dc69e9c6e4e302d4271fb29b9997365ad379629103af99f55fee115ad
|
7
|
+
data.tar.gz: cfd9852383a7cf97b141ab4ec6a1d5eac376cb05c3e6ecbb64a48e3c799bf513c043273e4a26c8890abb36331278e5705ec5abe34806102ceb615ff58a148bf5
|
data/.travis.yml
ADDED
data/Changes
CHANGED
@@ -1,4 +1,24 @@
|
|
1
1
|
Change history of write_xlsx rubygem.
|
2
|
+
2015-04-12 v0.83.0
|
3
|
+
Added option to combine two different chart types. For example to
|
4
|
+
create a Pareto chart.
|
5
|
+
|
6
|
+
2015-04-12 v0.82.0
|
7
|
+
Added extra documentation on how to handle VBA macros and added
|
8
|
+
automatic and manual setting of workbook and worksheet VBA codenames.
|
9
|
+
|
10
|
+
Fix for set_start_page() for values > 1.
|
11
|
+
|
12
|
+
Fix to copy user defined chart properties, such as trendlines,
|
13
|
+
so that they aren't overwritten.
|
14
|
+
|
15
|
+
Added column funtion_value option to add_table to allow
|
16
|
+
function value to be set.
|
17
|
+
|
18
|
+
Allow explicit text categories in charts.
|
19
|
+
|
20
|
+
Fix for column/bar gap/overlap on y2 axis.
|
21
|
+
|
2
22
|
2014-12-28 v0.81.1
|
3
23
|
use test-unit gem instead of test/unit.
|
4
24
|
|
data/README.md
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# write_xlsx
|
2
2
|
|
3
3
|
[](http://badge.fury.io/rb/write_xlsx)
|
4
|
+
[](https://travis-ci.org/cxn03651/write_xlsx)
|
4
5
|
|
5
6
|
gem to create a new file in the Excel 2007+ XLSX format, and you can use the
|
6
7
|
same interface as writeexcel gem. write_xlsx is converted from Perl's module
|
7
|
-
[Excel::Writer::XLSX-0.
|
8
|
+
[Excel::Writer::XLSX-0.83](https://github.com/jmcnamara/excel-writer-xlsx) .
|
8
9
|
|
9
10
|
## Description
|
10
11
|
|
@@ -84,7 +85,7 @@ the first worksheet in an Excel XML spreadsheet called ruby.xlsx:
|
|
84
85
|
Original Perl module was written by John McNamara(jmcnamara@cpan.org).
|
85
86
|
|
86
87
|
Converted to ruby by Hideo NAKAMURA(cxn03651@msj.biglobe.ne.jp)
|
87
|
-
Copyright (c) 2012-
|
88
|
+
Copyright (c) 2012-2015 Hideo NAKAMURA.
|
88
89
|
|
89
90
|
See LICENSE.txt for further details.
|
90
91
|
|
@@ -0,0 +1,107 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
#######################################################################
|
5
|
+
#
|
6
|
+
# An example of a Combined chart in WriteXLSX.
|
7
|
+
#
|
8
|
+
# reverse ('(c)'), March 2015, John McNamara, jmcnamara@cpan.org
|
9
|
+
# convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
|
10
|
+
#
|
11
|
+
|
12
|
+
require 'write_xlsx'
|
13
|
+
|
14
|
+
workbook = WriteXLSX.new('chart_combined.xlsx')
|
15
|
+
worksheet = workbook.add_worksheet
|
16
|
+
bold = workbook.add_format(:bold => 1)
|
17
|
+
|
18
|
+
# Add the worksheet data that the charts will refer to.
|
19
|
+
headings = ['Number', 'Batch 1', 'Batch 2']
|
20
|
+
data = [
|
21
|
+
[ 2, 3, 4, 5, 6, 7],
|
22
|
+
[10, 40, 50, 20, 10, 50],
|
23
|
+
[30, 60, 70, 50, 40, 30]
|
24
|
+
]
|
25
|
+
|
26
|
+
worksheet.write('A1', headings, bold)
|
27
|
+
worksheet.write('A2', data)
|
28
|
+
|
29
|
+
#
|
30
|
+
# In the first example we will create a combined column and line chart.
|
31
|
+
# They will share the same X and Y axes.
|
32
|
+
#
|
33
|
+
|
34
|
+
# Create a new column chart. This will use this as the primary chart.
|
35
|
+
column_chart1 = workbook.add_chart(:type => 'column', :embedded => 1)
|
36
|
+
|
37
|
+
# Configure the data series for the primary chart.
|
38
|
+
column_chart1.add_series(
|
39
|
+
:name => '=Sheet1!$B$1',
|
40
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
41
|
+
:values => '=Sheet1!$B$2:$B$7'
|
42
|
+
)
|
43
|
+
|
44
|
+
# Create a new column chart. This will use this as the secondary chart.
|
45
|
+
line_chart1 = workbook.add_chart(:type => 'line', :embedded => 1)
|
46
|
+
|
47
|
+
# Configure the data series for the secondary chart.
|
48
|
+
line_chart1.add_series(
|
49
|
+
:name => '=Sheet1!$C$1',
|
50
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
51
|
+
:values => '=Sheet1!$C$2:$C$7'
|
52
|
+
)
|
53
|
+
|
54
|
+
# Combine the charts.
|
55
|
+
column_chart1.combine(line_chart1)
|
56
|
+
|
57
|
+
# Add a chart title and some axis labels. Note, this is done via the
|
58
|
+
# primary chart.
|
59
|
+
column_chart1.set_title(:name => 'Combined chart - same Y axis')
|
60
|
+
column_chart1.set_x_axis(:name => 'Test number')
|
61
|
+
column_chart1.set_y_axis(:name => 'Sample length (mm)')
|
62
|
+
|
63
|
+
|
64
|
+
# Insert the chart into the worksheet
|
65
|
+
worksheet.insert_chart('E2', column_chart1)
|
66
|
+
|
67
|
+
#
|
68
|
+
# In the second example we will create a similar combined column and line
|
69
|
+
# chart except that the secondary chart will have a secondary Y axis.
|
70
|
+
#
|
71
|
+
|
72
|
+
# Create a new column chart. This will use this as the primary chart.
|
73
|
+
column_chart2 = workbook.add_chart(:type => 'column', :embedded => 1)
|
74
|
+
|
75
|
+
# Configure the data series for the primary chart.
|
76
|
+
column_chart2.add_series(
|
77
|
+
:name => '=Sheet1!$B$1',
|
78
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
79
|
+
:values => '=Sheet1!$B$2:$B$7'
|
80
|
+
)
|
81
|
+
|
82
|
+
# Create a new column chart. This will use this as the secondary chart.
|
83
|
+
line_chart2 = workbook.add_chart(:type => 'line', :embedded => 1)
|
84
|
+
|
85
|
+
# Configure the data series for the secondary chart. We also set a
|
86
|
+
# secondary Y axis via (y2_axis). This is the only difference between
|
87
|
+
# this and the first example, apart from the axis label below.
|
88
|
+
line_chart2.add_series(
|
89
|
+
:name => '=Sheet1!$C$1',
|
90
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
91
|
+
:values => '=Sheet1!$C$2:$C$7',
|
92
|
+
:y2_axis => 1
|
93
|
+
)
|
94
|
+
|
95
|
+
# Combine the charts.
|
96
|
+
column_chart2.combine(line_chart2)
|
97
|
+
|
98
|
+
# Add a chart title and some axis labels.
|
99
|
+
column_chart2.set_title(:name => 'Combine chart - secondary Y axis')
|
100
|
+
column_chart2.set_x_axis(:name => 'Test number')
|
101
|
+
column_chart2.set_y_axis(:name => 'Sample length (mm)')
|
102
|
+
column_chart2.set_y2_axis(:name => 'Target length (mm)')
|
103
|
+
|
104
|
+
# Insert the chart into the worksheet
|
105
|
+
worksheet.insert_chart('E18', column_chart2)
|
106
|
+
|
107
|
+
workbook.close
|
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
#######################################################################
|
5
5
|
#
|
6
|
-
# A demo of
|
6
|
+
# A demo of a Column chart with a data table on the X-axis using
|
7
7
|
# WriteXLSX.
|
8
8
|
#
|
9
9
|
# reverse ('(c)'), December 2012, John McNamara, jmcnamara@cpan.org
|
@@ -0,0 +1,82 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
#######################################################################
|
5
|
+
#
|
6
|
+
# A demo of a Pareto chart in Excel::Writer::XLSX.
|
7
|
+
#
|
8
|
+
# reverse ('(c)'), March 2015, John McNamara, jmcnamara@cpan.org
|
9
|
+
# convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
|
10
|
+
#
|
11
|
+
|
12
|
+
require 'write_xlsx'
|
13
|
+
|
14
|
+
workbook = WriteXLSX.new('chart_pareto.xlsx')
|
15
|
+
worksheet = workbook.add_worksheet
|
16
|
+
|
17
|
+
# Formats used in the workbook.
|
18
|
+
bold = workbook.add_format(:bold => 1)
|
19
|
+
percent_format = workbook.add_format(:num_format => '0.0%')
|
20
|
+
|
21
|
+
# Widen the columns for visibility.
|
22
|
+
worksheet.set_column('A:A', 15)
|
23
|
+
worksheet.set_column('B:C', 10)
|
24
|
+
|
25
|
+
# Add the worksheet data that the charts will refer to.
|
26
|
+
headings = ['Reason', 'Number', 'Percentage']
|
27
|
+
|
28
|
+
reasons = [
|
29
|
+
'Traffic', 'Child care', 'Public Transport', 'Weather',
|
30
|
+
'Overslept', 'Emergency'
|
31
|
+
]
|
32
|
+
|
33
|
+
numbers = [ 60, 40, 20, 15, 10, 5]
|
34
|
+
percents = [0.44, 0.667, 0.8, 0.9, 0.967, 1]
|
35
|
+
|
36
|
+
worksheet.write_row('A1', headings, bold)
|
37
|
+
worksheet.write_col('A2', reasons)
|
38
|
+
worksheet.write_col('B2', numbers)
|
39
|
+
worksheet.write_col('C2', percents, percent_format)
|
40
|
+
|
41
|
+
# Create a new column chart. This will be the primary chart.
|
42
|
+
column_chart = workbook.add_chart(:type => 'column', :embedded => 1)
|
43
|
+
|
44
|
+
# Add a series
|
45
|
+
column_chart.add_series(
|
46
|
+
:categories => 'Sheet1!$A$2:$A$7',
|
47
|
+
:values => 'Sheet1!$B$2:$B$7'
|
48
|
+
)
|
49
|
+
|
50
|
+
# Add a chart title.
|
51
|
+
column_chart.set_title(:name => 'Reasons for lateness')
|
52
|
+
|
53
|
+
# Turn off the chart legend.
|
54
|
+
column_chart.set_legend(:position => 'none')
|
55
|
+
|
56
|
+
# Set the title and scale of the Y axes. Note, the secondary axis is set from
|
57
|
+
# the primary chart.
|
58
|
+
column_chart.set_y_axis(
|
59
|
+
:name => 'Respondents (number)',
|
60
|
+
:min => 0,
|
61
|
+
:max => 120
|
62
|
+
)
|
63
|
+
column_chart.set_y2_axis(:max => 1)
|
64
|
+
|
65
|
+
# Create a new line chart. This will be the secondary chart.
|
66
|
+
line_chart = workbook.add_chart(:type => 'line', :embedded => 1)
|
67
|
+
|
68
|
+
# Add a series, on the secondary axis.
|
69
|
+
line_chart.add_series(
|
70
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
71
|
+
:values => '=Sheet1!$C$2:$C$7',
|
72
|
+
:marker => {:type => 'automatic'},
|
73
|
+
:y2_axis => 1
|
74
|
+
)
|
75
|
+
|
76
|
+
# Combine the charts.
|
77
|
+
column_chart.combine(line_chart)
|
78
|
+
|
79
|
+
# Insert the chart into the worksheet.
|
80
|
+
worksheet.insert_chart('F2', column_chart)
|
81
|
+
|
82
|
+
workbook.close
|
data/lib/write_xlsx/chart.rb
CHANGED
@@ -141,7 +141,11 @@ class Chart
|
|
141
141
|
attr_reader :embedded, :formula_ids, :formula_data # :nodoc:
|
142
142
|
attr_reader :x_scale, :y_scale, :x_offset, :y_offset # :nodoc:
|
143
143
|
attr_reader :width, :height # :nodoc:
|
144
|
-
attr_reader :label_positions, :label_position_default
|
144
|
+
attr_reader :label_positions, :label_position_default, :combined # :nodoc:
|
145
|
+
attr_writer :date_category, :already_inserted
|
146
|
+
attr_writer :series_index
|
147
|
+
attr_writer :writer
|
148
|
+
attr_reader :x2_axis, :y2_axis, :axis2_ids
|
145
149
|
|
146
150
|
#
|
147
151
|
# Factory method for returning chart objects based on their class type.
|
@@ -185,7 +189,7 @@ def initialize(subtype) # :nodoc:
|
|
185
189
|
@sheet_type = 0x0200
|
186
190
|
@series = []
|
187
191
|
@embedded = 0
|
188
|
-
@id =
|
192
|
+
@id = -1
|
189
193
|
@series_index = 0
|
190
194
|
@style_id = 2
|
191
195
|
@formula_ids = {}
|
@@ -197,6 +201,8 @@ def initialize(subtype) # :nodoc:
|
|
197
201
|
@name = ''
|
198
202
|
@table = nil
|
199
203
|
set_default_properties
|
204
|
+
@combined = nil
|
205
|
+
@is_secondary = false
|
200
206
|
end
|
201
207
|
|
202
208
|
def set_xml_writer(filename) # :nodoc:
|
@@ -245,6 +251,11 @@ def add_series(params)
|
|
245
251
|
x2_axis = params[:x2_axis]
|
246
252
|
y2_axis = params[:y2_axis]
|
247
253
|
|
254
|
+
# Store secondary status for combined charts.
|
255
|
+
if ptrue?(x2_axis) || ptrue?(y2_axis)
|
256
|
+
@is_secondary = true
|
257
|
+
end
|
258
|
+
|
248
259
|
# Set the gap and overlap for Bar/Column charts.
|
249
260
|
if params[:gap]
|
250
261
|
if ptrue?(y2_axis)
|
@@ -342,7 +353,7 @@ def set_chartarea(params)
|
|
342
353
|
# Set on of the 42 built-in Excel chart styles. The default style is 2.
|
343
354
|
#
|
344
355
|
def set_style(style_id = 2)
|
345
|
-
style_id = 2 if style_id < 0 || style_id >
|
356
|
+
style_id = 2 if style_id < 0 || style_id > 48
|
346
357
|
@style_id = style_id
|
347
358
|
end
|
348
359
|
|
@@ -423,6 +434,13 @@ def set_high_low_lines(params = {})
|
|
423
434
|
@hi_low_lines = Chartline.new(params)
|
424
435
|
end
|
425
436
|
|
437
|
+
#
|
438
|
+
# Add another chart to create a combined chart.
|
439
|
+
#
|
440
|
+
def combine(chart)
|
441
|
+
@combined = chart
|
442
|
+
end
|
443
|
+
|
426
444
|
#
|
427
445
|
# Setup the default configuration data for an embedded chart.
|
428
446
|
#
|
@@ -518,7 +536,12 @@ def params_to_font(params)
|
|
518
536
|
#
|
519
537
|
def process_names(name = nil, name_formula = nil) # :nodoc:
|
520
538
|
# Name looks like a formula, use it to set name_formula.
|
521
|
-
if name
|
539
|
+
if name.respond_to?(:to_ary)
|
540
|
+
cell = xl_rowcol_to_cell(name[1], name[2], 1, 1)
|
541
|
+
name_formula = "#{quote_sheetname(name[0])}!#{cell}"
|
542
|
+
name = ''
|
543
|
+
elsif
|
544
|
+
name && name =~ /^=[^!]+!\$/
|
522
545
|
name_formula = name
|
523
546
|
name = ''
|
524
547
|
end
|
@@ -556,6 +579,14 @@ def data_id(full_formula, data) # :nodoc:
|
|
556
579
|
id
|
557
580
|
end
|
558
581
|
|
582
|
+
def already_inserted?
|
583
|
+
@already_inserted
|
584
|
+
end
|
585
|
+
|
586
|
+
def is_secondary?
|
587
|
+
@is_secondary
|
588
|
+
end
|
589
|
+
|
559
590
|
private
|
560
591
|
|
561
592
|
def axis_setup
|
@@ -663,11 +694,11 @@ def add_axis_ids(params) # :nodoc:
|
|
663
694
|
end
|
664
695
|
|
665
696
|
def ids
|
666
|
-
chart_id =
|
697
|
+
chart_id = 5001 + @id
|
667
698
|
axis_count = 1 + @axis2_ids.size + @axis_ids.size
|
668
699
|
|
669
|
-
id1 = sprintf('
|
670
|
-
id2 = sprintf('
|
700
|
+
id1 = sprintf('%04d%04d', chart_id, axis_count)
|
701
|
+
id2 = sprintf('%04d%04d', chart_id, axis_count + 1)
|
671
702
|
|
672
703
|
[id1, id2]
|
673
704
|
end
|
@@ -832,6 +863,7 @@ def write_disp_blanks_as
|
|
832
863
|
# Write the <c:plotArea> element.
|
833
864
|
#
|
834
865
|
def write_plot_area # :nodoc:
|
866
|
+
second_chart = @combined
|
835
867
|
@writer.tag_elements('c:plotArea') do
|
836
868
|
# Write the c:layout element.
|
837
869
|
write_layout(@plotarea.layout, 'plot')
|
@@ -839,6 +871,27 @@ def write_plot_area # :nodoc:
|
|
839
871
|
write_chart_type(:primary_axes => 1)
|
840
872
|
write_chart_type(:primary_axes => 0)
|
841
873
|
|
874
|
+
# Configure a combined chart if present.
|
875
|
+
if second_chart
|
876
|
+
|
877
|
+
# Secondary axis has unique id otherwise use same as primary.
|
878
|
+
if second_chart.is_secondary?
|
879
|
+
second_chart.id = 1000 + @id
|
880
|
+
else
|
881
|
+
second_chart.id = @id
|
882
|
+
end
|
883
|
+
|
884
|
+
# Share the same writer for writing.
|
885
|
+
second_chart.writer = @writer
|
886
|
+
|
887
|
+
# Share series index with primary chart.
|
888
|
+
second_chart.series_index = @series_index
|
889
|
+
|
890
|
+
# Write the subclass chart type elements for combined chart.
|
891
|
+
second_chart.write_chart_type(:primary_axes => 1)
|
892
|
+
second_chart.write_chart_type(:primary_axes => 0)
|
893
|
+
end
|
894
|
+
|
842
895
|
# Write the category and value elements for the primary axes.
|
843
896
|
params = {
|
844
897
|
:x_axis => @x_axis,
|
@@ -852,7 +905,7 @@ def write_plot_area # :nodoc:
|
|
852
905
|
write_cat_axis(params)
|
853
906
|
end
|
854
907
|
|
855
|
-
write_val_axis(
|
908
|
+
write_val_axis(@x_axis, @y_axis, @axis_ids)
|
856
909
|
|
857
910
|
# Write the category and value elements for the secondary axes.
|
858
911
|
params = {
|
@@ -861,7 +914,23 @@ def write_plot_area # :nodoc:
|
|
861
914
|
:axis_ids => @axis2_ids
|
862
915
|
}
|
863
916
|
|
864
|
-
write_val_axis(
|
917
|
+
write_val_axis(@x2_axis, @y2_axis, @axis2_ids)
|
918
|
+
|
919
|
+
# Write the secondary axis for the secondary chart.
|
920
|
+
if second_chart && second_chart.is_secondary?
|
921
|
+
|
922
|
+
params = {
|
923
|
+
:x_axis => second_chart.x2_axis,
|
924
|
+
:y_axis => second_chart.y2_axis,
|
925
|
+
:axis_ids => second_chart.axis2_ids
|
926
|
+
}
|
927
|
+
|
928
|
+
second_chart.write_val_axis(
|
929
|
+
second_chart.x2_axis,
|
930
|
+
second_chart.y2_axis,
|
931
|
+
second_chart.axis2_ids
|
932
|
+
)
|
933
|
+
end
|
865
934
|
|
866
935
|
if @date_category
|
867
936
|
write_date_axis(params)
|
@@ -937,30 +1006,10 @@ def write_series(series) # :nodoc:
|
|
937
1006
|
# Write the <c:ser> element.
|
938
1007
|
#
|
939
1008
|
def write_ser(series) # :nodoc:
|
940
|
-
index = @series_index
|
941
|
-
@series_index += 1
|
942
|
-
|
943
1009
|
@writer.tag_elements('c:ser') do
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
write_order(index)
|
948
|
-
# Write the series name.
|
949
|
-
write_series_name(series)
|
950
|
-
# Write the c:spPr element.
|
951
|
-
write_sp_pr(series)
|
952
|
-
# Write the c:marker element.
|
953
|
-
write_marker(series.marker)
|
954
|
-
# Write the c:invertIfNegative element.
|
955
|
-
write_c_invert_if_negative(series.invert_if_negative)
|
956
|
-
# Write the c:dPt element.
|
957
|
-
write_d_pt(series.points)
|
958
|
-
# Write the c:dLbls element.
|
959
|
-
write_d_lbls(series.labels)
|
960
|
-
# Write the c:trendline element.
|
961
|
-
write_trendline(series.trendline)
|
962
|
-
# Write the c:errBars element.
|
963
|
-
write_error_bars(series.error_bars)
|
1010
|
+
write_ser_base(series) do
|
1011
|
+
write_c_invert_if_negative(series.invert_if_negative)
|
1012
|
+
end
|
964
1013
|
# Write the c:cat element.
|
965
1014
|
write_cat(series)
|
966
1015
|
# Write the c:val element.
|
@@ -968,6 +1017,31 @@ def write_ser(series) # :nodoc:
|
|
968
1017
|
# Write the c:smooth element.
|
969
1018
|
write_c_smooth(series.smooth) if ptrue?(@smooth_allowed)
|
970
1019
|
end
|
1020
|
+
@series_index += 1
|
1021
|
+
end
|
1022
|
+
|
1023
|
+
def write_ser_base(series)
|
1024
|
+
# Write the c:idx element.
|
1025
|
+
write_idx(@series_index)
|
1026
|
+
# Write the c:order element.
|
1027
|
+
write_order(@series_index)
|
1028
|
+
# Write the series name.
|
1029
|
+
write_series_name(series)
|
1030
|
+
# Write the c:spPr element.
|
1031
|
+
write_sp_pr(series)
|
1032
|
+
# Write the c:marker element.
|
1033
|
+
write_marker(series.marker)
|
1034
|
+
|
1035
|
+
yield if block_given?
|
1036
|
+
|
1037
|
+
# Write the c:dPt element.
|
1038
|
+
write_d_pt(series.points)
|
1039
|
+
# Write the c:dLbls element.
|
1040
|
+
write_d_lbls(series.labels)
|
1041
|
+
# Write the c:trendline element.
|
1042
|
+
write_trendline(series.trendline)
|
1043
|
+
# Write the c:errBars element.
|
1044
|
+
write_error_bars(series.error_bars)
|
971
1045
|
end
|
972
1046
|
|
973
1047
|
#
|
@@ -1177,7 +1251,7 @@ def write_cat_axis(params) # :nodoc:
|
|
1177
1251
|
write_crossing(y_axis.crossing)
|
1178
1252
|
end
|
1179
1253
|
# Write the c:auto element.
|
1180
|
-
write_auto(1)
|
1254
|
+
write_auto(1) unless x_axis.text_axis
|
1181
1255
|
# Write the c:labelAlign element.
|
1182
1256
|
write_label_align('ctr')
|
1183
1257
|
# Write the c:labelOffset element.
|
@@ -1190,18 +1264,17 @@ def write_cat_axis(params) # :nodoc:
|
|
1190
1264
|
#
|
1191
1265
|
# Write the <c:valAx> element. Usually the Y axis.
|
1192
1266
|
#
|
1193
|
-
def write_val_axis(
|
1194
|
-
axis_ids = params[:axis_ids]
|
1267
|
+
def write_val_axis(x_axis, y_axis, axis_ids, position = nil)
|
1195
1268
|
return unless axis_ids && !axis_ids.empty?
|
1196
1269
|
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
write_val_axis_base(x_axis, y_axis, axis_ids_0, axis_ids_1, position)
|
1270
|
+
write_val_axis_base(
|
1271
|
+
x_axis, y_axis,
|
1272
|
+
axis_ids[0],
|
1273
|
+
axis_ids[1],
|
1274
|
+
y_axis.position || position || @val_axis_position
|
1275
|
+
)
|
1204
1276
|
end
|
1277
|
+
public :write_val_axis
|
1205
1278
|
|
1206
1279
|
def write_val_axis_base(x_axis, y_axis, axis_ids_0, axis_ids_1, position) # :nodoc:
|
1207
1280
|
@writer.tag_elements('c:valAx') do
|