Sha256: e0156ff814959d149b587ff238634b6b520b6f835bf4f8d3c35176e18abea677

Contents?: true

Size: 1.85 KB

Versions: 5

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true

module Axlsx
  # A Series defines the common series attributes and is the super class for all concrete series types.
  # @note The recommended way to manage series is to use Chart#add_series
  # @see Worksheet#add_chart
  # @see Chart#add_series
  class Series
    include Axlsx::OptionsParser

    # The chart that owns this series
    # @return [Chart]
    attr_reader :chart

    # The title of the series
    # @return [SeriesTitle]
    attr_reader :title

    # Creates a new series
    # @param [Chart] chart
    # @option options [Integer] order
    # @option options [String] title
    def initialize(chart, options = {})
      @order = nil
      self.chart = chart
      @chart.series << self
      parse_options options
    end

    # The index of this series in the chart's series.
    # @return [Integer]
    def index
      @chart.series.index(self)
    end

    # The order of this series in the chart's series. By default the order is the index of the series.
    # @return [Integer]
    def order
      @order || index
    end

    # @see order
    def order=(v)
      Axlsx.validate_unsigned_int(v)
      @order = v
    end

    # @see title
    def title=(v)
      v = SeriesTitle.new(v) if v.is_a?(String) || v.is_a?(Cell)
      DataTypeValidator.validate "#{self.class}.title", SeriesTitle, v
      @title = v
    end

    private

    # assigns the chart for this series
    def chart=(v)
      DataTypeValidator.validate "Series.chart", Chart, v
      @chart = v
    end

    # Serializes the object
    # @param [String] str
    # @return [String]
    def to_xml_string(str = +'')
      str << '<c:ser>'
      str << '<c:idx val="' << index.to_s << '"/>'
      str << '<c:order val="' << (order || index).to_s << '"/>'
      title.to_xml_string(str) unless title.nil?
      yield if block_given?
      str << '</c:ser>'
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
caxlsx-4.2.0 lib/axlsx/drawing/series.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/caxlsx-4.1.0/lib/axlsx/drawing/series.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/caxlsx-4.1.0/lib/axlsx/drawing/series.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/caxlsx-4.1.0/lib/axlsx/drawing/series.rb
caxlsx-4.1.0 lib/axlsx/drawing/series.rb