libxlsxwriter/src/chart.c in fast_excel-0.2.3 vs libxlsxwriter/src/chart.c in fast_excel-0.2.5
- old
+ new
@@ -1,11 +1,11 @@
/*****************************************************************************
* chart - A library for creating Excel XLSX chart files.
*
* Used in conjunction with the libxlsxwriter library.
*
- * Copyright 2014-2017, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
+ * Copyright 2014-2018, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
*
*/
#include "xlsxwriter/xmlwriter.h"
#include "xlsxwriter/chart.h"
@@ -309,17 +309,25 @@
return NULL;
font = calloc(1, sizeof(struct lxw_chart_font));
RETURN_ON_MEM_ERROR(font, NULL);
- memcpy(font, user_font, sizeof(lxw_chart_font));
-
+ /* Copy the user supplied properties. */
font->name = lxw_strdup(user_font->name);
+ font->size = user_font->size;
+ font->bold = user_font->bold;
+ font->italic = user_font->italic;
+ font->underline = user_font->underline;
+ font->rotation = user_font->rotation;
+ font->color = user_font->color;
+ font->pitch_family = user_font->pitch_family;
+ font->charset = user_font->charset;
+ font->baseline = user_font->baseline;
/* Convert font size units. */
- if (font->size)
- font->size = font->size * 100;
+ if (font->size > 0.0)
+ font->size = font->size * 100.0;
/* Convert rotation into 60,000ths of a degree. */
if (font->rotation)
font->rotation = font->rotation * 60000;
@@ -343,11 +351,16 @@
return NULL;
line = calloc(1, sizeof(struct lxw_chart_line));
RETURN_ON_MEM_ERROR(line, NULL);
- memcpy(line, user_line, sizeof(lxw_chart_line));
+ /* Copy the user supplied properties. */
+ line->color = user_line->color;
+ line->none = user_line->none;
+ line->width = user_line->width;
+ line->dash_type = user_line->dash_type;
+ line->transparency = user_line->transparency;
if (line->color) {
line->color = lxw_format_check_color(line->color);
line->has_color = LXW_TRUE;
}
@@ -370,11 +383,14 @@
return NULL;
fill = calloc(1, sizeof(struct lxw_chart_fill));
RETURN_ON_MEM_ERROR(fill, NULL);
- memcpy(fill, user_fill, sizeof(lxw_chart_fill));
+ /* Copy the user supplied properties. */
+ fill->color = user_fill->color;
+ fill->none = user_fill->none;
+ fill->transparency = user_fill->transparency;
if (fill->color) {
fill->color = lxw_format_check_color(fill->color);
fill->has_color = LXW_TRUE;
}
@@ -407,11 +423,14 @@
}
pattern = calloc(1, sizeof(struct lxw_chart_pattern));
RETURN_ON_MEM_ERROR(pattern, NULL);
- memcpy(pattern, user_pattern, sizeof(lxw_chart_pattern));
+ /* Copy the user supplied properties. */
+ pattern->fg_color = user_pattern->fg_color;
+ pattern->bg_color = user_pattern->bg_color;
+ pattern->type = user_pattern->type;
pattern->fg_color = lxw_format_check_color(pattern->fg_color);
pattern->has_fg_color = LXW_TRUE;
if (pattern->bg_color) {
@@ -422,12 +441,10 @@
/* Default background color in Excel is white, when unspecified. */
pattern->bg_color = LXW_COLOR_WHITE;
pattern->has_bg_color = LXW_TRUE;
}
- pattern->type = user_pattern->type;
-
return pattern;
}
/*
* Set a marker type for a series.
@@ -834,12 +851,12 @@
has_color = font->color || font->has_color;
has_latin = font->name || font->pitch_family || font->charset;
use_font_default = !(has_color || has_latin || font->baseline == -1);
/* Set the font attributes. */
- if (font->size)
- LXW_PUSH_ATTRIBUTES_INT("sz", font->size);
+ if (font->size > 0.0)
+ LXW_PUSH_ATTRIBUTES_DBL("sz", font->size);
if (use_font_default || font->bold)
LXW_PUSH_ATTRIBUTES_INT("b", font->bold & 0x1);
if (use_font_default || font->italic)
@@ -906,12 +923,12 @@
has_color = font->color || font->has_color;
has_latin = font->name || font->pitch_family || font->charset;
use_font_default = !(has_color || has_latin || font->baseline == -1);
/* Set the font attributes. */
- if (font->size)
- LXW_PUSH_ATTRIBUTES_INT("sz", font->size);
+ if (font->size > 0.0)
+ LXW_PUSH_ATTRIBUTES_DBL("sz", font->size);
if (use_font_default || font->bold)
LXW_PUSH_ATTRIBUTES_INT("b", font->bold & 0x1);
if (use_font_default || font->italic)
@@ -1135,11 +1152,11 @@
STATIC void
_chart_write_v_num(lxw_chart *self, double number)
{
char data[LXW_ATTR_32];
- lxw_snprintf(data, LXW_ATTR_32, "%.16g", number);
+ lxw_sprintf_dbl(data, number);
lxw_xml_data_element(self->file, "c:v", data, NULL);
}
/*
@@ -4563,10 +4580,14 @@
_chart_write_layout(self);
/* Write subclass chart type elements for primary and secondary axes. */
self->write_chart_type(self);
+ /* Write the c:spPr element for the plotarea formatting. */
+ _chart_write_sp_pr(self, self->plotarea_line, self->plotarea_fill,
+ self->plotarea_pattern);
+
lxw_xml_end_tag(self->file, "c:plotArea");
}
/*
* Write the <c:plotArea> element.
@@ -5382,11 +5403,12 @@
/*
* Set an data labels number format.
*/
void
-chart_series_set_labels_num_format(lxw_chart_series *series, char *num_format)
+chart_series_set_labels_num_format(lxw_chart_series *series,
+ const char *num_format)
{
if (!num_format)
return;
/* Free any previously allocated resource. */
@@ -5529,11 +5551,11 @@
/*
* Set a line type for a series trendline.
*/
void
-chart_series_set_trendline_name(lxw_chart_series *series, char *name)
+chart_series_set_trendline_name(lxw_chart_series *series, const char *name)
{
if (!name)
return;
/* Free any previously allocated resource. */
@@ -5557,10 +5579,28 @@
series->trendline_line = _chart_convert_line_args(line);
}
/*
+ * Set the X or Y error bars from a chart series.
+ */
+lxw_series_error_bars *
+chart_series_get_error_bars(lxw_chart_series *series,
+ lxw_chart_error_bar_axis axis_type)
+{
+ if (!series)
+ return NULL;
+
+ if (axis_type == LXW_CHART_ERROR_BAR_AXIS_X)
+ return series->x_error_bars;
+ else if (axis_type == LXW_CHART_ERROR_BAR_AXIS_Y)
+ return series->y_error_bars;
+ else
+ return NULL;
+}
+
+/*
* 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)
@@ -5621,10 +5661,27 @@
error_bars->line = _chart_convert_line_args(line);
}
/*
+ * Get an axis pointer from a chart.
+ */
+lxw_chart_axis *
+chart_axis_get(lxw_chart *self, lxw_chart_axis_type axis_type)
+{
+ if (!self)
+ return NULL;
+
+ if (axis_type == LXW_CHART_AXIS_TYPE_X)
+ return self->x_axis;
+ else if (axis_type == LXW_CHART_AXIS_TYPE_Y)
+ return self->y_axis;
+ else
+ return NULL;
+}
+
+/*
* Set an axis caption.
*/
void
chart_axis_set_name(lxw_chart_axis *axis, const char *name)
{
@@ -5636,11 +5693,11 @@
else
axis->title.name = lxw_strdup(name);
}
/*
- * Set an axis caption, with a range instead or a formula..
+ * Set an axis caption, with a range instead or a formula.
*/
void
chart_axis_set_name_range(lxw_chart_axis *axis, const char *sheetname,
lxw_row_t row, lxw_col_t col)
{
@@ -5685,10 +5742,10 @@
/*
* Set an axis number format.
*/
void
-chart_axis_set_num_format(lxw_chart_axis *axis, char *num_format)
+chart_axis_set_num_format(lxw_chart_axis *axis, const char *num_format)
{
if (!num_format)
return;
/* Free any previously allocated resource. */