Package org.pepstock.charba.client.items
Class ScaleItem
- java.lang.Object
-
- org.pepstock.charba.client.commons.NativeObjectContainer
-
- org.pepstock.charba.client.items.BaseBoxItem
-
- org.pepstock.charba.client.items.BaseBoxNodeItem<AxisPosition>
-
- org.pepstock.charba.client.items.ScaleItem
-
- All Implemented Interfaces:
IsArea
- Direct Known Subclasses:
AxisItem
public class ScaleItem extends BaseBoxNodeItem<AxisPosition>
Wraps the scale item of CHART JS chart.
This is a wrapper of scale of Chart (of CHART.JS).- Author:
- Andrea "Stock" Stocchero
-
-
Constructor Summary
Constructors Constructor Description ScaleItem(CallbacksEnvelop<NativeObject> envelop)
Creates the item using an envelop (fromcallbacks
package) of native java script object which contains all properties.
-
Method Summary
All Methods Instance Methods Concrete Methods Default Methods Modifier and Type Method Description String
format(long time)
Formats the time passed as argument with date configuration.String
format(long time, String format)
Formats the time passed as argument with passed format.String
format(Date time)
Formats the time passed as argument with date configuration.String
format(Date time, String format)
Formats the time passed as argument with passed format.AxisKind
getAxis()
Which kind of axis this is.
Possible values are: ''x', 'y' or 'r'.double
getBasePixel()
Returns the pixel for the minimum chart value.
The coordinate (0, 0) is at the upper-left corner of the canvas.double
getBaseValue()
Returns the minimum chart value.int
getCharbaId()
Returns the unique id of scale.IsChart
getChart()
Returns the CHARBA chart instance.DateAdapter
getDateAdapter()
Returns the date adapter of the scale if the scale is a time or time series, otherwise new date adapter.double
getDecimalForPixel(double pixel)
Used to get the data value from a given pixel.
This is the inverse of getPixelForValue.
The coordinate (0, 0) is at the upper-left corner of the canvas.double
getDistanceFromCenterForValue(double value)
Returns the distance from the center of a specific value.int
getDrawingArea()
Returns the drawing area dimension of scale.double
getEnd()
Returns the end value of scale.ScaleId
getId()
Returns the id of scaleString
getLabelForValue(double value)
Used to get the label to display in the tooltip for the given value.List<ScaleLabelItem>
getLabelItems()
Returns the labels computed in the scale.double
getLabelRotation()
Returns the label rotation ratio.double
getMax()
Returns the max value of scale.Date
getMaxAsDate()
Returns the max value of scale.String
getMaxAsString()
Returns the max value of scale.double
getMin()
Returns the minimum value of scale.Date
getMinAsDate()
Returns the minimum value of scale.String
getMinAsString()
Returns the minimum value of scale.double
getPixelForDateValue(Date value)
Returns the location of the given data point.
The coordinate (0, 0) is at the upper-left corner of the canvas.double
getPixelForDateValue(Date value, double index)
Returns the location of the given data point.
Value can either be an index or a numerical value.
The coordinate (0, 0) is at the upper-left corner of the canvas.double
getPixelForDecimal(double decimal)
Utility for getting the pixel location of a percentage of scale.
The coordinate (0, 0) is at the upper-left corner of the canvas.double
getPixelForStringValue(String value)
Returns the location of the given data point.
The coordinate (0, 0) is at the upper-left corner of the canvas.double
getPixelForStringValue(String value, double index)
Returns the location of the given data point.
The coordinate (0, 0) is at the upper-left corner of the canvas.double
getPixelForTick(double index)
Returns the location of the tick at the given index.
The coordinate (0, 0) is at the upper-left corner of the canvas.double
getPixelForValue(double value)
Returns the location of the given data point.
The coordinate (0, 0) is at the upper-left corner of the canvas.double
getPixelForValue(double value, double index)
Returns the location of the given data point.
Value can either be an index or a numerical value.
The coordinate (0, 0) is at the upper-left corner of the canvas.List<String>
getPointLabels()
Returns the list of point labels of scale.double
getStart()
Returns the start value of scale.List<ScaleTickItem>
getTicks()
Returns the list of ticks.AxisType
getType()
Returns the type of scaleScaleValueItem
getValueAtEvent(NativeAbstractMouseEvent event)
Returns the value on the axis related to an event position.ScaleValueItem
getValueAtEvent(HasNativeEvent container)
Returns the value on the axis related to an event position.ScaleValueItem
getValueAtPixel(double position)
Returns the value on the axis related to a position, passed as pixels.double
getValueForDistanceFromCenter(double distance)
Returns the value calculated applying the specific distance from the center.double
getValueForPixel(double pixel)
Used to get the data value from a given pixel.
This is the inverse of getPixelForValue.
The coordinate (0, 0) is at the upper-left corner of the canvas.int
getXCenter()
Returns the X center of scale.int
getYCenter()
Returns the Y center of scale.boolean
isHorizontal()
Returnstrue
if the scale is horizontal.default boolean
isInside(NativeBaseEvent event)
Returnstrue
if the chart event is inside of a chart element, otherwisefalse
.default boolean
isInside(HasNativeEvent container)
Returnstrue
if the chart event is inside of this box, otherwisefalse
.-
Methods inherited from class org.pepstock.charba.client.items.BaseBoxNodeItem
getMaxHeight, getMaxWidth, getPaddingBottom, getPaddingLeft, getPaddingRight, getPaddingTop, getPosition, getWeight, isActive, isFullSize
-
Methods inherited from class org.pepstock.charba.client.items.BaseBoxItem
getBottom, getHeight, getLeft, getRight, getTop, getWidth, isInside
-
Methods inherited from class org.pepstock.charba.client.commons.NativeObjectContainer
checkAndGetColor, checkDefaultValuesArgument, empty, getArrayValue, getElement, getIncrementalId, getNativeChart, getNativeEvent, getNativeObject, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValueForMultipleKeyTypes, getValueForMultipleKeyTypes, getValueForMultipleKeyTypes, getValueOrArray, getValueOrArray, getValueOrArray, getValueOrArray, getValueOrArray, getValueOrArray, getValueOrArray, getValueOrArray, getValueOrArray, has, has, isType, keys, loadNativeObject, remove, remove, setArrayValue, setArrayValue, setArrayValue, setElement, setEmptyValue, setNewIncrementalId, setNewIncrementalId, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValueOrArray, setValueOrArray, setValueOrArray, setValueOrArray, setValueOrArray, setValueOrArray, setValueOrArray, setValueOrArray, setValueOrArray, setValueOrArray, toJSON, type
-
-
-
-
Constructor Detail
-
ScaleItem
public ScaleItem(CallbacksEnvelop<NativeObject> envelop)
Creates the item using an envelop (fromcallbacks
package) of native java script object which contains all properties.- Parameters:
envelop
- envelop of native java script object which contains all properties.
-
-
Method Detail
-
getChart
public final IsChart getChart()
Returns the CHARBA chart instance.- Returns:
- the CHARBA chart instance
-
getId
public final ScaleId getId()
Returns the id of scale- Returns:
- the id of scale.
-
getCharbaId
public final int getCharbaId()
Returns the unique id of scale.- Returns:
- the unique id of scale.
-
getDateAdapter
public final DateAdapter getDateAdapter()
Returns the date adapter of the scale if the scale is a time or time series, otherwise new date adapter.- Returns:
- the date adapter of the scale if the scale is a time or time series, otherwise new date adapter
-
getAxis
public final AxisKind getAxis()
Which kind of axis this is.
Possible values are: ''x', 'y' or 'r'.- Returns:
- the kind of axis.
-
getType
public final AxisType getType()
Returns the type of scale- Returns:
- the type of scale.
-
getMax
public final double getMax()
Returns the max value of scale.- Returns:
- the max value of scale.
-
getMin
public final double getMin()
Returns the minimum value of scale.- Returns:
- the minimum value of scale.
-
getMaxAsString
public final String getMaxAsString()
Returns the max value of scale.- Returns:
- the max value of scale.
-
getMinAsString
public final String getMinAsString()
Returns the minimum value of scale.- Returns:
- the minimum value of scale.
-
getMaxAsDate
public final Date getMaxAsDate()
Returns the max value of scale.- Returns:
- the max value of scale. If missing returns is
null
.
-
getMinAsDate
public final Date getMinAsDate()
Returns the minimum value of scale.- Returns:
- the minimum value of scale. If missing returns is
null
.
-
getTicks
public final List<ScaleTickItem> getTicks()
Returns the list of ticks.- Returns:
- the list of ticks.
-
getLabelRotation
public final double getLabelRotation()
Returns the label rotation ratio.- Returns:
- the label rotation ratio.
-
getStart
public final double getStart()
Returns the start value of scale.- Returns:
- the start value of scale.
-
getEnd
public final double getEnd()
Returns the end value of scale.- Returns:
- the end value of scale.
-
getXCenter
public final int getXCenter()
Returns the X center of scale.- Returns:
- the X center of scale.
-
getYCenter
public final int getYCenter()
Returns the Y center of scale.- Returns:
- the Y center of scale.
-
getDrawingArea
public final int getDrawingArea()
Returns the drawing area dimension of scale.- Returns:
- the drawing area dimension of scale.
-
getPointLabels
public final List<String> getPointLabels()
Returns the list of point labels of scale.- Returns:
- the list of point labels of scale.
-
getLabelItems
public List<ScaleLabelItem> getLabelItems()
Returns the labels computed in the scale.- Returns:
- the labels computed in the scale.
-
isHorizontal
public final boolean isHorizontal()
Returnstrue
if the scale is horizontal.- Returns:
true
if the scale is horizontal
-
format
public final String format(Date time)
Formats the time passed as argument with date configuration.- Parameters:
time
- epoch time to format- Returns:
- formatted time
-
format
public final String format(long time)
Formats the time passed as argument with date configuration.- Parameters:
time
- epoch time to format- Returns:
- formatted time
-
format
public final String format(Date time, String format)
Formats the time passed as argument with passed format.- Parameters:
time
- epoch time to formatformat
- string format to apply- Returns:
- formatted time
-
format
public final String format(long time, String format)
Formats the time passed as argument with passed format.- Parameters:
time
- epoch time to formatformat
- string format to apply- Returns:
- formatted time
-
getValueAtEvent
public final ScaleValueItem getValueAtEvent(HasNativeEvent container)
Returns the value on the axis related to an event position.- Parameters:
container
- event container instance used to get the value from the scale- Returns:
- the value on the axis related to an event position
-
getValueAtEvent
public final ScaleValueItem getValueAtEvent(NativeAbstractMouseEvent event)
Returns the value on the axis related to an event position.- Parameters:
event
- event instance used to get the value from the scale- Returns:
- the value on the axis related to an event position
-
getValueAtPixel
public final ScaleValueItem getValueAtPixel(double position)
Returns the value on the axis related to a position, passed as pixels.- Parameters:
position
- position in pixel used to get the value from the scale- Returns:
- the value on the axis related to a position, passed as pixels
-
getDecimalForPixel
public final double getDecimalForPixel(double pixel)
Used to get the data value from a given pixel.
This is the inverse of getPixelForValue.
The coordinate (0, 0) is at the upper-left corner of the canvas.- Parameters:
pixel
- pixel value- Returns:
- the data value from a given pixel
-
getPixelForDecimal
public final double getPixelForDecimal(double decimal)
Utility for getting the pixel location of a percentage of scale.
The coordinate (0, 0) is at the upper-left corner of the canvas.- Parameters:
decimal
- number value to use- Returns:
- the pixel location of a percentage of scale
-
getPixelForTick
public final double getPixelForTick(double index)
Returns the location of the tick at the given index.
The coordinate (0, 0) is at the upper-left corner of the canvas.- Parameters:
index
- tick index to use- Returns:
- the location of the tick at the given index
-
getLabelForValue
public final String getLabelForValue(double value)
Used to get the label to display in the tooltip for the given value.- Parameters:
value
- value of the data- Returns:
- the label to display in the tooltip for the given value
-
getPixelForStringValue
public final double getPixelForStringValue(String value)
Returns the location of the given data point.
The coordinate (0, 0) is at the upper-left corner of the canvas.- Parameters:
value
- value of the data- Returns:
- the location of the given data point
-
getPixelForStringValue
public final double getPixelForStringValue(String value, double index)
Returns the location of the given data point.
The coordinate (0, 0) is at the upper-left corner of the canvas.- Parameters:
value
- value of the data as stringindex
- index of the data- Returns:
- the location of the given data point
-
getPixelForDateValue
public final double getPixelForDateValue(Date value)
Returns the location of the given data point.
The coordinate (0, 0) is at the upper-left corner of the canvas.- Parameters:
value
- value of the data- Returns:
- the location of the given data point
-
getPixelForDateValue
public final double getPixelForDateValue(Date value, double index)
Returns the location of the given data point.
Value can either be an index or a numerical value.
The coordinate (0, 0) is at the upper-left corner of the canvas.- Parameters:
value
- value of the data as dateindex
- index of the data- Returns:
- the location of the given data point
-
getPixelForValue
public final double getPixelForValue(double value)
Returns the location of the given data point.
The coordinate (0, 0) is at the upper-left corner of the canvas.- Parameters:
value
- value of the data- Returns:
- the location of the given data point
-
getPixelForValue
public final double getPixelForValue(double value, double index)
Returns the location of the given data point.
Value can either be an index or a numerical value.
The coordinate (0, 0) is at the upper-left corner of the canvas.- Parameters:
value
- value of the dataindex
- index of the data- Returns:
- the location of the given data point
-
getValueForPixel
public final double getValueForPixel(double pixel)
Used to get the data value from a given pixel.
This is the inverse of getPixelForValue.
The coordinate (0, 0) is at the upper-left corner of the canvas.- Parameters:
pixel
- pixel value- Returns:
- the data value from a given pixel
-
getBaseValue
public final double getBaseValue()
Returns the minimum chart value.- Returns:
- the minimum chart value
-
getBasePixel
public final double getBasePixel()
Returns the pixel for the minimum chart value.
The coordinate (0, 0) is at the upper-left corner of the canvas.- Returns:
- the pixel for the minimum chart value
-
getDistanceFromCenterForValue
public final double getDistanceFromCenterForValue(double value)
Returns the distance from the center of a specific value.- Parameters:
value
- the value of to check- Returns:
- the distance from the center of a specific value
-
getValueForDistanceFromCenter
public final double getValueForDistanceFromCenter(double distance)
Returns the value calculated applying the specific distance from the center.- Parameters:
distance
- the distance which must be applied- Returns:
- the value calculated applying the specific distance from the center.
-
isInside
public default boolean isInside(NativeBaseEvent event)
Returnstrue
if the chart event is inside of a chart element, otherwisefalse
.- Parameters:
event
- event to check if inside of a chart element.- Returns:
true
if the chart event is inside a chart element, otherwisefalse
-
isInside
public default boolean isInside(HasNativeEvent container)
Returnstrue
if the chart event is inside of this box, otherwisefalse
.- Parameters:
container
- event container to check if inside the box- Returns:
true
if the chart event is inside of this box, otherwisefalse
-
-