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 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