-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplotX.c
266 lines (196 loc) · 7.22 KB
/
plotX.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*
-------------------------------------------------------------------------
OBJECT NAME: plotX.c
FULL NAME: Plot Graph in X window
ENTRY POINTS: DrawTimeSeries()
ResizeTimeSeries()
STATIC FNS: plotData()
DESCRIPTION: This is the Expose event procedure to regenerate the
main image.
COPYRIGHT: University Corporation for Atmospheric Research, 1992-2022
-------------------------------------------------------------------------
*/
#include "define.h"
#include <X11/Xutil.h>
#include <Xm/DrawingA.h>
static size_t currentPanel;
static int fontOffset;
void MakeLegendLabel(char *, DATASET_INFO *);
static void plotData(PLOT_INFO *plot, XFontStruct *fontInfo);
/* -------------------------------------------------------------------- */
void ResizeTimeSeries()
{
size_t i;
int n, totalVD, depth;
Arg args[5];
n = 0;
XtSetArg(args[n], XmNwidth, &mainPlot[0].x.windowWidth); ++n;
XtSetArg(args[n], XmNheight, &mainPlot[0].x.windowHeight); ++n;
XtSetArg(args[n], XtNdepth, &depth); ++n;
XtGetValues(mainPlot[0].canvas, args, n);
NewPixmap(&mainPlot[0], mainPlot[0].x.windowWidth, mainPlot[0].x.windowHeight, depth);
mainPlot[0].x.titleOffset = 45;
mainPlot[0].x.subTitleOffset = 65;
totalVD = mainPlot[0].x.windowHeight - 100;
for (i = 0; i < NumberOfPanels; ++i)
{
if (i > 0)
{
mainPlot[i].x.windowWidth = mainPlot[0].x.windowWidth;
mainPlot[i].x.windowHeight = mainPlot[0].x.windowHeight;
}
mainPlot[i].x.LV = (int)(mainPlot[0].x.windowWidth * 0.1364);
mainPlot[i].x.HD = (int)(mainPlot[0].x.windowWidth * 0.7273);
if (NumberOfPanels == 1)
{
mainPlot[i].x.TH = (int)(mainPlot[0].x.windowHeight * 0.2089);
mainPlot[i].x.VD = (int)(mainPlot[0].x.windowHeight * 0.5822); /* 5" */
}
else
{
mainPlot[i].x.TH = (int)(100 + totalVD / NumberOfPanels * i);
mainPlot[i].x.VD = (int)(totalVD / NumberOfPanels - 40);
}
mainPlot[i].x.RV = mainPlot[i].x.LV + mainPlot[i].x.HD;
mainPlot[i].x.BH = mainPlot[i].x.TH + mainPlot[i].x.VD;
if (NumberOfPanels == 1)
mainPlot[i].x.xLabelOffset = mainPlot[i].x.BH + 40;
else
mainPlot[i].x.xLabelOffset = mainPlot[i].x.BH + 20;
mainPlot[i].x.ticLength = mainPlot[i].x.HD > 400 ? 10 : 5;
mainPlot[i].x.yLabelOffset = 7;
mainPlot[i].x.yTicLabelOffset = 5;
mainPlot[i].x.xTicLabelOffset = 20;
mainPlot[i].x.xLegendText = mainPlot[i].x.LV;
}
fontOffset = (totalVD < 500) ? 1 : 0;
} /* END RESIZEPLOTWINDOW */
/* -------------------------------------------------------------------- */
void DrawTimeSeries()
{
size_t i;
static bool firstTime = true;
XFontStruct *fontInfo;
/* Set default Graphics Context stuff and get the GC
*/
if (firstTime)
{
initPlotGC(&mainPlot[0]);
for (i = 1; i < MAX_PANELS; ++i)
{
copyGC(&mainPlot[i], &mainPlot[0]);
copyGC(&xyyPlot[i], &mainPlot[0]);
}
copyGC(&xyyPlot[0], &mainPlot[0]);
copyGC(&xyzPlot, &mainPlot[0]);
ResizeTimeSeries();
InitializeColors(&mainPlot[0]);
firstTime = false;
}
/* Set clipping to whole window */
XSetClipMask(mainPlot[0].dpy, mainPlot[0].gc, None);
ClearPixmap(&mainPlot[0]);
bool warning = false;
for (i = 0; i < NumberDataSets; ++i)
if (dataFile[dataSet[i].fileIndex].ShowPrelimDataWarning)
warning = true;
plotTitlesX(&mainPlot[0], fontOffset, warning);
fontInfo = mainPlot[0].fontInfo[3+fontOffset];
XSetFont(mainPlot[0].dpy, mainPlot[0].gc, fontInfo->fid);
for (currentPanel = 0; currentPanel < NumberOfPanels; ++currentPanel)
{
XDrawRectangle(mainPlot[currentPanel].dpy, mainPlot[currentPanel].win,
mainPlot[currentPanel].gc,
mainPlot[currentPanel].x.LV, mainPlot[currentPanel].x.TH,
mainPlot[currentPanel].x.HD, mainPlot[currentPanel].x.VD);
if (allLabels || currentPanel == NumberOfPanels-1)
xTicsLabelsX(&mainPlot[currentPanel], fontInfo, true);
else
xTicsLabelsX(&mainPlot[currentPanel], fontInfo, false);
if (NumberDataSets > 0)
{
plotLabelsX(&mainPlot[currentPanel], fontOffset);
yTicsLabelsX(&mainPlot[currentPanel], fontInfo, LEFT_SIDE, true);
for (i = 0; i < NumberDataSets; ++i)
if (dataSet[i].scaleLocation == RIGHT_SIDE &&
dataSet[i].panelIndex == currentPanel)
yTicsLabelsX(&mainPlot[currentPanel], fontInfo, RIGHT_SIDE, true);
plotData(&mainPlot[currentPanel], fontInfo);
}
}
UpdateAnnotationsX(&mainPlot[0]);
} /* END DRAWTIMESERIES */
/* -------------------------------------------------------------------- */
static void plotData(PLOT_INFO *plot, XFontStruct *fontInfo)
{
DATASET_INFO *set;
VARTBL *vp;
int cnt, cntRt, cntLft, ylegend;
char dashList[4];
ResetColors();
cnt = cntRt = cntLft = 0;
for (CurrentDataSet = 0; CurrentDataSet < NumberDataSets; ++CurrentDataSet)
{
if (dataSet[CurrentDataSet].panelIndex != currentPanel)
continue;
set = &dataSet[CurrentDataSet];
if (Color)
XSetForeground(plot->dpy, plot->gc, NextColor());
if (Color || cnt == 0)
XSetLineAttributes(plot->dpy, plot->gc, LineThickness, LineSolid, CapButt, JoinMiter);
else
XSetLineAttributes(plot->dpy, plot->gc, LineThickness, LineOnOffDash, CapButt, JoinMiter);
plotTimeSeries(plot, set, fontInfo);
/* Display legend for each dataset
*/
vp = set->varInfo;
if (Color)
XSetLineAttributes(plot->dpy,plot->gc, 3,LineSolid,CapButt,JoinMiter);
if (Statistics)
{
int len;
ylegend = yLegendX(&mainPlot[0], cnt);
MakeLegendLabel(buffer, set);
len = XTextWidth(plot->fontInfo[3+fontOffset], buffer, strlen(buffer));
if (set->scaleLocation == LEFT_SIDE)
XDrawLine(plot->dpy, plot->win, plot->gc, plot->x.xLegendText-45,
ylegend-2, plot->x.xLegendText-5, ylegend-2);
else
XDrawLine(plot->dpy, plot->win, plot->gc, plot->x.xLegendText+len+5,
ylegend-2, plot->x.xLegendText+len+45, ylegend-2);
if (Color)
XSetForeground(plot->dpy, plot->gc, GetColor(0));
XDrawString(plot->dpy, plot->win, plot->gc, plot->x.xLegendText,
ylegend+3, buffer, strlen(buffer));
}
else
{
int pos;
ylegend = plot->x.TH - 5;
if (set->scaleLocation == LEFT_SIDE)
pos = plot->x.LV + (cntLft++ * 100);
else
pos = plot->x.RV - (++cntRt * 100);
XDrawLine(plot->dpy, plot->win, plot->gc, pos, ylegend-2, pos + 35, ylegend-2);
if (Color)
XSetForeground(plot->dpy, plot->gc, GetColor(0));
XDrawString(plot->dpy, plot->win, plot->gc, pos + 40,
ylegend+3, vp->name.c_str(), vp->name.size());
}
if (!Color)
{
/* Change Dash style for the next dataset */
dashList[0] = (cnt + 1) * 6;
dashList[1] = (cnt + 1) * 3;
XSetDashes(plot->dpy, plot->gc, 0, dashList, 2);
}
++cnt;
}
if (Color)
XSetForeground(plot->dpy, plot->gc, GetColor(0));
XSetLineAttributes(plot->dpy, plot->gc, 1, LineSolid, CapButt, JoinMiter);
if (Statistics)
XDrawString(plot->dpy, plot->win, plot->gc, plot->x.xLegendText,
yLegendX(plot, (cnt+1)) + 12, statsTitle, strlen(statsTitle));
} /* END PLOTDATA */
/* END PLOTX.C */