Debian Codegraph @

generic/bltGrLine.c

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
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 = -1; /* Suppress compiler warning. */
3089 minDist = searchPtr->dist;
3090 for (linkPtr = Blt_ChainFirstLink(linePtr->traces); linkPtr != NULL;
3091 linkPtr = Blt_ChainNextLink(linkPtr)) {
3092 tracePtr = Blt_ChainGetValue(linkPtr);
3093 for (pointPtr = tracePtr->screenPts,
3094 endPtr = tracePtr->screenPts + (tracePtr->nScreenPts - 1);
3095 pointPtr < endPtr; pointPtr++) {
3096 dist = (*distProc)(searchPtr->x, searchPtr->y, pointPtr,
3097 pointPtr + 1, &b);
3098 if (dist < minDist) {
3099 closest = b;
3100 i = tracePtr->symbolToData[pointPtr - tracePtr->screenPts];
3101 minDist = dist;
3102 }
3103 }
3104 }
3105 if (minDist < searchPtr->dist) {
3106 searchPtr->dist = minDist;
3107 searchPtr->elemPtr = (Element *)linePtr;
3108 searchPtr->index = i;
3109 searchPtr->point = Blt_InvMap2D(graphPtr, closest.x, closest.y,
3110 &(linePtr->axes));
3111 return TRUE;
3112 }
3113 return FALSE;
3114 }
3115
3116 /*
3117 *----------------------------------------------------------------------
3118 *
3119 * ClosestStrip --
3120 *
3121 * Find the line segment closest to the given window coordinate
3122 * in the element.
3123 *
3124 * Results:
3125 * If a new minimum distance is found, the information regarding
3126 * it is returned via searchPtr.
3127 *
3128 *----------------------------------------------------------------------
3129 */
3130 static int
3131 ClosestStrip(graphPtr, linePtr, searchPtr, distProc)
3132 Graph *graphPtr; /* Graph widget record */
3133 Line *linePtr; /* Line element record */
3134 ClosestSearch *searchPtr; /* Info about closest point in element */
3135 DistanceProc *distProc;
3136 {
3137 Point2D closest, b;
3138 double dist, minDist;
3139 int count;
3140 int i;
3141 register Segment2D *s;
3142
3143 i = 0;
3144 minDist = searchPtr->dist;
3145 s = linePtr->strips;
3146 for (count = 0; count < linePtr->nStrips; count++, s++) {
3147 dist = (*distProc)(searchPtr->x, searchPtr->y, &(s->p), &(s->q), &b);
3148 if (dist < minDist) {
3149 closest = b;
3150 i = linePtr->stripToData[count];
3151 minDist = dist;
3152 }
3153 }
3154 if (minDist < searchPtr->dist) {
3155 searchPtr->dist = minDist;
3156 searchPtr->elemPtr = (Element *)linePtr;
3157 searchPtr->index = i;
3158 searchPtr->point = Blt_InvMap2D(graphPtr, closest.x, closest.y,
3159 &(linePtr->axes));
3160 return TRUE;
3161 }
3162 return FALSE;
3163 }
3164
3165 /*
3166 *----------------------------------------------------------------------
3167 *
3168 * ClosestPoint --
3169 *
3170 * Find the element whose data point is closest to the given screen
3171 * coordinate.
3172 *
3173 * Results:
3174 * If a new minimum distance is found, the information regarding
3175 * it is returned via searchPtr.
3176 *
3177 *----------------------------------------------------------------------
3178 */
3179 static void
3180 ClosestPoint(linePtr, searchPtr)
3181 Line *linePtr; /* Line element that we are looking at */
3182 ClosestSearch *searchPtr; /* Assorted information related to searching
3183 * for the closest point */
3184 {
3185 double dist, minDist;
3186 double dx, dy;
3187 int count, i;
3188 register Point2D *pointPtr;
3189
3190 minDist = searchPtr->dist;
3191 i = 0;
3192
3193 /*
3194 * Instead of testing each data point in graph coordinates, look at
3195 * the array of mapped screen coordinates. The advantages are
3196 * 1) only examine points that are visible (unclipped), and
3197 * 2) the computed distance is already in screen coordinates.
3198 */
3199 pointPtr = linePtr->symbolPts;
3200 for (count = 0; count < linePtr->nSymbolPts; count++, pointPtr++) {
3201 dx = (double)(searchPtr->x - pointPtr->x);
3202 dy = (double)(searchPtr->y - pointPtr->y);
3203 if (searchPtr->along == SEARCH_BOTH) {
3204 dist = hypot(dx, dy);
3205 } else if (searchPtr->along == SEARCH_X) {
3206 dist = dx;
3207 } else if (searchPtr->along == SEARCH_Y) {
3208 dist = dy;
3209 } else {
3210 /* This can't happen */
3211 continue;
3212 }
3213 if (dist < minDist) {
3214 i = linePtr->symbolToData[count];
3215 minDist = dist;
3216 }
3217 }
3218 if (minDist < searchPtr->dist) {
3219 searchPtr->elemPtr = (Element *)linePtr;
3220 searchPtr->dist = minDist;
3221 searchPtr->index = i;
3222 searchPtr->point.x = linePtr->x.valueArr[i];
3223 searchPtr->point.y = linePtr->y.valueArr[i];
3224 }
3225 }
3226
3227 /*
3228 *----------------------------------------------------------------------
3229 *
3230 * GetLineExtents --
3231 *
3232 * Retrieves the range of the line element
3233 *
3234 * Results:
3235 * Returns the number of data points in the element.
3236 *
3237 *----------------------------------------------------------------------
3238 */
3239 static void
3240 GetLineExtents(elemPtr, extsPtr)
3241 Element *elemPtr;
3242 Extents2D *extsPtr;
3243 {
3244 int nPoints;
3245
3246 extsPtr->top = extsPtr->left = DBL_MAX;
3247 extsPtr->bottom = extsPtr->right = -DBL_MAX;
3248
3249 nPoints = NumberOfPoints(elemPtr);
3250 if (nPoints < 1) {
3251 return;
3252 }
3253 extsPtr->right = elemPtr->x.max;
3254 if ((elemPtr->x.min <= 0.0) && (elemPtr->axes.x->logScale)) {
3255 extsPtr->left = Blt_FindElemVectorMinimum(&elemPtr->x, DBL_MIN);
3256 } else {
3257 extsPtr->left = elemPtr->x.min;
3258 }
3259 extsPtr->bottom = elemPtr->y.max;
3260 if ((elemPtr->y.min <= 0.0) && (elemPtr->axes.y->logScale)) {
3261 extsPtr->top = Blt_FindElemVectorMinimum(&elemPtr->y, DBL_MIN);
3262 } else {
3263 extsPtr->top = elemPtr->y.min;
3264 }
3265
3266 /* Correct the data limits for error bars */
3267
3268 if (elemPtr->xError.nValues > 0) {
3269 register int i;
3270 double x;
3271
3272 nPoints = MIN(elemPtr->xError.nValues, nPoints);
3273 for (i = 0; i < nPoints; i++) {
3274 x = elemPtr->x.valueArr[i] + elemPtr->xError.valueArr[i];
3275 if (x > extsPtr->right) {
3276 extsPtr->right = x;
3277 }
3278 x = elemPtr->x.valueArr[i] - elemPtr->xError.valueArr[i];
3279 if (elemPtr->axes.x->logScale) {
3280 if (x < 0.0) {
3281 x = -x; /* Mirror negative values, instead
3282 * of ignoring them. */
3283 }
3284 if ((x > DBL_MIN) && (x < extsPtr->left)) {
3285 extsPtr->left = x;
3286 }
3287 } else if (x < extsPtr->left) {
3288 extsPtr->left = x;
3289 }
3290 }
3291 } else {
3292 if ((elemPtr->xHigh.nValues > 0) &&
3293 (elemPtr->xHigh.max > extsPtr->right)) {
3294 extsPtr->right = elemPtr->xHigh.max;
3295 }
3296 if (elemPtr->xLow.nValues > 0) {
3297 double left;
3298
3299 if ((elemPtr->xLow.min <= 0.0) &&
3300 (elemPtr->axes.x->logScale)) {
3301 left = Blt_FindElemVectorMinimum(&elemPtr->xLow, DBL_MIN);
3302 } else {
3303 left = elemPtr->xLow.min;
3304 }
3305 if (left < extsPtr->left) {
3306 extsPtr->left = left;
3307 }
3308 }
3309 }
3310
3311 if (elemPtr->yError.nValues > 0) {
3312 register int i;
3313 double y;
3314
3315 nPoints = MIN(elemPtr->yError.nValues, nPoints);
3316 for (i = 0; i < nPoints; i++) {
3317 y = elemPtr->y.valueArr[i] + elemPtr->yError.valueArr[i];
3318 if (y > extsPtr->bottom) {
3319 extsPtr->bottom = y;
3320 }
3321 y = elemPtr->y.valueArr[i] - elemPtr->yError.valueArr[i];
3322 if (elemPtr->axes.y->logScale) {
3323 if (y < 0.0) {
3324 y = -y; /* Mirror negative values, instead
3325 * of ignoring them. */
3326 }
3327 if ((y > DBL_MIN) && (y < extsPtr->left)) {
3328 extsPtr->top = y;
3329 }
3330 } else if (y < extsPtr->top) {
3331 extsPtr->top = y;
3332 }
3333 }
3334 } else {
3335 if ((elemPtr->yHigh.nValues > 0) &&
3336 (elemPtr->yHigh.max > extsPtr->bottom)) {
3337 extsPtr->bottom = elemPtr->yHigh.max;
3338 }
3339 if (elemPtr->yLow.nValues > 0) {
3340 double top;
3341
3342 if ((elemPtr->yLow.min <= 0.0) &&
3343 (elemPtr->axes.y->logScale)) {
3344 top = Blt_FindElemVectorMinimum(&elemPtr->yLow, DBL_MIN);
3345 } else {
3346 top = elemPtr->yLow.min;
3347 }
3348 if (top < extsPtr->top) {
3349 extsPtr->top = top;
3350 }
3351 }
3352 }
3353 }
3354
3355 /*
3356 *----------------------------------------------------------------------
3357 *
3358 * TileChangedProc
3359 *
3360 * Rebuilds the designated GC with the new tile pixmap.
3361 *
3362 * Results:
3363 * None.
3364 *
3365 *----------------------------------------------------------------------
3366 */
3367 /*ARGSUSED*/
3368 static void
3369 TileChangedProc(clientData, tile)
3370 ClientData clientData;
3371 Blt_Tile tile; /* Not used. */
3372 {
3373 Line *linePtr = clientData;
3374 Graph *graphPtr;
3375
3376 graphPtr = linePtr->graphPtr;
3377 if (graphPtr->tkwin != NULL) {
3378 graphPtr->flags |= REDRAW_WORLD;
3379 Blt_EventuallyRedrawGraph(graphPtr);
3380 }
3381 }
3382
3383 /*
3384 *----------------------------------------------------------------------
3385 *
3386 * ConfigureLine --
3387 *
3388 * Sets up the appropriate configuration parameters in the GC.
3389 * It is assumed the parameters have been previously set by
3390 * a call to Tk_ConfigureWidget.
3391 *
3392 * Results:
3393 * The return value is a standard Tcl result. If TCL_ERROR is
3394 * returned, then interp->result contains an error message.
3395 *
3396 * Side effects:
3397 * Configuration information such as line width, line style, color
3398 * etc. get set in a new GC.
3399 *
3400 *----------------------------------------------------------------------
3401 */
3402 /*ARGSUSED*/
3403 static int
3404 ConfigureLine(graphPtr, elemPtr)
3405 Graph *graphPtr;
3406 Element *elemPtr;
3407 {
3408 Line *linePtr = (Line *)elemPtr;
3409 unsigned long gcMask;
3410 XGCValues gcValues;
3411 GC newGC;
3412 Blt_ChainLink *linkPtr;
3413
3414 if (ConfigurePen(graphPtr, (Pen *)&(linePtr->builtinPen)) != TCL_OK) {
3415 return TCL_ERROR;
3416 }
3417 /*
3418 * Point to the static normal/active pens if no external pens have
3419 * been selected.
3420 */
3421 if (linePtr->normalPenPtr == NULL) {
3422 linePtr->normalPenPtr = &(linePtr->builtinPen);
3423 }
3424 linkPtr = Blt_ChainFirstLink(linePtr->palette);
3425 if (linkPtr != NULL) {
3426 LinePenStyle *stylePtr;
3427
3428 stylePtr = Blt_ChainGetValue(linkPtr);
3429 stylePtr->penPtr = linePtr->normalPenPtr;
3430 }
3431 if (linePtr->fillTile != NULL) {
3432 Blt_SetTileChangedProc(linePtr->fillTile, TileChangedProc, linePtr);
3433 }
3434 /*
3435 * Set the outline GC for this pen: GCForeground is outline color.
3436 * GCBackground is the fill color (only used for bitmap symbols).
3437 */
3438 gcMask = 0;
3439 if (linePtr->fillFgColor != NULL) {
3440 gcMask |= GCForeground;
3441 gcValues.foreground = linePtr->fillFgColor->pixel;
3442 }
3443 if (linePtr->fillBgColor != NULL) {
3444 gcMask |= GCBackground;
3445 gcValues.background = linePtr->fillBgColor->pixel;
3446 }
3447 if ((linePtr->fillStipple != None) &&
3448 (linePtr->fillStipple != PATTERN_SOLID)) {
3449 gcMask |= (GCStipple | GCFillStyle);
3450 gcValues.stipple = linePtr->fillStipple;
3451 gcValues.fill_style = (linePtr->fillBgColor == NULL)
3452 ? FillStippled : FillOpaqueStippled;
3453 }
3454 newGC = Tk_GetGC(graphPtr->tkwin, gcMask, &gcValues);
3455 if (linePtr->fillGC != NULL) {
3456 Tk_FreeGC(graphPtr->display, linePtr->fillGC);
3457 }
3458 linePtr->fillGC = newGC;
3459
3460 if (Blt_ConfigModified(linePtr->configSpecs, graphPtr->interp, "-scalesymbols",
3461 (char *)NULL)) {
3462 linePtr->flags |= (MAP_ITEM | SCALE_SYMBOL);
3463 }
3464 if (Blt_ConfigModified(linePtr->configSpecs, graphPtr->interp, "-pixels", "-trace", "-*data",
3465 "-smooth", "-map*", "-label", "-hide", "-x", "-y", "-areapattern",
3466 (char *)NULL)) {
3467 linePtr->flags |= MAP_ITEM;
3468 }
3469 return TCL_OK;
3470 }
3471
3472 /*
3473 *----------------------------------------------------------------------
3474 *
3475 * ClosestLine --
3476 *
3477 * Find the closest point or line segment (if interpolated) to
3478 * the given window coordinate in the line element.
3479 *
3480 * Results:
3481 * Returns the distance of the closest point among other
3482 * information.
3483 *
3484 *----------------------------------------------------------------------
3485 */
3486 static void
3487 ClosestLine(graphPtr, elemPtr, searchPtr)
3488 Graph *graphPtr; /* Graph widget record */
3489 Element *elemPtr; /* Element to examine */
3490 ClosestSearch *searchPtr; /* Info about closest point in element */
3491 {
3492 Line *linePtr = (Line *)elemPtr;
3493 int mode;
3494
3495 mode = searchPtr->mode;
3496 if (mode == SEARCH_AUTO) {
3497 LinePen *penPtr = linePtr->normalPenPtr;
3498
3499 mode = SEARCH_POINTS;
3500 if ((NumberOfPoints(linePtr) > 1) && (penPtr->traceWidth > 0)) {
3501 mode = SEARCH_TRACES;
3502 }
3503 }
3504 if (mode == SEARCH_POINTS) {
3505 ClosestPoint(linePtr, searchPtr);
3506 } else {
3507 DistanceProc *distProc;
3508 int found;
3509
3510 if (searchPtr->along == SEARCH_X) {
3511 distProc = DistanceToX;
3512 } else if (searchPtr->along == SEARCH_Y) {
3513 distProc = DistanceToY;
3514 } else {
3515 distProc = DistanceToLine;
3516 }
3517 if (elemPtr->classUid == bltStripElementUid) {
3518 found = ClosestStrip(graphPtr, linePtr, searchPtr, distProc);
3519 } else {
3520 found = ClosestTrace(graphPtr, linePtr, searchPtr, distProc);
3521 }
3522 if ((!found) && (searchPtr->along != SEARCH_BOTH)) {
3523 ClosestPoint(linePtr, searchPtr);
3524 }
3525 }
3526 }
3527
3528 /*
3529 * XDrawLines() points: XMaxRequestSize(dpy) - 3
3530 * XFillPolygon() points: XMaxRequestSize(dpy) - 4
3531 * XDrawSegments() segments: (XMaxRequestSize(dpy) - 3) / 2
3532 * XDrawRectangles() rectangles: (XMaxRequestSize(dpy) - 3) / 2
3533 * XFillRectangles() rectangles: (XMaxRequestSize(dpy) - 3) / 2
3534 * XDrawArcs() or XFillArcs() arcs: (XMaxRequestSize(dpy) - 3) / 3
3535 */
3536
3537 #define MAX_DRAWLINES(d) Blt_MaxRequestSize(d, sizeof(XPoint))
3538 #define MAX_DRAWPOLYGON(d) Blt_MaxRequestSize(d, sizeof(XPoint))
3539 #define MAX_DRAWSEGMENTS(d) Blt_MaxRequestSize(d, sizeof(XSegment))
3540 #define MAX_DRAWRECTANGLES(d) Blt_MaxRequestSize(d, sizeof(XRectangle))
3541 #define MAX_DRAWARCS(d) Blt_MaxRequestSize(d, sizeof(XArc))
3542
3543 #ifdef WIN32
3544
3545 static void
3546 DrawCircles(
3547 Display *display,
3548 Drawable drawable,
3549 Line *linePtr,
3550 LinePen *penPtr,
3551 int nSymbolPts,
3552 Point2D *symbolPts,
3553 int radius)
3554 {
3555 HBRUSH brush, oldBrush;
3556 HPEN pen, oldPen;
3557 HDC dc;
3558 TkWinDCState state;
3559 register Point2D *pointPtr, *endPtr;
3560
3561 if (drawable == None) {
3562 return; /* Huh? */
3563 }
3564 if ((penPtr->symbol.fillGC == NULL) &&
3565 (penPtr->symbol.outlineWidth == 0)) {
3566 return;
3567 }
3568 dc = TkWinGetDrawableDC(display, drawable, &state);
3569 /* SetROP2(dc, tkpWinRopModes[penPtr->symbol.fillGC->function]); */
3570 if (penPtr->symbol.fillGC != NULL) {
3571 brush = CreateSolidBrush(penPtr->symbol.fillGC->foreground);
3572 } else {
3573 brush = GetStockBrush(NULL_BRUSH);
3574 }
3575 if (penPtr->symbol.outlineWidth > 0) {
3576 pen = Blt_GCToPen(dc, penPtr->symbol.outlineGC);
3577 } else {
3578 pen = GetStockPen(NULL_PEN);
3579 }
3580 oldPen = SelectPen(dc, pen);
3581 oldBrush = SelectBrush(dc, brush);
3582 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
3583 pointPtr < endPtr; pointPtr++) {
3584 Ellipse(dc, (int)pointPtr->x - radius, (int)pointPtr->y - radius,
3585 (int)pointPtr->x + radius + 1, (int)pointPtr->y + radius + 1);
3586 }
3587 DeleteBrush(SelectBrush(dc, oldBrush));
3588 DeletePen(SelectPen(dc, oldPen));
3589 TkWinReleaseDrawableDC(drawable, dc, &state);
3590 }
3591
3592 #else
3593
3594 static void
3595 DrawCircles(display, drawable, linePtr, penPtr, nSymbolPts, symbolPts, radius)
3596 Display *display;
3597 Drawable drawable;
3598 Line *linePtr;
3599 LinePen *penPtr;
3600 int nSymbolPts;
3601 Point2D *symbolPts;
3602 int radius;
3603 {
3604 register int i;
3605 XArc *arcArr; /* Array of arcs (circle) */
3606 register XArc *arcPtr;
3607 int reqSize, nArcs;
3608 int s;
3609 int count;
3610 register Point2D *pointPtr, *endPtr;
3611
3612 s = radius + radius;
3613 arcArr = Blt_Malloc(nSymbolPts * sizeof(XArc));
3614 arcPtr = arcArr;
3615
3616 if (linePtr->symbolInterval > 0) {
3617 count = 0;
3618 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
3619 pointPtr < endPtr; pointPtr++) {
3620 if (DRAW_SYMBOL(linePtr)) {
3621 arcPtr->x = (short int)pointPtr->x - radius;
3622 arcPtr->y = (short int)pointPtr->y - radius;
3623 arcPtr->width = arcPtr->height = (unsigned short)s;
3624 arcPtr->angle1 = 0;
3625 arcPtr->angle2 = 23040;
3626 arcPtr++, count++;
3627 }
3628 linePtr->symbolCounter++;
3629 }
3630 } else {
3631 count = nSymbolPts;
3632 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
3633 pointPtr < endPtr; pointPtr++) {
3634 arcPtr->x = (short int)pointPtr->x - radius;
3635 arcPtr->y = (short int)pointPtr->y - radius;
3636 arcPtr->width = arcPtr->height = (unsigned short)s;
3637 arcPtr->angle1 = 0;
3638 arcPtr->angle2 = 23040;
3639 arcPtr++;
3640 }
3641 }
3642 reqSize = MAX_DRAWARCS(display);
3643 for (i = 0; i < count; i += reqSize) {
3644 nArcs = ((i + reqSize) > count) ? (count - i) : reqSize;
3645 if (penPtr->symbol.fillGC != NULL) {
3646 XFillArcs(display, drawable, penPtr->symbol.fillGC, arcArr + i,
3647 nArcs);
3648 }
3649 if (penPtr->symbol.outlineWidth > 0) {
3650 XDrawArcs(display, drawable, penPtr->symbol.outlineGC, arcArr + i,
3651 nArcs);
3652 }
3653 }
3654 Blt_Free(arcArr);
3655 }
3656
3657 #endif
3658
3659 static void
3660 DrawSquares(display, drawable, linePtr, penPtr, nSymbolPts, symbolPts, r)
3661 Display *display;
3662 Drawable drawable;
3663 Line *linePtr;
3664 LinePen *penPtr;
3665 int nSymbolPts;
3666 register Point2D *symbolPts;
3667 int r;
3668 {
3669 XRectangle *rectArr;
3670 register Point2D *pointPtr, *endPtr;
3671 register XRectangle *rectPtr;
3672 int reqSize, nRects;
3673 int s;
3674 register int i;
3675 int count;
3676
3677 s = r + r;
3678 rectArr = Blt_Malloc(nSymbolPts * sizeof(XRectangle));
3679 rectPtr = rectArr;
3680
3681 if (linePtr->symbolInterval > 0) {
3682 count = 0;
3683 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
3684 pointPtr < endPtr; pointPtr++) {
3685 if (DRAW_SYMBOL(linePtr)) {
3686 rectPtr->x = (short int)(pointPtr->x - r);
3687 rectPtr->y = (short int)(pointPtr->y - r);
3688 rectPtr->width = rectPtr->height = (unsigned short)s;
3689 rectPtr++, count++;
3690 }
3691 linePtr->symbolCounter++;
3692 }
3693 } else {
3694 count = nSymbolPts;
3695 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
3696 pointPtr < endPtr; pointPtr++) {
3697 rectPtr->x = (short int)(pointPtr->x - r);
3698 rectPtr->y = (short int)(pointPtr->y - r);
3699 rectPtr->width = rectPtr->height = (unsigned short)s;
3700 rectPtr++;
3701 }
3702 }
3703 reqSize = MAX_DRAWRECTANGLES(display);
3704 for (i = 0; i < count; i += reqSize) {
3705 nRects = ((i + reqSize) > count) ? (count - i) : reqSize;
3706 if (penPtr->symbol.fillGC != NULL) {
3707 XFillRectangles(display, drawable, penPtr->symbol.fillGC,
3708 rectArr + i, nRects);
3709 }
3710 if (penPtr->symbol.outlineWidth > 0) {
3711 XDrawRectangles(display, drawable, penPtr->symbol.outlineGC,
3712 rectArr + i, nRects);
3713 }
3714 }
3715 Blt_Free(rectArr);
3716 }
3717
3718 /*
3719 * -----------------------------------------------------------------
3720 *
3721 * DrawSymbols --
3722 *
3723 * Draw the symbols centered at the each given x,y coordinate
3724 * in the array of points.
3725 *
3726 * Results:
3727 * None.
3728 *
3729 * Side Effects:
3730 * Draws a symbol at each coordinate given. If active,
3731 * only those coordinates which are currently active are
3732 * drawn.
3733 *
3734 * -----------------------------------------------------------------
3735 */
3736 static void
3737 DrawSymbols(graphPtr, drawable, linePtr, penPtr, size, nSymbolPts, symbolPts)
3738 Graph *graphPtr; /* Graph widget record */
3739 Drawable drawable; /* Pixmap or window to draw into */
3740 Line *linePtr;
3741 LinePen *penPtr;
3742 int size; /* Size of element */
3743 int nSymbolPts; /* Number of coordinates in array */
3744 Point2D *symbolPts; /* Array of x,y coordinates for line */
3745 {
3746 XPoint pattern[13]; /* Template for polygon symbols */
3747 int r1, r2;
3748 register int i, n;
3749 int count;
3750 register Point2D *pointPtr, *endPtr;
3751 #define SQRT_PI 1.77245385090552
3752 #define S_RATIO 0.886226925452758
3753
3754 if (size < 3) {
3755 if (penPtr->symbol.fillGC != NULL) {
3756 XPoint *points;
3757
3758 points = Blt_Malloc(nSymbolPts * sizeof(XPoint));
3759 count = 0;
3760 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
3761 pointPtr < endPtr; pointPtr++) {
3762 points[count].x = (short int)pointPtr->x;
3763 points[count].y = (short int)pointPtr->y;
3764 count++;
3765 }
3766 XDrawPoints(graphPtr->display, drawable, penPtr->symbol.fillGC,
3767 points, nSymbolPts, CoordModeOrigin);
3768 Blt_Free(points);
3769 }
3770 return;
3771 }
3772 r1 = (int)ceil(size * 0.5);
3773 r2 = (int)ceil(size * S_RATIO * 0.5);
3774
3775 switch (penPtr->symbol.type) {
3776 case SYMBOL_NONE:
3777 break;
3778
3779 case SYMBOL_SQUARE:
3780 DrawSquares(graphPtr->display, drawable, linePtr, penPtr, nSymbolPts,
3781 symbolPts, r2);
3782 break;
3783
3784 case SYMBOL_CIRCLE:
3785 DrawCircles(graphPtr->display, drawable, linePtr, penPtr, nSymbolPts,
3786 symbolPts, r1);
3787 break;
3788
3789 case SYMBOL_SPLUS:
3790 case SYMBOL_SCROSS:
3791 {
3792 XSegment *segArr; /* Array of line segments (splus, scross) */
3793 register XSegment *segPtr;
3794 int reqSize, nSegs, chunk;
3795
3796 if (penPtr->symbol.type == SYMBOL_SCROSS) {
3797 r2 = Round(r2 * M_SQRT1_2);
3798 pattern[3].y = pattern[2].x = pattern[0].x = pattern[0].y = -r2;
3799 pattern[3].x = pattern[2].y = pattern[1].y = pattern[1].x = r2;
3800 } else {
3801 pattern[0].y = pattern[1].y = pattern[2].x = pattern[3].x = 0;
3802 pattern[0].x = pattern[2].y = -r2;
3803 pattern[1].x = pattern[3].y = r2;
3804 }
3805 segArr = Blt_Malloc(nSymbolPts * 2 * sizeof(XSegment));
3806 segPtr = segArr;
3807 if (linePtr->symbolInterval > 0) {
3808 count = 0;
3809 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
3810 pointPtr < endPtr; pointPtr++) {
3811 if (DRAW_SYMBOL(linePtr)) {
3812 segPtr->x1 = pattern[0].x + (short int)pointPtr->x;
3813 segPtr->y1 = pattern[0].y + (short int)pointPtr->y;
3814 segPtr->x2 = pattern[1].x + (short int)pointPtr->x;
3815 segPtr->y2 = pattern[1].y + (short int)pointPtr->y;
3816 segPtr++;
3817 segPtr->x1 = pattern[2].x + (short int)pointPtr->x;
3818 segPtr->y1 = pattern[2].y + (short int)pointPtr->y;
3819 segPtr->x2 = pattern[3].x + (short int)pointPtr->x;
3820 segPtr->y2 = pattern[3].y + (short int)pointPtr->y;
3821 segPtr++;
3822 count++;
3823 }
3824 linePtr->symbolCounter++;
3825 }
3826 } else {
3827 count = nSymbolPts;
3828 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
3829 pointPtr < endPtr; pointPtr++) {
3830 segPtr->x1 = pattern[0].x + (short int)pointPtr->x;
3831 segPtr->y1 = pattern[0].y + (short int)pointPtr->y;
3832 segPtr->x2 = pattern[1].x + (short int)pointPtr->x;
3833 segPtr->y2 = pattern[1].y + (short int)pointPtr->y;
3834 segPtr++;
3835 segPtr->x1 = pattern[2].x + (short int)pointPtr->x;
3836 segPtr->y1 = pattern[2].y + (short int)pointPtr->y;
3837 segPtr->x2 = pattern[3].x + (short int)pointPtr->x;
3838 segPtr->y2 = pattern[3].y + (short int)pointPtr->y;
3839 segPtr++;
3840 }
3841 }
3842 nSegs = count * 2;
3843 /* Always draw skinny symbols regardless of the outline width */
3844 reqSize = MAX_DRAWSEGMENTS(graphPtr->display);
3845 for (i = 0; i < nSegs; i += reqSize) {
3846 chunk = ((i + reqSize) > nSegs) ? (nSegs - i) : reqSize;
3847 XDrawSegments(graphPtr->display, drawable,
3848 penPtr->symbol.outlineGC, segArr + i, chunk);
3849 }
3850 Blt_Free(segArr);
3851 }
3852 break;
3853
3854 case SYMBOL_PLUS:
3855 case SYMBOL_CROSS:
3856 {
3857 XPoint *polygon;
3858 register XPoint *p;
3859 int d; /* Small delta for cross/plus thickness */
3860
3861 d = (r2 / 3);
3862
3863 /*
3864 *
3865 * 2 3 The plus/cross symbol is a closed polygon
3866 * of 12 points. The diagram to the left
3867 * 0,12 1 4 5 represents the positions of the points
3868 * x,y which are computed below. The extra
3869 * 11 10 7 6 (thirteenth) point connects the first and
3870 * last points.
3871 * 9 8
3872 */
3873
3874 pattern[0].x = pattern[11].x = pattern[12].x = -r2;
3875 pattern[2].x = pattern[1].x = pattern[10].x = pattern[9].x = -d;
3876 pattern[3].x = pattern[4].x = pattern[7].x = pattern[8].x = d;
3877 pattern[5].x = pattern[6].x = r2;
3878 pattern[2].y = pattern[3].y = -r2;
3879 pattern[0].y = pattern[1].y = pattern[4].y = pattern[5].y =
3880 pattern[12].y = -d;
3881 pattern[11].y = pattern[10].y = pattern[7].y = pattern[6].y = d;
3882 pattern[9].y = pattern[8].y = r2;
3883
3884 if (penPtr->symbol.type == SYMBOL_CROSS) {
3885 double dx, dy;
3886
3887 /* For the cross symbol, rotate the points by 45 degrees. */
3888 for (n = 0; n < 12; n++) {
3889 dx = (double)pattern[n].x * M_SQRT1_2;
3890 dy = (double)pattern[n].y * M_SQRT1_2;
3891 pattern[n].x = Round(dx - dy);
3892 pattern[n].y = Round(dx + dy);
3893 }
3894 pattern[12] = pattern[0];
3895 }
3896 polygon = Blt_Malloc(nSymbolPts * 13 * sizeof(XPoint));
3897 p = polygon;
3898 if (linePtr->symbolInterval > 0) {
3899 count = 0;
3900 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
3901 pointPtr < endPtr; pointPtr++) {
3902 if (DRAW_SYMBOL(linePtr)) {
3903 for (n = 0; n < 13; n++) {
3904 p->x = pattern[n].x + (short int)pointPtr->x;
3905 p->y = pattern[n].y + (short int)pointPtr->y;
3906 p++;
3907 }
3908 count++;
3909 }
3910 linePtr->symbolCounter++;
3911 }
3912 } else {
3913 count = nSymbolPts;
3914 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
3915 pointPtr < endPtr; pointPtr++) {
3916 for (n = 0; n < 13; n++) {
3917 p->x = pattern[n].x + (short int)pointPtr->x;
3918 p->y = pattern[n].y + (short int)pointPtr->y;
3919 p++;
3920 }
3921 }
3922 }
3923 if (penPtr->symbol.fillGC != NULL) {
3924 for (p = polygon, i = 0; i < count; i++, p += 13) {
3925 XFillPolygon(graphPtr->display, drawable,
3926 penPtr->symbol.fillGC, p, 13, Complex, CoordModeOrigin);
3927 }
3928 }
3929 if (penPtr->symbol.outlineWidth > 0) {
3930 for (p = polygon, i = 0; i < count; i++, p += 13) {
3931 XDrawLines(graphPtr->display, drawable,
3932 penPtr->symbol.outlineGC, p, 13, CoordModeOrigin);
3933 }
3934 }
3935 Blt_Free(polygon);
3936 }
3937 break;
3938
3939 case SYMBOL_DIAMOND:
3940 {
3941 XPoint *polygon;
3942 register XPoint *p;
3943
3944 /*
3945 *
3946 * The plus symbol is a closed polygon
3947 * 1 of 4 points. The diagram to the left
3948 * represents the positions of the points
3949 * 0,4 x,y 2 which are computed below. The extra
3950 * (fifth) point connects the first and
3951 * 3 last points.
3952 *
3953 */
3954 pattern[1].y = pattern[0].x = -r1;
3955 pattern[2].y = pattern[3].x = pattern[0].y = pattern[1].x = 0;
3956 pattern[3].y = pattern[2].x = r1;
3957 pattern[4] = pattern[0];
3958
3959 polygon = Blt_Malloc(nSymbolPts * 5 * sizeof(XPoint));
3960 p = polygon;
3961 if (linePtr->symbolInterval > 0) {
3962 count = 0;
3963 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
3964 pointPtr < endPtr; pointPtr++) {
3965 if (DRAW_SYMBOL(linePtr)) {
3966 for (n = 0; n < 5; n++, p++) {
3967 p->x = pattern[n].x + (short int)pointPtr->x;
3968 p->y = pattern[n].y + (short int)pointPtr->y;
3969 }
3970 count++;
3971 }
3972 linePtr->symbolCounter++;
3973 }
3974 } else {
3975 count = nSymbolPts;
3976 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
3977 pointPtr < endPtr; pointPtr++) {
3978 for (n = 0; n < 5; n++, p++) {
3979 p->x = pattern[n].x + (short int)pointPtr->x;
3980 p->y = pattern[n].y + (short int)pointPtr->y;
3981 }
3982 }
3983 }
3984 if (penPtr->symbol.fillGC != NULL) {
3985 for (p = polygon, i = 0; i < count; i++, p += 5) {
3986 XFillPolygon(graphPtr->display, drawable,
3987 penPtr->symbol.fillGC, p, 5, Convex, CoordModeOrigin);
3988
3989 }
3990 }
3991 if (penPtr->symbol.outlineWidth > 0) {
3992 for (p = polygon, i = 0; i < count; i++, p += 5) {
3993 XDrawLines(graphPtr->display, drawable,
3994 penPtr->symbol.outlineGC, p, 5, CoordModeOrigin);
3995 }
3996 }
3997 Blt_Free(polygon);
3998 }
3999 break;
4000
4001 case SYMBOL_TRIANGLE:
4002 case SYMBOL_ARROW:
4003 {
4004 XPoint *polygon;
4005 register XPoint *p;
4006 double b;
4007 int b2, h1, h2;
4008 #define H_RATIO 1.1663402261671607
4009 #define B_RATIO 1.3467736870885982
4010 #define TAN30 0.57735026918962573
4011 #define COS30 0.86602540378443871
4012
4013 b = Round(size * B_RATIO * 0.7);
4014 b2 = Round(b * 0.5);
4015 h2 = Round(TAN30 * b2);
4016 h1 = Round(b2 / COS30);
4017 /*
4018 *
4019 * The triangle symbol is a closed polygon
4020 * 0,3 of 3 points. The diagram to the left
4021 * represents the positions of the points
4022 * x,y which are computed below. The extra
4023 * (fourth) point connects the first and
4024 * 2 1 last points.
4025 *
4026 */
4027
4028 if (penPtr->symbol.type == SYMBOL_ARROW) {
4029 pattern[3].x = pattern[0].x = 0;
4030 pattern[3].y = pattern[0].y = h1;
4031 pattern[1].x = b2;
4032 pattern[2].y = pattern[1].y = -h2;
4033 pattern[2].x = -b2;
4034 } else {
4035 pattern[3].x = pattern[0].x = 0;
4036 pattern[3].y = pattern[0].y = -h1;
4037 pattern[1].x = b2;
4038 pattern[2].y = pattern[1].y = h2;
4039 pattern[2].x = -b2;
4040 }
4041 polygon = Blt_Malloc(nSymbolPts * 4 * sizeof(XPoint));
4042 p = polygon;
4043 if (linePtr->symbolInterval > 0) {
4044 count = 0;
4045 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
4046 pointPtr < endPtr; pointPtr++) {
4047 if (DRAW_SYMBOL(linePtr)) {
4048 for (n = 0; n < 4; n++) {
4049 p->x = pattern[n].x + (short int)pointPtr->x;
4050 p->y = pattern[n].y + (short int)pointPtr->y;
4051 p++;
4052 }
4053 count++;
4054 }
4055 linePtr->symbolCounter++;
4056 }
4057 } else {
4058 count = nSymbolPts;
4059 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
4060 pointPtr < endPtr; pointPtr++) {
4061 for (n = 0; n < 4; n++) {
4062 p->x = pattern[n].x + (short int)pointPtr->x;
4063 p->y = pattern[n].y + (short int)pointPtr->y;
4064 p++;
4065 }
4066 }
4067 }
4068 if (penPtr->symbol.fillGC != NULL) {
4069 for (p = polygon, i = 0; i < count; i++, p += 4) {
4070 XFillPolygon(graphPtr->display, drawable,
4071 penPtr->symbol.fillGC, p, 4, Convex, CoordModeOrigin);
4072 }
4073 }
4074 if (penPtr->symbol.outlineWidth > 0) {
4075 for (p = polygon, i = 0; i < count; i++, p += 4) {
4076 XDrawLines(graphPtr->display, drawable,
4077 penPtr->symbol.outlineGC, p, 4, CoordModeOrigin);
4078 }
4079 }
4080 Blt_Free(polygon);
4081 }
4082 break;
4083 case SYMBOL_BITMAP:
4084 {
4085 Pixmap bitmap, mask;
4086 int width, height, bmWidth, bmHeight;
4087 double scale, sx, sy;
4088 int dx, dy;
4089 register int x, y;
4090
4091 Tk_SizeOfBitmap(graphPtr->display, penPtr->symbol.bitmap,
4092 &width, &height);
4093 mask = None;
4094
4095 /*
4096 * Compute the size of the scaled bitmap. Stretch the
4097 * bitmap to fit a nxn bounding box.
4098 */
4099 sx = (double)size / (double)width;
4100 sy = (double)size / (double)height;
4101 scale = MIN(sx, sy);
4102 bmWidth = (int)(width * scale);
4103 bmHeight = (int)(height * scale);
4104
4105 XSetClipMask(graphPtr->display, penPtr->symbol.outlineGC, None);
4106 if (penPtr->symbol.mask != None) {
4107 mask = Blt_ScaleBitmap(graphPtr->tkwin, penPtr->symbol.mask,
4108 width, height, bmWidth, bmHeight);
4109 XSetClipMask(graphPtr->display, penPtr->symbol.outlineGC,
4110 mask);
4111 }
4112 bitmap = Blt_ScaleBitmap(graphPtr->tkwin, penPtr->symbol.bitmap,
4113 width, height, bmWidth, bmHeight);
4114 if (penPtr->symbol.fillGC == NULL) {
4115 XSetClipMask(graphPtr->display, penPtr->symbol.outlineGC,
4116 bitmap);
4117 }
4118 dx = bmWidth / 2;
4119 dy = bmHeight / 2;
4120 if (linePtr->symbolInterval > 0) {
4121 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
4122 pointPtr < endPtr; pointPtr++) {
4123 if (DRAW_SYMBOL(linePtr)) {
4124 x = (int)pointPtr->x - dx;
4125 y = (int)pointPtr->y - dy;
4126 if ((penPtr->symbol.fillGC == NULL) || (mask != None)) {
4127 XSetClipOrigin(graphPtr->display,
4128 penPtr->symbol.outlineGC, x, y);
4129 }
4130 XCopyPlane(graphPtr->display, bitmap, drawable,
4131 penPtr->symbol.outlineGC, 0, 0, bmWidth, bmHeight,
4132 x, y, 1);
4133 }
4134 linePtr->symbolCounter++;
4135 }
4136 } else {
4137 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
4138 pointPtr < endPtr; pointPtr++) {
4139 x = (int)pointPtr->x - dx;
4140 y = (int)pointPtr->y - dy;
4141 if ((penPtr->symbol.fillGC == NULL) || (mask != None)) {
4142 XSetClipOrigin(graphPtr->display,
4143 penPtr->symbol.outlineGC, x, y);
4144 }
4145 XCopyPlane(graphPtr->display, bitmap, drawable,
4146 penPtr->symbol.outlineGC, 0, 0, bmWidth, bmHeight,
4147 x, y, 1);
4148 }
4149 }
4150 Tk_FreePixmap(graphPtr->display, bitmap);
4151 if (mask != None) {
4152 Tk_FreePixmap(graphPtr->display, mask);
4153 }
4154 }
4155 break;
4156 }
4157 }
4158
4159 /*
4160 * -----------------------------------------------------------------
4161 *
4162 * DrawSymbol --
4163 *
4164 * Draw the symbol centered at the each given x,y coordinate.
4165 *
4166 * Results:
4167 * None.
4168 *
4169 * Side Effects:
4170 * Draws a symbol at the coordinate given.
4171 *
4172 * -----------------------------------------------------------------
4173 */
4174 static void
4175 DrawSymbol(graphPtr, drawable, elemPtr, x, y, size)
4176 Graph *graphPtr; /* Graph widget record */
4177 Drawable drawable; /* Pixmap or window to draw into */
4178 Element *elemPtr; /* Line element information */
4179 int x, y; /* Center position of symbol */
4180 int size; /* Size of symbol. */
4181 {
4182 Line *linePtr = (Line *)elemPtr;
4183 LinePen *penPtr = linePtr->normalPenPtr;
4184
4185 if (penPtr->traceWidth > 0) {
4186 /*
4187 * Draw an extra line offset by one pixel from the previous to
4188 * give a thicker appearance. This is only for the legend
4189 * entry. This routine is never called for drawing the actual
4190 * line segments.
4191 */
4192 XDrawLine(graphPtr->display, drawable, penPtr->traceGC, x - size,
4193 y, x + size, y);
4194 XDrawLine(graphPtr->display, drawable, penPtr->traceGC, x - size,
4195 y + 1, x + size, y + 1);
4196 }
4197 if (penPtr->symbol.type != SYMBOL_NONE) {
4198 Point2D point;
4199
4200 point.x = x, point.y = y;
4201 DrawSymbols(graphPtr, drawable, linePtr, linePtr->normalPenPtr, size,
4202 1, &point);
4203 }
4204 }
4205
4206 #ifdef WIN32
4207
4208 static void
4209 DrawTraces(
4210 Graph *graphPtr,
4211 Drawable drawable, /* Pixmap or window to draw into */
4212 Line *linePtr,
4213 LinePen *penPtr)
4214 {
4215 Blt_ChainLink *linkPtr;
4216 HBRUSH brush, oldBrush;
4217 HDC dc;
4218 HPEN pen, oldPen;
4219 POINT *points;
4220 TkWinDCState state;
4221 Trace *tracePtr;
4222 int j;
4223 int nPoints, remaining;
4224 register POINT *p;
4225 register int count;
4226
4227 /*
4228 * Depending if the line is wide (> 1 pixel), arbitrarily break
4229 * the line in sections of 100 points. This bit of weirdness has
4230 * to do with wide geometric pens. The longer the polyline, the
4231 * slower it draws. The trade off is that we lose dash and cap
4232 * uniformity for unbearably slow polyline draws.
4233 */
4234 if (penPtr->traceGC->line_width > 1) {
4235 nPoints = 100;
4236 } else {
4237 nPoints = Blt_MaxRequestSize(graphPtr->display, sizeof(POINT)) - 1;
4238 }
4239 points = Blt_Malloc((nPoints + 1) * sizeof(POINT));
4240
4241 dc = TkWinGetDrawableDC(graphPtr->display, drawable, &state);
4242
4243 pen = Blt_GCToPen(dc, penPtr->traceGC);
4244 oldPen = SelectPen(dc, pen);
4245 brush = CreateSolidBrush(penPtr->traceGC->foreground);
4246 oldBrush = SelectBrush(dc, brush);
4247 SetROP2(dc, tkpWinRopModes[penPtr->traceGC->function]);
4248
4249 for (linkPtr = Blt_ChainFirstLink(linePtr->traces); linkPtr != NULL;
4250 linkPtr = Blt_ChainNextLink(linkPtr)) {
4251 tracePtr = Blt_ChainGetValue(linkPtr);
4252
4253 /*
4254 * If the trace has to be split into separate XDrawLines
4255 * calls, then the end point of the current trace is also the
4256 * starting point of the new split.
4257 */
4258
4259 /* Step 1. Convert and draw the first section of the trace.
4260 * It may contain the entire trace. */
4261
4262 for (p = points, count = 0; count < MIN(nPoints, tracePtr->nScreenPts);
4263 count++, p++) {
4264 p->x = (int)tracePtr->screenPts[count].x;
4265 p->y = (int)tracePtr->screenPts[count].y;
4266 }
4267 Polyline(dc, points, count);
4268
4269 /* Step 2. Next handle any full-size chunks left. */
4270
4271 while ((count + nPoints) < tracePtr->nScreenPts) {
4272 /* Start with the last point of the previous trace. */
4273 points[0].x = points[nPoints - 1].x;
4274 points[0].y = points[nPoints - 1].y;
4275
4276 for (p = points + 1, j = 0; j < nPoints; j++, count++, p++) {
4277 p->x = (int)tracePtr->screenPts[count].x;
4278 p->y = (int)tracePtr->screenPts[count].y;
4279 }
4280 Polyline(dc, points, nPoints + 1);
4281 }
4282
4283 /* Step 3. Convert and draw the remaining points. */
4284
4285 remaining = tracePtr->nScreenPts - count;
4286 if (remaining > 0) {
4287 /* Start with the last point of the previous trace. */
4288 points[0].x = points[nPoints - 1].x;
4289 points[0].y = points[nPoints - 1].y;
4290
4291 for (p = points + 1; count < tracePtr->nScreenPts; count++, p++) {
4292 p->x = (int)tracePtr->screenPts[count].x;
4293 p->y = (int)tracePtr->screenPts[count].y;
4294 }
4295 Polyline(dc, points, remaining + 1);
4296 }
4297 }
4298 Blt_Free(points);
4299 DeletePen(SelectPen(dc, oldPen));
4300 DeleteBrush(SelectBrush(dc, oldBrush));
4301 TkWinReleaseDrawableDC(drawable, dc, &state);
4302 }
4303
4304 #else
4305
4306 static void
4307 DrawTraces(graphPtr, drawable, linePtr, penPtr)
4308 Graph *graphPtr;
4309 Drawable drawable; /* Pixmap or window to draw into */
4310 Line *linePtr;
4311 LinePen *penPtr;
4312 {
4313 Blt_ChainLink *linkPtr;
4314 Trace *tracePtr;
4315 XPoint *points;
4316 int j;
4317 int nPoints, remaining;
4318 register XPoint *p;
4319 register int count;
4320
4321 nPoints = Blt_MaxRequestSize(graphPtr->display, sizeof(XPoint)) - 1;
4322 points = Blt_Malloc((nPoints + 1) * sizeof(XPoint));
4323
4324 for (linkPtr = Blt_ChainFirstLink(linePtr->traces); linkPtr != NULL;
4325 linkPtr = Blt_ChainNextLink(linkPtr)) {
4326 int n;
4327
4328 tracePtr = Blt_ChainGetValue(linkPtr);
4329
4330 /*
4331 * If the trace has to be split into separate XDrawLines
4332 * calls, then the end point of the current trace is also the
4333 * starting point of the new split.
4334 */
4335 /* Step 1. Convert and draw the first section of the trace.
4336 * It may contain the entire trace. */
4337
4338 n = MIN(nPoints, tracePtr->nScreenPts);
4339 for (p = points, count = 0; count < n; count++, p++) {
4340 p->x = (short int)tracePtr->screenPts[count].x;
4341 p->y = (short int)tracePtr->screenPts[count].y;
4342 }
4343 XDrawLines(graphPtr->display, drawable, penPtr->traceGC, points,
4344 count, CoordModeOrigin);
4345
4346 /* Step 2. Next handle any full-size chunks left. */
4347
4348 while ((count + nPoints) < tracePtr->nScreenPts) {
4349 /* Start with the last point of the previous trace. */
4350 points[0].x = points[nPoints - 1].x;
4351 points[0].y = points[nPoints - 1].y;
4352
4353 for (p = points + 1, j = 0; j < nPoints; j++, count++, p++) {
4354 p->x = (short int)tracePtr->screenPts[count].x;
4355 p->y = (short int)tracePtr->screenPts[count].y;
4356 }
4357 XDrawLines(graphPtr->display, drawable, penPtr->traceGC, points,
4358 nPoints + 1, CoordModeOrigin);
4359 }
4360
4361 /* Step 3. Convert and draw the remaining points. */
4362
4363 remaining = tracePtr->nScreenPts - count;
4364 if (remaining > 0) {
4365 /* Start with the last point of the previous trace. */
4366 points[0].x = points[nPoints - 1].x;
4367 points[0].y = points[nPoints - 1].y;
4368 for (p = points + 1; count < tracePtr->nScreenPts; count++, p++) {
4369 p->x = (short int)tracePtr->screenPts[count].x;
4370 p->y = (short int)tracePtr->screenPts[count].y;
4371 }
4372 XDrawLines(graphPtr->display, drawable, penPtr->traceGC, points,
4373 remaining + 1, CoordModeOrigin);
4374 }
4375 }
4376 Blt_Free(points);
4377 }
4378 #endif /* WIN32 */
4379
4380 static void
4381 DrawValues(graphPtr, drawable, linePtr, penPtr, nSymbolPts, symbolPts,
4382 pointToData)
4383 Graph *graphPtr;
4384 Drawable drawable;
4385 Line *linePtr;
4386 LinePen *penPtr;
4387 int nSymbolPts;
4388 Point2D *symbolPts;
4389 int *pointToData;
4390 {
4391 Point2D *pointPtr, *endPtr;
4392 int count;
4393 char string[TCL_DOUBLE_SPACE * 2 + 2];
4394 char *fmt;
4395 double x, y;
4396
4397 fmt = penPtr->valueFormat;
4398 if (fmt == NULL) {
4399 fmt = "%g";
4400 }
4401 count = 0;
4402 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
4403 pointPtr < endPtr; pointPtr++) {
4404 x = linePtr->x.valueArr[pointToData[count]];
4405 y = linePtr->y.valueArr[pointToData[count]];
4406 count++;
4407 if (penPtr->valueShow == SHOW_X) {
4408 sprintf(string, fmt, x);
4409 } else if (penPtr->valueShow == SHOW_Y) {
4410 sprintf(string, fmt, y);
4411 } else if (penPtr->valueShow == SHOW_BOTH) {
4412 sprintf(string, fmt, x);
4413 strcat(string, ",");
4414 sprintf(string + strlen(string), fmt, y);
4415 }
4416 Blt_DrawText(graphPtr->tkwin, drawable, string, &(penPtr->valueStyle),
4417 (int)pointPtr->x, (int)pointPtr->y);
4418 }
4419 }
4420
4421
4422 /*
4423 *----------------------------------------------------------------------
4424 *
4425 * DrawActiveLine --
4426 *
4427 * Draws the connected line(s) representing the element. If the
4428 * line is made up of non-line symbols and the line width
4429 * parameter has been set (linewidth > 0), the element will also
4430 * be drawn as a line (with the linewidth requested). The line
4431 * may consist of separate line segments.
4432 *
4433 * Results:
4434 * None.
4435 *
4436 * Side effects:
4437 * X drawing commands are output.
4438 *
4439 *----------------------------------------------------------------------
4440 */
4441 static void
4442 DrawActiveLine(graphPtr, drawable, elemPtr)
4443 Graph *graphPtr; /* Graph widget record */
4444 Drawable drawable; /* Pixmap or window to draw into */
4445 Element *elemPtr; /* Element to be drawn */
4446 {
4447 Line *linePtr = (Line *)elemPtr;
4448 LinePen *penPtr = linePtr->activePenPtr;
4449 int symbolSize;
4450
4451 if (penPtr == NULL) {
4452 return;
4453 }
4454 symbolSize = ScaleSymbol(elemPtr, linePtr->activePenPtr->symbol.size);
4455
4456 /*
4457 * nActiveIndices
4458 * > 0 Some points are active. Uses activeArr.
4459 * < 0 All points are active.
4460 * == 0 No points are active.
4461 */
4462 if (linePtr->nActiveIndices > 0) {
4463 if (linePtr->flags & ACTIVE_PENDING) {
4464 MapActiveSymbols(graphPtr, linePtr);
4465 }
4466 if (penPtr->symbol.type != SYMBOL_NONE) {
4467 DrawSymbols(graphPtr, drawable, linePtr, penPtr, symbolSize,
4468 linePtr->nActivePts, linePtr->activePts);
4469 }
4470 if (penPtr->valueShow != SHOW_NONE) {
4471 DrawValues(graphPtr, drawable, linePtr, penPtr,
4472 linePtr->nActivePts, linePtr->activePts,
4473 linePtr->activeToData);
4474 }
4475 } else if (linePtr->nActiveIndices < 0) {
4476 if (penPtr->traceWidth > 0) {
4477 if (linePtr->nStrips > 0) {
4478 Blt_Draw2DSegments(graphPtr->display, drawable,
4479 penPtr->traceGC, linePtr->strips, linePtr->nStrips);
4480 } else if (Blt_ChainGetLength(linePtr->traces) > 0) {
4481 DrawTraces(graphPtr, drawable, linePtr, penPtr);
4482 }
4483 }
4484 if (penPtr->symbol.type != SYMBOL_NONE) {
4485 DrawSymbols(graphPtr, drawable, linePtr, penPtr, symbolSize,
4486 linePtr->nSymbolPts, linePtr->symbolPts);
4487 }
4488 if (penPtr->valueShow != SHOW_NONE) {
4489 DrawValues(graphPtr, drawable, linePtr, penPtr,
4490 linePtr->nSymbolPts, linePtr->symbolPts,
4491 linePtr->symbolToData);
4492 }
4493 }
4494 }
4495
4496 /*
4497 *----------------------------------------------------------------------
4498 *
4499 * DrawNormalLine --
4500 *
4501 * Draws the connected line(s) representing the element. If the
4502 * line is made up of non-line symbols and the line width parameter
4503 * has been set (linewidth > 0), the element will also be drawn as
4504 * a line (with the linewidth requested). The line may consist of
4505 * separate line segments.
4506 *
4507 * Results:
4508 * None.
4509 *
4510 * Side effects:
4511 * X drawing commands are output.
4512 *
4513 *----------------------------------------------------------------------
4514 */
4515 static void
4516 DrawNormalLine(graphPtr, drawable, elemPtr)
4517 Graph *graphPtr; /* Graph widget record */
4518 Drawable drawable; /* Pixmap or window to draw into */
4519 Element *elemPtr; /* Element to be drawn */
4520 {
4521 Line *linePtr = (Line *)elemPtr;
4522 LinePen *penPtr;
4523 Blt_ChainLink *linkPtr;
4524 register LinePenStyle *stylePtr;
4525 unsigned int count;
4526
4527 /* Fill area under the curve */
4528 if (linePtr->fillPts != NULL) {
4529 XPoint *points;
4530 Point2D *endPtr, *pointPtr;
4531
4532 points = Blt_Malloc(sizeof(XPoint) * linePtr->nFillPts);
4533 count = 0;
4534 for(pointPtr = linePtr->fillPts,
4535 endPtr = linePtr->fillPts + linePtr->nFillPts;
4536 pointPtr < endPtr; pointPtr++) {
4537 points[count].x = (short int)pointPtr->x;
4538 points[count].y = (short int)pointPtr->y;
4539 count++;
4540 }
4541 if (Blt_HasTile(linePtr->fillTile)) {
4542 Blt_SetTileOrigin(graphPtr->tkwin, linePtr->fillTile, 0, 0);
4543 Blt_TilePolygon(graphPtr->tkwin, drawable, linePtr->fillTile,
4544 points, linePtr->nFillPts);
4545 } else if (linePtr->fillStipple != None) {
4546 XFillPolygon(graphPtr->display, drawable, linePtr->fillGC,
4547 points, linePtr->nFillPts, Complex, CoordModeOrigin);
4548 }
4549 Blt_Free(points);
4550 }
4551
4552 /* Lines: stripchart segments or graph traces. */
4553
4554 if (linePtr->nStrips > 0) {
4555 for (linkPtr = Blt_ChainFirstLink(linePtr->palette); linkPtr != NULL;
4556 linkPtr = Blt_ChainNextLink(linkPtr)) {
4557 stylePtr = Blt_ChainGetValue(linkPtr);
4558 penPtr = stylePtr->penPtr;
4559 if ((stylePtr->nStrips > 0) && (penPtr->traceWidth > 0)) {
4560 Blt_Draw2DSegments(graphPtr->display, drawable,
4561 penPtr->traceGC, stylePtr->strips, stylePtr->nStrips);
4562 }
4563 }
4564 } else if ((Blt_ChainGetLength(linePtr->traces) > 0) &&
4565 (linePtr->normalPenPtr->traceWidth > 0)) {
4566 DrawTraces(graphPtr, drawable, linePtr, linePtr->normalPenPtr);
4567 }
4568
4569 if (linePtr->reqMaxSymbols > 0) {
4570 int total;
4571
4572 total = 0;
4573 for (linkPtr = Blt_ChainFirstLink(linePtr->palette); linkPtr != NULL;
4574 linkPtr = Blt_ChainNextLink(linkPtr)) {
4575 stylePtr = Blt_ChainGetValue(linkPtr);
4576 total += stylePtr->nSymbolPts;
4577 }
4578 linePtr->symbolInterval = total / linePtr->reqMaxSymbols;
4579 linePtr->symbolCounter = 0;
4580 }
4581
4582 /* Symbols, error bars, values. */
4583
4584 count = 0;
4585 for (linkPtr = Blt_ChainFirstLink(linePtr->palette); linkPtr != NULL;
4586 linkPtr = Blt_ChainNextLink(linkPtr)) {
4587 stylePtr = Blt_ChainGetValue(linkPtr);
4588 penPtr = stylePtr->penPtr;
4589 if ((stylePtr->xErrorBarCnt > 0) && (penPtr->errorBarShow & SHOW_X)) {
4590 Blt_Draw2DSegments(graphPtr->display, drawable, penPtr->errorBarGC,
4591 stylePtr->xErrorBars, stylePtr->xErrorBarCnt);
4592 }
4593 if ((stylePtr->yErrorBarCnt > 0) && (penPtr->errorBarShow & SHOW_Y)) {
4594 Blt_Draw2DSegments(graphPtr->display, drawable, penPtr->errorBarGC,
4595 stylePtr->yErrorBars, stylePtr->yErrorBarCnt);
4596 }
4597 if ((stylePtr->nSymbolPts > 0) &&
4598 (penPtr->symbol.type != SYMBOL_NONE)) {
4599 DrawSymbols(graphPtr, drawable, linePtr, penPtr,
4600 stylePtr->symbolSize, stylePtr->nSymbolPts,
4601 stylePtr->symbolPts);
4602 }
4603 if (penPtr->valueShow != SHOW_NONE) {
4604 DrawValues(graphPtr, drawable, linePtr, penPtr,
4605 stylePtr->nSymbolPts, stylePtr->symbolPts,
4606 linePtr->symbolToData + count);
4607 }
4608 count += stylePtr->nSymbolPts;
4609 }
4610 linePtr->symbolInterval = 0;
4611 }
4612
4613 /*
4614 * -----------------------------------------------------------------
4615 *
4616 * GetSymbolPostScriptInfo --
4617 *
4618 * Set up the PostScript environment with the macros and
4619 * attributes needed to draw the symbols of the element.
4620 *
4621 * Results:
4622 * None.
4623 *
4624 * -----------------------------------------------------------------
4625 */
4626 static void
4627 GetSymbolPostScriptInfo(graphPtr, psToken, penPtr, size)
4628 Graph *graphPtr;
4629 PsToken psToken;
4630 LinePen *penPtr;
4631 int size;
4632 {
4633 XColor *outlineColor, *fillColor, *defaultColor;
4634
4635 /* Set line and foreground attributes */
4636 outlineColor = penPtr->symbol.outlineColor;
4637 fillColor = penPtr->symbol.fillColor;
4638 defaultColor = penPtr->traceColor;
4639
4640 if (fillColor == COLOR_DEFAULT) {
4641 fillColor = defaultColor;
4642 }
4643 if (outlineColor == COLOR_DEFAULT) {
4644 outlineColor = defaultColor;
4645 }
4646 if (penPtr->symbol.type == SYMBOL_NONE) {
4647 Blt_LineAttributesToPostScript(psToken, defaultColor,
4648 penPtr->traceWidth + 2, &(penPtr->traceDashes),
4649 CapButt, JoinMiter);
4650 } else {
4651 Blt_LineWidthToPostScript(psToken, penPtr->symbol.outlineWidth);
4652 Blt_LineDashesToPostScript(psToken, (Blt_Dashes *)NULL);
4653 }
4654
4655 /*
4656 * Build a PostScript procedure to draw the symbols. For bitmaps,
4657 * paint both the bitmap and its mask. Otherwise fill and stroke
4658 * the path formed already.
4659 */
4660 Blt_AppendToPostScript(psToken, "\n/DrawSymbolProc {\n", (char *)NULL);
4661 switch (penPtr->symbol.type) {
4662 case SYMBOL_NONE:
4663 break; /* Do nothing */
4664 case SYMBOL_BITMAP:
4665 {
4666 int width, height;
4667 double sx, sy, scale;
4668
4669 /*
4670 * Compute how much to scale the bitmap. Don't let the
4671 * scaled bitmap exceed the bounding square for the
4672 * symbol.
4673 */
4674 Tk_SizeOfBitmap(graphPtr->display, penPtr->symbol.bitmap,
4675 &width, &height);
4676 sx = (double)size / (double)width;
4677 sy = (double)size / (double)height;
4678 scale = MIN(sx, sy);
4679
4680 if ((penPtr->symbol.mask != None) && (fillColor != NULL)) {
4681 Blt_AppendToPostScript(psToken,
4682 "\n % Bitmap mask is \"",
4683 Tk_NameOfBitmap(graphPtr->display, penPtr->symbol.mask),
4684 "\"\n\n ", (char *)NULL);
4685 Blt_BackgroundToPostScript(psToken, fillColor);
4686 Blt_BitmapToPostScript(psToken, graphPtr->display,
4687 penPtr->symbol.mask, scale, scale);
4688 }
4689 Blt_AppendToPostScript(psToken,
4690 "\n % Bitmap symbol is \"",
4691 Tk_NameOfBitmap(graphPtr->display, penPtr->symbol.bitmap),
4692 "\"\n\n ", (char *)NULL);
4693 Blt_ForegroundToPostScript(psToken, outlineColor);
4694 Blt_BitmapToPostScript(psToken, graphPtr->display,
4695 penPtr->symbol.bitmap, scale, scale);
4696 }
4697 break;
4698 default:
4699 if (fillColor != NULL) {
4700 Blt_AppendToPostScript(psToken, " ", (char *)NULL);
4701 Blt_BackgroundToPostScript(psToken, fillColor);
4702 Blt_AppendToPostScript(psToken, " Fill\n", (char *)NULL);
4703 }
4704 if ((outlineColor != NULL) && (penPtr->symbol.outlineWidth > 0)) {
4705 Blt_AppendToPostScript(psToken, " ", (char *)NULL);
4706 Blt_ForegroundToPostScript(psToken, outlineColor);
4707 Blt_AppendToPostScript(psToken, " stroke\n", (char *)NULL);
4708 }
4709 break;
4710 }
4711 Blt_AppendToPostScript(psToken, "} def\n\n", (char *)NULL);
4712 }
4713
4714 /*
4715 * -----------------------------------------------------------------
4716 *
4717 * SymbolsToPostScript --
4718 *
4719 * Draw a symbol centered at the given x,y window coordinate
4720 * based upon the element symbol type and size.
4721 *
4722 * Results:
4723 * None.
4724 *
4725 * Problems:
4726 * Most notable is the round-off errors generated when
4727 * calculating the centered position of the symbol.
4728 *
4729 * -----------------------------------------------------------------
4730 */
4731 static void
4732 SymbolsToPostScript(graphPtr, psToken, penPtr, size, nSymbolPts, symbolPts)
4733 Graph *graphPtr;
4734 PsToken psToken;
4735 LinePen *penPtr;
4736 int size;
4737 int nSymbolPts;
4738 Point2D *symbolPts;
4739 {
4740 double symbolSize;
4741 register Point2D *pointPtr, *endPtr;
4742 static char *symbolMacros[] =
4743 {
4744 "Li", "Sq", "Ci", "Di", "Pl", "Cr", "Sp", "Sc", "Tr", "Ar", "Bm",
4745 (char *)NULL,
4746 };
4747 GetSymbolPostScriptInfo(graphPtr, psToken, penPtr, size);
4748
4749 symbolSize = (double)size;
4750 switch (penPtr->symbol.type) {
4751 case SYMBOL_SQUARE:
4752 case SYMBOL_CROSS:
4753 case SYMBOL_PLUS:
4754 case SYMBOL_SCROSS:
4755 case SYMBOL_SPLUS:
4756 symbolSize = (double)Round(size * S_RATIO);
4757 break;
4758 case SYMBOL_TRIANGLE:
4759 case SYMBOL_ARROW:
4760 symbolSize = (double)Round(size * 0.7);
4761 break;
4762 case SYMBOL_DIAMOND:
4763 symbolSize = (double)Round(size * M_SQRT1_2);
4764 break;
4765
4766 default:
4767 break;
4768 }
4769 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
4770 pointPtr < endPtr; pointPtr++) {
4771 Blt_FormatToPostScript(psToken, "%g %g %g %s\n", pointPtr->x,
4772 pointPtr->y, symbolSize, symbolMacros[penPtr->symbol.type]);
4773 }
4774 }
4775
4776 /*
4777 * -----------------------------------------------------------------
4778 *
4779 * SymbolToPostScript --
4780 *
4781 * Draw the symbol centered at the each given x,y coordinate.
4782 *
4783 * Results:
4784 * None.
4785 *
4786 * Side Effects:
4787 * Draws a symbol at the coordinate given.
4788 *
4789 * -----------------------------------------------------------------
4790 */
4791 static void
4792 SymbolToPostScript(graphPtr, psToken, elemPtr, x, y, size)
4793 Graph *graphPtr; /* Graph widget record */
4794 PsToken psToken;
4795 Element *elemPtr; /* Line element information */
4796 double x, y; /* Center position of symbol */
4797 int size; /* Size of element */
4798 {
4799 Line *linePtr = (Line *)elemPtr;
4800 LinePen *penPtr = linePtr->normalPenPtr;
4801
4802 if (penPtr->traceWidth > 0) {
4803 /*
4804 * Draw an extra line offset by one pixel from the previous to
4805 * give a thicker appearance. This is only for the legend
4806 * entry. This routine is never called for drawing the actual
4807 * line segments.
4808 */
4809 Blt_LineAttributesToPostScript(psToken, penPtr->traceColor,
4810 penPtr->traceWidth + 2, &(penPtr->traceDashes), CapButt, JoinMiter);
4811 Blt_FormatToPostScript(psToken, "%g %g %d Li\n", x, y, size + size);
4812 }
4813 if (penPtr->symbol.type != SYMBOL_NONE) {
4814 Point2D point;
4815
4816 point.x = x, point.y = y;
4817 SymbolsToPostScript(graphPtr, psToken, penPtr, size, 1, &point);
4818 }
4819 }
4820
4821 static void
4822 SetLineAttributes(psToken, penPtr)
4823 PsToken psToken;
4824 LinePen *penPtr;
4825 {
4826 /* Set the attributes of the line (color, dashes, linewidth) */
4827 Blt_LineAttributesToPostScript(psToken, penPtr->traceColor,
4828 penPtr->traceWidth, &(penPtr->traceDashes), CapButt, JoinMiter);
4829 if ((LineIsDashed(penPtr->traceDashes)) &&
4830 (penPtr->traceOffColor != NULL)) {
4831 Blt_AppendToPostScript(psToken, "/DashesProc {\n gsave\n ",
4832 (char *)NULL);
4833 Blt_BackgroundToPostScript(psToken, penPtr->traceOffColor);
4834 Blt_AppendToPostScript(psToken, " ", (char *)NULL);
4835 Blt_LineDashesToPostScript(psToken, (Blt_Dashes *)NULL);
4836 Blt_AppendToPostScript(psToken, "stroke\n grestore\n} def\n",
4837 (char *)NULL);
4838 } else {
4839 Blt_AppendToPostScript(psToken, "/DashesProc {} def\n", (char *)NULL);
4840 }
4841 }
4842
4843 static void
4844 TracesToPostScript(psToken, linePtr, penPtr)
4845 PsToken psToken;
4846 Line *linePtr;
4847 LinePen *penPtr;
4848 {
4849 Blt_ChainLink *linkPtr;
4850 Trace *tracePtr;
4851 register Point2D *pointPtr, *endPtr;
4852 int count;
4853
4854 SetLineAttributes(psToken, penPtr);
4855 for (linkPtr = Blt_ChainFirstLink(linePtr->traces); linkPtr != NULL;
4856 linkPtr = Blt_ChainNextLink(linkPtr)) {
4857 tracePtr = Blt_ChainGetValue(linkPtr);
4858 if (tracePtr->nScreenPts <= 0) {
4859 continue;
4860 }
4861 #define PS_MAXPATH 1500 /* Maximum number of components in a PostScript
4862 * (level 1) path. */
4863 pointPtr = tracePtr->screenPts;
4864 Blt_FormatToPostScript(psToken, " newpath %g %g moveto\n",
4865 pointPtr->x,
4866 pointPtr->y);
4867 pointPtr++;
4868 count = 0;
4869 for (endPtr = tracePtr->screenPts + (tracePtr->nScreenPts - 1);
4870 pointPtr < endPtr; pointPtr++) {
4871 Blt_FormatToPostScript(psToken, " %g %g lineto\n",
4872 pointPtr->x,
4873 pointPtr->y);
4874 if ((count % PS_MAXPATH) == 0) {
4875 Blt_FormatToPostScript(psToken,
4876 "DashesProc stroke\n newpath %g %g moveto\n",
4877 pointPtr->x,
4878 pointPtr->y);
4879 }
4880 count++;
4881 }
4882 Blt_FormatToPostScript(psToken, " %g %g lineto\n",
4883 pointPtr->x,
4884 pointPtr->y);
4885 Blt_AppendToPostScript(psToken, "DashesProc stroke\n", (char *)NULL);
4886 }
4887 }
4888
4889
4890 static void
4891 ValuesToPostScript(psToken, linePtr, penPtr, nSymbolPts, symbolPts,
4892 pointToData)
4893 PsToken psToken;
4894 Line *linePtr;
4895 LinePen *penPtr;
4896 int nSymbolPts;
4897 Point2D *symbolPts;
4898 int *pointToData;
4899 {
4900 Point2D *pointPtr, *endPtr;
4901 int count;
4902 char string[TCL_DOUBLE_SPACE * 2 + 2];
4903 char *fmt;
4904 double x, y;
4905
4906 fmt = penPtr->valueFormat;
4907 if (fmt == NULL) {
4908 fmt = "%g";
4909 }
4910 count = 0;
4911 for (pointPtr = symbolPts, endPtr = symbolPts + nSymbolPts;
4912 pointPtr < endPtr; pointPtr++) {
4913 x = linePtr->x.valueArr[pointToData[count]];
4914 y = linePtr->y.valueArr[pointToData[count]];
4915 count++;
4916 if (penPtr->valueShow == SHOW_X) {
4917 sprintf(string, fmt, x);
4918 } else if (penPtr->valueShow == SHOW_Y) {
4919 sprintf(string, fmt, y);
4920 } else if (penPtr->valueShow == SHOW_BOTH) {
4921 sprintf(string, fmt, x);
4922 strcat(string, ",");
4923 sprintf(string + strlen(string), fmt, y);
4924 }
4925 Blt_TextToPostScript(psToken, string, &(penPtr->valueStyle),
4926 pointPtr->x, pointPtr->y);
4927 }
4928 }
4929
4930
4931 /*
4932 *----------------------------------------------------------------------
4933 *
4934 * ActiveLineToPostScript --
4935 *
4936 * Generates PostScript commands to draw as "active" the points
4937 * (symbols) and or line segments (trace) representing the
4938 * element.
4939 *
4940 * Results:
4941 * None.
4942 *
4943 * Side effects:
4944 * PostScript pen width, dashes, and color settings are changed.
4945 *
4946 *----------------------------------------------------------------------
4947 */
4948 static void
4949 ActiveLineToPostScript(graphPtr, psToken, elemPtr)
4950 Graph *graphPtr;
4951 PsToken psToken;
4952 Element *elemPtr;
4953 {
4954 Line *linePtr = (Line *)elemPtr;
4955 LinePen *penPtr = linePtr->activePenPtr;
4956 int symbolSize;
4957
4958 if (penPtr == NULL) {
4959 return;
4960 }
4961 symbolSize = ScaleSymbol(elemPtr, penPtr->symbol.size);
4962 if (linePtr->nActiveIndices > 0) {
4963 if (linePtr->flags & ACTIVE_PENDING) {
4964 MapActiveSymbols(graphPtr, linePtr);
4965 }
4966 if (penPtr->symbol.type != SYMBOL_NONE) {
4967 SymbolsToPostScript(graphPtr, psToken, penPtr, symbolSize,
4968 linePtr->nActivePts, linePtr->activePts);
4969 }
4970 if (penPtr->valueShow != SHOW_NONE) {
4971 ValuesToPostScript(psToken, linePtr, penPtr, linePtr->nActivePts,
4972 linePtr->activePts, linePtr->activeToData);
4973 }
4974 } else if (linePtr->nActiveIndices < 0) {
4975 if (penPtr->traceWidth > 0) {
4976 if (linePtr->nStrips > 0) {
4977 SetLineAttributes(psToken, penPtr);
4978 Blt_2DSegmentsToPostScript(psToken, linePtr->strips,
4979 linePtr->nStrips);
4980 }
4981 if (Blt_ChainGetLength(linePtr->traces) > 0) {
4982 TracesToPostScript(psToken, linePtr, (LinePen *)penPtr);
4983 }
4984 }
4985 if (penPtr->symbol.type != SYMBOL_NONE) {
4986 SymbolsToPostScript(graphPtr, psToken, penPtr, symbolSize,
4987 linePtr->nSymbolPts, linePtr->symbolPts);
4988 }
4989 if (penPtr->valueShow != SHOW_NONE) {
4990 ValuesToPostScript(psToken, linePtr, penPtr, linePtr->nSymbolPts,
4991 linePtr->symbolPts, linePtr->symbolToData);
4992 }
4993 }
4994 }
4995
4996 /*
4997 *----------------------------------------------------------------------
4998 *
4999 * NormalLineToPostScript --
5000 *
5001 * Similar to the DrawLine procedure, prints PostScript related
5002 * commands to form the connected line(s) representing the element.
5003 *
5004 * Results:
5005 * None.
5006 *
5007 * Side effects:
5008 * PostScript pen width, dashes, and color settings are changed.
5009 *
5010 *----------------------------------------------------------------------
5011 */
5012 static void
5013 NormalLineToPostScript(graphPtr, psToken, elemPtr)
5014 Graph *graphPtr;
5015 PsToken psToken;
5016 Element *elemPtr;
5017 {
5018 Line *linePtr = (Line *)elemPtr;
5019 register LinePenStyle *stylePtr;
5020 Blt_ChainLink *linkPtr;
5021 LinePen *penPtr;
5022 unsigned int count;
5023 XColor *colorPtr;
5024
5025 /* Draw fill area */
5026 if (linePtr->fillPts != NULL) {
5027 /* Create a path to use for both the polygon and its outline. */
5028 Blt_PathToPostScript(psToken, linePtr->fillPts, linePtr->nFillPts);
5029 Blt_AppendToPostScript(psToken, "closepath\n", (char *)NULL);
5030
5031 /* If the background fill color was specified, draw the
5032 * polygon in a solid fashion with that color. */
5033 if (linePtr->fillBgColor != NULL) {
5034 Blt_BackgroundToPostScript(psToken, linePtr->fillBgColor);
5035 Blt_AppendToPostScript(psToken, "Fill\n", (char *)NULL);
5036 }
5037 Blt_ForegroundToPostScript(psToken, linePtr->fillFgColor);
5038 if (Blt_HasTile(linePtr->fillTile)) {
5039 /* TBA: Transparent tiling is the hard part. */
5040 } else if ((linePtr->fillStipple != None) &&
5041 (linePtr->fillStipple != PATTERN_SOLID)) {
5042 /* Draw the stipple in the foreground color. */
5043 Blt_StippleToPostScript(psToken, graphPtr->display,
5044 linePtr->fillStipple);
5045 } else {
5046 Blt_AppendToPostScript(psToken, "Fill\n", (char *)NULL);
5047 }
5048 }
5049 /* Draw lines */
5050 if (linePtr->nStrips > 0) {
5051 for (linkPtr = Blt_ChainFirstLink(linePtr->palette); linkPtr != NULL;
5052 linkPtr = Blt_ChainNextLink(linkPtr)) {
5053 stylePtr = Blt_ChainGetValue(linkPtr);
5054 penPtr = stylePtr->penPtr;
5055 if ((stylePtr->nStrips > 0) && (penPtr->traceWidth > 0)) {
5056 SetLineAttributes(psToken, penPtr);
5057 Blt_2DSegmentsToPostScript(psToken, stylePtr->strips,
5058 stylePtr->nStrips);
5059 }
5060 }
5061 } else if ((Blt_ChainGetLength(linePtr->traces) > 0) &&
5062 (linePtr->normalPenPtr->traceWidth > 0)) {
5063 TracesToPostScript(psToken, linePtr, linePtr->normalPenPtr);
5064 }
5065
5066 /* Draw symbols, error bars, values. */
5067
5068 count = 0;
5069 for (linkPtr = Blt_ChainFirstLink(linePtr->palette); linkPtr != NULL;
5070 linkPtr = Blt_ChainNextLink(linkPtr)) {
5071 stylePtr = Blt_ChainGetValue(linkPtr);
5072 penPtr = stylePtr->penPtr;
5073 colorPtr = penPtr->errorBarColor;
5074 if (colorPtr == COLOR_DEFAULT) {
5075 colorPtr = penPtr->traceColor;
5076 }
5077 if ((stylePtr->xErrorBarCnt > 0) && (penPtr->errorBarShow & SHOW_X)) {
5078 Blt_LineAttributesToPostScript(psToken, colorPtr,
5079 penPtr->errorBarLineWidth, NULL, CapButt, JoinMiter);
5080 Blt_2DSegmentsToPostScript(psToken, stylePtr->xErrorBars,
5081 stylePtr->xErrorBarCnt);
5082 }
5083 if ((stylePtr->yErrorBarCnt > 0) && (penPtr->errorBarShow & SHOW_Y)) {
5084 Blt_LineAttributesToPostScript(psToken, colorPtr,
5085 penPtr->errorBarLineWidth, NULL, CapButt, JoinMiter);
5086 Blt_2DSegmentsToPostScript(psToken, stylePtr->yErrorBars,
5087 stylePtr->yErrorBarCnt);
5088 }
5089 if ((stylePtr->nSymbolPts > 0) &&
5090 (stylePtr->penPtr->symbol.type != SYMBOL_NONE)) {
5091 SymbolsToPostScript(graphPtr, psToken, penPtr,
5092 stylePtr->symbolSize, stylePtr->nSymbolPts,
5093 stylePtr->symbolPts);
5094 }
5095 if (penPtr->valueShow != SHOW_NONE) {
5096 ValuesToPostScript(psToken, linePtr, penPtr,
5097 stylePtr->nSymbolPts, stylePtr->symbolPts,
5098 linePtr->symbolToData + count);
5099 }
5100 count += stylePtr->nSymbolPts;
5101 }
5102 }
5103
5104 /*
5105 *----------------------------------------------------------------------
5106 *
5107 * DestroyLine --
5108 *
5109 * Release memory and resources allocated for the line element.
5110 *
5111 * Results:
5112 * None.
5113 *
5114 * Side effects:
5115 * Everything associated with the line element is freed up.
5116 *
5117 *----------------------------------------------------------------------
5118 */
5119 #define FreeVector(v) \
5120 if ((v).clientId != NULL) { \
5121 Blt_FreeVectorId((v).clientId); \
5122 } else if ((v).valueArr != NULL) { \
5123 Blt_Free((v).valueArr); \
5124 }
5125
5126 static void
5127 DestroyLine(graphPtr, elemPtr)
5128 Graph *graphPtr;
5129 Element *elemPtr;
5130 {
5131 Line *linePtr = (Line *)elemPtr;
5132
5133 if (linePtr->normalPenPtr != &(linePtr->builtinPen)) {
5134 Blt_FreePen(graphPtr, (Pen *)linePtr->normalPenPtr);
5135 }
5136 DestroyPen(graphPtr, (Pen *)&(linePtr->builtinPen));
5137 if (linePtr->activePenPtr != NULL) {
5138 Blt_FreePen(graphPtr, (Pen *)linePtr->activePenPtr);
5139 }
5140
5141 FreeVector(linePtr->w);
5142 FreeVector(linePtr->x);
5143 FreeVector(linePtr->xHigh);
5144 FreeVector(linePtr->xLow);
5145 FreeVector(linePtr->xError);
5146 FreeVector(linePtr->y);
5147 FreeVector(linePtr->yHigh);
5148 FreeVector(linePtr->yLow);
5149 FreeVector(linePtr->yError);
5150
5151 ResetLine(linePtr);
5152 if (linePtr->palette != NULL) {
5153 Blt_FreePalette(graphPtr, linePtr->palette);
5154 Blt_ChainDestroy(linePtr->palette);
5155 }
5156 if (linePtr->tags != NULL) {
5157 Blt_Free(linePtr->tags);
5158 }
5159 if (linePtr->activeIndices != NULL) {
5160 Blt_Free(linePtr->activeIndices);
5161 }
5162 if (linePtr->fillPts != NULL) {
5163 Blt_Free(linePtr->fillPts);
5164 }
5165 if (linePtr->fillTile != NULL) {
5166 Blt_FreeTile(linePtr->fillTile);
5167 }
5168 if ((linePtr->fillStipple != None) &&
5169 (linePtr->fillStipple != PATTERN_SOLID)) {
5170 Tk_FreeBitmap(graphPtr->display, linePtr->fillStipple);
5171 }
5172 if (linePtr->fillGC != NULL) {
5173 Tk_FreeGC(graphPtr->display, linePtr->fillGC);
5174 }
5175 }
5176
5177 /*
5178 *----------------------------------------------------------------------
5179 *
5180 * Blt_LineElement --
5181 *
5182 * Allocate memory and initialize methods for the new line element.
5183 *
5184 * Results:
5185 * The pointer to the newly allocated element structure is returned.
5186 *
5187 * Side effects:
5188 * Memory is allocated for the line element structure.
5189 *
5190 *----------------------------------------------------------------------
5191 */
5192
5193 static ElementProcs lineProcs =
5194 {
5195 ClosestLine, /* Finds the closest element/data point */
5196 ConfigureLine, /* Configures the element. */
5197 DestroyLine, /* Destroys the element. */
5198 DrawActiveLine, /* Draws active element */
5199 DrawNormalLine, /* Draws normal element */
5200 DrawSymbol, /* Draws the element symbol. */
5201 GetLineExtents, /* Find the extents of the element's data. */
5202 ActiveLineToPostScript, /* Prints active element. */
5203 NormalLineToPostScript, /* Prints normal element. */
5204 SymbolToPostScript, /* Prints the line's symbol. */
5205 MapLine /* Compute element's screen coordinates. */
5206 };
5207
5208 Element *
5209 Blt_LineElement(graphPtr, name, classUid)
5210 Graph *graphPtr;
5211 char *name;
5212 Blt_Uid classUid;
5213 {
5214 register Line *linePtr;
5215
5216 linePtr = Blt_Calloc(1, sizeof(Line));
5217 assert(linePtr);
5218 linePtr->procsPtr = &lineProcs;
5219 if (classUid == bltLineElementUid) {
5220 linePtr->configSpecs = lineElemConfigSpecs;
5221 } else {
5222 linePtr->configSpecs = stripElemConfigSpecs;
5223 }
5224
5225 /* By default an element's name and label are the same. */
5226 linePtr->label = Blt_Strdup(name);
5227 linePtr->name = Blt_Strdup(name);
5228
5229 linePtr->classUid = classUid;
5230 linePtr->flags = SCALE_SYMBOL;
5231 linePtr->graphPtr = graphPtr;
5232 linePtr->labelRelief = TK_RELIEF_FLAT;
5233 linePtr->normalPenPtr = &linePtr->builtinPen;
5234 linePtr->palette = Blt_ChainCreate();
5235 linePtr->penDir = PEN_BOTH_DIRECTIONS;
5236 linePtr->reqSmooth = PEN_SMOOTH_NONE;
5237 InitPen(linePtr->normalPenPtr);
5238 return (Element *)linePtr;
5239 }