Package uk.ac.starlink.ttools.plot2.geom
Class LabelUnit
java.lang.Object
uk.ac.starlink.ttools.plot2.geom.LabelUnit
- All Implemented Interfaces:
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 -
Method Summary
Modifier and TypeMethodDescriptionintstatic StringformatValue(double value, double eps, LabelUnit[] units) Formats a given number giving its value in a sensible precision using a suitable unit.doubleReturns the size of this unit in terms of some standard unit.getName()Returns this unit's name as used for annotating values.static LabelUnitReturns an appropriate unit for annotating the given value.
-
Constructor Details
-
LabelUnit
Constructor.- Parameters:
name- human-readable unit name for annotating valuesfactor- size of this unit in terms of some standard unit
-
-
Method Details
-
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
- Specified by:
compareToin interfaceComparable<LabelUnit>
-
getUnit
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
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
-