summaryrefslogtreecommitdiffstats
path: root/src/bltGraph.h
blob: 68ed3a395fb99e16e97d8a261d86e66a4e439f83 (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
/*
 * Smithsonian Astrophysical Observatory, Cambridge, MA, USA
 * This code has been modified under the terms listed below and is made
 * available under the same terms.
 */

/*
 *	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 __BltGraph_h__
#define __BltGraph_h__

#include "bltGrMisc.h"
#include "bltBind.h"
#include "bltPs.h"

extern "C" {
#include "bltChain.h"
};

class Graph;
class Crosshairs;
class Axis;
class Element;
class Legend;

typedef struct {
  Axis *x, *y;
} Axis2d;

typedef struct {
  int halo;
  int mode;
  int x;
  int y;
  int along;

  Element* elemPtr;
  Point2d point;
  int index;
  double dist;
} ClosestSearch;

typedef struct {
  int nSegments;
  Axis2d axes;
  float sum;
  int count;
  float lastY;
  size_t index;
} BarGroup;

typedef struct {
  float value;
  Axis2d axes;
} BarSetKey;

typedef enum BarModes {
  BARS_INFRONT, BARS_STACKED, BARS_ALIGNED, BARS_OVERLAP
} BarMode;

typedef struct {
  short int width;
  short int height;
  short int axesOffset;
  short int axesTitleLength;
  short int maxTickWidth;
  short int maxTickHeight;
  unsigned int nAxes;
  Blt_Chain axes;
  const char *varName;
  int reqSize;
  int site;
} Margin;

typedef struct {
  Tcl_HashTable table;
  Blt_Chain displayList;
  Tcl_HashTable tagTable;
} Component;

#define rightMargin	margins[MARGIN_RIGHT]
#define leftMargin	margins[MARGIN_LEFT]
#define topMargin	margins[MARGIN_TOP]
#define bottomMargin	margins[MARGIN_BOTTOM]

typedef struct {
  double aspect;
  Tk_3DBorder normalBg;
  int borderWidth;
  Margin margins[4];
  int backingStore;
  int doubleBuffer;
  Tk_Cursor cursor;
  TextStyle titleTextStyle;
  int reqHeight;
  XColor* highlightBgColor;
  XColor* highlightColor;
  int highlightWidth;
  int inverted;
  Tk_3DBorder plotBg;
  int plotBW;
  int xPad;
  int yPad;
  int plotRelief;
  int relief;
  ClosestSearch search;
  int stackAxes;
  const char *takeFocus; // nor used in C code
  const char *title;
  int reqWidth;
  int reqPlotWidth;
  int reqPlotHeight;

  // bar graph
  BarMode barMode;
  double barWidth;
  double baseline;
} GraphOptions;

class Graph {
 public:
  Tcl_Interp* interp_;
  Tk_Window tkwin_;
  Display *display_;
  Tcl_Command cmdToken_;
  Tk_OptionTable optionTable_;
  void* ops_;
  int valid_;

  ClassId classId_;
  unsigned int flags;
  int nextMarkerId_;

  Component axes;
  Component elements;
  Component markers;
  Tcl_HashTable dataTables;
  Tcl_HashTable penTable;
  Blt_BindTable bindTable;
  Blt_Chain axisChain[4];

  Legend* legend_;
  Crosshairs* crosshairs_;
  PageSetup* pageSetup_;

  int inset_;
  short int titleX_;
  short int titleY_;
  short int titleWidth_;
  short int titleHeight_;
  int width_;
  int height_;
  short int left_;
  short int right_;
  short int top_;
  short int bottom_;	
  Axis *focusPtr_;
  int halo;
  GC drawGC;
  int vRange;
  int vOffset;
  int hRange;
  int hOffset;
  float vScale;
  float hScale;
  Pixmap cache;
  short int cacheWidth;
  short int cacheHeight;

  // barchart specific information
  BarGroup *barGroups;
  int nBarGroups;
  Tcl_HashTable setTable;
  int maxBarSetSize;

 public:
  Graph(ClientData clientData, Tcl_Interp*interp, 
	int objc, Tcl_Obj* const objv[], ClassId classId);
  virtual ~Graph();

  void configure();
};

extern void Blt_MapGraph(Graph* graphPtr);
extern void Blt_ReconfigureGraph(Graph* graphPtr);
extern void Blt_GraphExtents(Graph* graphPtr, Region2d *extsPtr);
extern void Blt_EventuallyRedrawGraph(Graph* graphPtr);

typedef ClientData (MakeTagProc)(Graph* graphPtr, const char *tagName);
extern MakeTagProc Blt_MakeElementTag;
extern MakeTagProc Blt_MakeAxisTag;
extern Blt_BindTagProc Blt_GraphTags;
extern Blt_BindTagProc Blt_AxisTags;

#endif