TPCCLIB
Loading...
Searching...
No Matches
svg_vport.c File Reference

Create SVG plot viewports for TPC SVG C library. More...

#include "libtpcsvg.h"
#include <math.h>

Go to the source code of this file.

Functions

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)

Variables

int SVG_INLINE

Detailed Description

Create SVG plot viewports for TPC SVG C library.

Author
Vesa Oikonen

Definition in file svg_vport.c.

Function Documentation

◆ svg_define_viewports()

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 )

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.

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
verboseVerbose level; if zero, then nothing is printed to stderr or stdout

Definition at line 65 of file svg_vport.c.

82 {
83 int ti, m, n;
84
85 if(verbose>0)
86 printf("%s(%d, %d, %d, %d, %d, %d, vp, %d)\n", __func__,
87 main_viewport_width, main_viewport_height, is_main_title, is_yaxis_title,
88 is_xaxis_title, is_label_area, verbose);
89
90 if(vp==NULL) return(1);
91 /* Set main viewport */
93 if(main_viewport_width<1) vp->main_viewport.w=SVG_VIEWPORT_WIDTH;
94 if(main_viewport_height<1) vp->main_viewport.h=SVG_VIEWPORT_HEIGHT;
95 /* Set viewport for main title(s) */
96 if(is_main_title==0) {
101 } else {
107 }
108 /* Set viewport for x axis title */
109 if(is_xaxis_title==0) {
116 } else {
123 }
124 /* Set viewport for y axis title */
125 if(is_yaxis_title==0) {
132 } else {
140 else
142 }
143 /* Set viewport for label area */
144 if(is_label_area==0) {
150 } else {
156 }
157 /* Set viewport for plot area */
163 /* Set plot area contents (inside plot area) */
165 for(ti=m=0; ti<vp->y.tick_nr; ti++) {n=strlen(vp->y.tick_label[ti]); if(n>m) m=n;}
166 if(verbose>2) printf("max_yaxis_label_len=%d\n", m);
168 else if(m<5) vp->coordinate_area_viewport.x=vp->plot_area_viewport.w/10;
169 else if(m<7) vp->coordinate_area_viewport.x=vp->plot_area_viewport.w/7; // prev 8
170 else vp->coordinate_area_viewport.x=vp->plot_area_viewport.w/4; // prev 5
174 /* Calculate the character size for tick labels etc */
176 ceil(0.62*(double)(vp->plot_area_viewport.h-vp->coordinate_area_viewport.h)); // prev 0.67
177
178 if(verbose>3) printf("coordinate_area_viewport.h := %d\n", vp->coordinate_area_viewport.h);
179
180 return(0);
181}
#define SVG_VIEWPORT_WIDTH
Definition libtpcsvg.h:21
#define SVG_VIEWPORT_HEIGHT
Definition libtpcsvg.h:23
int tick_nr
Definition libtpcsvg.h:83
char tick_label[MAX_TICK_NR][MAX_TICK_LABEL_LEN+1]
Definition libtpcsvg.h:91
struct svg_viewport_pos coordinate_area_viewport
Definition libtpcsvg.h:116
struct svg_viewport_pos main_title_viewport
Definition libtpcsvg.h:106
struct svg_viewport_pos label_area_viewport
Definition libtpcsvg.h:112
struct svg_viewport_pos main_viewport
Definition libtpcsvg.h:104
struct svg_viewport_pos yaxis_title_viewport
Definition libtpcsvg.h:108
struct svg_coord y
Definition libtpcsvg.h:120
struct svg_viewport_pos plot_area_viewport
Definition libtpcsvg.h:114
struct svg_viewport_pos xaxis_title_viewport
Definition libtpcsvg.h:110

Referenced by plot_fit_svg(), plot_fitrange_svg(), and plot_svg().

◆ svg_init_coord()

void svg_init_coord ( struct svg_coord * p)

Initiate struct svg_coord contents to all-zeroes before use.

Definition at line 26 of file svg_vport.c.

28 {
29 p->min=0;
30 p->max=0;
31 p->scale=0.0;
32 p->origo=0.0;
33 p->tick_nr=0;
34 for(int i=0; i<MAX_TICK_NR; i++) p->tick[i]=0.0;
35 p->tickscale=0.0;
36 p->tick_decimals=0.0;
37 for(int i=0; i<MAX_TICK_NR; i++) p->tick_label[i][0]=(char)0;
38 p->upper_margin=0;
39 p->fixed_min=0;
40 p->fixed_max=0;
41}
#define MAX_TICK_NR
Definition libtpcsvg.h:25
int upper_margin
Definition libtpcsvg.h:93
double tickscale
Definition libtpcsvg.h:87
double origo
Definition libtpcsvg.h:81
double scale
Definition libtpcsvg.h:79
int fixed_max
Definition libtpcsvg.h:97
int tick_decimals
Definition libtpcsvg.h:89
double tick[MAX_TICK_NR]
Definition libtpcsvg.h:85
double max
Definition libtpcsvg.h:77
int fixed_min
Definition libtpcsvg.h:95
double min
Definition libtpcsvg.h:75

Referenced by svg_init_viewports().

◆ svg_init_viewport_pos()

void svg_init_viewport_pos ( struct svg_viewport_pos * p)

Initiate struct svg_viewport_pos contents to all-zeroes before use.

Definition at line 15 of file svg_vport.c.

17 {
18 p->is=0;
19 p->x=0;
20 p->y=0;
21 p->w=0;
22 p->h=0;
23 p->chr_size=0;
24}

Referenced by svg_init_viewports().

◆ svg_init_viewports()

void svg_init_viewports ( struct svg_viewports * p)

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().

Variable Documentation

◆ SVG_INLINE

int SVG_INLINE
extern

Write inline SVG (1) or separate SVG file (0)

Definition at line 12 of file svg_file.c.