Class LinearScaleTicks
- java.lang.Object
-
- org.eclipse.nebula.visualization.xygraph.linearscale.LinearScaleTicks
-
- All Implemented Interfaces:
ITicksProvider
public class LinearScaleTicks extends java.lang.Object implements ITicksProvider
Default scale tick mark algorithm
-
-
Field Summary
Fields Modifier and Type Field Description private intgridStepInPixelprivate java.util.ArrayList<java.lang.Integer>minorPositionsthe array of minor tick positions in pixelsprivate static java.lang.StringMINUSstatic java.lang.StringNAMEThe name of this tick providerprivate IScaleProviderscaleprivate booleanshowMaxLabeldefault: show max labelprivate booleanshowMinLabeldefault: show min labelprivate static intTICK_LABEL_GAPprivate inttickLabelMaxHeightthe maximum height of tick labelsprivate inttickLabelMaxLengththe maximum length of tick labelsprivate java.util.ArrayList<java.lang.Integer>tickLabelPositionsthe array of tick label position in pixelsprivate java.util.ArrayList<java.lang.String>tickLabelsthe array of tick labelprivate java.util.ArrayList<java.lang.Double>tickLabelValuesthe array of tick label valesprivate java.util.ArrayList<java.lang.Boolean>tickLabelVisibilitiesthe array of visibility state of tick label
-
Constructor Summary
Constructors Constructor Description LinearScaleTicks(IScaleProvider scale)constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleanaddMinMaxTickInfo(double value, int length, boolean isMin)Add the tick labels, positions and values for the min and max case to the corresponding List used to store them.private voidaddTickInfo(java.math.BigDecimal d, double max, double logMin, int length, boolean isFirstPosition, boolean minDateAdded)Add the tick labels, positions and values to the corresponding List used to store them.java.lang.StringgetDefaultFormatPattern(double min, double max)private doublegetGridStep(int lengthInPixels, double min, double max)Gets the grid step.intgetGridStepInPixels()intgetHeadMargin()java.lang.StringgetLabel(int index)intgetLabelPosition(int index)java.util.List<java.lang.String>getLabels()intgetMajorCount()intgetMaxHeight()intgetMaxWidth()intgetMinorCount()intgetMinorPosition(int index)intgetPosition(int index)java.util.List<java.lang.Integer>getPositions()Gets the tick positions.intgetTailMargin()intgetTickLabelMaxHeight()intgetTickLabelMaxLength()private doublegetTimeGridStep(double min, double max, double gridStepHint)Given min, max and the gridStepHint, returns the time grid step as a double.doublegetValue(int index)java.util.List<java.lang.Boolean>getVisibilities()private booleanhasSpaceToDraw(int previousPosition, int tickLabelPosition, java.lang.String previousTickLabel, java.lang.String tickLabel)If it has enough space to draw the tick labelprivate booleanisMajorTick(double tickValue)Checks if the tick label is major tick.booleanisShowMaxLabel()Shows the maximum value of the range as a labelbooleanisShowMinLabel()Shows the minimum value of the range as a labelbooleanisVisible(int index)private java.math.BigDecimalpow(double base, int exponent)Get base^exponentvoidsetShowMaxLabel(boolean showMaxLabel)sets the visibility of the maximum labelvoidsetShowMinLabel(boolean showMinLabel)Sets the visibility of the minimum labelRangeupdate(double min, double max, int length)Update ticks.private voidupdateTickLabelForLinearScale(double min, double max, int length)Updates tick label for normal scale.private voidupdateTickLabelForLinearScale(double min, double max, int length, double tickStep)Updates tick label for normal scale.private voidupdateTickLabelForLogScale(double min, double max, int length)Updates tick label for log scale.private voidupdateTickLabelMaxLengthAndHeight()Gets max length of tick label.private voidupdateTickVisibility()Updates the visibility of tick labels.
-
-
-
Field Detail
-
NAME
public static final java.lang.String NAME
The name of this tick provider- See Also:
- Constant Field Values
-
MINUS
private static final java.lang.String MINUS
- See Also:
- Constant Field Values
-
TICK_LABEL_GAP
private static final int TICK_LABEL_GAP
- See Also:
- Constant Field Values
-
showMaxLabel
private boolean showMaxLabel
default: show max label
-
showMinLabel
private boolean showMinLabel
default: show min label
-
tickLabelValues
private java.util.ArrayList<java.lang.Double> tickLabelValues
the array of tick label vales
-
tickLabels
private java.util.ArrayList<java.lang.String> tickLabels
the array of tick label
-
tickLabelPositions
private java.util.ArrayList<java.lang.Integer> tickLabelPositions
the array of tick label position in pixels
-
tickLabelVisibilities
private java.util.ArrayList<java.lang.Boolean> tickLabelVisibilities
the array of visibility state of tick label
-
tickLabelMaxLength
private int tickLabelMaxLength
the maximum length of tick labels
-
tickLabelMaxHeight
private int tickLabelMaxHeight
the maximum height of tick labels
-
gridStepInPixel
private int gridStepInPixel
-
minorPositions
private java.util.ArrayList<java.lang.Integer> minorPositions
the array of minor tick positions in pixels
-
scale
private IScaleProvider scale
-
-
Constructor Detail
-
LinearScaleTicks
public LinearScaleTicks(IScaleProvider scale)
constructor- Parameters:
scale-
-
-
Method Detail
-
pow
private java.math.BigDecimal pow(double base, int exponent)Get base^exponent
-
getGridStepInPixels
public int getGridStepInPixels()
- Returns:
- the gridStepInPixel
-
getTickLabelMaxHeight
public int getTickLabelMaxHeight()
- Returns:
- the tickLabelMaxHeight
-
getTickLabelMaxLength
public int getTickLabelMaxLength()
- Returns:
- the tickLabelMaxLength
-
getPositions
public java.util.List<java.lang.Integer> getPositions()
Description copied from interface:ITicksProviderGets the tick positions.- Specified by:
getPositionsin interfaceITicksProvider- Returns:
- the tick positions
-
getVisibilities
public java.util.List<java.lang.Boolean> getVisibilities()
- Specified by:
getVisibilitiesin interfaceITicksProvider- Returns:
- the tick visibilities
-
getPosition
public int getPosition(int index)
- Specified by:
getPositionin interfaceITicksProvider- Returns:
- tick position
-
getValue
public double getValue(int index)
- Specified by:
getValuein interfaceITicksProvider- Returns:
- tick value
-
getLabel
public java.lang.String getLabel(int index)
- Specified by:
getLabelin interfaceITicksProvider- Returns:
- tick label
-
getLabels
public java.util.List<java.lang.String> getLabels()
- Specified by:
getLabelsin interfaceITicksProvider- Returns:
- the tick labels
-
getLabelPosition
public int getLabelPosition(int index)
- Specified by:
getLabelPositionin interfaceITicksProvider- Returns:
- label position
-
isVisible
public boolean isVisible(int index)
- Specified by:
isVisiblein interfaceITicksProvider- Returns:
- true if tick is visible
-
getMajorCount
public int getMajorCount()
- Specified by:
getMajorCountin interfaceITicksProvider- Returns:
- number of major ticks
-
getMinorCount
public int getMinorCount()
- Specified by:
getMinorCountin interfaceITicksProvider- Returns:
- number of minor ticks
-
getMinorPosition
public int getMinorPosition(int index)
- Specified by:
getMinorPositionin interfaceITicksProvider- Returns:
- minor tick position
-
getMaxWidth
public int getMaxWidth()
- Specified by:
getMaxWidthin interfaceITicksProvider- Returns:
- maximum width in pixels of tick labels
-
getMaxHeight
public int getMaxHeight()
- Specified by:
getMaxHeightin interfaceITicksProvider- Returns:
- maximum height in pixels of tick labels
-
isShowMaxLabel
public boolean isShowMaxLabel()
Description copied from interface:ITicksProviderShows the maximum value of the range as a label- Specified by:
isShowMaxLabelin interfaceITicksProvider- Returns:
- true (default) if shown
-
setShowMaxLabel
public void setShowMaxLabel(boolean showMaxLabel)
Description copied from interface:ITicksProvidersets the visibility of the maximum label- Specified by:
setShowMaxLabelin interfaceITicksProvider
-
isShowMinLabel
public boolean isShowMinLabel()
Description copied from interface:ITicksProviderShows the minimum value of the range as a label- Specified by:
isShowMinLabelin interfaceITicksProvider- Returns:
- true (default) if shown
-
setShowMinLabel
public void setShowMinLabel(boolean showMinLabel)
Description copied from interface:ITicksProviderSets the visibility of the minimum label- Specified by:
setShowMinLabelin interfaceITicksProvider
-
getGridStep
private double getGridStep(int lengthInPixels, double min, double max)Gets the grid step.- Parameters:
lengthInPixels- scale length in pixelsmin- minimum valuemax- maximum value- Returns:
- rounded value.
-
getTimeGridStep
private double getTimeGridStep(double min, double max, double gridStepHint)Given min, max and the gridStepHint, returns the time grid step as a double.- Parameters:
min- minimum valuemax- maximum valuegridStepHint-- Returns:
- time rounded value
-
hasSpaceToDraw
private boolean hasSpaceToDraw(int previousPosition, int tickLabelPosition, java.lang.String previousTickLabel, java.lang.String tickLabel)If it has enough space to draw the tick label
-
isMajorTick
private boolean isMajorTick(double tickValue)
Checks if the tick label is major tick. For example: 0.001, 0.01, 0.1, 1, 10, 100...
-
getDefaultFormatPattern
public java.lang.String getDefaultFormatPattern(double min, double max)- Specified by:
getDefaultFormatPatternin interfaceITicksProvider- Returns:
- default format pattern for labels
-
updateTickLabelForLinearScale
private void updateTickLabelForLinearScale(double min, double max, int length)Updates tick label for normal scale.- Parameters:
min-max-length- scale tick length (without margin)
-
updateTickLabelForLinearScale
private void updateTickLabelForLinearScale(double min, double max, int length, double tickStep)Updates tick label for normal scale.- Parameters:
min-max-length- scale tick length (without margin)tickStep- the tick step
-
updateTickLabelForLogScale
private void updateTickLabelForLogScale(double min, double max, int length)Updates tick label for log scale.- Parameters:
min-max-length- the length of scale
-
addTickInfo
private void addTickInfo(java.math.BigDecimal d, double max, double logMin, int length, boolean isFirstPosition, boolean minDateAdded)Add the tick labels, positions and values to the corresponding List used to store them.- Parameters:
d- BigDecimal valuemax- maximum valuelogMin- value used to calculate tick label positionlength- value used to calculate tick label positionisFirstPosition- needed for date labelminDateAdded- needed for date label
-
addMinMaxTickInfo
private boolean addMinMaxTickInfo(double value, int length, boolean isMin)Add the tick labels, positions and values for the min and max case to the corresponding List used to store them.- Parameters:
value-length- used for max positionisMin- if True, we add the min related info, otherwise the max related info- Returns:
- minDateAdded false by default, true if min and date are enabled
-
updateTickLabelMaxLengthAndHeight
private void updateTickLabelMaxLengthAndHeight()
Gets max length of tick label.
-
getHeadMargin
public int getHeadMargin()
- Specified by:
getHeadMarginin interfaceITicksProvider- Returns:
- margin in pixel between edge of client area and head of axis line
-
getTailMargin
public int getTailMargin()
- Specified by:
getTailMarginin interfaceITicksProvider- Returns:
- margin in pixel between edge of client area and tail of axis line
-
updateTickVisibility
private void updateTickVisibility()
Updates the visibility of tick labels.
-
update
public Range update(double min, double max, int length)
Description copied from interface:ITicksProviderUpdate ticks.- Specified by:
updatein interfaceITicksProvider- Returns:
- null unless the provider has not had cause to change the range - in which case, the new range is returned.
-
-