XYPlotView Palette Here is the latest version of the XYPlotView Palette. This code is provided as-is, and no warranty express or implied is made. The source code is not to be used in any commercial for-profit endeavor. (That's from the original authors.) 09-26-94 I would love to hear back from anybody that makes a new version of this. Here is a palette I made from nxyPlot 1.90 inspired and aided by the previous nxyPlot palette. I have done some major cleanup to the code in certain areas. It works well although there are some features that are not fully implemented. I added support for UserPaths, fonts, and streams from memory. It does support multiple fonts for the titles and uses David Pollacks DPFontWell. (In order to set the font you must drag the font from the font panel to the font well... this could be improved) I haven't had much time to work on this lately and it does what I need for right now so I am sending it into the big Internet vortex to see if it gets improved or is useful to anybody. To use it to plot programmatically fill a stream with text as follows: x1 y1 x2 y2 . . . . or x1 y1..yn x2 y2..yn (for multiple curves in one graph.) Here's prototypical code: NXStream *dataStream; if ((dataStream = NXOpenMemory(NULL, 0, NX_READWRITE)) == NULL) { NXRunAlertPanel("Write Data", "Cannot open memory for stream", "OK", NULL, NULL, NULL); return self; } // send your data using NXPrintf(stream, "%f %f\n",x,y); // or NXPrintf(stream, "%f %f %f %f\n",x,y0,y1,y2)... [myXYPlotView plotFromStream:dataStream]; NXCloseMemory(dataStream,NX_FREEBUFFER); That's it. I also programmed it so that if you press the right button on any graph object in your program it will let you save an EPS of the graph. Thanks to all who wrote the code before me! Sean Hill --- Laboratoire de Neuro-Heuristique Work: ++41 021 692.5516 Institut de Physiologie Fax: ++41 021 692.5505 Rue du Bugnon, 7 Sean.Hill@iphysiol.unil.ch CH-1005 Lausanne SWITZERLAND ----------------------------------------------------------------- This is the README from nxyPalette which was a source of some code and the idea to do this. There are good ideas in this object that ought to be implemented in this implementation. Introduction for Version 1.2: This is a palette based on the wonderful (2D)graphing application nxyplot, written by Tom Pulliam and Dennis Jespersen. nxyplot may be obtained with source code from the archives, such as sonata.cc.purdue.edu. In no way should any flaws in this palette reflect on their work. There are a couple of reasons for this-first, this palette is based on early versions of nxyplot, much of which has changed with later versions. Second, I have not worked on this as a good example of palette code, quite the contrary my code is somewhat convoluted (see below), but mainly for functionality. How it works: As with any palette, this one is a is a subclass of View, but think of it as a piece of graph paper which you can add to your application. You may set certain parameters (like is it Log-Log paper) using the Inspector panel. Unlike graph paper, it will do autoscaling. How to use it: Load the palette into IB either by double clicking on the palette, or using the IB menu item in Tools. Drag the view into your application and set the parameters with the Inspector. You may test the graph in IB's test mode by clicking the right mouse button on the view when in IB's Test Mode. This will bring up an Open panel which may be used to load a data file. Be sure to load the palette before trying to load the examples. To compile your application, it will be necessary to add the library libNXYpalette.a (an archived library of the compiled class code which should be put in a suitable directory, such as /usr/local/lib) and header files NXYView.h and Plot.h to your project. You may add all the source files to your project instead of the library file. You will also needed to add the Makefile.preamble to your project which identifies the classes to be loaded (the -u linker option.) To plot your data, it will be necessary to write it to a (NXStream)stream. See the sample code which opens a file then writes the data to a stream. Your object which does this should then be connected to the graph view as the delegate of the view. Then include the method -nxyView:sender provideDataStream:(NXStream **)stream; in your object. NXYView checks to see if this selector is present before trying to access the data stream. If either the selector or the delegate is not present, an Alert panel will come up with the option of accessing data via an Open panel (see ~/nxyTestAppNoStream/TestNS.debug for an example of this.) This way the user may set up buttons which provide for the stream and test the application, either in IB test mode or by compiling, before the stream code is present. See the test examples for more details. Bugs and other comments: Much of the functionality of nxyplot is not present in this palette; for example, it will not handle multiple files (data sets) although it will handle multiple columns of a single data set, but only with a single line type (that is, no dotted lines, etc.) Sometimes when switching between data sets with the automatic scaling set will cause an Alert panel to appear saying that nxyplot is confused. Just continue, the proper min/max values are being set despite this Alert. Small y-axis values sometimes get labeled as 0 (zero). As I said before, I do not consider this a good example of code since I wrote it in a somewhat convoluted fashion. For example, there are times when the view messages plot for a value which in turn messages the view for the value. Why not just have view message itself? There are several (unclear) reasons for this. One is to stay consistant with the nxyplot code by rewriting as little as possible (or you could say I am just lazy.) The second, and most important reason to me, is that I still hold out that I will add an "Inspector" panel that "travels with the view." That is, it will become part of the users application, so that the palette will work in the users application much the same way nxyplot works. [I vaguely know how to do this, and it has in fact already been done. Mike Mezzino has written such a palette that handles 2D and 3D plots, based on the plplot library, and has many of these features and more. Contact Mike for pricing and licensing. Also check out the graphing palette from Objective Technology.] Report any bugs or strange behavior to me (charlie@technosci.com -- NextMail okay). The usual disclaimers apply--remember it's free and you get what you pay for. Bug Fixes and Additions in 1.2: Some minor bugs have been fixed--Text strings for axis labels and titles should no longer be clobbered when working in IB with multiple instances of NXYView; Bug in logo code that caused multiple page printing in IB test mode (and only in test mode) has been fixed; Some of the "ping-pong" code has been removed. NXYView now accesses the data stream via a delegate. This is a better scheme for generic code (see the NeXT Advantage Plotter example.) Pasteboard is now supported--the contents of NXYView may be copied to the pasteboard to be pasted into other NeXT applications. A switch on the Inspector to turn off the logo has been added. Future Enhancements: When I get the time, I hope to do the following additions to the palette (but not until after NextStep 3.0 is released): > Add multiple line types and color (code is there for some of this is you want to do it) > Add support for multiple files (code is in nxyplot 1.7) > Add an Inspector Panel callable from the user's application > Add legend support (again, the code is already there) Acknowledgement: My thanks to Tom Pulliam and Dennis Jespersen for their fine plotting package to build on. ----------------------------------------------------------------- FROM nxyPlot 1.90 README: by Dennis Jespersen and Tom Pulliam jesperse@rahul.net This is the README file for the nxyplot package. nxyplot is a plotting program for computers running the Nextstep operating system, release 3.0 or higher. Source code is provided, as well as a multi-architecture binary, which should be executable on both Motorola and Intel hardware. Program Summary: nxyplot is a program for plotting two-dimensional curves, with data coming from one or more files. Each file can contain multiple y-values for each x value. Each data file should be an ASCII or compressed file, with each line containing the x-value followed by the y-values for each curve. Thus, each data file should look like x1 y1 ... yn x2 y2 ... yn etc., where there are n curves to be plotted. A sample file (test2.xyp) is provided to illustrate this format and to use for testing the program. The input file can contain text comments as long as the text contains no periods or numerals. The various panels (controls, lines, symbols, legends) have some information displayed on them. They allow manipulation of the line style, symbol type, legend, minimum and maximum value along each axis, and titles. Also provided is the ability to move the legend and titles and to "zoom" in on a section of the plot. Printing capability is provided by standard NeXT system methods; the plot will be automatically scaled to an 8.5 in. x 11 in. page in either landscape or portrait mode (depending on whether the screen plot is landscape or portrait). Writing this program served as our introduction to programming using the Interface Builder and Objective-C. We wanted to emulate the functionality of a program called "xyplot", written by Marshal Merriam of NASA/Ames Research Center and T. Krysten Nguyen. The plotting program "QuickPlot" of Fred Richards (University of Illinois) was very helpful in showing how to get started with the Interface Builder. We use this program ourselves and intend to support it (in our spare time). Constructive criticism and suggestions for improvement are welcome; send e-mail to jesperse@rahul.net or pulliam@rft29.nas.nasa.gov. This code is provided as-is, and no warranty express or implied is made. The source code is not to be used in any commercial for-profit endeavor. Dennis Jespersen jesperse@rahul.net Version 1.89 of nxyplot. 1. NeXT help system implemented. 2. Autoplot preference added. 3. Miscellaneous bug fixes. Version 1.85 of nxyplot. 1. Capability to delete selected files. 2. Drag and drop capability added. 3. Bug fixes. Version 1.8 of nxyplot. 1. Error bar capability added; see Error bars (under Windows menu item). 2. Some bug fixes. 3. Services menu item added. 4. Copy Graphics menu item added. 5. Preview button added to main control panel. 6. Added capability to read and write binary files. 7. Tic marks can be on all four sides of the frame box. 8. Main menu reorganized to be more in conformance with NeXT UI Guidelines. Version 1.7 of nxyplot. 1. Allow user-specified formatting of tic labels; also bug fixes of automatic tic label formatting. 2. Allow data files with only one column of data (the given data is assumed to be y values, and the x values are taken to be the integers 1,2,3,...). 3. The linestyle and symbolstyle matrices now automatically arrange to turn off all but one button in each column. 4. The linestyle, symbolstyle, and legendstyle windows are now scrolling windows; they can be resized and scroll bars will appear (suggested and code supplied by Paul Howell using the ScrollWindow class of David Joerg). 5. Title of plot window now reflects name of data file most recently read in, or "pasteboard" if data came from a pasteboard. 6. Initial curve titles in legend window now reflect file names. 7. Arbitrary column of data file can be selected as the x-data for a plot. Note that choice of a column other than the first for the x-data is not taken into account when a format file is written or read. 8. Added capability for the Workspace Manager to launch nxyplot when any file with the extension "xyp", "dat", or "nxyplot" is double-clicked. 9. Added color vs black/white option in Preferences. 10. Any curve whose line style and symbol style are both set to none will be ignored when doing min/max calculations. A file's x-data will also be ignored if all the curves from that file are ignored. 11. Data files now may contain the comment character "!" anywhere on a line; anything following the "!" on a given line will be ignored. 12. nxyplot can now read options given on the command line. Usage is nxyplot file [file...] [-f formatfile] [-o epsfile] [-q] [-h] 13. Length of tic marks is now user-controllable by a slider/text field combination. 14. "Previous View" button added to control panel. 15. Print panel additions to allow easy printing in black and white even if display is being viewed in color. 16. "Fine tuning" panel added to organize many small details. Frame box control added. Ability to locate tic marks on axes added. Note that format files written by nxyplot version 1.6 or earlier may not work properly with version 1.7 of nxyplot. Version 1.6 of nxyplot. 1. Supports color: lines, background, text can be colored. 2. Titles may be moved, just like the legend box. 3. More robust handling of tic label formatting; also bug fixes. 4. Line thickness and symbol size controlled by sliders. 5. Format file supports colors and the previous enhancements. This implies that format files written with earlier version of nxyplot MAY MALFUNCTION when read with this version of nxyplot. 6. Axis thickness now user-controllable. 7. Added capability to save data files; this may be handy if one has read in data off the pasteboard (using services) and would like to save the data in a file. Version 1.5 of nxyplot. 1. More robust handling of input files; they can now have limited text comments and arbitrary non-ASCII characters. 2. Capability to read and write "format" files. A format file contains information about the min/max, line types, etc., and can be used as a template to allow easily regenerating plots where many non-default options have been selected. 3. Capability to read compressed files. This is to help conserve disk space. 4. Service providing. Under NeXT system 2.0 and higher, applications can register as service providers. This program offers a plotting service to any application which can put appropriate data on an ASCII pasteboard. See the help file (under "Preferences") for more information. Version 1.0 of nxyplot. Can now plot data from multiple files; can select different fonts for the various labels; better labeling along the axes.