Class: Writexlsx::Chart::Axis

Inherits:
Object
  • Object
show all
Includes:
Utility
Defined in:
lib/write_xlsx/chart/axis.rb

Constant Summary

Constants included from Utility

Utility::COL_MAX, Utility::ROW_MAX, Utility::SHEETNAME_MAX, Utility::STR_MAX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utility

#absolute_char, #check_dimensions, #check_dimensions_and_update_max_min_values, #check_parameter, #convert_date_time, delete_files, #float_to_str, #pixels_to_points, #ptrue?, #put_deprecate_message, #row_col_notation, #shape_style_base, #store_col_max_min_values, #store_row_max_min_values, #substitute_cellref, #underline_attributes, #v_shape_attributes_base, #v_shape_style_base, #write_anchor, #write_auto_fill, #write_color, #write_comment_path, #write_div, #write_fill, #write_font, #write_stroke, #xl_cell_to_rowcol, #xl_col_to_name, #xl_range, #xl_range_formula, #xl_rowcol_to_cell, #xml_str

Instance Attribute Details

#crossingObject

Returns the value of attribute crossing.



13
14
15
# File 'lib/write_xlsx/chart/axis.rb', line 13

def crossing
  @crossing
end

#data_idObject

Returns the value of attribute data_id.



10
11
12
# File 'lib/write_xlsx/chart/axis.rb', line 10

def data_id
  @data_id
end

#defaultsObject

Returns the value of attribute defaults.



10
11
12
# File 'lib/write_xlsx/chart/axis.rb', line 10

def defaults
  @defaults
end

#formulaObject

Returns the value of attribute formula.



10
11
12
# File 'lib/write_xlsx/chart/axis.rb', line 10

def formula
  @formula
end

#label_positionObject

Returns the value of attribute label_position.



13
14
15
# File 'lib/write_xlsx/chart/axis.rb', line 13

def label_position
  @label_position
end

#log_baseObject

Returns the value of attribute log_base.



13
14
15
# File 'lib/write_xlsx/chart/axis.rb', line 13

def log_base
  @log_base
end

#major_gridlinesObject

Returns the value of attribute major_gridlines.



15
16
17
# File 'lib/write_xlsx/chart/axis.rb', line 15

def major_gridlines
  @major_gridlines
end

#major_tick_markObject

Returns the value of attribute major_tick_mark.



15
16
17
# File 'lib/write_xlsx/chart/axis.rb', line 15

def major_tick_mark
  @major_tick_mark
end

#major_unitObject

Returns the value of attribute major_unit.



12
13
14
# File 'lib/write_xlsx/chart/axis.rb', line 12

def major_unit
  @major_unit
end

#major_unit_typeObject

Returns the value of attribute major_unit_type.



12
13
14
# File 'lib/write_xlsx/chart/axis.rb', line 12

def major_unit_type
  @major_unit_type
end

#maxObject

Returns the value of attribute max.



11
12
13
# File 'lib/write_xlsx/chart/axis.rb', line 11

def max
  @max
end

#minObject

Returns the value of attribute min.



11
12
13
# File 'lib/write_xlsx/chart/axis.rb', line 11

def min
  @min
end

#minor_gridlinesObject

Returns the value of attribute minor_gridlines.



15
16
17
# File 'lib/write_xlsx/chart/axis.rb', line 15

def minor_gridlines
  @minor_gridlines
end

#minor_unitObject

Returns the value of attribute minor_unit.



12
13
14
# File 'lib/write_xlsx/chart/axis.rb', line 12

def minor_unit
  @minor_unit
end

#minor_unit_typeObject

Returns the value of attribute minor_unit_type.



12
13
14
# File 'lib/write_xlsx/chart/axis.rb', line 12

def minor_unit_type
  @minor_unit_type
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/write_xlsx/chart/axis.rb', line 10

def name
  @name
end

#name_fontObject

Returns the value of attribute name_font.



14
15
16
# File 'lib/write_xlsx/chart/axis.rb', line 14

def name_font
  @name_font
end

#num_fontObject

Returns the value of attribute num_font.



14
15
16
# File 'lib/write_xlsx/chart/axis.rb', line 14

def num_font
  @num_font
end

#num_formatObject

Returns the value of attribute num_format.



14
15
16
# File 'lib/write_xlsx/chart/axis.rb', line 14

def num_format
  @num_format
end

#num_format_linkedObject

Returns the value of attribute num_format_linked.



14
15
16
# File 'lib/write_xlsx/chart/axis.rb', line 14

def num_format_linked
  @num_format_linked
end

#positionObject

Returns the value of attribute position.



13
14
15
# File 'lib/write_xlsx/chart/axis.rb', line 13

def position
  @position
end

#reverseObject

Returns the value of attribute reverse.



10
11
12
# File 'lib/write_xlsx/chart/axis.rb', line 10

def reverse
  @reverse
end

#visibleObject

Returns the value of attribute visible.



13
14
15
# File 'lib/write_xlsx/chart/axis.rb', line 13

def visible
  @visible
end

Instance Method Details

#gridline_properties(args) ⇒ Object

Convert user defined gridline properties to the structure required internally.



121
122
123
124
125
126
127
128
129
# File 'lib/write_xlsx/chart/axis.rb', line 121

def gridline_properties(args)
  # Set the visible property for the gridline.
  gridline = { :_visible => args[:visible] }

  # Set the line properties for the gridline.
  gridline[:_line] = @chart.line_properties(args[:line])

  gridline
end

#merge_with_hash(chart, params) ⇒ Object

Convert user defined axis values into axis instance.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/write_xlsx/chart/axis.rb', line 20

def merge_with_hash(chart, params) # :nodoc:
  @chart    = chart
  args      = (defaults || {}).merge(params)

  @name, @formula = @chart.process_names(args[:name], args[:name_formula])
  @data_id           = @chart.get_data_id(@formula, args[:data])
  @reverse           = args[:reverse]
  @min               = args[:min]
  @max               = args[:max]
  @minor_unit        = args[:minor_unit]
  @major_unit        = args[:major_unit]
  @minor_unit_type   = args[:minor_unit_type]
  @major_unit_type   = args[:major_unit_type]
  @log_base          = args[:log_base]
  @crossing          = args[:crossing]
  @label_position    = args[:label_position]
  @num_format        = args[:num_format]
  @num_format_linked = args[:num_format_linked]
  @visible           = args[:visible] || 1

  # Map major/minor_gridlines properties.
  [:major_gridlines, :minor_gridlines].each do |lines|
    if args[lines] && ptrue?(args[lines][:visible])
      instance_variable_set("@#{lines}", gridline_properties(args[lines]))
    else
      instance_variable_set("@#{lines}", nil)
    end
  end
  @major_tick_mark   = args[:major_tick_mark]

  # Only use the first letter of bottom, top, left or right.
  @position = args[:position]
  @position = @position.downcase[0, 1] if @position

  # Set the font properties if present.
  @num_font  = @chart.convert_font_args(args[:num_font])
  @name_font = @chart.convert_font_args(args[:name_font])
end

#write_cat_number_format(writer, cat_has_num_fmt) ⇒ Object

Write the <c:numFmt> element. Special case handler for category axes which don’t always have a number format.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/write_xlsx/chart/axis.rb', line 90

def write_cat_number_format(writer, cat_has_num_fmt)
  source_linked  = 1
  default_format = true

  # Check if a user defined number format has been set.
  if @defaults && @num_format != @defaults[:num_format]
    source_linked  = 0
    default_format = false
  end

  # User override of linkedSource.
  if @num_format_linked
    source_linked = 1
  end

  # Skip if cat doesn't have a num format (unless it is non-default).
  if !cat_has_num_fmt && default_format
    return ''
  end

  attributes = [
                'formatCode',   @num_format,
                'sourceLinked', source_linked,
               ]

  writer.empty_tag('c:numFmt', attributes)
end

#write_number_format(writer) ⇒ Object

Write the <c:numberFormat> element. Note: It is assumed that if a user defined number format is supplied (i.e., non-default) then the sourceLinked attribute is 0. The user can override this if required.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/write_xlsx/chart/axis.rb', line 65

def write_number_format(writer) # :nodoc:
  source_linked = 1

  # Check if a user defined number format has been set.
  if @defaults && @num_format != @defaults[:num_format]
    source_linked = 0
  end

  # User override of sourceLinked.
  if ptrue?(@num_format_linked)
    source_linked = 1
  end

  attributes = [
                'formatCode',   @num_format,
                'sourceLinked', source_linked
               ]

  writer.empty_tag('c:numFmt', attributes)
end