lib/write_xlsx/chart.rb in write_xlsx-0.86.0 vs lib/write_xlsx/chart.rb in write_xlsx-0.87.0
- old
+ new
@@ -38,31 +38,41 @@
class ChartArea
include Writexlsx::Utility
include Writexlsx::Gradient
- attr_reader :line, :fill, :gradient, :layout
+ attr_reader :line, :fill, :pattern, :gradient, :layout
def initialize(params = {})
@layout = layout_properties(params[:layout])
# Allow 'border' as a synonym for 'line'.
border = params_to_border(params)
# Set the line properties for the chartarea.
@line = border ? line_properties(border) : line_properties(params[:line])
+ # Set the pattern properties for the series.
+ @pattern = pattern_properties(params[:pattern])
+
# Set the gradient fill properties for the series.
@gradient = gradient_properties(params[:gradient])
# Map deprecated Spreadsheet::WriteExcel fill colour.
fill = params[:color] ? { :color => params[:color] } : params[:fill]
@fill = fill_properties(fill)
- if ptrue?(@gradient)
+ # Pattern fill overrides solid fill.
+ if ptrue?(@pattern)
@fill = nil
end
+
+ # Gradient fill overrides solid and pattern fills.
+ if ptrue?(@gradient)
+ @pattern = nil
+ @fill = nil
+ end
end
private
def params_to_border(params)
@@ -1296,10 +1306,12 @@
write_label_align('ctr')
# Write the c:labelOffset element.
write_label_offset(100)
# Write the c:tickLblSkip element.
write_tick_lbl_skip(x_axis.interval_unit)
+ # Write the c:tickMarkSkip element.
+ write_tick_mark_skip(x_axis.interval_tick)
end
end
#
# Write the <c:valAx> element. Usually the Y axis.
@@ -1434,10 +1446,12 @@
write_auto(1)
# Write the c:labelOffset element.
write_label_offset(100)
# Write the c:tickLblSkip element.
write_tick_lbl_skip(x_axis.interval_unit)
+ # Write the c:tickMarkSkip element.
+ write_tick_mark_skip(x_axis.interval_tick)
# Write the c:majorUnit element.
write_c_major_unit(x_axis.major_unit)
# Write the c:majorTimeUnit element.
write_c_major_time_unit(x_axis.major_unit_type) if x_axis.major_unit
# Write the c:minorUnit element.
@@ -1629,10 +1643,19 @@
@writer.empty_tag('c:tickLblSkip', [ ['val', val] ])
end
#
+ # Write the <c:tickMarkSkip> element.
+ #
+ def write_tick_mark_skip(val) # :nodoc:
+ return unless val
+
+ @writer.empty_tag( 'c:tickMarkSkip', [ ['val', val] ])
+ end
+
+ #
# Write the <c:majorGridlines> element.
#
def write_major_gridlines(gridlines) # :nodoc:
write_gridlines_base('c:majorGridlines', gridlines)
end
@@ -2088,14 +2111,15 @@
# Write the <c:spPr> element.
#
def write_sp_pr(series) # :nodoc:
line = series.line
fill = series.fill
+ pattern = series.pattern if series.respond_to?(:pattern)
gradient = series.gradient if series.respond_to?(:gradient)
return if (!line || !ptrue?(line[:_defined])) &&
- (!fill || !ptrue?(fill[:_defined])) && !gradient
+ (!fill || !ptrue?(fill[:_defined])) && !pattern && !gradient
@writer.tag_elements('c:spPr') do
# Write the fill elements for solid charts such as pie/doughnut and bar.
if fill && fill[:_defined] != 0
if ptrue?(fill[:none])
@@ -2104,10 +2128,13 @@
else
# Write the a:solidFill element.
write_a_solid_fill(fill)
end
end
+ if ptrue?(pattern)
+ write_a_patt_fill(pattern)
+ end
if ptrue?(gradient)
# Write the a:gradFill element.
write_a_grad_fill(gradient)
end
# Write the a:ln element.
@@ -2825,9 +2852,29 @@
['b', -100000]
]
end
@writer.empty_tag('a:tileRect', attributes)
+ end
+
+ #
+ # Write the <a:pattFill> element.
+ #
+ def write_a_patt_fill(pattern)
+ attributes = [ ['prst', pattern[:pattern]] ]
+
+ @writer.tag_elements('a:pattFill', attributes) do
+ write_a_fg_clr(pattern[:fg_color])
+ write_a_bg_clr(pattern[:bg_color])
+ end
+ end
+
+ def write_a_fg_clr(color)
+ @writer.tag_elements('a:fgClr') { write_a_srgb_clr(color(color)) }
+ end
+
+ def write_a_bg_clr(color)
+ @writer.tag_elements('a:bgClr') { write_a_srgb_clr(color(color)) }
end
def write_bars_base(tag, format)
if format.line_defined? || format.fill_defined?
@writer.tag_elements(tag) { write_sp_pr(format) }