home *** CD-ROM | disk | FTP | other *** search
- // -------------------------------------------------------------------------------------
- // BarChart.h
- // Martin D. Flynn, NeXT Computer, Inc.
- // -------------------------------------------------------------------------------------
-
- #import <sys/types.h>
- #import <objc/Storage.h>
-
- // -------------------------------------------------------------------------------------
- // chart types (may be logically OR'ed together)
- #define chartLINE 0x01 // line chart
- #define chartPOINT 0x02 // point chart
- #define chartBAR 0x04 // bar chart (along x-axis)
- #define chartAREA 0x08 // area chart
-
- // -------------------------------------------------------------------------------------
- // default line width
- #define DEFAULT_LINE_WIDTH -1.0
-
- // -------------------------------------------------------------------------------------
- // charting data source structure
- // The first two elements of this structure must not be modified by any external method call
- // Their integrity is set and maintained within the BarChart instance. The other structure
- // elements may be modified as necessary to accomplish the desired effect.
- typedef struct chartData_struct {
- int _srcType; // data source type (do not modify)
- id _srcId; // id of data source (do not modify)
- int chartType; // type of chart to plot
- BOOL isEditable; // specifies whether the data source is modifiable
- float lineWidth; // the linewidth to plot
- BOOL isColor; // chart in color, if TRUE
- NXColor chartColor; // the color value to plot
- } *chartData_t, chartData_s;
-
- // -------------------------------------------------------------------------------------
- @interface BarChart : View
- {
-
- // archived variables
-
- NXColor backgroundColor; // background color
- NXColor dftChartColor; // default chart color
- NXColor axisColor; // axis color
- NXColor xGridColor; // xGrid color
- NXColor yGridColor; // yGrid color
-
- int dftChartType; // default chart type
- NXRect tickMark; // (data) tick mark origin/size
- NXRect dataRange; // (data) data range
- id currentFont; // current font id
-
- struct _barFlags {
- u_short drawInColor:1; // use color to draw
- u_short transparent:1; // background transparent
- u_short xGridDraw:1; // draw x grid
- u_short yGridDraw:1; // draw y grid
- u_short xShowLabels:1; // show x axis labels
- u_short yShowLabels:1; // show y axis labels
- u_short xLogScale:1; // logorithmic scaling on x axis
- u_short yLogScale:1; // logorithmic scaling on y axis
- u_short xLabelRotate:1; // rotate X-axis labels 90 degrees
- u_short yLabelRotate:1; // rotate Y-axis labels 90 degrees
- u_short _RESERVED:6; // future use
- } cFlags; // chart flags
-
- // work variables
-
- id dataList; // chart data source
- id delegate; // chart delegate
-
- id xLabelMatrix; // (U/C) xAxis labels
- id yLabelMatrix; // (U/C) yAxis labels
- id actionMatrix; // matrix containing actions performed when selected
-
- NXSize xLblSize; // xAxis label size
- NXSize yLblSize; // yAxis label size
- NXPoint maxRange; // upper limit on data range
-
- float tickLength; // tick mark length
- float tickWidth; // tick and axis line width
- NXRect chartFrame; // calculated chart frame
- NXPoint axisOrigin; // (PS) axis origin point
- NXPoint axisPosition; // (PS) axis displayed position
- NXPoint dataScale; // (data=>PS) scale factor
-
- int precisionX; // label precision for X axis
- int precisionY; // label precision for Y axis
-
- BOOL reScale; // rescale axis info if true
- BOOL isFirstResponder; // first responder flag
-
- }
-
- // -------------------------------------------------------------------------------------
- // chart data source access
- - (Storage*)chartList; // return Storage object contains chartData_s elements
- - (int)chartCount; // return number of chartData_s elements
- - (chartData_s*)chartDataAt:(int)index; // return pointer to specified chartData_s elements
-
- // -------------------------------------------------------------------------------------
- // logorithmic axis scaling
- - (float)log:(float)num; // return base-10 log of specified value
- - (float)exp:(float)num; // return base-10 anti-log of specified value
-
- // -------------------------------------------------------------------------------------
- // point conversions
- - convertDataPointToChart:(NXPoint*)point; // return data point converted to chart view
- - convertChartPointToData:(NXPoint*)point; // return chart view point converted to data
-
- // -------------------------------------------------------------------------------------
- // default charting options (IB use)
- - setDftChartType:(int)chartType; // set default carting type
- - (int)dftChartType; // return default charting type
- - setDftChartGray:(float)gray; // set default chart gray
- - (float)dftChartGray; // return default chart gray
- - setDftChartColor:(NXColor)color; // set default chart color
- - (NXColor)dftChartColor; // return default chart color
-
- // -------------------------------------------------------------------------------------
- // chart axis options
- - setDataRange:(NXRect*)range; // set X/Y axis data range
- - (NXRect*)dataRange; // return current X/Y axis data range
- - setTickMark:(NXRect*)tick; // set X/Y axis tickMark size (origin not used)
- - (NXRect*)tickMark; // return current X/Y axis tickMark size
-
- // -------------------------------------------------------------------------------------
- // point selection/ change delegate
- - setDelegate:anObject; // set point selection/change delegate
- - delegate; // return designated selection/change delegate
-
- // -------------------------------------------------------------------------------------
- // changing the label font
- - setFont:fontId; // set the X/Y axis label font
- - font; // reutrn the current X/Y label font
-
- // -------------------------------------------------------------------------------------
- // transparent background
- - setBackgroundTransparent:(BOOL)flag; // set background transparent
- - (BOOL)backgroundTransparent; // return background transparent state
-
- // -------------------------------------------------------------------------------------
- // axis options
- - setXLogScaling:(BOOL)flag; // set X-axis log scaling
- - (BOOL)xLogScaling; // return current X-axis log scaling state
- - setYLogScaling:(BOOL)flag; // set Y-axis log scaling
- - (BOOL)yLogScaling; // return current Y-axis log scaling state
- - setXShowLabels:(BOOL)flag; // set X-axis labels ON/OFF
- - (BOOL)xShowLabels; // return X-axis labels state
- - setYShowLabels:(BOOL)flag; // set Y-axis labels ON/OFF
- - (BOOL)yShowLabels; // return Y-axis labels state
- - setXGridDraw:(BOOL)flag; // set X-axis grid lines ON/OFF
- - (BOOL)xGridDraw; // return X-axis grid lines state
- - setYGridDraw:(BOOL)flag; // set Y-axis grid lines ON/OFF
- - (BOOL)yGridDraw; // return Y-axis grid lines state
- - setXLabelRotate:(BOOL)flag; // rotate X-axis labels 90 degrees
- - (BOOL)xLabelRotate; // return X-axis label rotate state
- - setYLabelRotate:(BOOL)flag; // rotate Y-axis labels 90 degrees
- - (BOOL)yLabelRotate; // return Y-axis label rotate state
-
- // -------------------------------------------------------------------------------------
- // return color/gray draw mode
- - (BOOL)drawInColor; // return gray/color draw mode
-
- // -------------------------------------------------------------------------------------
- // gray support (these force drawInColor to NO)
- - setBackgroundGray:(float)gray; // set background gray
- - (float)backgroundGray; // return current background gray
- - setAxisGray:(float)gray; // set X/Y axis gray
- - (float)axisGray; // return current X/Y axis gray
- - setXGridGray:(float)gray; // set X-axis grid gray
- - (float)xGridGray; // return current X-axis grid gray
- - setYGridGray:(float)gray; // set Y-axis grid gray
- - (float)yGridGray; // return current Y-axis grid gray
-
- // -------------------------------------------------------------------------------------
- // color support (these force drawInColor to NO)
- - setBackgroundColor:(NXColor)color; // set background color
- - (NXColor)backgroundColor; // return current background color
- - setAxisColor:(NXColor)color; // set X/Y axis color
- - (NXColor)axisColor; // return current X/Y axis color
- - setXGridColor:(NXColor)color; // set X-axis grid color
- - (NXColor)xGridColor; // return current X-axis grid color
- - setYGridColor:(NXColor)color; // set Y-axis grid color
- - (NXColor)yGridColor; // return current Y-axis grid color
-
- // -------------------------------------------------------------------------------------
- // chart (re)draw
- - update:sender; // redraw chart from data source(s)
-
- // -------------------------------------------------------------------------------------
- // data source support
- // These methods may be used to add chart data sources to the barChart instance.
- // sourceId may be an instance of Matrix, ScrollView, Text, or Storage. If anObject is
- // an instance of Matrix, then the cells floatValue will be used as the Y-axis value,
- // and the cells tag will be used at the X-axis value. If anObject is an instance of
- // ScrollView, then it is checked to make sure that its content view is of type Text.
- // If anObject is an instance of Storage, then it is assumed to contain multiple
- // elements of NXPoint.
- - (int)addDataSource:sourceId type:(int)type lineWidth:(float)width gray:(float)gray;
- - (int)addDataSource:sourceId type:(int)type lineWidth:(float)width color:(NXColor)color;
-
- // -------------------------------------------------------------------------------------
- // data source support
- // These methods may be used to add chart data sources supplied by an NXStream.
- // Data points are read in x,y pairs from the stream to chart. Points are separated with
- // the new-line character (\n). If only one point is found on a line, then it is assumed
- // to be the Y-axis value, and the X-axis value is assigned from the ordinal value of the
- // data point.
- - (int)addDataStream:(NXStream*)s type:(int)type lineWidth:(float)width gray:(float)gray;
- - (int)addDataStream:(NXStream*)s type:(int)type lineWidth:(float)width color:(NXColor)color;
-
- // -------------------------------------------------------------------------------------
- // outlets
- - setDataSource:anObject; // set data soruce to specified object
- - setXLabelMatrix:anObject; // set matrix from which to draw X-axis labels
- - xLabelMatrix; // return current X-axis label matrix
- - setYLabelMatrix:anObject; // set matrix from which to draw Y-axis labels
- - yLabelMatrix; // return current Y-axis label matrix
-
- @end
-
- // -------------------------------------------------------------------------------------
- // bar chart delegate methods
- @interface BarChart(delegate)
-
- // This method is called when the user double-clicks on a point within an data source.
- // If a designated delegate has been specified, then this method is sent to the delegate.
- // The default action is to select the coresponding cell in the actionMatrix (if any), then
- // send 'sendAction:' to actionMatrix.
- - chartDataSelected:(chartData_s*)chartData index:(int)index;
-
- @end
-