Class Trace
- java.lang.Object
-
- org.eclipse.draw2d.Figure
-
- org.eclipse.nebula.visualization.xygraph.figures.Trace
-
- All Implemented Interfaces:
org.eclipse.draw2d.IFigure
,IDataProviderListener
,IAxisListener
public class Trace extends org.eclipse.draw2d.Figure implements IDataProviderListener, IAxisListener
The trace figure.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Trace.BaseLine
static class
Trace.ErrorBarType
static class
Trace.PointStyle
static class
Trace.TraceType
The way how the trace will be drawn.
-
Field Summary
Fields Modifier and Type Field Description private boolean
antiAliasing
private int
areaAlpha
private Trace.BaseLine
baseLine
private boolean
drawYErrorInArea
private int
errorBarCapWidth
private org.eclipse.swt.graphics.Color
errorBarColor
Color used for error bars.private boolean
errorBarColorSetFlag
private boolean
errorBarEnabled
private IPointStyleProvider
fPointStyleProvider
private java.util.List<ISample>
hotSampleist
private int
lineWidth
If traceType is bar, this is the width of the bar.private java.util.List<ITraceListener>
listeners
List of trace listenersprivate static int
MARKER_SIZE
Size of 'markers' used on X axis to indicate non-plottable samplesprivate java.lang.String
name
private int
pointSize
private Trace.PointStyle
pointStyle
private org.eclipse.swt.graphics.Color
traceColor
Color used to draw the main line/marker of the trace.private IDataProvider
traceDataProvider
private Trace.TraceType
traceType
private boolean
use_advanced_graphics
Use advanced graphics? Might not make a real performance difference, but since this it called a lot, keep it in variableprivate Axis
xAxis
private Trace.ErrorBarType
xErrorBarType
private IXYGraph
xyGraph
private Axis
yAxis
private Trace.ErrorBarType
yErrorBarType
-
Constructor Summary
Constructors Constructor Description Trace(java.lang.String name)
init(Axis, Axis, IDataProvider)
needs to be called if a trace is created with this constructorTrace(java.lang.String name, Axis xAxis, Axis yAxis, IDataProvider dataProvider)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(ITraceListener listener)
void
axisAutoScaleChanged(Axis axis, boolean oldAutoScale, boolean newAutoScale)
void
axisForegroundColorChanged(Axis axis, org.eclipse.swt.graphics.Color oldColor, org.eclipse.swt.graphics.Color newColor)
void
axisLogScaleChanged(Axis axis, boolean old, boolean logScale)
void
axisRangeChanged(Axis axis, Range old_range, Range new_range)
This event indicates a change in the axis' value rangevoid
axisRevalidated(Axis axis)
This method will be notified by axis whenever the axis is revalidated.void
axisTitleChanged(Axis axis, java.lang.String oldTitle, java.lang.String newTitle)
void
dataChanged(IDataProvider dataProvider)
This method will be notified by data provider whenever the data changed in data providervoid
dispose()
Remove figures and reset fieldsprivate void
drawErrorBar(org.eclipse.draw2d.Graphics graphics, org.eclipse.draw2d.geometry.Point dpPos, ISample dp)
void
drawLine(org.eclipse.draw2d.Graphics graphics, org.eclipse.draw2d.geometry.Point p1, org.eclipse.draw2d.geometry.Point p2)
Draw line with the line style and line width of the trace.void
drawPoint(org.eclipse.draw2d.Graphics graphics, org.eclipse.draw2d.geometry.Point pos)
Draw point with the pointStyle and size of the trace;private void
drawPoint(org.eclipse.draw2d.Graphics graphics, org.eclipse.draw2d.geometry.Point pos, ISample sample)
private void
drawPolyline(org.eclipse.draw2d.Graphics graphics, org.eclipse.draw2d.geometry.PointList pl)
Draw polyline with the line style and line width of the trace.private void
drawYErrorArea(org.eclipse.draw2d.Graphics graphics, ISample predp, ISample dp, org.eclipse.draw2d.geometry.Point predpPos, org.eclipse.draw2d.geometry.Point dpPos)
private boolean
evalDP(double x, double y, ISample dp1, ISample dp2)
Sanity check: Point x/y was computed to be an axis intersection, but that can fail because of rounding errors or for samples with NaN, Infinity.private void
firePointStyleChanged(Trace.PointStyle old, Trace.PointStyle newStyle)
private void
fireTraceColorChanged(org.eclipse.swt.graphics.Color old, org.eclipse.swt.graphics.Color newColor)
private void
fireTraceNameChanged(java.lang.String oldName, java.lang.String newName)
private void
fireTraceTypeChanged(Trace.TraceType old, Trace.TraceType newTraceType)
private void
fireYAxisChanged(Axis oldName, Axis newName)
int
getAreaAlpha()
Trace.BaseLine
getBaseLine()
IDataProvider
getDataProvider()
int
getErrorBarCapWidth()
org.eclipse.swt.graphics.Color
getErrorBarColor()
java.util.List<ISample>
getHotSampleList()
Hot Sample is the sample on the trace which has been drawn in plot area.private Range
getIndexRangeOnXAxis()
Get the corresponding sample index range based on the range of xAxis.private ISample[]
getIntersection(ISample dp1, ISample dp2)
Compute axes intersection considering the 'TraceType'int
getLineWidth()
java.lang.String
getName()
int
getPointSize()
Trace.PointStyle
getPointStyle()
IPointStyleProvider
getPointStyleProvider()
private ISample[]
getStraightLineIntersection(ISample dp1, ISample dp2)
Compute intersection of straight line with axes, no correction for 'TraceType'.org.eclipse.swt.graphics.Color
getTraceColor()
Trace.TraceType
getTraceType()
Axis
getXAxis()
Trace.ErrorBarType
getXErrorBarType()
IXYGraph
getXYGraph()
Axis
getYAxis()
Trace.ErrorBarType
getYErrorBarType()
void
init(Axis xAxis, Axis yAxis, IDataProvider dataProvider)
Must be called if usingTrace(String)
private void
internalInit(Axis xAxis, Axis yAxis, IDataProvider dataProvider)
boolean
isAntiAliasing()
boolean
isDrawYErrorInArea()
boolean
isErrorBarEnabled()
private int
nearBinarySearchX(double key, boolean left)
protected void
paintFigure(org.eclipse.draw2d.Graphics graphics)
private void
paintInternalFigure(org.eclipse.draw2d.Graphics graphics)
boolean
removeListener(ITraceListener listener)
void
setAntiAliasing(boolean antiAliasing)
void
setAreaAlpha(int areaAlpha)
void
setBaseLine(Trace.BaseLine baseLine)
void
setDataProvider(IDataProvider traceDataProvider)
void
setDrawYErrorInArea(boolean drawYErrorInArea)
void
setErrorBarCapWidth(int errorBarCapWidth)
void
setErrorBarColor(org.eclipse.swt.graphics.Color errorBarColor)
void
setErrorBarEnabled(boolean errorBarEnabled)
void
setLineWidth(int lineWidth)
void
setName(java.lang.String name)
void
setName(java.lang.String name, boolean fire)
void
setPointSize(int pointSize)
void
setPointStyle(Trace.PointStyle pointStyle)
void
setPointStyleProvider(IPointStyleProvider pointStyleProvider)
void
setTraceColor(org.eclipse.swt.graphics.Color traceColor)
void
setTraceType(Trace.TraceType traceType)
void
setXAxis(Axis axis)
void
setXErrorBarType(Trace.ErrorBarType errorBarType)
void
setXYGraph(IXYGraph xyGraph)
void
setYAxis(Axis axis)
void
setYErrorBarType(Trace.ErrorBarType errorBarType)
java.lang.String
toString()
-
Methods inherited from class org.eclipse.draw2d.Figure
add, add, add, add, addAncestorListener, addCoordinateListener, addFigureListener, addFocusListener, addKeyListener, addLayoutListener, addListener, addMouseListener, addMouseMotionListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, containsPoint, containsPoint, erase, findDescendantAtExcluding, findFigureAt, findFigureAt, findFigureAt, findFigureAtExcluding, findMouseEventTargetAt, findMouseEventTargetInDescendantsAt, fireCoordinateSystemChanged, fireFigureMoved, fireMoved, firePropertyChange, firePropertyChange, firePropertyChange, getBackgroundColor, getBorder, getBounds, getChildren, getClientArea, getClientArea, getClippingStrategy, getCursor, getFlag, getFont, getForegroundColor, getInsets, getLayoutManager, getListeners, getLocalBackgroundColor, getLocalFont, getLocalForegroundColor, getLocation, getMaximumSize, getMinimumSize, getMinimumSize, getParent, getPreferredSize, getPreferredSize, getSize, getToolTip, getUpdateManager, handleFocusGained, handleFocusLost, handleKeyPressed, handleKeyReleased, handleMouseDoubleClicked, handleMouseDragged, handleMouseEntered, handleMouseExited, handleMouseHover, handleMouseMoved, handleMousePressed, handleMouseReleased, hasFocus, internalGetEventDispatcher, intersects, invalidate, invalidateTree, isCoordinateSystem, isEnabled, isFocusTraversable, isMirrored, isMouseEventTarget, isOpaque, isRequestFocusEnabled, isShowing, isValid, isValidationRoot, isVisible, layout, paint, paintBorder, paintChildren, paintClientArea, primTranslate, remove, removeAll, removeAncestorListener, removeCoordinateListener, removeFigureListener, removeFocusListener, removeKeyListener, removeLayoutListener, removeListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, revalidate, setBackgroundColor, setBorder, setBounds, setChildrenDirection, setChildrenEnabled, setChildrenOrientation, setClippingStrategy, setConstraint, setCursor, setEnabled, setFlag, setFocusTraversable, setFont, setForegroundColor, setLayoutManager, setLocation, setMaximumSize, setMinimumSize, setOpaque, setParent, setPreferredSize, setPreferredSize, setRequestFocusEnabled, setSize, setSize, setToolTip, setValid, setVisible, translate, translateFromParent, translateToAbsolute, translateToParent, translateToRelative, useLocalCoordinates, validate
-
-
-
-
Field Detail
-
MARKER_SIZE
private static final int MARKER_SIZE
Size of 'markers' used on X axis to indicate non-plottable samples- See Also:
- Constant Field Values
-
use_advanced_graphics
private final boolean use_advanced_graphics
Use advanced graphics? Might not make a real performance difference, but since this it called a lot, keep it in variable
-
listeners
private final java.util.List<ITraceListener> listeners
List of trace listeners
-
name
private java.lang.String name
-
traceDataProvider
private IDataProvider traceDataProvider
-
xAxis
private Axis xAxis
-
yAxis
private Axis yAxis
-
traceColor
private org.eclipse.swt.graphics.Color traceColor
Color used to draw the main line/marker of the trace. Also used for error bars unless errorBarColor is defined
-
traceType
private Trace.TraceType traceType
-
baseLine
private Trace.BaseLine baseLine
-
pointStyle
private Trace.PointStyle pointStyle
-
lineWidth
private int lineWidth
If traceType is bar, this is the width of the bar.
-
pointSize
private int pointSize
-
areaAlpha
private int areaAlpha
-
antiAliasing
private boolean antiAliasing
-
errorBarEnabled
private boolean errorBarEnabled
-
yErrorBarType
private Trace.ErrorBarType yErrorBarType
-
xErrorBarType
private Trace.ErrorBarType xErrorBarType
-
errorBarCapWidth
private int errorBarCapWidth
-
errorBarColorSetFlag
private boolean errorBarColorSetFlag
-
errorBarColor
private org.eclipse.swt.graphics.Color errorBarColor
Color used for error bars. Ifnull
, traceColor is used
-
drawYErrorInArea
private boolean drawYErrorInArea
-
xyGraph
private IXYGraph xyGraph
-
hotSampleist
private java.util.List<ISample> hotSampleist
-
fPointStyleProvider
private IPointStyleProvider fPointStyleProvider
-
-
Constructor Detail
-
Trace
public Trace(java.lang.String name)
init(Axis, Axis, IDataProvider)
needs to be called if a trace is created with this constructor
-
Trace
public Trace(java.lang.String name, Axis xAxis, Axis yAxis, IDataProvider dataProvider)
-
-
Method Detail
-
addListener
public void addListener(ITraceListener listener)
-
removeListener
public boolean removeListener(ITraceListener listener)
-
setPointStyleProvider
public void setPointStyleProvider(IPointStyleProvider pointStyleProvider)
-
getPointStyleProvider
public IPointStyleProvider getPointStyleProvider()
-
init
public void init(Axis xAxis, Axis yAxis, IDataProvider dataProvider)
Must be called if usingTrace(String)
- Parameters:
xAxis
-yAxis
-dataProvider
-
-
internalInit
private void internalInit(Axis xAxis, Axis yAxis, IDataProvider dataProvider)
-
drawErrorBar
private void drawErrorBar(org.eclipse.draw2d.Graphics graphics, org.eclipse.draw2d.geometry.Point dpPos, ISample dp)
-
drawYErrorArea
private void drawYErrorArea(org.eclipse.draw2d.Graphics graphics, ISample predp, ISample dp, org.eclipse.draw2d.geometry.Point predpPos, org.eclipse.draw2d.geometry.Point dpPos)
-
drawPoint
public void drawPoint(org.eclipse.draw2d.Graphics graphics, org.eclipse.draw2d.geometry.Point pos)
Draw point with the pointStyle and size of the trace;- Parameters:
graphics
-pos
-
-
drawPoint
private void drawPoint(org.eclipse.draw2d.Graphics graphics, org.eclipse.draw2d.geometry.Point pos, ISample sample)
-
drawLine
public void drawLine(org.eclipse.draw2d.Graphics graphics, org.eclipse.draw2d.geometry.Point p1, org.eclipse.draw2d.geometry.Point p2)
Draw line with the line style and line width of the trace.- Parameters:
graphics
-p1
-p2
-
-
drawPolyline
private void drawPolyline(org.eclipse.draw2d.Graphics graphics, org.eclipse.draw2d.geometry.PointList pl)
Draw polyline with the line style and line width of the trace.- Parameters:
graphics
-pl
-
-
paintFigure
protected void paintFigure(org.eclipse.draw2d.Graphics graphics)
- Overrides:
paintFigure
in classorg.eclipse.draw2d.Figure
-
paintInternalFigure
private void paintInternalFigure(org.eclipse.draw2d.Graphics graphics)
-
getIntersection
private ISample[] getIntersection(ISample dp1, ISample dp2)
Compute axes intersection considering the 'TraceType'- Parameters:
dp1
- 'Start' point of linedp2
- 'End' point of line- Returns:
- The intersection points with the axes when draw the line between the two data points. The index 0 of the result is the first intersection point. index 1 is the second one.
-
getStraightLineIntersection
private ISample[] getStraightLineIntersection(ISample dp1, ISample dp2)
Compute intersection of straight line with axes, no correction for 'TraceType'.- Parameters:
dp1
- 'Start' point of linedp2
- 'End' point of line- Returns:
- The intersection points between the line, which is the straight line between the two data points, and the axes. Result could be { null, null }, { point1, null } or { point1, point2 }.
-
evalDP
private boolean evalDP(double x, double y, ISample dp1, ISample dp2)
Sanity check: Point x/y was computed to be an axis intersection, but that can fail because of rounding errors or for samples with NaN, Infinity. Is it in the plot area? Is it between the start/end points.- Parameters:
x
-y
-dp1
-dp2
-- Returns:
- true if the point (x,y) is between dp1 and dp2 BUT not equal to either AND within the x/y axes. false otherwise
-
setXAxis
public void setXAxis(Axis axis)
- Parameters:
axis
- the xAxis to set
-
getXAxis
public Axis getXAxis()
- Returns:
- the xAxis
-
setYAxis
public void setYAxis(Axis axis)
- Parameters:
axis
- the yAxis to set
-
setDataProvider
public void setDataProvider(IDataProvider traceDataProvider)
- Parameters:
traceDataProvider
- the traceDataProvider to set
-
getTraceType
public Trace.TraceType getTraceType()
- Returns:
- the traceType
-
setTraceColor
public void setTraceColor(org.eclipse.swt.graphics.Color traceColor)
- Parameters:
traceColor
- Desired trace color
-
fireTraceColorChanged
private void fireTraceColorChanged(org.eclipse.swt.graphics.Color old, org.eclipse.swt.graphics.Color newColor)
-
getTraceColor
public org.eclipse.swt.graphics.Color getTraceColor()
- Returns:
- the traceColor
-
setTraceType
public void setTraceType(Trace.TraceType traceType)
- Parameters:
traceType
- the traceType to set
-
fireTraceTypeChanged
private void fireTraceTypeChanged(Trace.TraceType old, Trace.TraceType newTraceType)
-
setBaseLine
public void setBaseLine(Trace.BaseLine baseLine)
- Parameters:
baseLine
- the baseLine to set
-
setPointStyle
public void setPointStyle(Trace.PointStyle pointStyle)
- Parameters:
pointStyle
- the pointStyle to set
-
firePointStyleChanged
private void firePointStyleChanged(Trace.PointStyle old, Trace.PointStyle newStyle)
-
setLineWidth
public void setLineWidth(int lineWidth)
- Parameters:
lineWidth
- the lineWidth to set
-
setPointSize
public void setPointSize(int pointSize)
- Parameters:
pointSize
- the pointSize to set
-
setAreaAlpha
public void setAreaAlpha(int areaAlpha)
- Parameters:
areaAlpha
- the areaAlpha to set
-
setAntiAliasing
public void setAntiAliasing(boolean antiAliasing)
- Parameters:
antiAliasing
- the antiAliasing to set
-
setName
public void setName(java.lang.String name)
- Parameters:
name
- the name of the trace to set
-
setName
public void setName(java.lang.String name, boolean fire)
- Parameters:
name
- the name of the trace to setfire
- if true, a traceNameChanged event is fired
-
fireTraceNameChanged
private void fireTraceNameChanged(java.lang.String oldName, java.lang.String newName)
-
getName
public java.lang.String getName()
- Returns:
- the name of the trace
-
getPointSize
public int getPointSize()
- Returns:
- the pointSize
-
getAreaAlpha
public int getAreaAlpha()
- Returns:
- the areaAlpha
-
getYAxis
public Axis getYAxis()
- Returns:
- the yAxis
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
dataChanged
public void dataChanged(IDataProvider dataProvider)
Description copied from interface:IDataProviderListener
This method will be notified by data provider whenever the data changed in data provider- Specified by:
dataChanged
in interfaceIDataProviderListener
-
getIndexRangeOnXAxis
private Range getIndexRangeOnXAxis()
Get the corresponding sample index range based on the range of xAxis. This will help trace to draw only the part of data confined in xAxis. So it may also provides the first data out of the range to make the line could be drawn between inside data and outside data. This method only works for chronological data, which means the data is naturally sorted on xAxis.- Returns:
- the Range of the index.
-
nearBinarySearchX
private int nearBinarySearchX(double key, boolean left)
-
axisRevalidated
public void axisRevalidated(Axis axis)
Description copied from interface:IAxisListener
This method will be notified by axis whenever the axis is revalidated.- Specified by:
axisRevalidated
in interfaceIAxisListener
-
axisRangeChanged
public void axisRangeChanged(Axis axis, Range old_range, Range new_range)
Description copied from interface:IAxisListener
This event indicates a change in the axis' value range- Specified by:
axisRangeChanged
in interfaceIAxisListener
-
getDataProvider
public IDataProvider getDataProvider()
- Returns:
- the traceDataProvider
-
setErrorBarEnabled
public void setErrorBarEnabled(boolean errorBarEnabled)
- Parameters:
errorBarEnabled
- the errorBarEnabled to set
-
setYErrorBarType
public void setYErrorBarType(Trace.ErrorBarType errorBarType)
- Parameters:
errorBarType
- the yErrorBarType to set
-
setXErrorBarType
public void setXErrorBarType(Trace.ErrorBarType errorBarType)
- Parameters:
errorBarType
- the xErrorBarType to set
-
setDrawYErrorInArea
public void setDrawYErrorInArea(boolean drawYErrorInArea)
- Parameters:
drawYErrorInArea
- the drawYErrorArea to set
-
setErrorBarCapWidth
public void setErrorBarCapWidth(int errorBarCapWidth)
- Parameters:
errorBarCapWidth
- the errorBarCapWidth to set
-
setErrorBarColor
public void setErrorBarColor(org.eclipse.swt.graphics.Color errorBarColor)
- Parameters:
errorBarColor
- Desired color for error bars, ornull
to use trace color
-
getHotSampleList
public java.util.List<ISample> getHotSampleList()
Hot Sample is the sample on the trace which has been drawn in plot area.- Returns:
- the hotPointList
-
getBaseLine
public Trace.BaseLine getBaseLine()
- Returns:
- the baseLine
-
getPointStyle
public Trace.PointStyle getPointStyle()
- Returns:
- the pointStyle
-
getLineWidth
public int getLineWidth()
- Returns:
- the lineWidth
-
isAntiAliasing
public boolean isAntiAliasing()
- Returns:
- the antiAliasing
-
isErrorBarEnabled
public boolean isErrorBarEnabled()
- Returns:
- the errorBarEnabled
-
getYErrorBarType
public Trace.ErrorBarType getYErrorBarType()
- Returns:
- the yErrorBarType
-
getXErrorBarType
public Trace.ErrorBarType getXErrorBarType()
- Returns:
- the xErrorBarType
-
getErrorBarCapWidth
public int getErrorBarCapWidth()
- Returns:
- the errorBarCapWidth
-
getErrorBarColor
public org.eclipse.swt.graphics.Color getErrorBarColor()
- Returns:
- Color used for error bars or 'area'
-
isDrawYErrorInArea
public boolean isDrawYErrorInArea()
- Returns:
- the drawYErrorInArea
-
setXYGraph
public void setXYGraph(IXYGraph xyGraph)
- Parameters:
xyGraph
- the xyGraph to set
-
getXYGraph
public IXYGraph getXYGraph()
- Returns:
- the xyGraph
-
axisForegroundColorChanged
public void axisForegroundColorChanged(Axis axis, org.eclipse.swt.graphics.Color oldColor, org.eclipse.swt.graphics.Color newColor)
- Specified by:
axisForegroundColorChanged
in interfaceIAxisListener
-
axisTitleChanged
public void axisTitleChanged(Axis axis, java.lang.String oldTitle, java.lang.String newTitle)
- Specified by:
axisTitleChanged
in interfaceIAxisListener
-
axisAutoScaleChanged
public void axisAutoScaleChanged(Axis axis, boolean oldAutoScale, boolean newAutoScale)
- Specified by:
axisAutoScaleChanged
in interfaceIAxisListener
-
axisLogScaleChanged
public void axisLogScaleChanged(Axis axis, boolean old, boolean logScale)
- Specified by:
axisLogScaleChanged
in interfaceIAxisListener
-
dispose
public void dispose()
Remove figures and reset fields
-
-