org.faceless.graph2
Class FunctionLineSeries

java.lang.Object
  extended by org.faceless.graph2.Series
      extended by org.faceless.graph2.AbstractLineSeries
          extended by org.faceless.graph2.FunctionLineSeries
Direct Known Subclasses:
SplineSeries

public abstract class FunctionLineSeries
extends AbstractLineSeries

This class represents a mathematical curve (eg. a Sine curve), drawn onto the graph as a line. To plot a curve, simply extend this class and implement the func(double) method. For example, to plot a Sine curve:

 FunctionLineSeries sinecurve = new FunctionLineSeries("Sine", -Math.PI, Math.PI) {
     public double func(double x) {
         return Math.sin(x);
     }
 };
 


Constructor Summary
FunctionLineSeries(String name, double min, double max)
          Create a new FunctionLineSeries
 
Method Summary
 void complete()
          Complete the function.
static FunctionLineSeries createFunctionSeries(String name, double min, double max, Method method)
          Return a FunctionLineSeries that uses the specifed method as it's function.
abstract  double func(double x)
          Given an X value, return the equivalent Y value of this function.
 LineSeries getLineSeries()
          Return the LineSeries set by the setLineSeries(org.faceless.graph2.LineSeries) method.
 void setLineSeries(LineSeries data)
          Set the LineSeries that this function takes it's data from.
 void setSteps(int steps)
          Set the number of steps to plot this curve in.
 
Methods inherited from class org.faceless.graph2.AbstractLineSeries
setDepth
 
Methods inherited from class org.faceless.graph2.Series
addBox, addLine, addMarker, getName, outputToSeries, outputToSeriesFunction, setStyle, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FunctionLineSeries

public FunctionLineSeries(String name,
                          double min,
                          double max)
Create a new FunctionLineSeries

Parameters:
name - the name of the series
min - the minimum value to be plotted with this series
max - the maximum value to be plotted with this series
Throws:
IllegalArgumentException - if min>max or min or max is Infinite
Method Detail

createFunctionSeries

public static FunctionLineSeries createFunctionSeries(String name,
                                                      double min,
                                                      double max,
                                                      Method method)
Return a FunctionLineSeries that uses the specifed method as it's function. The method passed in must be public, static, non-abstract, take a single double as an argument and return a single double, and not throw any exceptions (other than the implied RuntimeException. An example method meeting this criteria would be Math.sin(double).

Parameters:
name - the name of the series
min - the minimum value to be plotted with this series
max - the maximum value to be plotted with this series
method - the method as described above
Throws:
IllegalArgumentException - if min>max or min or max is Infinite, or if the method does not meet the requirements described above.

setLineSeries

public void setLineSeries(LineSeries data)
Set the LineSeries that this function takes it's data from. Can be used by subclasses to reference a lineseries for the data.

Since:
2.3.4

getLineSeries

public LineSeries getLineSeries()
Return the LineSeries set by the setLineSeries(org.faceless.graph2.LineSeries) method.

Since:
2.3.4

setSteps

public void setSteps(int steps)
Set the number of steps to plot this curve in. By default the curve is broken into 50 smaller line segments, but you can set the number with this method - higher values give smoother curves but take longer to plot.


func

public abstract double func(double x)
Given an X value, return the equivalent Y value of this function. The returned value may be Double.NaN or infinite, and either of those values will result in a gap in the line.

Parameters:
x - the X-value of the function - guaranteed not to be NaN or Infinite
Returns:
y the corresponding Y value

complete

public void complete()
Complete the function. This method is called after all the data points are available to the graph, and can be overridden to calculate the function based on the points in the graph. It is called automatically by the library - subclasses overriding this method must always call super.complete() first.

Since:
2.3.4


Copyright © 2001-2011 Big Faceless Organization