Module: Writexlsx::Chart::SeriesData
- Included in:
- Writexlsx::Chart
- Defined in:
- lib/write_xlsx/chart/series_data.rb
Instance Method Summary collapse
-
#data_id(full_formula, data) ⇒ Object
Assign an id to a each unique series formula or title/axis formula.
-
#process_names(name = nil, name_formula = nil) ⇒ Object
Switch name and name_formula parameters if required.
Instance Method Details
#data_id(full_formula, data) ⇒ Object
Assign an id to a each unique series formula or title/axis formula. Repeated formulas such as for categories get the same id. If the series or title has user specified data associated with it then that is also stored. This data is used to populate cached Excel data when creating a chart. If there is no user defined data then it will be populated by the parent workbook in Workbook::_add_chart_data
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/write_xlsx/chart/series_data.rb', line 38 def data_id(full_formula, data) # :nodoc: return unless full_formula # Strip the leading '=' from the formula. formula = full_formula.sub(/^=/, '') # Store the data id in a hash keyed by the formula and store the data # in a separate array with the same id. if @formula_ids.has_key?(formula) # Formula already seen. Return existing id. id = @formula_ids[formula] # Store user defined data if it isn't already there. @formula_data[id] ||= data else # Haven't seen this formula before. id = @formula_ids[formula] = @formula_data.size @formula_data << data end id end |
#process_names(name = nil, name_formula = nil) ⇒ Object
Switch name and name_formula parameters if required.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/write_xlsx/chart/series_data.rb', line 16 def process_names(name = nil, name_formula = nil) # :nodoc: # Name looks like a formula, use it to set name_formula. if name.respond_to?(:to_ary) cell = xl_rowcol_to_cell(name[1], name[2], 1, 1) name_formula = "#{quote_sheetname(name[0])}!#{cell}" name = '' elsif name && name =~ /^=[^!]+!\$/ name_formula = name name = '' end [name, name_formula] end |