Class: OoxmlParser::Chart

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

Overview

Class for working with Chart data

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

#==, #boolean_attribute_value, #parse_xml, #with_data?

Methods included from OoxmlObjectAttributeHelper

#attribute_enabled?, #option_enabled?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

#initialize(parent: nil) ⇒ Chart

Returns a new instance of Chart.



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 37

def initialize(parent: nil)
  @axis_ids = []
  @type = ''
  @data = []
  @grouping = nil
  @title = nil
  @legend = nil
  @axises = []
  @series = []
  super
end

Instance Attribute Details

#alternate_contentObject

Returns the value of attribute alternate_content.



17
18
19
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 17

def alternate_content
  @alternate_content
end

#axis_idsArray, ValuedChild (readonly)

Returns array axis id.

Returns:



19
20
21
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 19

def axis_ids
  @axis_ids
end

#axisesObject

Returns the value of attribute axises.



17
18
19
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 17

def axises
  @axises
end

#dataObject

Returns the value of attribute data.



17
18
19
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 17

def data
  @data
end

#display_labelsObject

Returns the value of attribute display_labels.



17
18
19
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 17

def display_labels
  @display_labels
end

#groupingObject

Returns the value of attribute grouping.



17
18
19
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 17

def grouping
  @grouping
end

#legendObject

Returns the value of attribute legend.



17
18
19
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 17

def legend
  @legend
end

#pivot_formatsPivotFormats

Returns list of pivot formats.

Returns:



23
24
25
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 23

def pivot_formats
  @pivot_formats
end

#plot_areaPlotArea

Returns plot area data.

Returns:



25
26
27
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 25

def plot_area
  @plot_area
end

#relationshipsRelationships (readonly)

Returns relationships of chart.

Returns:



35
36
37
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 35

def relationships
  @relationships
end

#seriesArray, Series

Returns series of chart.

Returns:

  • (Array, Series)

    series of chart



21
22
23
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 21

def series
  @series
end

#shape_propertiesObject

Returns the value of attribute shape_properties.



17
18
19
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 17

def shape_properties
  @shape_properties
end

#styleChartStyle (readonly)

Returns style of current chart.

Returns:



33
34
35
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 33

def style
  @style
end

#titleObject

Returns the value of attribute title.



17
18
19
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 17

def title
  @title
end

#typeObject

Returns the value of attribute type.



17
18
19
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 17

def type
  @type
end

#vary_colorsTrue, False (readonly)

each data marker in the series has a different color. ECMA-376 (5th Edition). 21.2.2.227

Returns:

  • (True, False)

    This element specifies that



29
30
31
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 29

def vary_colors
  @vary_colors
end

#view_3dView3D

Returns properties of 3D view.

Returns:

  • (View3D)

    properties of 3D view



31
32
33
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 31

def view_3d
  @view_3d
end

Instance Method Details

#parseChart

Parse Chart data

Returns:

  • (Chart)

    result of parsing



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 84

def parse
  chart_xml = parse_xml(root_object.current_xml)
  chart_xml.xpath('*').each do |chart_node|
    case chart_node.name
    when 'chartSpace'
      parse_chart_space(chart_node)
    end
  end
  parse_relationships
  parse_style
  self
end

#parse_properties(chart_prop_node) ⇒ void

This method returns an undefined value.

Parse properties of Chart

Parameters:

  • chart_prop_node (Nokogiri::XML:Element)

    node to parse



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
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 52

def parse_properties(chart_prop_node)
  chart_prop_node.xpath('*').each do |chart_props_node_child|
    case chart_props_node_child.name
    when 'axId'
      @axis_ids << ValuedChild.new(:integer, parent: self).parse(chart_props_node_child)
    when 'grouping'
      @grouping = chart_props_node_child.attribute('val').value.to_sym
    when 'ser'
      @series << Series.new(parent: self).parse(chart_props_node_child)
      val = case @type
            when :point, :bubble
              chart_props_node_child.xpath('c:yVal')[0]
            else
              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)
    when 'dLbls'
      @display_labels = DisplayLabelsProperties.new(parent: self).parse(chart_props_node_child)
    when 'varyColors'
      @vary_colors = option_enabled?(chart_props_node_child)
    end
  end
end