Debian Codegraph @

generic/bltGrLine.c

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1
2 /*
3 * bltGrLine.c --
4 *
5 * This module implements line graph and stripchart elements for
6 * the BLT graph widget.
7 *
8 * Copyright 1993-1998 Lucent Technologies, Inc.
9 *
10 * Permission to use, copy, modify, and distribute this software and
11 * its documentation for any purpose and without fee is hereby
12 * granted, provided that the above copyright notice appear in all
13 * copies and that both that the copyright notice and warranty
14 * disclaimer appear in supporting documentation, and that the names
15 * of Lucent Technologies any of their entities not be used in
16 * advertising or publicity pertaining to distribution of the software
17 * without specific, written prior permission.
18 *
19 * Lucent Technologies disclaims all warranties with regard to this
20 * software, including all implied warranties of merchantability and
21 * fitness. In no event shall Lucent Technologies be liable for any
22 * special, indirect or consequential damages or any damages
23 * whatsoever resulting from loss of use, data or profits, whether in
24 * an action of contract, negligence or other tortuous action, arising
25 * out of or in connection with the use or performance of this
26 * software.
27 */
28 #include "bltGraph.h"
29 #include "bltChain.h"
30 #include <X11/Xutil.h>
31
32 #include "bltGrElem.h"
33
34 #define COLOR_DEFAULT (XColor *)1
35 #define PATTERN_SOLID ((Pixmap)1)
36
37 #define PEN_INCREASING 1 /* Draw line segments for only those
38 * data points whose abscissas are
39 * monotonically increasing in
40 * order */
41 #define PEN_DECREASING 2 /* Lines will be drawn between only
42 * those points whose abscissas are
43 * decreasing in order */
44
45 #define PEN_BOTH_DIRECTIONS (PEN_INCREASING | PEN_DECREASING)
46 /* Lines will be drawn between points regardless of the ordering of
47 * the abscissas */
48
49 #define BROKEN_TRACE(dir,last,next) \
50 (((((dir) & PEN_DECREASING) == 0) && ((next) < (last))) || \
51 ((((dir) & PEN_INCREASING) == 0) && ((next) > (last))))
52
53 #define DRAW_SYMBOL(linePtr) \
54 (((linePtr)->symbolCounter % (linePtr)->symbolInterval) == 0)
55
56 typedef enum {
57 PEN_SMOOTH_NONE, /* Line segments */
58 PEN_SMOOTH_STEP, /* Step-and-hold */
59 PEN_SMOOTH_NATURAL, /* Natural cubic spline */
60 PEN_SMOOTH_QUADRATIC, /* Quadratic spline */
61 PEN_SMOOTH_CATROM, /* Catrom parametric spline */
62 PEN_SMOOTH_LAST /* Sentinel */
63 } Smoothing;
64
65 typedef struct {
66 char *name;
67 Smoothing value;
68 } SmoothingInfo;
69
70 static SmoothingInfo smoothingInfo[] = {
71 { "linear", PEN_SMOOTH_NONE },
72 { "step", PEN_SMOOTH_STEP },
73 { "natural", PEN_SMOOTH_NATURAL },
74 { "cubic", PEN_SMOOTH_NATURAL },
75 { "quadratic", PEN_SMOOTH_QUADRATIC },
76 { "catrom", PEN_SMOOTH_CATROM },
77 { (char *)NULL, PEN_SMOOTH_LAST }
78 };
79
80
81 typedef struct {
82 Point2D *screenPts; /* Array of transformed coordinates */
83 int nScreenPts; /* Number of coordinates */
84 int *dataToStyle; /* Index of pen styles */
85 int *indices; /* Maps segments/traces to data points */
86
87 } MapInfo;
88
89 /*
90 * Symbol types for line elements
91 */
92 typedef enum {
93 SYMBOL_NONE,
94 SYMBOL_SQUARE,
95 SYMBOL_CIRCLE,
96 SYMBOL_DIAMOND,
97 SYMBOL_PLUS,
98 SYMBOL_CROSS,
99 SYMBOL_SPLUS,
100 SYMBOL_SCROSS,
101 SYMBOL_TRIANGLE,
102 SYMBOL_ARROW,
103 SYMBOL_BITMAP
104 } SymbolType;
105
106 typedef struct {
107 SymbolType type; /* Type of symbol to be drawn/printed */
108
109 int size; /* Requested size of symbol in pixels */
110
111 XColor *outlineColor; /* Outline color */
112
113 int outlineWidth; /* Width of the outline */
114
115 GC outlineGC; /* Outline graphics context */
116
117 XColor *fillColor; /* Normal fill color */
118
119 GC fillGC; /* Fill graphics context */
120
121 /* The last two fields are used only for bitmap symbols. */
122
123 Pixmap bitmap; /* Bitmap to determine foreground/background
124 * pixels of the symbol */
125
126 Pixmap mask; /* Bitmap representing the transparent
127 * pixels of the symbol */
128
129 } Symbol;
130
131 typedef struct {
132 int start; /* Index into the X-Y coordinate
133 * arrays indicating where trace
134 * starts. */
135
136 int nScreenPts; /* Number of points in the continuous
137 * trace */
138
139 Point2D *screenPts; /* Array of screen coordinates
140 * (malloc-ed) representing the
141 * trace. */
142
143 int *symbolToData; /* Reverse mapping of screen
144 * coordinate indices back to their
145 * data coordinates */
146 } Trace;
147
148 typedef struct {
149 char *name; /* Name of pen style. If the pen was
150 * statically allocated the name will
151 * be NULL. */
152
153 Blt_Uid classUid; /* Type of pen */
154
155 char *typeId; /* String token identifying the type
156 * of pen */
157
158 unsigned int flags; /* Indicates if the pen element is
159 * active or normal */
160
161 int refCount; /* Reference count for elements using
162 * this pen. */
163 Blt_HashEntry *hashPtr;
164
165 Tk_ConfigSpec *configSpecs; /* Configuration specifications */
166
167 PenConfigureProc *configProc;
168 PenDestroyProc *destroyProc;
169
170 /* Symbol attributes. */
171 Symbol symbol; /* Element symbol type */
172
173 /* Trace attributes. */
174 int traceWidth; /* Width of the line segments. If
175 * lineWidth is 0, no line will be
176 * drawn, only symbols. */
177
178 Blt_Dashes traceDashes; /* Dash on-off list value */
179
180 XColor *traceColor; /* Line segment color */
181
182 XColor *traceOffColor; /* Line segment dash gap color */
183
184 GC traceGC; /* Line segment graphics context */
185
186 /* Error bar attributes. */
187 int errorBarShow; /* Describes which error bars to
188 * display: none, x, y, or * both. */
189
190 int errorBarLineWidth; /* Width of the error bar segments. */
191
192 int errorBarCapWidth; /* Width of the cap on error bars. */
193
194 XColor *errorBarColor; /* Color of the error bar. */
195
196 GC errorBarGC; /* Error bar graphics context. */
197
198 /* Show value attributes. */
199 int valueShow; /* Indicates whether to display data
200 * value. Values are x, y, both, or
201 * none. */
202 char *valueFormat; /* A printf format string. */
203
204 TextStyle valueStyle; /* Text attributes (color, font,
205 * rotation, etc.) of the value. */
206
207 } LinePen;
208
209 typedef struct {
210 Weight weight; /* Weight range where this pen is valid. */
211
212 LinePen *penPtr; /* Pen used to draw symbols, traces, error
213 * bars, segments, etc. */
214
215 Segment2D *xErrorBars; /* Point to start of this pen's X-error bar
216 * segments in the element's array. */
217 Segment2D *yErrorBars; /* Point to start of this pen's Y-error bar
218 * segments in the element's array. */
219 int xErrorBarCnt; /* # of error bars for this pen. */
220 int yErrorBarCnt; /* # of error bars for this pen. */
221
222 int errorBarCapWidth; /* Length of the cap ends on each
223 * error bar. */
224
225 int symbolSize; /* Size of the pen's symbol scaled to the
226 * current graph size. */
227
228 /* Graph specific data. */
229
230 Point2D *symbolPts; /* Points to start of array for this pen. */
231
232 int nSymbolPts; /* # of points for this pen. */
233
234 /* The last two fields are used only for stripcharts. */
235
236 Segment2D *strips; /* Points to start of the line segments
237 * for this pen. */
238
239 int nStrips; /* # of line segments for this pen. */
240
241 } LinePenStyle;
242
243 typedef struct {
244 char *name; /* Identifier used to refer the
245 * element. Used in the "insert",
246 * "delete", or "show", operations. */
247
248 Blt_Uid classUid; /* Type of element */
249
250 Graph *graphPtr; /* Graph widget of element*/
251
252 unsigned int flags; /* Indicates if the entire element is
253 * active, or if coordinates need to
254 * be calculated */
255
256 char **tags;
257
258 int hidden; /* If non-zero, don't display the
259 * element. */
260
261 Blt_HashEntry *hashPtr;
262
263 char *label; /* Label displayed in legend */
264
265 int labelRelief; /* Relief of label in legend. */
266
267 Axis2D axes;
268
269 ElemVector x, y, w; /* Contains array of numeric values */
270
271 ElemVector xError; /* Relative/symmetric X error values. */
272 ElemVector yError; /* Relative/symmetric Y error values. */
273 ElemVector xHigh, xLow; /* Absolute/asymmetric X-coordinate high/low
274 error values. */
275 ElemVector yHigh, yLow; /* Absolute/asymmetric Y-coordinate high/low
276 error values. */
277
278 int *activeIndices; /* Array of indices (malloc-ed) that
279 * indicate the data points are active
280 * (drawn with "active" colors). */
281
282 int nActiveIndices; /* Number of active data points.
283 * Special case: if < 0 then all data
284 * points are drawn active. */
285
286 ElementProcs *procsPtr;
287 Tk_ConfigSpec *configSpecs; /* Configuration specifications */
288
289 Segment2D *xErrorBars; /* Point to start of this pen's X-error bar
290 * segments in the element's array. */
291 Segment2D *yErrorBars; /* Point to start of this pen's Y-error bar
292 * segments in the element's array. */
293 int xErrorBarCnt; /* # of error bars for this pen. */
294 int yErrorBarCnt; /* # of error bars for this pen. */
295
296 int *xErrorToData; /* Maps individual error bar segments back
297 * to the data point associated with it. */
298 int *yErrorToData; /* Maps individual error bar segments back
299 * to the data point associated with it. */
300
301 int errorBarCapWidth; /* Length of cap on error bars */
302
303 LinePen *activePenPtr; /* Pen to draw "active" elements. */
304 LinePen *normalPenPtr; /* Pen to draw elements normally. */
305
306 Blt_Chain *palette; /* Array of pen styles: pens are associated
307 * with specific ranges of data.*/
308
309 /* Symbol scaling */
310 int scaleSymbols; /* If non-zero, the symbols will scale
311 * in size as the graph is zoomed
312 * in/out. */
313
314 double xRange, yRange; /* Initial X-axis and Y-axis ranges:
315 * used to scale the size of element's
316 * symbol. */
317
318 int state;
319 /*
320 * Line specific configurable attributes
321 */
322 LinePen builtinPen;
323
324 /* Line smoothing */
325 Smoothing reqSmooth; /* Requested smoothing function to use
326 * for connecting the data points */
327
328 Smoothing smooth; /* Smoothing function used. */
329
330 double rTolerance; /* Tolerance to reduce the number of
331 * points displayed. */
332 /*
333 * Drawing related data structures.
334 */
335
336 /* Area-under-curve fill attributes. */
337 XColor *fillFgColor;
338 XColor *fillBgColor;
339 GC fillGC;
340
341 Blt_Tile fillTile; /* Tile for fill area. */
342 Pixmap fillStipple; /* Stipple for fill area. */
343
344 int nFillPts;
345 Point2D *fillPts; /* Array of points used to draw
346 * polygon to fill area under the
347 * curve */
348
349 /* Symbol points */
350 Point2D *symbolPts; /* Holds the screen coordinates of all
351 * the data points for the element. */
352 int nSymbolPts; /* Number of points */
353
354 int *symbolToData; /* Contains indices of data points.
355 * It's first used to map pens to the
356 * visible points to sort them by pen
357 * style, and later to find data
358 * points from the index of a visible
359 * point. */
360
361 /* Active symbol points */
362 Point2D *activePts; /* Array of indices representing the
363 * "active" points. */
364 int nActivePts; /* Number of indices in the above array. */
365
366 int *activeToData; /* Contains indices of data points.
367 * It's first used to map pens to the
368 * visible points to sort them by pen
369 * style, and later to find data
370 * points from the index of a visible
371 * point. */
372
373 int reqMaxSymbols;
374 int symbolInterval;
375 int symbolCounter;
376
377 /* X-Y graph-specific fields */
378
379 int penDir; /* Indicates if a change in the pen
380 * direction should be considered a
381 * retrace (line segment is not
382 * drawn). */
383
384 Blt_Chain *traces; /* List of traces (a trace is a series
385 * of contiguous line segments). New
386 * traces are generated when either
387 * the next segment changes the pen
388 * direction, or the end point is
389 * clipped by the plotting area. */
390
391 /* Stripchart-specific fields */
392
393 Segment2D *strips; /* Holds the the line segments of the
394 * element trace. The segments are
395 * grouped by pen style. */
396 int nStrips; /* Number of line segments to be drawn. */
397 int *stripToData; /* Pen to visible line segment mapping. */
398
399 } Line;
400
401 static Tk_OptionParseProc StringToPattern;
402 static Tk_OptionPrintProc PatternToString;
403 static Tk_OptionParseProc StringToSmooth;
404 static Tk_OptionPrintProc SmoothToString;
405 extern Tk_OptionParseProc Blt_StringToStyles;
406 extern Tk_OptionPrintProc Blt_StylesToString;
407 static Tk_OptionParseProc StringToPenDir;
408 static Tk_OptionPrintProc PenDirToString;
409 static Tk_OptionParseProc StringToSymbol;
410 static Tk_OptionPrintProc SymbolToString;
411
412 static Tk_CustomOption patternOption =
413 {
414 StringToPattern, PatternToString, (ClientData)0
415 };
416 static Tk_CustomOption smoothOption =
417 {
418 StringToSmooth, SmoothToString, (ClientData)0
419 };
420 static Tk_CustomOption stylesOption =
421 {
422 Blt_StringToStyles, Blt_StylesToString, (ClientData)sizeof(LinePenStyle)
423 };
424 static Tk_CustomOption penDirOption =
425 {
426 StringToPenDir, PenDirToString, (ClientData)0
427 };
428 static Tk_CustomOption symbolOption =
429 {
430 StringToSymbol, SymbolToString, (ClientData)0
431 };
432 extern Tk_CustomOption bltColorOption;
433 extern Tk_CustomOption bltDashesOption;
434 extern Tk_CustomOption bltDataOption;
435 extern Tk_CustomOption bltDataPairsOption;
436 extern Tk_CustomOption bltDistanceOption;
437 extern Tk_CustomOption bltListOption;
438 extern Tk_CustomOption bltLinePenOption;
439 extern Tk_CustomOption bltShadowOption;
440 extern Tk_CustomOption bltXAxisOption;
441 extern Tk_CustomOption bltYAxisOption;
442 extern Tk_CustomOption bltTileOption;
443 extern Tk_CustomOption bltFillOption;
444 extern Tk_CustomOption bltStateOption;
445
446 #define DEF_LINE_ACTIVE_PEN "activeLine"
447 #define DEF_LINE_AXIS_X "x"
448 #define DEF_LINE_AXIS_Y "y"
449 #define DEF_LINE_DASHES (char *)NULL
450 #define DEF_LINE_DATA (char *)NULL
451 #define DEF_LINE_FILL_COLOR "defcolor"
452 #define DEF_LINE_FILL_MONO "defcolor"
453 #define DEF_LINE_HIDE "no"
454 #define DEF_LINE_LABEL (char *)NULL
455 #define DEF_LINE_LABEL_RELIEF "flat"
456 #define DEF_LINE_MAX_SYMBOLS "0"
457 #define DEF_LINE_OFFDASH_COLOR (char *)NULL
458 #define DEF_LINE_OFFDASH_MONO (char *)NULL
459 #define DEF_LINE_OUTLINE_COLOR "defcolor"
460 #define DEF_LINE_OUTLINE_MONO "defcolor"
461 #define DEF_LINE_OUTLINE_WIDTH "1"
462 #define DEF_LINE_PATTERN (char *)NULL
463 #define DEF_LINE_PATTERN_BG "white"
464 #define DEF_LINE_PATTERN_FG "black"
465 #define DEF_LINE_PATTERN_TILE (char *)NULL
466 #define DEF_LINE_PEN_COLOR RGB_NAVYBLUE
467 #define DEF_LINE_PEN_DIRECTION "both"
468 #define DEF_LINE_PEN_MONO RGB_BLACK
469 #define DEF_LINE_PEN_WIDTH "1"
470 #define DEF_LINE_PIXELS "0.125i"
471 #define DEF_LINE_REDUCE "0.0"
472 #define DEF_LINE_SCALE_SYMBOLS "yes"
473 #define DEF_LINE_SMOOTH "linear"
474 #define DEF_LINE_STATE "normal"
475 #define DEF_LINE_STIPPLE (char *)NULL
476 #define DEF_LINE_STYLES ""
477 #define DEF_LINE_SYMBOL "circle"
478 #define DEF_LINE_TAGS "all"
479 #define DEF_LINE_X_DATA (char *)NULL
480 #define DEF_LINE_Y_DATA (char *)NULL
481
482 #define DEF_LINE_ERRORBAR_COLOR "defcolor"
483 #define DEF_LINE_ERRORBAR_LINE_WIDTH "1"
484 #define DEF_LINE_ERRORBAR_CAP_WIDTH "1"
485 #define DEF_LINE_SHOW_ERRORBARS "both"
486
487 #define DEF_PEN_ACTIVE_COLOR RGB_BLUE
488 #define DEF_PEN_ACTIVE_MONO RGB_BLACK
489 #define DEF_PEN_DASHES (char *)NULL
490 #define DEF_PEN_FILL_COLOR "defcolor"
491 #define DEF_PEN_FILL_MONO "defcolor"
492 #define DEF_PEN_LINE_WIDTH "1"
493 #define DEF_PEN_NORMAL_COLOR RGB_NAVYBLUE
494 #define DEF_PEN_NORMAL_MONO RGB_BLACK
495 #define DEF_PEN_OFFDASH_COLOR (char *)NULL
496 #define DEF_PEN_OFFDASH_MONO (char *)NULL
497 #define DEF_PEN_OUTLINE_COLOR "defcolor"
498 #define DEF_PEN_OUTLINE_MONO "defcolor"
499 #define DEF_PEN_OUTLINE_WIDTH "1"
500 #define DEF_PEN_PIXELS "0.125i"
501 #define DEF_PEN_SYMBOL "circle"
502 #define DEF_PEN_TYPE "line"
503 #define DEF_PEN_VALUE_ANCHOR "s"
504 #define DEF_PEN_VALUE_COLOR RGB_BLACK
505 #define DEF_PEN_VALUE_FONT STD_FONT_SMALL
506 #define DEF_PEN_VALUE_FORMAT "%g"
507 #define DEF_PEN_VALUE_ROTATE (char *)NULL
508 #define DEF_PEN_VALUE_SHADOW (char *)NULL
509 #define DEF_PEN_SHOW_VALUES "no"
510
511 static Tk_ConfigSpec lineElemConfigSpecs[] =
512 {
513 {TK_CONFIG_CUSTOM, "-activepen", "activePen", "ActivePen",
514 DEF_LINE_ACTIVE_PEN, Tk_Offset(Line, activePenPtr),
515 TK_CONFIG_NULL_OK, &bltLinePenOption},
516 {TK_CONFIG_CUSTOM, "-areapattern", "areaPattern", "AreaPattern",
517 DEF_LINE_PATTERN, Tk_Offset(Line, fillStipple),
518 TK_CONFIG_NULL_OK, &patternOption},
519 {TK_CONFIG_COLOR, "-areaforeground", "areaForeground", "areaForeground",
520 DEF_LINE_PATTERN_FG, Tk_Offset(Line, fillFgColor), TK_CONFIG_NULL_OK},
521 {TK_CONFIG_COLOR, "-areabackground", "areaBackground", "areaBackground",
522 DEF_LINE_PATTERN_BG, Tk_Offset(Line, fillBgColor), TK_CONFIG_NULL_OK},
523 {TK_CONFIG_CUSTOM, "-areatile", "areaTile", "AreaTile",
524 DEF_LINE_PATTERN_TILE, Tk_Offset(Line, fillTile),
525 TK_CONFIG_NULL_OK, &bltTileOption},
526 {TK_CONFIG_CUSTOM, "-bindtags", "bindTags", "BindTags",
527 DEF_LINE_TAGS, Tk_Offset(Line, tags),
528 TK_CONFIG_NULL_OK, &bltListOption},
529 {TK_CONFIG_COLOR, "-color", "color", "Color",
530 DEF_LINE_PEN_COLOR, Tk_Offset(Line, builtinPen.traceColor),
531 TK_CONFIG_COLOR_ONLY},
532 {TK_CONFIG_COLOR, "-color", "color", "Color",
533 DEF_LINE_PEN_MONO, Tk_Offset(Line, builtinPen.traceColor),
534 TK_CONFIG_MONO_ONLY},
535 {TK_CONFIG_CUSTOM, "-dashes", "dashes", "Dashes",
536 DEF_LINE_DASHES, Tk_Offset(Line, builtinPen.traceDashes),
537 TK_CONFIG_NULL_OK, &bltDashesOption},
538 {TK_CONFIG_CUSTOM, "-data", "data", "Data",
539 DEF_LINE_DATA, 0, 0, &bltDataPairsOption},
540 {TK_CONFIG_CUSTOM, "-errorbarcolor", "errorBarColor", "ErrorBarColor",
541 DEF_LINE_ERRORBAR_COLOR, Tk_Offset(Line, builtinPen.errorBarColor),
542 0, &bltColorOption},
543 {TK_CONFIG_CUSTOM, "-errorbarwidth", "errorBarWidth", "ErrorBarWidth",
544 DEF_LINE_ERRORBAR_LINE_WIDTH,
545 Tk_Offset(Line, builtinPen.errorBarLineWidth),
546 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
547 {TK_CONFIG_CUSTOM, "-errorbarcap", "errorBarCap", "ErrorBarCap",
548 DEF_LINE_ERRORBAR_CAP_WIDTH,
549 Tk_Offset(Line, builtinPen.errorBarCapWidth),
550 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
551 {TK_CONFIG_CUSTOM, "-fill", "fill", "Fill",
552 DEF_LINE_FILL_COLOR, Tk_Offset(Line, builtinPen.symbol.fillColor),
553 TK_CONFIG_NULL_OK | TK_CONFIG_COLOR_ONLY, &bltColorOption},
554 {TK_CONFIG_CUSTOM, "-fill", "fill", "Fill",
555 DEF_LINE_FILL_MONO, Tk_Offset(Line, builtinPen.symbol.fillColor),
556 TK_CONFIG_NULL_OK | TK_CONFIG_MONO_ONLY, &bltColorOption},
557 {TK_CONFIG_BOOLEAN, "-hide", "hide", "Hide",
558 DEF_LINE_HIDE, Tk_Offset(Line, hidden), TK_CONFIG_DONT_SET_DEFAULT},
559 {TK_CONFIG_STRING, "-label", "label", "Label",
560 (char *)NULL, Tk_Offset(Line, label), TK_CONFIG_NULL_OK},
561 {TK_CONFIG_RELIEF, "-labelrelief", "labelRelief", "LabelRelief",
562 DEF_LINE_LABEL_RELIEF, Tk_Offset(Line, labelRelief),
563 TK_CONFIG_DONT_SET_DEFAULT},
564 {TK_CONFIG_CUSTOM, "-linewidth", "lineWidth", "LineWidth",
565 DEF_LINE_PEN_WIDTH, Tk_Offset(Line, builtinPen.traceWidth),
566 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
567 {TK_CONFIG_CUSTOM, "-mapx", "mapX", "MapX",
568 DEF_LINE_AXIS_X, Tk_Offset(Line, axes.x), 0, &bltXAxisOption},
569 {TK_CONFIG_CUSTOM, "-mapy", "mapY", "MapY",
570 DEF_LINE_AXIS_Y, Tk_Offset(Line, axes.y), 0, &bltYAxisOption},
571 {TK_CONFIG_CUSTOM, "-maxsymbols", "maxSymbols", "MaxSymbols",
572 DEF_LINE_MAX_SYMBOLS, Tk_Offset(Line, reqMaxSymbols),
573 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
574 {TK_CONFIG_CUSTOM, "-offdash", "offDash", "OffDash",
575 DEF_LINE_OFFDASH_COLOR, Tk_Offset(Line, builtinPen.traceOffColor),
576 TK_CONFIG_NULL_OK | TK_CONFIG_COLOR_ONLY, &bltColorOption},
577 {TK_CONFIG_CUSTOM, "-offdash", "offDash", "OffDash",
578 DEF_LINE_OFFDASH_MONO, Tk_Offset(Line, builtinPen.traceOffColor),
579 TK_CONFIG_NULL_OK | TK_CONFIG_MONO_ONLY, &bltColorOption},
580 {TK_CONFIG_CUSTOM, "-outline", "outline", "Outline",
581 DEF_LINE_OUTLINE_COLOR, Tk_Offset(Line, builtinPen.symbol.outlineColor),
582 TK_CONFIG_COLOR_ONLY, &bltColorOption},
583 {TK_CONFIG_CUSTOM, "-outline", "outline", "Outline",
584 DEF_LINE_OUTLINE_MONO, Tk_Offset(Line, builtinPen.symbol.outlineColor),
585 TK_CONFIG_MONO_ONLY, &bltColorOption},
586 {TK_CONFIG_CUSTOM, "-outlinewidth", "outlineWidth", "OutlineWidth",
587 DEF_LINE_OUTLINE_WIDTH, Tk_Offset(Line, builtinPen.symbol.outlineWidth),
588 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
589 {TK_CONFIG_CUSTOM, "-pen", "pen", "Pen",
590 (char *)NULL, Tk_Offset(Line, normalPenPtr),
591 TK_CONFIG_NULL_OK, &bltLinePenOption},
592 {TK_CONFIG_CUSTOM, "-pixels", "pixels", "Pixels",
593 DEF_LINE_PIXELS, Tk_Offset(Line, builtinPen.symbol.size),
594 GRAPH | STRIPCHART, &bltDistanceOption},
595 {TK_CONFIG_DOUBLE, "-reduce", "reduce", "Reduce",
596 DEF_LINE_REDUCE, Tk_Offset(Line, rTolerance),
597 GRAPH | STRIPCHART | TK_CONFIG_DONT_SET_DEFAULT},
598 {TK_CONFIG_BOOLEAN, "-scalesymbols", "scaleSymbols", "ScaleSymbols",
599 DEF_LINE_SCALE_SYMBOLS, Tk_Offset(Line, scaleSymbols),
600 TK_CONFIG_DONT_SET_DEFAULT},
601 {TK_CONFIG_CUSTOM, "-showerrorbars", "showErrorBars", "ShowErrorBars",
602 DEF_LINE_SHOW_ERRORBARS, Tk_Offset(Line, builtinPen.errorBarShow),
603 TK_CONFIG_DONT_SET_DEFAULT, &bltFillOption},
604 {TK_CONFIG_CUSTOM, "-showvalues", "showValues", "ShowValues",
605 DEF_PEN_SHOW_VALUES, Tk_Offset(Line, builtinPen.valueShow),
606 TK_CONFIG_DONT_SET_DEFAULT, &bltFillOption},
607 {TK_CONFIG_CUSTOM, "-smooth", "smooth", "Smooth",
608 DEF_LINE_SMOOTH, Tk_Offset(Line, reqSmooth),
609 TK_CONFIG_DONT_SET_DEFAULT, &smoothOption},
610 {TK_CONFIG_CUSTOM, "-state", "state", "State",
611 DEF_LINE_STATE, Tk_Offset(Line, state),
612 TK_CONFIG_DONT_SET_DEFAULT, &bltStateOption},
613 {TK_CONFIG_CUSTOM, "-styles", "styles", "Styles",
614 DEF_LINE_STYLES, Tk_Offset(Line, palette),
615 TK_CONFIG_NULL_OK, &stylesOption},
616 {TK_CONFIG_CUSTOM, "-symbol", "symbol", "Symbol",
617 DEF_LINE_SYMBOL, Tk_Offset(Line, builtinPen.symbol),
618 TK_CONFIG_DONT_SET_DEFAULT, &symbolOption},
619 {TK_CONFIG_CUSTOM, "-trace", "trace", "Trace",
620 DEF_LINE_PEN_DIRECTION, Tk_Offset(Line, penDir),
621 TK_CONFIG_DONT_SET_DEFAULT, &penDirOption},
622 {TK_CONFIG_ANCHOR, "-valueanchor", "valueAnchor", "ValueAnchor",
623 DEF_PEN_VALUE_ANCHOR,
624 Tk_Offset(Line, builtinPen.valueStyle.anchor), 0},
625 {TK_CONFIG_COLOR, "-valuecolor", "valueColor", "ValueColor",
626 DEF_PEN_VALUE_COLOR, Tk_Offset(Line, builtinPen.valueStyle.color), 0},
627 {TK_CONFIG_FONT, "-valuefont", "valueFont", "ValueFont",
628 DEF_PEN_VALUE_FONT, Tk_Offset(Line, builtinPen.valueStyle.font), 0},
629 {TK_CONFIG_STRING, "-valueformat", "valueFormat", "ValueFormat",
630 DEF_PEN_VALUE_FORMAT, Tk_Offset(Line, builtinPen.valueFormat),
631 TK_CONFIG_NULL_OK},
632 {TK_CONFIG_DOUBLE, "-valuerotate", "valueRotate", "ValueRotate",
633 DEF_PEN_VALUE_ROTATE, Tk_Offset(Line, builtinPen.valueStyle.theta), 0},
634 {TK_CONFIG_CUSTOM, "-valueshadow", "valueShadow", "ValueShadow",
635 DEF_PEN_VALUE_SHADOW, Tk_Offset(Line, builtinPen.valueStyle.shadow),
636 0, &bltShadowOption},
637 {TK_CONFIG_CUSTOM, "-weights", "weights", "Weights",
638 (char *)NULL, Tk_Offset(Line, w), 0, &bltDataOption},
639 {TK_CONFIG_CUSTOM, "-x", "xData", "XData",
640 (char *)NULL, Tk_Offset(Line, x), 0, &bltDataOption},
641 {TK_CONFIG_CUSTOM, "-xdata", "xData", "XData",
642 (char *)NULL, Tk_Offset(Line, x), 0, &bltDataOption},
643 {TK_CONFIG_CUSTOM, "-xerror", "xError", "XError",
644 (char *)NULL, Tk_Offset(Line, xError), 0, &bltDataOption},
645 {TK_CONFIG_CUSTOM, "-xhigh", "xHigh", "XHigh",
646 (char *)NULL, Tk_Offset(Line, xHigh), 0, &bltDataOption},
647 {TK_CONFIG_CUSTOM, "-xlow", "xLow", "XLow",
648 (char *)NULL, Tk_Offset(Line, xLow), 0, &bltDataOption},
649 {TK_CONFIG_CUSTOM, "-y", "yData", "YData",
650 (char *)NULL, Tk_Offset(Line, y), 0, &bltDataOption},
651 {TK_CONFIG_CUSTOM, "-ydata", "yData", "YData",
652 (char *)NULL, Tk_Offset(Line, y), 0, &bltDataOption},
653 {TK_CONFIG_CUSTOM, "-yerror", "yError", "YError",
654 (char *)NULL, Tk_Offset(Line, yError), 0, &bltDataOption},
655 {TK_CONFIG_CUSTOM, "-yhigh", "yHigh", "YHigh",
656 (char *)NULL, Tk_Offset(Line, yHigh), 0, &bltDataOption},
657 {TK_CONFIG_CUSTOM, "-ylow", "yLow", "YLow",
658 (char *)NULL, Tk_Offset(Line, yLow), 0, &bltDataOption},
659 {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0}
660 };
661
662
663 static Tk_ConfigSpec stripElemConfigSpecs[] =
664 {
665 {TK_CONFIG_CUSTOM, "-activepen", "activePen", "ActivePen",
666 DEF_LINE_ACTIVE_PEN, Tk_Offset(Line, activePenPtr),
667 TK_CONFIG_NULL_OK, &bltLinePenOption},
668 {TK_CONFIG_CUSTOM, "-bindtags", "bindTags", "BindTags",
669 DEF_LINE_TAGS, Tk_Offset(Line, tags),
670 TK_CONFIG_NULL_OK, &bltListOption},
671 {TK_CONFIG_COLOR, "-color", "color", "Color",
672 DEF_LINE_PEN_COLOR, Tk_Offset(Line, builtinPen.traceColor),
673 TK_CONFIG_COLOR_ONLY},
674 {TK_CONFIG_COLOR, "-color", "color", "Color",
675 DEF_LINE_PEN_MONO, Tk_Offset(Line, builtinPen.traceColor),
676 TK_CONFIG_MONO_ONLY},
677 {TK_CONFIG_CUSTOM, "-dashes", "dashes", "Dashes",
678 DEF_LINE_DASHES, Tk_Offset(Line, builtinPen.traceDashes),
679 TK_CONFIG_NULL_OK, &bltDashesOption},
680 {TK_CONFIG_CUSTOM, "-data", "data", "Data",
681 DEF_LINE_DATA, 0, 0, &bltDataPairsOption},
682 {TK_CONFIG_CUSTOM, "-errorbarcolor", "errorBarColor", "ErrorBarColor",
683 DEF_LINE_ERRORBAR_COLOR, Tk_Offset(Line, builtinPen.errorBarColor),
684 0, &bltColorOption},
685 {TK_CONFIG_CUSTOM, "-errorbarwidth", "errorBarWidth", "ErrorBarWidth",
686 DEF_LINE_ERRORBAR_LINE_WIDTH,
687 Tk_Offset(Line, builtinPen.errorBarLineWidth),
688 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
689 {TK_CONFIG_CUSTOM, "-errorbarcap", "errorBarCap",
690 "ErrorBarCap", DEF_LINE_ERRORBAR_CAP_WIDTH,
691 Tk_Offset(Line, builtinPen.errorBarCapWidth),
692 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
693 {TK_CONFIG_CUSTOM, "-fill", "fill", "Fill",
694 DEF_LINE_FILL_COLOR, Tk_Offset(Line, builtinPen.symbol.fillColor),
695 TK_CONFIG_NULL_OK | TK_CONFIG_COLOR_ONLY, &bltColorOption},
696 {TK_CONFIG_CUSTOM, "-fill", "fill", "Fill",
697 DEF_LINE_FILL_MONO, Tk_Offset(Line, builtinPen.symbol.fillColor),
698 TK_CONFIG_NULL_OK | TK_CONFIG_MONO_ONLY, &bltColorOption},
699 {TK_CONFIG_BOOLEAN, "-hide", "hide", "Hide",
700 DEF_LINE_HIDE, Tk_Offset(Line, hidden), TK_CONFIG_DONT_SET_DEFAULT},
701 {TK_CONFIG_STRING, "-label", "label", "Label",
702 (char *)NULL, Tk_Offset(Line, label), TK_CONFIG_NULL_OK},
703 {TK_CONFIG_RELIEF, "-labelrelief", "labelRelief", "LabelRelief",
704 DEF_LINE_LABEL_RELIEF, Tk_Offset(Line, labelRelief),
705 TK_CONFIG_DONT_SET_DEFAULT},
706 {TK_CONFIG_CUSTOM, "-linewidth", "lineWidth", "LineWidth",
707 DEF_LINE_PEN_WIDTH, Tk_Offset(Line, builtinPen.traceWidth),
708 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
709 {TK_CONFIG_CUSTOM, "-mapx", "mapX", "MapX",
710 DEF_LINE_AXIS_X, Tk_Offset(Line, axes.x), 0, &bltXAxisOption},
711 {TK_CONFIG_CUSTOM, "-mapy", "mapY", "MapY",
712 DEF_LINE_AXIS_Y, Tk_Offset(Line, axes.y), 0, &bltYAxisOption},
713 {TK_CONFIG_CUSTOM, "-maxsymbols", "maxSymbols", "MaxSymbols",
714 DEF_LINE_MAX_SYMBOLS, Tk_Offset(Line, reqMaxSymbols),
715 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
716 {TK_CONFIG_CUSTOM, "-offdash", "offDash", "OffDash",
717 DEF_LINE_OFFDASH_COLOR, Tk_Offset(Line, builtinPen.traceOffColor),
718 TK_CONFIG_NULL_OK | TK_CONFIG_COLOR_ONLY, &bltColorOption},
719 {TK_CONFIG_CUSTOM, "-offdash", "offDash", "OffDash",
720 DEF_LINE_OFFDASH_MONO, Tk_Offset(Line, builtinPen.traceOffColor),
721 TK_CONFIG_NULL_OK | TK_CONFIG_MONO_ONLY, &bltColorOption},
722 {TK_CONFIG_CUSTOM, "-outline", "outline", "Outline",
723 DEF_LINE_OUTLINE_COLOR, Tk_Offset(Line, builtinPen.symbol.outlineColor),
724 TK_CONFIG_COLOR_ONLY, &bltColorOption},
725 {TK_CONFIG_CUSTOM, "-outline", "outline", "Outline",
726 DEF_LINE_OUTLINE_MONO, Tk_Offset(Line, builtinPen.symbol.outlineColor),
727 TK_CONFIG_MONO_ONLY, &bltColorOption},
728 {TK_CONFIG_CUSTOM, "-outlinewidth", "outlineWidth", "OutlineWidth",
729 DEF_LINE_OUTLINE_WIDTH, Tk_Offset(Line, builtinPen.symbol.outlineWidth),
730 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
731 {TK_CONFIG_CUSTOM, "-pen", "pen", "Pen",
732 (char *)NULL, Tk_Offset(Line, normalPenPtr),
733 TK_CONFIG_NULL_OK, &bltLinePenOption},
734 {TK_CONFIG_CUSTOM, "-pixels", "pixels", "Pixels",
735 DEF_LINE_PIXELS, Tk_Offset(Line, builtinPen.symbol.size), 0,
736 &bltDistanceOption},
737 {TK_CONFIG_BOOLEAN, "-scalesymbols", "scaleSymbols", "ScaleSymbols",
738 DEF_LINE_SCALE_SYMBOLS, Tk_Offset(Line, scaleSymbols),
739 TK_CONFIG_DONT_SET_DEFAULT},
740 {TK_CONFIG_CUSTOM, "-showerrorbars", "showErrorBars", "ShowErrorBars",
741 DEF_LINE_SHOW_ERRORBARS, Tk_Offset(Line, builtinPen.errorBarShow),
742 TK_CONFIG_DONT_SET_DEFAULT, &bltFillOption},
743 {TK_CONFIG_CUSTOM, "-showvalues", "showValues", "ShowValues",
744 DEF_PEN_SHOW_VALUES, Tk_Offset(Line, builtinPen.valueShow),
745 TK_CONFIG_DONT_SET_DEFAULT, &bltFillOption},
746 {TK_CONFIG_CUSTOM, "-smooth", "smooth", "Smooth",
747 DEF_LINE_SMOOTH, Tk_Offset(Line, reqSmooth),
748 TK_CONFIG_DONT_SET_DEFAULT, &smoothOption},
749 {TK_CONFIG_CUSTOM, "-styles", "styles", "Styles",
750 DEF_LINE_STYLES, Tk_Offset(Line, palette),
751 TK_CONFIG_NULL_OK, &stylesOption},
752 {TK_CONFIG_CUSTOM, "-symbol", "symbol", "Symbol",
753 DEF_LINE_SYMBOL, Tk_Offset(Line, builtinPen.symbol),
754 TK_CONFIG_DONT_SET_DEFAULT, &symbolOption},
755 {TK_CONFIG_ANCHOR, "-valueanchor", "valueAnchor", "ValueAnchor",
756 DEF_PEN_VALUE_ANCHOR,
757 Tk_Offset(Line, builtinPen.valueStyle.anchor), 0},
758 {TK_CONFIG_COLOR, "-valuecolor", "valueColor", "ValueColor",
759 DEF_PEN_VALUE_COLOR, Tk_Offset(Line, builtinPen.valueStyle.color), 0},
760 {TK_CONFIG_FONT, "-valuefont", "valueFont", "ValueFont",
761 DEF_PEN_VALUE_FONT, Tk_Offset(Line, builtinPen.valueStyle.font), 0},
762 {TK_CONFIG_STRING, "-valueformat", "valueFormat", "ValueFormat",
763 DEF_PEN_VALUE_FORMAT, Tk_Offset(Line, builtinPen.valueFormat),
764 TK_CONFIG_NULL_OK},
765 {TK_CONFIG_DOUBLE, "-valuerotate", "valueRotate", "ValueRotate",
766 DEF_PEN_VALUE_ROTATE, Tk_Offset(Line, builtinPen.valueStyle.theta), 0},
767 {TK_CONFIG_CUSTOM, "-valueshadow", "valueShadow", "ValueShadow",
768 DEF_PEN_VALUE_SHADOW, Tk_Offset(Line, builtinPen.valueStyle.shadow), 0,
769 &bltShadowOption},
770 {TK_CONFIG_CUSTOM, "-weights", "weights", "Weights",
771 (char *)NULL, Tk_Offset(Line, w), 0, &bltDataOption},
772 {TK_CONFIG_CUSTOM, "-x", "xData", "XData",
773 (char *)NULL, Tk_Offset(Line, x), 0, &bltDataOption},
774 {TK_CONFIG_CUSTOM, "-xdata", "xData", "XData",
775 (char *)NULL, Tk_Offset(Line, x), 0, &bltDataOption},
776 {TK_CONFIG_CUSTOM, "-y", "yData", "YData",
777 (char *)NULL, Tk_Offset(Line, y), 0, &bltDataOption},
778 {TK_CONFIG_CUSTOM, "-xerror", "xError", "XError", (char *)NULL,
779 Tk_Offset(Line, xError), 0, &bltDataOption},
780 {TK_CONFIG_CUSTOM, "-ydata", "yData", "YData",
781 (char *)NULL, Tk_Offset(Line, y), 0, &bltDataOption},
782 {TK_CONFIG_CUSTOM, "-yerror", "yError", "YError", (char *)NULL,
783 Tk_Offset(Line, yError), 0, &bltDataOption},
784 {TK_CONFIG_CUSTOM, "-xhigh", "xHigh", "XHigh", (char *)NULL,
785 Tk_Offset(Line, xHigh), 0, &bltDataOption},
786 {TK_CONFIG_CUSTOM, "-xlow", "xLow", "XLow", (char *)NULL,
787 Tk_Offset(Line, xLow), 0, &bltDataOption},
788 {TK_CONFIG_CUSTOM, "-yhigh", "yHigh", "YHigh", (char *)NULL,
789 Tk_Offset(Line, xHigh), 0, &bltDataOption},
790 {TK_CONFIG_CUSTOM, "-ylow", "yLow", "YLow", (char *)NULL,
791 Tk_Offset(Line, yLow), 0, &bltDataOption},
792 {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0}
793 };
794
795 static Tk_ConfigSpec linePenConfigSpecs[] =
796 {
797 {TK_CONFIG_COLOR, "-color", "color", "Color",
798 DEF_PEN_ACTIVE_COLOR, Tk_Offset(LinePen, traceColor),
799 TK_CONFIG_COLOR_ONLY | ACTIVE_PEN},
800 {TK_CONFIG_COLOR, "-color", "color", "Color",
801 DEF_PEN_ACTIVE_MONO, Tk_Offset(LinePen, traceColor),
802 TK_CONFIG_MONO_ONLY | ACTIVE_PEN},
803 {TK_CONFIG_COLOR, "-color", "color", "Color",
804 DEF_PEN_NORMAL_COLOR, Tk_Offset(LinePen, traceColor),
805 TK_CONFIG_COLOR_ONLY | NORMAL_PEN},
806 {TK_CONFIG_COLOR, "-color", "color", "Color",
807 DEF_PEN_NORMAL_MONO, Tk_Offset(LinePen, traceColor),
808 TK_CONFIG_MONO_ONLY | NORMAL_PEN},
809 {TK_CONFIG_CUSTOM, "-dashes", "dashes", "Dashes",
810 DEF_PEN_DASHES, Tk_Offset(LinePen, traceDashes),
811 TK_CONFIG_NULL_OK | ALL_PENS, &bltDashesOption},
812 {TK_CONFIG_CUSTOM, "-errorbarcolor", "errorBarColor", "ErrorBarColor",
813 DEF_LINE_ERRORBAR_COLOR, Tk_Offset(LinePen, errorBarColor),
814 ALL_PENS, &bltColorOption},
815 {TK_CONFIG_CUSTOM, "-errorbarwidth", "errorBarWidth", "ErrorBarWidth",
816 DEF_LINE_ERRORBAR_LINE_WIDTH, Tk_Offset(LinePen, errorBarLineWidth),
817 ALL_PENS | TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
818 {TK_CONFIG_CUSTOM, "-errorbarcap", "errorBarCap",
819 "ErrorBarCap", DEF_LINE_ERRORBAR_CAP_WIDTH,
820 Tk_Offset(LinePen, errorBarCapWidth),
821 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
822 {TK_CONFIG_CUSTOM, "-fill", "fill", "Fill",
823 DEF_PEN_FILL_COLOR, Tk_Offset(LinePen, symbol.fillColor),
824 TK_CONFIG_NULL_OK | TK_CONFIG_COLOR_ONLY | ALL_PENS, &bltColorOption},
825 {TK_CONFIG_CUSTOM, "-fill", "fill", "Fill",
826 DEF_PEN_FILL_MONO, Tk_Offset(LinePen, symbol.fillColor),
827 TK_CONFIG_NULL_OK | TK_CONFIG_MONO_ONLY | ALL_PENS, &bltColorOption},
828 {TK_CONFIG_CUSTOM, "-linewidth", "lineWidth", "LineWidth",
829 (char *)NULL, Tk_Offset(LinePen, traceWidth),
830 ALL_PENS | TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
831 {TK_CONFIG_CUSTOM, "-offdash", "offDash", "OffDash",
832 DEF_PEN_OFFDASH_COLOR, Tk_Offset(LinePen, traceOffColor),
833 TK_CONFIG_NULL_OK | TK_CONFIG_COLOR_ONLY | ALL_PENS, &bltColorOption},
834 {TK_CONFIG_CUSTOM, "-offdash", "offDash", "OffDash",
835 DEF_PEN_OFFDASH_MONO, Tk_Offset(LinePen, traceOffColor),
836 TK_CONFIG_NULL_OK | TK_CONFIG_MONO_ONLY | ALL_PENS, &bltColorOption},
837 {TK_CONFIG_CUSTOM, "-outline", "outline", "Outline",
838 DEF_PEN_OUTLINE_COLOR, Tk_Offset(LinePen, symbol.outlineColor),
839 TK_CONFIG_COLOR_ONLY | ALL_PENS, &bltColorOption},
840 {TK_CONFIG_CUSTOM, "-outline", "outline", "Outline",
841 DEF_PEN_OUTLINE_MONO, Tk_Offset(LinePen, symbol.outlineColor),
842 TK_CONFIG_MONO_ONLY | ALL_PENS, &bltColorOption},
843 {TK_CONFIG_CUSTOM, "-outlinewidth", "outlineWidth", "OutlineWidth",
844 DEF_PEN_OUTLINE_WIDTH, Tk_Offset(LinePen, symbol.outlineWidth),
845 TK_CONFIG_DONT_SET_DEFAULT | ALL_PENS, &bltDistanceOption},
846 {TK_CONFIG_CUSTOM, "-pixels", "pixels", "Pixels",
847 DEF_PEN_PIXELS, Tk_Offset(LinePen, symbol.size),
848 ALL_PENS, &bltDistanceOption},
849 {TK_CONFIG_CUSTOM, "-showerrorbars", "showErrorBars", "ShowErrorBars",
850 DEF_LINE_SHOW_ERRORBARS, Tk_Offset(LinePen, errorBarShow),
851 TK_CONFIG_DONT_SET_DEFAULT, &bltFillOption},
852 {TK_CONFIG_CUSTOM, "-showvalues", "showValues", "ShowValues",
853 DEF_PEN_SHOW_VALUES, Tk_Offset(LinePen, valueShow),
854 ALL_PENS | TK_CONFIG_DONT_SET_DEFAULT, &bltFillOption},
855 {TK_CONFIG_CUSTOM, "-symbol", "symbol", "Symbol",
856 DEF_PEN_SYMBOL, Tk_Offset(LinePen, symbol),
857 TK_CONFIG_DONT_SET_DEFAULT | ALL_PENS, &symbolOption},
858 {TK_CONFIG_STRING, "-type", (char *)NULL, (char *)NULL,
859 DEF_PEN_TYPE, Tk_Offset(Pen, typeId), ALL_PENS | TK_CONFIG_NULL_OK},
860 {TK_CONFIG_ANCHOR, "-valueanchor", "valueAnchor", "ValueAnchor",
861 DEF_PEN_VALUE_ANCHOR, Tk_Offset(LinePen, valueStyle.anchor), ALL_PENS},
862 {TK_CONFIG_COLOR, "-valuecolor", "valueColor", "ValueColor",
863 DEF_PEN_VALUE_COLOR, Tk_Offset(LinePen, valueStyle.color), ALL_PENS},
864 {TK_CONFIG_FONT, "-valuefont", "valueFont", "ValueFont",
865 DEF_PEN_VALUE_FONT, Tk_Offset(LinePen, valueStyle.font), ALL_PENS},
866 {TK_CONFIG_STRING, "-valueformat", "valueFormat", "ValueFormat",
867 DEF_PEN_VALUE_FORMAT, Tk_Offset(LinePen, valueFormat),
868 ALL_PENS | TK_CONFIG_NULL_OK},
869 {TK_CONFIG_DOUBLE, "-valuerotate", "valueRotate", "ValueRotate",
870 DEF_PEN_VALUE_ROTATE, Tk_Offset(LinePen, valueStyle.theta), ALL_PENS},
871 {TK_CONFIG_CUSTOM, "-valueshadow", "valueShadow", "ValueShadow",
872 DEF_PEN_VALUE_SHADOW, Tk_Offset(LinePen, valueStyle.shadow),
873 ALL_PENS, &bltShadowOption},
874 {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0}
875 };
876
877 typedef double (DistanceProc) _ANSI_ARGS_((int x, int y, Point2D *p,
878 Point2D *q, Point2D *t));
879
880 /* Forward declarations */
881 static PenConfigureProc ConfigurePen;
882 static PenDestroyProc DestroyPen;
883 static ElementClosestProc ClosestLine;
884 static ElementConfigProc ConfigureLine;
885 static ElementDestroyProc DestroyLine;
886 static ElementDrawProc DrawActiveLine;
887 static ElementDrawProc DrawNormalLine;
888 static ElementDrawSymbolProc DrawSymbol;
889 static ElementExtentsProc GetLineExtents;
890 static ElementToPostScriptProc ActiveLineToPostScript;
891 static ElementToPostScriptProc NormalLineToPostScript;
892 static ElementSymbolToPostScriptProc SymbolToPostScript;
893 static ElementMapProc MapLine;
894 static DistanceProc DistanceToY;
895 static DistanceProc DistanceToX;
896 static DistanceProc DistanceToLine;
897 static Blt_TileChangedProc TileChangedProc;
898
899 #ifdef WIN32
900
901 static int tkpWinRopModes[] =
902 {
903 R2_BLACK, /* GXclear */
904 R2_MASKPEN, /* GXand */
905 R2_MASKPENNOT, /* GXandReverse */
906 R2_COPYPEN, /* GXcopy */
907 R2_MASKNOTPEN, /* GXandInverted */
908 R2_NOT, /* GXnoop */
909 R2_XORPEN, /* GXxor */
910 R2_MERGEPEN, /* GXor */
911 R2_NOTMERGEPEN, /* GXnor */
912 R2_NOTXORPEN, /* GXequiv */
913 R2_NOT, /* GXinvert */
914 R2_MERGEPENNOT, /* GXorReverse */
915 R2_NOTCOPYPEN, /* GXcopyInverted */
916 R2_MERGENOTPEN, /* GXorInverted */
917 R2_NOTMASKPEN, /* GXnand */
918 R2_WHITE /* GXset */
919 };
920
921 #endif
922
923 INLINE static int
924 Round(x)
925 register double x;
926 {
927 return (int) (x + ((x < 0.0) ? -0.5 : 0.5));
928 }
929
930 /*
931 * ----------------------------------------------------------------------
932 * Custom configuration option (parse and print) routines
933 * ----------------------------------------------------------------------
934 */
935
936 static int
937 StringToBitmap(interp, tkwin, symbolPtr, string)
938 Tcl_Interp *interp;
939 Tk_Window tkwin;
940 Symbol *symbolPtr;
941 char *string;
942 {
943 Pixmap bitmap, mask;
944 char **elemArr;
945 int nElems;
946 int result;
947
948 if (Tcl_SplitList(interp, string, &nElems, &elemArr) != TCL_OK) {
949 return TCL_ERROR;
950 }
951
952 if (nElems > 2) {
953 Tcl_AppendResult(interp, "too many elements in bitmap list \"", string,
954 "\": should be \"bitmap mask\"", (char *)NULL);
955 result = TCL_ERROR;
956 goto error;
957 }
958 mask = None;
959 bitmap = Tk_GetBitmap(interp, tkwin, Tk_GetUid(elemArr[0]));
960 if (bitmap == None) {
961 result = TCL_BREAK;
962 Tcl_ResetResult(interp);
963 goto error;
964 }
965 if ((nElems > 1) && (elemArr[1][0] != '\0')) {
966 mask = Tk_GetBitmap(interp, tkwin, Tk_GetUid(elemArr[1]));
967 if (mask == None) {
968 Tk_FreeBitmap(Tk_Display(tkwin), bitmap);
969 result = TCL_ERROR;
970 goto error;
971 }
972 }
973 Blt_Free(elemArr);
974 if (symbolPtr->bitmap != None) {
975 Tk_FreeBitmap(Tk_Display(tkwin), symbolPtr->bitmap);
976 }
977 symbolPtr->bitmap = bitmap;
978 if (symbolPtr->mask != None) {
979 Tk_FreeBitmap(Tk_Display(tkwin), symbolPtr->mask);
980 }
981 symbolPtr->mask = mask;
982 return TCL_OK;
983 error:
984 Blt_Free(elemArr);
985 return result;
986 }
987
988 /*ARGSUSED*/
989 static char *
990 PatternToString(clientData, tkwin, widgRec, offset, freeProcPtr)
991 ClientData clientData; /* Not used. */
992 Tk_Window tkwin;
993 char *widgRec; /* Element information record */
994 int offset; /* Offset of field in record */
995 Tcl_FreeProc **freeProcPtr; /* Not used. */
996 {
997 Pixmap stipple = *(Pixmap *)(widgRec + offset);
998
999 if (stipple == None) {
1000 return "";
1001 }
1002 if (stipple == PATTERN_SOLID) {
1003 return "solid";
1004 }
1005 return Tk_NameOfBitmap(Tk_Display(tkwin), stipple);
1006 }
1007
1008 /*ARGSUSED*/
1009 static int
1010 StringToPattern(clientData, interp, tkwin, string, widgRec, offset)
1011 ClientData clientData; /* Not used. */
1012 Tcl_Interp *interp; /* Interpreter to send results back to */
1013 Tk_Window tkwin; /* Not used. */
1014 char *string; /* String representing field */
1015 char *widgRec; /* Element information record */
1016 int offset; /* Offset of field in record */
1017 {
1018 Pixmap *stipplePtr = (Pixmap *)(widgRec + offset);
1019 Pixmap stipple;
1020
1021 if ((string == NULL) || (string[0] == '\0')) {
1022 stipple = None;
1023 } else if (strcmp(string, "solid") == 0) {
1024 stipple = PATTERN_SOLID;
1025 } else {
1026 stipple = Tk_GetBitmap(interp, tkwin, Tk_GetUid(string));
1027 if (stipple == None) {
1028 return TCL_ERROR;
1029 }
1030 }
1031 if ((*stipplePtr != None) && (*stipplePtr != PATTERN_SOLID)) {
1032 Tk_FreeBitmap(Tk_Display(tkwin), *stipplePtr);
1033 }
1034 *stipplePtr = stipple;
1035 return TCL_OK;
1036 }
1037
1038
1039 /*
1040 *----------------------------------------------------------------------
1041 *
1042 * NameOfSymbol --
1043 *
1044 * Converts the symbol value into its string representation.
1045 *
1046 * Results:
1047 * The static string representing the symbol type is returned.
1048 *
1049 *----------------------------------------------------------------------
1050 */
1051 static char *
1052 NameOfSymbol(symbolPtr)
1053 Symbol *symbolPtr;
1054 {
1055 switch (symbolPtr->type) {
1056 case SYMBOL_NONE:
1057 return "none";
1058 case SYMBOL_SQUARE:
1059 return "square";
1060 case SYMBOL_CIRCLE:
1061 return "circle";
1062 case SYMBOL_DIAMOND:
1063 return "diamond";
1064 case SYMBOL_PLUS:
1065 return "plus";
1066 case SYMBOL_CROSS:
1067 return "cross";
1068 case SYMBOL_SPLUS:
1069 return "splus";
1070 case SYMBOL_SCROSS:
1071 return "scross";
1072 case SYMBOL_TRIANGLE:
1073 return "triangle";
1074 case SYMBOL_ARROW:
1075 return "arrow";
1076 case SYMBOL_BITMAP:
1077 return "bitmap";
1078 }
1079 return NULL;
1080 }
1081
1082 /*
1083 *----------------------------------------------------------------------
1084 *
1085 * StringToSymbol --
1086 *
1087 * Convert the string representation of a line style or symbol name
1088 * into its numeric form.
1089 *
1090 * Results:
1091 * The return value is a standard Tcl result. The symbol type is
1092 * written into the widget record.
1093 *
1094 *----------------------------------------------------------------------
1095 */
1096 /*ARGSUSED*/
1097 static int
1098 StringToSymbol(clientData, interp, tkwin, string, widgRec, offset)
1099 ClientData clientData; /* Not used. */
1100 Tcl_Interp *interp; /* Interpreter to send results back to */
1101 Tk_Window tkwin; /* Not used. */
1102 char *string; /* String representing symbol type */
1103 char *widgRec; /* Element information record */
1104 int offset; /* Offset of symbol type field in record */
1105 {
1106 Symbol *symbolPtr = (Symbol *)(widgRec + offset);
1107 unsigned int length;
1108 char c;
1109
1110 c = string[0];
1111 length = strlen(string);
1112 if (c == '\0') {
1113 symbolPtr->type = SYMBOL_NONE;
1114 } else if ((c == 'n') && (strncmp(string, "none", length) == 0)) {
1115 symbolPtr->type = SYMBOL_NONE;
1116 } else if ((c == 'c') && (length > 1) &&
1117 (strncmp(string, "circle", length) == 0)) {
1118 symbolPtr->type = SYMBOL_CIRCLE;
1119 } else if ((c == 's') && (length > 1) &&
1120 (strncmp(string, "square", length) == 0)) {
1121 symbolPtr->type = SYMBOL_SQUARE;
1122 } else if ((c == 'd') && (strncmp(string, "diamond", length) == 0)) {
1123 symbolPtr->type = SYMBOL_DIAMOND;
1124 } else if ((c == 'p') && (strncmp(string, "plus", length) == 0)) {
1125 symbolPtr->type = SYMBOL_PLUS;
1126 } else if ((c == 'c') && (length > 1) &&
1127 (strncmp(string, "cross", length) == 0)) {
1128 symbolPtr->type = SYMBOL_CROSS;
1129 } else if ((c == 's') && (length > 1) &&
1130 (strncmp(string, "splus", length) == 0)) {
1131 symbolPtr->type = SYMBOL_SPLUS;
1132 } else if ((c == 's') && (length > 1) &&
1133 (strncmp(string, "scross", length) == 0)) {
1134 symbolPtr->type = SYMBOL_SCROSS;
1135 } else if ((c == 't') && (strncmp(string, "triangle", length) == 0)) {
1136 symbolPtr->type = SYMBOL_TRIANGLE;
1137 } else if ((c == 'a') && (strncmp(string, "arrow", length) == 0)) {
1138 symbolPtr->type = SYMBOL_ARROW;
1139 } else {
1140 int result;
1141
1142 result = StringToBitmap(interp, tkwin, symbolPtr, string);
1143 if (result != TCL_OK) {
1144 if (result != TCL_ERROR) {
1145 Tcl_AppendResult(interp, "bad symbol \"", string,
1146 "\": should be \"none\", \"circle\", \"square\", \"diamond\", \"plus\", \
1147 \"cross\", \"splus\", \"scross\", \"triangle\", \"arrow\" \
1148 or the name of a bitmap", (char *)NULL);
1149 }
1150 return TCL_ERROR;
1151 }
1152 symbolPtr->type = SYMBOL_BITMAP;
1153 }
1154 return TCL_OK;
1155 }
1156
1157 /*
1158 *----------------------------------------------------------------------
1159 *
1160 * SymbolToString --
1161 *
1162 * Convert the symbol value into a string.
1163 *
1164 * Results:
1165 * The string representing the symbol type or line style is returned.
1166 *
1167 *----------------------------------------------------------------------
1168 */
1169 /*ARGSUSED*/
1170 static char *
1171 SymbolToString(clientData, tkwin, widgRec, offset, freeProcPtr)
1172 ClientData clientData; /* Not used. */
1173 Tk_Window tkwin;
1174 char *widgRec; /* Element information record */
1175 int offset; /* Offset of symbol type field in record */
1176 Tcl_FreeProc **freeProcPtr; /* Not used. */
1177 {
1178 Symbol *symbolPtr = (Symbol *)(widgRec + offset);
1179 char *result;
1180
1181 if (symbolPtr->type == SYMBOL_BITMAP) {
1182 Tcl_DString dString;
1183
1184 Tcl_DStringInit(&dString);
1185 Tcl_DStringAppendElement(&dString,
1186 Tk_NameOfBitmap(Tk_Display(tkwin), symbolPtr->bitmap));
1187 Tcl_DStringAppendElement(&dString, (symbolPtr->mask == None) ? "" :
1188 Tk_NameOfBitmap(Tk_Display(tkwin), symbolPtr->mask));
1189 result = Blt_Strdup(Tcl_DStringValue(&dString));
1190 Tcl_DStringFree(&dString);
1191 *freeProcPtr = (Tcl_FreeProc *)Blt_Free;
1192 } else {
1193 result = NameOfSymbol(symbolPtr);
1194 }
1195 return result;
1196 }
1197
1198 /*
1199 *----------------------------------------------------------------------
1200 *
1201 * NameOfSmooth --
1202 *
1203 * Converts the smooth value into its string representation.
1204 *
1205 * Results:
1206 * The static string representing the smooth type is returned.
1207 *
1208 *----------------------------------------------------------------------
1209 */
1210 static char *
1211 NameOfSmooth(value)
1212 Smoothing value;
1213 {
1214 if ((value < 0) || (value >= PEN_SMOOTH_LAST)) {
1215 return "unknown smooth value";
1216 }
1217 return smoothingInfo[value].name;
1218 }
1219
1220 /*
1221 *----------------------------------------------------------------------
1222 *
1223 * StringToSmooth --
1224 *
1225 * Convert the string representation of a line style or smooth name
1226 * into its numeric form.
1227 *
1228 * Results:
1229 * The return value is a standard Tcl result. The smooth type is
1230 * written into the widget record.
1231 *
1232 *----------------------------------------------------------------------
1233 */
1234 /*ARGSUSED*/
1235 static int
1236 StringToSmooth(clientData, interp, tkwin, string, widgRec, offset)
1237 ClientData clientData; /* Not used. */
1238 Tcl_Interp *interp; /* Interpreter to send results back to */
1239 Tk_Window tkwin; /* Not used. */
1240 char *string; /* String representing smooth type */
1241 char *widgRec; /* Element information record */
1242 int offset; /* Offset of smooth type field in record */
1243 {
1244 Smoothing *valuePtr = (Smoothing *)(widgRec + offset);
1245 register SmoothingInfo *siPtr;
1246
1247 for (siPtr = smoothingInfo; siPtr->name != NULL; siPtr++) {
1248 if (strcmp(string, siPtr->name) == 0) {
1249 *valuePtr = siPtr->value;
1250 return TCL_OK;
1251 }
1252 }
1253 Tcl_AppendResult(interp, "bad smooth value \"", string, "\": should be \
1254 linear, step, natural, or quadratic", (char *)NULL);
1255 return TCL_ERROR;
1256 }
1257
1258 /*
1259 *----------------------------------------------------------------------
1260 *
1261 * SmoothToString --
1262 *
1263 * Convert the smooth value into a string.
1264 *
1265 * Results:
1266 * The string representing the smooth type or line style is returned.
1267 *
1268 *----------------------------------------------------------------------
1269 */
1270 /*ARGSUSED*/
1271 static char *
1272 SmoothToString(clientData, tkwin, widgRec, offset, freeProcPtr)
1273 ClientData clientData; /* Not used. */
1274 Tk_Window tkwin; /* Not used. */
1275 char *widgRec; /* Element information record */
1276 int offset; /* Offset of smooth type field in record */
1277 Tcl_FreeProc **freeProcPtr; /* Not used. */
1278 {
1279 int smooth = *(int *)(widgRec + offset);
1280
1281 return NameOfSmooth(smooth);
1282 }
1283
1284 /*
1285 *----------------------------------------------------------------------
1286 *
1287 * StringToPenDir --
1288 *
1289 * Convert the string representation of a line style or symbol name
1290 * into its numeric form.
1291 *
1292 * Results:
1293 * The return value is a standard Tcl result. The symbol type is
1294 * written into the widget record.
1295 *
1296 *----------------------------------------------------------------------
1297 */
1298 /*ARGSUSED*/
1299 static int
1300 StringToPenDir(clientData, interp, tkwin, string, widgRec, offset)
1301 ClientData clientData; /* Not used. */
1302 Tcl_Interp *interp; /* Interpreter to send results back to */
1303 Tk_Window tkwin; /* Not used. */
1304 char *string; /* String representing pen direction */
1305 char *widgRec; /* Element information record */
1306 int offset; /* Offset of pen direction field in record */
1307 {
1308 int *penDirPtr = (int *)(widgRec + offset);
1309 unsigned int length;
1310 char c;
1311
1312 c = string[0];
1313 length = strlen(string);
1314 if ((c == 'i') && (strncmp(string, "increasing", length) == 0)) {
1315 *penDirPtr = PEN_INCREASING;
1316 } else if ((c == 'd') && (strncmp(string, "decreasing", length) == 0)) {
1317 *penDirPtr = PEN_DECREASING;
1318 } else if ((c == 'b') && (strncmp(string, "both", length) == 0)) {
1319 *penDirPtr = PEN_BOTH_DIRECTIONS;
1320 } else {
1321 Tcl_AppendResult(interp, "bad trace value \"", string,
1322 "\" : should be \"increasing\", \"decreasing\", or \"both\"",
1323 (char *)NULL);
1324 return TCL_ERROR;
1325 }
1326 return TCL_OK;
1327 }
1328
1329 /*
1330 *----------------------------------------------------------------------
1331 *
1332 * NameOfPenDir --
1333 *
1334 * Convert the pen direction into a string.
1335 *
1336 * Results:
1337 * The static string representing the pen direction is returned.
1338 *
1339 *----------------------------------------------------------------------
1340 */
1341 static char *
1342 NameOfPenDir(penDir)
1343 int penDir; /* Direction for pen drawing between points */
1344 {
1345 switch (penDir) {
1346 case PEN_INCREASING:
1347 return "increasing";
1348 case PEN_DECREASING:
1349 return "decreasing";
1350 case PEN_BOTH_DIRECTIONS:
1351 return "both";
1352 default:
1353 return "unknown trace direction";
1354 }
1355 }
1356
1357 /*
1358 *----------------------------------------------------------------------
1359 *
1360 * PenDirToString --
1361 *
1362 * Convert the pen direction into a string.
1363 *
1364 * Results:
1365 * The string representing the pen drawing direction is returned.
1366 *
1367 *----------------------------------------------------------------------
1368 */
1369 /*ARGSUSED*/
1370 static char *
1371 PenDirToString(clientData, tkwin, widgRec, offset, freeProcPtr)
1372 ClientData clientData; /* Not used. */
1373 Tk_Window tkwin; /* Not used. */
1374 char *widgRec; /* Element information record */
1375 int offset; /* Offset of pen direction field in record */
1376 Tcl_FreeProc **freeProcPtr; /* Not used. */
1377 {
1378 int penDir = *(int *)(widgRec + offset);
1379
1380 return NameOfPenDir(penDir);
1381 }
1382
1383
1384 /*
1385 * Clear the number of points and segments, in case there are no
1386 * segments or points
1387 */
1388 static void
1389 ClearPalette(palette)
1390 Blt_Chain *palette;
1391 {
1392 register LinePenStyle *stylePtr;
1393 Blt_ChainLink *linkPtr;
1394
1395 for (linkPtr = Blt_ChainFirstLink(palette); linkPtr != NULL;
1396 linkPtr = Blt_ChainNextLink(linkPtr)) {
1397 stylePtr = Blt_ChainGetValue(linkPtr);
1398 stylePtr->nStrips = stylePtr->nSymbolPts = 0;
1399 stylePtr->xErrorBarCnt = stylePtr->yErrorBarCnt = 0;
1400 }
1401 }
1402
1403
1404 /*
1405 *----------------------------------------------------------------------
1406 *
1407 * ConfigurePen --
1408 *
1409 * Sets up the appropriate configuration parameters in the GC.
1410 * It is assumed the parameters have been previously set by
1411 * a call to Tk_ConfigureWidget.
1412 *
1413 * Results:
1414 * The return value is a standard Tcl result. If TCL_ERROR is
1415 * returned, then interp->result contains an error message.
1416 *
1417 * Side effects:
1418 * Configuration information such as line width, line style, color
1419 * etc. get set in a new GC.
1420 *
1421 *----------------------------------------------------------------------
1422 */
1423 /*ARGSUSED*/
1424 static int
1425 ConfigurePen(graphPtr, penPtr)
1426 Graph *graphPtr;
1427 Pen *penPtr;
1428 {
1429 LinePen *lpPtr = (LinePen *)penPtr;
1430 unsigned long gcMask;
1431 GC newGC;
1432 XGCValues gcValues;
1433 XColor *colorPtr;
1434
1435 Blt_ResetTextStyle(graphPtr->tkwin, &(lpPtr->valueStyle));
1436 /*
1437 * Set the outline GC for this pen: GCForeground is outline color.
1438 * GCBackground is the fill color (only used for bitmap symbols).
1439 */
1440 gcMask = (GCLineWidth | GCForeground);
1441 colorPtr = lpPtr->symbol.outlineColor;
1442 if (colorPtr == COLOR_DEFAULT) {
1443 colorPtr = lpPtr->traceColor;
1444 }
1445 gcValues.foreground = colorPtr->pixel;
1446 if (lpPtr->symbol.type == SYMBOL_BITMAP) {
1447 colorPtr = lpPtr->symbol.fillColor;
1448 if (colorPtr == COLOR_DEFAULT) {
1449 colorPtr = lpPtr->traceColor;
1450 }
1451 /*
1452 * Set a clip mask if either
1453 * 1) no background color was designated or
1454 * 2) a masking bitmap was specified.
1455 *
1456 * These aren't necessarily the bitmaps we'll be using for
1457 * clipping. But this makes it unlikely that anyone else will
1458 * be sharing this GC when we set the clip origin (at the time
1459 * the bitmap is drawn).
1460 */
1461 if (colorPtr != NULL) {
1462 gcValues.background = colorPtr->pixel;
1463 gcMask |= GCBackground;
1464 if (lpPtr->symbol.mask != None) {
1465 gcValues.clip_mask = lpPtr->symbol.mask;
1466 gcMask |= GCClipMask;
1467 }
1468 } else {
1469 gcValues.clip_mask = lpPtr->symbol.bitmap;
1470 gcMask |= GCClipMask;
1471 }
1472 }
1473 gcValues.line_width = LineWidth(lpPtr->symbol.outlineWidth);
1474 newGC = Tk_GetGC(graphPtr->tkwin, gcMask, &gcValues);
1475 if (lpPtr->symbol.outlineGC != NULL) {
1476 Tk_FreeGC(graphPtr->display, lpPtr->symbol.outlineGC);
1477 }
1478 lpPtr->symbol.outlineGC = newGC;
1479
1480 /* Fill GC for symbols: GCForeground is fill color */
1481
1482 gcMask = (GCLineWidth | GCForeground);
1483 colorPtr = lpPtr->symbol.fillColor;
1484 if (colorPtr == COLOR_DEFAULT) {
1485 colorPtr = lpPtr->traceColor;
1486 }
1487 newGC = NULL;
1488 if (colorPtr != NULL) {
1489 gcValues.foreground = colorPtr->pixel;
1490 newGC = Tk_GetGC(graphPtr->tkwin, gcMask, &gcValues);
1491 }
1492 if (lpPtr->symbol.fillGC != NULL) {
1493 Tk_FreeGC(graphPtr->display, lpPtr->symbol.fillGC);
1494 }
1495 lpPtr->symbol.fillGC = newGC;
1496
1497 /* Line segments */
1498
1499 gcMask = (GCLineWidth | GCForeground | GCLineStyle | GCCapStyle |
1500 GCJoinStyle);
1501 gcValues.cap_style = CapButt;
1502 gcValues.join_style = JoinRound;
1503 gcValues.line_style = LineSolid;
1504 gcValues.line_width = LineWidth(lpPtr->traceWidth);
1505
1506 colorPtr = lpPtr->traceOffColor;
1507 if (colorPtr == COLOR_DEFAULT) {
1508 colorPtr = lpPtr->traceColor;
1509 }
1510 if (colorPtr != NULL) {
1511 gcMask |= GCBackground;
1512 gcValues.background = colorPtr->pixel;
1513 }
1514 gcValues.foreground = lpPtr->traceColor->pixel;
1515 if (LineIsDashed(lpPtr->traceDashes)) {
1516 gcValues.line_width = lpPtr->traceWidth;
1517 gcValues.line_style =
1518 (colorPtr == NULL) ? LineOnOffDash : LineDoubleDash;
1519 }
1520 newGC = Blt_GetPrivateGC(graphPtr->tkwin, gcMask, &gcValues);
1521 if (lpPtr->traceGC != NULL) {
1522 Blt_FreePrivateGC(graphPtr->display, lpPtr->traceGC);
1523 }
1524 if (LineIsDashed(lpPtr->traceDashes)) {
1525 lpPtr->traceDashes.offset = lpPtr->traceDashes.values[0] / 2;
1526 Blt_SetDashes(graphPtr->display, newGC, &(lpPtr->traceDashes));
1527 }
1528 lpPtr->traceGC = newGC;
1529
1530 gcMask = (GCLineWidth | GCForeground);
1531 colorPtr = lpPtr->errorBarColor;
1532 if (colorPtr == COLOR_DEFAULT) {
1533 colorPtr = lpPtr->traceColor;
1534 }
1535 gcValues.line_width = LineWidth(lpPtr->errorBarLineWidth);
1536 gcValues.foreground = colorPtr->pixel;
1537 newGC = Tk_GetGC(graphPtr->tkwin, gcMask, &gcValues);
1538 if (lpPtr->errorBarGC != NULL) {
1539 Tk_FreeGC(graphPtr->display, lpPtr->errorBarGC);
1540 }
1541 lpPtr->errorBarGC = newGC;
1542
1543 return TCL_OK;
1544 }
1545
1546 /*
1547 *----------------------------------------------------------------------
1548 *
1549 * DestroyPen --
1550 *
1551 * Release memory and resources allocated for the style.
1552 *
1553 * Results:
1554 * None.
1555 *
1556 * Side effects:
1557 * Everything associated with the pen style is freed up.
1558 *
1559 *----------------------------------------------------------------------
1560 */
1561 static void
1562 DestroyPen(graphPtr, penPtr)
1563 Graph *graphPtr;
1564 Pen *penPtr;
1565 {
1566 LinePen *lpPtr = (LinePen *)penPtr;
1567
1568 Blt_FreeTextStyle(graphPtr->display, &(lpPtr->valueStyle));
1569 /* TODO: Do this for all shadows.
1570 if (lpPtr->valueStyle.shadow.color != NULL) {
1571 Tk_FreeColor(lpPtr->valueStyle.shadow.color);
1572 }
1573 */
1574 if (lpPtr->symbol.outlineGC != NULL) {
1575 Tk_FreeGC(graphPtr->display, lpPtr->symbol.outlineGC);
1576 }
1577 if (lpPtr->symbol.fillGC != NULL) {
1578 Tk_FreeGC(graphPtr->display, lpPtr->symbol.fillGC);
1579 }
1580 if (lpPtr->errorBarGC != NULL) {
1581 Tk_FreeGC(graphPtr->display, lpPtr->errorBarGC);
1582 }
1583 if (lpPtr->traceGC != NULL) {
1584 Blt_FreePrivateGC(graphPtr->display, lpPtr->traceGC);
1585 }
1586 if (lpPtr->symbol.bitmap != None) {
1587 Tk_FreeBitmap(graphPtr->display, lpPtr->symbol.bitmap);
1588 lpPtr->symbol.bitmap = None;
1589 }
1590 if (lpPtr->symbol.mask != None) {
1591 Tk_FreeBitmap(graphPtr->display, lpPtr->symbol.mask);
1592 lpPtr->symbol.mask = None;
1593 }
1594 }
1595
1596
1597 static void
1598 InitPen(penPtr)
1599 LinePen *penPtr;
1600 {
1601 Blt_InitTextStyle(&penPtr->valueStyle);
1602 penPtr->configProc = ConfigurePen;
1603 penPtr->configSpecs = linePenConfigSpecs;
1604 penPtr->destroyProc = DestroyPen;
1605 penPtr->errorBarLineWidth = 1;
1606 penPtr->errorBarShow = SHOW_BOTH;
1607 penPtr->flags = NORMAL_PEN;
1608 penPtr->name = "";
1609 penPtr->symbol.bitmap = penPtr->symbol.mask = None;
1610 penPtr->symbol.outlineColor = penPtr->symbol.fillColor = COLOR_DEFAULT;
1611 penPtr->symbol.outlineWidth = penPtr->traceWidth = 1;
1612 penPtr->symbol.type = SYMBOL_CIRCLE;
1613 penPtr->valueShow = SHOW_NONE;
1614 }
1615
1616 Pen *
1617 Blt_LinePen(penName)
1618 char *penName;
1619 {
1620 LinePen *penPtr;
1621
1622 penPtr = Blt_Calloc(1, sizeof(LinePen));
1623 assert(penPtr);
1624 InitPen(penPtr);
1625 penPtr->name = Blt_Strdup(penName);
1626 if (strcmp(penName, "activeLine") == 0) {
1627 penPtr->flags = ACTIVE_PEN;
1628 }
1629 return (Pen *)penPtr;
1630 }
1631
1632 /*
1633 * ----------------------------------------------------------------------
1634 *
1635 * In this section, the routines deal with building and filling
1636 * the element's data structures with transformed screen
1637 * coordinates. They are triggered from TranformLine which is
1638 * called whenever the data or coordinates axes have changed and
1639 * new screen coordinates need to be calculated.
1640 *
1641 * ----------------------------------------------------------------------
1642 */
1643
1644 /*
1645 *----------------------------------------------------------------------
1646 *
1647 * ScaleSymbol --
1648 *
1649 * Returns the scaled size for the line element. Scaling depends
1650 * upon when the base line ranges for the element were set and
1651 * the current range of the graph.
1652 *
1653 * Results:
1654 * The new size of the symbol, after considering how much the
1655 * graph has been scaled, is returned.
1656 *
1657 *----------------------------------------------------------------------
1658 */
1659 static int
1660 ScaleSymbol(elemPtr, normalSize)
1661 Element *elemPtr;
1662 int normalSize;
1663 {
1664 int maxSize;
1665 double scale;
1666 int newSize;
1667
1668 scale = 1.0;
1669 if (elemPtr->scaleSymbols) {
1670 double xRange, yRange;
1671
1672 xRange = (elemPtr->axes.x->max - elemPtr->axes.x->min);
1673 yRange = (elemPtr->axes.y->max - elemPtr->axes.y->min);
1674 if (elemPtr->flags & SCALE_SYMBOL) {
1675 /* Save the ranges as a baseline for future scaling. */
1676 elemPtr->xRange = xRange;
1677 elemPtr->yRange = yRange;
1678 elemPtr->flags &= ~SCALE_SYMBOL;
1679 } else {
1680 double xScale, yScale;
1681
1682 /* Scale the symbol by the smallest change in the X or Y axes */
1683 xScale = elemPtr->xRange / xRange;
1684 yScale = elemPtr->yRange / yRange;
1685 scale = MIN(xScale, yScale);
1686 }
1687 }
1688 newSize = Round(normalSize * scale);
1689
1690 /*
1691 * Don't let the size of symbols go unbounded. Both X and Win32
1692 * drawing routines assume coordinates to be a signed short int.
1693 */
1694 maxSize = (int)MIN(elemPtr->graphPtr->hRange, elemPtr->graphPtr->vRange);
1695 if (newSize > maxSize) {
1696 newSize = maxSize;
1697 }
1698
1699 /* Make the symbol size odd so that its center is a single pixel. */
1700 newSize |= 0x01;
1701 return newSize;
1702 }
1703
1704 /*
1705 *----------------------------------------------------------------------
1706 *
1707 * GetScreenPoints --
1708 *
1709 * Generates a coordinate array of transformed screen coordinates
1710 * from the data points.
1711 *
1712 * Results:
1713 * The transformed screen coordinates are returned.
1714 *
1715 * Side effects:
1716 * Memory is allocated for the coordinate array.
1717 *
1718 *----------------------------------------------------------------------
1719 */
1720 static void
1721 GetScreenPoints(graphPtr, linePtr, mapPtr)
1722 Graph *graphPtr;
1723 Line *linePtr;
1724 MapInfo *mapPtr;
1725 {
1726 double *x, *y;
1727 register int i, n;
1728 register int count;
1729 register Point2D *screenPts;
1730 register int *indices;
1731
1732 n = NumberOfPoints(linePtr);
1733 x = linePtr->x.valueArr;
1734 y = linePtr->y.valueArr;
1735 screenPts = Blt_Malloc(sizeof(Point2D) * n);
1736 assert(screenPts);
1737 indices = Blt_Malloc(sizeof(int) * n);
1738 assert(indices);
1739
1740 count = 0; /* Count the valid screen coordinates */
1741 if (graphPtr->inverted) {
1742 for (i = 0; i < n; i++) {
1743 if ((FINITE(x[i])) && (FINITE(y[i]))) {
1744 screenPts[count].x = Blt_HMap(graphPtr, linePtr->axes.y, y[i]);
1745 screenPts[count].y = Blt_VMap(graphPtr, linePtr->axes.x, x[i]);
1746 indices[count] = i;
1747 count++;
1748 }
1749 }
1750 } else {
1751 for (i = 0; i < n; i++) {
1752 if ((FINITE(x[i])) && (FINITE(y[i]))) {
1753 screenPts[count].x = Blt_HMap(graphPtr, linePtr->axes.x, x[i]);
1754 screenPts[count].y = Blt_VMap(graphPtr, linePtr->axes.y, y[i]);
1755 indices[count] = i;
1756 count++;
1757 }
1758 }
1759 }
1760 mapPtr->screenPts = screenPts;
1761 mapPtr->nScreenPts = count;
1762 mapPtr->indices = indices;
1763 }
1764
1765 /*
1766 *----------------------------------------------------------------------
1767 *
1768 * ReducePoints --
1769 *
1770 * Generates a coordinate array of transformed screen coordinates
1771 * from the data points.
1772 *
1773 * Results:
1774 * The transformed screen coordinates are returned.
1775 *
1776 * Side effects:
1777 * Memory is allocated for the coordinate array.
1778 *
1779 *----------------------------------------------------------------------
1780 */
1781 static void
1782 ReducePoints(mapPtr, tolerance)
1783 MapInfo *mapPtr;
1784 double tolerance;
1785 {
1786 register int i, k, n;
1787 Point2D *screenPts;
1788 int *indices, *simple;
1789
1790 simple = Blt_Malloc(sizeof(int) * mapPtr->nScreenPts);
1791 indices = Blt_Malloc(sizeof(int) * mapPtr->nScreenPts);
1792 screenPts = Blt_Malloc(sizeof(Point2D) * mapPtr->nScreenPts);
1793 n = Blt_SimplifyLine(mapPtr->screenPts, 0, mapPtr->nScreenPts - 1,
1794 tolerance, simple);
1795 for (i = 0; i < n; i++) {
1796 k = simple[i];
1797 screenPts[i] = mapPtr->screenPts[k];
1798 indices[i] = mapPtr->indices[k];
1799 }
1800 #ifdef notdef
1801 if (n < mapPtr->nScreenPts) {
1802 fprintf(stderr, "reduced from %d to %d\n", mapPtr->nScreenPts, n);
1803 }
1804 #endif
1805 Blt_Free(mapPtr->screenPts);
1806 Blt_Free(mapPtr->indices);
1807 Blt_Free(simple);
1808 mapPtr->screenPts = screenPts;
1809 mapPtr->indices = indices;
1810 mapPtr->nScreenPts = n;
1811 }
1812
1813 /*
1814 *----------------------------------------------------------------------
1815 *
1816 * GenerateSteps --
1817 *
1818 * Resets the coordinate and pen index arrays adding new points
1819 * for step-and-hold type smoothing.
1820 *
1821 * Results:
1822 * None.
1823 *
1824 * Side Effects:
1825 * The temporary arrays for screen coordinates and pen indices
1826 * are updated.
1827 *
1828 *----------------------------------------------------------------------
1829 */
1830 static void
1831 GenerateSteps(mapPtr)
1832 MapInfo *mapPtr;
1833 {
1834 int newSize;
1835 register int i, count;
1836 Point2D *screenPts;
1837 int *indices;
1838
1839 newSize = ((mapPtr->nScreenPts - 1) * 2) + 1;
1840 screenPts = Blt_Malloc(newSize * sizeof(Point2D));
1841 assert(screenPts);
1842 indices = Blt_Malloc(sizeof(int) * newSize);
1843 assert(indices);
1844
1845 screenPts[0] = mapPtr->screenPts[0];
1846 indices[0] = 0;
1847
1848 count = 1;
1849 for (i = 1; i < mapPtr->nScreenPts; i++) {
1850 screenPts[count + 1] = mapPtr->screenPts[i];
1851
1852 /* Hold last y-coordinate, use new x-coordinate */
1853 screenPts[count].x = screenPts[count + 1].x;
1854 screenPts[count].y = screenPts[count - 1].y;
1855
1856 /* Use the same style for both the hold and the step points */
1857 indices[count] = indices[count + 1] = mapPtr->indices[i];
1858 count += 2;
1859 }
1860 Blt_Free(mapPtr->screenPts);
1861 Blt_Free(mapPtr->indices);
1862 mapPtr->indices = indices;
1863 mapPtr->screenPts = screenPts;
1864 mapPtr->nScreenPts = newSize;
1865 }
1866
1867 /*
1868 *----------------------------------------------------------------------
1869 *
1870 * GenerateSpline --
1871 *
1872 * Computes a spline based upon the data points, returning a new
1873 * (larger) coordinate array or points.
1874 *
1875 * Results:
1876 * None.
1877 *
1878 * Side Effects:
1879 * The temporary arrays for screen coordinates and data indices
1880 * are updated based upon spline.
1881 *
1882 * FIXME: Can't interpolate knots along the Y-axis. Need to break
1883 * up point array into interchangable X and Y vectors earlier.
1884 * Pass extents (left/right or top/bottom) as parameters.
1885 *
1886 *----------------------------------------------------------------------
1887 */
1888 static void
1889 GenerateSpline(graphPtr, linePtr, mapPtr)
1890 Graph *graphPtr;
1891 Line *linePtr;
1892 MapInfo *mapPtr;
1893 {
1894 int extra;
1895 register int i, j, count;
1896 Point2D *origPts, *intpPts;
1897 int *indices;
1898 int nIntpPts, nOrigPts;
1899 int result;
1900 int x;
1901
1902 nOrigPts = mapPtr->nScreenPts;
1903 origPts = mapPtr->screenPts;
1904 assert(mapPtr->nScreenPts > 0);
1905 for (i = 0, j = 1; j < nOrigPts; i++, j++) {
1906 if (origPts[j].x <= origPts[i].x) {
1907 return; /* Points are not monotonically increasing */
1908 }
1909 }
1910 if (((origPts[0].x > (double)graphPtr->right)) ||
1911 ((origPts[mapPtr->nScreenPts - 1].x < (double)graphPtr->left))) {
1912 return; /* All points are clipped */
1913 }
1914 /*
1915 * The spline is computed in screen coordinates instead of data
1916 * points so that we can select the abscissas of the interpolated
1917 * points from each pixel horizontally across the plotting area.
1918 */
1919 extra = (graphPtr->right - graphPtr->left) + 1;
1920 if (extra < 1) {
1921 return;
1922 }
1923 nIntpPts = nOrigPts + extra + 1;
1924 intpPts = Blt_Malloc(nIntpPts * sizeof(Point2D));
1925 assert(intpPts);
1926
1927 indices = Blt_Malloc(sizeof(int) * nIntpPts);
1928 assert(indices);
1929
1930 /* Populate the x2 array with both the original X-coordinates and
1931 * extra X-coordinates for each horizontal pixel that the line
1932 * segment contains. */
1933 count = 0;
1934 for (i = 0, j = 1; j < nOrigPts; i++, j++) {
1935
1936 /* Add the original x-coordinate */
1937 intpPts[count].x = origPts[i].x;
1938
1939 /* Include the starting offset of the point in the offset array */
1940 indices[count] = mapPtr->indices[i];
1941 count++;
1942
1943 /* Is any part of the interval (line segment) in the plotting
1944 * area? */
1945 if ((origPts[j].x >= (double)graphPtr->left) ||
1946 (origPts[i].x <= (double)graphPtr->right)) {
1947 int last;
1948
1949 x = (int)(origPts[i].x + 1.0);
1950
1951 /*
1952 * Since the line segment may be partially clipped on the
1953 * left or right side, the points to interpolate are
1954 * always interior to the plotting area.
1955 *
1956 * left right
1957 * x1----|--------------------------|---x2
1958 *
1959 * Pick the max of the starting X-coordinate and the
1960 * left edge and the min of the last X-coordinate and
1961 * the right edge.
1962 */
1963 x = MAX(x, graphPtr->left);
1964 last = (int)MIN(origPts[j].x, graphPtr->right);
1965
1966 /* Add the extra x-coordinates to the interval. */
1967 while (x < last) {
1968 indices[count] = mapPtr->indices[i];
1969 intpPts[count++].x = (double)x;
1970 x++;
1971 }
1972 }
1973 }
1974 nIntpPts = count;
1975 result = FALSE;
1976 if (linePtr->smooth == PEN_SMOOTH_NATURAL) {
1977 result = Blt_NaturalSpline(origPts, nOrigPts, intpPts, nIntpPts);
1978 } else if (linePtr->smooth == PEN_SMOOTH_QUADRATIC) {
1979 result = Blt_QuadraticSpline(origPts, nOrigPts, intpPts, nIntpPts);
1980 }
1981 if (!result) {
1982 /* The spline interpolation failed. We'll fallback to the
1983 * current coordinates and do no smoothing (standard line
1984 * segments). */
1985 linePtr->smooth = PEN_SMOOTH_NONE;
1986 Blt_Free(intpPts);
1987 Blt_Free(indices);
1988 } else {
1989 Blt_Free(mapPtr->screenPts);
1990 Blt_Free(mapPtr->indices);
1991 mapPtr->indices = indices;
1992 mapPtr->screenPts = intpPts;
1993 mapPtr->nScreenPts = nIntpPts;
1994 }
1995 }
1996
1997
1998 /*
1999 *----------------------------------------------------------------------
2000 *
2001 * GenerateParametricSpline --
2002 *
2003 * Computes a spline based upon the data points, returning a new
2004 * (larger) coordinate array or points.
2005 *
2006 * Results:
2007 * None.
2008 *
2009 * Side Effects:
2010 * The temporary arrays for screen coordinates and data indices
2011 * are updated based upon spline.
2012 *
2013 * FIXME: Can't interpolate knots along the Y-axis. Need to break
2014 * up point array into interchangable X and Y vectors earlier.
2015 * Pass extents (left/right or top/bottom) as parameters.
2016 *
2017 *----------------------------------------------------------------------
2018 */
2019 static void
2020 GenerateParametricSpline(graphPtr, linePtr, mapPtr)
2021 Graph *graphPtr;
2022 Line *linePtr;
2023 MapInfo *mapPtr;
2024 {
2025 Extents2D exts;
2026 Point2D *origPts, *intpPts;
2027 Point2D p, q;
2028 double dist;
2029 int *indices;
2030 int nIntpPts, nOrigPts;
2031 int result;
2032 register int i, j, count;
2033
2034 nOrigPts = mapPtr->nScreenPts;
2035 origPts = mapPtr->screenPts;
2036 assert(mapPtr->nScreenPts > 0);
2037
2038 Blt_GraphExtents(graphPtr, &exts);
2039
2040 /*
2041 * Populate the x2 array with both the original X-coordinates and
2042 * extra X-coordinates for each horizontal pixel that the line
2043 * segment contains.
2044 */
2045 count = 1;
2046 for (i = 0, j = 1; j < nOrigPts; i++, j++) {
2047 p = origPts[i];
2048 q = origPts[j];
2049 count++;
2050 if (Blt_LineRectClip(&exts, &p, &q)) {
2051 count += (int)(hypot(q.x - p.x, q.y - p.y) * 0.5);
2052 }
2053 }
2054 nIntpPts = count;
2055 intpPts = Blt_Malloc(nIntpPts * sizeof(Point2D));
2056 assert(intpPts);
2057
2058 indices = Blt_Malloc(sizeof(int) * nIntpPts);
2059 assert(indices);
2060
2061 /*
2062 * FIXME: This is just plain wrong. The spline should be computed
2063 * and evaluated in separate steps. This will mean breaking
2064 * up this routine since the catrom coefficients can be
2065 * independently computed for original data point. This
2066 * also handles the problem of allocating enough points
2067 * since evaluation is independent of the number of points
2068 * to be evalualted. The interpolated
2069 * line segments should be clipped, not the original segments.
2070 */
2071 count = 0;
2072 for (i = 0, j = 1; j < nOrigPts; i++, j++) {
2073 p = origPts[i];
2074 q = origPts[j];
2075
2076 dist = hypot(q.x - p.x, q.y - p.y);
2077 /* Add the original x-coordinate */
2078 intpPts[count].x = (double)i;
2079 intpPts[count].y = 0.0;
2080
2081 /* Include the starting offset of the point in the offset array */
2082 indices[count] = mapPtr->indices[i];
2083 count++;
2084
2085 /* Is any part of the interval (line segment) in the plotting
2086 * area? */
2087
2088 if (Blt_LineRectClip(&exts, &p, &q)) {
2089 double distP, distQ;
2090
2091 distP = hypot(p.x - origPts[i].x, p.y - origPts[i].y);
2092 distQ = hypot(q.x - origPts[i].x, q.y - origPts[i].y);
2093 distP += 2.0;
2094 while(distP <= distQ) {
2095 /* Point is indicated by its interval and parameter t. */
2096 intpPts[count].x = (double)i;
2097 intpPts[count].y = distP / dist;
2098 indices[count] = mapPtr->indices[i];
2099 count++;
2100 distP += 2.0;
2101 }
2102 }
2103 }
2104 intpPts[count].x = (double)i;
2105 intpPts[count].y = 0.0;
2106 indices[count] = mapPtr->indices[i];
2107 count++;
2108 nIntpPts = count;
2109 result = FALSE;
2110 if (linePtr->smooth == PEN_SMOOTH_NATURAL) {
2111 result = Blt_NaturalParametricSpline(origPts, nOrigPts, &exts, FALSE,
2112 intpPts, nIntpPts);
2113 } else if (linePtr->smooth == PEN_SMOOTH_CATROM) {
2114 result = Blt_CatromParametricSpline(origPts, nOrigPts, intpPts,
2115 nIntpPts);
2116 }
2117 if (!result) {
2118 /* The spline interpolation failed. We'll fallback to the
2119 * current coordinates and do no smoothing (standard line
2120 * segments). */
2121 linePtr->smooth = PEN_SMOOTH_NONE;
2122 Blt_Free(intpPts);
2123 Blt_Free(indices);
2124 } else {
2125 Blt_Free(mapPtr->screenPts);
2126 Blt_Free(mapPtr->indices);
2127 mapPtr->indices = indices;
2128 mapPtr->screenPts = intpPts;
2129 mapPtr->nScreenPts = nIntpPts;
2130 }
2131 }
2132
2133
2134 /*
2135 *----------------------------------------------------------------------
2136 *
2137 * MapSymbols --
2138 *
2139 * Creates two arrays of points and pen indices, filled with
2140 * the screen coordinates of the visible
2141 *
2142 * Results:
2143 * None.
2144 *
2145 * Side effects:
2146 * Memory is freed and allocated for the index array.
2147 *
2148 *----------------------------------------------------------------------
2149 */
2150 static void
2151 MapSymbols(graphPtr, linePtr, mapPtr)
2152 Graph *graphPtr;
2153 Line *linePtr;
2154 MapInfo *mapPtr;
2155 {
2156 Extents2D exts;
2157 Point2D *symbolPts;
2158 int *indices;
2159 register int i, count;
2160
2161 symbolPts = Blt_Malloc(sizeof(Point2D) * mapPtr->nScreenPts);
2162 assert(symbolPts);
2163
2164 indices = Blt_Malloc(sizeof(int) * mapPtr->nScreenPts);
2165 assert(indices);
2166
2167 Blt_GraphExtents(graphPtr, &exts);
2168 count = 0; /* Count the number of visible points */
2169
2170 for (i = 0; i < mapPtr->nScreenPts; i++) {
2171 if (PointInRegion(&exts, mapPtr->screenPts[i].x,
2172 mapPtr->screenPts[i].y)) {
2173 symbolPts[count].x = mapPtr->screenPts[i].x;
2174 symbolPts[count].y = mapPtr->screenPts[i].y;
2175 indices[count] = mapPtr->indices[i];
2176 count++;
2177 }
2178 }
2179 linePtr->symbolPts = symbolPts;
2180 linePtr->nSymbolPts = count;
2181 linePtr->symbolToData = indices;
2182 }
2183
2184 /*
2185 *----------------------------------------------------------------------
2186 *
2187 * MapActiveSymbols --
2188 *
2189 * Creates an array of points of the active graph coordinates.
2190 *
2191 * Results:
2192 * None.
2193 *
2194 * Side effects:
2195 * Memory is freed and allocated for the active point array.
2196 *
2197 *----------------------------------------------------------------------
2198 */
2199 static void
2200 MapActiveSymbols(graphPtr, linePtr)
2201 Graph *graphPtr;
2202 Line *linePtr;
2203 {
2204 Extents2D exts;
2205 double x, y;
2206 int count;
2207 Point2D *activePts;
2208 register int i;
2209 int pointIndex;
2210 int nPoints;
2211 int *activeToData;
2212
2213 if (linePtr->activePts != NULL) {
2214 Blt_Free(linePtr->activePts);
2215 linePtr->activePts = NULL;
2216 }
2217 if (linePtr->activeToData != NULL) {
2218 Blt_Free(linePtr->activeToData);
2219 linePtr->activeToData = NULL;
2220 }
2221 Blt_GraphExtents(graphPtr, &exts);
2222 activePts = Blt_Malloc(sizeof(Point2D) * linePtr->nActiveIndices);
2223 assert(activePts);
2224 activeToData = Blt_Malloc(sizeof(int) * linePtr->nActiveIndices);
2225 nPoints = NumberOfPoints(linePtr);
2226 count = 0; /* Count the visible active points */
2227 for (i = 0; i < linePtr->nActiveIndices; i++) {
2228 pointIndex = linePtr->activeIndices[i];
2229 if (pointIndex >= nPoints) {
2230 continue; /* Index not available */
2231 }
2232 x = linePtr->x.valueArr[pointIndex];
2233 y = linePtr->y.valueArr[pointIndex];
2234 activePts[count] = Blt_Map2D(graphPtr, x, y, &(linePtr->axes));
2235 activeToData[count] = pointIndex;
2236 if (PointInRegion(&exts, activePts[count].x, activePts[count].y)) {
2237 count++;
2238 }
2239 }
2240 if (count > 0) {
2241 linePtr->activePts = activePts;
2242 linePtr->activeToData = activeToData;
2243 } else {
2244 /* No active points were visible. */
2245 Blt_Free(activePts);
2246 Blt_Free(activeToData);
2247 }
2248 linePtr->nActivePts = count;
2249 linePtr->flags &= ~ACTIVE_PENDING;
2250 }
2251
2252 /*
2253 *----------------------------------------------------------------------
2254 *
2255 * MapStrip --
2256 *
2257 * Creates an array of line segments of the graph coordinates.
2258 *
2259 * Results:
2260 * None.
2261 *
2262 * Side effects:
2263 * Memory is allocated for the line segment array.
2264 *
2265 *----------------------------------------------------------------------
2266 */
2267 static void
2268 MapStrip(graphPtr, linePtr, mapPtr)
2269 Graph *graphPtr;
2270 Line *linePtr;
2271 MapInfo *mapPtr;
2272 {
2273 Extents2D exts;
2274 Segment2D *strips;
2275 int *indices, *indexPtr;
2276 register Point2D *endPtr, *pointPtr;
2277 register Segment2D *segPtr;
2278 register int count;
2279
2280 indices = Blt_Malloc(sizeof(int) * mapPtr->nScreenPts);
2281 assert(indices);
2282
2283 /*
2284 * Create array to hold points for line segments (not polyline
2285 * coordinates). So allocate twice the number of points.
2286 */
2287 segPtr = strips = Blt_Malloc(mapPtr->nScreenPts * sizeof(Segment2D));
2288 assert(strips);
2289
2290 Blt_GraphExtents(graphPtr, &exts);
2291 count = 0; /* Count the number of segments. */
2292 indexPtr = mapPtr->indices;
2293 for (pointPtr = mapPtr->screenPts,
2294 endPtr = mapPtr->screenPts + (mapPtr->nScreenPts - 1);
2295 pointPtr < endPtr; pointPtr++, indexPtr++) {
2296 segPtr->p = pointPtr[0];
2297 segPtr->q = pointPtr[1];
2298 if (Blt_LineRectClip(&exts, &segPtr->p, &segPtr->q)) {
2299 segPtr++;
2300 indices[count] = *indexPtr;
2301 count++;
2302 }
2303 }
2304 linePtr->stripToData = indices;
2305 linePtr->nStrips = count;
2306 linePtr->strips = strips;
2307 }
2308
2309 /*
2310 *----------------------------------------------------------------------
2311 *
2312 * MergePens --
2313 *
2314 * Reorders the both arrays of points and segments to merge pens.
2315 *
2316 * Results:
2317 * None.
2318 *
2319 * Side effects:
2320 * The old arrays are freed and new ones allocated containing
2321 * the reordered points and segments.
2322 *
2323 *----------------------------------------------------------------------
2324 */
2325 static void
2326 MergePens(linePtr, dataToStyle)
2327 Line *linePtr;
2328 PenStyle **dataToStyle;
2329 {
2330 LinePenStyle *stylePtr;
2331 register int i;
2332 Blt_ChainLink *linkPtr;
2333
2334 if (Blt_ChainGetLength(linePtr->palette) < 2) {
2335 linkPtr = Blt_ChainFirstLink(linePtr->palette);
2336 stylePtr = Blt_ChainGetValue(linkPtr);
2337 stylePtr->nStrips = linePtr->nStrips;
2338 stylePtr->strips = linePtr->strips;
2339 stylePtr->nSymbolPts = linePtr->nSymbolPts;
2340 stylePtr->symbolPts = linePtr->symbolPts;
2341 stylePtr->xErrorBarCnt = linePtr->xErrorBarCnt;
2342 stylePtr->yErrorBarCnt = linePtr->yErrorBarCnt;
2343 stylePtr->xErrorBars = linePtr->xErrorBars;
2344 stylePtr->yErrorBars = linePtr->yErrorBars;
2345 stylePtr->errorBarCapWidth = linePtr->errorBarCapWidth;
2346 return;
2347 }
2348
2349 /* We have more than one style. Group line segments and points of
2350 * like pen styles. */
2351
2352 if (linePtr->nStrips > 0) {
2353 Segment2D *strips;
2354 int *stripToData;
2355 register Segment2D *segPtr;
2356 register int *indexPtr;
2357 int dataIndex;
2358
2359 strips = Blt_Malloc(linePtr->nStrips * sizeof(Segment2D));
2360 stripToData = Blt_Malloc(linePtr->nStrips * sizeof(int));
2361 assert(strips && stripToData);
2362 segPtr = strips, indexPtr = stripToData;
2363 for (linkPtr = Blt_ChainFirstLink(linePtr->palette); linkPtr != NULL;
2364 linkPtr = Blt_ChainNextLink(linkPtr)) {
2365 stylePtr = Blt_ChainGetValue(linkPtr);
2366 stylePtr->strips = segPtr;
2367 for (i = 0; i < linePtr->nStrips; i++) {
2368 dataIndex = linePtr->stripToData[i];
2369 if (dataToStyle[dataIndex] == (PenStyle *)stylePtr) {
2370 *segPtr++ = linePtr->strips[i];
2371 *indexPtr++ = dataIndex;
2372 }
2373 }
2374 stylePtr->nStrips = segPtr - stylePtr->strips;
2375 }
2376 Blt_Free(linePtr->strips);
2377 linePtr->strips = strips;
2378 Blt_Free(linePtr->stripToData);
2379 linePtr->stripToData = stripToData;
2380 }
2381 if (linePtr->nSymbolPts > 0) {
2382 int *indexPtr;
2383 register Point2D *symbolPts, *pointPtr;
2384 register int *symbolToData;
2385 int dataIndex;
2386
2387 symbolPts = Blt_Malloc(linePtr->nSymbolPts * sizeof(Point2D));
2388 symbolToData = Blt_Malloc(linePtr->nSymbolPts * sizeof(int));
2389 assert(symbolPts && symbolToData);
2390 pointPtr = symbolPts, indexPtr = symbolToData;
2391 for (linkPtr = Blt_ChainFirstLink(linePtr->palette); linkPtr != NULL;
2392 linkPtr = Blt_ChainNextLink(linkPtr)) {
2393 stylePtr = Blt_ChainGetValue(linkPtr);
2394 stylePtr->symbolPts = pointPtr;
2395 for (i = 0; i < linePtr->nSymbolPts; i++) {
2396 dataIndex = linePtr->symbolToData[i];
2397 if (dataToStyle[dataIndex] == (PenStyle *)stylePtr) {
2398 *pointPtr++ = linePtr->symbolPts[i];
2399 *indexPtr++ = dataIndex;
2400 }
2401 }
2402 stylePtr->nSymbolPts = pointPtr - stylePtr->symbolPts;
2403 }
2404 Blt_Free(linePtr->symbolPts);
2405 linePtr->symbolPts = symbolPts;
2406 Blt_Free(linePtr->symbolToData);
2407 linePtr->symbolToData = symbolToData;
2408 }
2409 if (linePtr->xErrorBarCnt > 0) {
2410 Segment2D *xErrorBars, *segPtr;
2411 int *xErrorToData, *indexPtr;
2412 int dataIndex;
2413
2414 xErrorBars = Blt_Malloc(linePtr->xErrorBarCnt * sizeof(Segment2D));
2415 xErrorToData = Blt_Malloc(linePtr->xErrorBarCnt * sizeof(int));
2416 assert(xErrorBars);
2417 segPtr = xErrorBars, indexPtr = xErrorToData;
2418 for (linkPtr = Blt_ChainFirstLink(linePtr->palette);
2419 linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
2420 stylePtr = Blt_ChainGetValue(linkPtr);
2421 stylePtr->xErrorBars = segPtr;
2422 for (i = 0; i < linePtr->xErrorBarCnt; i++) {
2423 dataIndex = linePtr->xErrorToData[i];
2424 if (dataToStyle[dataIndex] == (PenStyle *)stylePtr) {
2425 *segPtr++ = linePtr->xErrorBars[i];
2426 *indexPtr++ = dataIndex;
2427 }
2428 }
2429 stylePtr->xErrorBarCnt = segPtr - stylePtr->xErrorBars;
2430 }
2431 Blt_Free(linePtr->xErrorBars);
2432 linePtr->xErrorBars = xErrorBars;
2433 Blt_Free(linePtr->xErrorToData);
2434 linePtr->xErrorToData = xErrorToData;
2435 }
2436 if (linePtr->yErrorBarCnt > 0) {
2437 Segment2D *errorBars, *segPtr;
2438 int *errorToData, *indexPtr;
2439 int dataIndex;
2440
2441 errorBars = Blt_Malloc(linePtr->yErrorBarCnt * sizeof(Segment2D));
2442 errorToData = Blt_Malloc(linePtr->yErrorBarCnt * sizeof(int));
2443 assert(errorBars);
2444 segPtr = errorBars, indexPtr = errorToData;
2445 for (linkPtr = Blt_ChainFirstLink(linePtr->palette);
2446 linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
2447 stylePtr = Blt_ChainGetValue(linkPtr);
2448 stylePtr->yErrorBars = segPtr;
2449 for (i = 0; i < linePtr->yErrorBarCnt; i++) {
2450 dataIndex = linePtr->yErrorToData[i];
2451 if (dataToStyle[dataIndex] == (PenStyle *)stylePtr) {
2452 *segPtr++ = linePtr->yErrorBars[i];
2453 *indexPtr++ = dataIndex;
2454 }
2455 }
2456 stylePtr->yErrorBarCnt = segPtr - stylePtr->yErrorBars;
2457 }
2458 Blt_Free(linePtr->yErrorBars);
2459 linePtr->yErrorBars = errorBars;
2460 Blt_Free(linePtr->yErrorToData);
2461 linePtr->yErrorToData = errorToData;
2462 }
2463 }
2464
2465 #define CLIP_TOP (1<<0)
2466 #define CLIP_BOTTOM (1<<1)
2467 #define CLIP_RIGHT (1<<2)
2468 #define CLIP_LEFT (1<<3)
2469
2470 INLINE static int
2471 OutCode(extsPtr, p)
2472 Extents2D *extsPtr;
2473 Point2D *p;
2474 {
2475 int code;
2476
2477 code = 0;
2478 if (p->x > extsPtr->right) {
2479 code |= CLIP_RIGHT;
2480 } else if (p->x < extsPtr->left) {
2481 code |= CLIP_LEFT;
2482 }
2483 if (p->y > extsPtr->bottom) {
2484 code |= CLIP_BOTTOM;
2485 } else if (p->y < extsPtr->top) {
2486 code |= CLIP_TOP;
2487 }
2488 return code;
2489 }
2490
2491 static int
2492 ClipSegment(extsPtr, code1, code2, p, q)
2493 Extents2D *extsPtr;
2494 register int code1, code2;
2495 register Point2D *p, *q;
2496 {
2497 int inside, outside;
2498
2499 inside = ((code1 | code2) == 0);
2500 outside = ((code1 & code2) != 0);
2501
2502 /*
2503 * In the worst case, we'll clip the line segment against each of
2504 * the four sides of the bounding rectangle.
2505 */
2506 while ((!outside) && (!inside)) {
2507 if (code1 == 0) {
2508 Point2D *tmp;
2509 int code;
2510
2511 /* Swap pointers and out codes */
2512 tmp = p, p = q, q = tmp;
2513 code = code1, code1 = code2, code2 = code;
2514 }
2515 if (code1 & CLIP_LEFT) {
2516 p->y += (q->y - p->y) *
2517 (extsPtr->left - p->x) / (q->x - p->x);
2518 p->x = extsPtr->left;
2519 } else if (code1 & CLIP_RIGHT) {
2520 p->y += (q->y - p->y) *
2521 (extsPtr->right - p->x) / (q->x - p->x);
2522 p->x = extsPtr->right;
2523 } else if (code1 & CLIP_BOTTOM) {
2524 p->x += (q->x - p->x) *
2525 (extsPtr->bottom - p->y) / (q->y - p->y);
2526 p->y = extsPtr->bottom;
2527 } else if (code1 & CLIP_TOP) {
2528 p->x += (q->x - p->x) *
2529 (extsPtr->top - p->y) / (q->y - p->y);
2530 p->y = extsPtr->top;
2531 }
2532 code1 = OutCode(extsPtr, p);
2533
2534 inside = ((code1 | code2) == 0);
2535 outside = ((code1 & code2) != 0);
2536 }
2537 return (!inside);
2538 }
2539
2540 /*
2541 *----------------------------------------------------------------------
2542 *
2543 * SaveTrace --
2544 *
2545 * Creates a new trace and inserts it into the line's
2546 * list of traces.
2547 *
2548 * Results:
2549 * None.
2550 *
2551 *----------------------------------------------------------------------
2552 */
2553 static void
2554 SaveTrace(linePtr, start, length, mapPtr)
2555 Line *linePtr;
2556 int start; /* Starting index of the trace in data point
2557 * array. Used to figure out closest point */
2558 int length; /* Number of points forming the trace */
2559 MapInfo *mapPtr;
2560 {
2561 Trace *tracePtr;
2562 Point2D *screenPts;
2563 int *indices;
2564 register int i, j;
2565
2566 tracePtr = Blt_Malloc(sizeof(Trace));
2567 assert(tracePtr);
2568 screenPts = Blt_Malloc(sizeof(Point2D) * length);
2569 assert(screenPts);
2570 indices = Blt_Malloc(sizeof(int) * length);
2571 assert(indices);
2572
2573 /* Copy the screen coordinates of the trace into the point array */
2574
2575 if (mapPtr->indices != NULL) {
2576 for (i = 0, j = start; i < length; i++, j++) {
2577 screenPts[i].x = mapPtr->screenPts[j].x;
2578 screenPts[i].y = mapPtr->screenPts[j].y;
2579 indices[i] = mapPtr->indices[j];
2580 }
2581 } else {
2582 for (i = 0, j = start; i < length; i++, j++) {
2583 screenPts[i].x = mapPtr->screenPts[j].x;
2584 screenPts[i].y = mapPtr->screenPts[j].y;
2585 indices[i] = j;
2586 }
2587 }
2588 tracePtr->nScreenPts = length;
2589 tracePtr->screenPts = screenPts;
2590 tracePtr->symbolToData = indices;
2591 tracePtr->start = start;
2592 if (linePtr->traces == NULL) {
2593 linePtr->traces = Blt_ChainCreate();
2594 }
2595 Blt_ChainAppend(linePtr->traces, tracePtr);
2596 }
2597
2598 /*
2599 *----------------------------------------------------------------------
2600 *
2601 * FreeTraces --
2602 *
2603 * Deletes all the traces for the line.
2604 *
2605 * Results:
2606 * None.
2607 *
2608 *----------------------------------------------------------------------
2609 */
2610 static void
2611 FreeTraces(linePtr)
2612 Line *linePtr;
2613 {
2614 Blt_ChainLink *linkPtr;
2615 Trace *tracePtr;
2616
2617 for (linkPtr = Blt_ChainFirstLink(linePtr->traces); linkPtr != NULL;
2618 linkPtr = Blt_ChainNextLink(linkPtr)) {
2619 tracePtr = Blt_ChainGetValue(linkPtr);
2620 Blt_Free(tracePtr->symbolToData);
2621 Blt_Free(tracePtr->screenPts);
2622 Blt_Free(tracePtr);
2623 }
2624 Blt_ChainDestroy(linePtr->traces);
2625 linePtr->traces = NULL;
2626 }
2627
2628 /*
2629 *----------------------------------------------------------------------
2630 *
2631 * MapTraces --
2632 *
2633 * Creates an array of line segments of the graph coordinates.
2634 *
2635 * Results:
2636 * None.
2637 *
2638 * Side effects:
2639 * Memory is allocated for the line segment array.
2640 *
2641 *----------------------------------------------------------------------
2642 */
2643 static void
2644 MapTraces(graphPtr, linePtr, mapPtr)
2645 Graph *graphPtr;
2646 Line *linePtr;
2647 MapInfo *mapPtr;
2648 {
2649 int start, count;
2650 int code1, code2;
2651 Point2D *p, *q;
2652 Point2D s;
2653 Extents2D exts;
2654 register int i;
2655 int broken, offscreen;
2656
2657 Blt_GraphExtents(graphPtr, &exts);
2658 count = 1;
2659 code1 = OutCode(&exts, mapPtr->screenPts);
2660 p = mapPtr->screenPts;
2661 q = p + 1;
2662 for (i = 1; i < mapPtr->nScreenPts; i++, p++, q++) {
2663 code2 = OutCode(&exts, q);
2664 if (code2 != 0) {
2665 /* Save the coordinates of the last point, before clipping */
2666 s = *q;
2667 }
2668 broken = BROKEN_TRACE(linePtr->penDir, p->x, q->x);
2669 offscreen = ClipSegment(&exts, code1, code2, p, q);
2670 if (broken || offscreen) {
2671
2672 /*
2673 * The last line segment is either totally clipped by the plotting
2674 * area or the x-direction is wrong, breaking the trace. Either
2675 * way, save information about the last trace (if one exists),
2676 * discarding the current line segment
2677 */
2678
2679 if (count > 1) {
2680 start = i - count;
2681 SaveTrace(linePtr, start, count, mapPtr);
2682 count = 1;
2683 }
2684 } else {
2685 count++; /* Add the point to the trace. */
2686 if (code2 != 0) {
2687
2688 /*
2689 * If the last point is clipped, this means that the trace is
2690 * broken after this point. Restore the original coordinate
2691 * (before clipping) after saving the trace.
2692 */
2693
2694 start = i - (count - 1);
2695 SaveTrace(linePtr, start, count, mapPtr);
2696 mapPtr->screenPts[i] = s;
2697 count = 1;
2698 }
2699 }
2700 code1 = code2;
2701 }
2702 if (count > 1) {
2703 start = i - count;
2704 SaveTrace(linePtr, start, count, mapPtr);
2705 }
2706 }
2707
2708 /*
2709 *----------------------------------------------------------------------
2710 *
2711 * MapFillArea --
2712 *
2713 * Creates an array of points that represent a polygon that fills
2714 * the area under the element.
2715 *
2716 * Results:
2717 * None.
2718 *
2719 * Side effects:
2720 * Memory is allocated for the polygon point array.
2721 *
2722 *----------------------------------------------------------------------
2723 */
2724 static void
2725 MapFillArea(graphPtr, linePtr, mapPtr)
2726 Graph *graphPtr;
2727 Line *linePtr;
2728 MapInfo *mapPtr;
2729 {
2730 Point2D *origPts, *clipPts;
2731 Extents2D exts;
2732 double maxY;
2733 register int i, n;
2734
2735 if (linePtr->fillPts != NULL) {
2736 Blt_Free(linePtr->fillPts);
2737 linePtr->fillPts = NULL;
2738 linePtr->nFillPts = 0;
2739 }
2740 if (mapPtr->nScreenPts < 3) {
2741 return;
2742 }
2743 n = mapPtr->nScreenPts + 3;
2744 Blt_GraphExtents(graphPtr, &exts);
2745
2746 maxY = (double)graphPtr->bottom;
2747 origPts = Blt_Malloc(sizeof(Point2D) * n);
2748 for (i = 0; i < mapPtr->nScreenPts; i++) {
2749 origPts[i].x = mapPtr->screenPts[i].x + 1;
2750 origPts[i].y = mapPtr->screenPts[i].y;
2751 if (origPts[i].y > maxY) {
2752 maxY = origPts[i].y;
2753 }
2754 }
2755 /* Add edges to make (if necessary) the polygon fill to the bottom
2756 * of plotting window */
2757 origPts[i].x = origPts[i - 1].x;
2758 origPts[i].y = maxY;
2759 i++;
2760 origPts[i].x = origPts[0].x;
2761 origPts[i].y = maxY;
2762 i++;
2763 origPts[i] = origPts[0];
2764
2765 clipPts = Blt_Malloc(sizeof(Point2D) * n * 3);
2766 assert(clipPts);
2767 n = Blt_PolyRectClip(&exts, origPts, n - 1, clipPts);
2768
2769 Blt_Free(origPts);
2770 if (n < 3) {
2771 Blt_Free(clipPts);
2772 } else {
2773 linePtr->fillPts = clipPts;
2774 linePtr->nFillPts = n;
2775 }
2776 }
2777
2778 static void
2779 ResetLine(linePtr)
2780 Line *linePtr;
2781 {
2782 FreeTraces(linePtr);
2783 ClearPalette(linePtr->palette);
2784 if (linePtr->symbolPts != NULL) {
2785 Blt_Free(linePtr->symbolPts);
2786 }
2787 if (linePtr->symbolToData != NULL) {
2788 Blt_Free(linePtr->symbolToData);
2789 }
2790 if (linePtr->strips != NULL) {
2791 Blt_Free(linePtr->strips);
2792 }
2793 if (linePtr->stripToData != NULL) {
2794 Blt_Free(linePtr->stripToData);
2795 }
2796 if (linePtr->activePts != NULL) {
2797 Blt_Free(linePtr->activePts);
2798 }
2799 if (linePtr->activeToData != NULL) {
2800 Blt_Free(linePtr->activeToData);
2801 }
2802 if (linePtr->xErrorBars != NULL) {
2803 Blt_Free(linePtr->xErrorBars);
2804 }
2805 if (linePtr->xErrorToData != NULL) {
2806 Blt_Free(linePtr->xErrorToData);
2807 }
2808 if (linePtr->yErrorBars != NULL) {
2809 Blt_Free(linePtr->yErrorBars);
2810 }
2811 if (linePtr->yErrorToData != NULL) {
2812 Blt_Free(linePtr->yErrorToData);
2813 }
2814 linePtr->xErrorBars = linePtr->yErrorBars = linePtr->strips = NULL;
2815 linePtr->symbolPts = linePtr->activePts = NULL;
2816 linePtr->stripToData = linePtr->symbolToData = linePtr->xErrorToData =
2817 linePtr->yErrorToData = linePtr->activeToData = NULL;
2818 linePtr->nActivePts = linePtr->nSymbolPts = linePtr->nStrips =
2819 linePtr->xErrorBarCnt = linePtr->yErrorBarCnt = 0;
2820 }
2821
2822 /*
2823 *----------------------------------------------------------------------
2824 *
2825 * MapLine --
2826 *
2827 * Calculates the actual window coordinates of the line element.
2828 * The window coordinates are saved in an allocated point array.
2829 *
2830 * Results:
2831 * None.
2832 *
2833 * Side effects:
2834 * Memory is (re)allocated for the point array.
2835 *
2836 *----------------------------------------------------------------------
2837 */
2838 static void
2839 MapLine(graphPtr, elemPtr)
2840 Graph *graphPtr; /* Graph widget record */
2841 Element *elemPtr; /* Element component record */
2842 {
2843 Line *linePtr = (Line *)elemPtr;
2844 MapInfo mapInfo;
2845 int size, nPoints;
2846 PenStyle **dataToStyle;
2847 Blt_ChainLink *linkPtr;
2848 LinePenStyle *stylePtr;
2849
2850 ResetLine(linePtr);
2851 nPoints = NumberOfPoints(linePtr);
2852 if (nPoints < 1) {
2853 return; /* No data points */
2854 }
2855 GetScreenPoints(graphPtr, linePtr, &mapInfo);
2856 MapSymbols(graphPtr, linePtr, &mapInfo);
2857
2858 if ((linePtr->flags & ACTIVE_PENDING) && (linePtr->nActiveIndices > 0)) {
2859 MapActiveSymbols(graphPtr, linePtr);
2860 }
2861 /*
2862 * Map connecting line segments if they are to be displayed.
2863 */
2864 if ((nPoints > 1) && ((graphPtr->classUid == bltStripElementUid) ||
2865 (linePtr->builtinPen.traceWidth > 0))) {
2866 linePtr->smooth = linePtr->reqSmooth;
2867
2868 /*
2869 * Do smoothing if necessary. This can extend the coordinate array,
2870 * so both mapInfo.points and mapInfo.nPoints may change.
2871 */
2872
2873 switch (linePtr->smooth) {
2874 case PEN_SMOOTH_STEP:
2875 GenerateSteps(&mapInfo);
2876 break;
2877
2878 case PEN_SMOOTH_NATURAL:
2879 case PEN_SMOOTH_QUADRATIC:
2880 if (mapInfo.nScreenPts < 3) {
2881 /* Can't interpolate with less than three points. */
2882 linePtr->smooth = PEN_SMOOTH_NONE;
2883 } else {
2884 GenerateSpline(graphPtr, linePtr, &mapInfo);
2885 }
2886 break;
2887
2888 case PEN_SMOOTH_CATROM:
2889 if (mapInfo.nScreenPts < 3) {
2890 /* Can't interpolate with less than three points. */
2891 linePtr->smooth = PEN_SMOOTH_NONE;
2892 } else {
2893 GenerateParametricSpline(graphPtr, linePtr, &mapInfo);
2894 }
2895 break;
2896
2897 default:
2898 break;
2899 }
2900 if (linePtr->rTolerance > 0.0) {
2901 ReducePoints(&mapInfo, linePtr->rTolerance);
2902 }
2903 if ((Blt_HasTile(linePtr->fillTile)) || (linePtr->fillStipple != None)) {
2904 MapFillArea(graphPtr, linePtr, &mapInfo);
2905 }
2906 if (graphPtr->classUid == bltStripElementUid) {
2907 MapStrip(graphPtr, linePtr, &mapInfo);
2908 } else {
2909 MapTraces(graphPtr, linePtr, &mapInfo);
2910 }
2911 }
2912 Blt_Free(mapInfo.screenPts);
2913 Blt_Free(mapInfo.indices);
2914
2915 /* Set the symbol size of all the pen styles. */
2916 for (linkPtr = Blt_ChainFirstLink(linePtr->palette); linkPtr != NULL;
2917 linkPtr = Blt_ChainNextLink(linkPtr)) {
2918 stylePtr = Blt_ChainGetValue(linkPtr);
2919 size = ScaleSymbol(elemPtr, stylePtr->penPtr->symbol.size);
2920 stylePtr->symbolSize = size;
2921 stylePtr->errorBarCapWidth = (stylePtr->penPtr->errorBarCapWidth > 0)
2922 ? stylePtr->penPtr->errorBarCapWidth : (int)(size * 0.6666666);
2923 stylePtr->errorBarCapWidth /= 2;
2924 }
2925 dataToStyle = Blt_StyleMap((Element *)linePtr);
2926 if (((linePtr->yHigh.nValues > 0) && (linePtr->yLow.nValues > 0)) ||
2927 ((linePtr->xHigh.nValues > 0) && (linePtr->xLow.nValues > 0)) ||
2928 (linePtr->xError.nValues > 0) || (linePtr->yError.nValues > 0)) {
2929 Blt_MapErrorBars(graphPtr, (Element *)linePtr, dataToStyle);
2930 }
2931 MergePens(linePtr, dataToStyle);
2932 Blt_Free(dataToStyle);
2933 }
2934
2935 static double
2936 DistanceToLine(x, y, p, q, t)
2937 int x, y; /* Sample X-Y coordinate. */
2938 Point2D *p, *q; /* End points of the line segment. */
2939 Point2D *t; /* (out) Point on line segment. */
2940 {
2941 double right, left, top, bottom;
2942
2943 *t = Blt_GetProjection(x, y, p, q);
2944 if (p->x > q->x) {
2945 right = p->x, left = q->x;
2946 } else {
2947 left = p->x, right = q->x;
2948 }
2949 if (p->y > q->y) {
2950 bottom = p->y, top = q->y;
2951 } else {
2952 top = p->y, bottom = q->y;
2953 }
2954 if (t->x > right) {
2955 t->x = right;
2956 } else if (t->x < left) {
2957 t->x = left;
2958 }
2959 if (t->y > bottom) {
2960 t->y = bottom;
2961 } else if (t->y < top) {
2962 t->y = top;
2963 }
2964 return hypot((t->x - x), (t->y - y));
2965 }
2966
2967 static double
2968 DistanceToX(x, y, p, q, t)
2969 int x, y; /* Search X-Y coordinate. */
2970 Point2D *p, *q; /* End points of the line segment. */
2971 Point2D *t; /* (out) Point on line segment. */
2972 {
2973 double dx, dy;
2974 double dist;
2975
2976 if (p->x > q->x) {
2977 if ((x > p->x) || (x < q->x)) {
2978 return DBL_MAX; /* X-coordinate outside line segment. */
2979 }
2980 } else {
2981 if ((x > q->x) || (x < p->x)) {
2982 return DBL_MAX; /* X-coordinate outside line segment. */
2983 }
2984 }
2985 dx = p->x - q->x;
2986 dy = p->y - q->y;
2987 t->x = (double)x;
2988 if (FABS(dx) < DBL_EPSILON) {
2989 double d1, d2;
2990 /* Same X-coordinate indicates a vertical line. Pick the
2991 * closest end point. */
2992 d1 = p->y - y;
2993 d2 = q->y - y;
2994 if (FABS(d1) < FABS(d2)) {
2995 t->y = p->y, dist = d1;
2996 } else {
2997 t->y = q->y, dist = d2;
2998 }
2999 } else if (FABS(dy) < DBL_EPSILON) {
3000 /* Horizontal line. */
3001 t->y = p->y, dist = p->y - y;
3002 } else {
3003 double m, b;
3004
3005 m = dy / dx;
3006 b = p->y - (m * p->x);
3007 t->y = (x * m) + b;
3008 dist = y - t->y;
3009 }
3010 return FABS(dist);
3011 }
3012
3013 static double
3014 DistanceToY(x, y, p, q, t)
3015 int x, y; /* Search X-Y coordinate. */
3016 Point2D *p, *q; /* End points of the line segment. */
3017 Point2D *t; /* (out) Point on line segment. */
3018 {
3019 double dx, dy;
3020 double dist;
3021
3022 if (p->y > q->y) {
3023 if ((y > p->y) || (y < q->y)) {
3024 return DBL_MAX;
3025 }
3026 } else {
3027 if ((y > q->y) || (y < p->y)) {
3028 return DBL_MAX;
3029 }
3030 }
3031 dx = p->x - q->x;
3032 dy = p->y - q->y;
3033 t->y = y;
3034 if (FABS(dy) < DBL_EPSILON) {
3035 double d1, d2;
3036
3037 /* Save Y-coordinate indicates an horizontal line. Pick the
3038 * closest end point. */
3039 d1 = p->x - x;
3040 d2 = q->x - x;
3041 if (FABS(d1) < FABS(d2)) {
3042 t->x = p->x, dist = d1;
3043 } else {
3044 t->x = q->x, dist = d2;
3045 }
3046 } else if (FABS(dx) < DBL_EPSILON) {
3047 /* Vertical line. */
3048 t->x = p->x, dist = p->x - x;
3049 } else {
3050 double m, b;
3051
3052 m = dy / dx;
3053 b = p->y - (m * p->x);
3054 t->x = (y - b) / m;
3055 dist = x - t->x;
3056 }
3057 return FABS(dist);
3058 }
3059
3060 /*
3061 *----------------------------------------------------------------------
3062 *
3063 * ClosestTrace --
3064 *
3065 * Find the line segment closest to the given window coordinate
3066 * in the element.
3067 *
3068 * Results:
3069 * If a new minimum distance is found, the information regarding
3070 * it is returned via searchPtr.
3071 *
3072 *----------------------------------------------------------------------
3073 */
3074 static int
3075 ClosestTrace(graphPtr, linePtr, searchPtr, distProc)
3076 Graph *graphPtr; /* Graph widget record */
3077 Line *linePtr; /* Line element record */
3078 ClosestSearch *searchPtr; /* Info about closest point in element */
3079 DistanceProc *distProc;
3080 {
3081 Blt_ChainLink *linkPtr;
3082 Point2D closest, b;
3083 Trace *tracePtr;
3084 double dist, minDist;
3085 register Point2D *pointPtr, *endPtr;
3086 int i;
3087
•3088 i = searchPtr->index;
3089 minDist = searchPtr->dist;
•3090 closest = searchPtr->point;
3091 for (linkPtr = Blt_ChainFirstLink(linePtr->traces); linkPtr != NULL;
3092 linkPtr = Blt_ChainNextLink(linkPtr)) {
3093 tracePtr = Blt_ChainGetValue(linkPtr);
3094 for (pointPtr = tracePtr->screenPts,
3095 endPtr = tracePtr->screenPts + (tracePtr->nScreenPts - 1);
3096 pointPtr < endPtr; pointPtr++) {
3097 dist = (*distProc)(searchPtr->x, searchPtr->y, pointPtr,
3098 pointPtr + 1, &b);
3099 if (dist < minDist) {
3100 closest = b;
3101 i = tracePtr->symbolToData[pointPtr - tracePtr->screenPts];
3102 minDist = dist;
3103 }
3104 }
3105 }
3106 if (minDist < searchPtr->dist) {
3107 searchPtr->dist = minDist;
3108 searchPtr->elemPtr = (Element *)linePtr;
3109 searchPtr->index = i;
3110 searchPtr->point = Blt_InvMap2D(graphPtr, closest.x, closest.y,
3111 &(linePtr->axes));
3112 return TRUE;
3113 }
3114 return FALSE;
3115 }
3116
3117 /*
3118 *----------------------------------------------------------------------
3119 *
3120 * ClosestStrip --
3121 *
3122 * Find the line segment closest to the given window coordinate
3123 * in the element.
3124 *
3125 * Results:
3126 * If a new minimum distance is found, the information regarding
3127 * it is returned via searchPtr.
3128 *
3129 *----------------------------------------------------------------------
3130 */
3131 static int
3132 ClosestStrip(graphPtr, linePtr, searchPtr, distProc)
3133 Graph *graphPtr; /* Graph widget record */
3134 Line *linePtr; /* Line element record */
3135 ClosestSearch *searchPtr; /* Info about closest point in element */
3136 DistanceProc *distProc;
3137 {
3138 Point2D closest, b;
3139 double dist, minDist;
3140 int count;
3141 int i;
3142 register Segment2D *s;
3143
•3144 i = searchPtr->index;
3145 minDist = searchPtr->dist;
•3146 closest = searchPtr->point;
3147 s = linePtr->strips;
3148 for (count = 0; count < linePtr->nStrips; count++, s++) {
3149 dist = (*distProc)(searchPtr->x, searchPtr->y, &(s->p), &(s->q), &b);
3150 if (dist < minDist) {
3151 closest = b;
3152 i = linePtr->stripToData[count];
3153 minDist = dist;
3154 }
3155 }
3156 if (minDist < searchPtr->dist) {
3157 searchPtr->dist = minDist;
3158 searchPtr->elemPtr = (Element *)linePtr;
3159 searchPtr->index = i;
3160 searchPtr->point = Blt_InvMap2D(graphPtr, closest.x, closest.y,
3161 &(linePtr->axes));
3162 return TRUE;
3163 }
3164 return FALSE;
3165 }
3166
3167 /*
3168 *----------------------------------------------------------------------
3169 *
3170 * ClosestPoint --
3171 *
3172 * Find the element whose data point is closest to the given screen
3173 * coordinate.
3174 *
3175 * Results:
3176 * If a new minimum distance is found, the information regarding
3177 * it is returned via searchPtr.
3178 *
3179 *----------------------------------------------------------------------
3180 */
3181 static void
3182 ClosestPoint(linePtr, searchPtr)
3183 Line *linePtr; /* Line element that we are looking at */
3184 ClosestSearch *searchPtr; /* Assorted information related to searching
3185 * for the closest point */
3186 {
3187 double dist, minDist;
3188 double dx, dy;
3189 int count, i;
3190 register Point2D *pointPtr;
3191
3192 minDist = searchPtr->dist;
3193 i = 0;
3194
3195 /*
3196 * Instead of testing each data point in graph coordinates, look at
3197 * the array of mapped screen coordinates. The advantages are
3198 * 1) only examine points that are visible (unclipped), and
3199 * 2) the computed distance is already in screen coordinates.
3200 */
3201 pointPtr = linePtr->symbolPts;
3202 for (count = 0; count < linePtr->nSymbolPts; count++, pointPtr++) {
3203 dx = (double)(searchPtr->x - pointPtr->x);
3204 dy = (double)(searchPtr->y - pointPtr->y);
3205 if (searchPtr->along == SEARCH_BOTH) {
3206 dist = hypot(dx, dy);
3207 } else if (searchPtr->along == SEARCH_X) {
3208 dist = dx;
3209 } else if (searchPtr->along == SEARCH_Y) {
3210 dist = dy;
3211 } else {
3212 /* This can't happen */
3213 continue;
3214 }
3215 if (dist < minDist) {
3216 i = linePtr->symbolToData[count];
3217 minDist = dist;
3218 }
3219 }
3220 if (minDist < searchPtr->dist) {
3221 searchPtr->elemPtr = (Element *)linePtr;
3222 searchPtr->dist = minDist;
3223 searchPtr->index = i;
3224 searchPtr->point.x = linePtr->x.valueArr[i];
3225 searchPtr->point.y = linePtr->y.valueArr[i];
3226 }
3227 }
3228
3229 /*
3230 *----------------------------------------------------------------------
3231 *
3232 * GetLineExtents --
3233 *
3234 * Retrieves the range of the line element
3235 *
3236 * Results:
3237 * Returns the number of data points in the element.
3238 *
3239 *----------------------------------------------------------------------
3240 */
3241 static void
3242 GetLineExtents(elemPtr, extsPtr)
3243 Element *elemPtr;
3244 Extents2D *extsPtr;
3245 {
3246 int nPoints;
3247
3248 extsPtr->top = extsPtr->left = DBL_MAX;
3249 extsPtr->bottom = extsPtr->right = -DBL_MAX;
3250
3251 nPoints = NumberOfPoints(elemPtr);
3252 if (nPoints < 1) {
3253 return;
3254 }
3255 extsPtr->right = elemPtr->x.max;
3256 if ((elemPtr->x.min <= 0.0) && (elemPtr->axes.x->logScale)) {
3257 extsPtr->left = Blt_FindElemVectorMinimum(&elemPtr->x, DBL_MIN);
3258 } else {
3259 extsPtr->left = elemPtr->x.min;
3260 }
3261 extsPtr->bottom = elemPtr->y.max;
3262 if ((elemPtr->y.min <= 0.0) && (elemPtr->axes.y->logScale)) {
3263 extsPtr->top = Blt_FindElemVectorMinimum(&elemPtr->y, DBL_MIN);
3264 } else {
3265 extsPtr->top = elemPtr->y.min;
3266 }
3267
3268 /* Correct the data limits for error bars */
3269
3270 if (elemPtr->xError.nValues > 0) {
3271 register int i;
3272 double x;
3273
3274 nPoints = MIN(elemPtr->xError.nValues, nPoints);
3275 for (i = 0; i < nPoints; i++) {
3276 x = elemPtr->x.valueArr[i] + elemPtr->xError.valueArr[i];
3277 if (x > extsPtr->right) {
3278 extsPtr->right = x;
3279 }
3280 x = elemPtr->x.valueArr[i] - elemPtr->xError.valueArr[i];
3281 if (elemPtr->axes.x->logScale) {
3282 if (x < 0.0) {
3283 x = -x; /* Mirror negative values, instead
3284 * of ignoring them. */
3285 }
3286 if ((x > DBL_MIN) && (x < extsPtr->left)) {
3287 extsPtr->left = x;
3288 }
3289 } else if (x < extsPtr->left) {
3290 extsPtr->left = x;
3291 }
3292 }
3293 } else {
3294 if ((elemPtr->xHigh.nValues > 0) &&
3295 (elemPtr->xHigh.max > extsPtr->right)) {
3296 extsPtr->right = elemPtr->xHigh.max;
3297 }
3298 if (elemPtr->xLow.nValues > 0) {
3299 double left;
3300
3301 if ((elemPtr->xLow.min <= 0.0) &&
3302 (elemPtr->axes.x->logScale)) {
3303 left = Blt_FindElemVectorMinimum(&elemPtr->xLow, DBL_MIN);
3304 } else {
3305 left = elemPtr->xLow.min;
3306 }
3307 if (left < extsPtr->left) {
3308 extsPtr->left = left;
3309 }
3310 }
3311 }
3312
3313 if (elemPtr->yError.nValues > 0) {
3314 register int i;
3315 double y;
3316
3317 nPoints = MIN(elemPtr->yError.nValues, nPoints);
3318 for (i = 0; i < nPoints; i++) {
3319 y = elemPtr->y.valueArr[i] + elemPtr->yError.valueArr[i];
3320 if (y > extsPtr->bottom) {
3321 extsPtr->bottom = y;
3322 }
3323 y = elemPtr->y.valueArr[i] - elemPtr->yError.valueArr[i];
3324 if (elemPtr->axes.y->logScale) {
3325 if (y < 0.0) {
3326 y = -y; /* Mirror negative values, instead
3327 * of ignoring them. */
3328 }
3329 if ((y > DBL_MIN) && (y < extsPtr->left)) {
3330 extsPtr->top = y;
3331 }
3332 } else if (y < extsPtr->top) {
3333 extsPtr->top = y;
3334 }
3335 }
3336 } else {
3337 if ((elemPtr->yHigh.nValues > 0) &&
3338 (elemPtr->yHigh.max > extsPtr->bottom)) {
3339 extsPtr->bottom = elemPtr->yHigh.max;
3340 }
3341 if (elemPtr->yLow.nValues > 0) {
3342 double top;
3343
3344 if ((elemPtr->yLow.min <= 0.0) &&
3345 (elemPtr->axes.y->logScale)) {
3346 top = Blt_FindElemVectorMinimum(&elemPtr->yLow, DBL_MIN);
3347 } else {
3348 top = elemPtr->yLow.min;
3349 }
3350 if (top < extsPtr->top) {
3351 extsPtr->top = top;
3352 }
3353 }
3354 }
3355 }
3356
3357 /*
3358 *----------------------------------------------------------------------
3359 *
3360 * TileChangedProc
3361 *
3362 * Rebuilds the designated GC with the new tile pixmap.
3363 *
3364 * Results:
3365 * None.
3366 *
3367 *----------------------------------------------------------------------
3368 */
3369 /*ARGSUSED*/
3370 static void
3371 TileChangedProc(clientData, tile)
3372 ClientData clientData;
3373 Blt_Tile tile; /* Not used. */
3374 {
3375 Line *linePtr = clientData;
3376 Graph *graphPtr;
3377
3378 graphPtr = linePtr->graphPtr;
3379 if (graphPtr->tkwin != NULL) {
3380 graphPtr->flags |= REDRAW_WORLD;
3381 Blt_EventuallyRedrawGraph(graphPtr);
3382 }
3383 }
3384
3385 /*
3386 *----------------------------------------------------------------------
3387 *
3388 * ConfigureLine --
3389 *
3390 * Sets up the appropriate configuration parameters in the GC.
3391 * It is assumed the parameters have been previously set by
3392 * a call to Tk_ConfigureWidget.
3393 *
3394 * Results:
3395 * The return value is a standard Tcl result. If TCL_ERROR is
3396 * returned, then interp->result contains an error message.
3397 *
3398 * Side effects:
3399 * Configuration information such as line width, line style, color
3400 * etc. get set in a new GC.
3401 *
3402 *----------------------------------------------------------------------
3403 */
3404 /*ARGSUSED*/
3405 static int
3406 ConfigureLine(graphPtr, elemPtr)
3407 Graph *graphPtr;
3408 Element *elemPtr;
3409 {
3410 Line *linePtr = (Line *)elemPtr;
3411 unsigned long gcMask;
3412 XGCValues gcValues;
3413 GC newGC;
3414 Blt_ChainLink *linkPtr;
3415
3416 if (ConfigurePen(graphPtr, (Pen *)&(linePtr->builtinPen)) != TCL_OK) {
3417 return TCL_ERROR;
3418 }
3419 /*
3420 * Point to the static normal/active pens if no external pens have
3421 * been selected.
3422 */
3423 if (linePtr->normalPenPtr == NULL) {
3424 linePtr->normalPenPtr = &(linePtr->builtinPen);
3425 }
3426 linkPtr = Blt_ChainFirstLink(linePtr->palette);
3427 if (linkPtr != NULL) {
3428 LinePenStyle *stylePtr;
3429
3430 stylePtr = Blt_ChainGetValue(linkPtr);
3431 stylePtr->penPtr = linePtr->normalPenPtr;
3432 }
3433 if (linePtr->fillTile != NULL) {
3434 Blt_SetTileChangedProc(linePtr->fillTile, TileChangedProc, linePtr);
3435 }
3436 /*
3437 * Set the outline GC for this pen: GCForeground is outline color.
3438 * GCBackground is the fill color (only used for bitmap symbols).
3439 */
3440 gcMask = 0;
3441 if (linePtr->fillFgColor != NULL) {
3442 gcMask |= GCForeground;
3443 gcValues.foreground = linePtr->fillFgColor->pixel;
3444 }
3445 if (linePtr->fillBgColor != NULL) {
3446 gcMask |= GCBackground;
3447 gcValues.background = linePtr->fillBgColor->pixel;
3448 }
3449 if ((linePtr->fillStipple != None) &&
3450 (linePtr->fillStipple != PATTERN_SOLID)) {
3451 gcMask |= (GCStipple | GCFillStyle);
3452 gcValues.stipple = linePtr->fillStipple;
3453 gcValues.fill_style = (linePtr->fillBgColor == NULL)
3454 ? FillStippled : FillOpaqueStippled;
3455 }
3456 newGC = Tk_GetGC(graphPtr->tkwin, gcMask, &gcValues);
3457 if (linePtr->fillGC != NULL) {
3458 Tk_FreeGC(graphPtr->display, linePtr->fillGC);
3459 }
3460 linePtr->fillGC = newGC;
3461
3462 if (Blt_ConfigModified(linePtr->configSpecs, graphPtr->interp, "-scalesymbols",
3463 (char *)NULL)) {
3464 linePtr->flags |= (MAP_ITEM | SCALE_SYMBOL);
3465 }
3466 if (Blt_ConfigModified(linePtr->configSpecs, graphPtr->interp, "-pixels", "-trace", "-*data",
3467 "-smooth", "-map*", "-label", "-hide", "-x", "-y", "-areapattern",
3468 (char *)NULL)) {
3469 linePtr->flags |= MAP_ITEM;
3470 }
3471 return TCL_OK;
3472 }
3473
3474 /*
3475 *----------------------------------------------------------------------
3476 *
3477 * ClosestLine --
3478 *
3479 * Find the closest point or line segment (if interpolated) to
3480 * the given window coordinate in the line element.
3481 *
3482 * Results:
3483 * Returns the distance of the closest point among other
3484 * information.
3485 *
3486 *----------------------------------------------------------------------
3487 */
3488 static void
3489 ClosestLine(graphPtr, elemPtr, searchPtr)
3490 Graph *graphPtr; /* Graph widget record */
3491 Element *elemPtr; /* Element to examine */
3492 ClosestSearch *searchPtr; /* Info about closest point in element */
3493 {
3494 Line *linePtr = (Line *)elemPtr;
3495 int mode;
3496
3497 mode = searchPtr->mode;
3498 if (mode == SEARCH_AUTO) {
3499 LinePen *penPtr = linePtr->normalPenPtr;
3500
3501 mode = SEARCH_POINTS;
3502 if ((NumberOfPoints(linePtr) > 1) && (penPtr->traceWidth > 0)) {
3503 mode = SEARCH_TRACES;
3504 }
3505 }
3506 if (mode == SEARCH_POINTS) {
3507 ClosestPoint(linePtr, searchPtr);
3508 } else {
3509 DistanceProc *distProc;
3510 int found;
3511
3512 if (searchPtr->along == SEARCH_X) {
3513 distProc = DistanceToX;
3514 } else if (searchPtr->along == SEARCH_Y) {
3515 distProc = DistanceToY;
3516 } else {
3517 distProc = DistanceToLine;
3518 }
3519 if (elemPtr->classUid == bltStripElementUid) {
3520 found = ClosestStrip(graphPtr, linePtr, searchPtr, distProc);
3521 } else {
3522 found = ClosestTrace(graphPtr, linePtr, searchPtr, distProc);
3523 }
3524 if ((!found) && (searchPtr->along != SEARCH_BOTH)) {
3525 ClosestPoint(linePtr, searchPtr);
3526 }
3527 }
3528 }
3529
3530 /*
3531 * XDrawLines() points: XMaxRequestSize(dpy) - 3
3532 * XFillPolygon() points: XMaxRequestSize(dpy) - 4
3533 * XDrawSegments() segments: (XMaxRequestSize(dpy) - 3) / 2
3534 * XDrawRectangles() rectangles: (XMaxRequestSize(dpy) - 3) / 2
3535 * XFillRectangles() rectangles: (XMaxRequestSize(dpy) - 3) / 2
3536 * XDrawArcs() or XFillArcs() arcs: (XMaxRequestSize(dpy) - 3) / 3
3537 */
3538
3539 #define MAX_DRAWLINES(d) Blt_MaxRequestSize(d, sizeof(XPoint))
3540 #define MAX_DRAWPOLYGON(d) Blt_MaxRequestSize(d, sizeof(XPoint))
3541 #define MAX_DRAWSEGMENTS(d) Blt_MaxRequestSize(d, sizeof(XSegment))
3542 #define MAX_DRAWRECTANGLES(d) Blt_MaxRequestSize(d, sizeof(XRectangle))
3543 #define MAX_DRAWARCS(d) Blt_MaxRequestSize(d, sizeof(XArc))
3544
3545 #ifdef WIN32
3546
3547 static void
3548 DrawCircles(
3549 Display *display,
3550 Drawable drawable,
3551 Line *linePtr,
3552 LinePen *penPtr,
3553 int nSymbolPts,
3554 Point2D *symbolPts,
3555 int radius)
3556 {
3557 HBRUSH brush, oldBrush;
3558 HPEN pen, oldPen;
3559 HDC dc;
3560 TkWinDCState state;
3561 register Point2D *pointPtr, *endPtr;
3562
3563 if (drawable == None) {
3564 return; /* Huh? */
3565 }
3566 if ((penPtr->symbol.fillGC == NULL) &&
3567 (penPtr->symbol.outlineWidth == 0)) {
3568 return;
3569 }
3570 dc = TkWinGetDrawableDC(display, drawable, &state);
3571 /* SetROP2(dc, tkpWinRopModes[penPtr->symbol.fillGC->function]); */
3572 if (penPtr->symbol.fillGC != NULL) {
3573 brush = CreateSolidBrush(penPtr->symbol.fillGC->foreground);
3574 } else {
3575 brush = GetStockBrush(NULL_BRUSH);
3576 }
3577 if (penPtr->symbol.outlineWidth > 0) {
3578 pen = Blt_GCToPen(dc, penPtr->symbol.outlineGC);
3579 } else {
3580 pen = GetStockPen(NULL_PEN);
3581 }
3582 oldPen = SelectPen(dc, pen);
3583 oldBrush = SelectBrush(dc, brush);
3584 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
3585 pointPtr < endPtr; pointPtr++) {
3586 Ellipse(dc, (int)pointPtr->x - radius, (int)pointPtr->y - radius,
3587 (int)pointPtr->x + radius + 1, (int)pointPtr->y + radius + 1);
3588 }
3589 DeleteBrush(SelectBrush(dc, oldBrush));
3590 DeletePen(SelectPen(dc, oldPen));
3591 TkWinReleaseDrawableDC(drawable, dc, &state);
3592 }
3593
3594 #else
3595
3596 static void
3597 DrawCircles(display, drawable, linePtr, penPtr, nSymbolPts, symbolPts, radius)
3598 Display *display;
3599 Drawable drawable;
3600 Line *linePtr;
3601 LinePen *penPtr;
3602 int nSymbolPts;
3603 Point2D *symbolPts;
3604 int radius;
3605 {
3606 register int i;
3607 XArc *arcArr; /* Array of arcs (circle) */
3608 register XArc *arcPtr;
3609 int reqSize, nArcs;
3610 int s;
3611 int count;
3612 register Point2D *pointPtr, *endPtr;
3613
3614 s = radius + radius;
3615 arcArr = Blt_Malloc(nSymbolPts * sizeof(XArc));
3616 arcPtr = arcArr;
3617
3618 if (linePtr->symbolInterval > 0) {
3619 count = 0;
3620 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
3621 pointPtr < endPtr; pointPtr++) {
3622 if (DRAW_SYMBOL(linePtr)) {
3623 arcPtr->x = (short int)pointPtr->x - radius;
3624 arcPtr->y = (short int)pointPtr->y - radius;
3625 arcPtr->width = arcPtr->height = (unsigned short)s;
3626 arcPtr->angle1 = 0;
3627 arcPtr->angle2 = 23040;
3628 arcPtr++, count++;
3629 }
3630 linePtr->symbolCounter++;
3631 }
3632 } else {
3633 count = nSymbolPts;
3634 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
3635 pointPtr < endPtr; pointPtr++) {
3636 arcPtr->x = (short int)pointPtr->x - radius;
3637 arcPtr->y = (short int)pointPtr->y - radius;
3638 arcPtr->width = arcPtr->height = (unsigned short)s;
3639 arcPtr->angle1 = 0;
3640 arcPtr->angle2 = 23040;
3641 arcPtr++;
3642 }
3643 }
3644 reqSize = MAX_DRAWARCS(display);
3645 for (i = 0; i < count; i += reqSize) {
3646 nArcs = ((i + reqSize) > count) ? (count - i) : reqSize;
3647 if (penPtr->symbol.fillGC != NULL) {
3648 XFillArcs(display, drawable, penPtr->symbol.fillGC, arcArr + i,
3649 nArcs);
3650 }
3651 if (penPtr->symbol.outlineWidth > 0) {
3652 XDrawArcs(display, drawable, penPtr->symbol.outlineGC, arcArr + i,
3653 nArcs);
3654 }
3655 }
3656 Blt_Free(arcArr);
3657 }
3658
3659 #endif
3660
3661 static void
3662 DrawSquares(display, drawable, linePtr, penPtr, nSymbolPts, symbolPts, r)
3663 Display *display;
3664 Drawable drawable;
3665 Line *linePtr;
3666 LinePen *penPtr;
3667 int nSymbolPts;
3668 register Point2D *symbolPts;
3669 int r;
3670 {
3671 XRectangle *rectArr;
3672 register Point2D *pointPtr, *endPtr;
3673 register XRectangle *rectPtr;
3674 int reqSize, nRects;
3675 int s;
3676 register int i;
3677 int count;
3678
3679 s = r + r;
3680 rectArr = Blt_Malloc(nSymbolPts * sizeof(XRectangle));
3681 rectPtr = rectArr;
3682
3683 if (linePtr->symbolInterval > 0) {
3684 count = 0;
3685 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
3686 pointPtr < endPtr; pointPtr++) {
3687 if (DRAW_SYMBOL(linePtr)) {
3688 rectPtr->x = (short int)(pointPtr->x - r);
3689 rectPtr->y = (short int)(pointPtr->y - r);
3690 rectPtr->width = rectPtr->height = (unsigned short)s;
3691 rectPtr++, count++;
3692 }
3693 linePtr->symbolCounter++;
3694 }
3695 } else {
3696 count = nSymbolPts;
3697 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
3698 pointPtr < endPtr; pointPtr++) {
3699 rectPtr->x = (short int)(pointPtr->x - r);
3700 rectPtr->y = (short int)(pointPtr->y - r);
3701 rectPtr->width = rectPtr->height = (unsigned short)s;
3702 rectPtr++;
3703 }
3704 }
3705 reqSize = MAX_DRAWRECTANGLES(display);
3706 for (i = 0; i < count; i += reqSize) {
3707 nRects = ((i + reqSize) > count) ? (count - i) : reqSize;
3708 if (penPtr->symbol.fillGC != NULL) {
3709 XFillRectangles(display, drawable, penPtr->symbol.fillGC,
3710 rectArr + i, nRects);
3711 }
3712 if (penPtr->symbol.outlineWidth > 0) {
3713 XDrawRectangles(display, drawable, penPtr->symbol.outlineGC,
3714 rectArr + i, nRects);
3715 }
3716 }
3717 Blt_Free(rectArr);
3718 }
3719
3720 /*
3721 * -----------------------------------------------------------------
3722 *
3723 * DrawSymbols --
3724 *
3725 * Draw the symbols centered at the each given x,y coordinate
3726 * in the array of points.
3727 *
3728 * Results:
3729 * None.
3730 *
3731 * Side Effects:
3732 * Draws a symbol at each coordinate given. If active,
3733 * only those coordinates which are currently active are
3734 * drawn.
3735 *
3736 * -----------------------------------------------------------------
3737 */
3738 static void
3739 DrawSymbols(graphPtr, drawable, linePtr, penPtr, size, nSymbolPts, symbolPts)
3740 Graph *graphPtr; /* Graph widget record */
3741 Drawable drawable; /* Pixmap or window to draw into */
3742 Line *linePtr;
3743 LinePen *penPtr;
3744 int size; /* Size of element */
3745 int nSymbolPts; /* Number of coordinates in array */
3746 Point2D *symbolPts; /* Array of x,y coordinates for line */
3747 {
3748 XPoint pattern[13]; /* Template for polygon symbols */
3749 int r1, r2;
3750 register int i, n;
3751 int count;
3752 register Point2D *pointPtr, *endPtr;
3753 #define SQRT_PI 1.77245385090552
3754 #define S_RATIO 0.886226925452758
3755
3756 if (size < 3) {
3757 if (penPtr->symbol.fillGC != NULL) {
3758 XPoint *points;
3759
3760 points = Blt_Malloc(nSymbolPts * sizeof(XPoint));
3761 count = 0;
3762 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
3763 pointPtr < endPtr; pointPtr++) {
3764 points[count].x = (short int)pointPtr->x;
3765 points[count].y = (short int)pointPtr->y;
3766 count++;
3767 }
3768 XDrawPoints(graphPtr->display, drawable, penPtr->symbol.fillGC,
3769 points, nSymbolPts, CoordModeOrigin);
3770 Blt_Free(points);
3771 }
3772 return;
3773 }
3774 r1 = (int)ceil(size * 0.5);
3775 r2 = (int)ceil(size * S_RATIO * 0.5);
3776
3777 switch (penPtr->symbol.type) {
3778 case SYMBOL_NONE:
3779 break;
3780
3781 case SYMBOL_SQUARE:
3782 DrawSquares(graphPtr->display, drawable, linePtr, penPtr, nSymbolPts,
3783 symbolPts, r2);
3784 break;
3785
3786 case SYMBOL_CIRCLE:
3787 DrawCircles(graphPtr->display, drawable, linePtr, penPtr, nSymbolPts,
3788 symbolPts, r1);
3789 break;
3790
3791 case SYMBOL_SPLUS:
3792 case SYMBOL_SCROSS:
3793 {
3794 XSegment *segArr; /* Array of line segments (splus, scross) */
3795 register XSegment *segPtr;
3796 int reqSize, nSegs, chunk;
3797
3798 if (penPtr->symbol.type == SYMBOL_SCROSS) {
3799 r2 = Round(r2 * M_SQRT1_2);
3800 pattern[3].y = pattern[2].x = pattern[0].x = pattern[0].y = -r2;
3801 pattern[3].x = pattern[2].y = pattern[1].y = pattern[1].x = r2;
3802 } else {
3803 pattern[0].y = pattern[1].y = pattern[2].x = pattern[3].x = 0;
3804 pattern[0].x = pattern[2].y = -r2;
3805 pattern[1].x = pattern[3].y = r2;
3806 }
3807 segArr = Blt_Malloc(nSymbolPts * 2 * sizeof(XSegment));
3808 segPtr = segArr;
3809 if (linePtr->symbolInterval > 0) {
3810 count = 0;
3811 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
3812 pointPtr < endPtr; pointPtr++) {
3813 if (DRAW_SYMBOL(linePtr)) {
3814 segPtr->x1 = pattern[0].x + (short int)pointPtr->x;
3815 segPtr->y1 = pattern[0].y + (short int)pointPtr->y;
3816 segPtr->x2 = pattern[1].x + (short int)pointPtr->x;
3817 segPtr->y2 = pattern[1].y + (short int)pointPtr->y;
3818 segPtr++;
3819 segPtr->x1 = pattern[2].x + (short int)pointPtr->x;
3820 segPtr->y1 = pattern[2].y + (short int)pointPtr->y;
3821 segPtr->x2 = pattern[3].x + (short int)pointPtr->x;
3822 segPtr->y2 = pattern[3].y + (short int)pointPtr->y;
3823 segPtr++;
3824 count++;
3825 }
3826 linePtr->symbolCounter++;
3827 }
3828 } else {
3829 count = nSymbolPts;
3830 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
3831 pointPtr < endPtr; pointPtr++) {
3832 segPtr->x1 = pattern[0].x + (short int)pointPtr->x;
3833 segPtr->y1 = pattern[0].y + (short int)pointPtr->y;
3834 segPtr->x2 = pattern[1].x + (short int)pointPtr->x;
3835 segPtr->y2 = pattern[1].y + (short int)pointPtr->y;
3836 segPtr++;
3837 segPtr->x1 = pattern[2].x + (short int)pointPtr->x;
3838 segPtr->y1 = pattern[2].y + (short int)pointPtr->y;
3839 segPtr->x2 = pattern[3].x + (short int)pointPtr->x;
3840 segPtr->y2 = pattern[3].y + (short int)pointPtr->y;
3841 segPtr++;
3842 }
3843 }
3844 nSegs = count * 2;
3845 /* Always draw skinny symbols regardless of the outline width */
3846 reqSize = MAX_DRAWSEGMENTS(graphPtr->display);
3847 for (i = 0; i < nSegs; i += reqSize) {
3848 chunk = ((i + reqSize) > nSegs) ? (nSegs - i) : reqSize;
3849 XDrawSegments(graphPtr->display, drawable,
3850 penPtr->symbol.outlineGC, segArr + i, chunk);
3851 }
3852 Blt_Free(segArr);
3853 }
3854 break;
3855
3856 case SYMBOL_PLUS:
3857 case SYMBOL_CROSS:
3858 {
3859 XPoint *polygon;
3860 register XPoint *p;
3861 int d; /* Small delta for cross/plus thickness */
3862
3863 d = (r2 / 3);
3864
3865 /*
3866 *
3867 * 2 3 The plus/cross symbol is a closed polygon
3868 * of 12 points. The diagram to the left
3869 * 0,12 1 4 5 represents the positions of the points
3870 * x,y which are computed below. The extra
3871 * 11 10 7 6 (thirteenth) point connects the first and
3872 * last points.
3873 * 9 8
3874 */
3875
3876 pattern[0].x = pattern[11].x = pattern[12].x = -r2;
3877 pattern[2].x = pattern[1].x = pattern[10].x = pattern[9].x = -d;
3878 pattern[3].x = pattern[4].x = pattern[7].x = pattern[8].x = d;
3879 pattern[5].x = pattern[6].x = r2;
3880 pattern[2].y = pattern[3].y = -r2;
3881 pattern[0].y = pattern[1].y = pattern[4].y = pattern[5].y =
3882 pattern[12].y = -d;
3883 pattern[11].y = pattern[10].y = pattern[7].y = pattern[6].y = d;
3884 pattern[9].y = pattern[8].y = r2;
3885
3886 if (penPtr->symbol.type == SYMBOL_CROSS) {
3887 double dx, dy;
3888
3889 /* For the cross symbol, rotate the points by 45 degrees. */
3890 for (n = 0; n < 12; n++) {
3891 dx = (double)pattern[n].x * M_SQRT1_2;
3892 dy = (double)pattern[n].y * M_SQRT1_2;
3893 pattern[n].x = Round(dx - dy);
3894 pattern[n].y = Round(dx + dy);
3895 }
3896 pattern[12] = pattern[0];
3897 }
3898 polygon = Blt_Malloc(nSymbolPts * 13 * sizeof(XPoint));
3899 p = polygon;
3900 if (linePtr->symbolInterval > 0) {
3901 count = 0;
3902 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
3903 pointPtr < endPtr; pointPtr++) {
3904 if (DRAW_SYMBOL(linePtr)) {
3905 for (n = 0; n < 13; n++) {
3906 p->x = pattern[n].x + (short int)pointPtr->x;
3907 p->y = pattern[n].y + (short int)pointPtr->y;
3908 p++;
3909 }
3910 count++;
3911 }
3912 linePtr->symbolCounter++;
3913 }
3914 } else {
3915 count = nSymbolPts;
3916 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
3917 pointPtr < endPtr; pointPtr++) {
3918 for (n = 0; n < 13; n++) {
3919 p->x = pattern[n].x + (short int)pointPtr->x;
3920 p->y = pattern[n].y + (short int)pointPtr->y;
3921 p++;
3922 }
3923 }
3924 }
3925 if (penPtr->symbol.fillGC != NULL) {
3926 for (p = polygon, i = 0; i < count; i++, p += 13) {
3927 XFillPolygon(graphPtr->display, drawable,
3928 penPtr->symbol.fillGC, p, 13, Complex, CoordModeOrigin);
3929 }
3930 }
3931 if (penPtr->symbol.outlineWidth > 0) {
3932 for (p = polygon, i = 0; i < count; i++, p += 13) {
3933 XDrawLines(graphPtr->display, drawable,
3934 penPtr->symbol.outlineGC, p, 13, CoordModeOrigin);
3935 }
3936 }
3937 Blt_Free(polygon);
3938 }
3939 break;
3940
3941 case SYMBOL_DIAMOND:
3942 {
3943 XPoint *polygon;
3944 register XPoint *p;
3945
3946 /*
3947 *
3948 * The plus symbol is a closed polygon
3949 * 1 of 4 points. The diagram to the left
3950 * represents the positions of the points
3951 * 0,4 x,y 2 which are computed below. The extra
3952 * (fifth) point connects the first and
3953 * 3 last points.
3954 *
3955 */
3956 pattern[1].y = pattern[0].x = -r1;
3957 pattern[2].y = pattern[3].x = pattern[0].y = pattern[1].x = 0;
3958 pattern[3].y = pattern[2].x = r1;
3959 pattern[4] = pattern[0];
3960
3961 polygon = Blt_Malloc(nSymbolPts * 5 * sizeof(XPoint));
3962 p = polygon;
3963 if (linePtr->symbolInterval > 0) {
3964 count = 0;
3965 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
3966 pointPtr < endPtr; pointPtr++) {
3967 if (DRAW_SYMBOL(linePtr)) {
3968 for (n = 0; n < 5; n++, p++) {
3969 p->x = pattern[n].x + (short int)pointPtr->x;
3970 p->y = pattern[n].y + (short int)pointPtr->y;
3971 }
3972 count++;
3973 }
3974 linePtr->symbolCounter++;
3975 }
3976 } else {
3977 count = nSymbolPts;
3978 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
3979 pointPtr < endPtr; pointPtr++) {
3980 for (n = 0; n < 5; n++, p++) {
3981 p->x = pattern[n].x + (short int)pointPtr->x;
3982 p->y = pattern[n].y + (short int)pointPtr->y;
3983 }
3984 }
3985 }
3986 if (penPtr->symbol.fillGC != NULL) {
3987 for (p = polygon, i = 0; i < count; i++, p += 5) {
3988 XFillPolygon(graphPtr->display, drawable,
3989 penPtr->symbol.fillGC, p, 5, Convex, CoordModeOrigin);
3990
3991 }
3992 }
3993 if (penPtr->symbol.outlineWidth > 0) {
3994 for (p = polygon, i = 0; i < count; i++, p += 5) {
3995 XDrawLines(graphPtr->display, drawable,
3996 penPtr->symbol.outlineGC, p, 5, CoordModeOrigin);
3997 }
3998 }
3999 Blt_Free(polygon);
4000 }
4001 break;
4002
4003 case SYMBOL_TRIANGLE:
4004 case SYMBOL_ARROW:
4005 {
4006 XPoint *polygon;
4007 register XPoint *p;
4008 double b;
4009 int b2, h1, h2;
4010 #define H_RATIO 1.1663402261671607
4011 #define B_RATIO 1.3467736870885982
4012 #define TAN30 0.57735026918962573
4013 #define COS30 0.86602540378443871
4014
4015 b = Round(size * B_RATIO * 0.7);
4016 b2 = Round(b * 0.5);
4017 h2 = Round(TAN30 * b2);
4018 h1 = Round(b2 / COS30);
4019 /*
4020 *
4021 * The triangle symbol is a closed polygon
4022 * 0,3 of 3 points. The diagram to the left
4023 * represents the positions of the points
4024 * x,y which are computed below. The extra
4025 * (fourth) point connects the first and
4026 * 2 1 last points.
4027 *
4028 */
4029
4030 if (penPtr->symbol.type == SYMBOL_ARROW) {
4031 pattern[3].x = pattern[0].x = 0;
4032 pattern[3].y = pattern[0].y = h1;
4033 pattern[1].x = b2;
4034 pattern[2].y = pattern[1].y = -h2;
4035 pattern[2].x = -b2;
4036 } else {
4037 pattern[3].x = pattern[0].x = 0;
4038 pattern[3].y = pattern[0].y = -h1;
4039 pattern[1].x = b2;
4040 pattern[2].y = pattern[1].y = h2;
4041 pattern[2].x = -b2;
4042 }
4043 polygon = Blt_Malloc(nSymbolPts * 4 * sizeof(XPoint));
4044 p = polygon;
4045 if (linePtr->symbolInterval > 0) {
4046 count = 0;
4047 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
4048 pointPtr < endPtr; pointPtr++) {
4049 if (DRAW_SYMBOL(linePtr)) {
4050 for (n = 0; n < 4; n++) {
4051 p->x = pattern[n].x + (short int)pointPtr->x;
4052 p->y = pattern[n].y + (short int)pointPtr->y;
4053 p++;
4054 }
4055 count++;
4056 }
4057 linePtr->symbolCounter++;
4058 }
4059 } else {
4060 count = nSymbolPts;
4061 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
4062 pointPtr < endPtr; pointPtr++) {
4063 for (n = 0; n < 4; n++) {
4064 p->x = pattern[n].x + (short int)pointPtr->x;
4065 p->y = pattern[n].y + (short int)pointPtr->y;
4066 p++;
4067 }
4068 }
4069 }
4070 if (penPtr->symbol.fillGC != NULL) {
4071 for (p = polygon, i = 0; i < count; i++, p += 4) {
4072 XFillPolygon(graphPtr->display, drawable,
4073 penPtr->symbol.fillGC, p, 4, Convex, CoordModeOrigin);
4074 }
4075 }
4076 if (penPtr->symbol.outlineWidth > 0) {
4077 for (p = polygon, i = 0; i < count; i++, p += 4) {
4078 XDrawLines(graphPtr->display, drawable,
4079 penPtr->symbol.outlineGC, p, 4, CoordModeOrigin);
4080 }
4081 }
4082 Blt_Free(polygon);
4083 }
4084 break;
4085 case SYMBOL_BITMAP:
4086 {
4087 Pixmap bitmap, mask;
4088 int width, height, bmWidth, bmHeight;
4089 double scale, sx, sy;
4090 int dx, dy;
4091 register int x, y;
4092
4093 Tk_SizeOfBitmap(graphPtr->display, penPtr->symbol.bitmap,
4094 &width, &height);
4095 mask = None;
4096
4097 /*
4098 * Compute the size of the scaled bitmap. Stretch the
4099 * bitmap to fit a nxn bounding box.
4100 */
4101 sx = (double)size / (double)width;
4102 sy = (double)size / (double)height;
4103 scale = MIN(sx, sy);
4104 bmWidth = (int)(width * scale);
4105 bmHeight = (int)(height * scale);
4106
4107 XSetClipMask(graphPtr->display, penPtr->symbol.outlineGC, None);
4108 if (penPtr->symbol.mask != None) {
4109 mask = Blt_ScaleBitmap(graphPtr->tkwin, penPtr->symbol.mask,
4110 width, height, bmWidth, bmHeight);
4111 XSetClipMask(graphPtr->display, penPtr->symbol.outlineGC,
4112 mask);
4113 }
4114 bitmap = Blt_ScaleBitmap(graphPtr->tkwin, penPtr->symbol.bitmap,
4115 width, height, bmWidth, bmHeight);
4116 if (penPtr->symbol.fillGC == NULL) {
4117 XSetClipMask(graphPtr->display, penPtr->symbol.outlineGC,
4118 bitmap);
4119 }
4120 dx = bmWidth / 2;
4121 dy = bmHeight / 2;
4122 if (linePtr->symbolInterval > 0) {
4123 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
4124 pointPtr < endPtr; pointPtr++) {
4125 if (DRAW_SYMBOL(linePtr)) {
4126 x = (int)pointPtr->x - dx;
4127 y = (int)pointPtr->y - dy;
4128 if ((penPtr->symbol.fillGC == NULL) || (mask != None)) {
4129 XSetClipOrigin(graphPtr->display,
4130 penPtr->symbol.outlineGC, x, y);
4131 }
4132 XCopyPlane(graphPtr->display, bitmap, drawable,
4133 penPtr->symbol.outlineGC, 0, 0, bmWidth, bmHeight,
4134 x, y, 1);
4135 }
4136 linePtr->symbolCounter++;
4137 }
4138 } else {
4139 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
4140 pointPtr < endPtr; pointPtr++) {
4141 x = (int)pointPtr->x - dx;
4142 y = (int)pointPtr->y - dy;
4143 if ((penPtr->symbol.fillGC == NULL) || (mask != None)) {
4144 XSetClipOrigin(graphPtr->display,
4145 penPtr->symbol.outlineGC, x, y);
4146 }
4147 XCopyPlane(graphPtr->display, bitmap, drawable,
4148 penPtr->symbol.outlineGC, 0, 0, bmWidth, bmHeight,
4149 x, y, 1);
4150 }
4151 }
4152 Tk_FreePixmap(graphPtr->display, bitmap);
4153 if (mask != None) {
4154 Tk_FreePixmap(graphPtr->display, mask);
4155 }
4156 }
4157 break;
4158 }
4159 }
4160
4161 /*
4162 * -----------------------------------------------------------------
4163 *
4164 * DrawSymbol --
4165 *
4166 * Draw the symbol centered at the each given x,y coordinate.
4167 *
4168 * Results:
4169 * None.
4170 *
4171 * Side Effects:
4172 * Draws a symbol at the coordinate given.
4173 *
4174 * -----------------------------------------------------------------
4175 */
4176 static void
4177 DrawSymbol(graphPtr, drawable, elemPtr, x, y, size)
4178 Graph *graphPtr; /* Graph widget record */
4179 Drawable drawable; /* Pixmap or window to draw into */
4180 Element *elemPtr; /* Line element information */
4181 int x, y; /* Center position of symbol */
4182 int size; /* Size of symbol. */
4183 {
4184 Line *linePtr = (Line *)elemPtr;
4185 LinePen *penPtr = linePtr->normalPenPtr;
4186
4187 if (penPtr->traceWidth > 0) {
4188 /*
4189 * Draw an extra line offset by one pixel from the previous to
4190 * give a thicker appearance. This is only for the legend
4191 * entry. This routine is never called for drawing the actual
4192 * line segments.
4193 */
4194 XDrawLine(graphPtr->display, drawable, penPtr->traceGC, x - size,
4195 y, x + size, y);
4196 XDrawLine(graphPtr->display, drawable, penPtr->traceGC, x - size,
4197 y + 1, x + size, y + 1);
4198 }
4199 if (penPtr->symbol.type != SYMBOL_NONE) {
4200 Point2D point;
4201
4202 point.x = x, point.y = y;
4203 DrawSymbols(graphPtr, drawable, linePtr, linePtr->normalPenPtr, size,
4204 1, &point);
4205 }
4206 }
4207
4208 #ifdef WIN32
4209
4210 static void
4211 DrawTraces(
4212 Graph *graphPtr,
4213 Drawable drawable, /* Pixmap or window to draw into */
4214 Line *linePtr,
4215 LinePen *penPtr)
4216 {
4217 Blt_ChainLink *linkPtr;
4218 HBRUSH brush, oldBrush;
4219 HDC dc;
4220 HPEN pen, oldPen;
4221 POINT *points;
4222 TkWinDCState state;
4223 Trace *tracePtr;
4224 int j;
4225 int nPoints, remaining;
4226 register POINT *p;
4227 register int count;
4228
4229 /*
4230 * Depending if the line is wide (> 1 pixel), arbitrarily break
4231 * the line in sections of 100 points. This bit of weirdness has
4232 * to do with wide geometric pens. The longer the polyline, the
4233 * slower it draws. The trade off is that we lose dash and cap
4234 * uniformity for unbearably slow polyline draws.
4235 */
4236 if (penPtr->traceGC->line_width > 1) {
4237 nPoints = 100;
4238 } else {
4239 nPoints = Blt_MaxRequestSize(graphPtr->display, sizeof(POINT)) - 1;
4240 }
4241 points = Blt_Malloc((nPoints + 1) * sizeof(POINT));
4242
4243 dc = TkWinGetDrawableDC(graphPtr->display, drawable, &state);
4244
4245 pen = Blt_GCToPen(dc, penPtr->traceGC);
4246 oldPen = SelectPen(dc, pen);
4247 brush = CreateSolidBrush(penPtr->traceGC->foreground);
4248 oldBrush = SelectBrush(dc, brush);
4249 SetROP2(dc, tkpWinRopModes[penPtr->traceGC->function]);
4250
4251 for (linkPtr = Blt_ChainFirstLink(linePtr->traces); linkPtr != NULL;
4252 linkPtr = Blt_ChainNextLink(linkPtr)) {
4253 tracePtr = Blt_ChainGetValue(linkPtr);
4254
4255 /*
4256 * If the trace has to be split into separate XDrawLines
4257 * calls, then the end point of the current trace is also the
4258 * starting point of the new split.
4259 */
4260
4261 /* Step 1. Convert and draw the first section of the trace.
4262 * It may contain the entire trace. */
4263
4264 for (p = points, count = 0; count < MIN(nPoints, tracePtr->nScreenPts);
4265 count++, p++) {
4266 p->x = (int)tracePtr->screenPts[count].x;
4267 p->y = (int)tracePtr->screenPts[count].y;
4268 }
4269 Polyline(dc, points, count);
4270
4271 /* Step 2. Next handle any full-size chunks left. */
4272
4273 while ((count + nPoints) < tracePtr->nScreenPts) {
4274 /* Start with the last point of the previous trace. */
4275 points[0].x = points[nPoints - 1].x;
4276 points[0].y = points[nPoints - 1].y;
4277
4278 for (p = points + 1, j = 0; j < nPoints; j++, count++, p++) {
4279 p->x = (int)tracePtr->screenPts[count].x;
4280 p->y = (int)tracePtr->screenPts[count].y;
4281 }
4282 Polyline(dc, points, nPoints + 1);
4283 }
4284
4285 /* Step 3. Convert and draw the remaining points. */
4286
4287 remaining = tracePtr->nScreenPts - count;
4288 if (remaining > 0) {
4289 /* Start with the last point of the previous trace. */
4290 points[0].x = points[nPoints - 1].x;
4291 points[0].y = points[nPoints - 1].y;
4292
4293 for (p = points + 1; count < tracePtr->nScreenPts; count++, p++) {
4294 p->x = (int)tracePtr->screenPts[count].x;
4295 p->y = (int)tracePtr->screenPts[count].y;
4296 }
4297 Polyline(dc, points, remaining + 1);
4298 }
4299 }
4300 Blt_Free(points);
4301 DeletePen(SelectPen(dc, oldPen));
4302 DeleteBrush(SelectBrush(dc, oldBrush));
4303 TkWinReleaseDrawableDC(drawable, dc, &state);
4304 }
4305
4306 #else
4307
4308 static void
4309 DrawTraces(graphPtr, drawable, linePtr, penPtr)
4310 Graph *graphPtr;
4311 Drawable drawable; /* Pixmap or window to draw into */
4312 Line *linePtr;
4313 LinePen *penPtr;
4314 {
4315 Blt_ChainLink *linkPtr;
4316 Trace *tracePtr;
4317 XPoint *points;
4318 int j;
4319 int nPoints, remaining;
4320 register XPoint *p;
4321 register int count;
4322
4323 nPoints = Blt_MaxRequestSize(graphPtr->display, sizeof(XPoint)) - 1;
4324 points = Blt_Malloc((nPoints + 1) * sizeof(XPoint));
4325
4326 for (linkPtr = Blt_ChainFirstLink(linePtr->traces); linkPtr != NULL;
4327 linkPtr = Blt_ChainNextLink(linkPtr)) {
4328 int n;
4329
4330 tracePtr = Blt_ChainGetValue(linkPtr);
4331
4332 /*
4333 * If the trace has to be split into separate XDrawLines
4334 * calls, then the end point of the current trace is also the
4335 * starting point of the new split.
4336 */
4337 /* Step 1. Convert and draw the first section of the trace.
4338 * It may contain the entire trace. */
4339
4340 n = MIN(nPoints, tracePtr->nScreenPts);
4341 for (p = points, count = 0; count < n; count++, p++) {
4342 p->x = (short int)tracePtr->screenPts[count].x;
4343 p->y = (short int)tracePtr->screenPts[count].y;
4344 }
4345 XDrawLines(graphPtr->display, drawable, penPtr->traceGC, points,
4346 count, CoordModeOrigin);
4347
4348 /* Step 2. Next handle any full-size chunks left. */
4349
4350 while ((count + nPoints) < tracePtr->nScreenPts) {
4351 /* Start with the last point of the previous trace. */
4352 points[0].x = points[nPoints - 1].x;
4353 points[0].y = points[nPoints - 1].y;
4354
4355 for (p = points + 1, j = 0; j < nPoints; j++, count++, p++) {
4356 p->x = (short int)tracePtr->screenPts[count].x;
4357 p->y = (short int)tracePtr->screenPts[count].y;
4358 }
4359 XDrawLines(graphPtr->display, drawable, penPtr->traceGC, points,
4360 nPoints + 1, CoordModeOrigin);
4361 }
4362
4363 /* Step 3. Convert and draw the remaining points. */
4364
4365 remaining = tracePtr->nScreenPts - count;
4366 if (remaining > 0) {
4367 /* Start with the last point of the previous trace. */
4368 points[0].x = points[nPoints - 1].x;
4369 points[0].y = points[nPoints - 1].y;
4370 for (p = points + 1; count < tracePtr->nScreenPts; count++, p++) {
4371 p->x = (short int)tracePtr->screenPts[count].x;
4372 p->y = (short int)tracePtr->screenPts[count].y;
4373 }
4374 XDrawLines(graphPtr->display, drawable, penPtr->traceGC, points,
4375 remaining + 1, CoordModeOrigin);
4376 }
4377 }
4378 Blt_Free(points);
4379 }
4380 #endif /* WIN32 */
4381
4382 static void
4383 DrawValues(graphPtr, drawable, linePtr, penPtr, nSymbolPts, symbolPts,
4384 pointToData)
4385 Graph *graphPtr;
4386 Drawable drawable;
4387 Line *linePtr;
4388 LinePen *penPtr;
4389 int nSymbolPts;
4390 Point2D *symbolPts;
4391 int *pointToData;
4392 {
4393 Point2D *pointPtr, *endPtr;
4394 int count;
4395 char string[TCL_DOUBLE_SPACE * 2 + 2];
4396 char *fmt;
4397 double x, y;
4398
4399 fmt = penPtr->valueFormat;
4400 if (fmt == NULL) {
4401 fmt = "%g";
4402 }
4403 count = 0;
4404 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
4405 pointPtr < endPtr; pointPtr++) {
4406 x = linePtr->x.valueArr[pointToData[count]];
4407 y = linePtr->y.valueArr[pointToData[count]];
4408 count++;
4409 if (penPtr->valueShow == SHOW_X) {
4410 sprintf(string, fmt, x);
4411 } else if (penPtr->valueShow == SHOW_Y) {
4412 sprintf(string, fmt, y);
4413 } else if (penPtr->valueShow == SHOW_BOTH) {
4414 sprintf(string, fmt, x);
4415 strcat(string, ",");
4416 sprintf(string + strlen(string), fmt, y);
4417 }
4418 Blt_DrawText(graphPtr->tkwin, drawable, string, &(penPtr->valueStyle),
4419 (int)pointPtr->x, (int)pointPtr->y);
4420 }
4421 }
4422
4423
4424 /*
4425 *----------------------------------------------------------------------
4426 *
4427 * DrawActiveLine --
4428 *
4429 * Draws the connected line(s) representing the element. If the
4430 * line is made up of non-line symbols and the line width
4431 * parameter has been set (linewidth > 0), the element will also
4432 * be drawn as a line (with the linewidth requested). The line
4433 * may consist of separate line segments.
4434 *
4435 * Results:
4436 * None.
4437 *
4438 * Side effects:
4439 * X drawing commands are output.
4440 *
4441 *----------------------------------------------------------------------
4442 */
4443 static void
4444 DrawActiveLine(graphPtr, drawable, elemPtr)
4445 Graph *graphPtr; /* Graph widget record */
4446 Drawable drawable; /* Pixmap or window to draw into */
4447 Element *elemPtr; /* Element to be drawn */
4448 {
4449 Line *linePtr = (Line *)elemPtr;
4450 LinePen *penPtr = linePtr->activePenPtr;
4451 int symbolSize;
4452
4453 if (penPtr == NULL) {
4454 return;
4455 }
4456 symbolSize = ScaleSymbol(elemPtr, linePtr->activePenPtr->symbol.size);
4457
4458 /*
4459 * nActiveIndices
4460 * > 0 Some points are active. Uses activeArr.
4461 * < 0 All points are active.
4462 * == 0 No points are active.
4463 */
4464 if (linePtr->nActiveIndices > 0) {
4465 if (linePtr->flags & ACTIVE_PENDING) {
4466 MapActiveSymbols(graphPtr, linePtr);
4467 }
4468 if (penPtr->symbol.type != SYMBOL_NONE) {
4469 DrawSymbols(graphPtr, drawable, linePtr, penPtr, symbolSize,
4470 linePtr->nActivePts, linePtr->activePts);
4471 }
4472 if (penPtr->valueShow != SHOW_NONE) {
4473 DrawValues(graphPtr, drawable, linePtr, penPtr,
4474 linePtr->nActivePts, linePtr->activePts,
4475 linePtr->activeToData);
4476 }
4477 } else if (linePtr->nActiveIndices < 0) {
4478 if (penPtr->traceWidth > 0) {
4479 if (linePtr->nStrips > 0) {
4480 Blt_Draw2DSegments(graphPtr->display, drawable,
4481 penPtr->traceGC, linePtr->strips, linePtr->nStrips);
4482 } else if (Blt_ChainGetLength(linePtr->traces) > 0) {
4483 DrawTraces(graphPtr, drawable, linePtr, penPtr);
4484 }
4485 }
4486 if (penPtr->symbol.type != SYMBOL_NONE) {
4487 DrawSymbols(graphPtr, drawable, linePtr, penPtr, symbolSize,
4488 linePtr->nSymbolPts, linePtr->symbolPts);
4489 }
4490 if (penPtr->valueShow != SHOW_NONE) {
4491 DrawValues(graphPtr, drawable, linePtr, penPtr,
4492 linePtr->nSymbolPts, linePtr->symbolPts,
4493 linePtr->symbolToData);
4494 }
4495 }
4496 }
4497
4498 /*
4499 *----------------------------------------------------------------------
4500 *
4501 * DrawNormalLine --
4502 *
4503 * Draws the connected line(s) representing the element. If the
4504 * line is made up of non-line symbols and the line width parameter
4505 * has been set (linewidth > 0), the element will also be drawn as
4506 * a line (with the linewidth requested). The line may consist of
4507 * separate line segments.
4508 *
4509 * Results:
4510 * None.
4511 *
4512 * Side effects:
4513 * X drawing commands are output.
4514 *
4515 *----------------------------------------------------------------------
4516 */
4517 static void
4518 DrawNormalLine(graphPtr, drawable, elemPtr)
4519 Graph *graphPtr; /* Graph widget record */
4520 Drawable drawable; /* Pixmap or window to draw into */
4521 Element *elemPtr; /* Element to be drawn */
4522 {
4523 Line *linePtr = (Line *)elemPtr;
4524 LinePen *penPtr;
4525 Blt_ChainLink *linkPtr;
4526 register LinePenStyle *stylePtr;
4527 unsigned int count;
4528
4529 /* Fill area under the curve */
4530 if (linePtr->fillPts != NULL) {
4531 XPoint *points;
4532 Point2D *endPtr, *pointPtr;
4533
4534 points = Blt_Malloc(sizeof(XPoint) * linePtr->nFillPts);
4535 count = 0;
4536 for(pointPtr = linePtr->fillPts,
4537 endPtr = linePtr->fillPts + linePtr->nFillPts;
4538 pointPtr < endPtr; pointPtr++) {
4539 points[count].x = (short int)pointPtr->x;
4540 points[count].y = (short int)pointPtr->y;
4541 count++;
4542 }
4543 if (Blt_HasTile(linePtr->fillTile)) {
4544 Blt_SetTileOrigin(graphPtr->tkwin, linePtr->fillTile, 0, 0);
4545 Blt_TilePolygon(graphPtr->tkwin, drawable, linePtr->fillTile,
4546 points, linePtr->nFillPts);
4547 } else if (linePtr->fillStipple != None) {
4548 XFillPolygon(graphPtr->display, drawable, linePtr->fillGC,
4549 points, linePtr->nFillPts, Complex, CoordModeOrigin);
4550 }
4551 Blt_Free(points);
4552 }
4553
4554 /* Lines: stripchart segments or graph traces. */
4555
4556 if (linePtr->nStrips > 0) {
4557 for (linkPtr = Blt_ChainFirstLink(linePtr->palette); linkPtr != NULL;
4558 linkPtr = Blt_ChainNextLink(linkPtr)) {
4559 stylePtr = Blt_ChainGetValue(linkPtr);
4560 penPtr = stylePtr->penPtr;
4561 if ((stylePtr->nStrips > 0) && (penPtr->traceWidth > 0)) {
4562 Blt_Draw2DSegments(graphPtr->display, drawable,
4563 penPtr->traceGC, stylePtr->strips, stylePtr->nStrips);
4564 }
4565 }
4566 } else if ((Blt_ChainGetLength(linePtr->traces) > 0) &&
4567 (linePtr->normalPenPtr->traceWidth > 0)) {
4568 DrawTraces(graphPtr, drawable, linePtr, linePtr->normalPenPtr);
4569 }
4570
4571 if (linePtr->reqMaxSymbols > 0) {
4572 int total;
4573
4574 total = 0;
4575 for (linkPtr = Blt_ChainFirstLink(linePtr->palette); linkPtr != NULL;
4576 linkPtr = Blt_ChainNextLink(linkPtr)) {
4577 stylePtr = Blt_ChainGetValue(linkPtr);
4578 total += stylePtr->nSymbolPts;
4579 }
4580 linePtr->symbolInterval = total / linePtr->reqMaxSymbols;
4581 linePtr->symbolCounter = 0;
4582 }
4583
4584 /* Symbols, error bars, values. */
4585
4586 count = 0;
4587 for (linkPtr = Blt_ChainFirstLink(linePtr->palette); linkPtr != NULL;
4588 linkPtr = Blt_ChainNextLink(linkPtr)) {
4589 stylePtr = Blt_ChainGetValue(linkPtr);
4590 penPtr = stylePtr->penPtr;
4591 if ((stylePtr->xErrorBarCnt > 0) && (penPtr->errorBarShow & SHOW_X)) {
4592 Blt_Draw2DSegments(graphPtr->display, drawable, penPtr->errorBarGC,
4593 stylePtr->xErrorBars, stylePtr->xErrorBarCnt);
4594 }
4595 if ((stylePtr->yErrorBarCnt > 0) && (penPtr->errorBarShow & SHOW_Y)) {
4596 Blt_Draw2DSegments(graphPtr->display, drawable, penPtr->errorBarGC,
4597 stylePtr->yErrorBars, stylePtr->yErrorBarCnt);
4598 }
4599 if ((stylePtr->nSymbolPts > 0) &&
4600 (penPtr->symbol.type != SYMBOL_NONE)) {
4601 DrawSymbols(graphPtr, drawable, linePtr, penPtr,
4602 stylePtr->symbolSize, stylePtr->nSymbolPts,
4603 stylePtr->symbolPts);
4604 }
4605 if (penPtr->valueShow != SHOW_NONE) {
4606 DrawValues(graphPtr, drawable, linePtr, penPtr,
4607 stylePtr->nSymbolPts, stylePtr->symbolPts,
4608 linePtr->symbolToData + count);
4609 }
4610 count += stylePtr->nSymbolPts;
4611 }
4612 linePtr->symbolInterval = 0;
4613 }
4614
4615 /*
4616 * -----------------------------------------------------------------
4617 *
4618 * GetSymbolPostScriptInfo --
4619 *
4620 * Set up the PostScript environment with the macros and
4621 * attributes needed to draw the symbols of the element.
4622 *
4623 * Results:
4624 * None.
4625 *
4626 * -----------------------------------------------------------------
4627 */
4628 static void
4629 GetSymbolPostScriptInfo(graphPtr, psToken, penPtr, size)
4630 Graph *graphPtr;
4631 PsToken psToken;
4632 LinePen *penPtr;
4633 int size;
4634 {
4635 XColor *outlineColor, *fillColor, *defaultColor;
4636
4637 /* Set line and foreground attributes */
4638 outlineColor = penPtr->symbol.outlineColor;
4639 fillColor = penPtr->symbol.fillColor;
4640 defaultColor = penPtr->traceColor;
4641
4642 if (fillColor == COLOR_DEFAULT) {
4643 fillColor = defaultColor;
4644 }
4645 if (outlineColor == COLOR_DEFAULT) {
4646 outlineColor = defaultColor;
4647 }
4648 if (penPtr->symbol.type == SYMBOL_NONE) {
4649 Blt_LineAttributesToPostScript(psToken, defaultColor,
4650 penPtr->traceWidth + 2, &(penPtr->traceDashes),
4651 CapButt, JoinMiter);
4652 } else {
4653 Blt_LineWidthToPostScript(psToken, penPtr->symbol.outlineWidth);
4654 Blt_LineDashesToPostScript(psToken, (Blt_Dashes *)NULL);
4655 }
4656
4657 /*
4658 * Build a PostScript procedure to draw the symbols. For bitmaps,
4659 * paint both the bitmap and its mask. Otherwise fill and stroke
4660 * the path formed already.
4661 */
4662 Blt_AppendToPostScript(psToken, "\n/DrawSymbolProc {\n", (char *)NULL);
4663 switch (penPtr->symbol.type) {
4664 case SYMBOL_NONE:
4665 break; /* Do nothing */
4666 case SYMBOL_BITMAP:
4667 {
4668 int width, height;
4669 double sx, sy, scale;
4670
4671 /*
4672 * Compute how much to scale the bitmap. Don't let the
4673 * scaled bitmap exceed the bounding square for the
4674 * symbol.
4675 */
4676 Tk_SizeOfBitmap(graphPtr->display, penPtr->symbol.bitmap,
4677 &width, &height);
4678 sx = (double)size / (double)width;
4679 sy = (double)size / (double)height;
4680 scale = MIN(sx, sy);
4681
4682 if ((penPtr->symbol.mask != None) && (fillColor != NULL)) {
4683 Blt_AppendToPostScript(psToken,
4684 "\n % Bitmap mask is \"",
4685 Tk_NameOfBitmap(graphPtr->display, penPtr->symbol.mask),
4686 "\"\n\n ", (char *)NULL);
4687 Blt_BackgroundToPostScript(psToken, fillColor);
4688 Blt_BitmapToPostScript(psToken, graphPtr->display,
4689 penPtr->symbol.mask, scale, scale);
4690 }
4691 Blt_AppendToPostScript(psToken,
4692 "\n % Bitmap symbol is \"",
4693 Tk_NameOfBitmap(graphPtr->display, penPtr->symbol.bitmap),
4694 "\"\n\n ", (char *)NULL);
4695 Blt_ForegroundToPostScript(psToken, outlineColor);
4696 Blt_BitmapToPostScript(psToken, graphPtr->display,
4697 penPtr->symbol.bitmap, scale, scale);
4698 }
4699 break;
4700 default:
4701 if (fillColor != NULL) {
4702 Blt_AppendToPostScript(psToken, " ", (char *)NULL);
4703 Blt_BackgroundToPostScript(psToken, fillColor);
4704 Blt_AppendToPostScript(psToken, " Fill\n", (char *)NULL);
4705 }
4706 if ((outlineColor != NULL) && (penPtr->symbol.outlineWidth > 0)) {
4707 Blt_AppendToPostScript(psToken, " ", (char *)NULL);
4708 Blt_ForegroundToPostScript(psToken, outlineColor);
4709 Blt_AppendToPostScript(psToken, " stroke\n", (char *)NULL);
4710 }
4711 break;
4712 }
4713 Blt_AppendToPostScript(psToken, "} def\n\n", (char *)NULL);
4714 }
4715
4716 /*
4717 * -----------------------------------------------------------------
4718 *
4719 * SymbolsToPostScript --
4720 *
4721 * Draw a symbol centered at the given x,y window coordinate
4722 * based upon the element symbol type and size.
4723 *
4724 * Results:
4725 * None.
4726 *
4727 * Problems:
4728 * Most notable is the round-off errors generated when
4729 * calculating the centered position of the symbol.
4730 *
4731 * -----------------------------------------------------------------
4732 */
4733 static void
4734 SymbolsToPostScript(graphPtr, psToken, penPtr, size, nSymbolPts, symbolPts)
4735 Graph *graphPtr;
4736 PsToken psToken;
4737 LinePen *penPtr;
4738 int size;
4739 int nSymbolPts;
4740 Point2D *symbolPts;
4741 {
4742 double symbolSize;
4743 register Point2D *pointPtr, *endPtr;
4744 static char *symbolMacros[] =
4745 {
4746 "Li", "Sq", "Ci", "Di", "Pl", "Cr", "Sp", "Sc", "Tr", "Ar", "Bm",
4747 (char *)NULL,
4748 };
4749 GetSymbolPostScriptInfo(graphPtr, psToken, penPtr, size);
4750
4751 symbolSize = (double)size;
4752 switch (penPtr->symbol.type) {
4753 case SYMBOL_SQUARE:
4754 case SYMBOL_CROSS:
4755 case SYMBOL_PLUS:
4756 case SYMBOL_SCROSS:
4757 case SYMBOL_SPLUS:
4758 symbolSize = (double)Round(size * S_RATIO);
4759 break;
4760 case SYMBOL_TRIANGLE:
4761 case SYMBOL_ARROW:
4762 symbolSize = (double)Round(size * 0.7);
4763 break;
4764 case SYMBOL_DIAMOND:
4765 symbolSize = (double)Round(size * M_SQRT1_2);
4766 break;
4767
4768 default:
4769 break;
4770 }
4771 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
4772 pointPtr < endPtr; pointPtr++) {
4773 Blt_FormatToPostScript(psToken, "%g %g %g %s\n", pointPtr->x,
4774 pointPtr->y, symbolSize, symbolMacros[penPtr->symbol.type]);
4775 }
4776 }
4777
4778 /*
4779 * -----------------------------------------------------------------
4780 *
4781 * SymbolToPostScript --
4782 *
4783 * Draw the symbol centered at the each given x,y coordinate.
4784 *
4785 * Results:
4786 * None.
4787 *
4788 * Side Effects:
4789 * Draws a symbol at the coordinate given.
4790 *
4791 * -----------------------------------------------------------------
4792 */
4793 static void
4794 SymbolToPostScript(graphPtr, psToken, elemPtr, x, y, size)
4795 Graph *graphPtr; /* Graph widget record */
4796 PsToken psToken;
4797 Element *elemPtr; /* Line element information */
4798 double x, y; /* Center position of symbol */
4799 int size; /* Size of element */
4800 {
4801 Line *linePtr = (Line *)elemPtr;
4802 LinePen *penPtr = linePtr->normalPenPtr;
4803
4804 if (penPtr->traceWidth > 0) {
4805 /*
4806 * Draw an extra line offset by one pixel from the previous to
4807 * give a thicker appearance. This is only for the legend
4808 * entry. This routine is never called for drawing the actual
4809 * line segments.
4810 */
4811 Blt_LineAttributesToPostScript(psToken, penPtr->traceColor,
4812 penPtr->traceWidth + 2, &(penPtr->traceDashes), CapButt, JoinMiter);
4813 Blt_FormatToPostScript(psToken, "%g %g %d Li\n", x, y, size + size);
4814 }
4815 if (penPtr->symbol.type != SYMBOL_NONE) {
4816 Point2D point;
4817
4818 point.x = x, point.y = y;
4819 SymbolsToPostScript(graphPtr, psToken, penPtr, size, 1, &point);
4820 }
4821 }
4822
4823 static void
4824 SetLineAttributes(psToken, penPtr)
4825 PsToken psToken;
4826 LinePen *penPtr;
4827 {
4828 /* Set the attributes of the line (color, dashes, linewidth) */
4829 Blt_LineAttributesToPostScript(psToken, penPtr->traceColor,
4830 penPtr->traceWidth, &(penPtr->traceDashes), CapButt, JoinMiter);
4831 if ((LineIsDashed(penPtr->traceDashes)) &&
4832 (penPtr->traceOffColor != NULL)) {
4833 Blt_AppendToPostScript(psToken, "/DashesProc {\n gsave\n ",
4834 (char *)NULL);
4835 Blt_BackgroundToPostScript(psToken, penPtr->traceOffColor);
4836 Blt_AppendToPostScript(psToken, " ", (char *)NULL);
4837 Blt_LineDashesToPostScript(psToken, (Blt_Dashes *)NULL);
4838 Blt_AppendToPostScript(psToken, "stroke\n grestore\n} def\n",
4839 (char *)NULL);
4840 } else {
4841 Blt_AppendToPostScript(psToken, "/DashesProc {} def\n", (char *)NULL);
4842 }
4843 }
4844
4845 static void
4846 TracesToPostScript(psToken, linePtr, penPtr)
4847 PsToken psToken;
4848 Line *linePtr;
4849 LinePen *penPtr;
4850 {
4851 Blt_ChainLink *linkPtr;
4852 Trace *tracePtr;
4853 register Point2D *pointPtr, *endPtr;
4854 int count;
4855
4856 SetLineAttributes(psToken, penPtr);
4857 for (linkPtr = Blt_ChainFirstLink(linePtr->traces); linkPtr != NULL;
4858 linkPtr = Blt_ChainNextLink(linkPtr)) {
4859 tracePtr = Blt_ChainGetValue(linkPtr);
4860 if (tracePtr->nScreenPts <= 0) {
4861 continue;
4862 }
4863 #define PS_MAXPATH 1500 /* Maximum number of components in a PostScript
4864 * (level 1) path. */
4865 pointPtr = tracePtr->screenPts;
4866 Blt_FormatToPostScript(psToken, " newpath %g %g moveto\n",
4867 pointPtr->x,
4868 pointPtr->y);
4869 pointPtr++;
4870 count = 0;
4871 for (endPtr = tracePtr->screenPts + (tracePtr->nScreenPts - 1);
4872 pointPtr < endPtr; pointPtr++) {
4873 Blt_FormatToPostScript(psToken, " %g %g lineto\n",
4874 pointPtr->x,
4875 pointPtr->y);
4876 if ((count % PS_MAXPATH) == 0) {
4877 Blt_FormatToPostScript(psToken,
4878 "DashesProc stroke\n newpath %g %g moveto\n",
4879 pointPtr->x,
4880 pointPtr->y);
4881 }
4882 count++;
4883 }
4884 Blt_FormatToPostScript(psToken, " %g %g lineto\n",
4885 pointPtr->x,
4886 pointPtr->y);
4887 Blt_AppendToPostScript(psToken, "DashesProc stroke\n", (char *)NULL);
4888 }
4889 }
4890
4891
4892 static void
4893 ValuesToPostScript(psToken, linePtr, penPtr, nSymbolPts, symbolPts,
4894 pointToData)
4895 PsToken psToken;
4896 Line *linePtr;
4897 LinePen *penPtr;
4898 int nSymbolPts;
4899 Point2D *symbolPts;
4900 int *pointToData;
4901 {
4902 Point2D *pointPtr, *endPtr;
4903 int count;
4904 char string[TCL_DOUBLE_SPACE * 2 + 2];
4905 char *fmt;
4906 double x, y;
4907
4908 fmt = penPtr->valueFormat;
4909 if (fmt == NULL) {
4910 fmt = "%g";
4911 }
4912 count = 0;
4913 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
4914 pointPtr < endPtr; pointPtr++) {
4915 x = linePtr->x.valueArr[pointToData[count]];
4916 y = linePtr->y.valueArr[pointToData[count]];
4917 count++;
4918 if (penPtr->valueShow == SHOW_X) {
4919 sprintf(string, fmt, x);
4920 } else if (penPtr->valueShow == SHOW_Y) {
4921 sprintf(string, fmt, y);
4922 } else if (penPtr->valueShow == SHOW_BOTH) {
4923 sprintf(string, fmt, x);
4924 strcat(string, ",");
4925 sprintf(string + strlen(string), fmt, y);
4926 }
4927 Blt_TextToPostScript(psToken, string, &(penPtr->valueStyle),
4928 pointPtr->x, pointPtr->y);
4929 }
4930 }
4931
4932
4933 /*
4934 *----------------------------------------------------------------------
4935 *
4936 * ActiveLineToPostScript --
4937 *
4938 * Generates PostScript commands to draw as "active" the points
4939 * (symbols) and or line segments (trace) representing the
4940 * element.
4941 *
4942 * Results:
4943 * None.
4944 *
4945 * Side effects:
4946 * PostScript pen width, dashes, and color settings are changed.
4947 *
4948 *----------------------------------------------------------------------
4949 */
4950 static void
4951 ActiveLineToPostScript(graphPtr, psToken, elemPtr)
4952 Graph *graphPtr;
4953 PsToken psToken;
4954 Element *elemPtr;
4955 {
4956 Line *linePtr = (Line *)elemPtr;
4957 LinePen *penPtr = linePtr->activePenPtr;
4958 int symbolSize;
4959
4960 if (penPtr == NULL) {
4961 return;
4962 }
4963 symbolSize = ScaleSymbol(elemPtr, penPtr->symbol.size);
4964 if (linePtr->nActiveIndices > 0) {
4965 if (linePtr->flags & ACTIVE_PENDING) {
4966 MapActiveSymbols(graphPtr, linePtr);
4967 }
4968 if (penPtr->symbol.type != SYMBOL_NONE) {
4969 SymbolsToPostScript(graphPtr, psToken, penPtr, symbolSize,
4970 linePtr->nActivePts, linePtr->activePts);
4971 }
4972 if (penPtr->valueShow != SHOW_NONE) {
4973 ValuesToPostScript(psToken, linePtr, penPtr, linePtr->nActivePts,
4974 linePtr->activePts, linePtr->activeToData);
4975 }
4976 } else if (linePtr->nActiveIndices < 0) {
4977 if (penPtr->traceWidth > 0) {
4978 if (linePtr->nStrips > 0) {
4979 SetLineAttributes(psToken, penPtr);
4980 Blt_2DSegmentsToPostScript(psToken, linePtr->strips,
4981 linePtr->nStrips);
4982 }
4983 if (Blt_ChainGetLength(linePtr->traces) > 0) {
4984 TracesToPostScript(psToken, linePtr, (LinePen *)penPtr);
4985 }
4986 }
4987 if (penPtr->symbol.type != SYMBOL_NONE) {
4988 SymbolsToPostScript(graphPtr, psToken, penPtr, symbolSize,
4989 linePtr->nSymbolPts, linePtr->symbolPts);
4990 }
4991 if (penPtr->valueShow != SHOW_NONE) {
4992 ValuesToPostScript(psToken, linePtr, penPtr, linePtr->nSymbolPts,
4993 linePtr->symbolPts, linePtr->symbolToData);
4994 }
4995 }
4996 }
4997
4998 /*
4999 *----------------------------------------------------------------------
5000 *
5001 * NormalLineToPostScript --
5002 *
5003 * Similar to the DrawLine procedure, prints PostScript related
5004 * commands to form the connected line(s) representing the element.
5005 *
5006 * Results:
5007 * None.
5008 *
5009 * Side effects:
5010 * PostScript pen width, dashes, and color settings are changed.
5011 *
5012 *----------------------------------------------------------------------
5013 */
5014 static void
5015 NormalLineToPostScript(graphPtr, psToken, elemPtr)
5016 Graph *graphPtr;
5017 PsToken psToken;
5018 Element *elemPtr;
5019 {
5020 Line *linePtr = (Line *)elemPtr;
5021 register LinePenStyle *stylePtr;
5022 Blt_ChainLink *linkPtr;
5023 LinePen *penPtr;
5024 unsigned int count;
5025 XColor *colorPtr;
5026
5027 /* Draw fill area */
5028 if (linePtr->fillPts != NULL) {
5029 /* Create a path to use for both the polygon and its outline. */
5030 Blt_PathToPostScript(psToken, linePtr->fillPts, linePtr->nFillPts);
5031 Blt_AppendToPostScript(psToken, "closepath\n", (char *)NULL);
5032
5033 /* If the background fill color was specified, draw the
5034 * polygon in a solid fashion with that color. */
5035 if (linePtr->fillBgColor != NULL) {
5036 Blt_BackgroundToPostScript(psToken, linePtr->fillBgColor);
5037 Blt_AppendToPostScript(psToken, "Fill\n", (char *)NULL);
5038 }
5039 Blt_ForegroundToPostScript(psToken, linePtr->fillFgColor);
5040 if (Blt_HasTile(linePtr->fillTile)) {
5041 /* TBA: Transparent tiling is the hard part. */
5042 } else if ((linePtr->fillStipple != None) &&
5043 (linePtr->fillStipple != PATTERN_SOLID)) {
5044 /* Draw the stipple in the foreground color. */
5045 Blt_StippleToPostScript(psToken, graphPtr->display,
5046 linePtr->fillStipple);
5047 } else {
5048 Blt_AppendToPostScript(psToken, "Fill\n", (char *)NULL);
5049 }
5050 }
5051 /* Draw lines */
5052 if (linePtr->nStrips > 0) {
5053 for (linkPtr = Blt_ChainFirstLink(linePtr->palette); linkPtr != NULL;
5054 linkPtr = Blt_ChainNextLink(linkPtr)) {
5055 stylePtr = Blt_ChainGetValue(linkPtr);
5056 penPtr = stylePtr->penPtr;
5057 if ((stylePtr->nStrips > 0) && (penPtr->traceWidth > 0)) {
5058 SetLineAttributes(psToken, penPtr);
5059 Blt_2DSegmentsToPostScript(psToken, stylePtr->strips,
5060 stylePtr->nStrips);
5061 }
5062 }
5063 } else if ((Blt_ChainGetLength(linePtr->traces) > 0) &&
5064 (linePtr->normalPenPtr->traceWidth > 0)) {
5065 TracesToPostScript(psToken, linePtr, linePtr->normalPenPtr);
5066 }
5067
5068 /* Draw symbols, error bars, values. */
5069
5070 count = 0;
5071 for (linkPtr = Blt_ChainFirstLink(linePtr->palette); linkPtr != NULL;
5072 linkPtr = Blt_ChainNextLink(linkPtr)) {
5073 stylePtr = Blt_ChainGetValue(linkPtr);
5074 penPtr = stylePtr->penPtr;
5075 colorPtr = penPtr->errorBarColor;
5076 if (colorPtr == COLOR_DEFAULT) {
5077 colorPtr = penPtr->traceColor;
5078 }
5079 if ((stylePtr->xErrorBarCnt > 0) && (penPtr->errorBarShow & SHOW_X)) {
5080 Blt_LineAttributesToPostScript(psToken, colorPtr,
5081 penPtr->errorBarLineWidth, NULL, CapButt, JoinMiter);
5082 Blt_2DSegmentsToPostScript(psToken, stylePtr->xErrorBars,
5083 stylePtr->xErrorBarCnt);
5084 }
5085 if ((stylePtr->yErrorBarCnt > 0) && (penPtr->errorBarShow & SHOW_Y)) {
5086 Blt_LineAttributesToPostScript(psToken, colorPtr,
5087 penPtr->errorBarLineWidth, NULL, CapButt, JoinMiter);
5088 Blt_2DSegmentsToPostScript(psToken, stylePtr->yErrorBars,
5089 stylePtr->yErrorBarCnt);
5090 }
5091 if ((stylePtr->nSymbolPts > 0) &&
5092 (stylePtr->penPtr->symbol.type != SYMBOL_NONE)) {
5093 SymbolsToPostScript(graphPtr, psToken, penPtr,
5094 stylePtr->symbolSize, stylePtr->nSymbolPts,
5095 stylePtr->symbolPts);
5096 }
5097 if (penPtr->valueShow != SHOW_NONE) {
5098 ValuesToPostScript(psToken, linePtr, penPtr,
5099 stylePtr->nSymbolPts, stylePtr->symbolPts,
5100 linePtr->symbolToData + count);
5101 }
5102 count += stylePtr->nSymbolPts;
5103 }
5104 }
5105
5106 /*
5107 *----------------------------------------------------------------------
5108 *
5109 * DestroyLine --
5110 *
5111 * Release memory and resources allocated for the line element.
5112 *
5113 * Results:
5114 * None.
5115 *
5116 * Side effects:
5117 * Everything associated with the line element is freed up.
5118 *
5119 *----------------------------------------------------------------------
5120 */
5121 #define FreeVector(v) \
5122 if ((v).clientId != NULL) { \
5123 Blt_FreeVectorId((v).clientId); \
5124 } else if ((v).valueArr != NULL) { \
5125 Blt_Free((v).valueArr); \
5126 }
5127
5128 static void
5129 DestroyLine(graphPtr, elemPtr)
5130 Graph *graphPtr;
5131 Element *elemPtr;
5132 {
5133 Line *linePtr = (Line *)elemPtr;
5134
5135 if (linePtr->normalPenPtr != &(linePtr->builtinPen)) {
5136 Blt_FreePen(graphPtr, (Pen *)linePtr->normalPenPtr);
5137 }
5138 DestroyPen(graphPtr, (Pen *)&(linePtr->builtinPen));
5139 if (linePtr->activePenPtr != NULL) {
5140 Blt_FreePen(graphPtr, (Pen *)linePtr->activePenPtr);
5141 }
5142
5143 FreeVector(linePtr->w);
5144 FreeVector(linePtr->x);
5145 FreeVector(linePtr->xHigh);
5146 FreeVector(linePtr->xLow);
5147 FreeVector(linePtr->xError);
5148 FreeVector(linePtr->y);
5149 FreeVector(linePtr->yHigh);
5150 FreeVector(linePtr->yLow);
5151 FreeVector(linePtr->yError);
5152
5153 ResetLine(linePtr);
5154 if (linePtr->palette != NULL) {
5155 Blt_FreePalette(graphPtr, linePtr->palette);
5156 Blt_ChainDestroy(linePtr->palette);
5157 }
5158 if (linePtr->tags != NULL) {
5159 Blt_Free(linePtr->tags);
5160 }
5161 if (linePtr->activeIndices != NULL) {
5162 Blt_Free(linePtr->activeIndices);
5163 }
5164 if (linePtr->fillPts != NULL) {
5165 Blt_Free(linePtr->fillPts);
5166 }
5167 if (linePtr->fillTile != NULL) {
5168 Blt_FreeTile(linePtr->fillTile);
5169 }
5170 if ((linePtr->fillStipple != None) &&
5171 (linePtr->fillStipple != PATTERN_SOLID)) {
5172 Tk_FreeBitmap(graphPtr->display, linePtr->fillStipple);
5173 }
5174 if (linePtr->fillGC != NULL) {
5175 Tk_FreeGC(graphPtr->display, linePtr->fillGC);
5176 }
5177 }
5178
5179 /*
5180 *----------------------------------------------------------------------
5181 *
5182 * Blt_LineElement --
5183 *
5184 * Allocate memory and initialize methods for the new line element.
5185 *
5186 * Results:
5187 * The pointer to the newly allocated element structure is returned.
5188 *
5189 * Side effects:
5190 * Memory is allocated for the line element structure.
5191 *
5192 *----------------------------------------------------------------------
5193 */
5194
5195 static ElementProcs lineProcs =
5196 {
5197 ClosestLine, /* Finds the closest element/data point */
5198 ConfigureLine, /* Configures the element. */
5199 DestroyLine, /* Destroys the element. */
5200 DrawActiveLine, /* Draws active element */
5201 DrawNormalLine, /* Draws normal element */
5202 DrawSymbol, /* Draws the element symbol. */
5203 GetLineExtents, /* Find the extents of the element's data. */
5204 ActiveLineToPostScript, /* Prints active element. */
5205 NormalLineToPostScript, /* Prints normal element. */
5206 SymbolToPostScript, /* Prints the line's symbol. */
5207 MapLine /* Compute element's screen coordinates. */
5208 };
5209
5210 Element *
5211 Blt_LineElement(graphPtr, name, classUid)
5212 Graph *graphPtr;
5213 char *name;
5214 Blt_Uid classUid;
5215 {
5216 register Line *linePtr;
5217
5218 linePtr = Blt_Calloc(1, sizeof(Line));
5219 assert(linePtr);
5220 linePtr->procsPtr = &lineProcs;
5221 if (classUid == bltLineElementUid) {
5222 linePtr->configSpecs = lineElemConfigSpecs;
5223 } else {
5224 linePtr->configSpecs = stripElemConfigSpecs;
5225 }
5226
5227 /* By default an element's name and label are the same. */
5228 linePtr->label = Blt_Strdup(name);
5229 linePtr->name = Blt_Strdup(name);
5230
5231 linePtr->classUid = classUid;
5232 linePtr->flags = SCALE_SYMBOL;
5233 linePtr->graphPtr = graphPtr;
5234 linePtr->labelRelief = TK_RELIEF_FLAT;
5235 linePtr->normalPenPtr = &linePtr->builtinPen;
5236 linePtr->palette = Blt_ChainCreate();
5237 linePtr->penDir = PEN_BOTH_DIRECTIONS;
5238 linePtr->reqSmooth = PEN_SMOOTH_NONE;
5239 InitPen(linePtr->normalPenPtr);
5240 return (Element *)linePtr;
5241 }