Class GraphicsUtils

    • Constructor Detail

      • GraphicsUtils

        public GraphicsUtils()
    • Method Detail

      • parseColour

        public static Color parseColour​(String colourString)
                                 throws EdalParseException
        Parses a string to obtain a Color.
        Parameters:
        colourString - A string of one of the forms:
      • 0xRRGGBB
      • 0xAARRGGBB
      • #RRGGBB
      • #AARRGGBB
      • "transparent"
      • "extend"
      • A named colour. See getNamedColours() for a full list
      • Returns:
        A Color representing the string, or null if "extend" was supplied
        Throws:
        EdalParseException - If the format of the string does not fall into one of the above categories
      • getNamedColours

        public static Collection<String> getNamedColours()
        Returns:
        The available named colours
      • colourToString

        public static String colourToString​(Color colour)
        Converts a Color to an HTML-like String (#AARRGGBB), with additional cases for transparent / null values
        Parameters:
        colour - The colour to represent as a String
        Returns:
        The HTML representation of the Color, or null if a null Color was supplied.
      • colourToHtmlString

        public static String colourToHtmlString​(Color colour)
        Converts a Color to an HTML String (#RRGGBB), ignoring transparency.
        Parameters:
        colour - The colour to represent as a String
        Returns:
        The HTML representation of the Color, or null if a null Color was supplied.
      • estimateValueRange

        public static Extent<Float> estimateValueRange​(Dataset dataset,
                                                       String varId)
        Estimate the range of values in this layer by reading a sample of data from the default time and elevation. If the given variable is not found, a default range of 0-100 is returned
        Parameters:
        dataset - The dataset containing the variable to estimate
        varId - The ID of the variable to estimate
        Returns:
        An approximate value range
      • roundToSignificantFigures

        public static double roundToSignificantFigures​(double num,
                                                       int n)
        Rounds a double to a number of significant figures Taken from: http://stackoverflow.com/questions/202302/rounding-to-an-arbitrary -number-of-significant-digits
        Parameters:
        num - The number to round
        n - The number of significant figures
        Returns:
        The rounded number
      • generateColourSet

        public static Color[] generateColourSet​(Color[] palette,
                                                int numColorBands)
        Gets a version of this palette with the given number of color bands, either by subsampling or interpolating the existing palette
        Parameters:
        numColorBands - The number of bands of colour to be used in the new palette
        Returns:
        An array of Colors, with length numColorBands
      • drawCategoricalLegend

        public static BufferedImage drawCategoricalLegend​(Map<Integer,​Parameter.Category> categories)
        Renders a legend for categorical data
        Parameters:
        categories - The categories to draw a legend for
        Returns:
        The resulting BufferedImage
      • plotDefaultImage

        public static BufferedImage plotDefaultImage​(Dataset dataset,
                                                     String varId,
                                                     int width,
                                                     int height)
        Draws a raster image from the supplied dataset and variable
        Parameters:
        dataset - The dataset containing the data
        varId - The ID of the variable to plot
        width - The desired width of the output image
        height - The desired height of the output image
        Returns:
        A BufferedImage containing the plot