Class Graph

  • Direct Known Subclasses:
    AxesGraph, PieGraph

    public abstract class Graph
    extends java.lang.Object

    The abstract base class for all Graphs in the org.faceless.graph package.

    This class controls the building and rendering of the graph, adding the key and any annotations if necessary and rotating or scaling it as required. It doesn't contain any information about how to lay out the data - this is all taken care of by it's subclasses.

    All the types of Graph in the package have certain things in common.

    All the graphs are fully 3D. By default they are seen head-on and so look two-dimensional, but can be rotated to any angle to give a 3D effect by calling optionXRotation and it's friends.

    They all have data added two them in one of two ways - for discrete data, via the set() method, and for continuous data via the setCurve() method. The exact forms of these methods vary from subclass to subclass. The order in which the subsets appear on the Graph is the same as the order in which they were first specified.

    The look of the Graphs is controlled by calling the option methods, which an be used to set titles, axes labels and so on. As the name implies all of these methods are optional, and don't have to be called to create a Graph.

    Finally, all the graphs when complete are sent to an output device - be it a PDF document, a java.awt.Image or a specific image format. This is done with the render() method

    Concrete subclasses in this release are the PieGraph, BarGraph, TowerBarGraph, DepthBarGraph, LineGraph, AreaGraph and FloatingBarGraph, and more will be added in future releases.

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Graph()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addElement​(org.faceless.graph.Element e)
      This is the method used to add an Element to the graph.
      protected void complete()
      Complete is the first method that's called by a Graph when it's rendered.
      java.awt.Color getDefaultBorderColor()
      Returns the value set by setDefaultBorderColor(java.awt.Color)
      double getFontScale()
      Return the current font scale.
      void optionDisplayKey​(int val)
      What type of external key to display on the graph.
      void optionFixedAspectRatio​(boolean val)
      Whether this graph should have a fixed aspect ratio.
      void optionKeyBoxStyle​(Style val)
      The Style to give to the box holding the external key.
      void optionKeyStyle​(Style val)
      The Style to give to the text used in the external key
      protected void optionRemoveBackFace​(boolean val)
      Whether this graph should have the back-faces of polygons removed for faster rendering.
      void optionSubTitle​(java.lang.String val)
      The sub-title to give the graph
      void optionSubTitleStyle​(Style val)
      The Style to give to the sub-title of the graph
      void optionTitle​(java.lang.String val)
      The title to give the graph
      void optionTitleStyle​(Style val)
      The Style to give to the title of the graph
      void optionXRotation​(double val)
      How far to rotate the graph around the X-axis (the line running from the left of the graph to the right), in degrees.
      void optionYRotation​(double val)
      How far to rotate the graph around the Y-axis (the line running from the top of the graph to the bottom), in degrees.
      void optionZRotation​(double val)
      How far to rotate the graph around the Z-axis (the line running from the front of the graph to the back), in degrees.
      protected void postcomplete()
      PostComplete is called by a Graph when it's rendered, but after complete.
      protected void postpostcomplete()
      The unfortunately named PostPostComplete is called last of all by a Graph when it's rendered, to add anything that couldn't quite be laid out correctly on the last pass - usually Text dependant on the position of other text.
      void setDefaultBorderColor​(java.awt.Color c)
      This method changes the default border color of new styles.
      void setDefaultColors​(java.awt.Paint[] colors)
      Set the default colors for the graph.
      void setDefaultLineThickness​(double thickness)
      Set the default line thickness for all styles. 1 is the default, 0.5 is half as thick, and so on.
      void setFontScale​(double val)
      Every text element that's created may have it's font automatically scaled up or down by a percentage by setting a different fontscale.
      static void setLicenseKey​(java.lang.String skey)
      Set the license key for the library.
      void setLightLevel​(int level)
      Set the level of light (technically, the level of shade) that should be applied to a graph.
      void setLightVector​(int x, int y, int z)
      Set the vector of where the light is coming from.
      void setPieEdgeDegrees​(double val)
      Adjust the number of degrees taken by each of the small faces used to draw the edge of a PieGraph.
      void toCanvas​(Output o)
      starts the conversion of the graph from values added through the set() or setCurve() methods to an Output.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • canvas

        protected org.faceless.graph.Canvas canvas
      • key

        protected org.faceless.graph.Key key
      • keyboxstyle

        protected Style keyboxstyle
      • keystyle

        protected Style keystyle
      • titlestyle

        protected Style titlestyle
      • subtitlestyle

        protected Style subtitlestyle
      • title

        protected java.lang.String title
      • subtitle

        protected java.lang.String subtitle
      • keytype

        protected int keytype
      • xrotation

        protected double xrotation
      • yrotation

        protected double yrotation
      • zrotation

        protected double zrotation
      • titlepadding

        protected double titlepadding
      • keypadding

        protected double keypadding
      • KEY_NONE

        public static final int KEY_NONE
        The Graph should have no key at all
        See Also:
        Constant Field Values
      • KEY_BOXED_BOTTOM

        public static final int KEY_BOXED_BOTTOM
        The Graph should have a key in a box at the bottom of the output
        See Also:
        Constant Field Values
      • KEY_BOXED_RIGHT

        public static final int KEY_BOXED_RIGHT
        The Graph should have a key in a box to the right of the output
        See Also:
        Constant Field Values
      • KEY_BOXED_LEFT

        public static final int KEY_BOXED_LEFT
        The Graph should have a key in a box to the left of the output
        See Also:
        Constant Field Values
      • KEY_BOXED_TOP

        public static final int KEY_BOXED_TOP
        The Graph should have a key in a box above the output
        See Also:
        Constant Field Values
    • Constructor Detail

      • Graph

        protected Graph()
    • Method Detail

      • addElement

        protected final void addElement​(org.faceless.graph.Element e)
        This is the method used to add an Element to the graph. It is usually called by subclasses of Graph, but is public in case developers want to add their own objects.
      • setDefaultColors

        public void setDefaultColors​(java.awt.Paint[] colors)
        Set the default colors for the graph. Each new element that is added will use the next color in this list - if there are no unused colors left, the list is reset to the beginning.
      • optionTitle

        public void optionTitle​(java.lang.String val)
        The title to give the graph

        Default: empty string

      • optionSubTitle

        public void optionSubTitle​(java.lang.String val)
        The sub-title to give the graph

        Default: empty string

      • optionTitleStyle

        public void optionTitleStyle​(Style val)
        The Style to give to the title of the graph

        Default: Black 16pt Helvetica

      • optionSubTitleStyle

        public void optionSubTitleStyle​(Style val)
        The Style to give to the sub-title of the graph

        Default: Black 12pt Helvetica

      • optionXRotation

        public void optionXRotation​(double val)
        How far to rotate the graph around the X-axis (the line running from the left of the graph to the right), in degrees.

        Default: 0

      • optionYRotation

        public void optionYRotation​(double val)
        How far to rotate the graph around the Y-axis (the line running from the top of the graph to the bottom), in degrees.

        Default: 0

      • optionZRotation

        public void optionZRotation​(double val)
        How far to rotate the graph around the Z-axis (the line running from the front of the graph to the back), in degrees.

        Default: 0

      • optionKeyStyle

        public void optionKeyStyle​(Style val)
        The Style to give to the text used in the external key

        Default: Black 10pt Helvetica

      • optionKeyBoxStyle

        public void optionKeyBoxStyle​(Style val)
        The Style to give to the box holding the external key. Only used if the optionDisplayKey is set to a variety of BOXED

        Default: Color #FFFFE0, with a black border

      • optionFixedAspectRatio

        public void optionFixedAspectRatio​(boolean val)
        Whether this graph should have a fixed aspect ratio. For every graph except PieGraph, this should be left at the default.

        Default: true for subclass PieGraph, false otherwise

      • optionRemoveBackFace

        protected void optionRemoveBackFace​(boolean val)
        Whether this graph should have the back-faces of polygons removed for faster rendering.

        Default: false for subclass LineGraph, true otherwise

      • complete

        protected void complete()
        Complete is the first method that's called by a Graph when it's rendered. It should take the data from the dataset and add the various elements that it needs to the Graph. The first thing it should do, however, is call super.complete().
      • postcomplete

        protected void postcomplete()
        PostComplete is called by a Graph when it's rendered, but after complete. It should add any elements that are required but couldn't be calculated until after complete() (the axes in an axes graph are an example). The last thing it should do before returning is call super.postcomplete()
      • postpostcomplete

        protected void postpostcomplete()
        The unfortunately named PostPostComplete is called last of all by a Graph when it's rendered, to add anything that couldn't quite be laid out correctly on the last pass - usually Text dependant on the position of other text. The last thing it should do before returning is call super.postpostcomplete()
      • toCanvas

        public final void toCanvas​(Output o)

        starts the conversion of the graph from values added through the set() or setCurve() methods to an Output.

        Parameters:
        o - the Output to pain the graph onto.
      • setLicenseKey

        public static void setLicenseKey​(java.lang.String skey)
        Set the license key for the library. When the library is purchased, the Big Faceless Organization supplies a key which disables the 30-day use restriction.
        Parameters:
        skey - the license key
      • setFontScale

        public void setFontScale​(double val)
        Every text element that's created may have it's font automatically scaled up or down by a percentage by setting a different fontscale. This was intended for subclasses of Output, so those that use a totally different scaling can set it in one go. But it's useful for the end user too. The default is 1, and a value of 0.5 would make all the text half the original size.

        Replaces the equivalent static method in the Style class

        Since:
        1.0.3
      • getFontScale

        public double getFontScale()
        Return the current font scale. See setFontScale(double)

        Replaces the equivalent static method in the Style class

        Since:
        1.0.3
      • setLightLevel

        public void setLightLevel​(int level)
        Set the level of light (technically, the level of shade) that should be applied to a graph. A value of 0 is no shading at all, a value of 100 gives deep shadows. The default is 70.

        Replaces the equivalent static method in the Style class

        Since:
        1.0.3
      • setLightVector

        public void setLightVector​(int x,
                                   int y,
                                   int z)
        Set the vector of where the light is coming from. The light is assumed to be coming from an infinite distance away in the specified direction, so don't worry about the length of the vector. The default is (1,0,0), which makes the light appear to come from the right side of the graph. Calling graph.setLightVector(-1,0,1) would put the light to the left and in front of the graph, while a vector (0,-1,0) would put the light directly underneath the graph, for a strange result indeed.

        Replaces the equivalent static method in the Style class

        Since:
        1.0.3
      • setDefaultBorderColor

        public void setDefaultBorderColor​(java.awt.Color c)
        This method changes the default border color of new styles. By default, this is set to black, but it can be set to null for a different look, or a different color altogether. This is useful if the graph is to be rendered over a black background, for example.

        Replaces the equivalent static method in the Style class

        Since:
        1.0.3
      • getDefaultBorderColor

        public java.awt.Color getDefaultBorderColor()
        Returns the value set by setDefaultBorderColor(java.awt.Color)

        Replaces the equivalent static method in the Style class

        Since:
        1.0.3
      • setDefaultLineThickness

        public void setDefaultLineThickness​(double thickness)
        Set the default line thickness for all styles. 1 is the default, 0.5 is half as thick, and so on. Not all Output classes can use this option. A value of zero means "make the lines as thin as possible".

        Replaces the equivalent static method in the Style class

        Since:
        1.0.3
      • setPieEdgeDegrees

        public void setPieEdgeDegrees​(double val)
        Adjust the number of degrees taken by each of the small faces used to draw the edge of a PieGraph. The higher the number of faces, the less noticeable the "banding" effect will be on the edge of a 3D shaded PieGraph, but at the expense of slower rendering. The default value is 5 degrees.

        Replaces the equivalent static method in the Style class

        Parameters:
        val - the number of degrees per face at the edge of a PieGraph
        Since:
        1.0.3