Class: Writexlsx::Chart::Stock

Inherits:
Writexlsx::Chart show all
Includes:
Utility
Defined in:
lib/write_xlsx/chart/stock.rb

Overview

The default Stock chart is an High-Low-Close chart. A series must be added for each of these data sources.

Constant Summary

Constants included from Utility

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

Instance Attribute Summary

Attributes inherited from Writexlsx::Chart

#already_inserted, #axis2_ids, #combined, #date_category, #embedded, #formula_data, #formula_ids, #height, #id, #index, #label_position_default, #label_positions, #name, #palette, #protection, #series_index, #width, #writer, #x2_axis, #x_offset, #x_scale, #y2_axis, #y_offset, #y_scale

Instance Method Summary collapse

Methods included from Utility

#absolute_char, #check_dimensions, #check_dimensions_and_update_max_min_values, #check_parameter, #convert_date_time, #dash_types, delete_files, #fill_properties, #float_to_str, #layout_properties, #line_fill_properties, #line_properties, #palette_color, #pixels_to_points, #process_workbook_options, #ptrue?, #put_deprecate_message, #quote_sheetname, #r_id_attributes, #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, #value_or_raise, #write_anchor, #write_auto_fill, #write_color, #write_comment_path, #write_div, #write_fill, #write_font, #write_stroke, #write_xml_declaration, #xl_cell_to_rowcol, #xl_col_to_name, #xl_range, #xl_range_formula, #xl_rowcol_to_cell, #xml_str

Methods inherited from Writexlsx::Chart

#add_series, #already_inserted?, #assemble_xml_file, #combine, #convert_font_args, #data_id, factory, #is_secondary?, #params_to_font, #process_names, #set_chartarea, #set_drop_lines, #set_embedded_config_data, #set_high_low_lines, #set_legend, #set_plotarea, #set_size, #set_style, #set_table, #set_title, #set_up_down_bars, #set_x2_axis, #set_x_axis, #set_xml_writer, #set_y2_axis, #set_y_axis, #show_blanks_as, #show_hidden_data, #write_bar_chart, #write_val_axis

Constructor Details

#initialize(subtype) ⇒ Stock


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
# File 'lib/write_xlsx/chart/stock.rb', line 27

def initialize(subtype)
  super(subtype)
  @show_crosses  = false
  @hi_low_lines  = Chartline.new({})
  @date_category = true

  # Override and reset the default axis values.
  @x_axis.defaults[:num_format] = 'dd/mm/yyyy'
  @x2_axis.defaults[:num_format] = 'dd/mm/yyyy'
  set_x_axis
  set_x2_axis

  # Set the available data label positions for this chart type.
  @label_position_default = 'right'
  @label_positions = {
    'center'      => 'ctr',
    'right'       => 'r',
    'left'        => 'l',
    'above'       => 't',
    'below'       => 'b',
    # For backward compatibility.
    'top'         => 't',
    'bottom'      => 'b',
  }
end

Instance Method Details

#modify_series_formattingObject

Add default formatting to the series data.


100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/write_xlsx/chart/stock.rb', line 100

def modify_series_formatting
  array = []
  @series.each_with_index do |series, index|
    if index % 4 != 3
      series.line = {
        :width    => 2.25,
        :none     => 1,
        :_defined => 1
      } unless series.line_defined?

      if index % 4 == 2
        series.marker = Marker.new(:type => 'dot', :size => 3)
      else
        series.marker = Marker.new(:type => 'none')
      end unless ptrue?(series.marker)
    end
    array << series
  end
  @series = array
end

#write_chart_type(params) ⇒ Object

Override the virtual superclass method with a chart specific method.


56
57
58
59
# File 'lib/write_xlsx/chart/stock.rb', line 56

def write_chart_type(params)
  # Write the c:areaChart element.
  write_stock_chart(params)
end

#write_stock_chart(params) ⇒ Object

Write the <c:stockChart> element. Overridden to add hi_low_lines(). TODO. Refactor up into the SUPER class


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/write_xlsx/chart/stock.rb', line 65

def write_stock_chart(params)
  if params[:primary_axes] == 1
    series = get_primary_axes_series
  else
    series = get_secondary_axes_series
  end
  return if series.empty?

  # Add default formatting to the series data.
  modify_series_formatting

  @writer.tag_elements('c:stockChart') do
    # Write the series elements.
    series.each {|s| write_series(s)}

    # Write the c:dtopLines element.
    write_drop_lines

    # Write the c:hiLowLines element.
    write_hi_low_lines if ptrue?(params[:primary_axes])

    # Write the c:upDownBars element.
    write_up_down_bars

    # Write the c:marker element.
    write_marker_value

    # Write the c:axId elements
    write_axis_ids(params)
  end
end