|
LiveGraph data visualisation and analysis framework |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.LiveGraph.plot.Plotter
public class Plotter
This class handles the conversion of the cached data to a screen image and the
drawing of the image on a Graphics
object.
This class uses an AffineTransform
object to convert the data held in the
cache to a data plot in screen coordinates. In order to keep the AffineTransform
object appropriate for the current display at all times a plotter listens to
various DataCache
and ObservableSettings
events; in addition it offers
a setScreenSize(int, int)
-method which must be called each time when the
canvas-panel that uses the plotter changes its size.
Whenever the dataCache
changes, a plotter uses the current datScrTransform
object to convert the data from the cache into a plot in screen coordinates according to
the current global graph- and series-settings. The screen data obtained this way is locally
cached in the screenDataBuffer
array. This way the data does not need to be
re-computed each time the plot must be drawn on the screen.
In this version the plotter handles data values transformations required by the display
options (if any) on the fly. If new options should be added to theinterface, this mechanism
should be replaces by a more flexible solution.
This product includes software developed by the
LiveGraph project and its contributors.
(http://www.live-graph.org)
Copyright (c) 2007 G. Paperin.
All rights reserved.
File: Plotter.java
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following terms and conditions are met:
1. Redistributions of source code must retain the above
acknowledgement of the LiveGraph project and its web-site, the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above acknowledgement of the
LiveGraph project and its web-site, the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with
the distribution.
3. All advertising materials mentioning features or use of this software or any derived
software must display the following acknowledgement:
This product includes software developed by the LiveGraph project and its
contributors.
(http://www.live-graph.org)
4. All advertising materials distributed in form of HTML pages or any other technology
permitting active hyper-links that mention features or use of this software or any
derived software must display the acknowledgment specified in condition 3 of this
agreement, and in addition, include a visible and working hyper-link to the LiveGraph
homepage (http://www.live-graph.org).
THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Nested Class Summary | |
---|---|
private class |
Plotter.MutableInt
For holding mutable ints as objects. |
private class |
Plotter.PointsByIndexComparator
Used in order to compare points referenced by their index in Plotter.SeriesScreenData.points ;
the comparison is by x-xoordinates. |
private class |
Plotter.SeriesScreenData
A data structure to hold the locally cached plot data for a data series. |
private static interface |
Plotter.Transformer
Used to encapsulate data series points translation routines. |
Nested classes/interfaces inherited from interface org.LiveGraph.dataCache.CacheObserver |
---|
CacheObserver.CacheEvent |
Field Summary | |
---|---|
private static int |
AXES_LBL_GAP
Gap between axes labels. |
private static int |
AXES_MARKS_SIZE
Size of the scale marks on the axes. |
private DataCache |
dataCache
The data cache. |
private boolean |
dataComputationRunning
Whether screen data computation is in progress. |
private static int |
DATAPOINT_RAD
Radius for datapoints marks on small graphs. |
private java.awt.geom.Rectangle2D.Double |
dataViewport
Viewable area in data coordinates. |
private java.awt.geom.AffineTransform |
datScrTransform
Data space to screen space transformation. |
private static int |
FONT_SIZE
Label font size. |
private GraphSettings |
graphSetts
Graph settings. |
private static java.awt.Color |
HAXIS_COL
X axis colour. |
private double |
hGridStep
The actual h-grid step after the consideration of plot size. |
private boolean |
highlightPoints
Whether dara points close to the mouse position should be highlighted. |
private static int |
HMARGIN
Horisiontal margin. |
private static Plotter.Transformer |
IDTransform
|
private static int |
MIN_GRIDLINE_DIST
The minimum distance between grid lines (in pixels). |
private static java.awt.Dimension |
minScreenSize
|
private boolean |
pointHighlightComputationRunning
Whether screen data computation is in progress. |
private Plotter.PointsByIndexComparator |
pointsByIndexComparator
Used for sorting points by x values. |
private Plotter.SeriesScreenData[] |
screenDataBuffer
Buffers the screen coordinates of the graphs. |
private java.awt.Dimension |
screenSize
Screen size in pixels. |
private boolean |
selfSettingHGridSize
Whether the next change of h-grid settings was initiated by this plotter and should therefore be ignored by the plotter's handler. |
private boolean |
selfSettingVGridSize
Whether the next change of v-grid settings was initiated by this plotter and should therefore be ignored by the plotter's handler. |
private DataSeriesSettings |
seriesSetts
Data series settings. |
private boolean |
showAtLeastOneSeries
Whether anythig at all is to be displayed. |
private double |
userHGridStep
The h-grid size get by a settings change that was not initiated by this plotter itself. |
private double |
userVGridStep
The v-grid size get by a settings change that was not initiated by this plotter itself. |
private static java.awt.Color |
VAXIS_COL
Y axis colour. |
private double |
vGridStep
The actual v-grid step after the consideration of plot size. |
private static int |
VMARGIN
Vertical margin. |
private double[] |
xCoordinates
Buffers the x coordinates. |
Constructor Summary | |
---|---|
Plotter(DataCache dataCache)
Creates a plotter for the data held in the specified cache. |
Method Summary | |
---|---|
void |
cacheEventFired(DataCache cache,
CacheObserver.CacheEvent event)
If cached label info is changed, the screen buffer is recreated; if cached data is updated the view port and the screen data are recomputed. |
private void |
computeGridSteps()
Computes the actual grid mesh sizes taking in account the current plot size. |
private void |
computeScreenData()
Computes the screen coordinates for the visible data series. |
private void |
computeScreenDataForSeries(int seriesIndex)
Compute the screen coordinates for the specified series. |
private void |
computeXCoordinates()
Compute the x coordinates in data space according to the current settings. |
int |
getScreenHeight()
Gets canvas screen size (Y). |
int |
getScreenWidth()
Gets canvas screen size (X). |
boolean |
getShowAtLeastOneSeries()
Gets whether at least one series is to be plotted. |
java.util.List<java.lang.Integer> |
highlightAround(java.awt.Point sp)
Highlights the points around the specified point. |
private void |
initGlobalParameters()
Used by the constructor to initialise global settings references. |
void |
paint(java.awt.Graphics g)
Paints the previously computed graphs along with the axes, labels, grids and so on to the specified graphics context. |
private void |
paintAxes(java.awt.Graphics g)
Paints the coordinate axes. |
private void |
paintData(java.awt.Graphics g)
Paints the data series. |
private void |
paintGrids(java.awt.Graphics g)
Paints the grid. |
private void |
resetDataViewport()
Recomputes the currently visible data area according to the current graph and series settings. |
private void |
resetScreenDataBuffer()
Reallocates the screen data buffer. |
java.awt.geom.Point2D.Double |
screenToDataPoint(java.awt.Point sp)
Map the specified point in screen coordinates into the data space. |
boolean |
screenTooSmall()
Gets whether the screen area is large enough to paint the graph. |
void |
setScreenSize(int width,
int height)
Set the current view screen size. |
void |
settingHasChanged(DataSeriesSettings settings,
java.lang.String info)
Calls the neccesary recoputations when seties settings are changed. |
void |
settingHasChanged(GraphSettings settings,
java.lang.String info)
Calls the neccesary recoputations when graph settings are changed. |
void |
settingHasChanged(ObservableSettings settings,
java.lang.Object info)
Dispatches settings change events. |
private void |
updateDatScrTransform()
Updates the data to screen transform map according to the currently visible data area and screen size. |
private void |
updateScreenData()
First, recomputes the currently visible data area according to the current graph and series settings; then, computes the screen coordinates for the visible data series.. |
private void |
updateSeriesTransformer(int seriesIndex)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final int VMARGIN
private static final int HMARGIN
private static final java.awt.Dimension minScreenSize
private static final java.awt.Color VAXIS_COL
private static final java.awt.Color HAXIS_COL
private static final int FONT_SIZE
private static final int AXES_LBL_GAP
private static final int AXES_MARKS_SIZE
private static final int DATAPOINT_RAD
private static final int MIN_GRIDLINE_DIST
private DataCache dataCache
private DataSeriesSettings seriesSetts
private GraphSettings graphSetts
private boolean showAtLeastOneSeries
private Plotter.SeriesScreenData[] screenDataBuffer
private double[] xCoordinates
private Plotter.PointsByIndexComparator pointsByIndexComparator
private java.awt.geom.Rectangle2D.Double dataViewport
private java.awt.Dimension screenSize
private java.awt.geom.AffineTransform datScrTransform
private boolean dataComputationRunning
private boolean pointHighlightComputationRunning
private boolean selfSettingHGridSize
private double userHGridStep
private double hGridStep
private boolean selfSettingVGridSize
private double userVGridStep
private double vGridStep
private boolean highlightPoints
private static Plotter.Transformer IDTransform
Constructor Detail |
---|
public Plotter(DataCache dataCache)
dataCache
- Cache holding the data to plot.Method Detail |
---|
private void initGlobalParameters()
public boolean screenTooSmall()
true
iff the screen area is large enough to paint the graph.public boolean getShowAtLeastOneSeries()
true
if at seast one data series should be plotted, false
otherwise.public void paint(java.awt.Graphics g)
g
- Paint context.private void paintGrids(java.awt.Graphics g)
g
- The graphics context.private void paintAxes(java.awt.Graphics g)
g
- The graphics context.private void paintData(java.awt.Graphics g)
g
- The graphics context.private void computeScreenData()
private void computeXCoordinates()
private void computeScreenDataForSeries(int seriesIndex)
seriesIndex
- The cache index of the series to be computed.public java.util.List<java.lang.Integer> highlightAround(java.awt.Point sp)
sp
- A marker screen point.
private void computeGridSteps()
public java.awt.geom.Point2D.Double screenToDataPoint(java.awt.Point sp)
sp
- A point in screen coordinates.
private void updateDatScrTransform()
private void resetScreenDataBuffer()
private void updateScreenData()
private void updateSeriesTransformer(int seriesIndex)
private void resetDataViewport()
public void setScreenSize(int width, int height)
width
- Canvas width in pixels.height
- Canvas height in pixelspublic int getScreenWidth()
public int getScreenHeight()
public void cacheEventFired(DataCache cache, CacheObserver.CacheEvent event)
cacheEventFired
in interface CacheObserver
public void settingHasChanged(ObservableSettings settings, java.lang.Object info)
settingHasChanged
in interface SettingsObserver
settings
- The settings object that was changed.info
- Is used to further specify the change. Usually this is a
String
containing the name of the changed setting.public void settingHasChanged(DataSeriesSettings settings, java.lang.String info)
settings
- Series settings.info
- Change event info.public void settingHasChanged(GraphSettings settings, java.lang.String info)
settings
- Graph settings.info
- Change event info.
|
LiveGraph data visualisation and analysis framework |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |