|
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 the interface, 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-2008 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.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. |
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.lang.Object |
screenDataBufferLock
Used to synchronise of the screen data buffer. |
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 | |
---|---|
boolean |
checkEventInterest(Event<? extends EventType> event)
Does nothing. |
boolean |
checkEventValid(Event<? extends EventType> event,
boolean soFar)
Does nothing. |
void |
completedRegisterWithEventManager(EventManager manager)
Does nothing. |
void |
completedUnregisterWithEventManager(EventManager manager)
Does nothing. |
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. |
void |
eventRaised(Event<? extends EventType> event)
Processes events. |
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. |
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. |
boolean |
permissionRegisterWithEventManager(EventManager manager)
Permits to register as listener with the main LiveGraph event manager and only with the main LiveGraph event manager. |
boolean |
permissionUnregisterWithEventManager(EventManager manager)
Does not permit any unregistering. |
private void |
processCacheEvent(Event<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 |
processSettingsEvent(Event<SettingsEvent> event)
Calls the neccesary recomputations when graph settings or series settings have changed. |
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. |
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)
Updates the Transformer for the specified series (Transformer is the object that applies the data transformation set in the series settings). |
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 java.lang.Object screenDataBufferLock
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 |
---|
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)
seriesIndex
- The series index for which the Transformer must be updated.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 boolean permissionRegisterWithEventManager(EventManager manager)
permissionRegisterWithEventManager
in interface EventListener
manager
- The EventManager
for the registering attempt.
(LiveGraph.application().eventManager() == manager)
.EventListener.permissionRegisterWithEventManager(EventManager)
public boolean permissionUnregisterWithEventManager(EventManager manager)
permissionUnregisterWithEventManager
in interface EventListener
manager
- The EventManager
for the registering attempt.
false
.EventListener.permissionUnregisterWithEventManager(EventManager)
public void completedRegisterWithEventManager(EventManager manager)
completedRegisterWithEventManager
in interface EventListener
manager
- The EventManager
with which this EventListener
is now registered.EventListener.completedRegisterWithEventManager(EventManager)
public void completedUnregisterWithEventManager(EventManager manager)
completedUnregisterWithEventManager
in interface EventListener
manager
- The EventManager
with which this EventListener
is now unregistered.EventListener.completedUnregisterWithEventManager(EventManager)
public boolean checkEventInterest(Event<? extends EventType> event)
checkEventInterest
in interface EventListener
event
- An event in which this EventListener
may be interested.
false
.EventListener.checkEventInterest(Event)
public boolean checkEventValid(Event<? extends EventType> event, boolean soFar)
checkEventValid
in interface EventListener
event
- The event to be validated.soFar
- Whether event
has been successfuly validated by whichever EventListener
s
(if any) were invoked to validate event
before this EventListener
.
true
.EventListener.checkEventValid(Event, boolean)
public void eventRaised(Event<? extends EventType> event) throws java.io.FileNotFoundException
eventRaised
in interface EventListener
event
- Event to process.
java.io.FileNotFoundException
- If could not read new data file.private void processSettingsEvent(Event<SettingsEvent> event)
event
- Describes the change event.private void processCacheEvent(Event<CacheEvent> event)
event
- The cache event.
|
LiveGraph data visualisation and analysis framework |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |