dataGraph
Class DataGraph

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--java.applet.Applet
                          |
                          +--edu.davidson.tools.SApplet
                                |
                                +--dataGraph.DataGraph
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class DataGraph
extends SApplet

This applet plots data sets and functions. Each data set is a "series" of of coordinate pairs, (x,y). A series is identified by a series numeber. Each series a unique color and style. Whenever data is added, the appropriate series number must be specified.

The following embedding parameters are defined:

Parameter  Value  Type Description
Function null string An analytic function, f(x).
XMin -1.0 double Minimum value along x axis.
XMin 1.0 double Maximum value along x axis.
YMin -1.0 double Minimum value along y axis.
YMax 1.0 double Maximum value along y axis.
AutoScaleX true boolean Autoscale the x axis.
AutoScaleY true boolean Autoscale the y axis.
ShowControls true boolean Show the user interface.

A DataTable can be used as a data listener by obtaining its object identifier and passing this value to a data connection.  This value is obtained using

getGraphID().

A data series is a data source.  This enables other data listeners to change whenever data is added to a series.  This interface, SDataSource, enables inter-applet data passing between Physlets.

Object Identifier Variables
series id=getSeriesID(int sid x,y,u,v
Note: u and v are the differences between neighboring data points, Dx, Dy.
clock id=getClockID() t

 

See Also:
Serialized Form

Fields inherited from class edu.davidson.tools.SApplet
clock, dataConnections, dataListeners, dataSources, lock
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
DataGraph()
           
 
Method Summary
 int addCursor(double x, double y)
          Add a dragable cursor to the graph.
 void addData(int sid, double[] x, double[] y)
          Add a data vector to the series.
 void addDatum(int sid, double x, double y)
          Add a data point to the series.
 int addObject(java.lang.String name, java.lang.String parList)
          Create an object and add it to the Physlet.
 void clearAllSeries()
          Clear all data from the graph.
 void clearSeries(int s)
          Clear the data from a series.
 int createSeries(int sid)
          Create a series and return the series ID for use by a data connector.
 void deleteAllFunctions()
          Delete all functions from the plot.
 void deleteAllSeries()
          Delete all series from the graph
 void deleteFunction(int id)
          Delete a function from the plot.
 void deleteSeries(int s)
          Delete a series from the graph
 void destroy()
          Destroy all threads and cleanup the applet.
 java.lang.String getAppletInfo()
           
 java.lang.String getFunctionString(int id)
          Get the function that is being ploted.
 int getGraphID()
          Get the series ID for the applet.
 java.lang.String getParameter(java.lang.String key, java.lang.String def)
           
 java.lang.String[][] getParameterInfo()
           
 int getRegressionID(int sid, int start, int end)
          The id to the linear regression data source.
 int getSeriesID(int sid)
           
 void init()
           
 void loadDataFile(int sid, java.lang.String fileName)
          Read a data file of x,y coordinate pairs.
 int plotRegression(int sid, int start, int end)
          Plot a linear regression for the data in a series.
 boolean set(int id, java.lang.String name, java.lang.String parList)
          Change the properies of an object.
 void setAddRepeatedDatum(int sid, boolean add)
          Set the addRepeatedDataum property.
 void setAutoRefresh(boolean auto)
          Set the autoRefresh property.
 void setAutoReplaceData(int id, boolean auto)
          Disables the clearSeries function so that new data will replace a dataset when the addData method is called.
 void setAutoscaleX(boolean autoOn)
          Set the autoscaleX property for the graph.
 void setAutoscaleY(boolean autoOn)
          Set the autoscaleY property for the graph.
 void setDefault()
          Set the graph to default.
 boolean setDisplayOffset(int id, int xOff, int yOff)
          Offset the object's position on the screen from its default drawing position.
 boolean setDragable(int id, boolean drag)
          Make the object with the given id dragable.
 void setDrawGrid(boolean drawOn)
          Set the draw grid property for the graph.
 void setDrawZero(boolean drawOn)
          Set the graph to draw lines at x=0 and y=0.
 void setEnableMouse(boolean mouseOn)
          Enable to mouse to show coordinates.
 boolean setFormat(int id, java.lang.String fstr)
          Change the object's format for the display of numeric data.
 void setFormat(java.lang.String str)
          Change the display format for mouse actions.
 void setFunctionRange(int id, double xmin, double xmax, int n)
          Set the range of an analytic function.
 boolean setFunctionString(int id, java.lang.String str)
          Change the function that is being ploted.
 boolean setFunctionVariable(int id, java.lang.String str)
          Change the function's independent variable.
 void setGutters(int g1, int g2, int g3, int g4)
          Set the gutters i.e., margins, around the graph.
 void setLabelX(java.lang.String s)
          Set the x axis label.
 void setLabelY(java.lang.String s)
          Set the y axis label.
 void setLastPointMarker(int id, boolean lpm)
          Set the series so that the last point in the dataset has a distinctive marker.
 void setMarkerSize(int id, double size)
          Set the marker size.
 void setMinMaxX(double min, double max)
          Set the x axis minimum and maximum values.
 void setMinMaxY(double min, double max)
          Set the y axis minimum and maximum values.
 void setMinXRange(boolean enable, double min, double max)
          Restrict the range on the x axis so that it can be no smaller than the given values.
 void setMinYRange(boolean enable, double min, double max)
          Restrict the range on the y axis so that it can be no smaller than the given values.
 void setRGB(int id, int r, int g, int b)
          Set the color of the object.
 void setSeriesLegend(int id, int xpix, int ypix, java.lang.String legend)
          Set the series legend.
 void setSeriesLegendRGB(int id, int r, int g, int b)
          Set the series legend color.
 void setSeriesRGB(int id, int r, int g, int b)
          Set the series line and marker color.
 void setSeriesStyle(int id, boolean conPts, int m)
          Set the series style.
 void setShowAxes(boolean show)
          Show or hide the the X and Y axes on the graph.
 int setSketchMode(boolean sketch)
          Enable sketching with the mouse.
 void setSorted(int sid, boolean sorted)
          Sort the series data according to the x value.
 void setSquare(boolean isSquare)
          Set the aspect ratio=1 so that both axes have the same pixels per unit.
 void setStripChart(int sid, int numPts, boolean stripChart)
          Set strip chart mode.
 void setTimeDisplay(boolean show)
          Enable the time display in the applet window.
 void setTitle(java.lang.String str)
          Set the graph title.
 boolean setVisibility(int id, boolean show)
          Show the visibility of the object.
 void setYScaleFromFunction(int id)
          Set the y scale of the graph to the analytic function max-min.
 void start()
           
 void stop()
           
 void updateDataConnections()
          Have all series and functions transfer their data to their connections.
 
Methods inherited from class edu.davidson.tools.SApplet
addDataListener, addDataSource, cleanupDataConnections, clearAllData, clearData, deleteDataConnection, deleteDataConnections, forward, getClockID, getClockTime, getDataConnectionFromDL, getDataConnectionFromDS, getDataFromDS, getDataListener, getDataListener, getDataSource, getDataSource, getID, getRunningID, getSourceData, getSourceVariables, isAutoRefresh, isClockRunning, makeDataConnection, pause, removeDataListener, removeDataSource, reset, reverse, setClockContinous, setClockCycle, setClockOneShot, setClockTime, setConnectionBlock, setConnectionListener, setConnectionSmoothing, setConnectionSource, setConnectionStride, setDt, setExternalClock, setFPS, setRunningID, setRunningID, setTimeContinuous, setTimeCycle, setTimeOneShot, startClock, stepClock, stepTime, stepTimeBack, stepTimeForward, stopClock, updateDataConnection
 
Methods inherited from class java.applet.Applet
getAccessibleContext, getAppletContext, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, remove, remove, removeAll, removeContainerListener, removeNotify, setFont, setLayout, update, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, disable, dispatchEvent, enable, enable, enableInputMethods, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DataGraph

public DataGraph()
Method Detail

addCursor

public int addCursor(double x,
                     double y)
Add a dragable cursor to the graph. The cursor is a data source.
Parameters:
x - The initial x coordinate.
y - The initial y coordinate.
Returns:
int The ID.

addData

public void addData(int sid,
                    double[] x,
                    double[] y)
Add a data vector to the series.
Parameters:
id - series ID
x[] - x vector
y[] - y vector

addDatum

public void addDatum(int sid,
                     double x,
                     double y)
Add a data point to the series.
Parameters:
id - series ID
x - x value
y - y value

addObject

public int addObject(java.lang.String name,
                     java.lang.String parList)
Create an object and add it to the Physlet. The first argument is the name of the object to be added and the second is a comma-delimited list of parameters. For example, a circle can be added a follows:

addObject ("circle", "x = 0, y = -1.0, r = 10");

See the supplemental documentation for a list of object names and parameters.
Parameters:
name - the type of object to be created.
parList - a list of parameters to be set
Returns:
id that identifies the object.

clearAllSeries

public void clearAllSeries()
Clear all data from the graph. Series properties such as color and style remain unchanged.

clearSeries

public void clearSeries(int s)
Clear the data from a series. Series properties such as color and style remain unchanged.
Parameters:
Series - ID

createSeries

public int createSeries(int sid)
Create a series and return the series ID for use by a data connector. Return an existing ID if the series already exists.
Parameters:
series - Series ID
Returns:
series Object ID

deleteAllFunctions

public void deleteAllFunctions()
Delete all functions from the plot.

deleteAllSeries

public void deleteAllSeries()
Delete all series from the graph

deleteFunction

public void deleteFunction(int id)
Delete a function from the plot.
Parameters:
id - The id of the function;

deleteSeries

public void deleteSeries(int s)
Delete a series from the graph
Parameters:
Series - ID

destroy

public void destroy()
Destroy all threads and cleanup the applet.
Overrides:
destroy in class SApplet

getAppletInfo

public java.lang.String getAppletInfo()
Overrides:
getAppletInfo in class java.applet.Applet

getFunctionString

public java.lang.String getFunctionString(int id)
Get the function that is being ploted.
Parameters:
id - The id of the function.
Returns:
str The function string, f(x);

getGraphID

public int getGraphID()
Get the series ID for the applet. This ID is used to make a connection to a SDataSource.

getParameter

public java.lang.String getParameter(java.lang.String key,
                                     java.lang.String def)

getParameterInfo

public java.lang.String[][] getParameterInfo()
Overrides:
getParameterInfo in class java.applet.Applet

getRegressionID

public int getRegressionID(int sid,
                           int start,
                           int end)
The id to the linear regression data source. The source variables are m,b,dm, and db.
Parameters:
sid - the series id.
start - the first point to use in the regression
end - the last point to use in the regression
Returns:
int the object identifier for the data source

getSeriesID

public int getSeriesID(int sid)

init

public void init()
Overrides:
init in class java.applet.Applet

loadDataFile

public void loadDataFile(int sid,
                         java.lang.String fileName)
Read a data file of x,y coordinate pairs.
Parameters:
sid - The series id.
fileName - The file name

plotRegression

public int plotRegression(int sid,
                          int start,
                          int end)
Plot a linear regression for the data in a series. The regression is stored as an analytic function.
Parameters:
sid - the series id.
start - the first point to use in the regression
end - the last point to use in the regression
Returns:
int the object identifier. Use the object id to reference the regression as a function.

set

public boolean set(int id,
                   java.lang.String name,
                   java.lang.String parList)
Change the properies of an object. The first argument is the object identifier. The second argument is the name of the property and the third is a comma-delimited list of parameters. For example, the scale can be added a follows:

set(id, "sale", "xmin=0, xmax=2, autoscalx=false");

Parameters:
id - the identifier of the object
name - the type of property to be created.
parList - a list of parameters
Returns:
true if successful

setAddRepeatedDatum

public void setAddRepeatedDatum(int sid,
                                boolean add)
Set the addRepeatedDataum property. A new datum will not be added to a series if this is false. Default is true.
Parameters:
add - Added repeated data values to the graph?

setAutoRefresh

public void setAutoRefresh(boolean auto)
Set the autoRefresh property. AutoRefresh will repaint the graph whenever data changes but slows down the system and may cause flicker.
Overrides:
setAutoRefresh in class SApplet
Parameters:
auto - AutoRefresh the graph?

setAutoReplaceData

public void setAutoReplaceData(int id,
                               boolean auto)
Disables the clearSeries function so that new data will replace a dataset when the addData method is called. Eliminates screen flash since clearSeries(id) does not have to be called.
Parameters:
id - The series id.
auto - AutoReplace

setAutoscaleX

public void setAutoscaleX(boolean autoOn)
Set the autoscaleX property for the graph.
Parameters:
autoOn - Autoscale the x axis?

setAutoscaleY

public void setAutoscaleY(boolean autoOn)
Set the autoscaleY property for the graph.
Parameters:
autoOn - Autoscale the y axis?

setDefault

public void setDefault()
Set the graph to default. Delete functions. Delete series. Delete drawable objects such as cursors.
Overrides:
setDefault in class SApplet

setDisplayOffset

public boolean setDisplayOffset(int id,
                                int xOff,
                                int yOff)
Offset the object's position on the screen from its default drawing position.
Parameters:
id - The id of the object.
xoff - The x offset.
yoff - The y offset.
Returns:
True if successful.

setDragable

public boolean setDragable(int id,
                           boolean drag)
Make the object with the given id dragable.
Parameters:
id - The id of the object.
drag - Dragable?
Returns:
true if successful.

setDrawGrid

public void setDrawGrid(boolean drawOn)
Set the draw grid property for the graph.
Parameters:
drawOn - Draw the grid?

setDrawZero

public void setDrawZero(boolean drawOn)
Set the graph to draw lines at x=0 and y=0.
Parameters:
drawOn - Draw the zero lines?

setEnableMouse

public void setEnableMouse(boolean mouseOn)
Enable to mouse to show coordinates.
Parameters:
mouseOn - Enable the mouse?

setFormat

public boolean setFormat(int id,
                         java.lang.String fstr)
Change the object's format for the display of numeric data. An id of zero will change the display format for mouse actions. Use this method to control the number of significant digits in calculations with text objects. Use Unix printf conventions. For example fstr="%6.3f"
Parameters:
id - The id of the object.
fstr - the format string.
Returns:
True if successful.

setFormat

public void setFormat(java.lang.String str)
Change the display format for mouse actions. Use UNIX fprint syntax.
Parameters:
str - The format for cooridinate display.

setFunctionRange

public void setFunctionRange(int id,
                             double xmin,
                             double xmax,
                             int n)
Set the range of an analytic function.
Parameters:
id - The id of the function.
xmin - Minimum value of the range.
xmax - Maximum value of the range.
n - The number of data points.

setFunctionString

public boolean setFunctionString(int id,
                                 java.lang.String str)
Change the function that is being ploted.
Parameters:
str - The function string, f(x);

setFunctionVariable

public boolean setFunctionVariable(int id,
                                   java.lang.String str)
Change the function's independent variable.
Parameters:
id - The id of the function.
str - The new independent variable.

setGutters

public void setGutters(int g1,
                       int g2,
                       int g3,
                       int g4)
Set the gutters i.e., margins, around the graph. Should only be used if the axes are visible.
Parameters:
g1 - The gutter on the left of the graph.
g1 - The gutter on the top of the graph.
g1 - The gutter on the right of the graph.
g1 - The gutter on the bottom of the graph.

setLabelX

public void setLabelX(java.lang.String s)
Set the x axis label.
Parameters:
The - label value.

setLabelY

public void setLabelY(java.lang.String s)
Set the y axis label.
Parameters:
The - label value.

setLastPointMarker

public void setLastPointMarker(int id,
                               boolean lpm)
Set the series so that the last point in the dataset has a distinctive marker.
Parameters:
id - The series id.
lpm - Enable the marker.

setMarkerSize

public void setMarkerSize(int id,
                          double size)
Set the marker size.
Parameters:
id - Series id.
size - Marker size.

setMinMaxX

public void setMinMaxX(double min,
                       double max)
Set the x axis minimum and maximum values. No effect if autoscale is true.
Parameters:
min - Minumum value.
max - Maximum value.

setMinMaxY

public void setMinMaxY(double min,
                       double max)
Set the y axis minimum and maximum values. No effect if autoscale is true.
Parameters:
min - Minumum value.
max - Maximum value.

setMinXRange

public void setMinXRange(boolean enable,
                         double min,
                         double max)
Restrict the range on the x axis so that it can be no smaller than the given values.
Parameters:
enable - true to restrict the range, false otherwise
min - minimum value.
max - maximum value.

setMinYRange

public void setMinYRange(boolean enable,
                         double min,
                         double max)
Restrict the range on the y axis so that it can be no smaller than the given values.
Parameters:
enable - true to restrict the range, false otherwise
min - minimum value.
max - maximum value.

setRGB

public void setRGB(int id,
                   int r,
                   int g,
                   int b)
Set the color of the object.
Parameters:
id - The series id.
r - red.
g - green.
b - blue.

setSeriesLegend

public void setSeriesLegend(int id,
                            int xpix,
                            int ypix,
                            java.lang.String legend)
Set the series legend.
Parameters:
id - The series id.
xpix - The x postion in pixels.
ypix - The y postion in pixels.
legend - The legend.

setSeriesLegendRGB

public void setSeriesLegendRGB(int id,
                               int r,
                               int g,
                               int b)
Set the series legend color.
Parameters:
id - The series id.
r - red.
g - green.
b - blue.

setSeriesRGB

public void setSeriesRGB(int id,
                         int r,
                         int g,
                         int b)
Set the series line and marker color.
Parameters:
id - The series id.
r - red.
g - green.
b - blue.

setSeriesStyle

public void setSeriesStyle(int id,
                           boolean conPts,
                           int m)
Set the series style.
Parameters:
id - The series id.
conPts - Connect the points?
m - Marker style. (m=1 is cross; m=2 is square, m=3 is circle)

setShowAxes

public void setShowAxes(boolean show)
Show or hide the the X and Y axes on the graph. May need to set the gutters to zero seliminate white space.
Parameters:
show - Show the axis?

setSketchMode

public int setSketchMode(boolean sketch)
Enable sketching with the mouse.
Parameters:
sketch - true will sketch
Returns:
int the id of the mouse data source

setSorted

public void setSorted(int sid,
                      boolean sorted)
Sort the series data according to the x value.
Parameters:
sid - the series number
sorted - true if data should be sorted

setSquare

public void setSquare(boolean isSquare)
Set the aspect ratio=1 so that both axes have the same pixels per unit.
Parameters:
isSquare? -  

setStripChart

public void setStripChart(int sid,
                          int numPts,
                          boolean stripChart)
Set strip chart mode. A strip chart will drop data points to keep the total number of displayed points constant.
Parameters:
sid - the series number
numPts - the number of points in the strip chart
stripChart - true for stip chart mode

setTimeDisplay

public void setTimeDisplay(boolean show)
Enable the time display in the applet window.
Parameters:
show - boolean Show the time?

setTitle

public void setTitle(java.lang.String str)
Set the graph title.
Parameters:
str - Title string.

setVisibility

public boolean setVisibility(int id,
                             boolean show)
Show the visibility of the object.
Parameters:
st - show object on screen?

setYScaleFromFunction

public void setYScaleFromFunction(int id)
Set the y scale of the graph to the analytic function max-min. The Y scale of a graph only depends on the the data in the data series. This method can be used to set the scale to the max-min of an analytic function.
Parameters:
id - The id of the function.

start

public void start()
Overrides:
start in class java.applet.Applet

stop

public void stop()
Overrides:
stop in class java.applet.Applet

updateDataConnections

public void updateDataConnections()
Have all series and functions transfer their data to their connections.
Overrides:
updateDataConnections in class SApplet

Copyright Wolfgang Christian

Visit the Davidson CollegePhyslets Page