3 /* $Log: barChart.h,v $
4 /* Revision 1.10 1996/01/10 02:33:23 tamches
5 /* changed uses of dynamic1dArray/2d to the vector class
6 /* removed theWindowName
7 /* added a tkInstallIdle
8 /* int --> unsigned for many index variables
9 /* constructor now takes an array of color names
10 /* added getMetricColorName
12 * Revision 1.9 1995/09/22 19:24:03 tamches
13 * removed warnings under g++ 2.7.0
15 * Revision 1.8 1994/11/06 10:26:20 tamches
16 * removed fullResourceHeight as a member vrble
18 * Revision 1.7 1994/10/14 10:27:45 tamches
19 * Swapped the x and y axes -- now resources print vertically and
20 * metrics print horizontally. Can fit many, many more resources
21 * on screen at once with no label overlap. Multiple metrics
22 * are now shown in the metrics axis. Metric names are shown in
23 * a "key" in the lower-left.
25 * Revision 1.6 1994/10/13 00:51:03 tamches
26 * Removed xoffsets and widths while implementing
27 * sorting and bug-fixing deletion of resources.
28 * double-buffer is now the only drawing option
30 * Revision 1.5 1994/10/11 22:02:48 tamches
31 * added validMetrics and validResources arrays to avoid
32 * drawing bars of deleted resources
34 * Revision 1.4 1994/10/10 23:08:39 tamches
35 * preliminary changes on the way to swapping the x and y axes
37 * Revision 1.3 1994/10/10 14:36:14 tamches
38 * fixed some resizing bugs
40 * Revision 1.2 1994/09/29 20:05:34 tamches
43 * Revision 1.1 1994/09/29 19:48:42 tamches
44 * initial implementation
51 // Note: we should make an effort to keep this class as tk-independent as possible.
62 tkInstallIdle drawWhenIdle;
64 bool HaveSeenFirstGoodWid;
65 // set when wid becomes non-zero (usually 1st resize event)
66 int borderPix; // in pixels
67 int currScrollOffset; // in pixels (always <= 0?)
69 Display *display; // low-level display structure used in Xlib drawing calls
71 XColor *greyColor; // for the background
72 vector<string> metricColorNames; // needed for call by tcl
73 vector<XColor *> metricColors;
74 // an arbitrary-sized array (not necessarily equal to # metrics)
75 // (note: this is a new characteristic!!!)
77 GC myGC; // we change colors here very frequently with XSetForeground/
78 // XSetBackground before actual drawing; hence, we could not use
82 enum DataFormats {Current, Average, Total};
84 DataFormats DataFormat;
86 Pixmap doubleBufferPixmap;
87 // set with XCreatePixmap; you should reset with XFreePixmap and another call
88 // to XCreatePixmap whenever the window size changes. Delete with
89 // XFreePixmap when done.
90 void changeDoubleBuffering();
92 unsigned numMetrics, numResources;
93 unsigned numValidMetrics, numValidResources;
94 // how many are enabled by visi lib (as opposed to deleted)
96 vector<unsigned> indirectResources;
97 vector<bool> validMetrics, validResources;
98 // which metrics and resources are valid and should be drawn?
100 int totalResourceHeight; // same as tcl vrble "currResourceHeight"
101 int individualResourceHeight; // fullResourceHeight / numMetrics, but pinned to a max value (maxIndividualColorHeight tcl vrble)
102 int resourceBorderHeight; // vertical padding due to "90%" rule, above.
104 vector< vector<double> > values;
105 // array [metric][rsrc] of numerical (not pixel) bar values
106 // the basis for barPixWidths[][]
107 vector< vector<int> > barPixWidths;
108 // array [metric][rsrc] of pixel widths for each bar. This
109 // changes quite often (every time new data arrives) and
110 // needs to be saved for the case of expose events...
111 vector<double> metricCurrMaxVals;
112 // array [metric] of the current y-axis high value for each metric.
113 // When new data comes in that is higher than this, I give the command
114 // to rethink the metrics axis.
116 bool TryFirstGoodWid();
117 // if wid is still zero, try a fresh Tk_WindowId() to try and change that...
119 void lowestLevelDrawBarsDoubleBuffer();
120 // called by the below routine
122 static void lowestLevelDrawBars(ClientData pthis);
123 // assuming the barPixWidths[][] have changed, redraw bars
124 // with a call to XFillRectanges() or Tk_Fill3DRectangle()'s.
125 // the "static" ensures that "this" isn't required to
126 // call this routine, which is absolutely necessary since
127 // it gets installed as a Tk_DoWhenIdle() routine...
129 void rethinkValidMetricsAndResources();
131 void RethinkMetricColors();
132 // assuming metrics have change, rethink "metricColors" array
134 void RethinkBarLayouts();
135 // assuming a resize (but not added/deleted metrics), fill in barXoffsets,
136 // barPixWidths, resourceCurrMaxY, etc,
138 void rethinkBarPixWidths();
139 // assuming given new bar values and/or new metric max values and/or change
140 // in window width, recalculate barWidths[][].
142 void rethinkValues();
143 // reallocates values[][], assuming a major config change
145 void rethinkMetricMaxValues();
146 void setMetricNewMax(unsigned metricindex, double newmaxval);
147 double nicelyRoundedMetricNewMaxValue(unsigned metricindex, double newmaxval);
151 BarChart(char *tkWindowName, unsigned iNumMetrics, unsigned iNumResources,
152 const vector<string> &colorNames);
155 unsigned getNumMetrics() const {
158 unsigned getNumFoci() const {
162 void processFirstGoodWid();
163 void processResizeWindow(int newWidth, int newHeight);
164 void processExposeWindow();
166 void RethinkMetricsAndResources();
167 // erase and reallocate barXoffsets, barWidths, barWidths, resourceCurrMaxY;
168 // set numMetrics, numResources -- all based on a complete re-reading from
169 // dataGrid[][]. (If visi had provided more fine-grained callbacks than
170 // ADDMETRICSRESOURCES, such a crude routine would not be necessary.)
171 // When done, redraws.
172 void rethinkIndirectResources(); // needed to implement sorting
174 void processNewData(int newBucketIndex);
175 // assuming new data has arrived at the given bucket index for all
176 // metric/rsrc pairs, read the new information from dataGrid[][],
177 // update barWidths[][] accordingly, and call lowLevelDrawBars()
179 void processNewScrollPosition(int newPos);
180 void rethinkDataFormat(DataFormats);
182 const string &getMetricColorName(unsigned index) const {
183 index %= metricColorNames.size();
184 return metricColorNames[index];
188 extern BarChart *theBarChart;