papaya
Class Visuals

java.lang.Object
  extended by papaya.Visuals
All Implemented Interfaces:
PapayaConstants
Direct Known Subclasses:
BoxPlot, CorrelationPlot, ScatterPlot, SubPlot

public class Visuals
extends Object
implements PapayaConstants

Visuals is the parent class behind most of the other plotting classes.

It:
1. Contains some useful functions for the visual representation of your data (e.g. setting up your font, writing labels, mapping arrays to the plot right-left-top-bottom parameters, xTicks, yTicks, etc.) that should help you reduce the amount of code you end up writing.
2. Is extended by the available "Plotting" classes used to quickly give a visual snapshot of your data.


Field Summary
 int bgColor
          Specifies the plot background color
 
Fields inherited from interface papaya.PapayaConstants
BASELINE, big, biginv, BOTTOM, CENTER, CORNER, FONTNAME, GRAY, INDEX_NOT_FOUND, INDICES_NOT_FOUND, LEFT, LOGPI, MACHEP, MAXGAM, MAXLOG, MINLOG, RIGHT, SQRTH, SQTPI, STROKEWEIGHT, TEXTSIZE, TOP
 
Constructor Summary
Visuals(PApplet _theParent, float _plotLeft, float _plotTop, float _plotWidth, float _plotHeight)
          The parent class behind the other plotting classes.
 
Method Summary
 void drawAxes(int _sColor, float _sWeight)
          Draws the plot axes using a line with color _sColor, and weight _sWeight
 void drawRect()
          Draw the plot background rectangle using the default plot dimensions and background color.
 void drawRect(float _left, float _top, float _width, float _height, int _rectColor)
          Draws the plot background rectangle using the input dimensions and background color.
 float getBottom()
           
 float getHeight()
           
 float getLeft()
           
 float getRight()
           
 float getTop()
           
 float getWidth()
           
 void horizLine(float _xFrom, float _xTo, float _y, int _sColor, float _sWeight)
          draws a horizonal line with color _sColor, and weight _sWeight
 void legendHoriz(float x, float y, int[] colors, String[] labels)
          Draws a legend going to the right with the first element situated at (x,y).
 void legendVert(float x, float y, int[] colors, String[] labels)
          Draws a legend going downwards with the first element situated at (x,y).
 void line(float _x1, float _y1, float _x2, float _y2, int _sColor, float _sWeight)
          Draws a straight line going from (x[0],y[0]) to (x[1],y[1]) with color _sColor, and weight _sWeight
 float[] mapXData(float[] data)
          Maps the x-data from the range min(data) to max(data) to the plotLeft and plotLeft+plotWidth.
 float[] mapXData(float[] data, float minXDat, float maxXDat)
          Maps the x-data from the range minXDat to maxXDat to the plotLeft and plotRight.
 float[] mapYData(float[] data)
          Maps the y-data from the range min(data) to max(data) to the plotBottom and plotTop.
 float[] mapYData(float[] data, float minYDat, float maxYDat)
          Maps the y-data from the range minYDat to maxYDat to the plotBottom and plotTop.
 void setBackgroundColor(int _backgroundColor)
           
 void setHeight(float _plotHeight)
           
 void setLeft(float _plotLeft)
           
 void setTop(float _plotTop)
           
 void setupFont(String _fontName, int _xAlign, int _yAlign, int _tSize)
          function for setting the font up for writing the labels
 void setupFont(String _fontName, int _xAlign, int _yAlign, int _tSize, int _fontColor)
          overload setupFont function that takes in font color
 void setWidth(float _plotWidth)
           
 void vertLine(float _yFrom, float _yTo, float _x, int _sColor, float _sWeight)
          draws a vertical line with color _sColor, and weight _sWeight
 void writeLabels(float _text, float _xPos, float _yPos)
           
 void writeLabels(PFont _plotFont, float _text, float _xPos, float _yPos)
           
 void writeLabels(PFont _plotFont, String[] _text, float[] _xPos, float[] _yPos)
           
 void writeLabels(PFont _plotFont, String _text, float _xPos, float _yPos)
           
 void writeLabels(String _text, float _xPos, float _yPos)
           
 void writeTitle(String _title, PFont _plotFont)
          titles the plot given the String _title and the PFont
 void xLabels(float _left, float _width, float _xDatMin, float _xDatMax, int _numDiv)
          Write the x-axis labels.
 void xLabels(float _left, float _width, String[] _xLabels)
          Write the x-axis labels.
 void xTicks(float _left, float _width, int _numDiv, int _tickHeight)
          Draws the x-axis tickmarks.
 void yLabels(float _top, float _height, float _yDatMin, float _yDatMax, int _numDiv)
          Write the y-axis labels.
 void yLabels(float _top, float _height, String[] _yLabels)
          Write the y-axis labels.
 void YLines(int _numDiv)
          Draws horizontal y-lines on the plot
 void yTicks(float _top, float _height, int _numDiv, int _tickWidth)
          Draws the y-axis tickmarks.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bgColor

public int bgColor
Specifies the plot background color

Constructor Detail

Visuals

public Visuals(PApplet _theParent,
               float _plotLeft,
               float _plotTop,
               float _plotWidth,
               float _plotHeight)
The parent class behind the other plotting classes.

Visuals contains some useful functions for the (elementary!) visual representation of your data (e.g. setting up your font, writing labels, mapping arrays to the plot right-left-top-bottom parameters, xTicks, yTicks,legends, etc). Nothing very fancy like writing x-labels at an angle or computing your tax returns for you though so don't get your hopes up. Sorry.

Parameters:
_theParent - the Processing papplet. Just "this" in your sketch.
_plotLeft - the plot left
_plotTop - the plot top (in Processing coordinates!)
_plotWidth - the plot width
_plotHeight - the plot height.

The bottom of the plot area is then given by _plotTop + _plotHeight while the right is _plotLeft + _plotWidth.

Method Detail

mapXData

public float[] mapXData(float[] data)
Maps the x-data from the range min(data) to max(data) to the plotLeft and plotLeft+plotWidth. That is, mappedData[i] = plotLeft + (data[i] - min) / (max-min) * plotWidth. This is not done directly though, but rather, the Mat.map(float[] data, float low1, float high1, float low2, float high2) function is used.

Parameters:
data - the x data to map.
Returns:
the mapped data.

mapXData

public float[] mapXData(float[] data,
                        float minXDat,
                        float maxXDat)
Maps the x-data from the range minXDat to maxXDat to the plotLeft and plotRight. That is, mappedData[i] = plotLeft + (data[i] - minXDat) / (maxXDat-minXDat) * plotWidth. This is not done directly though, but rather, the Mat.map(float[] data, float low1, float high1, float low2, float high2) function is used.

Note: No internal checks are done to make sure that the min/max values are in the data range.

Parameters:
data - the x data to map.
minXDat - the minimum value to use in the data mapping.
maxXDat - the maximum value to use in the data mapping.
Returns:
the mapped data.

mapYData

public float[] mapYData(float[] data)
Maps the y-data from the range min(data) to max(data) to the plotBottom and plotTop. That is, mappedData[i] = plotBottom + (data[i] - min) / (max-min) * (-plotHeight). (The minus sign above accounts for the difference in Processing's coordinate system and what we associate with Top/Bottom). The computation above is not done directly though, but rather, the Mat.map(float[] data, float low1, float high1, float low2, float high2) function is used.

Parameters:
data - the y data to map.
Returns:
the mapped data.

mapYData

public float[] mapYData(float[] data,
                        float minYDat,
                        float maxYDat)
Maps the y-data from the range minYDat to maxYDat to the plotBottom and plotTop. That is, mappedData[i] = plotBottom + (data[i] - minYDat) / (maxYDat-minYDat) * (-plotHeight). (The minus sign above accounts for the difference in Processing's coordinate system and what we associate with Top/Bottom). The computation above is not done directly though, but rather, the Mat.map(float[] data, float low1, float high1, float low2, float high2) function is used.

Note: No internal checks are done to make sure that the min/max values are in the data range.

Parameters:
data - the x data to map.
minYDat - the minimum value to use in the data mapping.
maxYDat - the maximum value to use in the data mapping.
Returns:
the mapped data.

drawAxes

public void drawAxes(int _sColor,
                     float _sWeight)
Draws the plot axes using a line with color _sColor, and weight _sWeight


drawRect

public void drawRect()
Draw the plot background rectangle using the default plot dimensions and background color.
  • Left most point: plotLeft
  • Top most point: plotTop
  • Width: plotWidth
  • Height: plotHeight

  • drawRect

    public void drawRect(float _left,
                         float _top,
                         float _width,
                         float _height,
                         int _rectColor)
    Draws the plot background rectangle using the input dimensions and background color.

    Parameters:
    _left - the left-most point of the rectangle
    _top - the top-most point of the rectangle
    _width - the width of the rectangle
    _height - the height of the rectangle
    _rectColor - the rectangle color.

    legendVert

    public void legendVert(float x,
                           float y,
                           int[] colors,
                           String[] labels)
    Draws a legend going downwards with the first element situated at (x,y). Useful for situations where you are plotting more than one dataset.

    Parameters:
    colors - the legend colors
    labels - labels that go with each color

    legendHoriz

    public void legendHoriz(float x,
                            float y,
                            int[] colors,
                            String[] labels)
    Draws a legend going to the right with the first element situated at (x,y). Useful for situations where you are plotting more than one dataset.

    Parameters:
    colors - the legend colors
    labels - labels that go with each color

    xTicks

    public void xTicks(float _left,
                       float _width,
                       int _numDiv,
                       int _tickHeight)
    Draws the x-axis tickmarks.

    Parameters:
    _left - left most tick position. Set to negative to make it default to the plotLeft)
    _width - (_left + _width) = right most tick position. Set to negative
    _numDiv - the number of divisions. The number of tick marks drawn = _numDiv+1.
    _tickHeight - the height of the tick mark.

    xLabels

    public void xLabels(float _left,
                        float _width,
                        float _xDatMin,
                        float _xDatMax,
                        int _numDiv)
    Write the x-axis labels.

    Parameters:
    _left - left most label position. Set to negative to make it default to the plotLeft)
    _width - (_left + _width) = right most label position. Set to negative to make it default to the plotWidth
    _xDatMin - minimum data value to show in the label
    _xDatMax - maximum data value to show in the label
    _numDiv - the number of divisions.

    xLabels

    public void xLabels(float _left,
                        float _width,
                        String[] _xLabels)
    Write the x-axis labels.

    Parameters:
    _left - left most label position. Set to negative to make it default to the plotLeft)
    _width - (_left + _width) = right most label position. Set to negative to make it default to the plotWidth
    _xLabels - the String array of labels.

    yTicks

    public void yTicks(float _top,
                       float _height,
                       int _numDiv,
                       int _tickWidth)
    Draws the y-axis tickmarks.

    Parameters:
    _top - top most tick position in Processing's coordinate system. Set to negative to make it default to the plotTop)
    _height - (top + height) = bottom most label position in Processing's coordinate system. Set to negative to make it default to the plotHeight.
    _numDiv - the number of divisions. The number of tick marks drawn = _numDiv+1.
    _tickWidth - the width of the tick mark.

    yLabels

    public void yLabels(float _top,
                        float _height,
                        float _yDatMin,
                        float _yDatMax,
                        int _numDiv)
    Write the y-axis labels.

    Parameters:
    _top - top most label position in Processing's coordinate system. Set to negative to make it default to the plotTop)
    _height - (top + height) = bottom most label positionin Processing's coordinate system. Set to negative to make it default to the plotHeight.
    _yDatMin - minimum data value to show in the label
    _yDatMax - maximum data value to show in the label
    _numDiv - the number of divisions.

    yLabels

    public void yLabels(float _top,
                        float _height,
                        String[] _yLabels)
    Write the y-axis labels.

    Parameters:
    _top - top most label position in Processing's coordinate system. Set to negative to make it default to the plotTop)
    _height - (top + height) = bottom most label positionin Processing's coordinate system. Set to negative to make it default to the plotHeight.
    _yLabels - the String array of labels.

    YLines

    public void YLines(int _numDiv)
    Draws horizontal y-lines on the plot

    Parameters:
    _numDiv - number of divisions. The number of lines drawn = numDiv+1

    horizLine

    public void horizLine(float _xFrom,
                          float _xTo,
                          float _y,
                          int _sColor,
                          float _sWeight)
    draws a horizonal line with color _sColor, and weight _sWeight


    vertLine

    public void vertLine(float _yFrom,
                         float _yTo,
                         float _x,
                         int _sColor,
                         float _sWeight)
    draws a vertical line with color _sColor, and weight _sWeight


    line

    public void line(float _x1,
                     float _y1,
                     float _x2,
                     float _y2,
                     int _sColor,
                     float _sWeight)
    Draws a straight line going from (x[0],y[0]) to (x[1],y[1]) with color _sColor, and weight _sWeight


    writeTitle

    public void writeTitle(String _title,
                           PFont _plotFont)
    titles the plot given the String _title and the PFont


    writeLabels

    public void writeLabels(PFont _plotFont,
                            String[] _text,
                            float[] _xPos,
                            float[] _yPos)

    writeLabels

    public void writeLabels(PFont _plotFont,
                            String _text,
                            float _xPos,
                            float _yPos)

    writeLabels

    public void writeLabels(PFont _plotFont,
                            float _text,
                            float _xPos,
                            float _yPos)

    writeLabels

    public void writeLabels(float _text,
                            float _xPos,
                            float _yPos)

    writeLabels

    public void writeLabels(String _text,
                            float _xPos,
                            float _yPos)

    setupFont

    public void setupFont(String _fontName,
                          int _xAlign,
                          int _yAlign,
                          int _tSize)
    function for setting the font up for writing the labels


    setupFont

    public void setupFont(String _fontName,
                          int _xAlign,
                          int _yAlign,
                          int _tSize,
                          int _fontColor)
    overload setupFont function that takes in font color


    setBackgroundColor

    public void setBackgroundColor(int _backgroundColor)

    getLeft

    public float getLeft()

    getRight

    public float getRight()

    getTop

    public float getTop()

    getBottom

    public float getBottom()

    getWidth

    public float getWidth()

    getHeight

    public float getHeight()

    setLeft

    public void setLeft(float _plotLeft)

    setWidth

    public void setWidth(float _plotWidth)

    setTop

    public void setTop(float _plotTop)

    setHeight

    public void setHeight(float _plotHeight)


    Processing library papaya by Adila Faruk. (C) 2014