#include <stdio.h>#include <stdlib.h>#include <math.h>#include <string.h>#include "axis.h"#include "libtpcsvgv.h"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 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().
| enum svgColor |
Definition at line 42 of file libtpcsvg.h.
| enum svgSymbolType |
Definition at line 40 of file libtpcsvg.h.
| 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 | ||
| ) |
| 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 |
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().
| 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.
| 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 |
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.
| vp | Struct 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.
| int svg_close | ( | FILE * | fp, |
| char * | errmsg | ||
| ) |
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 |
Definition at line 127 of file svg_file.c.
References svg_write().
| 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.
| 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 |
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.
| int svg_create_xaxis_title | ( | FILE * | fp, |
| char * | title_text, | ||
| struct svg_viewports * | vp, | ||
| char * | errmsg | ||
| ) |
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 |
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.
| int svg_create_yaxis_title | ( | FILE * | fp, |
| char * | title_text, | ||
| struct svg_viewports * | vp, | ||
| char * | errmsg | ||
| ) |
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 |
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.
| int svg_define_symbols | ( | FILE * | fp, |
| char * | errmsg | ||
| ) |
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 |
Definition at line 51 of file svg_defs.c.
References SVG_INLINE, and svg_write().
Referenced by svg_start_plot_viewport().
| 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.
| 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 |
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.
| 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 |
Definition at line 353 of file svg_plot.c.
References SVG_INLINE, and svg_write().
| int svg_end_plot_viewport | ( | FILE * | fp, |
| struct svg_viewports * | vp, | ||
| char * | errmsg | ||
| ) |
End plot 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 |
Definition at line 280 of file svg_plot.c.
References SVG_INLINE, and svg_write().
| 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.
| 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 |
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.
| int svg_start_coordinate_viewport | ( | FILE * | fp, |
| struct svg_viewports * | vp, | ||
| char * | errmsg | ||
| ) |
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 |
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.
| int svg_start_plot_viewport | ( | FILE * | fp, |
| struct svg_viewports * | vp, | ||
| char * | errmsg | ||
| ) |
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 |
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.
| int svg_write | ( | FILE * | fp, |
| char * | svg_string, | ||
| char * | errmsg | ||
| ) |
| 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 |
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.
| fp | SVG graphics file pointer |
| vp | Struct containing the viewport sizes |
| errmsg | Pointer 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.
| 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.
| 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 |
| errmsg | Char 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.
| int svg_write_xticks | ( | FILE * | fp, |
| struct svg_viewports * | vp, | ||
| char * | errmsg | ||
| ) |
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 |
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.
| int svg_write_yticks | ( | FILE * | fp, |
| struct svg_viewports * | vp, | ||
| char * | errmsg | ||
| ) |
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 |
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.
| int svg_xhtml_close | ( | FILE * | fp, |
| char * | errmsg | ||
| ) |
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 |
Definition at line 205 of file svg_file.c.
References SVG_INLINE, and svg_write().
| 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.
| filename | File name for SVG graphics |
| XHTML_title | XHTML title; if NULL, then filename is used |
| errmsg | Char 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().
| int svg_xhtml_svg_close | ( | FILE * | fp, |
| char * | errmsg | ||
| ) |
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 |
Definition at line 271 of file svg_file.c.
References svg_write().
| int svg_xhtml_svg_open | ( | FILE * | fp, |
| double | height, | ||
| double | width, | ||
| struct svg_viewports * | vp, | ||
| char * | errmsg | ||
| ) |
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 |
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.
1.8.0