95 int i=0, n, crossings=0;
100 printf(
"%s(%g, %g, %g, %g, cavp, nx1, ny1, nx2, ny2, %d)\n",
101 __func__, x1, y1, x2, y2, verbose);
105 mx[0]=x1; my[0]=y1; mx[1]=x2; my[1]=y2;
107 n=
get_line_intersection(x1, y1, x2, y2, 0.0, 0.0, (
double)cavp->
w, 0.0, &ix, &iy, verbose);
110 if(y1<iy) i=0;
else i=1;
112 if(i==0) i=1;
else i=0;
114 mx[i]=ix; my[i]=iy; crossings++;
116 printf(
"line between (%g,%g) and (%g,%g) would cross upper border at (%g,%g)\n",
117 x1, y1, x2, y2, ix, iy);
121 0.0, (
double)cavp->
h, (
double)cavp->
w, (
double)cavp->
h, &ix, &iy, verbose);
124 if(y1>iy) i=0;
else i=1;
126 if(i==0) i=1;
else i=0;
128 mx[i]=ix; my[i]=iy; crossings++;
130 printf(
"line between (%g,%g) and (%g,%g) would cross lower border at (%g,%g)\n",
131 x1, y1, x2, y2, ix, iy);
135 0.0, 0.0, 0.0, cavp->
h,
139 if(x1<ix) i=0;
else i=1;
141 if(i==0) i=1;
else i=0;
143 mx[i]=ix; my[i]=iy; crossings++;
145 printf(
"line between (%g,%g) and (%g,%g) would cross left border at (%g,%g)\n",
146 x1, y1, x2, y2, ix, iy);
150 (
double)cavp->
w, 0.0, (
double)cavp->
w, (
double)cavp->
h,
154 if(x1>ix) i=0;
else i=1;
156 if(i==0) i=1;
else i=0;
158 mx[i]=ix; my[i]=iy; crossings++;
160 printf(
"line between (%g,%g) and (%g,%g) would cross right border at (%g,%g)\n",
161 x1, y1, x2, y2, ix, iy);
163 if(verbose>3 && crossings>0) printf(
"crossings=%d\n", crossings);
165 if(nx1!=NULL) *nx1=mx[0];
166 if(ny1!=NULL) *ny1=my[0];
167 if(nx2!=NULL) *nx2=mx[1];
168 if(ny2!=NULL) *ny2=my[1];
169 if(verbose>2 && crossings>0)
170 printf(
"modified line (%g,%g) -> (%g,%g)\n", mx[0], my[0], mx[1], my[1]);
566 char tmp[1024], line[128], ilc[9];
568 double pos, ypos, yheight;
570 if(verbose>0) {printf(
"%s(fp, vp, errmsg, %d)\n", __func__, verbose); fflush(stdout);}
574 if(fp==NULL) {
if(errmsg!=NULL) sprintf(errmsg,
"file was closed too early");
return(1);}
576 if(
SVG_INLINE) strcpy(ilc,
"svg:");
else strcpy(ilc,
"");
581 strcpy(tmp,
"\n <!-- X axis ticks inside plot area -->\n");
583 sprintf(tmp,
" <%srect x=\"0px\" y=\"%dpx\" width=\"%dpx\" height=\"%gpx\" stroke=\"none\" fill=\"aqua\" fill-opacity=\"0.3\" />\n",
586 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(99);}
589 sprintf(tmp,
" <%sg", ilc);
590 sprintf(line,
" stroke=\"%s\"",
"black"); strcat(tmp, line);
591 sprintf(line,
" stroke-width=\"%g\"", 20.); strcat(tmp, line);
592 sprintf(line,
" fill=\"%s\"",
"none"); strcat(tmp, line);
594 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(5);}
603 if(verbose>1) printf(
"ti=%d: x tick pos=%g\n", ti, pos);
604 sprintf(tmp,
" <%s", ilc);
605 sprintf(line,
"line x1=\"%g\" x2=\"%g\" y1=\"%g\" y2=\"%g\" />\n",
606 pos, pos, ypos, ypos+yheight/8);
608 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(6);}
613 if(pos<vp->plot_area_viewport.w) {
614 if(verbose>1) printf(
"extra ti=%d: x tick pos=%g\n", ti, pos);
615 sprintf(tmp,
" <%s", ilc);
616 sprintf(line,
"line x1=\"%g\" x2=\"%g\" y1=\"%g\" y2=\"%g\" />\n",
617 pos, pos, ypos, ypos+yheight/8);
619 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(6);}
621 sprintf(tmp,
" </%sg>\n", ilc);
622 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(7);}
625 sprintf(tmp,
" <%sg", ilc);
626 sprintf(line,
" font-family=\"Sans-serif\""); strcat(tmp, line);
627 sprintf(line,
" text-anchor=\"middle\""); strcat(tmp, line);
629 sprintf(line,
" fill=\"black\""); strcat(tmp, line);
631 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(8);}
635 if(verbose>1) printf(
"ti=%d: x tick pos=%g\n", ti, pos);
636 sprintf(tmp,
" <%s", ilc);
637 sprintf(line,
"text x=\"%g\" y=\"%g\"", pos, ypos+0.92*(
double)yheight); strcat(tmp, line);
638 sprintf(line,
">"); strcat(tmp, line);
640 strcat(tmp,
"</"); strcat(tmp, ilc); strcat(tmp,
"text>\n");
641 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(9);}
643 sprintf(tmp,
" </%sg>\n", ilc);
644 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(10);}
666 char tmp[1024], line[128], ilc[9];
670 if(verbose>0) {printf(
"%s(fp, vp, errmsg, %d)\n", __func__, verbose); fflush(stdout);}
674 if(fp==NULL) {
if(errmsg!=NULL) sprintf(errmsg,
"file was closed too early");
return(1);}
676 if(
SVG_INLINE) strcpy(ilc,
"svg:");
else strcpy(ilc,
"");
680 strcpy(tmp,
"\n <!-- Y axis ticks inside plot area -->\n");
683 " <%srect width=\"%gpx\" height=\"%dpx\" stroke=\"none\" fill=\"aqua\" fill-opacity=\"0.3\" />\n",
686 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(99);}
689 printf(
"vp->y.tick_nr=%d\n", vp->
y.
tick_nr);
690 printf(
"vp->y.tickscale=%g\n", vp->
y.
tickscale);
695 sprintf(tmp,
" <%sg", ilc);
696 sprintf(line,
" stroke=\"%s\"",
"black"); strcat(tmp, line);
697 sprintf(line,
" stroke-width=\"%g\"", 20.); strcat(tmp, line);
698 sprintf(line,
" fill=\"%s\"",
"none"); strcat(tmp, line);
700 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(5);}
703 if(verbose>1) printf(
"ti=%d: y tick pos=%g\n", ti, pos);
704 sprintf(tmp,
" <%s", ilc);
705 sprintf(line,
"line x1=\"%g\" x2=\"%g\" y1=\"%g\" y2=\"%g\" />\n",
708 pos, pos); strcat(tmp, line);
709 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(6);}
711 sprintf(tmp,
" </%sg>\n", ilc);
712 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(7);}
715 sprintf(tmp,
" <%sg", ilc);
716 sprintf(line,
" font-family=\"Sans-serif\""); strcat(tmp, line);
717 sprintf(line,
" text-anchor=\"end\""); strcat(tmp, line);
719 sprintf(line,
" fill=\"black\""); strcat(tmp, line);
721 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(8);}
724 if(verbose>1) printf(
"ti=%d: y tick pos=%g\n", ti, pos);
725 sprintf(tmp,
" <%s", ilc);
726 sprintf(line,
"text x=\"%g\" y=\"%g\"",
729 sprintf(line,
">"); strcat(tmp, line);
731 strcat(tmp,
"</"); strcat(tmp, ilc); strcat(tmp,
"text>\n");
732 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(9);}
734 sprintf(tmp,
" </%sg>\n", ilc);
735 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(10);}
756 const char *tac_title,
778 char tmp[1024], line[128], ilc[9];
780 double px, py, size=100.0, trgsize=140.0, circsize=120.0;
783 printf(
"%s(fp, vp, %d, %s, %s, x, y, %d, %s, %d, %d, errmsg, %d)\n", __func__,
784 plot_type, tac_id, tac_title, data_nr, color, (
int)symbol_type, (
int)symbol_fill, verbose);
789 if(data_nr<1)
return(0);
790 if(fp==NULL) {
if(errmsg!=NULL) sprintf(errmsg,
"file was closed too early");
return(1);}
791 if(color==NULL || strlen(color)<2) {
792 if(errmsg!=NULL) sprintf(errmsg,
"invalid color");
796 if(
SVG_INLINE) strcpy(ilc,
"svg:");
else strcpy(ilc,
"");
799 sprintf(tmp,
"\n <!-- %s : %s -->\n <%sg", tac_id, tac_title, ilc);
800 sprintf(line,
" stroke=\"%s\"", color); strcat(tmp, line);
801 sprintf(line,
" stroke-width=\"%g\"", 0.25*size); strcat(tmp, line);
802 sprintf(line,
" fill=\"%s\"", color); strcat(tmp, line);
803 if(symbol_fill==SYMBOLOPEN) sprintf(line,
" fill-opacity=\"0.02\"");
804 else sprintf(line,
" fill-opacity=\"0.92\"");
805 strcat(tmp, line); strcat(tmp,
">\n");
806 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(11);}
808 sprintf(tmp,
" <%s", ilc);
809 sprintf(line,
"title>"); strcat(tmp, line);
811 if(senc==NULL) strcat(tmp, tac_title);
else {strcat(tmp, senc); free(senc);}
812 strcat(tmp,
"</"); strcat(tmp, ilc); strcat(tmp,
"title>\n");
813 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(12);}
816 strcpy(tmp,
""); strcpy(line,
"");
817 if(plot_type==0 || plot_type==1) {
818 int lineon=0, path_started=0, prev_exists=0, cross_nr;
819 double prev_px=-1, prev_py=-1, nx1, ny1, nx2, ny2;
823 for(i=j=0; i<data_nr; i++) {
824 if(isnan(x[i]) || isnan(y[i])) {lineon=0;
continue;}
827 if(path_started==0) {
828 sprintf(tmp,
" <%spath fill=\"none\" d=\"", ilc);
829 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(14);}
832 if(
svg_write(fp, line, errmsg, verbose-5)!=0) {
return(15);}
834 j=0; strcpy(line,
"\n ");
837 if(verbose>3) printf(
"x[%d]=%g y[%d]=%g\n", i, x[i], i, y[i]);
841 if(prev_exists==0) {prev_px=px; prev_py=py; prev_exists=1;}
845 if(verbose>2 &&cross_nr>0)
846 printf(
"new line coordinates (%g,%g) -> (%g,%g)\n", nx1, ny1, nx2, ny2);
849 if(j>0) strcat(line,
" ");
850 sprintf(tmp,
"M%.0f %.0f L%.0f %.0f", nx1, ny1, nx2, ny2);
851 if(verbose>4) printf(
" write %s\n", tmp);
852 strcat(line, tmp); j+=2;
855 prev_px=px; prev_py=py;
857 }
else if(cross_nr==1) {
858 if(nx1!=prev_px || ny1!=prev_py) lineon=0;
860 if(j>0) strcat(line,
" ");
861 if(lineon==0) {sprintf(tmp,
"M%.0f %.0f L%.0f %.0f", nx1, ny1, nx2, ny2); j+=2;}
862 else if(lineon==1) {sprintf(tmp,
"L%.0f %.0f", nx2, ny2); j++;}
863 else {sprintf(tmp,
"%.0f %.0f", nx2, ny2); j++;}
864 if(verbose>4) printf(
" write %s\n", tmp);
866 if(nx2!=px || ny2!=py) lineon=0;
else lineon++;
868 prev_px=px; prev_py=py;
871 nx1=prev_px; ny1=prev_py; nx2=px; ny2=py;
874 if(nx1>=0 && nx1<=vp->coordinate_area_viewport.w+1 &&
875 nx2>=0 && nx2<=vp->coordinate_area_viewport.w+1 &&
876 ny1>=0 && ny1<=vp->coordinate_area_viewport.h+1 &&
877 ny2>=0 && ny2<=vp->coordinate_area_viewport.h+1)
879 if(j>0) strcat(line,
" ");
881 if(nx1!=nx2 && ny1!=ny2) sprintf(tmp,
"M%.0f %.0f L%.0f %.0f", nx1, ny1, nx2, ny2);
882 else sprintf(tmp,
"M%.0f %.0f", nx2, ny2);
885 else if(lineon==1) {sprintf(tmp,
"L%.0f %.0f", nx2, ny2); j++;}
886 else {sprintf(tmp,
"%.0f %.0f", nx2, ny2); j++;}
887 if(verbose>4) printf(
" write %s\n", tmp);
893 prev_px=px; prev_py=py;
897 if(path_started==0) {
898 sprintf(tmp,
" <%spath fill=\"none\" d=\"", ilc);
899 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(14);}
901 if(
svg_write(fp, line, errmsg, verbose-5)!=0) {
return(16);}
904 strcpy(tmp,
"\" />\n");
905 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(17);}
910 if(plot_type==0 || plot_type==2) {
911 int prev_px=-1, prev_py=-1;
912 for(i=0; i<data_nr; i++) {
913 if(isnan(x[i]) || isnan(y[i]))
continue;
917 if(px<0 || py<0)
continue;
920 if(px==prev_px && py==prev_py)
continue;
921 prev_px=px; prev_py=py;
923 sprintf(tmp,
" <%suse ", ilc);
924 switch(symbol_type) {
926 sprintf(line,
"xlink:href=\"#sym-rect\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\"",
927 px-0.5*size, py-0.5*size, size, size);
930 sprintf(line,
"xlink:href=\"#sym-uptr\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\"",
931 px-0.5*trgsize, py-0.5*trgsize, trgsize, trgsize);
934 sprintf(line,
"xlink:href=\"#sym-dotr\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\"",
935 px-0.5*trgsize, py-0.5*trgsize, trgsize, trgsize);
938 sprintf(line,
"xlink:href=\"#sym-diam\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\"",
939 px-0.5*trgsize, py-0.5*trgsize, trgsize, trgsize);
942 sprintf(line,
"xlink:href=\"#sym-letr\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\"",
943 px-0.5*trgsize, py-0.5*trgsize, trgsize, trgsize);
946 sprintf(line,
"xlink:href=\"#sym-ritr\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\"",
947 px-0.5*trgsize, py-0.5*trgsize, trgsize, trgsize);
951 sprintf(line,
"xlink:href=\"#sym-circ\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\"",
952 px-0.5*circsize, py-0.5*circsize, circsize, circsize);
956 strcat(tmp,
" />\n");
957 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(18);}
962 sprintf(tmp,
" </%sg>\n", ilc);
963 if(
svg_write(fp, tmp, errmsg, verbose-5)!=0) {
return(19);}