Class: OoxmlParser::Chart

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

#==, add_to_xmls_stack, copy_file_and_rename_to_zip, current_xml, dir, encrypted_file?, get_link_from_rels, unzip_file, #with_data?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

#initializeChart

Returns a new instance of Chart.



17
18
19
20
21
22
23
24
25
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 17

def initialize
  @type = ''
  @data = []
  @grouping = nil
  @title = nil
  @legend = nil
  @axises = []
  @series = []
end

Instance Attribute Details

#alternate_contentObject

Returns the value of attribute alternate_content.



11
12
13
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 11

def alternate_content
  @alternate_content
end

#axisesObject

Returns the value of attribute axises.



11
12
13
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 11

def axises
  @axises
end

#dataObject

Returns the value of attribute data.



11
12
13
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 11

def data
  @data
end

#display_labelsObject

Returns the value of attribute display_labels.



11
12
13
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 11

def display_labels
  @display_labels
end

#groupingObject

Returns the value of attribute grouping.



11
12
13
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 11

def grouping
  @grouping
end

#legendObject

Returns the value of attribute legend.



11
12
13
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 11

def legend
  @legend
end

#seriesArray, Series

Returns series of chart.

Returns:

  • (Array, Series)

    series of chart



13
14
15
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 13

def series
  @series
end

#shape_propertiesObject

Returns the value of attribute shape_properties.



11
12
13
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 11

def shape_properties
  @shape_properties
end

#titleObject

Returns the value of attribute title.



11
12
13
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 11

def title
  @title
end

#typeObject

Returns the value of attribute type.



11
12
13
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 11

def type
  @type
end

#view_3dView3D

Returns properties of 3D view.

Returns:

  • (View3D)

    properties of 3D view



15
16
17
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 15

def view_3d
  @view_3d
end

Class Method Details

.parseObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 49

def self.parse
  chart = Chart.new
  chart_xml = Nokogiri::XML(File.open(OOXMLDocumentObject.current_xml))
  chart_xml.xpath('*').each do |chart_node|
    case chart_node.name
    when 'chartSpace'
      chart_node.xpath('*').each do |chart_space_node_child|
        case chart_space_node_child.name
        when 'AlternateContent'
          chart.alternate_content = AlternateContent.new(parent: chart).parse(chart_space_node_child)
        when 'spPr'
          chart.shape_properties = DocxShapeProperties.new(parent: chart).parse(chart_space_node_child)
        when 'chart'
          chart_space_node_child.xpath('*').each do |chart_node_child|
            case chart_node_child.name
            when 'plotArea'
              chart_node_child.xpath('*').each do |plot_area_node_child|
                next unless chart.type.empty?
                case plot_area_node_child.name
                when 'barChart'
                  chart.type = :bar
                  bar_dir_node = plot_area_node_child.xpath('c:barDir')
                  chart.type = :column if bar_dir_node.first.attribute('val').value == 'col'
                  chart.parse_properties(plot_area_node_child)
                when 'lineChart'
                  chart.type = :line
                  chart.parse_properties(plot_area_node_child)
                when 'areaChart'
                  chart.type = :area
                  chart.parse_properties(plot_area_node_child)
                when 'bubbleChart'
                  chart.type = :bubble
                  chart.parse_properties(plot_area_node_child)
                when 'doughnutChart'
                  chart.type = :doughnut
                  chart.parse_properties(plot_area_node_child)
                when 'pieChart'
                  chart.type = :pie
                  chart.parse_properties(plot_area_node_child)
                when 'scatterChart'
                  chart.type = :point
                  chart.parse_properties(plot_area_node_child)
                when 'radarChart'
                  chart.type = :radar
                  chart.parse_properties(plot_area_node_child)
                when 'stockChart'
                  chart.type = :stock
                  chart.parse_properties(plot_area_node_child)
                when 'surface3DChart'
                  chart.type = :surface_3d
                  chart.parse_properties(plot_area_node_child)
                when 'line3DChart'
                  chart.type = :line_3d
                  chart.parse_properties(plot_area_node_child)
                when 'bar3DChart'
                  chart.type = :bar_3d
                  chart.parse_properties(plot_area_node_child)
                when 'pie3DChart'
                  chart.type = :pie_3d
                  chart.parse_properties(plot_area_node_child)
                end
              end
              chart_node_child.xpath('*').each do |plot_area_node_child|
                case plot_area_node_child.name
                when 'catAx', 'valAx'
                  chart.axises << ChartAxis.new(parent: chart).parse(plot_area_node_child)
                end
              end
            when 'title'
              chart.title = ChartAxisTitle.new(parent: chart).parse(chart_node_child)
            when 'legend'
              chart.legend = ChartLegend.new(parent: chart).parse(chart_node_child)
            when 'view3D'
              chart.view_3d = View3D.new(parent: chart).parse(chart_node_child)
            end
          end
        end
      end
    end
  end
  chart
end

Instance Method Details

#parse_properties(chart_prop_node) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 27

def parse_properties(chart_prop_node)
  chart_prop_node.xpath('*').each do |chart_props_node_child|
    case chart_props_node_child.name
    when 'grouping'
      @grouping = chart_props_node_child.attribute('val').value.to_sym
    when 'ser'
      @series << Series.new(parent: self).parse(chart_props_node_child)
      case @type
      when :point, :bubble
        val = chart_props_node_child.xpath('c:yVal')[0]
      else
        val = chart_props_node_child.xpath('c:val')[0]
      end
      next unless val
      next if val.xpath('c:numRef').empty?
      @data << ChartCellsRange.new(parent: self).parse(val.xpath('c:numRef').first).dup
    when 'dLbls'
      @display_labels = DisplayLabelsProperties.new(parent: self).parse(chart_props_node_child)
    end
  end
end