summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/drawing/named_axis_data.rb
blob: 2272976cf3c7a81b962f409e74e08b9ed09610a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# encoding: UTF-8
module Axlsx
  # The NamedAxisData class manages the values for a chart value series.
  class NamedAxisData < CatAxisData

    # creates a new NamedAxisData Object
    # @param [String] name The serialized node name for the axis data object
    # @param [Array] The data to associate with the axis data object
    def initialize(name, data=[])
      super(data)
      @name = name
    end

    # Serializes the object
    # @param [String] str
    # @return [String]
    def to_xml_string(str = '')
      str << '<c:' << @name.to_s << '>'
      str << '<c:numRef>'
      str << '<c:f>' << Axlsx::cell_range(@list) << '</c:f>'
      str << '<c:numCache>'
      str << '<c:formatCode>General</c:formatCode>'
      str << '<c:ptCount val="' << size.to_s << '"/>'
      each_with_index do |item, index|
        v = item.is_a?(Cell) ?  item.value.to_s : item
        str << '<c:pt idx="' << index.to_s << '"><c:v>' << v.to_s << '</c:v></c:pt>'
      end
      str << '</c:numCache>'
      str << '</c:numRef>'
      str << '</c:' << @name.to_s << '>'
    end

  end

end