summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/drawing/d_lbls.rb
blob: b1c010f1b41b3b0f74b208d425c5c6061a16a08d (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
module Axlsx
  #       <c:dLbls>
  #<c:dLblPos val="outEnd"/>
  #<c:showLegendKey val="0"/>
  #<c:showVal val="0"/>
  #<c:showCatName val="1"/>
  #<c:showSerName val="0"/>
  #<c:showPercent val="1"/>
  #<c:showBubbleSize val="0"/>
  #<c:showLeaderLines val="1"/>
  #</c:dLbls>

  #The DLbls class manages serialization of data labels
  class DLbls
    BOOLEAN_ATTRIBUTES = [:show_legend_key, :show_val, :show_cat_name, :show_ser_name, :show_percent, :show_bubble_size, :show_leader_lines]
    
    # creates a new DLbls object
    def initialize(options={})
      d_lbl_pos = :best_fit
      initialize_defaults
      options.each do |o|
        self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
      end

    end
    
    def initialize_defaults
      BOOLEAN_ATTRIBUTES.each do |attr|
        self.send("#{attr}=", false)
      end
    end

    attr_reader :d_lbl_pos

    # @see DLbls#d_lbl_pos
    # Assigns the label postion for this data labels on this chart.
    # Allowed positions are :bestFilt, :b, :ctr, :inBase, :inEnd, :l,
    # :outEnd, :r and :t
    # The default is :best_fit
    # @param [Symbol] label_postion the postion you want to use.
    def d_lbl_pos=(label_position)
      Axlsx::RestrictionValidator.validate 'DLbls#d_lbl_pos',  [:bestFit, :b, :ctr, :inBase, :inEnd, :l, :outEnd, :r, :t], label_position
      @d_lbl_pos = label_position
    end
   
    BOOLEAN_ATTRIBUTES.each do |attr|    
      class_eval %{
      attr_reader :#{attr} 

      def #{attr}=(v)
        Axlsx::validate_boolean(v)
        @#{attr} = v
      end
      }
    end


    # serializes the data labels
    # @return [String]
    def to_xml_string(str = '')
      str << '<c:dLbls>'
      instance_values.each { |name, value| str << "<c:#{Axlsx::camel(name, false)} val='#{value}' />" }
      str << '</c:dLbls>'
    end
  end
end