mirror of
https://github.com/jmcnamara/libxlsxwriter.git
synced 2026-05-21 06:45:21 -06:00
Added support for chart line smoothing.
This commit is contained in:
parent
fb9190f360
commit
a128d70074
14 changed files with 283 additions and 9 deletions
|
|
@ -724,6 +724,7 @@ typedef struct lxw_chart_series {
|
|||
lxw_chart_point *points;
|
||||
uint16_t point_count;
|
||||
|
||||
uint8_t smooth;
|
||||
uint8_t invert_if_negative;
|
||||
|
||||
STAILQ_ENTRY (lxw_chart_series) list_pointers;
|
||||
|
|
@ -1333,6 +1334,8 @@ void chart_series_set_marker_pattern(lxw_chart_series *series,
|
|||
lxw_error chart_series_set_points(lxw_chart_series *series,
|
||||
lxw_chart_point *points[]);
|
||||
|
||||
void chart_series_set_smooth(lxw_chart_series *series, uint8_t smooth);
|
||||
|
||||
/**
|
||||
* @brief Set the name caption of the an axis.
|
||||
*
|
||||
|
|
@ -2334,7 +2337,6 @@ void chart_plotarea_set_pattern(lxw_chart *chart, lxw_chart_pattern *pattern);
|
|||
* to the base chart type. They can not be defined by the `chart_set_style()``
|
||||
* function.
|
||||
*
|
||||
*
|
||||
*/
|
||||
void chart_set_style(lxw_chart *chart, uint8_t style_id);
|
||||
|
||||
|
|
|
|||
34
src/chart.c
34
src/chart.c
|
|
@ -2070,14 +2070,16 @@ _chart_write_marker_value(lxw_chart *self)
|
|||
* Write the <c:smooth> element.
|
||||
*/
|
||||
STATIC void
|
||||
_chart_write_smooth(lxw_chart *self)
|
||||
_chart_write_smooth(lxw_chart *self, uint8_t smooth)
|
||||
{
|
||||
struct xml_attribute_list attributes;
|
||||
struct xml_attribute *attribute;
|
||||
char val[] = "1";
|
||||
|
||||
if (!smooth)
|
||||
return;
|
||||
|
||||
LXW_INIT_ATTRIBUTES();
|
||||
LXW_PUSH_ATTRIBUTES_STR("val", val);
|
||||
LXW_PUSH_ATTRIBUTES_STR("val", "1");
|
||||
|
||||
lxw_xml_empty_tag(self->file, "c:smooth", &attributes);
|
||||
|
||||
|
|
@ -2211,6 +2213,10 @@ _chart_write_ser(lxw_chart *self, lxw_chart_series *series)
|
|||
/* Write the c:val element. */
|
||||
_chart_write_val(self, series);
|
||||
|
||||
/* Write the c:smooth element. */
|
||||
if (self->is_scatter_chart || self->type == LXW_CHART_LINE)
|
||||
_chart_write_smooth(self, series->smooth);
|
||||
|
||||
lxw_xml_end_tag(self->file, "c:ser");
|
||||
}
|
||||
|
||||
|
|
@ -2249,11 +2255,8 @@ _chart_write_xval_ser(lxw_chart *self, lxw_chart_series *series)
|
|||
/* Write the yVal element. */
|
||||
_chart_write_y_val(self, series);
|
||||
|
||||
if (self->type == LXW_CHART_SCATTER_SMOOTH
|
||||
|| self->type == LXW_CHART_SCATTER_SMOOTH_WITH_MARKERS) {
|
||||
/* Write the c:smooth element. */
|
||||
_chart_write_smooth(self);
|
||||
}
|
||||
/* Write the c:smooth element. */
|
||||
_chart_write_smooth(self, series->smooth);
|
||||
|
||||
lxw_xml_end_tag(self->file, "c:ser");
|
||||
}
|
||||
|
|
@ -4000,6 +4003,12 @@ chart_add_series(lxw_chart *self, const char *categories, const char *values)
|
|||
if (_chart_init_data_cache(series->title.range) != LXW_NO_ERROR)
|
||||
goto mem_error;
|
||||
|
||||
if (self->type == LXW_CHART_SCATTER_SMOOTH)
|
||||
series->smooth = LXW_TRUE;
|
||||
|
||||
if (self->type == LXW_CHART_SCATTER_SMOOTH_WITH_MARKERS)
|
||||
series->smooth = LXW_TRUE;
|
||||
|
||||
STAILQ_INSERT_TAIL(self->series_list, series, list_pointers);
|
||||
|
||||
return series;
|
||||
|
|
@ -4272,6 +4281,15 @@ chart_series_set_points(lxw_chart_series *series, lxw_chart_point *points[])
|
|||
return LXW_NO_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the smooth property for a line or scatter series.
|
||||
*/
|
||||
void
|
||||
chart_series_set_smooth(lxw_chart_series *series, uint8_t smooth)
|
||||
{
|
||||
series->smooth = smooth;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set an axis caption.
|
||||
*/
|
||||
|
|
|
|||
44
test/functional/src/test_chart_line03.c
Normal file
44
test/functional/src/test_chart_line03.c
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* Copyright 2014-2017, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xlsxwriter.h"
|
||||
|
||||
int main() {
|
||||
|
||||
lxw_workbook *workbook = new_workbook("test_chart_line03.xlsx");
|
||||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
||||
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_LINE);
|
||||
|
||||
/* For testing, copy the randomly generated axis ids in the target file. */
|
||||
chart->axis_id_1 = 47673728;
|
||||
chart->axis_id_2 = 47675264;
|
||||
|
||||
uint8_t data[5][3] = {
|
||||
{5, 10, 15},
|
||||
{2, 4, 6 },
|
||||
{3, 6, 9 },
|
||||
{4, 8, 12},
|
||||
{3, 6, 9 }
|
||||
};
|
||||
|
||||
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 *series = chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
|
||||
chart_add_series(chart, NULL, "=Sheet1!$B$1:$B$5");
|
||||
chart_add_series(chart, NULL, "=Sheet1!$C$1:$C$5");
|
||||
|
||||
chart_series_set_smooth(series, LXW_TRUE);
|
||||
|
||||
worksheet_insert_chart(worksheet, CELL("E9"), chart);
|
||||
|
||||
return workbook_close(workbook);
|
||||
}
|
||||
45
test/functional/src/test_chart_line04.c
Normal file
45
test/functional/src/test_chart_line04.c
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* Copyright 2014-2017, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xlsxwriter.h"
|
||||
|
||||
int main() {
|
||||
|
||||
lxw_workbook *workbook = new_workbook("test_chart_line04.xlsx");
|
||||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
||||
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_LINE);
|
||||
|
||||
/* For testing, copy the randomly generated axis ids in the target file. */
|
||||
chart->axis_id_1 = 47670016;
|
||||
chart->axis_id_2 = 47671552;
|
||||
|
||||
uint8_t data[5][3] = {
|
||||
{5, 10, 15},
|
||||
{2, 4, 6 },
|
||||
{3, 6, 9 },
|
||||
{4, 8, 12},
|
||||
{3, 6, 9 }
|
||||
};
|
||||
|
||||
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");
|
||||
chart_add_series(chart, NULL, "=Sheet1!$B$1:$B$5");
|
||||
lxw_chart_series *series3 = chart_add_series(chart, NULL, "=Sheet1!$C$1:$C$5");
|
||||
|
||||
chart_series_set_smooth(series1, LXW_TRUE);
|
||||
chart_series_set_smooth(series3, LXW_TRUE);
|
||||
|
||||
worksheet_insert_chart(worksheet, CELL("E9"), chart);
|
||||
|
||||
return workbook_close(workbook);
|
||||
}
|
||||
50
test/functional/src/test_chart_scatter09.c
Normal file
50
test/functional/src/test_chart_scatter09.c
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* Copyright 2014-2017, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xlsxwriter.h"
|
||||
|
||||
int main() {
|
||||
|
||||
lxw_workbook *workbook = new_workbook("test_chart_scatter09.xlsx");
|
||||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
||||
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_SCATTER_SMOOTH_WITH_MARKERS);
|
||||
|
||||
/* For testing, copy the randomly generated axis ids in the target file. */
|
||||
chart->axis_id_1 = 45953024;
|
||||
chart->axis_id_2 = 45954944;
|
||||
|
||||
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 *series = chart_add_series(chart,
|
||||
"=Sheet1!$A$1:$A$5",
|
||||
"=Sheet1!$B$1:$B$5"
|
||||
);
|
||||
|
||||
chart_add_series(chart,
|
||||
"=Sheet1!$A$1:$A$5",
|
||||
"=Sheet1!$C$1:$C$5"
|
||||
);
|
||||
|
||||
chart_series_set_smooth(series, LXW_FALSE);
|
||||
|
||||
worksheet_insert_chart(worksheet, CELL("E9"), chart);
|
||||
|
||||
return workbook_close(workbook);
|
||||
}
|
||||
50
test/functional/src/test_chart_scatter10.c
Normal file
50
test/functional/src/test_chart_scatter10.c
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* Copyright 2014-2017, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xlsxwriter.h"
|
||||
|
||||
int main() {
|
||||
|
||||
lxw_workbook *workbook = new_workbook("test_chart_scatter10.xlsx");
|
||||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
||||
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_SCATTER_SMOOTH);
|
||||
|
||||
/* For testing, copy the randomly generated axis ids in the target file. */
|
||||
chart->axis_id_1 = 84754816;
|
||||
chart->axis_id_2 = 84756352;
|
||||
|
||||
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);
|
||||
|
||||
chart_add_series(chart,
|
||||
"=Sheet1!$A$1:$A$5",
|
||||
"=Sheet1!$B$1:$B$5"
|
||||
);
|
||||
|
||||
lxw_chart_series *series = chart_add_series(chart,
|
||||
"=Sheet1!$A$1:$A$5",
|
||||
"=Sheet1!$C$1:$C$5"
|
||||
);
|
||||
|
||||
chart_series_set_smooth(series, LXW_FALSE);
|
||||
|
||||
worksheet_insert_chart(worksheet, CELL("E9"), chart);
|
||||
|
||||
return workbook_close(workbook);
|
||||
}
|
||||
50
test/functional/src/test_chart_scatter11.c
Normal file
50
test/functional/src/test_chart_scatter11.c
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* Copyright 2014-2017, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xlsxwriter.h"
|
||||
|
||||
int main() {
|
||||
|
||||
lxw_workbook *workbook = new_workbook("test_chart_scatter11.xlsx");
|
||||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
||||
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_SCATTER_STRAIGHT_WITH_MARKERS);
|
||||
|
||||
/* For testing, copy the randomly generated axis ids in the target file. */
|
||||
chart->axis_id_1 = 47439232;
|
||||
chart->axis_id_2 = 47670400;
|
||||
|
||||
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 *series = chart_add_series(chart,
|
||||
"=Sheet1!$A$1:$A$5",
|
||||
"=Sheet1!$B$1:$B$5"
|
||||
);
|
||||
|
||||
chart_add_series(chart,
|
||||
"=Sheet1!$A$1:$A$5",
|
||||
"=Sheet1!$C$1:$C$5"
|
||||
);
|
||||
|
||||
chart_series_set_smooth(series, LXW_TRUE);
|
||||
|
||||
worksheet_insert_chart(worksheet, CELL("E9"), chart);
|
||||
|
||||
return workbook_close(workbook);
|
||||
}
|
||||
|
|
@ -15,3 +15,9 @@ class TestCompareXLSXFiles(base_test_class.XLSXBaseTest):
|
|||
|
||||
def test_chart_line01(self):
|
||||
self.run_exe_test('test_chart_line01')
|
||||
|
||||
def test_chart_line03(self):
|
||||
self.run_exe_test('test_chart_line03')
|
||||
|
||||
def test_chart_line04(self):
|
||||
self.run_exe_test('test_chart_line04')
|
||||
|
|
|
|||
|
|
@ -31,6 +31,15 @@ class TestCompareXLSXFiles(base_test_class.XLSXBaseTest):
|
|||
def test_chart_scatter06(self):
|
||||
self.run_exe_test('test_chart_scatter06')
|
||||
|
||||
def test_chart_scatter09(self):
|
||||
self.run_exe_test('test_chart_scatter09')
|
||||
|
||||
def test_chart_scatter10(self):
|
||||
self.run_exe_test('test_chart_scatter10')
|
||||
|
||||
def test_chart_scatter11(self):
|
||||
self.run_exe_test('test_chart_scatter11')
|
||||
|
||||
def test_chart_scatter12(self):
|
||||
self.run_exe_test('test_chart_scatter12')
|
||||
|
||||
|
|
|
|||
BIN
test/functional/xlsx_files/chart_line03.xlsx
Normal file
BIN
test/functional/xlsx_files/chart_line03.xlsx
Normal file
Binary file not shown.
BIN
test/functional/xlsx_files/chart_line04.xlsx
Normal file
BIN
test/functional/xlsx_files/chart_line04.xlsx
Normal file
Binary file not shown.
BIN
test/functional/xlsx_files/chart_scatter09.xlsx
Normal file
BIN
test/functional/xlsx_files/chart_scatter09.xlsx
Normal file
Binary file not shown.
BIN
test/functional/xlsx_files/chart_scatter10.xlsx
Normal file
BIN
test/functional/xlsx_files/chart_scatter10.xlsx
Normal file
Binary file not shown.
BIN
test/functional/xlsx_files/chart_scatter11.xlsx
Normal file
BIN
test/functional/xlsx_files/chart_scatter11.xlsx
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue