lib/write_xlsx/chart/axis.rb in write_xlsx-0.83.0 vs lib/write_xlsx/chart/axis.rb in write_xlsx-0.85.1

- old
+ new

@@ -9,10 +9,11 @@ include Writexlsx::Utility attr_accessor :defaults attr_accessor :min, :max, :num_format, :position, :major_tick_mark attr_reader :minor_unit, :major_unit, :minor_unit_type, :major_unit_type + attr_reader :display_units_visible, :display_units attr_reader :log_base, :crossing, :position_axis, :label_position, :visible attr_reader :num_format_linked, :num_font, :layout, :interval_unit attr_reader :major_gridlines, :minor_gridlines, :reverse attr_reader :line, :fill, :text_axis # @@ -21,18 +22,20 @@ def merge_with_hash(params) # :nodoc: super args = (defaults || {}).merge(params) [ - :reverse, :min, :max, :minor_unit, :major_unit, :minor_unit_type, - :major_unit_type, :log_base, :crossing, :position_axis, :label_position, - :num_format, :num_format_linked, :interval_unit, :major_tick_mark, - :line, :fill + :reverse, :min, :max, :minor_unit, :major_unit, :minor_unit_type, + :major_unit_type, :log_base, :crossing, :position_axis, + :label_position, :num_format, :num_format_linked, :interval_unit, + :major_tick_mark, :line, :fill ].each { |val| instance_variable_set("@#{val}", args[val]) } @visible = args[:visible] || 1 set_major_minor_gridlines(args) + set_display_units(args) + set_display_units_visible(args) set_position(args) set_position_axis set_font_properties(args) set_axis_name_layout(args) set_axis_line(args) @@ -90,9 +93,49 @@ if args[lines] && ptrue?(args[lines][:visible]) instance_variable_set("@#{lines}", Gridline.new(args[lines])) else instance_variable_set("@#{lines}", nil) end + end + end + + # + # + # Convert user defined display units to internal units. + # + def get_display_units(display_units) + + return unless ptrue?(display_units) + + types = { + 'hundreds' => 'hundreds', + 'thousands' => 'thousands', + 'ten_thousands' => 'tenThousands', + 'hundred_thousands' => 'hundredThousands', + 'millions' => 'millions', + 'ten_millions' => 'tenMillions', + 'hundred_millions' => 'hundredMillions', + 'billions' => 'billions', + 'trillions' => 'trillions' + } + + if types[display_units] + return types[display_units] + else + # warn "Unknown display_units type '$display_units'\n" + return + end + end + + def set_display_units(args) + @display_units = get_display_units(args[:display_units]) + end + + def set_display_units_visible(args) + if args[:display_units_visible] + @display_units_visible = args[:display_units_visible] + else + @display_units_visible = 1; end end def set_position(args) # Only use the first letter of bottom, top, left or right.