mirror of
https://github.com/jmcnamara/libxlsxwriter
synced 2025-03-28 21:13:14 +00:00
Fix for ignored position in chart custom data labels.
Fix issue where custom chart data labels didn't inherit the position for the data labels in the series.`
This commit is contained in:
parent
dfbc07c973
commit
110af3ff4d
@ -2317,6 +2317,10 @@ _chart_write_custom_label_formula(lxw_chart *self, lxw_chart_series *series,
|
||||
|
||||
_chart_write_custom_label_format_only(self, data_label);
|
||||
|
||||
/* Write the c:dLblPos element. */
|
||||
if (series->label_position)
|
||||
_chart_write_d_lbl_pos(self, series->label_position);
|
||||
|
||||
/* Write the c:showVal element. */
|
||||
if (series->show_labels_value)
|
||||
_chart_write_show_val(self);
|
||||
@ -2356,6 +2360,10 @@ _chart_write_custom_label_str(lxw_chart *self, lxw_chart_series *series,
|
||||
_chart_write_sp_pr(self, data_label->line, data_label->fill,
|
||||
data_label->pattern);
|
||||
|
||||
/* Write the c:dLblPos element. */
|
||||
if (series->label_position)
|
||||
_chart_write_d_lbl_pos(self, series->label_position);
|
||||
|
||||
/* Write the c:showVal element. */
|
||||
if (series->show_labels_value)
|
||||
_chart_write_show_val(self);
|
||||
|
53
test/functional/src/test_chart_data_labels48.c
Normal file
53
test/functional/src/test_chart_data_labels48.c
Normal file
@ -0,0 +1,53 @@
|
||||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* Copyright 2014-2020, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xlsxwriter.h"
|
||||
|
||||
int main() {
|
||||
|
||||
lxw_workbook *workbook = workbook_new("test_chart_data_labels48.xlsx");
|
||||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
||||
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_COLUMN);
|
||||
|
||||
/* For testing, copy the randomly generated axis ids in the target file. */
|
||||
chart->axis_id_1 = 61160832;
|
||||
chart->axis_id_2 = 61167104;
|
||||
|
||||
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_data_label data_label1 = {.value = "31"};
|
||||
lxw_chart_data_label data_label2 = {.value = "32"};
|
||||
lxw_chart_data_label *data_labels1[] = {&data_label1, NULL};
|
||||
lxw_chart_data_label *data_labels2[] = {&data_label2, 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");
|
||||
chart_add_series(chart, NULL, "=Sheet1!$C$1:$C$5");
|
||||
|
||||
chart_series_set_labels(series1);
|
||||
chart_series_set_labels(series2);
|
||||
chart_series_set_labels_position(series2, LXW_CHART_LABEL_POSITION_INSIDE_BASE);
|
||||
chart_series_set_labels_custom(series1, data_labels1);
|
||||
chart_series_set_labels_custom(series2, data_labels2);
|
||||
|
||||
worksheet_insert_chart(worksheet, CELL("E9"), chart);
|
||||
|
||||
return workbook_close(workbook);
|
||||
}
|
53
test/functional/src/test_chart_data_labels49.c
Normal file
53
test/functional/src/test_chart_data_labels49.c
Normal file
@ -0,0 +1,53 @@
|
||||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* Copyright 2014-2020, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xlsxwriter.h"
|
||||
|
||||
int main() {
|
||||
|
||||
lxw_workbook *workbook = workbook_new("test_chart_data_labels49.xlsx");
|
||||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
||||
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_COLUMN);
|
||||
|
||||
/* For testing, copy the randomly generated axis ids in the target file. */
|
||||
chart->axis_id_1 = 59202176;
|
||||
chart->axis_id_2 = 60966784;
|
||||
|
||||
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_data_label data_label1 = {.value = "=Sheet1!$B$1"};
|
||||
lxw_chart_data_label data_label2 = {.value = "=Sheet1!$B$2"};
|
||||
lxw_chart_data_label *data_labels1[] = {&data_label1, NULL};
|
||||
lxw_chart_data_label *data_labels2[] = {&data_label2, 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");
|
||||
chart_add_series(chart, NULL, "=Sheet1!$C$1:$C$5");
|
||||
|
||||
chart_series_set_labels(series1);
|
||||
chart_series_set_labels(series2);
|
||||
chart_series_set_labels_position(series2, LXW_CHART_LABEL_POSITION_INSIDE_BASE);
|
||||
chart_series_set_labels_custom(series1, data_labels1);
|
||||
chart_series_set_labels_custom(series2, data_labels2);
|
||||
|
||||
worksheet_insert_chart(worksheet, CELL("E9"), chart);
|
||||
|
||||
return workbook_close(workbook);
|
||||
}
|
53
test/functional/src/test_chart_data_labels50.c
Normal file
53
test/functional/src/test_chart_data_labels50.c
Normal file
@ -0,0 +1,53 @@
|
||||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* Copyright 2014-2020, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xlsxwriter.h"
|
||||
|
||||
int main() {
|
||||
|
||||
lxw_workbook *workbook = workbook_new("test_chart_data_labels50.xlsx");
|
||||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
||||
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_COLUMN);
|
||||
|
||||
/* For testing, copy the randomly generated axis ids in the target file. */
|
||||
chart->axis_id_1 = 84605184;
|
||||
chart->axis_id_2 = 84639744;
|
||||
|
||||
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_line line = {.color = LXW_COLOR_RED};
|
||||
lxw_chart_font font = {.bold = LXW_TRUE, .italic = LXW_TRUE, .color = LXW_COLOR_RED, .baseline = -1};
|
||||
|
||||
lxw_chart_data_label data_label1 = {.line = &line, .font = &font};
|
||||
lxw_chart_data_label *data_labels[] = {&data_label1, NULL};
|
||||
|
||||
lxw_chart_series *series = chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
|
||||
chart_series_set_labels_custom(series, data_labels);
|
||||
chart_series_set_labels_position(series, LXW_CHART_LABEL_POSITION_CENTER);
|
||||
|
||||
chart_add_series(chart, NULL, "=Sheet1!$B$1:$B$5");
|
||||
chart_add_series(chart, NULL, "=Sheet1!$C$1:$C$5");
|
||||
|
||||
worksheet_insert_chart(worksheet, CELL("E9"), chart);
|
||||
|
||||
return workbook_close(workbook);
|
||||
}
|
@ -149,3 +149,12 @@ class TestCompareXLSXFiles(base_test_class.XLSXBaseTest):
|
||||
|
||||
def test_chart_data_labels47(self):
|
||||
self.run_exe_test('test_chart_data_labels47')
|
||||
|
||||
def test_chart_data_labels48(self):
|
||||
self.run_exe_test('test_chart_data_labels48')
|
||||
|
||||
def test_chart_data_labels49(self):
|
||||
self.run_exe_test('test_chart_data_labels49')
|
||||
|
||||
def test_chart_data_labels50(self):
|
||||
self.run_exe_test('test_chart_data_labels50')
|
||||
|
BIN
test/functional/xlsx_files/chart_data_labels48.xlsx
Normal file
BIN
test/functional/xlsx_files/chart_data_labels48.xlsx
Normal file
Binary file not shown.
BIN
test/functional/xlsx_files/chart_data_labels49.xlsx
Normal file
BIN
test/functional/xlsx_files/chart_data_labels49.xlsx
Normal file
Binary file not shown.
BIN
test/functional/xlsx_files/chart_data_labels50.xlsx
Normal file
BIN
test/functional/xlsx_files/chart_data_labels50.xlsx
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user