Class: Axlsx::ScatterSeries

Inherits:
Series
  • Object
show all
Defined in:
lib/axlsx/drawing/scatter_series.rb

Overview

Note:

The recommended way to manage series is to use Chart#add_series

A ScatterSeries defines the x and y position of data in the chart

See Also:

Instance Attribute Summary collapse

Attributes inherited from Series

#chart, #title

Instance Method Summary collapse

Methods inherited from Series

#index, #order, #order=

Methods included from OptionsParser

#parse_options

Constructor Details

#initialize(chart, options = {}) ⇒ ScatterSeries

Creates a new ScatterSeries



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/axlsx/drawing/scatter_series.rb', line 37

def initialize(chart, options = {})
  @xData, @yData = nil
  if options[:smooth].nil?
    # If caller hasn't specified smoothing or not, turn smoothing on or off based on scatter style
    @smooth = [:smooth, :smoothMarker].include?(chart.scatter_style)
  else
    # Set smoothing according to the option provided
    Axlsx::validate_boolean(options[:smooth])
    @smooth = options[:smooth]
  end
  @ln_width = options[:ln_width] unless options[:ln_width].nil?
  @show_marker = [:lineMarker, :marker, :smoothMarker].include?(chart.scatter_style)
  @marker_symbol = :default

  super(chart, options)
  @xData = AxDataSource.new(:tag_name => :xVal, :data => options[:xData]) unless options[:xData].nil?
  @yData = NumDataSource.new({ :tag_name => :yVal, :data => options[:yData] }) unless options[:yData].nil?
end

Instance Attribute Details

#colorString

The fill color for this series. Red, green, and blue is expressed as sequence of hex digits, RRGGBB. A perceptual gamma of 2.2 is used.

Returns:

  • (String)


19
20
21
# File 'lib/axlsx/drawing/scatter_series.rb', line 19

def color
  @color
end

#ln_widthString

Returns:

  • (String)


22
23
24
# File 'lib/axlsx/drawing/scatter_series.rb', line 22

def ln_width
  @ln_width
end

#marker_symbolString

custom marker symbol

Returns:

  • (String)


34
35
36
# File 'lib/axlsx/drawing/scatter_series.rb', line 34

def marker_symbol
  @marker_symbol
end

#show_markerBoolean (readonly)

Line markers presence

Returns:

  • (Boolean)


30
31
32
# File 'lib/axlsx/drawing/scatter_series.rb', line 30

def show_marker
  @show_marker
end

#smoothBoolean

Line smoothing between data points

Returns:

  • (Boolean)


26
27
28
# File 'lib/axlsx/drawing/scatter_series.rb', line 26

def smooth
  @smooth
end

#xDataNamedAxisData (readonly)

The x data for this series.

Returns:

  • (NamedAxisData)


10
11
12
# File 'lib/axlsx/drawing/scatter_series.rb', line 10

def xData
  @xData
end

#yDataNamedAxisData (readonly)

The y data for this series.

Returns:

  • (NamedAxisData)


14
15
16
# File 'lib/axlsx/drawing/scatter_series.rb', line 14

def yData
  @yData
end

Instance Method Details

#to_xml_string(str = '') ⇒ String

Serializes the object

Parameters:

  • str (String) (defaults to: '')

Returns:

  • (String)


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
# File 'lib/axlsx/drawing/scatter_series.rb', line 81

def to_xml_string(str = '')
  super(str) do
    # needs to override the super color here to push in ln/and something else!
    if color
      str << '<c:spPr><a:solidFill>'
      str << ('<a:srgbClr val="' << color << '"/>')
      str << '</a:solidFill>'
      str << '<a:ln><a:solidFill>'
      str << ('<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>')
      str << '</c:spPr>'
      str << '<c:marker>'
      str << '<c:spPr><a:solidFill>'
      str << ('<a:srgbClr val="' << color << '"/>')
      str << '</a:solidFill>'
      str << '<a:ln><a:solidFill>'
      str << ('<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>')
      str << '</c:spPr>'
      str << marker_symbol_xml
      str << '</c:marker>'
    else
      str << "<c:marker>#{marker_symbol_xml}</c:marker>"
    end

    if ln_width
      str << '<c:spPr>'
      str << '<a:ln w="' << ln_width.to_s << '"/>'
      str << '</c:spPr>'
    end
    @xData.to_xml_string(str) unless @xData.nil?
    @yData.to_xml_string(str) unless @yData.nil?
    str << ('<c:smooth val="' << ((smooth) ? '1' : '0') << '"/>')
  end
  str
end