1
/************************************************************************************
2
TerraLib - a library for developing GIS applications.
3
Copyright ļæ½ 2001-2004 INPE and Tecgraf/PUC-Rio.
5
This code is part of the TerraLib library.
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Lesser General Public
8
License as published by the Free Software Foundation; either
9
version 2.1 of the License, or (at your option) any later version.
11
You should have received a copy of the GNU Lesser General Public
12
License along with this library.
14
The authors reassure the license terms regarding the warranties.
15
They specifically disclaim any warranties, including, but not limited to,
16
the implied warranties of merchantability and fitness for a particular purpose.
17
The library provided hereunder is on an "as is" basis, and the authors have no
18
obligation to provide maintenance, support, updates, enhancements, or modifications.
19
In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
20
indirect, special, incidental, or consequential damages arising out of the use
21
of this library and its documentation.
22
*************************************************************************************/
25
#pragma warning ( disable: 4786 )
29
#include <TeDefines.h>
36
int set_font(int font_number);
38
#define PEN_UP 0 /* pen status up */
39
#define PEN_DOWN 1 /* pen status down */
41
#define ERR -1 /* return value when error occurs */
47
/*** symbol shapes ***/
49
#define RECTANGLE 0 /* tells PlotSymbol to draw a rectangle */
50
#define TRIANGLE 1 /* tells PlotSymbol to draw a triangle */
51
#define DIAMOND 2 /* tells PlotSymbol to draw a diamond */
52
#define SCROSS 3 /* tells PlotSymbol to draw an upright cross */
53
#define XCROSS 4 /* tells PlotSymbol to draw an angled cross */
57
#define CURVES_LIMIT 10 /* maximum number of curves */
58
#define MAIN_ROW 3 /* row number for main menu */
59
#define MAIN_COL 2 /* column number for main menu */
60
#define MAX_ITEMS 13 /* maximum number of items in a menu window */
61
#define MASK_SIZE 50 /* length of file mask string */
62
#define ASCII 0 /* Ascii output format */
63
#define BINARY 1 /* Binary output format */
64
#define LOAD 0 /* load options */
65
#define SAVE 1 /* save options */
66
#define SET 2 /* set options */
67
#define DIGITS 6 /* number of digits to display for regression
68
coefficients and mean square error */
69
int Font_width[FONT_MAX] = {9,9};
70
int Font_height[FONT_MAX] = {15,15};
71
int Font_direct[FONT_MAX] = {HORIZ_FONT,VERT_FONT};
74
char Symbol[CURVES_MAX] = { /* symbols identifying each curve */
75
RECTANGLE, /* symbol for curve 1 is a rectangle */
76
SCROSS, /* symbol for curve 4 is an upright cross */
77
TRIANGLE, /* symbol for curve 2 is a triangle */
78
DIAMOND, /* symbol for curve 3 is a diamond */
79
XCROSS, /* symbol for curve 5 is an angled cross */
80
RECTANGLE, /* symbol for curve 6 is a rectangle */
81
SCROSS, /* symbol for curve 9 is an upright cross */
82
TRIANGLE, /* symbol for curve 7 is a triangle */
83
DIAMOND, /* symbol for curve 8 is a diamond */
84
XCROSS /* symbol for curve 10 is an angled cross */
88
{ /* terms in each regression function */
89
0, /* terms for polynomial set by regres_func */
90
2, /* number of exponential terms */
91
2, /* number of logarithmic terms */
92
3 /* number of sinusoidal terms */
96
struct { /* Options default settings */
103
char filemask[MASK_SIZE];
109
char printer_port[5];
116
} Options ; /* curve legend turned on */
119
unsigned char background; /* color of outermost window */
120
unsigned char pattern; /* color of pattern in outermost window */
121
unsigned char input; /* color of input window */
122
unsigned char input_prompt; /* color of input window prompt */
123
unsigned char input_answer; /* color of input window answer */
124
unsigned char edit; /* color of edit window */
125
unsigned char edit_bar; /* color of selection bar in edit window */
126
unsigned char edit_answer; /* color of answer bar in edit window */
127
unsigned char edit_index; /* color of index values in edit window */
128
unsigned char edit_heading; /* color of X/Y values heading in edit window */
129
unsigned char error; /* color of error window */
130
unsigned char help; /* color of help message text */
134
TeColor grid; /* color of plot grid */
135
TeColor text; /* color of plot text */
136
TeColor lines; /* color of plot all lines */
137
TeColor symbol[CURVES_LIMIT];/* color of plot all lines */
138
TeColor curve[CURVES_LIMIT]; /* color of plot curves */
141
int f_spoly(Real x, Real_Vector terms, unsigned n);
142
int f_sexp(Real x, Real_Vector terms, unsigned n);
143
int f_slog(Real x, Real_Vector terms, unsigned n);
144
int f_ssin(Real x, Real_Vector terms, unsigned n);
146
int (*Function[])(Real, Real_Vector, unsigned) =
147
{ /* array of functions used for regression */
148
f_spoly, /* calculate terms of polynomial equation */
149
f_sexp, /* calculate terms of exponential equation */
150
f_slog, /* calculate terms of logarithmic equation */
151
f_ssin /* calculate terms of sinusoidal equation */
154
Real vmaxval(Real_Vector v, unsigned int n, int *imx)
156
// subroutine determines the maximum value (maxx) of the
157
// vector v[] of length n and returns the index (imx) where
158
// the maximum occurs; i.e. imx, where maxx = v[imx].
159
// On exit, the maximum is returned as the value of vmaxval().
182
//---------------------------------------------------------------------------------
184
vminval(Real_Vector v, unsigned int n, int *imn)
186
// subroutine determines the minimum value (minx) of the
187
// vector v[] of length n and returns the index (imn) where
188
// the minimum occurs; i.e. imn, where minx = v[imn].
189
// On exit, the minimum is returned as the value of vminval().
211
//---------------------------------------------------------------------------------
213
TeGraphPlot :: TeGraphPlot ()
231
for( i = 0; i < CURVES_MAX; i++ )
238
Graph_color.grid.init(0,100,100);
239
Graph_color.text.init(0,0,0);
240
Graph_color.lines.init(30,30,30);// preto
242
for( i = 0; i < CURVES_LIMIT; i++ )
244
Graph_color.symbol[i].init(0,255,0);
245
Graph_color.curve[i].init(0,0,0);
251
//---------------------------------------------------------------------------------
253
TeGraphPlot :: ~TeGraphPlot ()
257
//---------------------------------------------------------------------------------
259
TeGraphPlot :: setColorGrid(int r, int g, int b)
261
Graph_color.grid.init(r,g,b);
264
//---------------------------------------------------------------------------------
266
TeGraphPlot :: setColorText(int r, int g, int b)
268
Graph_color.text.init(r,g,b);
271
//---------------------------------------------------------------------------------
273
TeGraphPlot :: setColorSymbol(int r, int g, int b, int curve, int w, int h)
276
for (int i=0; i<CURVES_LIMIT; i++)
277
Graph_color.symbol[i].init(r,g,b);
279
Graph_color.symbol[curve].init(r,g,b);
285
//---------------------------------------------------------------------------------
287
TeGraphPlot :: setColorLine(int r, int g, int b)
289
Graph_color.lines.init(r,g,b);
292
//---------------------------------------------------------------------------------
294
TeGraphPlot :: setColorCurve(int c,int r, int g, int b)
296
if( c < 0 || c > CURVES_LIMIT-1 )
301
Graph_color.curve[c].init(r,g,b);
307
TeGraphPlot :: pieLegends ()
309
if (sliceVector == 0)
319
w = min(width,height);
323
xt = xupleft + w + pw;
326
for (unsigned int i = 0; i < sliceVector->size (); i++)
328
TeLegendEntry slice = (*sliceVector)[i];
330
//vis = slice.visual (TePOLYGONS);
331
TeColor cor = vis.color();
333
setFillAreaColor (cor);
334
string leg = slice.label ();
336
textExtent (leg, xw, xh);
337
textext = max (textext, xw);
338
fillRectangle (xt, yt-ph, pw, ph);
339
drawText ((int)(xt+1.2*pw), yt-2, (char*)leg.c_str ());
341
if (yt > (yupleft + height))
343
xt += (int)(textext+2.2*pw);
351
//---------------------------------------------------------------------------------
353
TeGraphPlot :: setGridSize(int s)
367
//---------------------------------------------------------------------------------
369
TeGraphPlot :: setGridSize(int xma, int yma, int xmi, int ymi )
371
if( xma <= 0 || yma <= 0 || xmi <= 0 || ymi <= 0 )
384
//---------------------------------------------------------------------------------
386
TeGraphPlot :: loadDirect (int format, int curv, int points, Labels& labels, Real_Vector x, Real_Vector y)
388
if( curv < 0 || curv > CURVES_LIMIT-1 )
393
strcpy(Plot_label.title, labels.title);
394
strcpy(Plot_label.xaxis, labels.xaxis);
395
strcpy(Plot_label.yaxis, labels.yaxis);
396
Input_format[curv] = format;
398
strcpy(Plot_label.curve[curv], labels.curve[curv]);
402
Plot_points[curv] = points;
404
if (Plot_curves < (curv+1) )
412
void TeGraphPlot::loadHistogram (TeLegendEntryVector& sv, const string& label)
414
// Manage number of curves, only one histogram is allowed per plotting
417
Input_format[order] = BAR_BINARY;
419
// Allocate space for data arrays
420
unsigned int size = sv.size ();
422
delete [] Plot_x[order];
424
delete [] Plot_y[order];
425
Plot_x[order] = new double [size];
426
Plot_y[order] = new double [size];
427
Plot_points[order] = size;
429
// Transfer data from TeLegendEntrys to double array
431
for (unsigned int i=0;i<size;i++)
433
TeLegendEntry sl = sv[i];
434
Plot_y[order][i] = sl.count();
435
Plot_x[order][i] = (double)i+1;
436
vmax = max (vmax,sl.count() );
440
strcpy(Plot_label.title, label.c_str ());
441
strcpy(Plot_label.xaxis, "Fatia");
442
strcpy(Plot_label.yaxis, "Objetos");
443
strcpy(Plot_label.curve[order],"");
444
setScale(1., Real(size+1) , 0., Real (vmax));
445
setGridSize(size, 8, 1, 1);
448
void TeGraphPlot::loadPie (TeLegendEntryVector& sv, const string& label)
450
// Manage number of curves, only one pie is allowed per plotting
453
Input_format[order] = PIE_BINARY;
454
height = Y_pixels - yupleft;
456
// Allocate space for data arrays
457
unsigned int size = sv.size ();
459
delete [] Plot_x[order];
461
delete [] Plot_y[order];
462
Plot_x[order] = new double [size];
463
Plot_y[order] = new double [size];
464
Plot_points[order] = size;
466
// Transfer data from TeLegendEntrys to double array
468
for (unsigned int i=0;i<size;i++)
470
TeLegendEntry sl = sv[i];
471
Plot_y[order][i] = sl.count();
472
Plot_x[order][i] = (double)i+1;
473
vmax = max (vmax,sl.count() );
477
strcpy(Plot_label.title, label.c_str ());
478
// strcpy(Label.curve[order],label.c_str ());
481
//---------------------------------------------------------------------------------
483
TeGraphPlot :: autoScale(void)
485
// scale axes for Scale_curve (for all curves if Scale_curve == -1)
490
if (Scale_curve == -1)
495
xminval = vminval(Plot_x[index], Plot_points[index], &i);
496
xmaxval = vmaxval(Plot_x[index], Plot_points[index], &i);
497
yminval = vminval(Plot_y[index], Plot_points[index], &i);
498
ymaxval = vmaxval(Plot_y[index], Plot_points[index], &i);
500
if (Scale_curve == -1)
502
for (i = 1; i < Plot_curves; i++)
504
value = vminval(Plot_x[i], Plot_points[i], &index);
505
if (value < xminval) xminval = value;
506
value = vmaxval(Plot_x[i], Plot_points[i], &index);
507
if (value > xmaxval) xmaxval = value;
508
value = vminval(Plot_y[i], Plot_points[i], &index);
509
if (value < yminval) yminval = value;
510
value = vmaxval(Plot_y[i], Plot_points[i], &index);
511
if (value > ymaxval) ymaxval = value;
515
for (int curva=0; curva < Plot_curves; curva++)
517
if (Input_format[curva] == ROSE_BINARY)
526
//---------------------------------------------------------------------------------
528
TeGraphPlot :: setScale(Real x1, Real x2 , Real y1, Real y2)
535
for (int curva=0; curva < Plot_curves; curva++)
537
if (Input_format[curva] == ROSE_BINARY)
546
int f_spoly(Real x, Real_Vector terms, unsigned n)
550
for (i = 1; i < n; i++) terms[i] = x * terms[i-1];
554
int f_sexp(Real x, Real_Vector terms, unsigned n)
558
if (value != HUGE_VAL)
561
terms[n-1] = (Real) value;
566
show_err("Value of exp(x) is too large");
571
int f_slog(Real x, Real_Vector terms, unsigned n)
575
terms[n-1] = (Real) log(x);
579
show_err("Value of x is less than or equal to 0");
584
int f_ssin(Real x, Real_Vector terms, unsigned n)
588
terms[1] = (Real) sin(x);
589
terms[n-1] = (Real) cos(x);
594
show_err("Loss of significance for cos(x) or sin(x)");
599
void show_err (char* /* mess */)
601
// printf("%s\n",mess);
604
//---------------------------------------------------------------------------------
607
TeGraphPlot :: kill(int order)
610
if (Plot_curves == 0)
612
for (i = 0; i < Plot_curves; i++)
614
if (Plot_x[i] == Plot_x[order]) count++;
619
delete [] Plot_x[order];
621
delete [] Plot_y[order];
625
for (i = order; i < Plot_curves-1; i++)
627
Plot_x[i] = Plot_x[i+1];
628
Plot_y[i] = Plot_y[i+1];
629
Plot_points[i] = Plot_points[i+1];
630
strcpy(Plot_label.curve[i], Plot_label.curve[i+1]);
637
//---------------------------------------------------------------------------------
639
TeGraphPlot :: plotCurves ( int with_simbols)
641
short drawplot = true;
642
Plot_symbols = with_simbols; // numero de pontos
643
// que devem ser plotados
645
for (int curva=0; curva < Plot_curves; curva++)
647
if (Plot_y[curva] == NULL)
650
if (Input_format[curva] == PIE_BINARY && sliceVector)
652
plot_title(Plot_label.title);
654
int i, w, h, xc, yc, points;
656
w = min(width,height);
657
h = min(width,height);
660
points = Plot_points[0];
662
Real_Vector y = Plot_y[0];
664
Real count = 0., value;
666
for (i = 0; i < points; i++) count += y[i];
667
if (count == 0.) break;
672
for (i = 0; i < points; i++)
674
TeLegendEntry slice = (*sliceVector)[i];
675
TeColor cor = slice.visual(TePOLYGONS).color ();
678
setFillAreaColor(cor);
679
fillArc (xc, yc, w, h, a1, a2, cor);
683
sprintf (percent," %.1f",value*100);
684
drawText (xc+w/2, yc+h/2, percent, (a1+a2)/2);
690
else if (Input_format[curva] == BAR_BINARY)
692
//-------------------------------------
699
// |__:_|_:_|_:_|_:____
701
//-------------------------------------
705
// Real_Vector x = Plot_x[0],
707
Real_Vector x = Plot_x[curva],
710
// setLineAttributes(Graph_color.curve[0],0,0);
711
// setFillAreaColor(Graph_color.curve[0]);
712
setLineAttributes(Graph_color.curve[curva],TeLnTypeContinuous,0);
713
setFillAreaColor(Graph_color.curve[curva]);
715
for (i = 0; i < Plot_points[curva]; i++)
720
TeLegendEntry slice = (*sliceVector)[i];
721
TeColor cor = slice.visual(TePOLYGONS).color ();
722
setFillAreaColor (cor);
725
// if (i < Plot_points[0]-1)
726
if (i < Plot_points[curva]-1)
728
value_to_pixel(x[i], y[i], &x1, &y1);
729
value_to_pixel(x[i+1], y[i+1], &x2, &y2);
730
if ((height + yupleft - y1 - 1) > 0)
731
fillRectangle(x1-(x2-x1)/2, y1, (x2-x1-2), height + yupleft - y1);
735
value_to_pixel(x[i-1], y[i-1], &x1, &y1);
736
value_to_pixel(x[i], y[i], &x2, &y2);
737
if ((height + yupleft - y2 - 1) > 0)
738
fillRectangle(x2-(x2-x1)/2, y2, (x2-x1-2), height + yupleft - y2);
743
else if (Input_format[curva] == ROSE_BINARY)
749
Real_Vector x = Plot_x[0],
752
plot_title(Plot_label.title);
754
for (i = 0; i < Plot_points[0]-1; i++)
756
if (y[i]==0.)continue;
757
a1 = (int)(x[i] * 64.);
758
a2 = (int)(x[i+1] * 64.) - a1;
759
value_to_pixel(-y[i], y[i], &x1, &y1);
760
value_to_pixel(y[i], -y[i], &x2, &y2);
761
fillArc (x1, y1, x2-x1, y2-y1, a1, a2, Graph_color.curve[0]);
764
Real step = ymaxval / (Real)major_tick;
766
for(Real j = step ; j <= ymaxval; j += step )
768
value_to_pixel(-j, j, &x1, &y1);
769
value_to_pixel(j, -j, &x2, &y2);
771
setLineAttributes(Graph_color.lines,TeLnTypeContinuous,0);
772
drawArc(x1, y1, x2-x1, y2-y1,0,360*64,Graph_color.lines);
775
else if (Input_format[curva] == POINT_BINARY)
779
for (int j = 0; j < Plot_points[curva]; j ++)
780
plotSymbol(Plot_x[curva][j], Plot_y[curva][j], Symbol[curva], GPpointwidth, GPpointheight, curva);
791
plot_curve(Plot_x[curva], Plot_y[curva], Plot_points[curva],Graph_color.curve[curva]);
799
//---------------------------------------------------------------------------------
801
TeGraphPlot :: draw_plot(void)
806
// if (Options.grid[1] == 'n')
809
plot_title(Plot_label.title);
810
plot_xaxis(Plot_label.xaxis);
811
plot_yaxis(Plot_label.yaxis);
812
// if (Options.legend[1] == 'n')
816
//---------------------------------------------------------------------------------
818
TeGraphPlot :: setSymbolType(int type, int curve)
820
if(curve>=0 && curve<=9)
821
Symbol[curve] = type;
824
//---------------------------------------------------------------------------------
826
TeGraphPlot :: draw_symbols(int curve)
830
if (Plot_symbols > 0)
832
step = Plot_points[curve]/Plot_symbols;
833
if (Plot_points[curve] % Plot_symbols != 0) step++;
834
for (i = 0; i < Plot_points[curve]; i += step)
835
plotSymbol(Plot_x[curve][i], Plot_y[curve][i], Symbol[curve], GPpointwidth, GPpointheight, curve);
839
//---------------------------------------------------------------------------------
841
TeGraphPlot :: plot_axes(void)
843
setLineAttributes(Graph_color.lines,TeLnTypeContinuous,0);
844
drawRectangle(xupleft, yupleft, width, height);
847
//---------------------------------------------------------------------------------
849
TeGraphPlot :: plot_ticks(void)
851
int i, x, y, maximum, delta, length;
852
int x_ticks = x_major * x_minor;
853
int y_ticks = y_major * y_minor;
855
setLineAttributes(Graph_color.lines,TeLnTypeContinuous,0);
856
delta = (width-1)/x_ticks;
859
maximum = yupleft + height ;
860
for (i = 1; i < x_ticks; i++)
862
if (i % x_minor == 0)
866
drawLine(x, y, x, y + length );
867
drawLine(x, maximum, x, maximum - length );
870
delta = (height-1)/y_ticks;
873
maximum = xupleft + width -1;
874
for (i = 1; i < y_ticks; i++)
876
if (i % y_minor == 0)
880
drawLine(x, y, x + length , y);
881
drawLine(maximum, y, maximum - length , y);
886
void TeGraphPlot :: plot_grid(void)
888
int i, x, y, maximum, delta;
889
setLineAttributes(Graph_color.grid,TeLnTypeDotted,0);
890
delta = (width-1)/x_major;
892
maximum = yupleft + height - major_tick - 1;
893
for (i = 1; i < x_major; i++)
895
y = yupleft + 1 + major_tick;
896
// while (y < maximum) {
900
drawLine(x,y,x,maximum);
903
delta = (height-1)/y_major;
905
maximum = xupleft + width - major_tick - 1;
906
for (i = 1; i < y_major; i++)
908
x = xupleft + 1 + major_tick;
909
// while (x < maximum) {
913
drawLine(x,y,maximum,y);
918
int TeGraphPlot :: plot_labels(void)
921
int i, x, y, delta, font;
922
int digits_left, digits_right, exp_flag;
923
Real value, values[3];
924
setTextColor(Graph_color.text);
926
if ((font = set_font(label_font)) == ERR) return ERR;
929
values[2] = (values[1] - values[0]) / y_major;
930
label_format(values, 3, label_field, &digits_left, &digits_right, &exp_flag);
931
delta = (height-1) / y_major;
932
y = yupleft - label_height/2;
935
for (i = 0; i <= y_major; i++)
937
ftos(value, digits_left, digits_right, exp_flag, text);
938
x = xupleft - strlen(text) * label_width - label_width/2;
941
drawText (x, y+8, text);
945
if (yaxis_direct == HORIZ_FONT)
947
Yaxis_x -= (yaxis_width + label_width/2);
953
Yaxis_x -= label_width/2;
954
if (Yaxis_x < yaxis_height)
955
Yaxis_x = yaxis_height;
959
values[2] = (values[1] - values[0]) / x_major;
960
label_format(values, 3, label_field, &digits_left, &digits_right, &exp_flag);
961
delta = (width-1) / x_major;
962
y = yupleft + height + label_height/2;
964
for (i = 0; i <= x_major; i++)
966
ftos(value, digits_left, digits_right, exp_flag, text);
967
x = xupleft + i*delta - strlen(text) * label_width / 2;
968
drawText (x, y+8, text);
974
// if (x_major > 9) {
976
// value += values[2];
984
int TeGraphPlot :: plot_title(char *text)
987
if ((font = set_font(title_font)) == ERR) return ERR;
988
plot_horiz(text, Title_y, title_width);
993
int TeGraphPlot :: plot_xaxis(char *text)
996
if ((font = set_font(xaxis_font)) == ERR) return ERR;
997
plot_horiz(text, Xaxis_y, xaxis_width);
1003
TeGraphPlot :: plot_horiz(char *text, int y, int w)
1006
char *ptr = NULL,buffer[80];
1007
setTextColor(Graph_color.text);
1009
x = xupleft + (width-1)/2 - (l * w)/2;
1012
count = (xupleft - x)/w;
1014
strncpy(buffer, text, sizeof(buffer)-1);
1015
buffer[l-count-1] = '\0';
1019
drawText (x, y, ptr);
1024
TeGraphPlot :: plot_yaxis(char *text)
1026
int y, length, count, font, delta;
1027
char *ptr= NULL, buffer[80], c[2];
1028
setTextColor(Graph_color.text);
1029
c[0] = '*'; c[1] = '\0';
1030
if ((font = set_font(yaxis_font)) == ERR) return ERR;
1031
length = strlen(text);
1033
delta = yaxis_direct == HORIZ_FONT ?
1034
yaxis_height : yaxis_width;
1035
y = (Title_y + Xaxis_y + delta * length) / 2;
1037
strncpy(buffer, text, sizeof(buffer)-1);
1040
count = 2 * (Title_y - y)/delta;
1041
buffer[length-count-1] = '\0';
1045
if (yaxis_direct == HORIZ_FONT)
1047
while (*ptr != '\0')
1050
drawText (Yaxis_x, y, c);
1055
drawText (Yaxis_x, y, ptr, 90.);
1063
TeGraphPlot :: plot_curve(Real_Vector x, Real_Vector y,int points,TeColor c)
1067
setLineAttributes(c,TeLnTypeContinuous,0);
1069
count = plot_point(x[0], y[0], PEN_UP);
1070
for (i = 1; i < points; i++)
1071
count += plot_point(x[i], y[i], PEN_DOWN);
1076
TeGraphPlot :: plot_point(Real x_value, Real y_value, int pen_status)
1078
static Real last_x_value, last_y_value;
1079
static int last_x, last_y;
1080
Real temp_x, temp_y;
1083
if (point_visible(x_value, y_value))
1085
value_to_pixel(x_value, y_value, &x, &y);
1086
if (pen_status == PEN_UP)
1088
// SET_PIXEL(x, y, color);
1092
if (!point_visible(last_x_value, last_y_value))
1094
temp_x = last_x_value;
1095
temp_y = last_y_value;
1096
find_intersect(x_value, y_value, &temp_x, &temp_y);
1097
value_to_pixel(temp_x, temp_y, &last_x, &last_y);
1099
if (last_y_value < TeMAXFLOAT)
1100
drawLine(last_x, last_y, x, y);
1106
else if (pen_status == PEN_DOWN && point_visible(last_x_value, last_y_value))
1108
if (y_value < TeMAXFLOAT)
1112
find_intersect(last_x_value, last_y_value, &temp_x, &temp_y);
1113
value_to_pixel(temp_x, temp_y, &x, &y);
1114
drawLine(last_x, last_y, x, y);
1118
last_x_value = x_value;
1119
last_y_value = y_value;
1124
TeGraphPlot :: plotSymbol(Real x_value, Real y_value, int symbol, int w, int h, int curve)
1128
setLineAttributes(Graph_color.symbol[curve],TeLnTypeContinuous,1);
1130
if (point_visible(x_value, y_value))
1132
value_to_pixel(x_value, y_value, &x, &y);
1133
draw_symbol(x, y, symbol, w, h);
1140
TeGraphPlot :: draw_symbol(int x, int y,int symbol, int w, int h)
1142
if( symbol < 0 ) //V2.0-01 GAIA
1146
symbol = symbol % 5; //V2.0-01 GAIA
1151
drawLine(x - w/2, y - h/2, x + w/2, y - h/2);
1152
drawLine(x + w/2, y - h/2, x + w/2, y + h/2);
1153
drawLine(x + w/2, y + h/2, x - w/2, y + h/2);
1154
drawLine(x - w/2, y + h/2, x - w/2, y - h/2);
1158
drawLine(x - w/2, y + h/2, x, y - h/2);
1159
drawLine(x, y - h/2, x + w/2, y + h/2);
1160
drawLine(x + w/2, y + h/2, x - w/2, y + h/2);
1164
drawLine(x - w/2, y, x, y - h/2);
1165
drawLine(x, y - h/2, x + w/2, y);
1166
drawLine(x + w/2, y, x, y + h/2);
1167
drawLine(x, y + h/2, x - w/2, y);
1171
drawLine(x - w/2, y, x + w/2, y);
1172
drawLine(x, y - h/2, x, y + h/2);
1176
drawLine(x - w/2, y + h/2, x + w/2, y - h/2);
1177
drawLine(x - w/2, y - h/2, x + w/2, y + h/2);
1183
void TeGraphPlot :: draw_symbol_legend(int x, int y, int symbol, int w, int h)
1185
if( symbol < 0 ) //V2.0-01 GAIA
1189
symbol = symbol % 5; //V2.0-01 GAIA
1194
drawLine(x - w/2, y - h/2, x + w/2, y - h/2);
1195
drawLine(x + w/2, y - h/2, x + w/2, y + h/2);
1196
drawLine(x + w/2, y + h/2, x - w/2, y + h/2);
1197
drawLine(x - w/2, y + h/2, x - w/2, y - h/2);
1201
drawLine(x - w/2, y + h/2, x, y - h/2);
1202
drawLine(x, y - h/2, x + w/2, y + h/2);
1203
drawLine(x + w/2, y + h/2, x - w/2, y + h/2);
1207
drawLine(x - w/2, y, x, y - h/2);
1208
drawLine(x, y - h/2, x + w/2, y);
1209
drawLine(x + w/2, y, x, y + h/2);
1210
drawLine(x, y + h/2, x - w/2, y);
1214
drawLine(x - w/2, y, x + w/2, y);
1215
drawLine(x, y - h/2, x, y + h/2);
1219
drawLine(x - w/2, y + h/2, x + w/2, y - h/2);
1220
drawLine(x - w/2, y - h/2, x + w/2, y + h/2);
1227
TeGraphPlot :: label_format(Real values[], int nvalues, int field_width,
1228
int *digits_left, int *digits_right, int *exp_flag)
1231
int i, j, digits, decimal, sign, trail0;
1233
digits = sizeof(Real) == sizeof(float) ? FLT_DIG : DBL_DIG;
1234
*digits_left = *digits_right = *exp_flag = 0;
1235
for (i = 0; i < nvalues && *exp_flag == 0; i++) {
1236
str = ecvt(values[i], digits, &decimal, &sign);
1237
if (decimal > *digits_left) *digits_left = decimal;
1238
for (j = digits-1, trail0 = 0; j >= 0 && str[j] == '0'; j--) trail0++;
1239
j = digits - trail0 - decimal;
1240
if (j > *digits_right) *digits_right = j;
1241
if (*digits_right + *digits_left > field_width-2) {
1244
*digits_right = field_width - 8;
1245
if (*digits_right < 0) *digits_right = 0;
1251
void TeGraphPlot :: find_intersect(Real x_in, Real y_in,
1252
Real *x_out, Real *y_out)
1254
// find values for x_out and y_out that intersect the
1255
// plot boundary on a line between the points (x_in, y_in) inside
1256
// the plot region and (x_out, y_out) outside the plot region
1258
Real m, b, temp_x, temp_y;
1259
m = (y_in - *y_out) / (x_in - *x_out);
1260
b = y_in - m * x_in;
1261
if (*x_out >= xminval && *x_out <= xmaxval) {
1262
// only y_out is outside plot region
1263
if (*y_out < yminval) *y_out = yminval;
1264
else if (*y_out > ymaxval) *y_out = ymaxval;
1265
*x_out = (*y_out - b) / m;
1269
if (*y_out >= yminval && *y_out <= ymaxval) {
1270
// only x_out is outside plot region
1271
if (*x_out < xminval) *x_out = xminval;
1272
else if (*x_out > xmaxval) *x_out = xmaxval;
1273
*y_out = *x_out * m + b;
1277
// both x_out and y_out are outside plot region
1278
if (*y_out < yminval) temp_y = yminval;
1279
else temp_y = ymaxval;
1280
temp_x = (temp_y - b) / m;
1281
if (temp_x >= xminval && temp_x <= xmaxval) {
1286
if (*x_out < xminval) *x_out = xminval;
1287
else *x_out = xmaxval;
1288
*y_out = *x_out * m + b;
1294
//----------------------------------------------------------------------------------------
1296
TeGraphPlot :: drawLegend(void)
1301
for (i = 0; i < Plot_curves; i++)
1303
if (Plot_label.curve[i][0] != '\0') count++;
1308
h = Font_height[0] + 4;
1309
if (count > 3) h += Font_height[0] + 3;
1310
y = getHeight() - h;
1312
setLineAttributes(Graph_color.lines,TeLnTypeContinuous,0);
1313
drawRectangle(0, y, width - 1, h);
1315
x = Font_width[0] + 1;
1316
delta = Font_height[0] + 3;
1317
for (count = 0, i = 0; i < Plot_curves; i++)
1319
if (Plot_label.curve[i][0] != '\0' && count < 7)
1322
x = Font_width[0] + 1;
1323
y += Font_height[0] + 6;
1326
setLineAttributes(Graph_color.curve[i],TeLnTypeContinuous,0);
1327
draw_symbol_legend(x, y + delta - Font_height[0]/2, Symbol[i], 7, 7);
1330
setTextColor(Graph_color.text);
1331
drawText (x, y + delta - Font_height[0], Plot_label.curve[i]);
1332
x += 10 * Font_width[0];
1338
//----------------------------------------------------------------------------------------
1340
TeGraphPlot :: value_to_pixel(Real x_value, Real y_value, int *x_pixel, int *y_pixel)
1342
*x_pixel = (int) ((x_value - xminval) /
1343
(xmaxval - xminval) * (width - 1) + xupleft);
1344
*y_pixel = (int) ((ymaxval - y_value) /
1345
(ymaxval - yminval) * (height - 1) + yupleft);
1348
//----------------------------------------------------------------------------------------
1350
TeGraphPlot :: pixelToValue(int x_pixel, int y_pixel, Real& x_value, Real& y_value)
1352
x_value = (Real) (x_pixel - xupleft) / (width-1) *
1353
(xmaxval - xminval) + xminval;
1354
y_value = (Real) (yupleft - y_pixel) / (height-1) *
1355
(ymaxval - yminval) + ymaxval;
1358
//----------------------------------------------------------------------------------------
1360
TeGraphPlot :: point_visible(Real x, Real y)
1362
if (x >= xminval && x <= xmaxval &&
1363
y >= yminval && y <= ymaxval) return 1;
1367
//FAMI0395 int set_font(int font_number)
1373
// set font to specified font number
1374
if (_set_font(font_number) == 0) {
1375
previous_font = font;
1377
return previous_font;
1380
video_err = FONT_ERR;
1384
return (int)true; //FAMI0394
1387
void ftos(Real f, int digits_left, int digits_right, int exp_flag, char *s)
1389
int i = 0, decimal, sign;
1391
str = ecvt(f, digits_left+digits_right, &decimal, &sign);
1392
if (sign) *s++ = '-';
1394
{ /* exponential format */
1395
for (i=0; i < digits_left; i++) *s++ = *str++;
1397
for (i=0; i < digits_right; i++) *s++ = *str++;
1399
decimal -= digits_left;
1408
for (i = 0; i < 3; i++)
1410
*s-- = (char) (decimal % 10 + (int) '0');
1415
{ /* fixed point format */
1418
if (digits_left > 0) *s++ = '0';
1419
if (digits_right > 0) *s++ = '.';
1420
for (i = decimal; i != 0 && digits_right > 0 ; i++)
1425
for (i = 0; i < digits_right; i++) *s++ = *str++;
1429
for (i = 0; i < decimal; i++) *s++ = *str++;
1430
if (digits_right > 0)
1433
for (i = 0; i < digits_right; i++) *s++ = *str++;
1441
//----------------------------------------------------------------------------------------
1444
TeGraphPlot :: plotInit(int pixels_above, int pixels_below, int pixels_left, int pixels_right)
1446
// initialize Plot variables, reserving the number of pixels specified by
1447
// pixels_above, pixels_below, pixels_left, and pixels_right for use by
1450
int delta, x_ticks, y_ticks;
1452
// initialize variables appropriately for current plotting device
1453
X_pixels = getWidth ();
1454
Y_pixels = getHeight ();
1457
get_font_size(title_font, &title_width, &title_height);
1458
get_font_size(label_font, &label_width, &label_height);
1459
get_font_size(xaxis_font, &xaxis_width, &xaxis_height);
1460
yaxis_direct = get_font_size(yaxis_font, &yaxis_width, &yaxis_height);
1461
delta = yaxis_direct == HORIZ_FONT ? yaxis_width : yaxis_height;
1462
xupleft = pixels_left + delta + (label_field + 1) * label_width;
1463
delta = title_height + label_height/2;
1464
yupleft = pixels_above + delta + title_height;
1465
Title_y = yupleft - delta;
1467
// make width of Plot region a multiple of x_ticks
1468
x_ticks = x_major * x_minor;
1469
width = (X_pixels - pixels_right - xupleft -
1470
label_field * label_width / 2 + 1)
1471
/x_ticks*x_ticks + 1;
1473
// make height of Plot region a multiple of y_ticks
1474
y_ticks = y_major * y_minor;
1475
delta = 2 * label_height + 1;
1476
height = (Y_pixels - pixels_below - yupleft - delta -
1477
xaxis_height)/y_ticks*y_ticks + 1;
1479
// define y coordinate for x axis title
1480
Xaxis_y = yupleft + height - 1 + delta;
1483
//----------------------------------------------------------------------------------------
1485
TeGraphPlot :: get_plot_fonts()
1493
//----------------------------------------------------------------------------------------
1495
TeGraphPlot :: get_font_size(int font_number, int *w, int *h)
1497
// return width, height, and direction of specified font number
1498
if (font_number < FONT_MAX)
1500
*w = Font_width[font_number];
1501
*h = Font_height[font_number];
1502
return Font_direct[font_number];
1510
//----------------------------------------------------------------------------------------
1512
TeGraphPlot :: reset()
1514
for (int i=0; i<Plot_curves; i++)
1526
void TeGraphPlot::drawMoranText (double dx1, double dy1, double dx2, double dy2)
1529
int x1, y1, x2, y2, mx, my;
1531
setTextColor(Graph_color.text);
1533
value_to_pixel(dx1, dy1, &x1, &y1);
1534
value_to_pixel(dx2, dy2, &x2, &y2);
1535
value_to_pixel(0., 0., &mx, &my);
1538
textExtent(tx, w, h);
1539
x = (int)(mx + (double)(x2-mx)/2. - (double)w/2.);
1540
y = (int)(my - (double)(my-y2)/2. + (double)h/2.);
1541
drawText(x, y, (char*)tx.c_str());
1544
textExtent(tx, w, h);
1545
x = (int)(mx - (double)(mx-x1)/2. - (double)w/2.);
1546
drawText(x, y, (char*)tx.c_str());
1549
textExtent(tx, w, h);
1550
y = (int)(my + (double)(y1-my)/2. + (double)h/2.);
1551
drawText(x, y, (char*)tx.c_str());
1554
textExtent(tx, w, h);
1555
x = (int)(mx + (double)(x2-mx)/2. - (double)w/2.);
1556
drawText(x, y, (char*)tx.c_str());