mirror of
https://github.com/jmcnamara/libxlsxwriter.git
synced 2026-05-21 06:45:21 -06:00
Refactoring of error bar function structure.
This commit is contained in:
parent
6ef24a312c
commit
7b69c672bf
6 changed files with 85 additions and 24 deletions
2
.indent.pro
vendored
2
.indent.pro
vendored
|
|
@ -111,7 +111,7 @@
|
|||
-T lxw_row_t
|
||||
-T lxw_selection
|
||||
-T lxw_series_data_point
|
||||
-T lxw_series_error_bar
|
||||
-T lxw_series_error_bars
|
||||
-T lxw_series_range
|
||||
-T lxw_sst
|
||||
-T lxw_styles
|
||||
|
|
|
|||
|
|
@ -1758,6 +1758,15 @@ void chart_series_set_labels_num_format(lxw_chart_series *series,
|
|||
void chart_series_set_labels_font(lxw_chart_series *series,
|
||||
lxw_chart_font *font);
|
||||
|
||||
void chart_series_set_error_bars(lxw_series_error_bars *error_bars,
|
||||
uint8_t type, double value);
|
||||
|
||||
void chart_series_set_error_bars_direction(lxw_series_error_bars *error_bars,
|
||||
uint8_t direction);
|
||||
|
||||
void chart_series_set_error_bars_endcap(lxw_series_error_bars *error_bars,
|
||||
uint8_t endcap);
|
||||
|
||||
void chart_series_set_error_bars_line(lxw_series_error_bars *error_bars,
|
||||
lxw_chart_line *line);
|
||||
|
||||
|
|
|
|||
53
src/chart.c
53
src/chart.c
|
|
@ -468,7 +468,7 @@ _chart_check_error_bars(lxw_series_error_bars * error_bars, char *property)
|
|||
if (error_bars->chart_group != LXW_CHART_SCATTER
|
||||
&& error_bars->chart_group != LXW_CHART_BAR) {
|
||||
|
||||
LXW_WARN_FORMAT1("chart_series_set_error_bars_%s(): "
|
||||
LXW_WARN_FORMAT1("chart_series_set_error_bars%s(): "
|
||||
"'X error bar' properties only available for"
|
||||
" Scatter and Bar charts in Excel", property);
|
||||
|
||||
|
|
@ -477,7 +477,7 @@ _chart_check_error_bars(lxw_series_error_bars * error_bars, char *property)
|
|||
}
|
||||
else {
|
||||
if (error_bars->chart_group == LXW_CHART_BAR) {
|
||||
LXW_WARN_FORMAT1("chart_series_set_error_bars_%s(): "
|
||||
LXW_WARN_FORMAT1("chart_series_set_error_bars%s(): "
|
||||
"'Y error bar' properties not available for "
|
||||
"Bar charts in Excel", property);
|
||||
|
||||
|
|
@ -5164,13 +5164,58 @@ chart_series_set_labels_font(lxw_chart_series *series, lxw_chart_font *font)
|
|||
}
|
||||
|
||||
/*
|
||||
* Set a line type for a series marker.
|
||||
* Set the error bars and type for a chart series.
|
||||
*/
|
||||
void
|
||||
chart_series_set_error_bars(lxw_series_error_bars *error_bars,
|
||||
uint8_t type, double value)
|
||||
{
|
||||
if (_chart_check_error_bars(error_bars, ""))
|
||||
return;
|
||||
|
||||
error_bars->type = type;
|
||||
error_bars->value = value;
|
||||
error_bars->has_value = LXW_TRUE;
|
||||
error_bars->is_set = LXW_TRUE;
|
||||
|
||||
if (type == LXW_CHART_ERROR_BAR_TYPE_STD_ERROR)
|
||||
error_bars->has_value = LXW_FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the error bars direction for a chart series.
|
||||
*/
|
||||
void
|
||||
chart_series_set_error_bars_direction(lxw_series_error_bars *error_bars,
|
||||
uint8_t direction)
|
||||
{
|
||||
if (_chart_check_error_bars(error_bars, "_direction"))
|
||||
return;
|
||||
|
||||
error_bars->direction = direction;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the error bars end cap type for a chart series.
|
||||
*/
|
||||
void
|
||||
chart_series_set_error_bars_endcap(lxw_series_error_bars *error_bars,
|
||||
uint8_t endcap)
|
||||
{
|
||||
if (_chart_check_error_bars(error_bars, "_endcap"))
|
||||
return;
|
||||
|
||||
error_bars->endcap = endcap;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set a line type for a series error bars.
|
||||
*/
|
||||
void
|
||||
chart_series_set_error_bars_line(lxw_series_error_bars *error_bars,
|
||||
lxw_chart_line *line)
|
||||
{
|
||||
if (_chart_check_error_bars(error_bars, "line"))
|
||||
if (_chart_check_error_bars(error_bars, "_line"))
|
||||
return;
|
||||
|
||||
if (!line)
|
||||
|
|
|
|||
|
|
@ -43,7 +43,8 @@ int main() {
|
|||
);
|
||||
|
||||
|
||||
series1->y_error_bars->is_set = 1;
|
||||
chart_series_set_error_bars(series1->y_error_bars,
|
||||
LXW_CHART_ERROR_BAR_TYPE_STD_ERROR, 0);
|
||||
|
||||
worksheet_insert_chart(worksheet, CELL("E9"), chart);
|
||||
|
||||
|
|
|
|||
|
|
@ -42,19 +42,24 @@ int main() {
|
|||
"=Sheet1!$C$1:$C$5"
|
||||
);
|
||||
|
||||
series1->y_error_bars->is_set = 1;
|
||||
series1->y_error_bars->type = LXW_CHART_ERROR_BAR_TYPE_FIXED;
|
||||
series1->y_error_bars->direction = LXW_CHART_ERROR_BAR_DIR_MINUS;
|
||||
series1->y_error_bars->endcap = LXW_CHART_ERROR_BAR_NO_CAP;
|
||||
series1->y_error_bars->has_value = 1;
|
||||
series1->y_error_bars->value = 2;
|
||||
|
||||
series2->y_error_bars->is_set = 1;
|
||||
series2->y_error_bars->type = LXW_CHART_ERROR_BAR_TYPE_PERCENTAGE;
|
||||
series2->y_error_bars->direction = LXW_CHART_ERROR_BAR_DIR_PLUS;
|
||||
series2->y_error_bars->endcap = LXW_CHART_ERROR_BAR_END_CAP;
|
||||
series2->y_error_bars->has_value = 1;
|
||||
series2->y_error_bars->value = 5;
|
||||
chart_series_set_error_bars(series1->y_error_bars,
|
||||
LXW_CHART_ERROR_BAR_TYPE_FIXED, 2);
|
||||
|
||||
chart_series_set_error_bars_direction(series1->y_error_bars,
|
||||
LXW_CHART_ERROR_BAR_DIR_MINUS);
|
||||
|
||||
chart_series_set_error_bars_endcap(series1->y_error_bars,
|
||||
LXW_CHART_ERROR_BAR_NO_CAP);
|
||||
|
||||
chart_series_set_error_bars(series2->y_error_bars,
|
||||
LXW_CHART_ERROR_BAR_TYPE_PERCENTAGE, 5);
|
||||
|
||||
chart_series_set_error_bars_direction(series2->y_error_bars,
|
||||
LXW_CHART_ERROR_BAR_DIR_PLUS);
|
||||
|
||||
chart_series_set_error_bars_endcap(series2->y_error_bars,
|
||||
LXW_CHART_ERROR_BAR_END_CAP);
|
||||
|
||||
worksheet_insert_chart(worksheet, CELL("E9"), chart);
|
||||
|
||||
|
|
|
|||
|
|
@ -46,8 +46,9 @@ int main() {
|
|||
lxw_chart_line line = {.color = LXW_COLOR_RED,
|
||||
.dash_type = LXW_CHART_LINE_DASH_ROUND_DOT};
|
||||
|
||||
series1->y_error_bars->is_set = 1;
|
||||
series1->y_error_bars->type = LXW_CHART_ERROR_BAR_TYPE_STD_ERROR;
|
||||
chart_series_set_error_bars(series1->y_error_bars,
|
||||
LXW_CHART_ERROR_BAR_TYPE_STD_ERROR, 0);
|
||||
|
||||
chart_series_set_error_bars_line(series1->y_error_bars, &line);
|
||||
|
||||
worksheet_insert_chart(worksheet, CELL("E9"), chart);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue