File: test_chart.c

package info (click to toggle)
libxlsxwriter 1.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,888 kB
  • sloc: ansic: 65,861; python: 2,106; makefile: 693; perl: 229; sh: 224; xml: 168; cpp: 73; javascript: 5
file content (157 lines) | stat: -rw-r--r-- 5,425 bytes parent folder | download
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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
 * Tests for the lib_xlsx_writer library.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 * Copyright 2014-2026, John McNamara, jmcnamara@cpan.org.
 *
 */

#include "../ctest.h"
#include "../helper.h"

#include "../../../include/xlsxwriter/chart.h"

// Test assembling a complete Chart file.
CTEST(chart, chart01) {

    lxw_chart_series *series1;
    lxw_chart_series *series2;

    uint8_t data[5][3] = {
        {1, 2,  3},
        {2, 4,  6},
        {3, 6,  9},
        {4, 8,  12},
        {5, 10, 15}
    };



    char* got;
    char exp[] =
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
        "<c:chartSpace xmlns:c=\"http://schemas.openxmlformats.org/drawingml/2006/chart\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
          "<c:lang val=\"en-US\"/>"
          "<c:chart>"
            "<c:plotArea>"
              "<c:layout/>"
              "<c:barChart>"
                "<c:barDir val=\"bar\"/>"
                "<c:grouping val=\"clustered\"/>"
                "<c:ser>"
                  "<c:idx val=\"0\"/>"
                  "<c:order val=\"0\"/>"
                  "<c:val>"
                    "<c:numRef>"
                      "<c:f>Sheet1!$A$1:$A$5</c:f>"
                      "<c:numCache>"
                        "<c:formatCode>General</c:formatCode>"
                        "<c:ptCount val=\"5\"/>"
                        "<c:pt idx=\"0\">"
                          "<c:v>1</c:v>"
                        "</c:pt>"
                        "<c:pt idx=\"1\">"
                          "<c:v>2</c:v>"
                        "</c:pt>"
                        "<c:pt idx=\"2\">"
                          "<c:v>3</c:v>"
                        "</c:pt>"
                        "<c:pt idx=\"3\">"
                          "<c:v>4</c:v>"
                        "</c:pt>"
                        "<c:pt idx=\"4\">"
                          "<c:v>5</c:v>"
                        "</c:pt>"
                      "</c:numCache>"
                    "</c:numRef>"
                  "</c:val>"
                "</c:ser>"
                "<c:ser>"
                  "<c:idx val=\"1\"/>"
                  "<c:order val=\"1\"/>"
                  "<c:val>"
                    "<c:numRef>"
                      "<c:f>Sheet1!$B$1:$B$5</c:f>"
                      "<c:numCache>"
                        "<c:formatCode>General</c:formatCode>"
                        "<c:ptCount val=\"5\"/>"
                        "<c:pt idx=\"0\">"
                          "<c:v>2</c:v>"
                        "</c:pt>"
                        "<c:pt idx=\"1\">"
                          "<c:v>4</c:v>"
                        "</c:pt>"
                        "<c:pt idx=\"2\">"
                          "<c:v>6</c:v>"
                        "</c:pt>"
                        "<c:pt idx=\"3\">"
                          "<c:v>8</c:v>"
                        "</c:pt>"
                        "<c:pt idx=\"4\">"
                          "<c:v>10</c:v>"
                        "</c:pt>"
                      "</c:numCache>"
                    "</c:numRef>"
                  "</c:val>"
                "</c:ser>"
                "<c:axId val=\"50010001\"/>"
                "<c:axId val=\"50010002\"/>"
              "</c:barChart>"
              "<c:catAx>"
                "<c:axId val=\"50010001\"/>"
                "<c:scaling>"
                  "<c:orientation val=\"minMax\"/>"
                "</c:scaling>"
                "<c:axPos val=\"l\"/>"
                "<c:tickLblPos val=\"nextTo\"/>"
                "<c:crossAx val=\"50010002\"/>"
                "<c:crosses val=\"autoZero\"/>"
                "<c:auto val=\"1\"/>"
                "<c:lblAlgn val=\"ctr\"/>"
                "<c:lblOffset val=\"100\"/>"
              "</c:catAx>"
              "<c:valAx>"
                "<c:axId val=\"50010002\"/>"
                "<c:scaling>"
                  "<c:orientation val=\"minMax\"/>"
                "</c:scaling>"
                "<c:axPos val=\"b\"/>"
                "<c:majorGridlines/>"
                "<c:numFmt formatCode=\"General\" sourceLinked=\"1\"/>"
                "<c:tickLblPos val=\"nextTo\"/>"
                "<c:crossAx val=\"50010001\"/>"
                "<c:crosses val=\"autoZero\"/>"
                "<c:crossBetween val=\"between\"/>"
              "</c:valAx>"
            "</c:plotArea>"
            "<c:legend>"
              "<c:legendPos val=\"r\"/>"
              "<c:layout/>"
            "</c:legend>"
            "<c:plotVisOnly val=\"1\"/>"
          "</c:chart>"
          "<c:printSettings>"
            "<c:headerFooter/>"
            "<c:pageMargins b=\"0.75\" l=\"0.7\" r=\"0.7\" t=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
            "<c:pageSetup/>"
          "</c:printSettings>"
        "</c:chartSpace>";

    FILE* testfile = lxw_tmpfile(NULL);

    lxw_chart *chart = lxw_chart_new(LXW_CHART_BAR);
    chart->file = testfile;

    series1 = chart_add_series(chart, NULL, "Sheet1!$A$1:$A$5");
    series2 = chart_add_series(chart, NULL, "Sheet1!$B$1:$B$5");

    lxw_chart_add_data_cache(series1->values, data[0], 5, 3, 0);
    lxw_chart_add_data_cache(series2->values, data[0], 5, 3, 1);

    lxw_chart_assemble_xml_file(chart);

    RUN_XLSX_STREQ_SHORT(exp, got);

    lxw_chart_free(chart);
}