lib/write_xlsx/chart.rb in write_xlsx-1.11.1 vs lib/write_xlsx/chart.rb in write_xlsx-1.11.2
- old
+ new
@@ -566,10 +566,17 @@
def is_secondary?
@is_secondary
end
+ #
+ # Set the option for displaying #N/A as an empty cell in a chart.
+ #
+ def show_na_as_empty_cell
+ @show_na_as_empty = true
+ end
+
private
def axis_setup
@axis_ids = []
@axis2_ids = []
@@ -596,10 +603,11 @@
@legend = Legend.new
@smooth_allowed = 0
@cross_between = 'between'
@date_category = false
@show_blanks = 'gap'
+ @show_na_as_empty = false
@show_hidden_data = false
@show_crosses = true
end
#
@@ -780,10 +788,13 @@
# Write the c:plotVisOnly element.
write_plot_vis_only
# Write the c:dispBlanksAs element.
write_disp_blanks_as
+
+ # Write the c:extLst element.
+ write_ext_lst_display_na if @show_na_as_empty
end
end
#
# Write the <c:dispBlanksAs> element.
@@ -948,16 +959,17 @@
write_cat(series)
# Write the c:val element.
write_val(series)
# Write the c:smooth element.
write_c_smooth(series.smooth) if ptrue?(@smooth_allowed)
- write_ext_lst(series.inverted_color) if series.inverted_color
+ # Write the c:extLst element.
+ write_ext_lst_inverted_fill(series.inverted_color) if series.inverted_color
end
@series_index += 1
end
- def write_ext_lst(color)
+ def write_ext_lst_inverted_fill(color)
uri = '{6F2FDCE9-48DA-4B69-8628-5D25D57E5C99}'
xmlns_c_14 =
'http://schemas.microsoft.com/office/drawing/2007/8/2/chart'
attributes_1 = [
@@ -978,10 +990,35 @@
end
end
end
end
+ #
+ # Write the <c:extLst> element for the display N/A as empty cell option.
+ #
+ def write_ext_lst_display_na
+ uri = '{56B9EC1D-385E-4148-901F-78D8002777C0}'
+ xmlns_c_16 = 'http://schemas.microsoft.com/office/drawing/2017/03/chart'
+
+ attributes1 = [
+ ['uri', uri],
+ ['xmlns:c16r3', xmlns_c_16]
+ ]
+
+ attributes2 = [
+ ['val', 1]
+ ]
+
+ @writer.tag_elements('c:extLst') do
+ @writer.tag_elements('c:ext', attributes1) do
+ @writer.tag_elements('c16r3:dataDisplayOptions16') do
+ @writer.empty_tag('c16r3:dispNaAsBlank', attributes2)
+ end
+ end
+ end
+ end
+
def write_ser_base(series)
# Write the c:idx element.
write_idx(@series_index)
# Write the c:order element.
write_order(@series_index)
@@ -2120,11 +2157,11 @@
end
if trendline.display_equation
# Write the c:dispEq element.
write_disp_eq
# Write the c:trendlineLbl element.
- write_trendline_lbl
+ write_trendline_lbl(trendline)
end
end
end
#
@@ -2197,16 +2234,22 @@
end
#
# Write the <c:trendlineLbl> element.
#
- def write_trendline_lbl
+ def write_trendline_lbl(trendline)
@writer.tag_elements('c:trendlineLbl') do
# Write the c:layout element.
write_layout
# Write the c:numFmt element.
write_trendline_num_fmt
+ # Write the c:spPr element for the label formatting.
+ write_sp_pr(trendline.label)
+ # Write the data label font elements.
+ if trendline.label && ptrue?(trendline.label[:font])
+ write_axis_font(trendline.label[:font])
+ end
end
end
#
# Write the <c:numFmt> element.
@@ -2542,15 +2585,29 @@
#
def write_separator(data)
@writer.data_element('c:separator', data)
end
- #
- # Write the <c:showLeaderLines> element.
- #
+ # Write the <c:showLeaderLines> element. This is different for Pie/Doughnut
+ # charts. Other chart types only supported leader lines after Excel 2015 via
+ # an extension element.
def write_show_leader_lines
- @writer.empty_tag('c:showLeaderLines', [['val', 1]])
+ uri = '{CE6537A1-D6FC-4f65-9D91-7224C49458BB}'
+ xmlns_c_15 = 'http://schemas.microsoft.com/office/drawing/2012/chart'
+
+ attributes1 = [
+ ['uri', uri],
+ ['xmlns:c15', xmlns_c_15]
+ ]
+
+ attributes2 = [['val', 1]]
+
+ @writer.tag_elements('c:extLst') do
+ @writer.tag_elements('c:ext', attributes1) do
+ @writer.empty_tag('c15:showLeaderLines', attributes2)
+ end
+ end
end
#
# Write the <c:dLblPos> element.
#
@@ -2860,12 +2917,10 @@
#
# Write the <a:fillToRect> element.
#
def write_a_fill_to_rect(type)
- attributes = []
-
attributes = if type == 'shape'
[
['l', 50000],
['t', 50000],
['r', 50000],
@@ -2883,11 +2938,9 @@
#
# Write the <a:tileRect> element.
#
def write_a_tile_rect(type)
- attributes = []
-
attributes = if type == 'shape'
[]
else
[
['r', -100000],