libtpcsvg
 All Data Structures Files Functions Variables Enumerations Enumerator Defines
Data Structures | Defines | Enumerations | Functions
include/libtpcsvg.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "axis.h"
#include "libtpcsvgv.h"
Include dependency graph for libtpcsvg.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  svg_viewport_pos
struct  svg_coord
struct  svg_viewports

Defines

#define SVG_VIEWPORT_WIDTH   10000
#define SVG_VIEWPORT_HEIGHT   10000
#define MAX_TICK_NR   12
#define MAX_TICK_LABEL_LEN   20

Enumerations

enum  svgSymbolType {
  RECTANGLE, CIRCLE, UPTRIANGLE, DOWNTRIANGLE,
  DIAMOND, LEFTTRIANGLE, RIGHTTRIANGLE
}
enum  svgColor {
  BLACK, RED, BLUE, GREEN,
  PURPLE, OLIVE, AQUA, FUCHSIA,
  GRAY, LIME, MAROON, NAVY,
  SILVER, TEAL, YELLOW
}

Functions

FILE * svg_initiate (char *filename, double height, double width, struct svg_viewports *vp, char *errmsg)
int svg_close (FILE *fp, char *errmsg)
FILE * svg_xhtml_initiate (char *filename, char *XHTML_title, char *errmsg)
int svg_xhtml_close (FILE *fp, char *errmsg)
int svg_xhtml_svg_open (FILE *fp, double height, double width, struct svg_viewports *vp, char *errmsg)
int svg_xhtml_svg_close (FILE *fp, char *errmsg)
int svg_write (FILE *fp, char *svg_string, char *errmsg)
int svg_define_viewports (int main_viewport_width, int main_viewport_height, int is_main_title, int is_yaxis_title, int is_xaxis_title, int is_label_area, struct svg_viewports *vp)
int svg_start_plot_viewport (FILE *fp, struct svg_viewports *vp, char *errmsg)
int svg_end_plot_viewport (FILE *fp, struct svg_viewports *vp, char *errmsg)
int svg_start_coordinate_viewport (FILE *fp, struct svg_viewports *vp, char *errmsg)
int svg_end_coordinate_viewport (FILE *fp, char *errmsg)
int svg_calculate_axes (struct svg_viewports *vp)
int svg_write_axes (FILE *fp, struct svg_viewports *vp, char *errmsg)
int svg_write_xticks (FILE *fp, struct svg_viewports *vp, char *errmsg)
int svg_write_yticks (FILE *fp, struct svg_viewports *vp, char *errmsg)
int svg_write_tac (FILE *fp, struct svg_viewports *vp, int plot_type, char *tac_id, char *tac_title, double *x, double *y, int data_nr, char *color, svgSymbolType symbol_type, char *errmsg)
int get_line_intersection (double a1x, double a1y, double a2x, double a2y, double b1x, double b1y, double b2x, double b2y, double *ix, double *iy)
int check_intersection_with_viewport (double x1, double y1, double x2, double y2, struct svg_viewport_pos *cavp, double *nx1, double *ny1, double *nx2, double *ny2)
int svg_create_main_title (FILE *fp, char *main_title_text, char *sub_title_text, struct svg_viewports *vp, char *errmsg)
int svg_create_xaxis_title (FILE *fp, char *title_text, struct svg_viewports *vp, char *errmsg)
int svg_create_yaxis_title (FILE *fp, char *title_text, struct svg_viewports *vp, char *errmsg)
int svg_define_symbols (FILE *fp, char *errmsg)

Define Documentation

#define MAX_TICK_LABEL_LEN   20

Definition at line 38 of file libtpcsvg.h.

#define MAX_TICK_NR   12

Definition at line 37 of file libtpcsvg.h.

#define SVG_VIEWPORT_HEIGHT   10000

Definition at line 36 of file libtpcsvg.h.

Referenced by svg_define_viewports().

#define SVG_VIEWPORT_WIDTH   10000

Definition at line 35 of file libtpcsvg.h.

Referenced by svg_define_viewports().


Enumeration Type Documentation

enum svgColor
Enumerator:
BLACK 
RED 
BLUE 
GREEN 
PURPLE 
OLIVE 
AQUA 
FUCHSIA 
GRAY 
LIME 
MAROON 
NAVY 
SILVER 
TEAL 
YELLOW 

Definition at line 42 of file libtpcsvg.h.

Enumerator:
RECTANGLE 
CIRCLE 
UPTRIANGLE 
DOWNTRIANGLE 
DIAMOND 
LEFTTRIANGLE 
RIGHTTRIANGLE 

Definition at line 40 of file libtpcsvg.h.


Function Documentation

int check_intersection_with_viewport ( double  x1,
double  y1,
double  x2,
double  y2,
struct svg_viewport_pos cavp,
double *  nx1,
double *  ny1,
double *  nx2,
double *  ny2 
)
Parameters:
x1x,y coordinates of line at points 1 and 2; x coordinate of point 1
y1y coordinate of point 1
x2x coordinate of point 2
y2y coordinate of point 2
cavpPointer to coordinate area viewport
nx1Pointers for (possibly) modified line coordinates; NULL if not needed
ny1new y coordinate of point 1
nx2new x coordinate of point 2
ny2new y coordinate of point 2

Definition at line 132 of file svg_plot.c.

References get_line_intersection(), svg_viewport_pos::h, SVG_TEST, and svg_viewport_pos::w.

Referenced by svg_write_tac().

Here is the call graph for this function:

int get_line_intersection ( double  a1x,
double  a1y,
double  a2x,
double  a2y,
double  b1x,
double  b1y,
double  b2x,
double  b2y,
double *  ix,
double *  iy 
)

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.

Returns:
Returns 1 in case of intersection, and 0 if they do not cross.
Parameters:
a1xx,y coordinates of line a at points 1 and 2; x coordinate of point 1
a1yy coordinate of point 1
a2xx coordinate of point 2
a2yy coordinate of point 2
b1xx,y coordinates of line b at points 1 and 2; x coordinate of point 1
b1yy coordinate of point 1
b2xx coordinate of point 2
b2yy coordinate of point 2
ixPointers for intersection point coordinates; NULL if not needed
iyIntersection y coordinate

Definition at line 87 of file svg_plot.c.

References SVG_TEST.

Referenced by check_intersection_with_viewport().

int svg_calculate_axes ( struct svg_viewports vp)

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.

Returns:
Returns 0 if successful, <>0 in case of error.
Parameters:
vpStruct containing the viewport sizes

Definition at line 381 of file svg_plot.c.

References axis_check_range(), axis_tick_positions(), svg_coord::fixed_max, svg_coord::fixed_min, svg_coord::max, MAX_TICK_NR, svg_coord::min, svg_coord::tick, svg_coord::tick_decimals, svg_coord::tick_label, svg_coord::tick_nr, svg_coord::tickscale, svg_viewports::x, and svg_viewports::y.

Here is the call graph for this function:

int svg_close ( FILE *  fp,
char *  errmsg 
)

Close SVG graphics file.

Returns:
Returns 0 if successful, <>0 in case of error.
Parameters:
fpSVG graphics file pointer
errmsgChar pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary

Definition at line 127 of file svg_file.c.

References svg_write().

Here is the call graph for this function:

int svg_create_main_title ( FILE *  fp,
char *  main_title_text,
char *  sub_title_text,
struct svg_viewports vp,
char *  errmsg 
)

Create SVG plot main title.

Returns:
Returns 0 if successful, <>0 in case of error.
Parameters:
fpSVG graphics file pointer
main_title_textText for main title
sub_title_textText for sub title
vpStruct containing the viewport sizes
errmsgChar pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary

Definition at line 55 of file svg_title.c.

References svg_viewport_pos::chr_size, svg_viewport_pos::h, svg_viewport_pos::is, svg_viewports::main_title_viewport, SVG_INLINE, svg_write(), svg_viewport_pos::w, svg_viewport_pos::x, and svg_viewport_pos::y.

Here is the call graph for this function:

int svg_create_xaxis_title ( FILE *  fp,
char *  title_text,
struct svg_viewports vp,
char *  errmsg 
)

Create SVG plot x axis title.

Returns:
Returns 0 if successful, <>0 in case of error.
Parameters:
fpSVG graphics file pointer
title_textText for x axis title
vpStruct containing the viewport sizes
errmsgChar pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary

Definition at line 159 of file svg_title.c.

References svg_viewport_pos::chr_size, svg_viewport_pos::h, svg_viewport_pos::is, SVG_INLINE, svg_write(), svg_viewport_pos::w, svg_viewport_pos::x, svg_viewports::xaxis_title_viewport, and svg_viewport_pos::y.

Here is the call graph for this function:

int svg_create_yaxis_title ( FILE *  fp,
char *  title_text,
struct svg_viewports vp,
char *  errmsg 
)

Create SVG plot y axis title.

Returns:
Returns 0 if successful, <>0 in case of error.
Parameters:
fpSVG graphics file pointer
title_textText for y axis title
vpStruct containing the viewport sizes
errmsgChar pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary

Definition at line 225 of file svg_title.c.

References svg_viewport_pos::chr_size, svg_viewport_pos::h, svg_viewport_pos::is, SVG_INLINE, svg_write(), svg_viewport_pos::w, svg_viewport_pos::x, svg_viewport_pos::y, and svg_viewports::yaxis_title_viewport.

Here is the call graph for this function:

int svg_define_symbols ( FILE *  fp,
char *  errmsg 
)

Define the curve symbols for SVG graphics file.

Returns:
Returns 0 if successful, <>0 in case of error.
Parameters:
fpSVG graphics file pointer
errmsgChar pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary

Definition at line 51 of file svg_defs.c.

References SVG_INLINE, and svg_write().

Referenced by svg_start_plot_viewport().

Here is the call graph for this function:

int svg_define_viewports ( int  main_viewport_width,
int  main_viewport_height,
int  is_main_title,
int  is_yaxis_title,
int  is_xaxis_title,
int  is_label_area,
struct svg_viewports vp 
)

Define the viewport positions for further use. All measures are in pixels.

Returns:
Returns pointer to the file if successful and NULL in case of an error.
Parameters:
main_viewport_widthMain viewport width (zero if default is used)
main_viewport_heightMain viewport height (zero if default is used)
is_main_titleIs there main title? no=0, yes<>0
is_yaxis_titleIs there y axis title? no=0, yes<>0
is_xaxis_titleIs there x axis title? no=0, yes<>0
is_label_areaIs there label area? no=0, yes<>0
vpPointer to structure which will be filled with viewport positions and sizes

Definition at line 53 of file svg_vport.c.

References svg_viewport_pos::chr_size, svg_viewports::coordinate_area_viewport, svg_viewport_pos::h, svg_viewport_pos::is, svg_viewports::label_area_viewport, svg_viewports::main_title_viewport, svg_viewports::main_viewport, svg_viewports::plot_area_viewport, SVG_TEST, SVG_VIEWPORT_HEIGHT, SVG_VIEWPORT_WIDTH, svg_coord::tick_label, svg_coord::tick_nr, svg_viewport_pos::w, svg_viewport_pos::x, svg_viewports::xaxis_title_viewport, svg_viewport_pos::y, svg_viewports::y, and svg_viewports::yaxis_title_viewport.

int svg_end_coordinate_viewport ( FILE *  fp,
char *  errmsg 
)

End coordinate area viewport.

Returns:
Returns 0 if successful, <>0 in case of error.
Parameters:
fpSVG graphics file pointer
errmsgChar pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary

Definition at line 353 of file svg_plot.c.

References SVG_INLINE, and svg_write().

Here is the call graph for this function:

int svg_end_plot_viewport ( FILE *  fp,
struct svg_viewports vp,
char *  errmsg 
)

End plot viewport.

Returns:
Returns 0 if successful, <>0 in case of error.
Parameters:
fpSVG graphics file pointer
vpStruct containing the viewport sizes
errmsgChar pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary

Definition at line 280 of file svg_plot.c.

References SVG_INLINE, and svg_write().

Here is the call graph for this function:

FILE* svg_initiate ( char *  filename,
double  height,
double  width,
struct svg_viewports vp,
char *  errmsg 
)

Initiate a new SVG graphics file. If file with same name exists, it is overwritten without backup.

Returns:
Returns pointer to the file if successful and NULL in case of an error.
Parameters:
filenameFile name for SVG graphics
heightPlot height in cm; 0, if not predefined
widthPlot width in cm; 0, if not predefined
vpStruct containing the viewport sizes
errmsgChar pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary

Definition at line 59 of file svg_file.c.

References svg_viewport_pos::h, svg_viewports::main_viewport, svg_write(), and svg_viewport_pos::w.

Here is the call graph for this function:

int svg_start_coordinate_viewport ( FILE *  fp,
struct svg_viewports vp,
char *  errmsg 
)

Start coordinate area viewport.

Returns:
Returns 0 if successful, <>0 in case of error.
Parameters:
fpSVG graphics file pointer
vpStruct containing the viewport sizes
errmsgChar pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary

Definition at line 310 of file svg_plot.c.

References svg_viewports::coordinate_area_viewport, svg_viewport_pos::h, SVG_INLINE, svg_write(), svg_viewport_pos::w, svg_viewport_pos::x, and svg_viewport_pos::y.

Here is the call graph for this function:

int svg_start_plot_viewport ( FILE *  fp,
struct svg_viewports vp,
char *  errmsg 
)

Start plot area viewport.

Returns:
Returns 0 if successful, <>0 in case of error.
Parameters:
fpSVG graphics file pointer
vpStruct containing the viewport sizes
errmsgChar pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary

Definition at line 234 of file svg_plot.c.

References svg_viewport_pos::h, svg_viewports::plot_area_viewport, svg_define_symbols(), SVG_INLINE, svg_write(), svg_viewport_pos::w, svg_viewport_pos::x, and svg_viewport_pos::y.

Here is the call graph for this function:

int svg_write ( FILE *  fp,
char *  svg_string,
char *  errmsg 
)
Parameters:
fpSVG graphics file pointer
svg_stringChar pointer to NULL terminated string to be written into file
errmsgChar pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary

Definition at line 287 of file svg_file.c.

Referenced by svg_close(), 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().

int svg_write_axes ( FILE *  fp,
struct svg_viewports vp,
char *  errmsg 
)

Draw the axes into SVG plot coordinate area.

Returns:
Returns 0 if successful, <>0 in case of error.
Parameters:
fpSVG graphics file pointer
vpStruct containing the viewport sizes
errmsgPointer to string where error message is written; NULL if not needed

Definition at line 438 of file svg_plot.c.

References svg_viewports::coordinate_area_viewport, svg_viewport_pos::h, svg_coord::max, svg_coord::min, svg_coord::origo, svg_coord::scale, SVG_INLINE, SVG_TEST, svg_write(), svg_coord::upper_margin, svg_viewport_pos::w, svg_viewports::x, and svg_viewports::y.

Here is the call graph for this function:

int svg_write_tac ( FILE *  fp,
struct svg_viewports vp,
int  plot_type,
char *  tac_id,
char *  tac_title,
double *  x,
double *  y,
int  data_nr,
char *  color,
svgSymbolType  symbol_type,
char *  errmsg 
)

Draw sample curve in an SVG file.

Returns:
Returns 0 if successful, <>0 in case of error.
Parameters:
fpSVG graphics file pointer
vpStruct containing the viewport sizes
plot_typePlot type: 1=line, 2=symbols, 0=both line and symbols
tac_idUnique ID for the curve
tac_titleTitle of the curve, which may be shown in the graph
xPointer to the polyline data x array (original quantities)
yPointer to the polyline data y array (original quantities)
data_nrNr of data points in the array (half of array length)
colorSVG 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_typeSymbol type: RECTANGLE,CIRCLE,UPTRIANGLE,DOWNTRIANGLE,DIAMOND, LEFTTRIANGLE, RIGHTTRIANGLE
errmsgChar pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary

Definition at line 665 of file svg_plot.c.

References check_intersection_with_viewport(), CIRCLE, svg_viewports::coordinate_area_viewport, DIAMOND, DOWNTRIANGLE, svg_viewport_pos::h, LEFTTRIANGLE, svg_coord::origo, RECTANGLE, RIGHTTRIANGLE, svg_coord::scale, SVG_INLINE, SVG_TEST, svg_write(), UPTRIANGLE, svg_viewport_pos::w, svg_viewports::x, and svg_viewports::y.

Here is the call graph for this function:

int svg_write_xticks ( FILE *  fp,
struct svg_viewports vp,
char *  errmsg 
)

Create SVG plot x axis ticks.

Returns:
Returns 0 if successful, <>0 in case of error.
Parameters:
fpSVG graphics file pointer
vpStruct containing the viewport sizes
errmsgChar pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary

Definition at line 523 of file svg_plot.c.

References svg_viewport_pos::chr_size, svg_viewports::coordinate_area_viewport, svg_viewport_pos::h, svg_coord::origo, svg_viewports::plot_area_viewport, svg_coord::scale, SVG_INLINE, SVG_TEST, svg_write(), svg_coord::tick, svg_coord::tick_label, svg_coord::tick_nr, svg_coord::tickscale, svg_viewport_pos::w, and svg_viewports::x.

Here is the call graph for this function:

int svg_write_yticks ( FILE *  fp,
struct svg_viewports vp,
char *  errmsg 
)

Create SVG plot y axis ticks.

Returns:
Returns 0 if successful, <>0 in case of error.
Parameters:
fpSVG graphics file pointer
vpStruct containing the viewport sizes
errmsgChar pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary

Definition at line 591 of file svg_plot.c.

References svg_viewport_pos::chr_size, svg_viewports::coordinate_area_viewport, svg_viewport_pos::h, svg_coord::origo, svg_viewports::plot_area_viewport, svg_coord::scale, SVG_INLINE, SVG_TEST, svg_write(), svg_coord::tick, svg_coord::tick_decimals, svg_coord::tick_label, svg_coord::tick_nr, svg_coord::tickscale, svg_viewport_pos::w, and svg_viewports::y.

Here is the call graph for this function:

int svg_xhtml_close ( FILE *  fp,
char *  errmsg 
)

Close XHTML file containing inline SVG.

Returns:
Returns 0 if successful, <>0 in case of error.
Parameters:
fpSVG graphics file pointer
errmsgChar pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary

Definition at line 205 of file svg_file.c.

References SVG_INLINE, and svg_write().

Here is the call graph for this function:

FILE* svg_xhtml_initiate ( char *  filename,
char *  XHTML_title,
char *  errmsg 
)

Initiate a new XHTML file for one or more inline SVG graphics files. If file with same name exists, it is overwritten without backup.

Returns:
Returns pointer to the file if successful and NULL in case of an error.
Parameters:
filenameFile name for SVG graphics
XHTML_titleXHTML title; if NULL, then filename is used
errmsgChar pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary

Definition at line 145 of file svg_file.c.

References SVG_INLINE, and svg_write().

Here is the call graph for this function:

int svg_xhtml_svg_close ( FILE *  fp,
char *  errmsg 
)

Close SVG graphics inline in XHTML file. Leaves the file open.

Returns:
Returns 0 if successful, <>0 in case of error.
Parameters:
fpSVG graphics file pointer
errmsgChar pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary

Definition at line 271 of file svg_file.c.

References svg_write().

Here is the call graph for this function:

int svg_xhtml_svg_open ( FILE *  fp,
double  height,
double  width,
struct svg_viewports vp,
char *  errmsg 
)

Open a new SVG inline XHTML file.

Returns:
Returns 0 if successful, <>0 in case of error.
Parameters:
fpSVG graphics file pointer
heightPlot height in cm; 0, if not predefined
widthPlot width in cm; 0, if not predefined
vpStruct containing the viewport sizes
errmsgChar pointer to string (at least of length 128) where possible error description is copied; set to NULL if not necessary

Definition at line 225 of file svg_file.c.

References svg_viewport_pos::h, svg_viewports::main_viewport, svg_write(), and svg_viewport_pos::w.

Here is the call graph for this function: