# Class LabelUnit

java.lang.Object
uk.ac.starlink.ttools.plot2.geom.LabelUnit

All Implemented Interfaces:
  `Comparable<LabelUnit>`

public class LabelUnit extends Object implements 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(String name, double factor)`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`int`
`compareTo(LabelUnit other)`
`static 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.
`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.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### LabelUnit

public LabelUnit(String name, double factor)
Constructor.

Parameters:
  `name` - human-readable unit name for annotating values
  `factor` - size of this unit in terms of some standard unit

## Method Details

### getName

public 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 interface `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 units
  `units` - list of available units
Returns:
  most suitable entry from supplied units list

### formatValue

public static 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 units
  `eps` - approximate precision of value in standard units
  `units` - list of available units
Returns:
  string giving numeric value, with unit name appended