The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ _1. _I_n_t_r_o_d_u_c_t_i_o_n 9 This document is supposed to be an overview document and describes how to use the AthenaTools Plotter Widget Set to add graphs to your X programs. It is assumed the reader is familiar in general with programming X and widget sets. All of the detailed information regarding resources etc. is documented in the relevant manual pages. The AthenaTools Plotter Widget Set provides many of the features scientific and business users need in a graph that will be embedded in another program. Some highlights of the plotter widgets are 9X-Y plots for scientific-style graphics. 9Line and bar plots for business-style graphics. 9Automatic or manual scaling of axis values, automatic selection of tic and subtic points. 9Callbacks to get the current pointer position in the plotting area in pixel and user coordinates, and to cut off a range or rectangle from the plotting area for zooming in, for example. 9Very flexible text facilities, including mathematical symbols, sub- and super-scripts, font changes etc. These text facilities can be used for legend names, graph titles, axis labels, tic labels, or attached to arbitrary points on the graph in either pixel space or user space. 9Unlimited number of plots on each graph, with each plot independently specified[1]. 9Encapsulated PostScript generated that closely matches the screen output. 9Logarithmic and linear axes, or axes labeled at arbitrary points with arbitrary strings (which is very useful for labeling axes with dates, for example). 9Very flexible axis handling. There are up to four axes on the graph, and any plot can be associated with either X axis and either Y axis. 9"Frame" axes that get their scaling etc. from another axis object, on either the same or another graph. This makes coordination between related graphs very easy. 9A Fast Update mode that can quickly redraw rapidly-changing data[2]. 9Easy access to application data. The widget set is designed to access application data that is stored in an array of structures; it can pull data out of structures in either Float, Double or ____________________ 9 [1]Each plot on the graph is a different widget. [2]This is implemented but untested at this point in time. 9_________________________________________________________________ August 1992 1 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ Integer format, but other data types are easily added. The Plotter Widget is a widget based on Xlib and Xtoolkit. It is intended to be used in conjunction with other widget sets based on Xlib and Xtoolkit, like the Athena Widget Set or the OSF/Motif Widget Set. The Plotter Widget Set is not intended for stand-alone graphic applications (use GNUplot or similar for that). It is not a 3D library, and is not really a replacement for Harvard Graphics or some such. It cannot do Pie charts or other non-XY type graphs. 9 _________________________________________________________________ August 1992 2 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ _2. _U_s_a_g_e _W_a_l_k_t_h_r_o_u_g_h 9 This section gives a quick overview of how to program using the AthenaTools Plotter Widget Set, and explains what sort of data the plotter expects from your application. There can be found four test programs using the Athena Widget Set in the subdirectory athena, and one larger test program using the OSF/Motif Widget Set in the subdirectory motif. You can make and run these programs by typing xmkmf to create the Makefiles from the Imakefiles, and then typing make all or make to create the executables. All these programs are written in C and use no resource files to run properly. This means anyone should be able to compile and run them. You should be able to transfer the concepts to your favourite development environment with no problems. The example source code in this section is taken from two test programs that came with the source. The file Plot.c, containing all the stuff how to use and program the plotter widgets, from the Motif based example program mplot, and the file sample_prog.c, a Athena based application, are completely listed in Section 5. The title page of this document, and the Figure 1 below, a plotter PostScript output from mplot, show a typical scientific use of the plotter widget set. _________________________________________________________________ 9 Figure 1: PostScript Output From The mplot Test Program 9_________________________________________________________________ _2._1. _C_r_e_a_t_i_n_g _T_h_e _P_l_o_t_t_e_r _A_n_d _T_h_e _A_x_e_s The general arrangement is as follows. For each graph, you create a single AtPlotter widget. This is a widget, and has an X window, the same as most other widgets. You then create some axis objects (some subclass of AtAxisCore, usually AtXYAxis or AtAxis) as children of the AtPlotter and attach them to the parent by doing an XtSetValues() using the XtNxAxis and XtNyAxis resources. In the sample program mplot, a more scientific use of the plotter widgets, this is done in the procedure MakePlotter() which is called when the application shell, the main window, some buttons and other widgets, and a parent form and frame for the plotter are created: _________________________________________________________________ August 1992 3 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ 98 #include 8 #include 98 Widget parent; /* Already created! */ 8 Widget plotter, xaxis, yaxis; 8 Arg args[8]; 8 int n; 98 /* Create the plotter */ 8 n = 0; 8 XtSetArg(args[n], XtNwidth, 400); n++; 8 XtSetArg(args[n], XtNheight, 300); n++; 8 XtSetArg(args[n], XtNborderWidth, 0); n++; 8 XtSetArg(args[n], XtNshowLegend, True); n++; 8 plotter = XtCreateManagedWidget("plotter", atPlotterWidgetClass, 8 parent_widget, args, n); 98 /* Create the X axis */ 8 n = 0; 8 XtSetArg(args[n], XtNlabel, "Time"); n++; 8 XtSetArg(args[n], XtNaxisWidth, 1); n++; 8 xaxis = XtCreateWidget("xaxis", atXYAxisWidgetClass, plotter, args, n); 98 /* Create the Y axis */ 8 n = 0; 8 XtSetArg(args[n], XtNlabel, "Amplitude"); n++; 8 XtSetArg(args[n], XtNaxisWidth, 1); n++; 8 XtSetArg(args[n], XtNvertical, True); n++; 8 yaxis = XtCreateWidget("yaxis", atXYAxisWidgetClass, plotter, args, n); 98 /* Attach X and Y axes to the plotter */ 8 n = 0; 8 XtSetArg(args[n], XtNxAxis, xaxis); n++; 8 XtSetArg(args[n], XtNyAxis, yaxis); n++; 8 XtSetValues(plotter, args, n); This is the minimal configuration for graphs using the AthenaToolkit Plotter Widget Set[3]. _2._2. _C_r_e_a_t_i_n_g _P_l_o_t _O_b_j_e_c_t_s _A_n_d _A_t_t_a_c_h_i_n_g _D_a_t_a Then, for each data item to plot on this graph, you create a plot object, in this example AtXYLinePlot, a subclass of AtXYPlot: 98 #include 98 Widget plotter; /* Already created! */ 8 Widget line1; 8 Arg args[4]; 8 int n; 98 /* Create line 1 */ 8 n = 0; 8 XtSetArg(args[n], XtNlegendName, "sinus-points"); n++; 8 XtSetArg(args[n], XtNplotLineStyle, AtLineDOTTED); n++; 8 XtSetArg(args[n], XtNplotMarkType, AtMarkRECTANGLE); n++; 8 line1 = XtCreateWidget("line1", atXYLinePlotWidgetClass, 8 plotter, args, n); When the plot objects are created, you can use the member functions for that plot object to attach it to your application data. In the test program the data, a simple polygon and some curves, are created from within the routine MakeDemoData(), or are read in from a data file in the procedure ReadPlotData(). Once the data are attached and the AtPlotter is first displayed, it will automatically calculate all the bounds, scaling etc. and display the graph. In contrast to previous releases of this widget set[4], copies of the data are not required. The assumption is your application data are stored in an array of structures, statically ____________________ 9 [3]A complete listing of the source file Plot.c from which the examples are taken, is enclosed in Section 5.1. [4]Up to Version 4. 9_________________________________________________________________ August 1992 4 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ declared as in MakeDemoData() or dynamically allocated as in ReadPlotData(). For the AtXYLinePlot class there are three pre- defined data types AtDoublePoint, AtFloatPoint and AtIntPoint which correspond to the currently supported data types AtDouble, AtFloat and AtInt. These are simple structs containing one item for the X coordinate and one item for the Y coordinate of a data point. AtDoublePoint, for example, is defined in At/XYLineplot.h as follows: 98 typedef struct { 8 double x; /* X coordinate */ 8 double y; /* Y coordinate */ 8 } AtDoublePoint; 9 An array of such a struct type is just a line composed of its data points. For the polygon in Figure 1, a connected line defined of 6 points, you would declare an array of 6 data points: 98 #include 98 #define PNUM 6 8 static AtDoublePoint polygon[PNUM]; and attach the polygon to a plot object. using the member routine AtXYLinePlotAttachDoublePoints()[5]. In the example this is done in the procedure AttachData(): 98 Widget line3; /* Already created! */ 98 /* Attach polygon from predefined type AtDoublePoint to line3 */ 8 AtXYLinePlotAttachDoublePoints(line3, &polygon[0], 1, PNUM); The parameters for this routine are : 9The widget line3 (a subclass of AtXYPlot) you are attaching the data to. 9A pointer &polygon[0] to the first item in the static array. 9The index of the first item in the array which should be plotted (often 1 but not always). The number of items PNUM in the array which should be plotted. 9 The data pointed to in this routine should remain valid until the next attach call is made (as it may be accessed if the window resizes or if other plots change or if PostScript output is generated). Setting the address to NULL and the count to 0 will effectively undisplay the plot. If the underlying data has changed, a new call to the attach routine should be made so that the change is noted and new bounds are calculated. In addition, providing your application is suitably arranged, the plot widgets can read the information straight out of your existing structures. Assume you have defined a record ____________________ 9 [5]This routine is a #define'd alias for the routine AtXYPlo- tAttachData. _________________________________________________________________ August 1992 5 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ type, composed of one common X value and two Y values, like the struct point: 98 struct point { 8 double xval; /* The X value */ 8 double yval1; /* The Y values */ 8 double yval2; 8 }; and you have 24 items of that type. You would then declare an array of 24 records: 98 #define CNUM 24 8 static struct point curve[CNUM]; and use the appropriate member routine AtXYLinePlotAttachData()[6] to attach the data. This routine is more general than the above denominated member routine AtXYLinePlotAttachDoublePoints() and somewhat more complicated: 98 /* Attach curve from own defined type point to line1 */ 8 AtXYLinePlotAttachData(line1, 8 (XtPointer) &curve[0].xval, AtDouble, sizeof(struct point), 8 (XtPointer) &curve[0].yval1, AtDouble, sizeof(struct point), 8 1, CNUM); The parameters are as follows: 9The widget line1 (a subclass of AtXYPlot) you are attaching the data to. 9A pointer &curve[0].xval to the first X value data item in the array. 9The type AtDouble of that item. 9A parameter sizeof(struct point) called the Stride, which is the number of bytes between successive data items. In most applications, that will be the size of the structure you are accessing. 9A pointer &curve[0].yval1 to the first Y value data item in the array. 9The type AtDouble of that item. 9The stride parameter sizeof(struct point). 9The index of the first item in the array. 9The number of items in the array which shoud be plotted. 9 Once the XtMainLoop() routine is called after creating the plotter, the axes and the lines, and after attaching the data to the lines, the graph magically appears. 9____________________ 9 [6]This routine also is just a #define'd alias for the routine AtXYPlotAttachData(). _________________________________________________________________ August 1992 6 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ _2._3. _U_s_i_n_g _T_h_e _L_i_n_e_P_l_o_t _A_n_d _B_a_r_P_l_o_t _C_l_a_s_s_e_s As an example for a more business-like graphic using line and bar plots and two Y axes, consider the second test program sample_prog, a simple accounting application for a Widget Distribution Company[7]. You might wish to display the weekly sales and profit figures for the sale of Widgets for the past year. But your database stores only the volume sold, the sale price and the purchase price. So you would declare a structure like this: 98 struct profits { 8 /* From database */ 8 long volume; 8 float buy_price; 8 float sell_price; 8 /* Calculated values */ 8 double sales; 8 double cost; 8 double profit; 8 }; _________________________________________________________________ 9 Figure 2: PostScript Output From The sample_prog Program 9_________________________________________________________________ You would then declare an array of 52 structs: 98 #define NUM_WEEKS 52 8 struct profits profits[NUM_WEEKS]; Two routines (called ReadFromDatabase() and CalculateProfits() in the sample program) could read in the weekly figures from the database and run through a loop to calculate sales, cost and profits for each week. This creates the data to be plotted. Like in the first example you have to create the plotter and its children, when application shell and parent form are created. The routine MakePlotter() does that: it creates the main plotter, then the X axis for the week number, the Y axis for profit, and the Y2 axis (on the right hand side) for volume. Then it creates the plot objects, one AtLinePlot object for profits and one AtBarPlot object for volume. The routine AttachData() attaches the calculated data to the plot objects using the member routine AtLinePlotAttachData()[8], with a call like: 98 AtLinePlotAttachData(line, (XtPointer) &profits[0].profit, 8 AtDouble, sizeof(struct profits), 1, NUM_WEEKS); 9____________________ 9 [7]The complete listing of sample_prog.c is enclosed in Sec- tion 5.2. [8]This routine is alos just a #define'd alias for the routine AtSPlotAttachData(). _________________________________________________________________ August 1992 7 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ The parameters, similar to that in the first example above, are as follows: The widget line (a subclass of AtSPlot) you are attaching the data to, a pointer &profits[0].profile to the first data item, the type AtDouble of that item, the stride sizeof(struct profits), the integer X axis value of the first item in the list, and the number NUM_WEEKS of items in the list. The X axis value of the last item will be (start + num - 1). The volume data is attached to the AtBarPlot widget with the equivalent call[9] : 98 AtBarPlotAttachData(bar, (XtPointer) &results[0].volume, 8 AtInt, sizeof (struct profits), 0, NUM_WEEKS); with the same parameters as above. _2._4. _D_i_f_f_e_r_e_n_c_e_s _B_e_t_w_e_e_n _T_h_e _A_t_X_Y_L_i_n_e_P_l_o_t _A_n_d _A_t_L_i_n_e_P_l_o_t _C_l_a_s_s_e_s Lets close this section by pointing out the main differences between the AtXYLinePlot and the AtLinePlot class, as can be seen in the examples given in the above subsections: 99When attaching data to an object of the AtXYLinePlot class you have to specify explicitely the X and the Y values of your data, no matter if you use one of the pre-defined structure types like AtDoublePoint or specify your own data types. As you would expect you can define any range for the X and the Y values, as it is needed for most scientific applications, including connected lines like the polygon in the first example (see Section 2.1). 9In contrast to an AtXYLinePlot object objects from the AtLineplot or AtBarPlot classes require data with a continuous X range. The X values are taken as integers from the indices in the data arrays. You can set the XtNticMultiplier resource to make the X indices and the tic labels more conform to your real X data, but it's impossible to specify a range from xmin = -3 to xmax = +3, for example, or to plot connected lines. ____________________ 9 [9]The AtBarPlotAttachData is also a #define'd alias for AtSPlotAttachData. _________________________________________________________________ August 1992 8 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ _3. _M_o_r_e _D_e_t_a_i_l 9 _3._1. _D_e_f_i_n_i_t_i_o_n_s Lets start by defining some terms so we all understand what we are talking about. 9_O_b_j_e_c_t Any X Toolkit Intrinsics object that is a subclass of the Object class. XtSetValues operates on Objects and XtCreateWidget() creates them. 9_W_i_d_g_e_t Any Object that is a subclass of Core and thus has a window. 9_G_r_a_p_h The entire display of a Plotter widget which includes the main plotter widget and all children, axes and plots. There can be multiple graphs, and hence multiple AtPlotter widgets, in one program. 9_P_l_o_t A single data Object plotted on a graph. (i.e. a single line or bar plot). One AtPlot Object per plot, multiple plots per graph. 9_U_s_e_r _S_p_a_c_e, _P_i_x_e_l _S_p_a_c_e User space is the realm of real numbers that the graph is attempting to plot. Pixel space is the screen coordinates that X windows works in. All application data is expressed in user space, and is converted to pixel space (or pixel locations) by the various recalc routines inside the plotter. Application programmers should deal with user space only, and not need to touch pixel space. 9_R_e_f_r_e_s_h Simply redraw one plot on the graph. No screen clear or redraw of other child Objects required. 9_R_e_d_r_a_w Simply refresh the on screen image of the whole plotter widget. No calculation required. 9_R_e_l_a_y_o_u_t The pixel dimensions of the graph widget have changed (e.g. because the user resized the application) or the size of one of the component parts (e.g. an axis is wider because the font changed), but the data that is plotted is unchanged. 9_R_e_s_c_a_l_e The data has changed and the existing axis bounds are not sufficient. New axis bounds are required, but no layout has changed and all axes are in the same spot. Is concerned with min/max of axis values, tic values and intervals etc. 9_R_e_c_a_l_c Either pixel location or data has changed for a plot, and the cached pixel values need to be recalculated. Can be for a single child or the whole graph. _________________________________________________________________ August 1992 9 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ A rescale implies a recalc, and a relayout implies a recalc, but relayout and rescale are orthogonal (i.e. one doesn't necessarily imply the other). A recalc implies a redraw. 9 _________________________________________________________________ August 1992 10 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ _3._2. _W_i_d_g_e_t _C_l_a_s_s _H_i_e_r_a_r_c_h_y Figure 3 below shows the class inheritance of the AthenaTools Plotter Widget Set: _________________________________________________________________ 9 Figure 3: The Plotter Widget Set Class Hierarchy 9_________________________________________________________________ As can be seen, most of the widgets in the set are actually Objects and don't have an X window of their own. They draw on the the window supplied by the parent AtPlotter widget. A minimal graph includes a single AtPlotter widget that is the parent of two Objects that are subclasses of AtAxisCore, and one Object that is a subclass of AtSPlot or AtXYPlot. The AtPlot, AtSPlot, AtXYPlot and AtAxisCore widget classes are simply placeholders for some logic and resources; you shouldn't ever need to make Objects of these types. The AtPlotter will only accept children that are a subclass of AtPlot, and AtPlot classes will only accept AtPlotter widgets as a parent. We will examine each of the elements in turn. _3._3. _E_l_e_m_e_n_t_s _o_f _t_h_e _G_r_a_p_h Figure 4 on the next page shows the various areas of the graph. The string along the top is known as the title. The font, size, color and style (i.e. roman, _i_t_a_l_i_c, bold etc.) and the string itself can be set using resources of the AtPlotter widget. The font family (see Section 4.1) is the same for all the strings in the AtPlotter widget. Specifying a title as the empty string removes the title and reclaims the space for the main part of the graph. Along the right hand edge of the graph is the legend. The AtPlotter maintains details about the legend as Constraint resources on behalf of the children. The AtPlotter has resources to set the string, size and style of the legend title, as well as the size and style of the legend labels. The color of the text in the legend is set in the AtPlotter and affects all the text in the legend. The actual legend strings are constraint resources and belong (logically) to the child. Each item (apart from the title) in the legend is drawn by the child plot, and exactly matches the corresponding plot in the main graph area. The legend is controlled by the AtPlotter widget, and the resource 9 Figure 4: Elements Of The Plotter Window 9_________________________________________________________________ 9_________________________________________________________________ August 1992 11 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ XtNdrawLegend controls whether it is displayed. There are two axes used in the sample graph shown in Figure 1, the horizontal axis is a logarithmic axis of class AtXYAxis, the vertical axis is a linear axis, also of class AtXYAxis. All the values displayed on these axes were calculated automatically (although you can manually set the maximum, minimum and the distance between tic marks if required). There are 3 tics on the logarithmic X axis, and 5 tics on the linear Y axis. Each tic has a label and a tight dotted grid line associated with it. The color of the axis, the font, size and style of the tic labels and a sprintf()-like format string can be specified. The small marks between the tic values are called subtics, and have a wider dotted optional subgrid line associated with it. They are automatically generated, whether the main ticks are manually or automatically set. For the AtAxis class the subtic density resource can increase or decrease the number of subtics per tic, and care is taken that the number is sensible (e.g. power of 2 or 5 etc). There is a label associated with each axis, again an arbitrary text string in any font, color or style. For vertical axes it is rotated 90 degrees. These are the labels "Time" and "Amplitude" in the sample graph. In general, there are four axes on the graph. The horizontal axes are the X axes, the lower is known as the X axis and the upper as the X2 axis. The vertical axes are Y axes, the left being Y axis and the right being Y2 axis. Each plot on the graph is associated with one X axis and one Y axis. The AtPlotter maintains constraint resources on behalf of each plot child to decide which X and Y axis it is associated with. If there are no plot children associated with an axis (as is the case for the Y2 and X2 axes in the graph shown in Figure 1 or for the X2 axis in the graph shown in Figure 2), then there is no need for an axis widget to be created for that axis. The X2 and Y2 axes are known as mirror axes, and the AtAxisCore resource XtNmirror must be set on axes used for these axes and must not be set on axes used for the X axis and Y axis. Similarly, the AtAxisCore resource XtNvertical must be set on axes used for the Y axis and Y2 axis, and must not be set on axes used for the X axis and X2 axis. Both XtNmirror and XtNvertical resources can be set at Object creation time only; any attempt to change them will fail with a warning message. The AtAxisCore widget is a placeholder for most of the axis resources, and also contains the logic for calculating pixel values from user-space values. It relies on subclass member functions to decide what values to use for minimum and maximum, at what values to place tic and subtic marks, and the labels associated with those tic marks. The AtAxisCore widget then handles all the pixel conversions and screen and PostScript redrawing, so the axis classes are very simple to implement. 9_________________________________________________________________ August 1992 12 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ When the AtPlotter widget is created, it does not create any child axes[10]. It is the programmers responsibility to create (at least) two AtAxisCore Objects and attach them to the AtPlotter (using XtSetValues() and the XtNxAxis and similar resources). Nasty things happen if this isn't done (i.e. the program exits via XtAppError()). It is possible to have axis children that are not one of the currently used axes, but they must not be displayed (i.e. must have XtNdisplayed = False). This is useful for having several possible axes on a plot (e.g. an AtAxis if it is used for scaling a plot, or a AtFrameAxis to carry tic marks when the opposite axis is being used), and to swap between them with calls to XtSetValues() using for example the XtNx2Axis resource. Also on the sample graph are three plots from class AtXYLinePlot. For these plots, the color, line type, line style, point marker types and line thickness can be set. This effects both the main plot and the legend entry for that plot. For the AtLinePlot class only the color, line style and line thickness can be set. For the AtBarPlot, the interior of the bars can either be the same color as the outline, or a different color. The interior area can also be stippled with one of 11 stipples[11] that will be converted to a grayscale level on PostScript output. Ether the outline or the interior fill can be disabled (but, obviously, not both). NOTE: All Objects that are not subclasses of rectObj (and that includes all the AtPlot Objects) do not have a managed flag. Hence they should never be managed children of the AtPlotter widget. This means they should be created with XtCreateWidget() and not XtCreateManagedWidget(), and should never be the argument to the XtManageChild() routine. Attempts to manage non-rectObjs will corrupt the instance record with undefined results. Rather than use XtManageChild() and the XtNmappedWhenManaged flag to display plots and axes, the parent AtPlotter maintains a constraint variable for each child called displayed which may be set with the XtNdisplayed resource. Setting this to false has the same effect that calling XtUnmanageChild() with the XtNmappedWhenManaged flag set would have on a normal widget, i.e. the child would disappear and take no part in the calculation of axes bounds etc. It is an error to undisplay an axis that still has child plots associated with it, and undefined results occur if a normal (as opposed to frame) axis is displayed without children associated with it. ____________________ 9 [10]This is a change in behaviour since Version 4. [11]Only 5 distinct on-screen stipple patterns are implemented at the moment, pending discovery of good "10 gray" sort of stip- ples. The 11 stipples GRAY0 through GRAY10 correspond to PostScript 1.0 setgray down to 0.0 setgray constructs. _________________________________________________________________ August 1992 13 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ _4. _A_d_v_a_n_c_e_d _T_o_p_i_c_s 9 _4._1. _T_e_x_t _F_a_c_i_l_i_t_i_e_s All text strings in the plotter widget set are implemented using the AtText facility. This is in the style of Motif compound XmString type. It is a unified set of routines that allows easy specification of text styles, multiple fonts and sizes as well as symbols, and PostScript output that closely matches the on-screen version. See the AtText(3X) manual page for the full details. Each string segment is made up from five elements: the font family, the style, the size, and the text. The font family is something like "times" and specifies the basic look of the font. The style specifies AtFontPlain, _A_t_F_o_n_t_I_T_A_L_I_C, AtFontBOLD or bAtFontBOLDITALIC typeface (defined in At/FontFamily.h). The size ranges from tiny AtFontSMALLEST (about 8 point) to large AtFontBIGGEST (about 24 point). Each segment is a simple list of characters in that font/face/size combination. The routine that compiles Strings to the AtText structs has facilities for interpreting escapes to change fonts, to display mathematical symbols etc. In this widget set, the font family is set once per Object, but the size and style can be changed on a per-string basis. (This avoids the possibility of the so-called "ransom note" look). _4._2. _T_h_e _L_a_y_o_u_t _P_r_o_c_e_d_u_r_e This is the sequence of steps the plotter goes through to lay out a graph. 9The X and Y range for each plot child is accumulated and remembered as data is attached to or changed for each child. 9The X and Y ranges of all the child plots are merged, on the basis of the XtNuseX2Axis and XtNuseY2Axis resources, into a simple bounding box for all four axes. (One X axis and one Y axis may be unused at this stage). 9minmax: Each axis currently in use is in turn offered its minimum and maximum (calculated above) via a call to the AtAxis member function AtAxisAskRange(). It is the responsibility of this routine to do any rounding, communication etc. as required, and the returned minimum and maximum are used by the plotter. There is a callback list on the AtAxisCore Object (XtNrangeCallback) that is called by the AtAxisCore code after it has decided on the axis bounds. This programmer-written routine can modify the minimum, maximum, number width and tic interval values as required. This is used for linking graphs (see Section 4.7). The calculated number width (which may be approximate only at this stage) is used to calculate the "width" of the axis (which is the amount of the axis that is outside the main graph area). 9 _________________________________________________________________ August 1992 14 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ A layout is done, assuming the axis widths calculated in step minmax are accurate. This sets the position of all the graph components within the main AtPlotter window. 9Each of the active axes is positioned by a call to the AtAxisSetLocation() member function. If the length of the axis changes significantly (currently by 10), then it is assumed the number of relevant tics might have changed, thus changing the rounding and endpoints of the axis. If this is the case, the process is repeated at step minmax. Should not loop more than twice at this point, assuming step minmax can do a reasonable guess for the axis width. 9Each of the axes is recalculated by a call to the AtPlot AtPlotRecalc() member function. Most of the arguments to the recalc function for axis objects are ignored. This step may give a better guess as to things like the number width, which changes the layout. If so, the sequence restarts at step minmax. Some care is taken to avoid infinite loops. 9Each of the non-axis child plots is recalculated by a call to the AtPlotRecalc() routine, with the scales being extracted from the already-recalculated axes as appropriate. 9All children in the graph are redisplayed. 9 All of this is controlled by one routine which is the redraw routine for the AtPlotter class. All requests are remembered and stored up, so the above procedure is only done when necessary. This means a program can change several things one after the other, and the graph will only do the expensive layout and redraw calculation once, not once per change. This is faster and reduces flickering. Furthermore, much care is taken internally to avoid as much of the above sequence as is possible, so that if small things change, minimal calculation and redrawing is done. _4._3. _D_r_a_w_i_n_g _O_r_d_e_r The order in which the children of the AtPlotter widget are drawn affects which is "above" (and hence obscures) which in the display. The first one drawn is conceptually on the bottom, as you would expect. (In this context, "children" refers to all children, both axes and plots). There are three typical situations where this is relevant: 9Generally the grid provided by the axes should be below the plotted data. 9When drawing line plots and bar plots on the same graph, you want the line plots to be drawn second so that they are visible and not obscured by the bars. Otherwise, the information from the line graph will likely be hidden. 9Several bar plots can create the "stacked bar" effect by drawing them in sequence, and arranging them to overlap slightly. 9 _________________________________________________________________ August 1992 15 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ There are two ways the AtPlotter can use to decide which order to draw plots. The first and default method, which is used when the AtPlotter resource XtNrankChildren is False, is to draw them in creation order. The first created child is drawn first, and so on. The second method, used when XtNrankChildren is True, is to draw them according to a programmer-specified rank order. The parent widget stores a constraint variable called XtNrank of behalf of all its children, and will use this to decide which order to draw in. This is more flexible but takes more programmer effort. (When several children have the same rank, they are drawn in unspecified order). _4._4. _C_u_s_t_o_m_i_z_i_n_g _A_x_i_s _L_a_y_o_u_t_s There are several alternatives to using the default calculated axis bounds and tic positions. The default behaviour (for the AtXYAxis and AtAxis classes) is to pick some number of tics (depending on axis length and the font used to display labels), find a nice, round number for the tic interval that gives approximately that number of tics[12], then round the endpoints up or down to be a multiple of the tic interval. Each tic is given a label by doing a sprintf() using the XtNticFormat resource[13]. This is fine is the axis values are numeric, but not very useful if the axis represents dates or categories, or if you need to coordinate axes between separate graphs (for example, having six variables to graph against a common X value, each pair plotted on a separate graph, one graph on top of the other, and all sharing the same X axis values - which would look silly if each X axis was in a different pixel position or had a different scale). There are three separate mechanisms to address these problems. _4._5. _L_a_b_e_l _A_x_e_s The AtLabelAxis class is very useful if your axis doesn't represent numbers. There are two main areas this could be useful: 9If you are doing something like a stacked bar graph, plotting a couple of figures (say, quarterly sales) for each of several items (say, state by state). Labeling the X axis with numbers is silly. Instead, each X tic can be labeled with a string, i.e. "Vic", "N.S.W." etc. In this situation, you would want to a label and tic for every X axis value. 9If you are plotting values against dates, you would like to be able to specify the axis tics as dates, not numbers. Also, because dates are not regular and months are not all the same ____________________ 9 [12]For AtAxis objects the resource XtNticDensity is used in addition to calculate the number of tics per axis. [13] For AtAxis objects the XtNticMultiplier resource is used in addition for labeling the tics. _________________________________________________________________ August 1992 16 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ length, automatically deciding tic values cannot do the logical thing, such as putting a tic at the start of every month. You would also like to be able to choose which X values have tics and hence labels. 9 The AtLabelAxis axis allows the application writer to specify arbitrary labels to put on tics, and arbitrary positions to place tics, at the expense of a bit more programming effort. The programmer can specify things like "a tic on the first day of every second month", and label the axes with dates, which cannot be done algorithmically. The plotter and axis code supports arbitrary X-Y plotting styles, but with exception of the AtXYAxis class and the AtXYPlot class (with the AtXYLinePlot subclass), all other implemented plot widgets assume the X axis is integer valued, and that successive Y values are at successive integral X values (i.e. there are no "holes" in the sequence of Y values). The AtLabelAxis also makes a similar assumption. (This is because the initial use of this widget set is to plot historical data against date, and the AtLabelAxis is used for the X axis. The application attaches data to the AtLabelAxis with a member function called AtLabelAxisAttachData()[14] that acts similarly to the attach procedures for the AtXYLinePlot, AtLinePlot and AtBarPlot classes. It would be used in a manner similar to this: 98 AtLabelAxisAttachData(label_axis, (XtPointer) &answers[0].date_ptr, 8 sizeof(answers[0]), 0, NUM_ANSWERS); The arguments to this function are: 9The AtLabelAxis label_axis that you are attaching the data to. 9A pointer &answers[0].data_ptr to a String that is the first X axis label. 9The stride sizeof(answers[0]), or number of bytes between successive Strings. The X axis value of the first String. This may or may not be the minimum value for the axis, depending on the XtNautoScale resource. The number NUM_ANSWERS of strings in the array. 9 If the nth String is non-NULL and points to a non-empty string, then a tic mark is placed at that X value with the label specified by that string. Otherwise no tic mark or label is ____________________ 9 [14]Which is not an alias for the AtSPlot function! This would be one place where multiple inheritance would be nice, as the AtLabelAxis has elements of both AxisCore and AtSPlot classes. _________________________________________________________________ August 1992 17 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ placed there. This gives the application writer complete control over labeling the axis. For example, in the above code fragment, the application writer would make sure the date_ptr field of the answers[] array (which should be a char *) would only be set on elements representing the first of the month, and would point to a string like "July, 1990". _4._6. _F_r_a_m_e _A_x_e_s The AtFrameAxis class is so named because the original use was to put two more axes around simple graphs so that they were completely enclosed. (This gives a more balanced look.) This can also be done setting the XtNdrawFrame resource of an object of the AtAxisCore subclasses (like AtXYAxis), which draws a single solid line as axis frame without tics, subtics and labels. An AtFrameAxis object is conceptually attached to another AtAxisCore object (in this or another graph), and, when asked about axis bounds or tic positions, gets the answer by looking at the axis to which it is attached. The frame axis is attached to its target axis by setting the XtNwidget resource. The only things imported from the target axis are the tic and subtic values, the tic labels and the endpoints. The resources concerned with displaying the axis (e.g. things such as color, font, label, tic length, whether or not to draw the tic labels, etc) are individually settable. This is very flexible but may require two axes to be changed instead of one in some circumstances. One use might be to have a frame axis as the X2 axis attached to the normal X axis. It would get the same tic, subtic and bounds information as the X axis, giving a nice symmetric look. The labels would also be the same, even though they might be rendered in a different font. _4._7. _I_n_t_e_r-_g_r_a_p_h _l_i_n_k_i_n_g The third method for handling axes is the most flexible but also the most complex for the programmer. As part of the layout processing, each axis gets presented with the minimum and maximum values of all of the plot widgets that are associated with that axis. The axis then does whatever processing is required to determine the endpoints of the axis (in user space, not pixels), such as rounding or examining other axes. Finally, before the values are returned to the main plotter code, the AxisCore code calls the XtNrangeCallback callback of the axis. This routine is passed three arguments: the widget ID of the axis, the closure field specified when the callback was added (using XtAddCallback() or equivalent), and a pointer to an AtAxisRangeArgs structure. The AtAxisRangeArgs structure is defined in and looks like this: 9 _________________________________________________________________ August 1992 18 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ 98 typedef struct { 8 double *minp, *maxp, *tic_intervalp; 8 int *max_widthp; 8 } AtAxisRangeArgs; The four pointers point to the currently chosen values for the maximum and minimum values of the axis, the interval (in user space) between successive tics, and the maximum width (in pixels) of the tic labels. The called routine can chose whatever it likes for these values and, by setting the pointed-to variables, will affect the values used by the axis. The number width field is supposed to be the width of the widest tic label, and is used to calculate the axis "width" (and hence the pixel position of the axis). Like the axis "width" it represents height of the labels for horizontal axes (as that is what determines the pixel Y position for that axis), and the real width for vertical axes (as that determines the X pixel position). Why is this important? Consider the three stacked graphs discussed above. The pixel position of the Y axis of a graph depends on the width of the Y axis. So to maintain all Y axes at the same pixel locations it is important to make all three Y axes have the same number width (assuming all Y axes have the XtNdrawNumbers and XtNnumbersOutside resources set to True), as well as making sure the tic length and label resources etc. the same. _4._8. _E_x_t_e_n_d_i_n_g _G_r_a_p_h_s A facility that is important in the plot widgets implemented so far is the ability to efficiently handle graphs that are being extended. The intention is to allow efficient and reduced- flicker update of graphs that are being added to in sort-of real time (say once every few seconds). As an example, consider something like xmeter or perfmeter on the Sun - a strip chart that is added to every 20 seconds, and, once every couple of minutes does a shift to the left to leave more room to stuff to be added. The AtSPlot and AtXYPlot classes support this via member functions[15]: 98 AtSPlotDataExtended(widget, num) and 98 AtXYPlotDataExtended(widget ,num) This tells the graph that extra data has arrived, and the new maximum (not the number added!) is now num. If there is enough room on the X axis, and the new data doesn't go over the Y ____________________ 9 [15]There are #define'd versions of this for all subclasses of AtSPlot and AtXYPlot, including the AtLinePlot, AtBarPlot and AtXYLinePlot classes. 9_________________________________________________________________ August 1992 19 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ axis bounds, the new data points are calculated and redrawn with minimum effort, and little or no redrawing of the rest of the display. If either X or Y axis bounds are exceeded, or num is less than the current value, the equivalent of an attach is done and the graph is redrawn. _4._9. _C_a_l_l_b_a_c_k_s For the application programmer, the AthenaTools Plotter Widget Set provides additional callbacks[16] to permit user interaction and more flexibility. Procedures in the XtNmotionCallback list are called when mouse motion events occur over the plotting area. That may be used to follow the pointer and to get the current pointer position on the plotting area. The call_data argument to the XtNmotionCallback is of type AtPointCallbackData as defined in At/Plotter.h: 98 typedef struct { 8 short pixelx, pixely; /* Pixel point coordinates */ 8 double x1, y1; /* 1st axes point coordinates */ 8 double x2, y2; /* 2nd axes point coordinates */ 8 } AtPointCallbackData; The items pixelx and pixely contain the pixel coordinates of the current pointer position, x1 and y1 the user coordinates scaled against the first X and Y axes, x2 and y2 the user coordinates scaled against the second axis X2 and Y2. Some of the example programs make use of this callback. Procedures of the XtNclickCallback list are called when mouse button one is clicked in the plotting aread. That may be used to request the current pointer position in pixel and user coordinates. The call_data argument of the XtNclickCallback is also of type AtPointCallbackData (see above). Procedures of the XtNdragCallback list are called when mouse button one is dragged over the plotting area. This callback may be used to define a rectangle on the plotting area, for example, for further zooming, as it is done by some of the sample programs. The call_data argument to the XtNdragCallback, also defined in At/Plotter.h is of type AtRectangleCallbackData: 98 typedef struct { 8 short pixelx1, pixely1; /* Pixel lower left */ 8 short pixelx2, pixely2; /* Pixel upper rigth */ 8 double x11, y11, x12, y12; /* 1st axes range coordinates */ 8 double x21, y21, x22, y22; /* 2nd axes range coordinates */ 8 } AtRectangleCallbackData; Pixelx1 and pixely1 contain the pixel coordinates of the lower left corner of the defined rectangle, Pixelx2 and pixely2 the pixel coordinates of the upper right corner. In a similar fashion contain x11, y11, x12 and y12 the user coordinates of the ____________________ 9 [16]The Version 4 provided similar callbacks, but these were dropped out in Version 5. 9_________________________________________________________________ August 1992 20 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ lower left corner scaled against the axes X, Y and X2, Y2, x21, y21, x22 and y22 the user coordinates of the upper right corner also scaled against the axes X, Y and X2, Y2. Care should be taken not to make superfluous use of the XtNmotionCallback, XtNclickCallback and XtNdragCallback callbacks, to avoid unnecessary activity of the plotter widget. 9 _________________________________________________________________ August 1992 21 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ _4._1_0. _T_h_e _M_o_t_i_f _T_e_s_t _P_r_o_g_r_a_m _m_p_l_o_t The OSF/Motif demo program mplot, as shown on the title page, should be included in the directory motif. Most of the Motif stuff was generated with the User Interface Builder _M_o_t_i_f_a_t_i_o_n. All the interesting stuff on how to use and program the plotter widgets can bei found in the source file Plot.c: 8/* 8 * Plot.c 8 * 8 * Plotter demo program using motif 8 * klin, Mon Aug 3 16:24:02 1992 8 */ 98#include 8#include 8#include 98#include 8#include 8#include 98#include "mplot.xbm" 98static Widget plotter; /* The plotter widget */ 8static Widget xaxis, yaxis; /* The axis widgets */ 8static Widget line1 = NULL; /* The 3 demo lines */ 8static Widget line2 = NULL; 8static Widget line3 = NULL; 8static Widget line4 = NULL; /* The 3 user lines */ 8static Widget line5 = NULL; 8static Widget line6 = NULL; 98#define TITLE "Plotter Widget Demo" /* Plotter title */ 8#define WIDTH 600 /* Plotter width */ 8#define HEIGHT 400 /* Plotter height */ 8#define MARGIN 6 /* Plotter margin */ 8#define ZOOM 100.0 /* Max zoom in % */ 98#define VERSION "0he Athena Tools Plotter Widget Set0ersion 6-beta0atchlevel 3, Aug 4 19920; 98#define COPYRIGHT "0 1990 by the Massachusetts Institute of Technology0 1991 by Burdett, Buckeridge & Young Ltd.0 1992 by University of Paderborn0; 98#define AUTHOR "0SF/Motif Demo Program by Peter Klingebiel (klin@iat.uni-paderborn.de)0ave fun and enjoy0 98char *version = VERSION; 8char *copyright = COPYRIGHT; 8char *author = AUTHOR; 98/* 8 * External widgets used here 8 */ 98extern Boolean display_demo_lines; 8extern XtAppContext application_context; 8extern Widget appshell; 98extern Widget plotter_form, plotter_frame, position_frame, title_label; 8extern Widget xpos_label, ypos_label, x_text, y_text; 8extern Widget ask_label, zoom_label; 8extern Widget linearx_button, lineary_button; 8extern Widget logarithmicx_button, logarithmicy_button; 8extern Widget subgrid_button; 8extern Widget dialog; 98/* 8 * The plot data 8 */ 98struct point { 8 double xval; 8 double yval1; 8 double yval2; 8}; 98#define CNUM 24 8#define PNUM 6 98static struct point curve[CNUM]; 98static AtDoublePoint polygon[PNUM]; 98/* 8 * Create plotter and axes 8 */ 98static void MakePlotter(parent) 8 Widget parent; 8{ 8 Arg args[10]; 8 int n; 98 /* Create the plotter */ 8 n = 0; 8 XtSetArg(args[n], XtNwidth, WIDTH); n++; 8 XtSetArg(args[n], XtNheight, HEIGHT); n++; 8 XtSetArg(args[n], XtNborderWidth, 0); n++; 8 XtSetArg(args[n], XtNmarginWidth, MARGIN); n++; 8 XtSetArg(args[n], XtNmarginHeight, MARGIN); n++; 8 XtSetArg(args[n], XtNtitle, TITLE); n++; _________________________________________________________________ August 1992 22 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ 8 XtSetArg(args[n], XtNshowTitle, False); n++; 8 XtSetArg(args[n], XtNshowLegend, True); n++; 8 plotter = XtCreateManagedWidget("plotter", atPlotterWidgetClass, parent, args, n); 98 /* Create the X axis */ 8 n = 0; 8 XtSetArg(args[n], XtNlabel, "Time"); n++; 8 XtSetArg(args[n], XtNaxisWidth, 1); n++; 8 xaxis = XtCreateWidget("xaxis", atXYAxisWidgetClass, plotter, args, n); 98 /* Create the Y axis */ 8 n = 0; 8 XtSetArg(args[n], XtNlabel, "Amplitude"); n++; 8 XtSetArg(args[n], XtNaxisWidth, 1); n++; 8 XtSetArg(args[n], XtNvertical, True); n++; 8 yaxis = XtCreateWidget("yaxis", atXYAxisWidgetClass, plotter, args, n); 98 /* Attach X and Y axes to the plotter */ 8 n = 0; 8 XtSetArg(args[n], XtNxAxis, xaxis); n++; 8 XtSetArg(args[n], XtNyAxis, yaxis); n++; 8 XtSetValues(plotter, args, n); 8} 98/* 8 * Create the 3 lines 8 */ 8void MakeDemoLines() 8{ 8 Arg args[4]; 8 int n; 98 /* Create line 1 */ 8 n = 0; 8 XtSetArg(args[n], XtNlegendName, "sinus-points"); n++; 8 XtSetArg(args[n], XtNplotLineStyle, AtLineDOTTED); n++; 8 XtSetArg(args[n], XtNplotMarkType, AtMarkRECTANGLE); n++; 8 line1 = XtCreateWidget("line1", atXYLinePlotWidgetClass, plotter, args, n); 98 /* Create line 2 */ 8 n = 0; 8 XtSetArg(args[n], XtNlegendName, "cosinus-points"); n++; 8 XtSetArg(args[n], XtNplotLineStyle, AtLineDOTDASHED); n++; 8 XtSetArg(args[n], XtNplotMarkType, AtMarkXMARK); n++; 8 line2 = XtCreateWidget("line2", atXYLinePlotWidgetClass, plotter, args, n); 98 /* Create line 3 */ 8 n = 0; 8 XtSetArg(args[n], XtNlegendName, "polygon"); n++; 8 XtSetArg(args[n], XtNplotMarkType, AtMarkSTAR); n++; 8 line3 = XtCreateWidget("line3", atXYLinePlotWidgetClass, plotter, args, n); 8} 98/* 8 * Create the plot data and attach them to the demo lines 8 */ 98static void MakeData() 8{ 8 double sin(), cos(); 8 double x; 8 int i; 98 /* Create two curves from own data type struct point */ 8 for(i = 0, x = 0.125; i < CNUM; i++, x += 0.275) { 8 curve[i].xval = x; 8 curve[i].yval1 = 3.50 * sin(x); 8 curve[i].yval2 = 2.67 * cos(x); 8 } 98 /* Create a polygon from type AtDoublePoint */ 8 polygon[0].x = 1.0; polygon[0].y = 1.0; 8 polygon[1].x = 5.0; polygon[1].y = 4.0; 8 polygon[2].x = 8.0; polygon[2].y = 3.0; 8 polygon[3].x = 6.0; polygon[3].y = -2.0; 8 polygon[4].x = 3.0; polygon[4].y = -3.0; 8 polygon[5].x = 1.0; polygon[5].y = 1.0; 8} 98static void AttachData() 8{ 8 /* Attach curve from own defined type point to line1 and line 2*/ 8 AtXYLinePlotAttachData(line1, 8 (XtPointer) &curve[0].xval, AtDouble, sizeof(struct point), 8 (XtPointer) &curve[0].yval1, AtDouble, sizeof(struct point), 8 1, CNUM); 8 AtXYLinePlotAttachData(line2, 8 (XtPointer) &curve[0].xval, AtDouble, sizeof(struct point), 8 (XtPointer) &curve[0].yval2, AtDouble, sizeof(struct point), 8 1, CNUM); 98 /* Attach polygon from predefined type AtDoublePoint to line3 */ 8 AtXYLinePlotAttachDoublePoints(line3, &polygon[0], 1, PNUM); 8} 98/* 8 * Read data from file 8 */ 8static char *ReadPlotData(filename) 8 char *filename; 8{ 8 static char msg[256]; 8 Arg args[8]; 8 char buf[256]; 8 AtDoublePoint *data, *p; 8 FILE *fp; 8 double x, y; 8 char *errmsg; 8 int nd, n; _________________________________________________________________ August 1992 23 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ 8 if(fp = fopen(filename, "r")) { 8 fgets(buf, sizeof(buf), fp); 8 nd = atoi(buf); 8 data = (AtDoublePoint *) calloc(nd, sizeof(AtDoublePoint)); 8 for(p = data, n = 0; n < nd && fgets(buf, sizeof(buf), fp); p++, n++) { 8 sscanf(buf, "%lf %lf", &x, &y); 8 p->x = x; 8 p->y = y; 8 } 8 fclose(fp); 8 if(nd == n) { 8 if(line4 == NULL) { 8 n = 0; 8 XtSetArg(args[n], XtNlegendName, "test-data1"); n++; 8 XtSetArg(args[n], XtNplotLineType, AtPlotLINEPOINTS); n++; 8 XtSetArg(args[n], XtNplotMarkType, AtMarkDIAMOND); n++; 8 XtSetArg(args[n], XtNplotLineStyle, AtLineSOLID), n++; 8 line4 = XtCreateWidget("line4", atXYLinePlotWidgetClass, plotter, args, n); 8 AtXYLinePlotAttachDoublePoints(line4, data, 1, nd); 8 } 8 else if(line5 == NULL) { 8 n = 0; 8 XtSetArg(args[n], XtNlegendName, "test-data2"); n++; 8 XtSetArg(args[n], XtNplotLineType, AtPlotLINEPOINTS); n++; 8 XtSetArg(args[n], XtNplotMarkType, AtMarkTRIANGLE1); n++; 8 XtSetArg(args[n], XtNplotLineStyle, AtLineDASHED), n++; 8 line5 = XtCreateWidget("line5", atXYLinePlotWidgetClass, plotter, args, n); 8 AtXYLinePlotAttachDoublePoints(line5, data, 1, nd); 8 } 8 else if(line6 == NULL) { 8 n = 0; 8 XtSetArg(args[n], XtNlegendName, "test-data3"); n++; 8 XtSetArg(args[n], XtNplotLineType, AtPlotLINEIMPULSES); n++; 8 XtSetArg(args[n], XtNplotMarkType, AtMarkDIAMOND); n++; 8 XtSetArg(args[n], XtNplotLineStyle, AtLineSOLID), n++; 8 line6 = XtCreateWidget("line6", atXYLinePlotWidgetClass, plotter, args, n); 8 AtXYLinePlotAttachDoublePoints(line6, data, 1, nd); 8 } 8 errmsg = NULL; 8 } 8 else { 8 free(data); 8 sprintf(msg, "Warning: Cannot not read %d items from data file %s", nd, filename); 8 errmsg = msg; 8 } 8 } 8 else { 8 sprintf(msg, "Warning: Cannot open data file %s", filename); 8 errmsg = msg; 8 } 8 return(errmsg); 8} 98/* 8 * The mainmenu callbacks 8 */ 98extern int exit(); 98/* callback from dialog */ 8static char *plotfilename = NULL; 98/* file_pulldown: quit_button */ 8void quit_callback() 8{ 8 exit(0); 8} 98/* file_pulldown: read_button */ 8void cancelread_callback(); 98void readdata_callback(widget, client_data, call_data) 8 Widget widget; 8 XtPointer client_data; 8 XmSelectionBoxCallbackStruct *call_data; 8{ 8 char *msg; 98 XtRemoveCallback(dialog, XmNokCallback, readdata_callback, NULL); 8 XtRemoveCallback(dialog, XmNcancelCallback, cancelread_callback, NULL); 8 XmStringGetLtoR(call_data->value, XmSTRING_DEFAULT_CHARSET, &plotfilename); 8 if(plotfilename) { 8 if(msg = ReadPlotData(plotfilename)) 8 Popup_warning(msg); 8 XtFree(plotfilename); 8 plotfilename = NULL; 8 } 8} 98void cancelread_callback() 8{ 8 XtRemoveCallback(dialog, XmNokCallback, readdata_callback, NULL); 8 XtRemoveCallback(dialog, XmNcancelCallback, cancelread_callback, NULL); 8} 98void read_callback() 8{ 8 if(line4 && line5 && line6) { 8 Popup_warning("Warning: Cannot create more than 3 lines"); 8 } 8 else 8 Popup_dialog(readdata_callback, cancelread_callback, 8 "Plotter Demo Datafile Selection", "*.data"); 8} 98/* file_pulldown: print_button */ 8static char *printfilename = NULL; 98void cancelprint_callback(); _________________________________________________________________ August 1992 24 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ 8void psprint_callback(widget, client_data, call_data) 8 Widget widget; 8 XtPointer client_data; 8 XmSelectionBoxCallbackStruct *call_data; 8{ 8 char msg[256]; 98 XtRemoveCallback(dialog, XmNokCallback, psprint_callback, NULL); 8 XtRemoveCallback(dialog, XmNcancelCallback, cancelprint_callback, NULL); 8 XmStringGetLtoR(call_data->value, XmSTRING_DEFAULT_CHARSET, &printfilename); 8 if(printfilename) { 8 AtPlotterGeneratePostscript(printfilename, (AtPlotterWidget) plotter, 8 "Sample Plot", 50, 50, 480, 320, False); 8 XtFree(printfilename); 8 printfilename = NULL; 8 } 8} 98void cancelprint_callback() 8{ 8 XtRemoveCallback(dialog, XmNokCallback, psprint_callback, NULL); 8 XtRemoveCallback(dialog, XmNcancelCallback, cancelprint_callback, NULL); 8} 98void print_callback() 8{ 8 Popup_dialog(psprint_callback, cancelprint_callback, 8 "Plot Demo PS Print", "*.ps"); 8} 98/* plot_pulldown: askposition_button */ 8static Boolean is_asking = False; 98void get_click_callback(widget, client_data, call_data) 8 Widget widget; 8 XtPointer client_data; 8 AtPointCallbackData *call_data; 8{ 8 static char xstr[64], ystr[64]; 8 Arg args[2]; 98 sprintf(xstr, "%.4lf", call_data->x1); 8 XtSetArg(args[0], XmNvalue, xstr); 8 XtSetValues(x_text, args, 1); 8 sprintf(ystr, "%.4lf", call_data->y1); 8 XtSetArg(args[0], XmNvalue, ystr); 8 XtSetValues(y_text, args, 1); 8} 98void askposition_callback() 8{ 8 Arg args[4]; 98 if(is_asking) { 8 XtRemoveAllCallbacks(plotter, XtNclickCallback); 8 XtSetArg(args[0], XmNvalue, ""); 8 XtSetValues(x_text, args, 1); 8 XtSetValues(y_text, args, 1); 8 XtSetArg(args[0], XmNsensitive, False); 8 XtSetValues(ask_label, args, 1); 8 is_asking = False; 8 } 8 else { 8 XtAddCallback(plotter, XtNclickCallback, get_click_callback, NULL); 8 XtSetArg(args[0], XmNsensitive, True); 8 XtSetValues(ask_label, args, 1); 8 is_asking = True; 8 } 8} 98/* plot_pulldown: getposition_button */ 8static Boolean is_positioning = False; 98void get_motion_callback(widget, client_data, call_data) 8 Widget widget; 8 XtPointer client_data; 8 AtPointCallbackData *call_data; 8{ 8 static char xstr[64], ystr[64]; 8 Arg args[2]; 98 sprintf(xstr, "%.4lf", call_data->x1); 8 XtSetArg(args[0], XmNvalue, xstr); 8 XtSetValues(x_text, args, 1); 8 sprintf(ystr, "%.4lf", call_data->y1); 8 XtSetArg(args[0], XmNvalue, ystr); 8 XtSetValues(y_text, args, 1); 8} 98void getposition_callback() 8{ 8 Arg args[4]; 98 if(is_positioning) { 8 XtRemoveAllCallbacks(plotter, XtNmotionCallback); 8 XtSetArg(args[0], XmNsensitive, False); 8 XtSetValues(xpos_label, args, 1); 8 XtSetValues(ypos_label, args, 1); 8 XtSetArg(args[0], XmNvalue, ""); 8 XtSetValues(x_text, args, 1); 8 XtSetValues(y_text, args, 1); 8 is_positioning = False; 8 } 8 else { 8 XtSetArg(args[0], XmNsensitive, True); 8 XtSetValues(xpos_label, args, 1); 8 XtSetValues(ypos_label, args, 1); 8 XtAddCallback(plotter, XtNmotionCallback, get_motion_callback, NULL); 8 is_positioning = True; _________________________________________________________________ August 1992 25 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ 8 } 8} 98void plotterform_callback(widget, client_data, event, cont) 8 Widget widget; 8 XtPointer client_data; 8 XEvent *event; 8 Boolean cont; 8{ 8 Arg args[2]; 8 Boolean enter = (Boolean) client_data; 98 if(enter) { 8 XtSetArg(args[0], XmNshadowType, XmSHADOW_IN); 8 } 8 else { 8 if(is_positioning && !is_asking) { 8 XtSetArg(args[0], XmNvalue, ""); 8 XtSetValues(x_text, args, 1); 8 XtSetValues(y_text, args, 1); 8 } 8 XtSetArg(args[0], XmNshadowType, XmSHADOW_OUT); 8 } 8 XtSetValues(plotter_frame, args, 1); 8} 98/* plot_pulldown: zoom_button */ 98static double oldxmin, oldxmax, minxlen; 8static double oldymin, oldymax, minylen; 98void get_drag_callback(widget, client_data, call_data) 8 Widget widget; 8 XtPointer client_data; 8 AtRectangleCallbackData *call_data; 8{ 8 Arg args[4]; 8 char msg[256]; 8 static double x1, y1, x2, y2; 8 double xl, yl; 98 x1 = call_data->x11; 8 x2 = call_data->x12; 8 xl = fabs(x2 - x1); 8 y1 = call_data->y11; 8 y2 = call_data->y12; 8 yl = fabs(y2 - y1); 8 if(xl < minxlen) { 8 sprintf(msg, "Warning: Zooming not possible for X axis (>%.0lf%%)", ZOOM); 8 Popup_warning(msg); 8 } 8 else { 8 XtSetArg(args[0], XtNmin, &x1); 8 XtSetArg(args[1], XtNmax, &x2); 8 XtSetArg(args[2], XtNautoScale, False); 8 XtSetValues(xaxis, args, 3); 8 } 8 if(yl < minylen) { 8 sprintf(msg, "Warning: Zooming not possible for Y axis (>%.0lf%%)", ZOOM); 8 Popup_warning(msg); 8 } 8 else { 8 XtSetArg(args[0], XtNmin, &y1); 8 XtSetArg(args[1], XtNmax, &y2); 8 XtSetArg(args[2], XtNautoScale, False); 8 XtSetValues(yaxis, args, 3); 8 } 8} 98void zoom_callback() 8{ 8 Arg args[6]; 8 int n; 8 static Boolean is_zooming = False; 98 if(is_zooming) { 8 XtRemoveAllCallbacks(plotter, XtNdragCallback); 8 XtSetArg(args[0], XtNmin, &oldxmin); 8 XtSetArg(args[1], XtNmax, &oldxmax); 8 XtSetArg(args[2], XtNautoScale, True); 8 XtSetValues(xaxis, args, 3); 8 XtSetArg(args[0], XtNmin, &oldymin); 8 XtSetArg(args[1], XtNmax, &oldymax); 8 XtSetArg(args[2], XtNautoScale, True); 8 XtSetValues(yaxis, args, 3); 8 XtSetArg(args[0], XmNsensitive, False); 8 XtSetValues(zoom_label, args, 1); 8 is_zooming = False; 8 } 8 else { 8 XtVaGetValues(xaxis, XtNmin, &oldxmin, XtNmax, &oldxmax, NULL); 8 XtVaGetValues(yaxis, XtNmin, &oldymin, XtNmax, &oldymax, NULL); 8 minxlen = (oldxmax - oldxmin) / ZOOM; 8 minylen = (oldymax - oldymin) / ZOOM; 8 XtAddCallback(plotter, XtNdragCallback, get_drag_callback, NULL); 8 XtSetArg(args[0], XmNsensitive, True); 8 XtSetValues(zoom_label, args, 1); 8 is_zooming = True; 8 } 8} 98/* plot_pulldown: legend_button */ 8void legend_callback() 8{ 8 Arg args[2]; 8 Boolean l; 98 XtVaGetValues(plotter, XtNshowLegend, &l, NULL); 8 l = l ? False : True; _________________________________________________________________ August 1992 26 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ 8 XtSetArg(args[0], XtNshowLegend, l); 8 XtSetValues(plotter, args, 1); 8} 98/* plot_pulldown: position_button */ 8void position_callback() 8{ 8 Arg args[4]; 8 Boolean l; 98 XtVaGetValues(plotter, XtNlegendLeft, &l, NULL); 8 l = l ? False : True; 8 XtSetArg(args[0], XtNshowLegend, True); 8 XtSetArg(args[1], XtNlegendLeft, l); 8 XtSetValues(plotter, args, 2); 8} 98/* plot_pulldown: pixmap_button */ 8void pixmap_callback() 8{ 8 Arg args[2]; 8 Boolean l; 98 XtVaGetValues(plotter, XtNusePixmap, &l, NULL); 8 l = l ? False : True; 8 XtSetArg(args[0], XtNusePixmap, l); 8 XtSetValues(plotter, args, 1); 8} 98/* axis_pulldown: transform_button */ 8void transform_callback(widget, client_data, call_data) 8 Widget widget; 8 XtPointer client_data; 8 XmAnyCallbackStruct call_data; 98{ 8 Arg args[2]; 98 if(AtAxisGetTransform(xaxis) == AtTransformLOGARITHMIC) { 8 XtSetArg(args[0], XmNsensitive, True); 8 XtSetValues(linearx_button, args, 1); 8 XtSetArg(args[0], XmNsensitive, False); 8 XtSetValues(logarithmicx_button, args, 1); 8 } 8 else { /* LINEAR */ 8 XtSetArg(args[0], XmNsensitive, False); 8 XtSetValues(linearx_button, args, 1); 8 XtSetArg(args[0], XmNsensitive, True); 8 XtSetValues(logarithmicx_button, args, 1); 8 } 8 if(AtAxisGetTransform(yaxis) == AtTransformLOGARITHMIC) { 8 XtSetArg(args[0], XmNsensitive, True); 8 XtSetValues(lineary_button, args, 1); 8 XtSetArg(args[0], XmNsensitive, False); 8 XtSetValues(logarithmicy_button, args, 1); 8 } 8 else { /* LINEAR */ 8 XtSetArg(args[0], XmNsensitive, False); 8 XtSetValues(lineary_button, args, 1); 8 XtSetArg(args[0], XmNsensitive, True); 8 XtSetValues(logarithmicy_button, args, 1); 8 } 8} 98/* axis_pulldown/transform_pulldown: linearx_button */ 8void linearx_callback() 8{ 8 Arg args[2]; 98 XtSetArg(args[0], XtNaxisTransform, AtTransformLINEAR); 8 XtSetValues(xaxis, args, 1); 8} 98/* axis_pulldown/transform_pulldown: logarithmicx_button */ 8void logarithmicx_callback() 8{ 8 Arg args[2]; 98 XtSetArg(args[0], XtNaxisTransform, AtTransformLOGARITHMIC); 8 XtSetValues(xaxis, args, 1); 8} 8/* axis_pulldown/transform_pulldown: lineary_button */ 8void lineary_callback() 8{ 8 Arg args[2]; 98 XtSetArg(args[0], XtNaxisTransform, AtTransformLINEAR); 8 XtSetValues(yaxis, args, 1); 8} 98/* axis_pulldown/transform_pulldown: logarithmicy_button */ 8void logarithmicy_callback() 8{ 8 Arg args[2]; 98 XtSetArg(args[0], XtNaxisTransform, AtTransformLOGARITHMIC); 8 XtSetValues(yaxis, args, 1); 8} 98/* axis_pulldown/round button: roundx_button */ 8void roundx_callback() 8{ 8 Arg args[2]; 8 Boolean r; 98 XtVaGetValues(xaxis, XtNroundEndpoints, &r, NULL); 8 XtSetArg(args[0], XtNroundEndpoints, r ? False : True); 8 XtSetValues(xaxis, args, 1); 8} _________________________________________________________________ August 1992 27 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ 8/* axis_pulldown/round button: roundy_button */ 8void roundy_callback() 8{ 8 Arg args[2]; 8 Boolean r; 98 XtVaGetValues(yaxis, XtNroundEndpoints, &r, NULL); 8 XtSetArg(args[0], XtNroundEndpoints, r ? False : True); 8 XtSetValues(yaxis, args, 1); 8} 98/* axis_pulldown: grid_button */ 8void grid_callback() 8{ 8 Arg aargs[2]; 8 Arg gargs[2]; 8 Boolean gx, gy; 98 XtVaGetValues(xaxis, XtNdrawGrid, &gx, NULL); 8 XtVaGetValues(yaxis, XtNdrawGrid, &gy, NULL); 8 if(gx || gy) { 8 XtSetArg(aargs[0], XtNdrawGrid, False); 8 XtSetArg(gargs[0], XmNsensitive, False); 8 } 8 else { 8 XtSetArg(aargs[0], XtNdrawGrid, True); 8 XtSetArg(gargs[0], XmNsensitive, True); 8 } 8 XtSetValues(xaxis, aargs, 1); 8 XtSetValues(yaxis, aargs, 1); 8 XtSetValues(subgrid_button, gargs, 1); 8} 98/* axis_pulldown: subgrid_button */ 8void subgrid_callback() 8{ 8 Arg args[2]; 8 Boolean gx, gy, gn; 98 XtVaGetValues(xaxis, XtNdrawSubgrid, &gx, NULL); 8 XtVaGetValues(yaxis, XtNdrawSubgrid, &gy, NULL); 8 gn = gx || gy ? False : True; 8 XtSetArg(args[0], XtNdrawSubgrid, gn); 8 XtSetValues(xaxis, args, 1); 8 XtSetValues(yaxis, args, 1); 8} 98/* line_pulldown: linewidth_buttons 0..3 contained in client_data */ 8void width_callback(widget, client_data, call_data) 8 Widget widget; 8 XtPointer client_data; 8 XmAnyCallbackStruct call_data; 8{ 8 Arg args[2]; 98 XtSetArg(args[0], XtNlineWidth, client_data); 8 if(line1) 8 XtSetValues(line1, args, 1); 8 if(line2) 8 XtSetValues(line2, args, 1); 8 if(line3) 8 XtSetValues(line3, args, 1); 8 if(line4) 8 XtSetValues(line4, args, 1); 8 if(line5) 8 XtSetValues(line5, args, 1); 8 if(line6) 8 XtSetValues(line6, args, 1); 8} 98/* line_pulldown: linetype_buttons. Type is contained in client_data */ 8void type_callback(widget, client_data, call_data) 8 Widget widget; 8 XtPointer client_data; 8 XmAnyCallbackStruct call_data; 8{ 8 Arg args[2]; 8 AtPlotLineType type; 98 switch((int) client_data) { 8 case 0: type = AtPlotLINES; break; 8 case 1: type = AtPlotPOINTS; break; 8 case 2: type = AtPlotIMPULSES; break; 8 case 3: type = AtPlotSTEPS; break; 8 case 4: type = AtPlotLINEPOINTS; break; 8 case 5: type = AtPlotLINEIMPULSES; break; 8 case 6: type = AtPlotBARS; break; 8 default: return; 8 } 8 XtSetArg(args[0], XtNplotLineType, type); 8 if(line1) 8 XtSetValues(line1, args, 1); 8 if(line2) 8 XtSetValues(line2, args, 1); 8 if(line3) 8 XtSetValues(line3, args, 1); 8 if(line4) 8 XtSetValues(line4, args, 1); 8 if(line5) 8 XtSetValues(line5, args, 1); 8 if(line6) 8 XtSetValues(line6, args, 1); 8} 98/* line_pulldown: linestyle_buttons. Style is contained in client_data */ 8void style_callback(widget, client_data, call_data) 8 Widget widget; 8 XtPointer client_data; 8 XmAnyCallbackStruct call_data; _________________________________________________________________ August 1992 28 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ 8{ 8 Arg args[2]; 8 AtPlotLineStyle style; 98 switch((int) client_data) { 8 case 0: style = AtLineSOLID; break; 8 case 1: style = AtLineDOTTED; break; 8 case 2: style = AtLineDASHED; break; 8 case 3: style = AtLineDOTDASHED; break; 8 case 4: style = AtLineDOTTED3; break; 8 case 5: style = AtLineDASHED4; break; 8 case 6: style = AtLineDOTDASHED2; break; 8 default: return; 8 } 8 XtSetArg(args[0], XtNplotLineStyle, style); 8 if(line1) 8 XtSetValues(line1, args, 1); 8 if(line2) 8 XtSetValues(line2, args, 1); 8 if(line3) 8 XtSetValues(line3, args, 1); 8 if(line4) 8 XtSetValues(line4, args, 1); 8 if(line5) 8 XtSetValues(line5, args, 1); 8 if(line6) 8 XtSetValues(line6, args, 1); 8} 98/* help_pulldown: version_button */ 8void version_callback() 8{ 8 Popup_help(version); 8} 98/* help_pulldown: copyright_button */ 8void copyright_callback() 8{ 8 Popup_help(copyright); 8} 98/* help_pulldown: author_button */ 8void author_callback() 8{ 8 Popup_help(author); 8} 98/* 8 * Handler for Xt warnings 8 */ 98static void warning_handler(msg) 8 char *msg; 8{ 8 char buf[256]; 98 sprintf(buf, "Warning: %s", msg); 8 Popup_warning(buf); 8} 98/* 8 * Build plotter and create/attach data 8 */ 98void BuildPlotter() 8{ 8 Arg args[2]; 8 XmString xms[1]; 8 Display *dpy; 8 Window win; 8 Pixmap ipm; 98 /* Set the icon bitmap */ 8 dpy = XtDisplay(appshell); 8 win = DefaultRootWindow(dpy); 8 ipm = XCreateBitmapFromData(dpy, win, mplot_bits, mplot_width, mplot_height); 8 XtSetArg(args[0], XmNiconPixmap, ipm); 8 XtSetValues(appshell, args, 1); 98 /* Set the title */ 8 xms[0] = (XmString) XmStringCreateLtoR(TITLE, XmSTRING_DEFAULT_CHARSET); 8 XtSetArg(args[0], XmNlabelString, xms[0]); 8 XtSetValues(title_label, args, 1); 8 XmStringFree(xms[0]); 98 /* Make plotter/axes/lines and data */ 8 MakePlotter(plotter_frame); 98 /* Create the demo lines and attach data */ 8 if(display_demo_lines == True) { 8 MakeDemoLines(); 8 MakeData(); 8 AttachData(); 8 } 98 /* Set a warning message handler */ 8 XtAppSetWarningHandler(application_context, warning_handler); 8} 9 _________________________________________________________________ August 1992 29 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ _4._1_1. _T_h_e _T_e_s_t _P_r_o_g_r_a_m _s_a_m_p_l_e__p_r_o_g Gregory Bond's test program sample_prog.c from version 5 of the plotter widget set should be included in the directory athena. 8/* 8 * A simple sample test program 8 * 8 * Copyright 1991 by Burdett, Buckeridge & Young Ltd. 8 */ 98/* First, the various headers required */ 98#include 8#include 8#include 8#include 98#ifdef _AtDevelopment_ 8#include "Plotter.h" 8#include "LinePlot.h" 8#include "BarPlot.h" 8#include "Axis.h" 8#else 8#include 8#include 8#include 8#include 8#endif 98/* 8 * The application data - weekly sales data for Widgets. 8 */ 8struct profits { 8 /* From database */ 8 long volume; 8 float buy_price; 8 float sell_price; 8 /* calculated values */ 8 double sales; 8 double cost; 8 double profit; 8}; 98#define NUM_WEEKS 52 98struct profits profits[NUM_WEEKS]; 98/* 8 * Read from the database - a dummy routine, we'll use random numbers 8 */ 8void ReadFromDatabase() 8{ 8 int i; 8 extern int rand(); 98 for (i = 0; i < NUM_WEEKS; i++) { 8 /* Volume between 1000 and 5095 */ 8 profits[i].volume = (rand() & 0xfff) + 1000; 8 /* Sell price between $15 and $25 */ 8 profits[i].sell_price = (double)(rand() & 0xffffff) / 8 0xffffff * 10.0 + 15.0; 8 /* Buy price between $5 and $15 */ 8 profits[i].buy_price = (double)(rand() & 0xffffff) / 8 0xffffff * 10.0 + 5.0; 8 } 8} 98/* 8 * Calculate the profit from the above data 8 */ 98void CalculateProfit() 8{ 8 int i; 98 for (i = 0; i < NUM_WEEKS; i++) { 8 profits[i].sales = profits[i].volume * 8 profits[i].sell_price; 8 profits[i].cost = profits[i].volume * profits[i].buy_price; 8 profits[i].profit = profits[i].sales - profits[i].cost; 8 } 8} 998/***************************************************************** 8 * 8 * This is the interesting bit. Make a simple graph, profits on left, 8 * volume on right, weeknumber on bottom, profit a line graph, volume 8 * a bar graph. 8 */ 98Widget plotter, xaxis, yaxis, y2axis, line, bar; 98void MakePlotter(parent) 8Widget parent; 8{ 8 double thousandth = 1.0e-3; 8 plotter = XtVaCreateManagedWidget("plotter", atPlotterWidgetClass, parent, 8 XtNtitle, "Widget Sales & Profits", 8 XtNwidth, 600, XtNheight, 450, 8 NULL); _________________________________________________________________ August 1992 30 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ 8 /* Note axis objects are unmanaged */ 8 xaxis = XtVaCreateWidget("xaxis", atAxisWidgetClass, plotter, 8 XtNlabel, "Week Number", 8 XtNticFormat, "%.0f", 8 NULL); 8 /* Note Y axis is vertical */ 8 yaxis = XtVaCreateWidget("yaxis", atAxisWidgetClass, plotter, 8 XtNvertical, True, 8 XtNlabel, "Profit ($1,000's)", 8 XtNticMultiplier, &thousandth, 8 NULL); 8 /* Note Y2 axis is vertical and mirrored */ 8 y2axis = XtVaCreateWidget("y2axis", atAxisWidgetClass, plotter, 8 XtNvertical, True, 8 XtNmirror, True, 8 XtNlabel, "Volume Shipped (1,000s)", 8 XtNdrawGrid, False, /* Two grids is confusing */ 8 XtNticMultiplier, &thousandth, 8 XtNticFormat, "%4.1f", 8 NULL); 8 /* Now attach axes to the parent */ 8 XtVaSetValues(plotter, XtNxAxis, xaxis, 8 XtNyAxis, yaxis, 8 XtNy2Axis, y2axis, 8 NULL); 98 /* Now create the plots */ 8 /* The volume is scaled against y2 axis */ 8 bar = XtVaCreateWidget("vol", atBarPlotWidgetClass, plotter, 8 XtNlegendName, "Volume", 8 XtNuseY2Axis, True, 8 XtNshading, AtGRAY3, /* For better PS */ 8 NULL); 8 /* But profit against Y axis */ 8 line = XtVaCreateWidget("profit", atLinePlotWidgetClass, plotter, 8 XtNlegendName, "Profit", 8 XtNlineWidth, 2, 8 NULL); 8} 98/***************************************************************** 8 * 8 * Attach the application data to the plot children 8 */ 98void AttachData() 8{ 8 AtLinePlotAttachData(line, (XtPointer)&profits[0].profit, 8 AtDouble, sizeof (struct profits), 8 1, NUM_WEEKS); 8 AtBarPlotAttachData(bar, (XtPointer)&profits[0].volume, 8 AtInt, sizeof (struct profits), 8 1, NUM_WEEKS); 8} 98/***************************************************************** 8 * 8 * This is the boring bit: a form with two buttons and the plotter as 8 * children 8 */ 98Widget form, quitbutton, printbutton; 98extern int exit(); 98void quit_callback() 8{ 8 exit(0); 8} 98void print_callback() 8{ 8 AtPlotterGeneratePostscript("ps.out", (AtPlotterWidget)plotter, 8 "Widget Profits", 0, 0, 400, 250, False); 8 fprintf(stderr, "Plot dumped in ps.out0); 8} 98void MakeForm(parent) 8Widget parent; 8{ 8 form = XtVaCreateManagedWidget("form", formWidgetClass, parent, NULL); 8 quitbutton = XtVaCreateManagedWidget("quit", commandWidgetClass, form, 8 XtNlabel, "Quit", 8 XtNleft, XtChainLeft, 8 NULL); 8 XtAddCallback(quitbutton, XtNcallback, quit_callback, NULL); 8 printbutton = XtVaCreateManagedWidget("print", commandWidgetClass, form, 8 XtNlabel, "Print", 8 XtNfromHoriz, quitbutton, 8 NULL); 8 XtAddCallback(printbutton, XtNcallback, print_callback, NULL); 8} 998int main(ac, av) 8Cardinal ac; 8char **av; 8{ 8 Widget appShell; 8 XtAppContext app; 98 appShell = XtAppInitialize(&app, "Test", NULL, 0, &ac, av, 8 NULL, NULL, 0); 98 MakeForm(appShell); 8 MakePlotter(form); 8 /* Make the plotter below the buttons! */ 8 XtVaSetValues(plotter, XtNleft, XtChainLeft, 8 XtNfromVert, quitbutton, _________________________________________________________________ August 1992 31 9 The AthenaTools Plotter Widget Set Version 6.0 _________________________________________________________________ 8 NULL); 98 /* Now read the data and calculate it */ 8 ReadFromDatabase(); 8 CalculateProfit(); 98 /* Now attach the data to the plot widget */ 8 AttachData(); 98 XtRealizeWidget(appShell); 98 XtAppMainLoop(app); 8 /*NOTREACHED*/ 8 return 0; 8} _________________________________________________________________ August 1992 32 9