mirror of
https://github.com/jmcnamara/libxlsxwriter
synced 2025-03-28 21:13:14 +00:00
Initial working category axis.
This commit is contained in:
parent
a68075c07e
commit
e32b664316
1
.indent.pro
vendored
1
.indent.pro
vendored
@ -82,6 +82,7 @@
|
||||
-T lxw_row_col_options
|
||||
-T lxw_row_t
|
||||
-T lxw_selection
|
||||
-T lxw_series_data_point
|
||||
-T lxw_series_range
|
||||
-T lxw_sst
|
||||
-T lxw_styles
|
||||
|
@ -35,7 +35,6 @@ typedef struct lxw_series_range {
|
||||
uint16_t first_col;
|
||||
uint16_t last_col;
|
||||
|
||||
uint8_t has_data_cache;
|
||||
uint16_t num_data_points;
|
||||
struct lxw_series_data_points *data_cache;
|
||||
|
||||
@ -72,6 +71,8 @@ typedef struct lxw_chart {
|
||||
uint32_t axis_id_3;
|
||||
uint32_t axis_id_4;
|
||||
|
||||
uint8_t cat_has_num_fmt;
|
||||
|
||||
struct lxw_chart_series_list *series_list;
|
||||
|
||||
STAILQ_ENTRY (lxw_chart) list_pointers;
|
||||
|
39
src/chart.c
39
src/chart.c
@ -391,6 +391,27 @@ _chart_write_num_ref(lxw_chart *self, lxw_series_range *range)
|
||||
lxw_xml_end_tag(self->file, "c:numRef");
|
||||
}
|
||||
|
||||
/*
|
||||
* Write the <c:cat> element.
|
||||
*/
|
||||
STATIC void
|
||||
_chart_write_cat(lxw_chart *self, lxw_chart_series *series)
|
||||
{
|
||||
/* Ignore <c:cat> elements for charts without category values. */
|
||||
if (!series->categories->formula)
|
||||
return;
|
||||
|
||||
/* TODO */
|
||||
self->cat_has_num_fmt = LXW_TRUE;
|
||||
|
||||
lxw_xml_start_tag(self->file, "c:cat", NULL);
|
||||
|
||||
/* Write the c:numRef element. */
|
||||
_chart_write_num_ref(self, series->categories);
|
||||
|
||||
lxw_xml_end_tag(self->file, "c:cat");
|
||||
}
|
||||
|
||||
/*
|
||||
* Write the <c:val> element.
|
||||
*/
|
||||
@ -421,6 +442,9 @@ _chart_write_ser(lxw_chart *self, lxw_chart_series *series)
|
||||
/* Write the c:order element. */
|
||||
_chart_write_order(self, index);
|
||||
|
||||
/* Write the c:cat element. */
|
||||
_chart_write_cat(self, series);
|
||||
|
||||
/* Write the c:val element. */
|
||||
_chart_write_val(self, series);
|
||||
|
||||
@ -765,6 +789,10 @@ _chart_write_cat_axis(lxw_chart *self)
|
||||
/* Write the c:axPos element. */
|
||||
_chart_write_axis_pos(self, "l");
|
||||
|
||||
/* Write the c:numFmt element. */
|
||||
if (self->cat_has_num_fmt)
|
||||
_chart_write_num_fmt(self);
|
||||
|
||||
/* Write the c:tickLblPos element. */
|
||||
_chart_write_tick_lbl_pos(self);
|
||||
|
||||
@ -1013,8 +1041,19 @@ chart_add_series(lxw_chart *self, char *categories, char *values)
|
||||
series->values = calloc(1, sizeof(lxw_series_range));
|
||||
GOTO_LABEL_ON_MEM_ERROR(series->values, mem_error);
|
||||
|
||||
if (categories) {
|
||||
if (categories[0] == '=')
|
||||
series->categories->formula = lxw_strdup(categories + 1);
|
||||
else
|
||||
series->categories->formula = lxw_strdup(categories);
|
||||
}
|
||||
|
||||
if (values) {
|
||||
if (values[0] == '=')
|
||||
series->values->formula = lxw_strdup(values + 1);
|
||||
else
|
||||
series->values->formula = lxw_strdup(values);
|
||||
}
|
||||
|
||||
lxw_chart_init_data_cache(series->categories);
|
||||
lxw_chart_init_data_cache(series->values);
|
||||
|
@ -14,9 +14,10 @@ int main() {
|
||||
lxw_workbook *workbook = new_workbook("test_chart_bar01.xlsx");
|
||||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
||||
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_BAR);
|
||||
lxw_chart_series *series1;
|
||||
lxw_chart_series *series2;
|
||||
int row, col;
|
||||
|
||||
/* For testing, copy the randomly generated axis ids in the target file. */
|
||||
chart->axis_id_1 = 64052224;
|
||||
chart->axis_id_2 = 64055552;
|
||||
|
||||
uint8_t data[5][3] = {
|
||||
{1, 2, 3},
|
||||
@ -26,19 +27,22 @@ int main() {
|
||||
{5, 10, 15}
|
||||
};
|
||||
|
||||
int row, col;
|
||||
for (row = 0; row < 5; row++)
|
||||
for (col = 0; col < 3; col++)
|
||||
worksheet_write_number(worksheet, row, col, data[row][col] , NULL);
|
||||
|
||||
series1 = chart_add_series(chart, NULL, "Sheet1!$A$1:$A$5");
|
||||
series2 = chart_add_series(chart, NULL, "Sheet1!$B$1:$B$5");
|
||||
|
||||
|
||||
/* Add the cached data for testing. */
|
||||
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_series *series1 = chart_add_series(chart, "=Sheet1!$A$1:$A$5", "=Sheet1!$B$1:$B$5");
|
||||
lxw_chart_series *series2 = chart_add_series(chart, "=Sheet1!$A$1:$A$5", "=Sheet1!$C$1:$C$5");
|
||||
|
||||
worksheet_insert_chart(worksheet, CELL("E9"), chart);
|
||||
|
||||
/* Add cache data for testing. */
|
||||
lxw_chart_add_data_cache(series1->categories, data[0], 5, 3, 0);
|
||||
lxw_chart_add_data_cache(series2->categories, data[0], 5, 3, 0);
|
||||
lxw_chart_add_data_cache(series1->values, data[0], 5, 3, 1);
|
||||
lxw_chart_add_data_cache(series2->values, data[0], 5, 3, 2);
|
||||
|
||||
|
||||
return workbook_close(workbook);
|
||||
}
|
||||
|
47
test/functional/src/test_chart_bar05.c
Normal file
47
test/functional/src/test_chart_bar05.c
Normal file
@ -0,0 +1,47 @@
|
||||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* Copyright 2014-2015, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xlsxwriter.h"
|
||||
|
||||
int main() {
|
||||
|
||||
lxw_workbook *workbook = new_workbook("test_chart_bar05.xlsx");
|
||||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
||||
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_BAR);
|
||||
|
||||
/* For testing, copy the randomly generated axis ids in the target file. */
|
||||
chart->axis_id_1 = 64264064;
|
||||
chart->axis_id_2 = 64447232;
|
||||
|
||||
uint8_t data[5][3] = {
|
||||
{1, 2, 3},
|
||||
{2, 4, 6},
|
||||
{3, 6, 9},
|
||||
{4, 8, 12},
|
||||
{5, 10, 15}
|
||||
};
|
||||
|
||||
int row, col;
|
||||
for (row = 0; row < 5; row++)
|
||||
for (col = 0; col < 3; col++)
|
||||
worksheet_write_number(worksheet, row, col, data[row][col] , NULL);
|
||||
|
||||
lxw_chart_series *series1 = chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
|
||||
lxw_chart_series *series2 = chart_add_series(chart, NULL, "=Sheet1!$B$1:$B$5");
|
||||
lxw_chart_series *series3 = chart_add_series(chart, NULL, "=Sheet1!$C$1:$C$5");
|
||||
|
||||
/* Add cache data for testing. */
|
||||
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_add_data_cache(series3->values, data[0], 5, 3, 2);
|
||||
|
||||
worksheet_insert_chart(worksheet, CELL("E9"), chart);
|
||||
|
||||
return workbook_close(workbook);
|
||||
}
|
44
test/functional/src/test_chart_bar51.c
Normal file
44
test/functional/src/test_chart_bar51.c
Normal file
@ -0,0 +1,44 @@
|
||||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* Copyright 2014-2015, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xlsxwriter.h"
|
||||
|
||||
int main() {
|
||||
|
||||
lxw_workbook *workbook = new_workbook("test_chart_bar51.xlsx");
|
||||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
||||
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_BAR);
|
||||
lxw_chart_series *series1;
|
||||
lxw_chart_series *series2;
|
||||
int row, col;
|
||||
|
||||
uint8_t data[5][3] = {
|
||||
{1, 2, 3},
|
||||
{2, 4, 6},
|
||||
{3, 6, 9},
|
||||
{4, 8, 12},
|
||||
{5, 10, 15}
|
||||
};
|
||||
|
||||
for (row = 0; row < 5; row++)
|
||||
for (col = 0; col < 3; col++)
|
||||
worksheet_write_number(worksheet, row, col, data[row][col] , NULL);
|
||||
|
||||
series1 = chart_add_series(chart, NULL, "Sheet1!$A$1:$A$5");
|
||||
series2 = chart_add_series(chart, NULL, "Sheet1!$B$1:$B$5");
|
||||
|
||||
|
||||
/* Add the cached data for testing. */
|
||||
lxw_chart_add_data_cache(series1->values, data[0], 5, 3, 0);
|
||||
lxw_chart_add_data_cache(series2->values, data[0], 5, 3, 1);
|
||||
|
||||
worksheet_insert_chart(worksheet, CELL("E9"), chart);
|
||||
|
||||
return workbook_close(workbook);
|
||||
}
|
@ -16,5 +16,11 @@ class TestCompareXLSXFiles(base_test_class.XLSXBaseTest):
|
||||
def test_chart_bar01(self):
|
||||
self.run_exe_test('test_chart_bar01')
|
||||
|
||||
def test_chart_bar05(self):
|
||||
self.run_exe_test('test_chart_bar05')
|
||||
|
||||
def test_chart_bar51(self):
|
||||
self.run_exe_test('test_chart_bar51')
|
||||
|
||||
|
||||
|
||||
|
Binary file not shown.
BIN
test/functional/xlsx_files/chart_bar05.xlsx
Normal file
BIN
test/functional/xlsx_files/chart_bar05.xlsx
Normal file
Binary file not shown.
BIN
test/functional/xlsx_files/chart_bar51.xlsx
Normal file
BIN
test/functional/xlsx_files/chart_bar51.xlsx
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user