TPCCLIB
Loading...
Searching...
No Matches
libtpcsvg
svg_vport.c
Go to the documentation of this file.
1
5
/*****************************************************************************/
6
#include "
libtpcsvg.h
"
7
#include <math.h>
8
/*****************************************************************************/
10
extern
int
SVG_INLINE
;
11
/*****************************************************************************/
12
13
/*****************************************************************************/
15
void
svg_init_viewport_pos
(
16
struct
svg_viewport_pos
*p
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
}
26
void
svg_init_coord
(
27
struct
svg_coord
*p
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
}
43
void
svg_init_viewports
(
44
struct
svg_viewports
*p
45
) {
46
svg_init_viewport_pos
(&p->
main_viewport
);
47
svg_init_viewport_pos
(&p->
main_title_viewport
);
48
svg_init_viewport_pos
(&p->
yaxis_title_viewport
);
49
svg_init_viewport_pos
(&p->
xaxis_title_viewport
);
50
svg_init_viewport_pos
(&p->
label_area_viewport
);
51
svg_init_viewport_pos
(&p->
plot_area_viewport
);
52
svg_init_viewport_pos
(&p->
coordinate_area_viewport
);
53
svg_init_coord
(&p->
x
);
54
svg_init_coord
(&p->
y
);
55
}
56
/*****************************************************************************/
57
58
/*****************************************************************************/
65
int
svg_define_viewports
(
67
const
int
main_viewport_width,
69
const
int
main_viewport_height,
71
const
int
is_main_title,
73
const
int
is_yaxis_title,
75
const
int
is_xaxis_title,
77
const
int
is_label_area,
79
struct
svg_viewports
*vp,
81
int
verbose
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 */
92
vp->
main_viewport
.
is
=1; vp->
main_viewport
.
x
=vp->
main_viewport
.
y
=0;
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) {
97
vp->
main_title_viewport
.
is
=0;
98
vp->
main_title_viewport
.
x
=vp->
main_title_viewport
.
y
=0;
99
vp->
main_title_viewport
.
w
=vp->
main_title_viewport
.
h
=0;
100
vp->
main_title_viewport
.
chr_size
=0;
101
}
else
{
102
vp->
main_title_viewport
.
is
=1;
103
vp->
main_title_viewport
.
x
=vp->
main_title_viewport
.
y
=0;
104
vp->
main_title_viewport
.
w
=vp->
main_viewport
.
w
;
105
vp->
main_title_viewport
.
h
=vp->
main_viewport
.
w
/12;
106
vp->
main_title_viewport
.
chr_size
=5*vp->
main_title_viewport
.
h
/10;
107
}
108
/* Set viewport for x axis title */
109
if
(is_xaxis_title==0) {
110
vp->
xaxis_title_viewport
.
is
=0;
111
vp->
xaxis_title_viewport
.
x
=0;
112
vp->
xaxis_title_viewport
.
y
=vp->
main_title_viewport
.
h
;
113
vp->
xaxis_title_viewport
.
w
=vp->
main_title_viewport
.
w
;
114
vp->
xaxis_title_viewport
.
h
=0;
115
vp->
xaxis_title_viewport
.
chr_size
=0;
116
}
else
{
117
vp->
xaxis_title_viewport
.
is
=1;
118
vp->
xaxis_title_viewport
.
x
=0;
119
vp->
xaxis_title_viewport
.
w
=vp->
main_viewport
.
w
;
120
vp->
xaxis_title_viewport
.
h
=vp->
main_viewport
.
h
/18;
121
vp->
xaxis_title_viewport
.
y
=vp->
main_viewport
.
h
-vp->
xaxis_title_viewport
.
h
;
122
vp->
xaxis_title_viewport
.
chr_size
=7*vp->
xaxis_title_viewport
.
h
/10;
123
}
124
/* Set viewport for y axis title */
125
if
(is_yaxis_title==0) {
126
vp->
yaxis_title_viewport
.
is
=0;
127
vp->
yaxis_title_viewport
.
x
=0;
128
vp->
yaxis_title_viewport
.
y
=vp->
main_title_viewport
.
h
;
129
vp->
yaxis_title_viewport
.
w
=0;
130
vp->
yaxis_title_viewport
.
h
=vp->
main_viewport
.
h
-vp->
main_title_viewport
.
h
-vp->
xaxis_title_viewport
.
h
;
131
vp->
yaxis_title_viewport
.
chr_size
=0;
132
}
else
{
133
vp->
yaxis_title_viewport
.
is
=1;
134
vp->
yaxis_title_viewport
.
x
=0;
135
vp->
yaxis_title_viewport
.
y
=vp->
main_title_viewport
.
h
;
136
vp->
yaxis_title_viewport
.
w
=vp->
main_viewport
.
w
/18;
137
vp->
yaxis_title_viewport
.
h
=vp->
main_viewport
.
h
-vp->
main_title_viewport
.
h
-vp->
xaxis_title_viewport
.
h
;
138
if
(vp->
xaxis_title_viewport
.
is
)
139
vp->
yaxis_title_viewport
.
chr_size
=vp->
xaxis_title_viewport
.
chr_size
;
140
else
141
vp->
yaxis_title_viewport
.
chr_size
=7*vp->
yaxis_title_viewport
.
w
/10;
142
}
143
/* Set viewport for label area */
144
if
(is_label_area==0) {
145
vp->
label_area_viewport
.
is
=0;
146
vp->
label_area_viewport
.
x
=vp->
main_viewport
.
w
;
147
vp->
label_area_viewport
.
y
=vp->
main_title_viewport
.
h
;
148
vp->
label_area_viewport
.
w
=0;
149
vp->
label_area_viewport
.
h
=vp->
main_viewport
.
h
-vp->
main_title_viewport
.
h
-vp->
xaxis_title_viewport
.
h
;
150
}
else
{
151
vp->
label_area_viewport
.
is
=1;
152
vp->
label_area_viewport
.
x
=3*vp->
main_viewport
.
w
/4;
153
vp->
label_area_viewport
.
y
=vp->
main_title_viewport
.
h
;
154
vp->
label_area_viewport
.
w
=vp->
main_viewport
.
w
-vp->
label_area_viewport
.
x
;
155
vp->
label_area_viewport
.
h
=vp->
main_viewport
.
h
-vp->
main_title_viewport
.
h
-vp->
xaxis_title_viewport
.
h
;
156
}
157
/* Set viewport for plot area */
158
vp->
plot_area_viewport
.
is
=1;
159
vp->
plot_area_viewport
.
x
=vp->
yaxis_title_viewport
.
w
;
160
vp->
plot_area_viewport
.
y
=vp->
main_title_viewport
.
h
;
161
vp->
plot_area_viewport
.
w
=vp->
main_viewport
.
w
-vp->
yaxis_title_viewport
.
w
-vp->
label_area_viewport
.
w
;
162
vp->
plot_area_viewport
.
h
=vp->
main_viewport
.
h
-vp->
main_title_viewport
.
h
-vp->
xaxis_title_viewport
.
h
;
163
/* Set plot area contents (inside plot area) */
164
vp->
coordinate_area_viewport
.
is
=1;
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);
167
if
(m<3) vp->
coordinate_area_viewport
.
x
=vp->
plot_area_viewport
.
w
/14;
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
171
vp->
coordinate_area_viewport
.
y
=0;
172
vp->
coordinate_area_viewport
.
w
=vp->
plot_area_viewport
.
w
-vp->
coordinate_area_viewport
.
x
;
173
vp->
coordinate_area_viewport
.
h
=19*vp->
plot_area_viewport
.
h
/20;
174
/* Calculate the character size for tick labels etc */
175
vp->
plot_area_viewport
.
chr_size
=vp->
coordinate_area_viewport
.
chr_size
=
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
}
182
/*****************************************************************************/
183
184
/*****************************************************************************/
libtpcsvg.h
Header file for libtpcsvg.
MAX_TICK_NR
#define MAX_TICK_NR
Definition
libtpcsvg.h:25
SVG_VIEWPORT_WIDTH
#define SVG_VIEWPORT_WIDTH
Definition
libtpcsvg.h:21
SVG_VIEWPORT_HEIGHT
#define SVG_VIEWPORT_HEIGHT
Definition
libtpcsvg.h:23
svg_coord
Definition
libtpcsvg.h:73
svg_coord::upper_margin
int upper_margin
Definition
libtpcsvg.h:93
svg_coord::tickscale
double tickscale
Definition
libtpcsvg.h:87
svg_coord::tick_nr
int tick_nr
Definition
libtpcsvg.h:83
svg_coord::origo
double origo
Definition
libtpcsvg.h:81
svg_coord::scale
double scale
Definition
libtpcsvg.h:79
svg_coord::fixed_max
int fixed_max
Definition
libtpcsvg.h:97
svg_coord::tick_decimals
int tick_decimals
Definition
libtpcsvg.h:89
svg_coord::tick
double tick[MAX_TICK_NR]
Definition
libtpcsvg.h:85
svg_coord::max
double max
Definition
libtpcsvg.h:77
svg_coord::fixed_min
int fixed_min
Definition
libtpcsvg.h:95
svg_coord::tick_label
char tick_label[MAX_TICK_NR][MAX_TICK_LABEL_LEN+1]
Definition
libtpcsvg.h:91
svg_coord::min
double min
Definition
libtpcsvg.h:75
svg_viewport_pos
Definition
libtpcsvg.h:55
svg_viewport_pos::x
int x
Definition
libtpcsvg.h:59
svg_viewport_pos::chr_size
int chr_size
Definition
libtpcsvg.h:67
svg_viewport_pos::is
int is
Definition
libtpcsvg.h:57
svg_viewport_pos::y
int y
Definition
libtpcsvg.h:61
svg_viewport_pos::w
int w
Definition
libtpcsvg.h:63
svg_viewport_pos::h
int h
Definition
libtpcsvg.h:65
svg_viewports
Definition
libtpcsvg.h:102
svg_viewports::coordinate_area_viewport
struct svg_viewport_pos coordinate_area_viewport
Definition
libtpcsvg.h:116
svg_viewports::main_title_viewport
struct svg_viewport_pos main_title_viewport
Definition
libtpcsvg.h:106
svg_viewports::label_area_viewport
struct svg_viewport_pos label_area_viewport
Definition
libtpcsvg.h:112
svg_viewports::x
struct svg_coord x
Definition
libtpcsvg.h:118
svg_viewports::main_viewport
struct svg_viewport_pos main_viewport
Definition
libtpcsvg.h:104
svg_viewports::yaxis_title_viewport
struct svg_viewport_pos yaxis_title_viewport
Definition
libtpcsvg.h:108
svg_viewports::y
struct svg_coord y
Definition
libtpcsvg.h:120
svg_viewports::plot_area_viewport
struct svg_viewport_pos plot_area_viewport
Definition
libtpcsvg.h:114
svg_viewports::xaxis_title_viewport
struct svg_viewport_pos xaxis_title_viewport
Definition
libtpcsvg.h:110
SVG_INLINE
int SVG_INLINE
Definition
svg_file.c:12
svg_init_coord
void svg_init_coord(struct svg_coord *p)
Definition
svg_vport.c:26
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)
Definition
svg_vport.c:65
svg_init_viewports
void svg_init_viewports(struct svg_viewports *p)
Definition
svg_vport.c:43
svg_init_viewport_pos
void svg_init_viewport_pos(struct svg_viewport_pos *p)
Definition
svg_vport.c:15
Generated on Fri Sep 19 2025 13:32:05 for TPCCLIB by
1.12.0