Package org.faceless.graph2
Class FunctionLineSeries
- java.lang.Object
-
- org.faceless.graph2.Series
-
- org.faceless.graph2.AbstractLineSeries
-
- org.faceless.graph2.FunctionLineSeries
-
- Direct Known Subclasses:
SplineSeries
,TrendSeries
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 thefunc(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
Constructors Constructor Description FunctionLineSeries(String name, double min, double max)
Create a new FunctionLineSeries
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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 thesetLineSeries(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
-
-
-
-
Constructor Detail
-
FunctionLineSeries
public FunctionLineSeries(String name, double min, double max)
Create a new FunctionLineSeries- Parameters:
name
- the name of the seriesmin
- the minimum value to be plotted with this seriesmax
- 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 impliedRuntimeException
. An example method meeting this criteria would beMath.sin(double)
.- Parameters:
name
- the name of the seriesmin
- the minimum value to be plotted with this seriesmax
- the maximum value to be plotted with this seriesmethod
- 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 thesetLineSeries(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 beDouble.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 callsuper.complete()
first.- Since:
- 2.3.4
-
-