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 classTrace.BaseLinestatic classTrace.ErrorBarTypestatic classTrace.PointStylestatic classTrace.TraceTypeThe way how the trace will be drawn.
-
Field Summary
Fields Modifier and Type Field Description private booleanantiAliasingprivate intareaAlphaprivate Trace.BaseLinebaseLineprivate booleandrawYErrorInAreaprivate interrorBarCapWidthprivate org.eclipse.swt.graphics.ColorerrorBarColorColor used for error bars.private booleanerrorBarColorSetFlagprivate booleanerrorBarEnabledprivate IPointStyleProviderfPointStyleProviderprivate java.util.List<ISample>hotSampleistprivate intlineWidthIf traceType is bar, this is the width of the bar.private java.util.List<ITraceListener>listenersList of trace listenersprivate static intMARKER_SIZESize of 'markers' used on X axis to indicate non-plottable samplesprivate java.lang.Stringnameprivate intpointSizeprivate Trace.PointStylepointStyleprivate org.eclipse.swt.graphics.ColortraceColorColor used to draw the main line/marker of the trace.private IDataProvidertraceDataProviderprivate Trace.TraceTypetraceTypeprivate booleanuse_advanced_graphicsUse advanced graphics? Might not make a real performance difference, but since this it called a lot, keep it in variableprivate AxisxAxisprivate Trace.ErrorBarTypexErrorBarTypeprivate IXYGraphxyGraphprivate AxisyAxisprivate Trace.ErrorBarTypeyErrorBarType
-
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 voidaddListener(ITraceListener listener)voidaxisAutoScaleChanged(Axis axis, boolean oldAutoScale, boolean newAutoScale)voidaxisForegroundColorChanged(Axis axis, org.eclipse.swt.graphics.Color oldColor, org.eclipse.swt.graphics.Color newColor)voidaxisLogScaleChanged(Axis axis, boolean old, boolean logScale)voidaxisRangeChanged(Axis axis, Range old_range, Range new_range)This event indicates a change in the axis' value rangevoidaxisRevalidated(Axis axis)This method will be notified by axis whenever the axis is revalidated.voidaxisTitleChanged(Axis axis, java.lang.String oldTitle, java.lang.String newTitle)voiddataChanged(IDataProvider dataProvider)This method will be notified by data provider whenever the data changed in data providervoiddispose()Remove figures and reset fieldsprivate voiddrawErrorBar(org.eclipse.draw2d.Graphics graphics, org.eclipse.draw2d.geometry.Point dpPos, ISample dp)voiddrawLine(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.voiddrawPoint(org.eclipse.draw2d.Graphics graphics, org.eclipse.draw2d.geometry.Point pos)Draw point with the pointStyle and size of the trace;private voiddrawPoint(org.eclipse.draw2d.Graphics graphics, org.eclipse.draw2d.geometry.Point pos, ISample sample)private voiddrawPolyline(org.eclipse.draw2d.Graphics graphics, org.eclipse.draw2d.geometry.PointList pl)Draw polyline with the line style and line width of the trace.private voiddrawYErrorArea(org.eclipse.draw2d.Graphics graphics, ISample predp, ISample dp, org.eclipse.draw2d.geometry.Point predpPos, org.eclipse.draw2d.geometry.Point dpPos)private booleanevalDP(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 voidfirePointStyleChanged(Trace.PointStyle old, Trace.PointStyle newStyle)private voidfireTraceColorChanged(org.eclipse.swt.graphics.Color old, org.eclipse.swt.graphics.Color newColor)private voidfireTraceNameChanged(java.lang.String oldName, java.lang.String newName)private voidfireTraceTypeChanged(Trace.TraceType old, Trace.TraceType newTraceType)private voidfireYAxisChanged(Axis oldName, Axis newName)intgetAreaAlpha()Trace.BaseLinegetBaseLine()IDataProvidergetDataProvider()intgetErrorBarCapWidth()org.eclipse.swt.graphics.ColorgetErrorBarColor()java.util.List<ISample>getHotSampleList()Hot Sample is the sample on the trace which has been drawn in plot area.private RangegetIndexRangeOnXAxis()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'intgetLineWidth()java.lang.StringgetName()intgetPointSize()Trace.PointStylegetPointStyle()IPointStyleProvidergetPointStyleProvider()private ISample[]getStraightLineIntersection(ISample dp1, ISample dp2)Compute intersection of straight line with axes, no correction for 'TraceType'.org.eclipse.swt.graphics.ColorgetTraceColor()Trace.TraceTypegetTraceType()AxisgetXAxis()Trace.ErrorBarTypegetXErrorBarType()IXYGraphgetXYGraph()AxisgetYAxis()Trace.ErrorBarTypegetYErrorBarType()voidinit(Axis xAxis, Axis yAxis, IDataProvider dataProvider)Must be called if usingTrace(String)private voidinternalInit(Axis xAxis, Axis yAxis, IDataProvider dataProvider)booleanisAntiAliasing()booleanisDrawYErrorInArea()booleanisErrorBarEnabled()private intnearBinarySearchX(double key, boolean left)protected voidpaintFigure(org.eclipse.draw2d.Graphics graphics)private voidpaintInternalFigure(org.eclipse.draw2d.Graphics graphics)booleanremoveListener(ITraceListener listener)voidsetAntiAliasing(boolean antiAliasing)voidsetAreaAlpha(int areaAlpha)voidsetBaseLine(Trace.BaseLine baseLine)voidsetDataProvider(IDataProvider traceDataProvider)voidsetDrawYErrorInArea(boolean drawYErrorInArea)voidsetErrorBarCapWidth(int errorBarCapWidth)voidsetErrorBarColor(org.eclipse.swt.graphics.Color errorBarColor)voidsetErrorBarEnabled(boolean errorBarEnabled)voidsetLineWidth(int lineWidth)voidsetName(java.lang.String name)voidsetName(java.lang.String name, boolean fire)voidsetPointSize(int pointSize)voidsetPointStyle(Trace.PointStyle pointStyle)voidsetPointStyleProvider(IPointStyleProvider pointStyleProvider)voidsetTraceColor(org.eclipse.swt.graphics.Color traceColor)voidsetTraceType(Trace.TraceType traceType)voidsetXAxis(Axis axis)voidsetXErrorBarType(Trace.ErrorBarType errorBarType)voidsetXYGraph(IXYGraph xyGraph)voidsetYAxis(Axis axis)voidsetYErrorBarType(Trace.ErrorBarType errorBarType)java.lang.StringtoString()-
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:
paintFigurein 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:
toStringin classjava.lang.Object
-
dataChanged
public void dataChanged(IDataProvider dataProvider)
Description copied from interface:IDataProviderListenerThis method will be notified by data provider whenever the data changed in data provider- Specified by:
dataChangedin 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:IAxisListenerThis method will be notified by axis whenever the axis is revalidated.- Specified by:
axisRevalidatedin interfaceIAxisListener
-
axisRangeChanged
public void axisRangeChanged(Axis axis, Range old_range, Range new_range)
Description copied from interface:IAxisListenerThis event indicates a change in the axis' value range- Specified by:
axisRangeChangedin 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, ornullto 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:
axisForegroundColorChangedin interfaceIAxisListener
-
axisTitleChanged
public void axisTitleChanged(Axis axis, java.lang.String oldTitle, java.lang.String newTitle)
- Specified by:
axisTitleChangedin interfaceIAxisListener
-
axisAutoScaleChanged
public void axisAutoScaleChanged(Axis axis, boolean oldAutoScale, boolean newAutoScale)
- Specified by:
axisAutoScaleChangedin interfaceIAxisListener
-
axisLogScaleChanged
public void axisLogScaleChanged(Axis axis, boolean old, boolean logScale)
- Specified by:
axisLogScaleChangedin interfaceIAxisListener
-
dispose
public void dispose()
Remove figures and reset fields
-
-