lib/write_xlsx/chart/area.rb in write_xlsx-0.0.4 vs lib/write_xlsx/chart/area.rb in write_xlsx-0.51.0

- old
+ new

@@ -18,32 +18,66 @@ module Writexlsx class Chart class Area < self include Writexlsx::Utility - def initialize - super(self.class) + def initialize(subtype) + super(subtype) + @subtype = subtype || 'standard' @cross_between = 'midCat' + @show_crosses = false end # # Override the virtual superclass method with a chart specific method. # - def write_chart_type + def write_chart_type(params) # Write the c:areaChart element. - write_area_chart + write_area_chart(params) end # # Write the <c:areaChart> element. # - def write_area_chart + def write_area_chart(params) + series = axes_series(params) + return if series.empty? + + if @subtype == 'percent_stacked' + subtype = 'percentStacked' + else + subtype = @subtype + end @writer.tag_elements('c:areaChart') do # Write the c:grouping element. - write_grouping('standard') + write_grouping(subtype) # Write the series elements. - write_series + series.each {|s| write_series(s)} + + # Write the c:marker element. + write_marker_value + + # Write the c:axId elements + write_axis_ids(params) end + end + + # + # Over-ridden to add % format. TODO. This will be refactored back up to the + # SUPER class later. + # + # Write the <C:numFmt> element. + # + def write_number_format(format_code = nil) + source_linked = 1 + format_code = 'General' if !format_code || format_code.empty? + format_code = '0%' if @subtype == 'percent_stacked' + + attributes = [ + 'formatCode', format_code, + 'sourceLinked', source_linked + ] + @writer.empty_tag('c:numFmt', attributes) end end end end