PHGraph is a very simple cocoa framework to display scientific plots in the plane, for osX tiger and leopard (universal binary).

Why another framework ? Because the plotting frameworks I've been able to find here or there did not fulfill my expectations, including the ability to display quickly and efficiently plots with a large number of points.

Although it is a very young and immature framework, I decided to make it public so that users, developers could try it, discuss its evolution and in the effect that, if major changes would appear necessary, doing it at the first stages of development would make it much easier and cleaner.

The design is simple : the major class is the view, PHGraphView which inherits from NSView, and whose instance variables are mostly three MutableArrays. One is an array of horizontal axis, a second for vertical axis, and a third for objects to be drawn in the view.

Several axis can be added (but I guess no one will ever use more than two in each direction), as well as some objects, subclassed from PHGraphObjects to be drawn on the plane. See the class tree to see some objects implemented so far. Each object is associated with a couple of axis. Each object is responsible for its own drawing, and the modular conception of the framework makes it very easy to expand with user defined objects for example.

The PHGraphView itself is responsible for dealing with the mouse events, with a few predefined modes. The most convenient in my opinion is the PHCompositeZoomAndDrag : a left click (mouse not moving) is a zoom in (centered), a alt+left click is a zoom out (cancelling a zoom in), and dragging the mouse with the button pressed moves the plot.

The framework takes care of it, but you could do it yourself with a delegate as well...

For all the modes : the right click or control+left click shows a contextual menu with the possibility to copy the graph to the pasteboard as TIFF, PDF or EPS image.

The data for the set of points or curves is just the given of references to double arrays. This way, there is no memory wasted, and the fastest access to data in the framework, and the plotting itself is for the major part realized with core graphics (Quartz 2d), with some cocoa for displaying strings.

See here for screenshots and code examples

Here for the TODO list,

Here for the distribution files