summaryrefslogtreecommitdiffstats
path: root/src/bltGrElemOp.h
blob: d898847c3d0d25c45d1d92a99ada6314ead8ee4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/*
 * Smithsonian Astrophysical Observatory, Cambridge, MA, USA
 * This code has been modified under the terms listed below and is made
 * available under the same terms.
 */

/*
 * bltGrElem.h --
 *
 *	Copyright 1993-2004 George A Howlett.
 *
 *	Permission is hereby granted, free of charge, to any person obtaining
 *	a copy of this software and associated documentation files (the
 *	"Software"), to deal in the Software without restriction, including
 *	without limitation the rights to use, copy, modify, merge, publish,
 *	distribute, sublicense, and/or sell copies of the Software, and to
 *	permit persons to whom the Software is furnished to do so, subject to
 *	the following conditions:
 *
 *	The above copyright notice and this permission notice shall be
 *	included in all copies or substantial portions of the Software.
 *
 *	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *	EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *	MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 *	NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 *	LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 *	OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 *	WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef _BLT_GR_ELEM_H
#define _BLT_GR_ELEM_H

#include <bltVector.h>

#define ELEM_SOURCE_VALUES	0
#define ELEM_SOURCE_VECTOR	1

#define SEARCH_X	0
#define SEARCH_Y	1
#define SEARCH_BOTH	2

#define SHOW_NONE	0
#define SHOW_X		1
#define SHOW_Y		2
#define SHOW_BOTH	3

#define SEARCH_POINTS	0	/* Search for closest data point. */
#define SEARCH_TRACES	1	/* Search for closest point on trace.
				 * Interpolate the connecting line segments if
				 * necessary. */
#define SEARCH_AUTO	2	/* Automatically determine whether to search
				 * for data points or traces.  Look for traces
				 * if the linewidth is > 0 and if there is
				 * more than one data point. */

#define	LABEL_ACTIVE 	(1<<9)	/* Non-zero indicates that the element's entry
				 * in the legend should be drawn in its active
				 * foreground and background colors. */
#define SCALE_SYMBOL	(1<<10)

#define NUMBEROFPOINTS(e)	MIN((e)->x.nValues, (e)->y.nValues)

#define NORMALPEN(e)		((((e)->normalPenPtr == NULL) ?  \
				  (e)->builtinPenPtr :		 \
				  (e)->normalPenPtr))

/*
 *---------------------------------------------------------------------------
 *
 * Weight --
 *
 *	Designates a range of values by a minimum and maximum limit.
 *
 *---------------------------------------------------------------------------
 */
typedef struct {
    double min, max, range;
} Weight;

#define SetRange(l) \
	((l).range = ((l).max > (l).min) ? ((l).max - (l).min) : DBL_EPSILON)
#define SetScale(l) \
	((l).scale = 1.0 / (l).range)
#define SetWeight(l, lo, hi) \
	((l).min = (lo), (l).max = (hi), SetRange(l))

typedef struct {
    Segment2d *segments;	/* Point to start of this pen's X-error bar
				 * segments in the element's array. */
    int nSegments;
} ErrorBarSegments;

/* 
 * An element has one or more vectors plus several attributes, such as line
 * style, thickness, color, and symbol type.  It has an identifier which
 * distinguishes it among the list of all elements.
 */
typedef struct {
    Weight weight;		/* Weight range where this pen is valid. */
    Pen *penPtr;		/* Pen to use. */
} PenStyle;


typedef struct {
    XColor *color;		/* Color of error bar */
    int lineWidth;		/* Width of the error bar segments. */
    GC gc;
    int show;			/* Flags for errorbars: none, x, y, or both */
} ErrorBarAttributes;

typedef struct {
    /* Inputs */
    int halo;			/* Maximal screen distance a candidate point
				 * can be from the sample window coordinate */

    int mode;			/* Indicates whether to find the closest data
				 * point or the closest point on the trace by
				 * interpolating the line segments.  Can also
				 * be SEARCH_AUTO, indicating to choose how to
				 * search.*/

    int x, y;			/* Screen coordinates of test point */

    int along;			/* Indicates to let search run along a
				 * particular axis: x, y, or both. */

    /* Outputs */
    Element *elemPtr;		/* Name of the closest element */

    Point2d point;		/* Graph coordinates of closest point */

    int index;			/* Index of closest data point */

    double dist;		/* Distance in screen coordinates */

} ClosestSearch;

typedef void (ElementDrawProc) (Graph *graphPtr, Drawable drawable, 
	Element *elemPtr);

typedef void (ElementToPostScriptProc) (Graph *graphPtr, Blt_Ps ps, 
	Element *elemPtr);

typedef void (ElementDestroyProc) (Graph *graphPtr, Element *elemPtr);

typedef int (ElementConfigProc) (Graph *graphPtr, Element *elemPtr);

typedef void (ElementMapProc) (Graph *graphPtr, Element *elemPtr);

typedef void (ElementExtentsProc) (Element *elemPtr, Region2d *extsPtr);

typedef void (ElementClosestProc) (Graph *graphPtr, Element *elemPtr, 
	ClosestSearch *searchPtr);

typedef void (ElementDrawSymbolProc) (Graph *graphPtr, Drawable drawable, 
	Element *elemPtr, int x, int y, int symbolSize);

typedef void (ElementSymbolToPostScriptProc) (Graph *graphPtr, 
	Blt_Ps ps, Element *elemPtr, double x, double y, int symSize);

typedef struct {
    ElementClosestProc *closestProc;
    ElementConfigProc *configProc;
    ElementDestroyProc *destroyProc;
    ElementDrawProc *drawActiveProc;
    ElementDrawProc *drawNormalProc;
    ElementDrawSymbolProc *drawSymbolProc;
    ElementExtentsProc *extentsProc;
    ElementToPostScriptProc *printActiveProc;
    ElementToPostScriptProc *printNormalProc;
    ElementSymbolToPostScriptProc *printSymbolProc;
    ElementMapProc *mapProc;
} ElementProcs;

typedef struct {
    Blt_VectorId vector;
} VectorDataSource;

/* 
 * The data structure below contains information pertaining to a line vector.
 * It consists of an array of floating point data values and for convenience,
 * the number and minimum/maximum values.
 */
typedef struct {
    int type;			/* Selects the type of data populating this
				 * vector: ELEM_SOURCE_VECTOR,
				 * ELEM_SOURCE_TABLE, or ELEM_SOURCE_VALUES
				 */
    Element *elemPtr;		/* Element associated with vector. */
    VectorDataSource vectorSource;
    double *values;
    int nValues;
    int arraySize;
    double min, max;
} ElemValues;


struct _Element {
    GraphObj obj;			/* Must be first field in element. */
    unsigned int flags;		
    Tcl_HashEntry *hashPtr;

    /* Fields specific to elements. */
    const char *label;			/* Label displayed in legend */
    unsigned short row, col;		/* Position of the entry in the
					 * legend. */
    int legendRelief;			/* Relief of label in legend. */
    Axis2d axes;			/* X-axis and Y-axis mapping the
					 * element */
    ElemValues x, y, w;			/* Contains array of floating point
					 * graph coordinate values. Also holds
					 * min/max and the number of
					 * coordinates */
    int *activeIndices;			/* Array of indices (malloc-ed) which
					 * indicate which data points are
					 * active (drawn with "active"
					 * colors). */
    int nActiveIndices;			/* Number of active data points.
					 * Special case: if nActiveIndices < 0
					 * and the active bit is set in
					 * "flags", then all data points are
					 * drawn active. */
    ElementProcs *procsPtr;
    Blt_ConfigSpec *configSpecs;	/* Configuration specifications. */
    Pen *activePenPtr;			/* Standard Pens */
    Pen *normalPenPtr;
    Pen *builtinPenPtr;
    Blt_Chain stylePalette;		/* Palette of pens. */

    /* Symbol scaling */
    int scaleSymbols;			/* If non-zero, the symbols will scale
					 * in size as the graph is zoomed
					 * in/out.  */
    double xRange, yRange;		/* Initial X-axis and Y-axis ranges:
					 * used to scale the size of element's
					 * symbol. */
    int state;
    Blt_ChainLink link;			/* Element's link in display list. */
};


extern double Blt_FindElemValuesMinimum(ElemValues *vecPtr, double minLimit);
extern void Blt_ResizeStatusArray(Element *elemPtr, int nPoints);
extern int Blt_GetPenStyle(Graph *graphPtr, char *name, size_t classId, 
	PenStyle *stylePtr);
extern void Blt_FreeStylePalette (Blt_Chain stylePalette);
extern PenStyle **Blt_StyleMap (Element *elemPtr);
extern void Blt_MapErrorBars(Graph *graphPtr, Element *elemPtr, 
	PenStyle **dataToStyle);
extern void Blt_FreeDataValues(ElemValues *evPtr);
extern int Blt_GetElement(Tcl_Interp *interp, Graph *graphPtr, 
	Tcl_Obj *objPtr, Element **elemPtrPtr);

#endif /* _BLT_GR_ELEM_H */