public class AxisTickLabels
extends java.lang.Object
implements org.eclipse.swt.events.PaintListener
Modifier and Type | Field and Description |
---|---|
private Axis |
axis
the axis
|
private org.eclipse.swt.graphics.Rectangle |
bounds
the bounds of tick labels area
|
private Chart |
chart
the chart
|
private static java.lang.String |
DEFAULT_DECIMAL_FORMAT
the default label format
|
private static org.eclipse.swt.graphics.Font |
DEFAULT_FONT
the default font
|
private static int |
DEFAULT_FOREGROUND
the default foreground
|
private org.eclipse.swt.graphics.Font |
font
the font
|
private org.eclipse.swt.graphics.Color |
foreground
the foreground color
|
private java.text.Format |
format
the format for tick labels
|
private int |
heightHint
the height hint of tick labels area
|
private java.util.Map<java.lang.Integer,java.lang.Integer[]> |
possibleTickSteps
the possible tick steps
|
private java.util.ArrayList<java.lang.Integer> |
tickLabelPositions
the array of tick label position in pixels
|
private java.util.ArrayList<java.lang.String> |
tickLabels
the array of tick label
|
private java.util.ArrayList<java.lang.Double> |
tickLabelValues
the array of tick label vales
|
private java.util.ArrayList<java.lang.Boolean> |
tickVisibilities
the array of visibility state of tick label
|
private int |
timeUnit
the time unit for tick step
|
private int |
widthHint
the width hint of tick labels area
|
Modifier | Constructor and Description |
---|---|
protected |
AxisTickLabels(Chart chart,
Axis axis)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
dispose()
Disposes the resources.
|
private static void |
drawRotatedText(org.eclipse.swt.graphics.GC gc,
java.lang.String text,
float x,
float y,
int angle)
Draws the rotated text.
|
private void |
drawXTick(org.eclipse.swt.graphics.GC gc)
Draw the X tick.
|
private void |
drawYTick(org.eclipse.swt.graphics.GC gc)
Draw the Y tick.
|
private java.lang.String |
format(java.lang.Object obj)
Formats the given object.
|
protected org.eclipse.swt.graphics.Rectangle |
getBounds()
Gets the bounds on chart panel.
|
org.eclipse.swt.graphics.Font |
getFont()
Gets the font.
|
protected org.eclipse.swt.graphics.Color |
getForeground()
Gets the foreground color.
|
protected java.text.Format |
getFormat()
Gets the format for axis tick label.
|
private java.math.BigDecimal |
getGridStep(int lengthInPixels,
double min,
double max)
Gets the grid step.
|
ChartLayoutData |
getLayoutData()
Gets the layout data.
|
int |
getLeftMarginHint(int length)
Updates the left margin hint.
|
private static long |
getPeriodInMillis(int unit,
int amount)
Gets the period in milliseconds of given unit of date and amount.
|
int |
getRightMarginHint(int length)
Gets the right margin hint.
|
int |
getTickLabelMaxLength()
Gets the max length of tick label.
|
java.util.ArrayList<java.lang.Integer> |
getTickLabelPositions()
Gets the tick label positions.
|
protected java.util.ArrayList<java.lang.Double> |
getTickLabelValues()
Gets the tick label values.
|
private int |
getTimeUnit(double gridStepHint)
Gets the tick step unit.
|
private boolean |
hasSpaceToDraw(int previousPosition,
int tickLabelPosition,
java.lang.String tickLabel)
Returns the state indicating if there is a space to draw tick label.
|
private void |
initializePossibleTickSteps()
Initialized the possible tick steps.
|
private boolean |
isMajorTick(double tickValue)
Checks if the tick label is major (...,0.01,0.1,1,10,100,...).
|
void |
paintControl(org.eclipse.swt.events.PaintEvent e) |
private static java.math.BigDecimal |
pow(double base,
int exponent)
Calculates the value of the first argument raised to the power of the
second argument.
|
void |
setBounds(int x,
int y,
int width,
int height)
Sets the bounds on chart panel.
|
protected void |
setFont(org.eclipse.swt.graphics.Font font)
Sets the font.
|
void |
setForeground(org.eclipse.swt.graphics.Color color)
Sets the foreground color.
|
protected void |
setFormat(java.text.Format format)
Sets the format for axis tick label.
|
protected void |
update(int length)
Updates the tick labels.
|
protected void |
updateLayoutData()
Updates the tick labels layout.
|
private void |
updateTickLabelForCategoryAxis(int length)
Updates tick label for category axis.
|
private void |
updateTickLabelForDateAxis(int length)
Updates tick label for date axis.
|
private void |
updateTickLabelForLinearScale(int length)
Updates tick label for normal scale.
|
private void |
updateTickLabelForLinearScale(int length,
java.math.BigDecimal tickStep)
Updates tick label for normal scale.
|
private void |
updateTickLabelForLogScale(int length)
Updates tick label for log scale.
|
private void |
updateTickLabelForMonthOrYear(int length,
double gridStepHint,
int tickStepUnit)
Updates the tick label for month or year.
|
private void |
updateTickVisibility()
Updates the visibility of tick labels.
|
private final Chart chart
private final Axis axis
private org.eclipse.swt.graphics.Color foreground
private int widthHint
private int heightHint
private org.eclipse.swt.graphics.Rectangle bounds
private final java.util.ArrayList<java.lang.Double> tickLabelValues
private final java.util.ArrayList<java.lang.String> tickLabels
private final java.util.ArrayList<java.lang.Integer> tickLabelPositions
private final java.util.ArrayList<java.lang.Boolean> tickVisibilities
private java.text.Format format
private static final int DEFAULT_FOREGROUND
private static final org.eclipse.swt.graphics.Font DEFAULT_FONT
private static final java.lang.String DEFAULT_DECIMAL_FORMAT
private java.util.Map<java.lang.Integer,java.lang.Integer[]> possibleTickSteps
private int timeUnit
private org.eclipse.swt.graphics.Font font
private void initializePossibleTickSteps()
public void setForeground(org.eclipse.swt.graphics.Color color)
color
- the foreground colorprotected org.eclipse.swt.graphics.Color getForeground()
protected void update(int length)
length
- the axis lengthprivate void updateTickLabelForDateAxis(int length)
length
- the length of axisprivate void updateTickLabelForMonthOrYear(int length, double gridStepHint, int tickStepUnit)
length
- the length of axisgridStepHint
- the grid step hinttickStepUnit
- the tick step unit of timeprivate void updateTickLabelForCategoryAxis(int length)
length
- the length of axisprivate void updateTickLabelForLogScale(int length)
length
- the length of axisprivate void updateTickLabelForLinearScale(int length)
length
- axis length (>0)private void updateTickLabelForLinearScale(int length, java.math.BigDecimal tickStep)
length
- axis length (>0)tickStep
- the tick stepprivate void updateTickVisibility()
private int getTimeUnit(double gridStepHint)
gridStepHint
- the grid step hintprivate static long getPeriodInMillis(int unit, int amount)
unit
- the unit of time like Calendar.YEAR.amount
- the amount of period.private java.lang.String format(java.lang.Object obj)
obj
- the objectprivate boolean isMajorTick(double tickValue)
tickValue
- the tick label valueprivate boolean hasSpaceToDraw(int previousPosition, int tickLabelPosition, java.lang.String tickLabel)
previousPosition
- the previously drawn tick label position.tickLabelPosition
- the tick label position.tickLabel
- the tick label textpublic int getRightMarginHint(int length)
length
- the axis lengthpublic int getLeftMarginHint(int length)
length
- the axis lengthpublic int getTickLabelMaxLength()
private static java.math.BigDecimal pow(double base, int exponent)
base
- the baseexponent
- the exponentprivate java.math.BigDecimal getGridStep(int lengthInPixels, double min, double max)
lengthInPixels
- axis length in pixelsmin
- minimum valuemax
- maximum valuepublic java.util.ArrayList<java.lang.Integer> getTickLabelPositions()
protected java.util.ArrayList<java.lang.Double> getTickLabelValues()
protected void setFont(org.eclipse.swt.graphics.Font font)
font
- the fontpublic org.eclipse.swt.graphics.Font getFont()
public ChartLayoutData getLayoutData()
public void setBounds(int x, int y, int width, int height)
x
- the x coordinatey
- the y coordinatewidth
- the widthheight
- the heightprotected org.eclipse.swt.graphics.Rectangle getBounds()
protected void dispose()
protected void updateLayoutData()
public void paintControl(org.eclipse.swt.events.PaintEvent e)
paintControl
in interface org.eclipse.swt.events.PaintListener
private void drawXTick(org.eclipse.swt.graphics.GC gc)
gc
- the graphics contextprivate static void drawRotatedText(org.eclipse.swt.graphics.GC gc, java.lang.String text, float x, float y, int angle)
gc
- the graphics contexttext
- the textx
- the x coordinatey
- the y coordinateangle
- the angleprivate void drawYTick(org.eclipse.swt.graphics.GC gc)
gc
- the graphics contextprotected void setFormat(java.text.Format format)
If null is set, default format will be used.
format
- the formatprotected java.text.Format getFormat()