Package uk.ac.starlink.ttools.plot2.geom
Class LabelUnit
- java.lang.Object
-
- uk.ac.starlink.ttools.plot2.geom.LabelUnit
-
- All Implemented Interfaces:
java.lang.Comparable<LabelUnit>
public class LabelUnit extends java.lang.Object implements java.lang.Comparable<LabelUnit>
Utility class for working with units for labelling extents. It is not currently intended for use with absolute values.- Since:
- 23 Jan 2018
- Author:
- Mark Taylor
-
-
Constructor Summary
Constructors Constructor Description LabelUnit(java.lang.String name, double factor)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(LabelUnit other)
static java.lang.String
formatValue(double value, double eps, LabelUnit[] units)
Formats a given number giving its value in a sensible precision using a suitable unit.double
getFactor()
Returns the size of this unit in terms of some standard unit.java.lang.String
getName()
Returns this unit's name as used for annotating values.static LabelUnit
getUnit(double value, LabelUnit[] units)
Returns an appropriate unit for annotating the given value.
-
-
-
Method Detail
-
getName
public java.lang.String getName()
Returns this unit's name as used for annotating values.- Returns:
- name
-
getFactor
public double getFactor()
Returns the size of this unit in terms of some standard unit.- Returns:
- factor
-
compareTo
public int compareTo(LabelUnit other)
- Specified by:
compareTo
in interfacejava.lang.Comparable<LabelUnit>
-
getUnit
public static LabelUnit getUnit(double value, LabelUnit[] units)
Returns an appropriate unit for annotating the given value.- Parameters:
value
- value in standard unitsunits
- list of available units- Returns:
- most suitable entry from supplied units list
-
formatValue
public static java.lang.String formatValue(double value, double eps, LabelUnit[] units)
Formats a given number giving its value in a sensible precision using a suitable unit.- Parameters:
value
- numeric value in standard unitseps
- approximate precision of value in standard unitsunits
- list of available units- Returns:
- string giving numeric value, with unit name appended
-
-