Class AbstractLineGraph

  • Direct Known Subclasses:
    AreaGraph, LineGraph

    public abstract class AbstractLineGraph
    extends AxesGraph

    The abstract superclass for all graphs plotting continuous data (as opposed to bar graphs, which are for plotting discrete data). Unlike Pie Graphs and Bar Graphs, Line Graphs plot a Curve, which covers everything from a set of X and Y values (a DataCurve) to complex mathematical functions.

    Several curves can be plotted on the same graph, for example to compare a set of readings with a theoretical curve.

    • Field Detail

      • minx

        protected double minx
        The minimum and maximum X and Y values that are being plotted
      • maxx

        protected double maxx
        The minimum and maximum X and Y values that are being plotted
      • minval

        protected double minval
        The minimum and maximum X and Y values that are being plotted
      • maxval

        protected double maxval
        The minimum and maximum X and Y values that are being plotted
    • Constructor Detail

      • AbstractLineGraph

        protected AbstractLineGraph()
    • Method Detail

      • setCurve

        public void setCurve​(java.lang.String name,
                             Curve curve,
                             java.awt.Color color)
        Add a Curve to the graph in the specified color. If a curve with this name already exists it will be replaced.
        Parameters:
        name - the name to give this curve
        curve - the curve to add
        color - the color to plot this curve in
      • setCurve

        public void setCurve​(java.lang.String name,
                             Curve curve)
        Add a Curve to the graph in the next default color. If a curve with this name already exists it will be replaced.
        Parameters:
        name - the name to give this curve
        curve - the curve to add
      • optionMinX

        public void optionMinX​(double val)
        The minimum value to plot on the X axis. This is only a recommendation - if you're plotting one or more DataCurve, the actual minimum will be the lesser of this value and the lowest value in the curve. For graphs plotting only one or more FunctionCurve, this value is mandatory.

        Default: data-driven

      • optionMaxX

        public void optionMaxX​(double val)
        The maximum value to plot on the X axis.

        Default: data-driven

      • optionFunctionSmoothness

        public void optionFunctionSmoothness​(double val)
        If you're plotting a FunctionCurve, how many steps to divide the curve into. Higher numbers give smoother curves, but slower rendering times.

        Default: 30

      • optionMaxDataPoints

        public void optionMaxDataPoints​(int val)
        If you're plotting a DataCurve, the maximum number of values to plot. If your data set has thousands of values, you may set this and drop a few to speed things up (exactly which points are dropped are undefined, but the remaning data is guaranteed to be evenly spread across the graph).

        Default: 100

      • optionCurveDepth

        public void optionCurveDepth​(double val)
        The depth "into the screen" of a curve. Higher values give thicker curves.

        Default: 1

      • postDrawLines

        protected void postDrawLines()
      • plotLine

        protected abstract double plotLine​(int set,
                                           Curve c,
                                           double prevlastval,
                                           double prevval,
                                           double lastx,
                                           double x,
                                           double linewidth,
                                           boolean isLast,
                                           java.util.Map m)
        Actually plot the line. This method needs to be filled in by concrete subclasses of this class. This method must handle NaN and Infinite values. All current subclasses deal with these by skipping those points and leaving a gap in the line.
        Parameters:
        set - The number of the set that's being plotted
        c - The curve that's being plotted
        prevlastval - The value returned by the last X value from the previous set. Set to Double.NaN if there was no previous set, or no last X value.
        prevval - The value returned by this X value from the previous set. Set to Double.NaN if no previous set.
        lastx - The last X value passed in. Set to Double.NaN if no previous X value exists.
        x - The current X value.
        linewidth - The width (or rather depth) of the line to be plotted.
        isLast - Whether this X value is the last value in the set.
        m - A map which can be used by plotLine to pass data between other calls to plotLine. A common use is to set a "start" value if this is the first X value in the set.