com.sas.graphics.components
Class ReferenceLineModel

com.sas.graphics.components.ReferenceLineModel

public class ReferenceLineModel

A ReferenceLineModel class stores the label, location and the line style for the reference line.
A ReferenceLineModel is normally attached to an AxisModel and the orientation of the lines are same as the axis for the AxisModel.

Usage

Let's say you have a bar chart of student's weight in a class. All the students below 100 pounds are under-weight and above 180 pounds are overweight. Ideal weight is say 130 pounds. So by putting three reference lines helps to see who is close to ideal and who is outside the healthy range. We can also assign green color for the ideal weight and red to define the healthy reange. So here is how to do this.
 // Create the reference lines
 ReferenceLineModel[] myReferenceLineModels = new ReferenceLineModel[3];
 BasicStroke stroke =  new BasicStroke(3f);
 java.awt.Font font = new java.awt.Font("Arial", java.awt.Font.PLAIN, 8);
 
 StrokeLineStyle greenLine = new StrokeLineStyle(stroke, java.awt.Color.green);
 AdvancedTextStyle greenText = new AdvancedTextStyle(font, java.awt.Color.green);
 
 StrokeLineStyle redLine = new StrokeLineStyle(stroke, java.awt.Color.red);
 AdvancedTextStyle redText = new AdvancedTextStyle(font, java.awt.Color.red);
 
  // Define the ideal line
 myReferenceLineModels[0] = new ReferenceLineModel();
 myReferenceLineModels[0].setPosition(130.0);
 myReferenceLineModels[0].setLineStyle(greenLine);
 myReferenceLineModels[0].setTextStyle( greenText);
 myReferenceLineModels[0].setLabel("Ideal Weight");
 
  // Now the range
 myReferenceLineModels[1] = new ReferenceLineModel();
 myReferenceLineModels[1].setPosition(180.0);
 myReferenceLineModels[1].setLineStyle(redLine);
 myReferenceLineModels[1].setTextStyle( redText);
 myReferenceLineModels[1].setLabel("Over Weight");

 myReferenceLineModels[2] = new ReferenceLineModel();
 myReferenceLineModels[2].setPosition(100.0);
 myReferenceLineModels[2].setLineStyle(redLine);
 myReferenceLineModels[2].setTextStyle( redText);
 myReferenceLineModels[2].setLabel("Under Weight");

 // Attach them to the chart
 AxisModel axisModel = barChartModel.getResponseAxisModel();
 axisModel.setReferenceLineModels(myReferenceLineModels);
 

Behavior

You need to create the array of ReferenceLineModel and set the properties for each ReferenceLineModel before passing it to AxisModel. There will be one reference line for each element in the array. AxisModel does not keep the pointer to the array but creates it own copy from the models. So any change done to the array elements after the setter will be lost.

By default, label, lineStyle and textStyle are null and the position property is displayed as label using the axis's valueTextStyle and lineStyle.

When you set a property on a ReferenceLineModel, any change to that property generates an event that propagates to the top of the object chain so that appropriate actions can be taken. For example, for an existing ReferenceLineModel named refLine, if you set a LineStyle by calling refLine.setLineStyle(), the refLine becomes a listener to the events from the new LineStyle. A change to the LineStyle generates a propertyChangeEvent for the line, and refLine responds to that event to pick up the change and generate its own propertyChangeEvent. If the refLine is attached to a ScatterPlotModel, then the ScatterPlotModel responds to the refLine event to pick up the change and generate its own propertyChangeEvent. If the ScatterPlotModel is attached to a ScatterPlot, then the ScatterPlot responds to the event to pick up the change and redraw its reference line.

Dependencies

com.sas.graphics.components.StrokeLineStyle com.sas.graphics.components.AdvancedTextStyle

Since:
SAS 9.1
See Also:
AxisModel, ModelBase, AdvancedTextStyle, StrokeLineStyle

Constructor Summary
ReferenceLineModel()
          Default constructor.
ReferenceLineModel(double newPosition)
          Constructor with a defined position.
ReferenceLineModel(java.lang.Object newPositionAsObject)
          Constructor with a defined position.
ReferenceLineModel(java.lang.String newLabel, double newPosition)
          Constructor with a defined label and position.
 
Method Summary
 void apply(ReferenceLineModel theOtherObject)
          Utility method to convey properties contained in "theOtherObject" to this object.
 boolean equals(java.lang.Object obj)
          Determines whether another object is equal to this ReferenceLineModel.
 java.lang.String getLabel()
          Get the text style for the label.
 int getLabelPlacement()
          Returns the placement of the label.
 StrokeLineStyle getLineStyle()
          Returns the reference line style.
 double getPosition()
          Get the position of the reference line on the axis.
 java.lang.Object getPositionAsObject()
           
 AdvancedTextStyle getTextStyle()
          Get the text style for the label.
 int hashCode()
          Computes the hash code for this ReferenceLineModel.
 boolean isInFront()
          Returns true if the reference line is drawn in front of the chart.
 boolean isVisible()
          Query if the reference line is visible or not.
static ReferenceLineModel[] rangeToArray(double minPosition, double maxPosition, int interval)
          Convience method to return an array of reference line models containing reference lines positioned starting from minPosition and ending on or before maxPosition incremented by the amount specified in the interval parameter.
static ReferenceLineModel[] rangeToArrayByDate(double minPosition, double maxPosition, int timeInterval, int multiplier)
          Convience method to return an array of reference line models containing reference lines positioned starting from minPosition and ending on or before maxPosition incremented by the amount specified in the timeInterval parameter multiplied by the multiplier parameter.
static ReferenceLineModel[] rangeToArrayByTime(double minPosition, double maxPosition, int timeInterval, int multiplier)
          Convience method to return an array of reference line models containing reference lines positioned starting from minPosition and ending on or before maxPosition incremented by the amount specified in the timeInterval parameter multiplied by the multiplier parameter.
 void setInFront(boolean newInFront)
          Sets whether of not the reference line is drawn in front of the chart.
 void setLabel(java.lang.String newLabel)
          Sets the text for the label.
 void setLabelPlacement(int newPlacement)
          Sets the placement of the label.
 void setLineStyle(StrokeLineStyle newLineStyle)
          Sets the reference line style.
 void setPosition(double newPosition)
          Sets the value at which the reference line is placed.
 void setPositionAsObject(java.lang.Object newPositionAsObject)
           
 void setTextStyle(AdvancedTextStyle newTextStyle)
          Sets the text style for the label.
 void setVisible(boolean visible)
          Set whether the reference line is visible or not.
 
Methods inherited from class com.sas.graphics.components.ModelBase
addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, removePropertyChangeListener, setContainedModel
 

Constructor Detail

ReferenceLineModel

public ReferenceLineModel()
Default constructor.


ReferenceLineModel

public ReferenceLineModel(double newPosition)
Constructor with a defined position.


ReferenceLineModel

public ReferenceLineModel(java.lang.Object newPositionAsObject)
Constructor with a defined position.


ReferenceLineModel

public ReferenceLineModel(java.lang.String newLabel,
                          double newPosition)
Constructor with a defined label and position.

Method Detail

apply

public void apply(ReferenceLineModel theOtherObject)
Utility method to convey properties contained in "theOtherObject" to this object.

Note: Contained "models" (i.e. properties that are subclasses of ModelBase) will in turn be called on to convey their properties to the like contained models in the other object. In that respect this can be considered a "tree" type copy.

Also Note: This is a deep copy. Thus after the copy, mutable properties will not be shared by the two instances. With the exception of the Object set in setPositionAsObject(Object). If the Object is implements cloneable, then the object is cloned and the deep copy holds true, however, if it is not, then a reference to the Object is assigned and the mutable properties will be shared by the two instances. Since it is expected that only immutable classes will be set, non-sharing rule should hold true and be the expected behavior.

Parameters:
theOtherObject - a model whose properties to be conveyed

setLineStyle

public void setLineStyle(StrokeLineStyle newLineStyle)
Sets the reference line style.

Note: Any modification done to the ReferenceLineModel after attaching it to the AxisModel will be lost. AxisModel does not keep the pointer to the ReferenceLineModel but creates it own copy from the model.

Note: If lineStyle is set to null, then the line style from the axismodel is used.

Parameters:
newLineStyle - the new repository for the line display attributes
See Also:
getLineStyle(), StrokeLineStyle.apply(com.sas.graphics.components.StrokeLineStyle)

getLineStyle

public StrokeLineStyle getLineStyle()
Returns the reference line style.

Note: If the lineStyle is null, then the line style from the axismodel is used.

Returns:
StrokeLineStyle appearance properties for the line
See Also:
setLineStyle(com.sas.graphics.components.StrokeLineStyle)

setTextStyle

public void setTextStyle(AdvancedTextStyle newTextStyle)
Sets the text style for the label.

Note: Any modification done to the ReferenceLineModel after attaching it to the AxisModel will be lost. AxisModel does not keep the pointer to the ReferenceLineModel but creates it own copy from the model.

Note: If null is passed as newTextStyle then the label uses the the valueTextStyle from the axis model.

Parameters:
newTextStyle - the new repository for the label's text display attributes
See Also:
getTextStyle(), AdvancedTextStyle.apply(com.sas.graphics.components.AdvancedTextStyle)

getTextStyle

public AdvancedTextStyle getTextStyle()
Get the text style for the label.

Note: The default value for the textStyle is null and in that case the label uses the the valueTextStyle from the axis model.

Returns:
AdvancedTextStyle text appearance properties for the label
See Also:
AdvancedTextStyle.apply(com.sas.graphics.components.AdvancedTextStyle), setTextStyle(com.sas.graphics.components.AdvancedTextStyle)

setLabel

public void setLabel(java.lang.String newLabel)
Sets the text for the label.

Note: Any modification done to the ReferenceLineModel after attaching it to the AxisModel will be lost. AxisModel does not keep the pointer to the ReferenceLineModel but creates it own copy from the model.

Note: null is a valid value for the newLabel parameter and in this case value of the position property is displayed. Default value for the label is also null.

Parameters:
newLabel - String the new text for the label
See Also:
getLabel()

getLabel

public java.lang.String getLabel()
Get the text style for the label.

Note: The label may be null (default) and in that case the label uses the position value as label.

Returns:
String text for the label
See Also:
setLabel(java.lang.String)

setPosition

public void setPosition(double newPosition)
Sets the value at which the reference line is placed. If the value is not inside the axis range, the reference line will not be drawn.

Note: Any modification done to the ReferenceLineModel after attaching it to the AxisModel will be lost. AxisModel does not keep the pointer to the ReferenceLineModel but creates it own copy from the model.

Parameters:
newPosition - Anchor point for the line
See Also:
getPosition()

getPositionAsObject

public java.lang.Object getPositionAsObject()

setPositionAsObject

public void setPositionAsObject(java.lang.Object newPositionAsObject)

getPosition

public double getPosition()
Get the position of the reference line on the axis.

Returns:
Anchor point for the line
See Also:
setPosition(double)

setInFront

public void setInFront(boolean newInFront)
Sets whether of not the reference line is drawn in front of the chart.

Note: You need to modify the line style before attaching to AxisModel as AxisModel does not keep the pointer to the ReferenceLineModel but creates it own copy from the model. So any change done to the model after the setter will be lost.

Parameters:
newInFront - true if reference line is in front
See Also:
isInFront()

isInFront

public boolean isInFront()
Returns true if the reference line is drawn in front of the chart.

Returns:
true if reference line is in front
See Also:
setInFront(boolean)

setLabelPlacement

public void setLabelPlacement(int newPlacement)
                       throws java.lang.IllegalArgumentException
Sets the placement of the label.

Valid values are:

Parameters:
newPlacement - new placement from GraphConstants
Throws:
java.lang.IllegalArgumentException - if newPlacement is not a valid value
See Also:
getLabelPlacement()

getLabelPlacement

public int getLabelPlacement()
Returns the placement of the label.

Returns:
int Label placement
See Also:
setLabelPlacement(int)

isVisible

public boolean isVisible()
Query if the reference line is visible or not.

Returns:
boolean which denotes if axis is visible or not.
See Also:
setVisible(boolean)

setVisible

public void setVisible(boolean visible)
Set whether the reference line is visible or not.

Parameters:
visible - set axis visibility
See Also:
isVisible()

equals

public boolean equals(java.lang.Object obj)
Determines whether another object is equal to this ReferenceLineModel.

The result is true if and only if the argument is not null and is a ReferenceLineModel object that has the same property values as this object.

Overrides:
equals in class ModelBase
Parameters:
obj - the object to test for equality with this ReferenceLineModel
Returns:
true if the objects are the same; false otherwise.

hashCode

public int hashCode()
Computes the hash code for this ReferenceLineModel.

Overrides:
hashCode in class ModelBase
Returns:
a hash code value for this object.

rangeToArray

public static ReferenceLineModel[] rangeToArray(double minPosition,
                                                double maxPosition,
                                                int interval)
                                         throws java.lang.IllegalArgumentException
Convience method to return an array of reference line models containing reference lines positioned starting from minPosition and ending on or before maxPosition incremented by the amount specified in the interval parameter.

Parameters:
minPosition - beginning of the period
maxPosition - end of the period
interval - amount to move forward with each advance
Throws:
java.lang.IllegalArgumentException - if interval <= 0, minPosition <= 0, minPosition or maxPosition are Positive_infinity or Nan, minPositon > maxPosition.

rangeToArrayByTime

public static ReferenceLineModel[] rangeToArrayByTime(double minPosition,
                                                      double maxPosition,
                                                      int timeInterval,
                                                      int multiplier)
                                               throws java.lang.IllegalArgumentException
Convience method to return an array of reference line models containing reference lines positioned starting from minPosition and ending on or before maxPosition incremented by the amount specified in the timeInterval parameter multiplied by the multiplier parameter.

Note: minPosition & maxPosition are number of seconds (SAS DATETIME and TIME format).

Only predefined values are accepted for timeInterval parameter:

Parameters:
minPosition - number of seconds for beginning of the period
maxPosition - number of seconds for end of the period
timeInterval - time interval to advance by
multiplier - number of intervals forward with each advance
Throws:
java.lang.IllegalArgumentException - if multiplier <= 0, minPosition <= 0, minPosition or maxPosition are Positive_infinity or Nan, minPositon > maxPosition, or timeInterval not valid.

rangeToArrayByDate

public static ReferenceLineModel[] rangeToArrayByDate(double minPosition,
                                                      double maxPosition,
                                                      int timeInterval,
                                                      int multiplier)
                                               throws java.lang.IllegalArgumentException
Convience method to return an array of reference line models containing reference lines positioned starting from minPosition and ending on or before maxPosition incremented by the amount specified in the timeInterval parameter multiplied by the multiplier parameter.

Note: minPosition & maxPosition are number of days (SAS DATE format).

Only predefined values are accepted for timeInterval parameter:

Parameters:
minPosition - beginning of the period
maxPosition - end of the period
timeInterval - time interval to advance by
multiplier - number of intervals forward with each advance
Throws:
java.lang.IllegalArgumentException - if multiplier <= 0, minPosition <= 0, minPosition or maxPosition are Positive_infinity or Nan, minPositon > maxPosition, or timeInterval not valid.



Copyright © 2009 SAS Institute Inc. All Rights Reserved.