TPCCLIB
|
Header file for libtpcsvg. More...
#include "tpcclibConfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
Go to the source code of this file.
Data Structures | |
struct | svg_viewport_pos |
struct | svg_coord |
struct | svg_viewports |
struct | SVG_LEGEND |
struct | SVG_LEGENDS |
Macros | |
#define | SVG_VIEWPORT_WIDTH 10000 |
#define | SVG_VIEWPORT_HEIGHT 10000 |
#define | MAX_TICK_NR 12 |
#define | MAX_TICK_LABEL_LEN 20 |
#define | MAX_SVG_LEGEND_LEN 30 |
Enumerations | |
enum | svgSymbolType { RECTANGLE , CIRCLE , UPTRIANGLE , DOWNTRIANGLE , DIAMOND , LEFTTRIANGLE , RIGHTTRIANGLE } |
enum | svgSymbolFill { SYMBOLOPEN , SYMBOLFILLED } |
enum | svgColor { BLACK , RED , BLUE , GREEN , PURPLE , OLIVE , AQUA , FUCHSIA , GRAY , LIME , MAROON , NAVY , SILVER , TEAL , YELLOW } |
Functions | |
int | axis_tick_positions (const double begin, const double end, double *ticks, int *tick_nr, double *scale_factor, int *tick_decimals, int verbose) |
void | axis_check_range (double *begin, double *end, int verbose) |
void | strRmExpZeroes (char *str) |
FILE * | svg_initiate (const char *filename, const double height, const double width, struct svg_viewports *vp, char *errmsg, int verbose) |
int | svg_close (FILE *fp, char *errmsg, int verbose) |
FILE * | svg_xhtml_initiate (const char *filename, const char *XHTML_title, char *errmsg, int verbose) |
int | svg_xhtml_close (FILE *fp, char *errmsg, int verbose) |
int | svg_xhtml_svg_open (FILE *fp, const double height, const double width, struct svg_viewports *vp, char *errmsg, int verbose) |
int | svg_xhtml_svg_close (FILE *fp, char *errmsg, int verbose) |
int | svg_write (FILE *fp, const char *svg_string, char *errmsg, int verbose) |
void | svg_init_viewport_pos (struct svg_viewport_pos *p) |
void | svg_init_coord (struct svg_coord *p) |
void | svg_init_viewports (struct svg_viewports *p) |
int | svg_define_viewports (const int main_viewport_width, const int main_viewport_height, const int is_main_title, const int is_yaxis_title, const int is_xaxis_title, const int is_label_area, struct svg_viewports *vp, int verbose) |
int | svg_start_plot_viewport (FILE *fp, struct svg_viewports *vp, char *errmsg, int verbose) |
int | svg_end_plot_viewport (FILE *fp, char *errmsg, int verbose) |
int | svg_start_coordinate_viewport (FILE *fp, struct svg_viewports *vp, char *errmsg, int verbose) |
int | svg_end_coordinate_viewport (FILE *fp, char *errmsg, int verbose) |
int | svg_calculate_axes (struct svg_viewports *vp, int verbose) |
int | svg_write_axes (FILE *fp, struct svg_viewports *vp, char *errmsg, int verbose) |
int | svg_write_xticks (FILE *fp, struct svg_viewports *vp, char *errmsg, int verbose) |
int | svg_write_yticks (FILE *fp, struct svg_viewports *vp, char *errmsg, int verbose) |
int | svg_write_tac (FILE *fp, struct svg_viewports *vp, const int plot_type, const char *tac_id, const char *tac_title, double *x, double *y, const int data_nr, const char *color, const svgSymbolType symbol_type, const svgSymbolFill symbol_fill, char *errmsg, int verbose) |
int | get_line_intersection (const double a1x, const double a1y, const double a2x, const double a2y, const double b1x, const double b1y, const double b2x, const double b2y, double *ix, double *iy, int verbose) |
int | check_intersection_with_viewport (const double x1, const double y1, const double x2, const double y2, struct svg_viewport_pos *cavp, double *nx1, double *ny1, double *nx2, double *ny2, int verbose) |
int | svg_create_main_title (FILE *fp, const char *main_title_text, const char *sub_title_text, struct svg_viewports *vp, char *errmsg, int verbose) |
int | svg_create_xaxis_title (FILE *fp, const char *title_text, struct svg_viewports *vp, char *errmsg, int verbose) |
int | svg_create_yaxis_title (FILE *fp, const char *title_text, struct svg_viewports *vp, char *errmsg, int verbose) |
int | svg_define_symbols (FILE *fp, char *errmsg, int verbose) |
char * | svgColorName (const svgColor index) |
char * | svgSymbolName (const svgSymbolType index) |
void | svg_init_legends (SVG_LEGENDS *legends) |
void | svg_legend_empty (SVG_LEGENDS *legends) |
int | svg_legend_add (SVG_LEGENDS *legends, const int plot_type, const int symbol_type, const svgSymbolFill symbol_fill, const int color, const char *text) |
int | svg_create_legends (FILE *fp, struct svg_viewports *vp, SVG_LEGENDS *legends, char *errmsg, int verbose) |
char * | svg_str_encode (const char *s) |
Header file for libtpcsvg.
Definition in file libtpcsvg.h.
#define MAX_SVG_LEGEND_LEN 30 |
Max length of SVG legend texts
Definition at line 29 of file libtpcsvg.h.
Referenced by svg_legend_add().
#define MAX_TICK_LABEL_LEN 20 |
Max length of axis tick labels
Definition at line 27 of file libtpcsvg.h.
#define MAX_TICK_NR 12 |
Max nr of axis ticks
Definition at line 25 of file libtpcsvg.h.
Referenced by svg_calculate_axes(), and svg_init_coord().
#define SVG_VIEWPORT_HEIGHT 10000 |
Height of SVG viewport
Definition at line 23 of file libtpcsvg.h.
Referenced by svg_define_viewports().
#define SVG_VIEWPORT_WIDTH 10000 |
Width of SVG viewport
Definition at line 21 of file libtpcsvg.h.
Referenced by svg_define_viewports().
enum svgColor |
SVG plot colour
Definition at line 49 of file libtpcsvg.h.
enum svgSymbolFill |
SVG plot symbol open/filled
Definition at line 47 of file libtpcsvg.h.
enum svgSymbolType |
SVG plot symbol type
Definition at line 44 of file libtpcsvg.h.
void axis_check_range | ( | double * | begin, |
double * | end, | ||
int | verbose ) |
Check and if necessary correct axis range: min must be smaller than max. Also, if the range is close to zero, then make it larger. Also, if the range is relatively large, then change it to start from zero.
begin | axis range minimum |
end | axis range maximum |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout |
Definition at line 116 of file axis.c.
Referenced by svg_calculate_axes().
int axis_tick_positions | ( | const double | begin, |
const double | end, | ||
double * | ticks, | ||
int * | tick_nr, | ||
double * | scale_factor, | ||
int * | tick_decimals, | ||
int | verbose ) |
Define suitable tick positions for XY plot.
begin | axis range minimum. |
end | axis range maximum. |
ticks | Pointer to array where tick values will be written. Length must be at least tick_nr. |
tick_nr | Input: Max allowed nr of ticks; Output: actual nr of ticks. |
scale_factor | Output: Suggested scale factor (x10^sf). NULL, if not needed. |
tick_decimals | Output: tick value precision (nr of decimals). NULL, if not needed. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 14 of file axis.c.
Referenced by svg_calculate_axes().
|
extern |
Check the intersections between specified line and viewport borders.
x1 | x,y coordinates of line at points 1 and 2; x coordinate of point 1. |
y1 | y coordinate of point 1. |
x2 | x coordinate of point 2. |
y2 | y coordinate of point 2. |
cavp | Pointer to coordinate area viewport. |
nx1 | Pointers for (possibly) modified line coordinates; NULL if not needed. |
ny1 | new y coordinate of point 1. |
nx2 | new x coordinate of point 2. |
ny2 | new y coordinate of point 2. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 73 of file svg_plot.c.
Referenced by svg_write_tac().
|
extern |
Check whether two lines, each drawn between two points, intersect each other.
If either end of lines intersects with the other line, that is NOT counted as intersection.
a1x | x,y coordinates of line a at points 1 and 2; x coordinate of point 1. |
a1y | y coordinate of point 1. |
a2x | x coordinate of point 2. |
a2y | y coordinate of point 2. |
b1x | x,y coordinates of line b at points 1 and 2; x coordinate of point 1. |
b1y | y coordinate of point 1. |
b2x | x coordinate of point 2. |
b2y | y coordinate of point 2. |
ix | Pointers for intersection point coordinates; NULL if not needed. |
iy | Intersection y coordinate |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 19 of file svg_plot.c.
Referenced by check_intersection_with_viewport().
void strRmExpZeroes | ( | char * | str | ) |
Remove initial exponential zeroes from the exponential part of string representation of values, for example, '1.01E-010' -> '1.01E-10'.
Definition at line 179 of file axis.c.
Referenced by svg_calculate_axes().
|
extern |
Calculate the axis tick positions. Before calling this, viewport must be filled with curve min and max values. This routine checks that max>min, changing the values if necessary.
vp | Struct containing the viewport sizes. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 364 of file svg_plot.c.
Referenced by plot_fit_svg(), plot_fitrange_svg(), and plot_svg().
|
extern |
Close SVG graphics file.
fp | SVG graphics file pointer. |
errmsg | Char pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 107 of file svg_file.c.
Referenced by plot_fit_svg(), plot_fitrange_svg(), and plot_svg().
|
extern |
Create SVG plot legends.
fp | SVG graphics file pointer. |
vp | Struct containing the viewport sizes. |
legends | Pointer to struct containing legends. |
errmsg | Char pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 76 of file svg_legend.c.
Referenced by plot_fit_svg(), plot_fitrange_svg(), and plot_svg().
|
extern |
Create SVG plot main title.
fp | SVG graphics file pointer. |
main_title_text | Text for main title. |
sub_title_text | Text for sub title. |
vp | Struct containing the viewport sizes. |
errmsg | Char pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 17 of file svg_title.c.
Referenced by plot_fit_svg(), plot_fitrange_svg(), and plot_svg().
|
extern |
Create SVG plot x axis title.
fp | SVG graphics file pointer. |
title_text | Text for x axis title. |
vp | Struct containing the viewport sizes. |
errmsg | Char pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 126 of file svg_title.c.
Referenced by plot_fit_svg(), plot_fitrange_svg(), and plot_svg().
|
extern |
Create SVG plot y axis title.
fp | SVG graphics file pointer. |
title_text | Text for y axis title. |
vp | Struct containing the viewport sizes. |
errmsg | Char pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 197 of file svg_title.c.
Referenced by plot_fit_svg(), plot_fitrange_svg(), and plot_svg().
|
extern |
Define the curve symbols for SVG graphics file.
fp | SVG graphics file pointer. |
errmsg | Char pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 83 of file svg_defs.c.
Referenced by svg_initiate(), svg_start_plot_viewport(), and svg_xhtml_initiate().
|
extern |
Define the viewport positions for further use. All measures are in pixels.
Axis tick labels (y axis at least) should be set before calling this, so that enough room for the labels can be reserved.
main_viewport_width | Main viewport width (zero if default is used) |
main_viewport_height | Main viewport height (zero if default is used) |
is_main_title | Is there main title? no=0, yes<>0 |
is_yaxis_title | Is there y axis title? no=0, yes<>0 |
is_xaxis_title | Is there x axis title? no=0, yes<>0 |
is_label_area | Is there label area? no=0, yes<>0 |
vp | Pointer to structure which will be filled with viewport positions and sizes |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout |
Definition at line 65 of file svg_vport.c.
Referenced by plot_fit_svg(), plot_fitrange_svg(), and plot_svg().
|
extern |
End coordinate area viewport.
fp | SVG graphics file pointer. |
errmsg | Char pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 327 of file svg_plot.c.
Referenced by plot_fit_svg(), plot_fitrange_svg(), and plot_svg().
|
extern |
End plot viewport.
fp | SVG graphics file pointer. |
errmsg | Char pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 238 of file svg_plot.c.
Referenced by plot_fit_svg(), plot_fitrange_svg(), and plot_svg().
|
extern |
Initiate struct svg_coord contents to all-zeroes before use.
Definition at line 26 of file svg_vport.c.
Referenced by svg_init_viewports().
|
extern |
Initiate SVG plot legends struct contents; call this once before usage
legends | Pointer to legends struct |
Definition at line 14 of file svg_legend.c.
Referenced by plot_fit_svg(), plot_fitrange_svg(), and plot_svg().
|
extern |
Initiate struct svg_viewport_pos contents to all-zeroes before use.
Definition at line 15 of file svg_vport.c.
Referenced by svg_init_viewports().
|
extern |
Initiate struct svg_viewports contents to all-zeroes before use.
Definition at line 43 of file svg_vport.c.
Referenced by plot_fit_svg(), plot_fitrange_svg(), and plot_svg().
|
extern |
Initiate a new SVG graphics file.
If file with same name exists, it is overwritten without backup.
filename | File name for SVG graphics. |
height | Plot height in cm; 0, if not predefined. |
width | Plot width in cm; 0, if not predefined. |
vp | Struct containing the viewport sizes. |
errmsg | Char pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 22 of file svg_file.c.
Referenced by plot_fit_svg(), plot_fitrange_svg(), and plot_svg().
|
extern |
Add information of one legend item to legends struct.
Memory will be allocated here.
legends | Pointer to legends structure. |
plot_type | Plot type: 1=line, 2=symbols, 0=both line and symbols. |
symbol_type | Symbol type: RECTANGLE, CIRCLE, UPTRIANGLE, DOWNTRIANGLE, DIAMOND, LEFTTRIANGLE, RIGHTTRIANGLE |
symbol_fill | Symbol filling: SYMBOLOPEN, SYMBOLFILLED |
color | SVG color index. |
text | Pointer to Legend text. |
Definition at line 43 of file svg_legend.c.
Referenced by plot_fit_svg(), plot_fitrange_svg(), and plot_svg().
|
extern |
Empty the legends struct contents and free the allocated memory.
legends | Pointer to legends struct |
Definition at line 26 of file svg_legend.c.
Referenced by plot_fit_svg(), plot_fitrange_svg(), and plot_svg().
|
extern |
Start coordinate area viewport.
fp | SVG graphics file pointer. |
vp | Struct containing the viewport sizes. |
errmsg | Char pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 276 of file svg_plot.c.
Referenced by plot_fit_svg(), plot_fitrange_svg(), and plot_svg().
|
extern |
Start plot area viewport.
fp | SVG graphics file pointer. |
vp | Struct containing the viewport sizes. |
errmsg | Char pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 181 of file svg_plot.c.
Referenced by plot_fit_svg(), plot_fitrange_svg(), and plot_svg().
|
extern |
Encode special characters for XML, including SVG.
s | Pointer to the string to be encoded. |
Definition at line 256 of file svg_legend.c.
Referenced by svg_create_legends(), and svg_write_tac().
|
extern |
Write given string into open SVG file
fp | SVG graphics file pointer. |
svg_string | Char pointer to NULL terminated string to be written into file. |
errmsg | Char pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 304 of file svg_file.c.
Referenced by svg_close(), svg_create_legends(), svg_create_main_title(), svg_create_xaxis_title(), svg_create_yaxis_title(), svg_define_symbols(), svg_end_coordinate_viewport(), svg_end_plot_viewport(), svg_initiate(), svg_start_coordinate_viewport(), svg_start_plot_viewport(), svg_write_axes(), svg_write_tac(), svg_write_xticks(), svg_write_yticks(), svg_xhtml_close(), svg_xhtml_initiate(), svg_xhtml_svg_close(), and svg_xhtml_svg_open().
|
extern |
Draw the axes into SVG plot coordinate area.
fp | SVG graphics file pointer. |
vp | Struct containing the viewport sizes. |
errmsg | Pointer to string where error message is written; NULL if not needed. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 437 of file svg_plot.c.
Referenced by plot_fit_svg(), plot_fitrange_svg(), and plot_svg().
|
extern |
Draw sample curve in an SVG file.
fp | SVG graphics file pointer. |
vp | Struct containing the viewport sizes. |
plot_type | Plot type: 1=line, 2=symbols, 0=both line and symbols. |
tac_id | Unique ID for the curve. |
tac_title | Title of the curve, which may be shown in the graph. |
x | Pointer to the polyline data x array (original quantities). |
y | Pointer to the polyline data y array (original quantities). |
data_nr | Nr of data points in the array (half of array length). |
color | SVG color name as a string, e.g. aqua,black,blue,fuchsia,gray, green,lime,maroon,navy,olive,purple,red,silver,teal,yellow. Note that this string is not tested. |
symbol_type | Symbol type: RECTANGLE,CIRCLE,UPTRIANGLE,DOWNTRIANGLE,DIAMOND, LEFTTRIANGLE, RIGHTTRIANGLE |
symbol_fill | Symbol filling: SYMBOLOPEN, SYMBOLFILLED |
errmsg | Char pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 746 of file svg_plot.c.
Referenced by plot_fit_svg(), plot_fitrange_svg(), and plot_svg().
|
extern |
Create SVG plot x axis ticks.
fp | SVG graphics file pointer. |
vp | Struct containing the viewport sizes. |
errmsg | Char pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 555 of file svg_plot.c.
Referenced by plot_fit_svg(), plot_fitrange_svg(), and plot_svg().
|
extern |
Create SVG plot y axis ticks.
fp | SVG graphics file pointer. |
vp | Struct containing the viewport sizes. |
errmsg | Char pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 655 of file svg_plot.c.
Referenced by plot_fit_svg(), plot_fitrange_svg(), and plot_svg().
|
extern |
Close XHTML file containing inline SVG.
fp | SVG graphics file pointer. |
errmsg | Char pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 206 of file svg_file.c.
|
extern |
Initiate a new XHTML file for one or more inline SVG graphics files.
If file with same name exists, it is overwritten without backup.
filename | File name for SVG graphics. |
XHTML_title | XHTML title; if NULL, then file name is used. |
errmsg | Char pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 131 of file svg_file.c.
|
extern |
Close SVG graphics inline in XHTML file. Leaves the file open.
fp | SVG graphics file pointer. |
errmsg | Char pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 283 of file svg_file.c.
|
extern |
Open a new SVG inline XHTML file.
fp | SVG graphics file pointer. |
height | Plot height in cm; 0, if not predefined. |
width | Plot width in cm; 0, if not predefined. |
vp | Struct containing the viewport sizes. |
errmsg | Char pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 231 of file svg_file.c.
|
extern |
Return pointer to string describing the color, or NULL if outside of limits.
i | index of color |
Definition at line 38 of file svg_defs.c.
Referenced by plot_fit_svg(), plot_fitrange_svg(), plot_svg(), and svg_create_legends().
|
extern |
Return pointer to string describing the symbol, or NULL if outside of limits.
i | index of symbol |
Definition at line 67 of file svg_defs.c.
Referenced by plot_fit_svg(), plot_fitrange_svg(), and plot_svg().