89 char tmp[1024], line[128], ilc[9];
90 double xpos, ypos, ygap, size=100.0, trgsize=140.0, circsize=120.0;
91 int ti, len, maxlen, text_space;
94 const double hrratio=1.20;
96 if(verbose>0) printf(
"%s(fp, vp, legends, errmsg, %d)\n", __func__, verbose);
100 if(legends==NULL || legends->
n<1)
return(0);
102 if(errmsg!=NULL) sprintf(errmsg,
"file was closed too early");
106 if(
SVG_INLINE) strcpy(ilc,
"svg:");
else strcpy(ilc,
"");
109 strcpy(tmp,
"\n <!-- Legends viewport -->\n");
110 sprintf(line,
" <%ssvg x=\"%dpx\" y=\"%dpx\" width=\"%dpx\" height=\"%d\"",
113 sprintf(line,
"\n viewBox=\"0 0 %d %d\"",
115 strcat(tmp,
"\n preserveAspectRatio=\"xMidYMid meet\"");
117 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(4);}
121 sprintf(tmp,
" <%srect width=\"%dpx\" height=\"%dpx\" stroke=\"none\" fill=\"red\" fill-opacity=\"0.3\" />\n",
123 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(99);}
131 ti=legends->
n;
if(ti<defNr) ti=defNr;
136 ti=0; maxlen=len=strlen(legends->
l[ti].
text);
137 for(ti=1; ti<legends->
n; ti++) {
138 len=strlen(legends->
l[ti].
text);
if(len>maxlen) maxlen=len;}
149 sprintf(tmp,
" <%sg", ilc);
150 sprintf(line,
" font-family=\"Sans-serif\""); strcat(tmp, line);
151 sprintf(line,
" text-anchor=\"Start\""); strcat(tmp, line);
153 sprintf(line,
" fill=\"black\""); strcat(tmp, line);
155 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(8);}
157 for(ti=0; ti<legends->
n; ti++) {
159 sprintf(tmp,
" <%s", ilc);
160 sprintf(line,
"text x=\"%g\" y=\"%g\"", xpos, ypos); strcat(tmp, line);
161 sprintf(line,
">"); strcat(tmp, line);
163 if(senc==NULL) strcat(tmp, legends->
l[ti].
text);
else {strcat(tmp, senc); free(senc);}
164 strcat(tmp,
"</"); strcat(tmp, ilc); strcat(tmp,
"text>\n");
165 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(9);}
168 sprintf(tmp,
" </%sg>\n", ilc);
169 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(10);}
174 for(ti=0; ti<legends->
n; ti++) {
175 sprintf(tmp,
" <%sg", ilc);
176 sprintf(line,
" stroke=\"%s\"",
svgColorName(legends->
l[ti].
color)); strcat(tmp, line);
178 if(legends->
l[ti].
symbol_fill==SYMBOLOPEN) sprintf(line,
" fill-opacity=\"0.02\"");
179 else sprintf(line,
" fill-opacity=\"0.92\"");
181 sprintf(line,
" stroke-width=\"25\""); strcat(tmp, line);
183 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(8);}
187 sprintf(tmp,
" <%sline", ilc);
188 sprintf(line,
" x1=\"%g\"", 0.25*xpos); strcat(tmp, line);
189 sprintf(line,
" y1=\"%g\"", ypos); strcat(tmp, line);
190 sprintf(line,
" x2=\"%g\"", 1.75*xpos); strcat(tmp, line);
191 sprintf(line,
" y2=\"%g\"", ypos); strcat(tmp, line);
192 strcat(tmp,
" />\n");
193 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(18);}
198 sprintf(tmp,
" <%suse ", ilc);
201 sprintf(line,
"xlink:href=\"#sym-rect\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\"",
202 xpos-0.5*size, ypos-0.5*size, size, size);
205 sprintf(line,
"xlink:href=\"#sym-uptr\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\"",
206 xpos-0.5*trgsize, ypos-0.5*trgsize, trgsize, trgsize);
209 sprintf(line,
"xlink:href=\"#sym-dotr\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\"",
210 xpos-0.5*trgsize, ypos-0.5*trgsize, trgsize, trgsize);
213 sprintf(line,
"xlink:href=\"#sym-diam\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\"",
214 xpos-0.5*trgsize, ypos-0.5*trgsize, trgsize, trgsize);
217 sprintf(line,
"xlink:href=\"#sym-letr\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\"",
218 xpos-0.5*trgsize, ypos-0.5*trgsize, trgsize, trgsize);
221 sprintf(line,
"xlink:href=\"#sym-ritr\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\"",
222 xpos-0.5*trgsize, ypos-0.5*trgsize, trgsize, trgsize);
226 sprintf(line,
"xlink:href=\"#sym-circ\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\"",
227 xpos-0.5*circsize, ypos-0.5*circsize, circsize, circsize);
231 strcat(tmp,
" />\n");
232 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(18);}
236 sprintf(tmp,
" </%sg>\n", ilc);
237 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(10);}
242 sprintf(tmp,
" </%ssvg>\n", ilc);
243 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(9);}