summaryrefslogtreecommitdiffhomepage
path: root/test/drawing/tc_scatter_chart.rb
blob: 9a7a30732e76d09a4a371bef04a4e00eb9236786 (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
# frozen_string_literal: true

require 'tc_helper'

class TestScatterChart < Test::Unit::TestCase
  def setup
    @p = Axlsx::Package.new
    @chart = nil
    @p.workbook.add_worksheet do |sheet|
      sheet.add_row ["First",  1,  5, 7, 9]
      sheet.add_row ["",       1, 25, 49, 81]
      sheet.add_row ["Second", 5, 2, 14, 9]
      sheet.add_row ["",       5, 10, 15, 20]
      sheet.add_chart(Axlsx::ScatterChart, title: "example 7: Scatter Chart") do |chart|
        chart.start_at 0, 4
        chart.end_at 10, 19
        chart.add_series xData: sheet["B1:E1"], yData: sheet["B2:E2"], title: sheet["A1"]
        chart.add_series xData: sheet["B3:E3"], yData: sheet["B4:E4"], title: sheet["A3"]
        @chart = chart
      end
    end
  end

  def teardown; end

  def test_scatter_style
    @chart.scatterStyle = :marker

    assert_equal(:marker, @chart.scatterStyle)
    assert_raise(ArgumentError) { @chart.scatterStyle = :buckshot }
  end

  def test_initialization
    assert_equal(:lineMarker, @chart.scatterStyle, "scatterStyle defualt incorrect")
    assert_equal(@chart.series_type, Axlsx::ScatterSeries, "series type incorrect")
    assert(@chart.xValAxis.is_a?(Axlsx::ValAxis), "independant value axis not created")
    assert(@chart.yValAxis.is_a?(Axlsx::ValAxis), "dependant value axis not created")
  end

  def test_to_xml_string
    schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
    doc = Nokogiri::XML(@chart.to_xml_string)
    errors = []
    schema.validate(doc).each do |error|
      errors.push error
      puts error.message
    end

    assert_empty(errors, "error free validation")
  end
end